Week 3 Linear codes

Version 2023-10-02. To PDF of this week only Open the whole set of notes in PDF

Synopsis. The most important class of codes is linear codes. Their ability to correct errors is no worse than that of general codes, but linear codes are easier to implement in practice and allow us to use algebraic methods. We learn how to find the minimum distance by looking at weights, and how to define a linear code by its generator matrix.

The definition of a linear code

Reminder (vector spaces): let Fq denote the field of q elements. When we use Fq as the alphabet, we refer to words in Fqn as (row) vectors. The set Fqn of all vectors of length n has the structure of a vector space over the field Fq. If the vectors u, v are in Fqn, we can add the vectors together: u+vFqn, and multiply a vector by a scalar: λuFqn for all λFq. The addition and the scalar multiplication are performed componentwise. We will often write vectors in compact form, as words:

011011,100110F26011011+100110=111101F26.

Definition: linear code, codevector

A linear code is a subspace of the vector space Fqn.

Codewords of a linear code are called codevectors.

This means that the zero vector 0 belongs to C, and that sums and scalar multiples of codevectors are again codevectors. Thus, C is a vector space in its own right.

Discussion: Why are linear codes useful? (not examinable)

1. They seem to be as efficient as general codes. In particular, it was proved that Shannon’s Theorem about the capacity of a channel (discussed later) is still true for linear codes.

2. It is possible to define a linear code without specifying all the codewords (see below).

3. The minimum distance is easier to calculate than for general codes (see below).

4. We can use algebra to design linear codes and to construct efficient encoding and decoding algorithms.

The absolute majority of codes designed by coding theorists are linear codes. In the rest of the course, (almost) all the codes we consider will be linear codes.

End of discussion.

Example: trivial, repetition codes

The trivial code Fqn is a linear code. (Indeed, Fqn is a vector subspace of itself.)

The repetition code Rep(n,Fq) over Fq is a linear code (exercise; will see soon).

To get non-trivial examples, we need to introduce more structure.

The weight

Definition: weight of a vector, weight of a code

The weight w(v) of a vector vFqn is the number of non-zero symbols in v.

The weight w(C) of a code CFqn is w(C)=min{w(v)vC{0}}.

Lemma 3.1: distance and weight

For any vectors v,yFqn, d(v,y)=w(vy).

  • Proof. Indeed, d(v,y) is the number of positions i, 1in, where viyi. Obviously, this is the same as the number of positions i where viyi0. By definition of the weight, this is w(vy), as claimed.

Recall that the minimum distance, d(C), of a code C is a very important parameter which tells us how many errors can the code detect and correct in a codeword. The following theorem shows how one can find d(C) if C is linear.

Theorem 3.2: minimum distance equals weight

d(C)=w(C) for a linear code C.

  • Proof. Take a codevector v such that w(C)=w(v). Observe, w(v)=w(v0)=d(v,0) but v0C so w(v)d(C). We proved that w(C)d(C).

    Now take a pair yzC such that d(y,z)=d(C). Rewrite this as w(yz). Since C is linear, yzC{0} so w(yz)w(C). We proved that d(C)w(C).

Remark: in the proof, we twice used that C is linear: first, 0C; second, y,zC implies yzC. This condition is essential.

Remark: given a linear code C, one needs to check only M1 vectors to compute d(C)=w(C). For a non-linear code, one has to check M(M1)/2 pairs of words to compute the minimum distance d.

Here is a non-trivial construction of a linear code.

Example: the zero sum code

For any finite field Fq and for any n1 we can define the zero sum code in Fqn as

Z={(v1,v2,,vn)Fqnv1+v2++vn=0 in Fq}.

We note that the zero sum code in Fqn is a linear code because Z is the set of solutions to the homogeneous linear equation v1++vn=0. It is known from linear algebra (and is easy to check directly) that the sum of two vectors satisfying this equation also satisfies this equation, and scaling a vector satisfying this equation again satisfies the equation. In other words, Z is a vector space.

Binary zero sum codes are very common and have a special name.

