Linear Codes: 3.1 Basics
Linear Codes: 3.1 Basics
Linear Codes
In order to define codes that we can encode and decode efficiently, we add more
structure to the codespace. We shall be mainly interested in linear codes. A
linear code of length n over the field F is a subspace of F n . Thus the words of linear code
the codespace F n are vectors, and we often refer to codewords as codevectors. codevectors
In the first section we develop the basics of linear codes, in particular we
introduce the crucial concept of the dual of a code. The second and third sections
then discuss the general principles behind encoding and decoding linear codes.
We encounter the important concept of a syndrome.
3.1 Basics
If C is a linear code that, as a vector space over the field F , has dimension k,
then we say that C is an [n, k] linear code over F , or an [n, k] code, for short. [n, k] linear code
There is no conflict with our definition of the dimension of C as a code, since
|C| = |F |k . (Indeed the choice of general terminology was motivated by the
special case of linear codes.) In particular the rate of an [n, k] linear code is
k/n. If C has minimum distance d, then C is an [n, k, d] linear code over F .
The number n k is again the redundancy of C. redundancy
We begin to use F2 in preference to {0, 1} to denote our binary alphabet,
since we wish to emphasize that the alphabet carries with it an arithmetic
structure. Similar remarks apply to ternary codes.
Examples. (i) The repetition code of length n over F is an [n, 1, n]
linear code.
(ii) The binary parity check code of length n is an [n, n 1, 2] linear
code.
(iii) The [7, 4], [8, 4], and [4, 2] Hamming codes of the introduction
were all defined by parity considerations or similar equations. We shall
see below that this forces them to be linear.
(iv) The real Reed-Solomon code of our example is a [27, 7, 21] linear
code over the real numbers R.
31
32 CHAPTER 3. LINEAR CODES
Forney (1966) proved a strong version of this theorem which says that we need
only consider those linear codes of length n with encoder/decoder complexity
on the order of n4 (but at the expense of using very long codes). Thus there
are Shannon families whose members have rate approaching capacity and are,
in a theoretical sense, practical1 .
Hamming weight The Hamming weight (for short, weight) of a vector v is the number of its
nonzero entries and is denoted wH (v). We have wH (x) = dH (x, 0). The mini-
minimum weight mum weight of the code C is the minimum nonzero weight among all codewords
of C,
wmin (C) = min (wH (x)) .
06=xC
dH (x, y) = dH (x y, y y) = dH (x y, 0) . 2
( 3.1.3 ) Problem. Prove that, for binary vectors x and y of the same length, we
have
wH (x + y) = wH (x) + wH (y) 2wH (x y)
where x y is defined to have a 1 only in those positions where both x and y have a 1.
3.1. BASICS 33
The matrix G is a spanning matrix for the linear code C provided C = spanning matrix
RS(G), the row space of G. A generator matrix of the [n, k] linear code C over generator matrix
F is a k n matrix G with C = RS(G). Thus a generator matrix is a spanning
matrix whose rows are linearly independent. We may easily construct many
codes using generator matrices. Of course it is not clear from the matrix how
good the code will be.
Examples. (i) The repetition code has generator matrix
h i
G = 1, 1, . . . , 1 .
(ii) A particularly nice generator matrix for the parity check code is
1 0 0 0 0 1
2 3
6 0
6 1 0 0 0 1 7 7
6 0 0 1 0 0 1 7
7 ,
6 7
6 .. .. ..
6
6 . . . 7
7
4 0 0 0 1 0 1 5
0 0 0 0 1 1
composed of all weight 2 codewords with a one in the last column. This
code will have many other generator matrices as well. Here are two for
the [7, 6] parity check code:
2 3 2 3
1 1 0 0 0 0 0 1 1 1 1 1 1 0
6
6 1 0 1 0 0 0 0 7 6
7 6 1 0 1 0 0 0 0 7
7
6
6 1 0 0 1 0 0 0 7 6
7 , 6 1 1 0 1 0 1 1 7
7 .
6
6 1 0 0 0 1 0 0 7 6
7 6 1 1 1 0 1 0 0 7
7
4 1 0 0 0 0 1 0 5 4 0 0 0 0 0 1 1 5
1 0 0 0 0 0 1 1 1 1 1 0 0 0
(iv) A generator matrix for the [8, 4] extended Hamming code of Ex-
ample 1.3.4 results from adding a column at the front to that for the [7, 4]
code, each new entry checking parity of that row in the matrix. We have
2 3
1 1 1 1 0 0 0 0
6 1 1 0 0 1 1 0 0 7
6 7
4 1 0 1 0 1 0 1 0 5
0 1 1 0 1 0 0 1
1 Oxymoron!
34 CHAPTER 3. LINEAR CODES
(v) For a generator matrix of the [4, 2] ternary Hamming code of Ex-
ample 1.3.5, we may set (a, b) equal to (1, 0) and (0, 1) in turn to get the
matrix
1 0 1 2
,
0 1 1 1
although any pair of codewords would do as rows provided one is not a
multiple of the other. For instance
0 1 1 1
1 1 2 0
( 3.1.4 ) Problem. Prove that, in a linear code over the field Fq , either all of the
codewords begin with 0 or exactly 1/q of the codewords begin with 0. (You might want
first to consider the binary case.)
( 3.1.6 ) Problem. Prove the Plotkin bound for a general m-ary code C of length n
and minimum distance d with d/n > (m 1)/m:
d
|C| m1 .
d m
n
( Hint: Find an upper bound on the average nonzero distance between codewords by
comparing all distinct pairs of codewords and examining each coordinate position in
turn.)
Let C be any code (not necessarily linear) in F n , for F a field. The dual
dual code code of C, denoted C , is the code
C = {x F n | x c = 0, for all c C} ,
where x c is the usual dot product. The dual of C is linear even if C is not.
(This is often a good way of proving that a given code is linear.) We can in
turn examine the dual of the dual and discover easily that (C ) = C C.
If C is itself a linear code, then in fact C = C. For instance, the dual of
the binary repetition code of length n is the parity check code of length n; and
the dual of the parity check code of length n is the repetition code of length n.
To see that C = C for linear C, we use another description of C . Let G
be a generator matrix for C. Then x is in C if and only if Gx> = 0. Thus
3.1. BASICS 35
the vectors of C are precisely the transposes of the vectors of the null space
NS(G). Therefore by Theorem A.1.7 the dimension of C plus the dimension of
C equals the length n, that is, C has dimension nk. Calculating dimensions
twice, we learn that C has dimension k. As this space contains C and has
the same dimension as C, it is equal to C. In summary:
( 3.1.9 ) Problem. Consider a binary code of length 21 whose words are written as
arrays in the following gem shape:
x1 x2 x3
x4 x5 x6 x7 x8
x9 x10 x11 x12 x13
x14 x15 x16 x17 x18
x19 x20 x21
The code E is composed of every binary array M of this shape and such that:
(i) every row of M contains an even number of 1s; and
(ii) every column of M contains an even number of 1s.
(a) Prove that E is a linear code.
(b) What is the dimension of E?
(c) What is the minimum distance of E?
(d) If the array
0 1 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 0
is received, give all possible decodings subject to MDD. That is, find all codewords in
E that are closest to this array.
(e) If the array
1 0 1
1 1 1 1 1
0 1 1 1 0
1 1 1 1 1
1 0 1
is received, give all possible decodings subject to MDD.
( 3.1.10 ) Problem. If C is a binary [n, k] linear code, prove that either all weights
of codewords of C are even or the even weight codewords of C form a linear [n, k 1]
subcode B. In the second case, how can the dual code of B be constructed from the
dual code of C?
( 3.1.11 ) Problem. (a) Let C be a self-orthogonal binary linear code. Prove that all
of its codewords have even weight. If additionally C has a spanning set composed of
codewords with weights a multiple of 4, prove that every codeword has weight a multiple
of 4.
(b) Prove that a linear ternary code is self-orthogonal if and only if all its weights
are a multiple of three.
be the check matrix of the e-error-correcting, binary [n, k] linear code D, the various
hj being the columns of H. Next let D0 be the binary [n, k] linear code with check
matrix h i
H 0 = h1 , h1 + h2 , h1 + h3 , . . . , h1 + hn .
Prove that D0 is also an e-error-correcting code.
We have seen in Problem 2.3.10 that this result is true even for nonlinear
codes. Indeed if we move k and d = dmin (C) to opposite sides and raise q = |F |
to the appropriate power, we are left with
|C| = q k q nd+1 .
The present proof of the bound shows that even more is true. Any set of
n k + 1 coordinate positions contains the support (the nonzero entries) of a
nonzero codeword.
( 3.1.15 ) Problem. Use a generator matrix in RREF to give another quick proof
of the Singleton bound for linear codes.
A linear code that meets the Singleton bound with equality is called maxi-
maximum distance separable mum distance separable or, for short, an M DS code. Every subset of n k + 1
M DS code coordinate positions supports a codeword in an M DS code. By convention
the zero code {0} is M DS, even though its minimum distance is somewhat
ill-defined.
The [4, 2] ternary Hamming code has minimum distance 3 and so is M DS
since 3 = 4 2 + 1. We shall meet many M DS codes later when we discuss the
generalized Reed-Solomon codes.
3.2. ENCODING AND INFORMATION 39
( 3.1.17 ) Problem. Prove that a binary M DS code of length n is one of {0}, the
repetition code, the parity check code, or all Fn
2.
0 0 0 1 1 1 1
Not every 4-subset of positions is an information set. The definition via
check equations guarantees that {4, 5, 6, 7} is not an information set, since
40 CHAPTER 3. LINEAR CODES
( 3.2.1 ) Problem. Let C be an [n, k] linear code over F , and let J be a subset of
k coordinate positions. For the generator matrix G we write GJ for the k k matrix
composed of those columns of G indexed by J. Similarly, for the codeword c, we write
cJ for the k-tuple of entries in the positions of J.
The following are equivalent:
(1) J is an information set;
(2) for each m F k , there is a unique c C with cJ = m;
(3) for every generator matrix G, the matrix GJ is invertible.
Two related codes may be different but still share many properties. For
instance, if the code D is gotten from C by reversing all codewords (i.e., first
entry last, . . . , last entry first) then C and D will likely be different but will have
many common propertiesthe same length, minimum distance, dimension, etc.
For many purposes we need not distinguish between C and D.
permutation equivalent Two codes C and D of length n over A are permutation equivalent if they
are the same up to a uniform permutation of their coordinate entries. (This is
equivalence often abbreviated to equivalence.) That is, there is a permutation of the set
{1, . . . , n} such that
Since every linear code has a systematic generator matrix, and a systematic
matrix can be changed into a standard matrix by permuting columns, we find
that every linear code is equivalent to a code with a standard generator matrix.
3.2. ENCODING AND INFORMATION 41
Although we do not need the definitions right now, this seems a good time
to give three further notions of equivalence for codes defined over fields. Notice
that linearity is not required for the various forms of equivalence. In practice
regular equivalence is the one of most relevance for codes that are not linear.
Definition. Two codes C and D of length n over the field F are diagonally
equivalent if they are the same up to the multiplication in each codeword of the diagonally equivalent
ith entry by the nonzero constant i , for each i.
Definition. Two codes C and D of length n over the field F are monomially
equivalent if they are the same up to: monomially equivalent
(1) a uniform permutation of their entries (as with regular equivalence);
(2) the multiplication in each codeword of the ith entry by the nonzero constant
i , for each i.
So monomial equivalence is the union of regular equivalence and diagonal equiv-
alence. For a linear code it corresponds to multiplying column i of a generator
matrix by the constant i in addition to permuting the columns of the generator.
Definition. Two codes C and D of length n over the field F are affine
equivalent if they are the same up to: affine equivalent
(1) a uniform permutation of their entries;
(2) the multiplication in each codeword of the ith entry by the nonzero constant
i , for each i;
(3) translation by a fixed vector of F n .
Two codes that are affine equivalent have the same size, length, and minimum
distance. Here if C is a linear code, then D is a coset of a code monomially
equivalent to C.
( 3.2.3 ) Problem. For k 6= 0, prove that the [n, k] linear code C is an M DS code if
and only if every subset of k coordinate positions is an information set.
where rj is the j-th entry of received r and Gj is the j-th column of the matrix G.
(a) Prove that setting x equal to m solves n e of the equations Eqnj . Prove that
m gets ne
`
k
votes.
(b) For any k-tuple l that is not equal to m, prove that setting `x equal to l solves
at most e + k 1 of the equations Eqnj . Prove that l gets at most e+k1k
votes.
(c) Prove that, as long as 2e < n k + 1 (= dmin (C)), the received vector r will be
decoded correctly to c.
( 3.2.5 ) Problem. Consider the M DS code C over the field F7 of integers modulo
7 with generator matrix
1 1 1 1 1 1
.
2 4 6 1 3 5
Use the method of the previous problem to decode the received vector
r = (1, 3, 6, 5, 4, 2) .
(0, 0, 0, 1, 1, 0, 1, 0) (0, 1, 0, 1, 1, 0, 1, 1) .
(a) Let x and y be binary n-tuples, and set f = x + y. Prove that x y if and only
if wH (y) = wH (x) + wH (f ).
(b) Let C be a binary linear code of length n. Prove that if y is a coset leader for the
coset y + C and x y, then x is also a coset leader for the coset x + C.
Our first method for coset leader decoding is standard array decoding. Set standard array decoding
K = |C|, the cardinality of C, and R = |F n |/|C|, the number of distinct cosets
of C. Enumerate the codewords:
C = { c1 = 0, c2 , . . . , cK }
The second method of coset leader decoding is syndrome decoding, where syndrome decoding
the dual code and check matrices are used. Let H be a check matrix for the
[n, k] linear code C. We have already mentioned that the vector x is in the
code C if and only if the matrix product Hx> equals 0. For any received vector
x, the length r = n k column vector Hx> is a measure of whether on not
syndrome the n-tuple x belongs to the code. The column r-tuple Hx> is the syndrome
of the n-tuple x. According to the Pocket Oxford Dictionary, a syndrome
is generally a characteristic combination of opinions. The syndrome voices
information about the error vector. Syndrome decoding is error oriented, using
the opinions voiced by the syndrome vector to identify the appropriate error
vector.
As the syndrome of a codeword is 0, two vectors x and e that differ by a
codeword c will have the same syndrome:
Example. Consider the [4, 2] ternary Hamming code with check matrix
1 1 2 0
H= .
0 1 1 1
1+2+2+0 2
Hx> = = .
0+2+1+1 1
syndrome coset
transpose leader
00 0000
01 0001
02 0002
10 1000
11 0100
12 0020
20 2000
21 0010
22 0200
It is not necessary to list out all cosets of the code to make this dictionary.
Instead notice that two words of F43 are in the same coset if and only if
their difference is a codeword. So, for instance, not only must (0, 0, 0, 1),
(0, 0, 0, 2), and (0, 2, 0, 0) all be of minimum weight in their respective
cosets; but they belong to different cosets. (Subtracting one of them from
another gives a word of weight less than 3, not a codeword since the
minimum weight of the Hamming code is 3.) The transposed syndromes
are then calculated as, respectively, (0, 1), (0, 2), and (2, 2); and the results
are recorded in the dictionary.
To decode our received vector x = (1, 2, 1, 1) we first calculate, as
before, its transposed syndrome (2, 1). We then look up this syndrome
in our dictionary and discover that the corresponding coset leader is b e=
(0, 0, 1, 0). We therefore assume that this is the error that occurred and
decode x to the codeword
c = xb
b e = (1, 2, 1, 1) (0, 0, 1, 0) = (1, 2, 0, 1) .
( 3.3.2 ) Problem. (a) Give a syndrome dictionary for the [8, 4] extended binary
Hamming code E with the following check matrix (and generator matrixthe code is
self dual): 2 3
0 0 0 0 1 1 1 1
6 0 0 1 1 0 0 1 1 7
XL3 = 6 4 0 1 0 1 0 1 0 1 5 .
7
1 1 1 1 1 1 1 1
(0, 0, 1, 0, 0, 1, 1, 0) .
(0, 1, 1, 1, 1, 1, 0, 1) .
hi x = hi p for i = 1, . . . , r
xj = 0 for j 6 L ()
x = c p = e.
Proof. This set of equations has at least one solution, namely the actual
erasure vector e = cp. If e0 is any solution of the equations () then c0 = ee0
has syndrome 0 and equals 0 off L. Therefore c0 is a codeword of weight at most
d 1 and so must be 0. We conclude that e = e0 , and the set of equations ()
has the unique solution x = e. 2