Example: The binary even weight code En

The binary even weight code of length n is defined as

En={vF2n:w(v) is even}.

Due to the rules of arithmetic in F2 we have

En={x1x2xn:xiF2, x1+x2++xn=0 in F2}

which shows that En is a particular case of a zero sum code, hence is a linear code.

Note: 0 is an even number! The binary even weight code contains the codeword 000.

Basic properties of the binary even weight code En

Minimum distance = weight: a vector with only one 1 has odd weight but a vector 11000 of weight 2 is in En. Hence d(En)=w(En)=2. The code detects up to 1 error and corrects up to 0 errors.

The number of codewords: in a codeword v=(x1,x2,,xn), the first n1 bits can be arbitrary (2n1 combinations), and the last bit is uniquely determined by xn=x1++xn1, where + is the addition is in the field F2. We thus have 2n1 codewords.

Another argument to that effect is as follows. We can take a binary word and flip (change) its first bit. This operation splits the set F2n into pairs of vectors, such that the vectors in a pair only differ in the first bit. Each pair contains one vector of even weight and one vector of odd weight. Therefore, the number of vectors of even weight is equal to the number of vectors of odd weight, and is 12#F2n=2n1.

Conclusion: En is an [n,n1,2]2-code.

Remark: A widely used code. If an error is detected, the recipient will request retransmission of the codeword where the error occurred. Error correction is not available.

The code generated by a matrix. A generator matrix of a linear code

We have an unlimited supply of linear codes, due to the following construction.

Definition: the linear code generated by a matrix

Let G be a k×n matrix with linearly independent rows r1,,rkFqn. The code

C={u1r1++ukrku1,,ukFq}Fqn

is said to be generated by the matrix G. In this case, the function

ENCODE:FqkC,ENCODE(u)=uGfor all uFqk

is the encoder for C given by the matrix G.

Proposition 3.3: properties of a code generated by a matrix

In the above definition, C is a linear code. The function ENCODE is a bijective linear map between Fqk and C. The information dimension of C is k and is equal to vector space dimension, dimC.

  • Proof. The definition says that C is the span of r1,,rk in the vector space Fqn. By linear algebra, a span is a subspace of Fqn hence a linear code.

    Matrix multiplication is linear in each argument so ENCODE(u)=uG is a linear function of u=(u1,,uk). As C consists of vectors of the form u1r1++ukrk=uG, the image of ENCODE is C so ENCODE is surjective. The kernel of ENCODE is made up of all (u1,,uk) such that u1r1++ukrk=0, but as r1,,rk are linearly independent, kerENCODE={0} and so ENCODE is injective, hence bijective.

    Hence M=#C=#Fqk=qk and so the information dimension of C is logq(M)=k.

    On the other hand, the vector space dimension of C is, by definition, the number of element in a basis of C. Note that the k-element set {r1,,rk} is a basis of C, as this is a linearly independent set which spans C. Hence dimC is also k.

In fact, all linear codes arise from the above construction. Indeed, we know from linear algebra that every vector space C has a basis. So every linear code is generated by a matrix:

Definition: generator matrix

Let CFqn be a linear code. A generator matrix of C is a matrix G=[r1r2rk], where the row vectors r1,,rk are a basis of C. (Clearly, C is generated by any of its generator matrices.)

Let us consider some simple matrices and work out the codes they generate.

Example: matrices that can generate a trivial code

The identity matrix In is a generator matrix for the trivial code, Fqn. Any other n×n matrix with linearly independent rows is also a generator matrix for the trivial code of length n.

Example: matrices that generate repetition codes

The repetition code Rep(n,Fq) has generator matrix G=[111], of size 1×n. The matrix λG for any λFq, λ0 is also a generator matrix for Rep(n,Fq).

Example: matrices that generate the binary even weight code E3

E3={000,011,101,110} has 4=22 codewords, so the dimension of this code is 2. Therefore, a generator matrix has 2 rows and 3 columns.

To write down a generator matrix, we need to take two linearly independent codevectors. We must not use the zero codevector, 000, because a linearly independent set must not contain the zero vector, but can use any two others. So, each of

G=[011101] or G=[011110] or G=[101011] etc.

is a generator matrix for E3.

Discussion: storing generator matrix instead of the whole code

Thus, to work with a linear code, it is enough to store just its generator matrix instead of storing all codevectors. This approach to linear codes has its practical advantages and disadvantages.

The single advantage which outweighs everything else is the amount of storage space required.

To visualise the difference between storing all the qk codewords of a linear code and storing only k rows of a generator matrix, consider a binary code of dimension about 1500 used in computer networking for error detection. We can store 1500 rows of a generator matrix, but it is absolutely impossible to store a list of all 21500 codewords. Indeed, the number 10100 (the googol) is believed to be bigger than the number of electrons in the visible Universe; but googol is less than 2340.

Disadvantages. A generator matrix is in general not unique, because a basis of a vector space C can be chosen in more than one way. It may not be obvious if two matrices generate the same code (although it is easy to test by bringing both matrices to reduced row echelon form and comparing the result).

If a linear code C is specified by a generator matrix G, it may be difficult to compute the weight w(C) of C. Of course, the weight of C does not exceed, but is in general not equal to, the minimum weight of a row of G. For some linear codes which have been used in practice, the weight is not known!

Generator matrices in standard form

For a linear code C, the encoder, ENCODE(u)=uG, depends on the choice of a generator matrix G. In practice, for many codes there is the best choice:

Definition: matrix in standard form

A matrix G is in standard form if its leftmost colums form an identity matrix:

G=[Ik|A]=[100010001].

Note that entries in the last nk columns, denoted , are arbitrary elements of Fq.

If G is in standard form, then, after encoding, the first k symbols of the codeword show the original message:

uFqkENCODE(u)=uG=u[Ik|A]=[u|uA]

(this is an easy example of multiplication of block matrices). This means that it is easy to unencode a codevector, simply by taking its first k symbols.

In this situation, the first k symbols of a codeword are called information symbols. The last nk symbols are called check symbols; their job is to protect the information from noise by increasing the Hamming distance between codewords.

Theorem 3.4: generator matrix in standard form

If a generator matrix in standard form exists for a linear code C, it is unique, and any generator matrix can be brought to the standard from by the following operations:

  • (R1) Permutation of rows.

  • (R2) Multiplication of a row by a non-zero scalar.

  • (R3) Adding a scalar multiple of one row to another row.

  • Proof. Not given — a standard fact from linear algebra (uniqueness of reduced row echelon form). We will do examples to show how to find the generator matrix in standard form.

Remark. If we apply a sequence of the row operations (R1), (R2) and (R3) to a generator matrix of a code C, we again obtain a generator matrix of C. This is implied in the Theorem, and follows from the fact that a basis of a vector space remains a basis under permutations, multiplication of an element of the basis by a scalar, and adding a scalar multiple of an element to another element. This fact is known from linear algebra.

Examples of finding a generator matrix in standard form, and some codes which have no generator matrix in standard form, are on example sheets. We consider one example here:

Example: bringing a generator matrix into standard form

The binary code C is generated by [01111101111101111110]. Find the generator matrix in standard form for C. Find the parameters of C. Identify the code C by its well-known name.

Solution: apply row operations [01111101111101111110] (r1r2) [10111011111101111110] (r3r3+r1, r4r4+r1) [10111011110110001001] (r2r4) [10111010010110001111] (r3r3+r2, r4r4+r2) [10111010010010100110] (r1r1+r4) [10001010010010100110] (r4r4+r3) [10001010010010100011].

The parameters of C are: length 5 (the number of columns of the generator matrix), dimension 4 (the number of rows of the generator matrix). From the generator matrix in standard form (its rows are also codevectors!) we can see that w(C)2. In fact, all the rows of the generator matrix are of even weight; hence they lie in the vector space E5. Hence all their linear combinations lie in E5. Since dimC=4=dimE5, we have C=E5 (the even weight code of length 5) and d(C)=w(C)=2.