Part VI · Structures Chapter 42 of 60
Rings, fields and codes
How do you correct an error in a message when you can’t ask for it again? An engineer’s logbook: from triple repetition and Hamming’s three circles to Galois fields and the Reed–Solomon codes hidden in every QR code.
Builds on: 41 · Modular arithmetic and ciphers
You will learn
- encode and decode the Hamming (7, 4) code and understand why it corrects any single error
- tell a ring from a field and build finite fields like GF(4) from irreducible polynomials
- explain how Reed–Solomon codes recover a message from a polynomial and why they need a field
The last chapter ended with a question: what other systems of “numbers”, besides remainders modulo a prime, can do all four operations? The answer will come in handy in a problem that at first sight has nothing to do with algebra. Voyager 1 has flown more than twenty-five billion kilometres away. Its transmitter, of about twenty watts, sends a signal that takes almost a day to reach Earth and arrives so faint that it barely stands out from the noise. Some bits flip along the way: a zero was sent, a one was received. You can’t ask again: the answer would arrive two days later, and the probe has long since moved on to the next frame.
A CD player faces the same trouble when the beam hits a scratch, and so does a phone camera reading a QR code splashed with coffee. The receiver has to find the error itself and correct it itself. This chapter is an engineer’s logbook: we’ll build several prototype codes, from a naive one to the one that works in every QR code, and at every step we’ll run into one question: which arithmetic should the calculations be done in? The answer will be rings and fields.
A noisy channel
Let’s start with a simple model. A message is a sequence of bits, and the channel spoils each bit independently of the others with the same probability $p$: a zero turns into a one, or a one into a zero. With $p = 0.01$ a text of a thousand bits has on average ten spoiled. Not many, but if they’re the digits of a bank transfer or the coordinates of a frame, one is enough.
An error-correcting code is a rule for adding check symbols to a message so that the receiver can recover the original message even if some of the symbols were spoiled in transit. A message together with its check symbols is called a codeword.
Prototype one, the most naive: repeat each bit three times. Instead of $1$ we send $111$, instead of $0$, $000$. The receiver takes a majority vote: $101$ is read as $1$, $001$ as $0$. It can go wrong only if at least two bits out of three flip.
The price is three times as much transmission. Engineers measure it like this.
The rate of a code is the ratio of the number of message bits to the number of transmitted bits. For triple repetition it’s $\frac13$: two thirds of the channel are taken up by repeats.
Prototype two is the opposite extreme. To every eight bits add one, so that the number of ones becomes even: to $1011\,0010$ we add $0$, to $1011\,0011$ we add $1$. The rate is $\frac89$, almost lossless. If one bit flips along the way, the parity breaks, and the receiver sees that the byte is spoiled. But it doesn’t know which of the nine bits is to blame, and it won’t notice two errors in one byte at all: the parity comes back.
A parity bit is an extra bit that makes the number of ones in a block even. It notices any odd number of errors in the block, but doesn’t show where they are.
For a modem that can ask again, that’s enough; for Voyager it isn’t. Compare the prototypes on a picture that has to be transmitted.
Triple repetition is reliable but wasteful. Can errors be corrected more cheaply?
Hamming’s three circles
In the late 1940s Richard Hamming worked at Bell Labs and at weekends set problems for a relay computer. The machine checked itself with codes like parity and, on noticing an error, dropped the problem and moved on to the next. On Monday Hamming would find emptiness instead of an answer. By his own account, at some point he got angry: if the machine can detect an error, why can’t it find where it is and correct it? In 1950 he published codes that can do exactly that.
The best known of them is conveniently drawn with three overlapping circles. The circles divide the plane into seven regions, and we put a bit in each. The four message bits occupy the regions where circles overlap. The three check bits occupy the regions belonging to only one circle, and are chosen so that each circle contains an even number of ones.
Number the regions from $1$ to $7$ so that the binary expansion of the number says which circles the region lies in: the lowest digit is circle $A$, the middle one circle $B$, the highest circle $C$. Region $5 = 101_2$ lies in circles $A$ and $C$ but not $B$; region $7 = 111_2$ is in the centre, in all three. The check bits are in places $1$, $2$ and $4$, the message bits in places $3$, $5$, $6$ and $7$.
The Hamming code $(7, 4)$ turns $4$ message bits into a codeword of $7$ bits: the check bits in places $1$, $2$, $4$ are chosen so that each of the three circles has an even number of ones. Its rate is $\frac47$.
If at most one bit of a Hamming $(7, 4)$ codeword has flipped, the receiver uniquely finds the spoiled bit from the received word, and so recovers the message.
The idea: each bit lies in its own unique set of circles, and an error in it breaks the parity in exactly that set.
Circles are good for the eye, but for a computer the same thing is written as a matrix. Bits add like remainders modulo $2$: $1 + 1 = 0$, which is the “exclusive or” (XOR) operation. Checking a circle’s parity is the sum of its bits modulo $2$. Three checks are three rows of a matrix whose columns are the position numbers in binary.
Why does the column give the number? For a codeword $\mathbf c$ all the checks are even, $H\mathbf c = \mathbf 0$. If bit $j$ is spoiled, then $\mathbf r = \mathbf c + \mathbf e_j$, where $\mathbf e_j$ has a one only in place $j$, and $H\mathbf r = H\mathbf c + H\mathbf e_j = H\mathbf e_j$, which is the $j$th column. The syndrome doesn’t depend on the message, only on the error.
The syndrome of a received word $\mathbf r$ is the result of all the checks, $\mathbf s = H\mathbf r$. It’s zero on codewords and depends only on the error, so all the decoder needs is a “syndrome → error” table.
The word $1110101$ arrived (bits one to seven). It’s known that there’s at most one error. In which position is the error? If there’s none, answer $0$.
Row $C$ (bits $4$–$7$): $0 + 1 + 0 + 1 = 0$. Row $B$ (bits $2, 3, 6, 7$): $1 + 1 + 0 + 1 = 1$. Row $A$ (bits $1, 3, 5, 7$): $1 + 1 + 1 + 1 = 0$. The syndrome is $010_2 = 2$: the second bit, a check bit, is spoiled. The corrected word is $1010101$, and the message (bits $3, 5, 6, 7$) is $1101$.
How many errors a code can take
Why does the Hamming code correct one error, and triple repetition one out of three? And how do you build a code that corrects more? The answer comes from a geometry in which the distance between words is measured by the number of mismatches.
The Hamming distance between words of the same length is the number of positions in which they differ. Between $10110$ and $11100$ it’s $2$. The minimum distance of a code is the smallest distance between two different codewords.
Suppose any two different codewords differ in at least $d$ positions. Then the code detects any $d - 1$ errors in a word, and if a received word is replaced by the nearest codeword, it corrects any $t$ errors with $2t + 1 \le d$.
The idea: draw a “ball” round each codeword, all the words that can be reached by $t$ errors, and see that the balls don’t overlap. We’ll show it on triple repetition; in general the argument is the same.
The minimum distance of the Hamming code is $3$. The sum of two codewords modulo $2$ is again a codeword (parities add), and the number of ones in it is the distance between the originals. A word with a single one isn’t a codeword: any region lies in at least one circle and breaks its parity. A word with two ones in different regions isn’t a codeword either: the regions have different sets of circles, and there’s a circle containing exactly one of them. But $1110000$ is a codeword: circles $A$ and $B$ have two ones each, $C$ none. By the theorem the Hamming code corrects one error and detects two.
The balls of radius $1$ round the $16$ codewords of the Hamming $(7, 4)$ code cover all $2^7 = 128$ words of length $7$, and each word lies in exactly one ball.
A ball of radius $1$ round a word contains eight words: the word itself and the seven words differing from it in one position. There are $2^4 = 16$ codewords, one for each message, and by the theorem just proved their balls don’t overlap, since $2 \cdot 1 + 1 \le 3$. Together they hold $16 \cdot 8 = 128$ different words, exactly as many as there are words of length $7$. So no other words are left.
The Hamming code wastes not a single syndrome: the decoder understands each of the $128$ possible words unambiguously. Such codes are called perfect.
Hamming’s prototype is good against single errors. But a scratch on a disc destroys hundreds of bits in a row, and a single block of seven will contain many errors at once. The way out is to count not in bits but in bytes: if all eight bits of a byte are spoiled, it’s one error in a “letter” out of $256$ possible. For this we need an arithmetic over an alphabet of $256$ symbols in which, as in $\mathbb Z_2$, you can add, subtract, multiply and divide: all the linear algebra of codes rests on division. Remainders modulo $256$ won’t do: $2 \cdot 128 = 256 \equiv 0$, and you can’t divide by $2$. What arithmetics like that exist at all?
Where you can compute
Integers, remainders modulo $n$, polynomials, square matrices: all of them have addition and multiplication, and almost all the familiar rules hold. What they have in common is described by one definition.
A ring is a set with two operations, addition and multiplication, for which the ring axioms hold. A ring is commutative if $ab = ba$ for all $a$ and $b$.
For any elements $a$, $b$, $c$:
- under addition the elements form a commutative group (chapter 40): $a + b = b + a$, $(a + b) + c = a + (b + c)$, there’s a zero with $a + 0 = a$, and each $a$ has an opposite $-a$ with $a + (-a) = 0$;
- multiplication is associative: $(ab)c = a(bc)$;
- the distributive laws hold: $a(b + c) = ab + ac$ and $(a + b)c = ac + bc$;
- there’s a one: $1 \cdot a = a \cdot 1 = a$.
Some books don’t require the last axiom; all our rings have a one.
Examples of rings are $\mathbb Z$, $\mathbb Z_n$, and polynomials with real coefficients. $2 \times 2$ matrices form a ring too, but a non-commutative one: as we saw in the chapter on matrices, $AB$ and $BA$ usually differ. Division isn’t part of the definition. In $\mathbb Z$ you can’t divide $1$ by $2$, and in $\mathbb Z_6$ something happens that never happens with numbers: $2 \cdot 3 = 0$, although neither $2$ nor $3$ is zero.
A zero divisor is a non-zero element $a$ of a ring for which there’s a non-zero $b$ with $ab = 0$. In $\mathbb Z_6$ the zero divisors are $2$, $3$ and $4$ (since $4 \cdot 3 = 12 \equiv 0$).
Where there are zero divisors, familiar reasoning breaks down. From $ab = 0$ it no longer follows that one of the factors is zero, and so equations can’t be solved by factorising.
How many solutions does the equation $x^2 = 1$ have in $\mathbb Z_8$?
$1^2 = 1$, $3^2 = 9 \equiv 1$, $5^2 = 25 \equiv 1$, $7^2 = 49 \equiv 1$. An equation of degree two with four roots! Factorising $(x - 1)(x + 1) = 0$ doesn’t help: at $x = 3$ the factors are $2$ and $4$, both non-zero, and their product is $8 \equiv 0$. $\mathbb Z_8$ has zero divisors, and the rule “a product is zero only if a factor is zero” doesn’t work.
Systems in which you can divide by everything but zero have a name of their own.
A field is a commutative ring in which $1 \ne 0$ and every non-zero element $a$ has an inverse $a^{-1}$ with $aa^{-1} = 1$. In a field you can divide: $\frac ba = ba^{-1}$.
Fields include $\mathbb Q$, $\mathbb R$, $\mathbb C$ and, as we found out in the last chapter, $\mathbb Z_p$ for a prime $p$. The ring $\mathbb Z$ isn’t a field: $2$ has no integer inverse. In a field all of school algebra works: proportions, the quadratic formula (if square roots exist and $2 \ne 0$), Gaussian elimination for systems, interpolation. It all rests on division and on the following property.
If $ab = 0$ in a field, then $a = 0$ or $b = 0$.
Let $a \ne 0$. Then $a$ has an inverse; multiply the equation $ab = 0$ by $a^{-1}$: $b = 1 \cdot b = (a^{-1}a)b = a^{-1}(ab) = a^{-1} \cdot 0 = 0$. The last equation is a general rule of rings: $x \cdot 0 = x(0 + 0) = x \cdot 0 + x \cdot 0$, and subtracting $x \cdot 0$ from both sides gives $x \cdot 0 = 0$.
For $n \ge 2$ the ring $\mathbb Z_n$ is a field if and only if $n$ is prime.
If $n = p$ is prime, each non-zero $a$ from $1$ to $p - 1$ is coprime to $p$ and so invertible by the criterion from the last chapter. The other field axioms are inherited from the integers: congruences can be added and multiplied, so the laws of addition and multiplication of integers carry over to remainders.
If $n$ is composite, $n = ab$ with $1 < a, b < n$, then $a$ and $b$ are non-zero remainders, while $ab = n \equiv 0$. These are zero divisors, and a field has none, so $\mathbb Z_n$ isn’t a field.
Compute $\frac35$ in the field $\mathbb Z_7$, as a number from $0$ to $6$.
Dividing by $5$ means multiplying by $5^{-1}$. Since $5 \cdot 3 = 15 \equiv 1 \pmod 7$, $5^{-1} = 3$, and $\frac35 = 3 \cdot 3 = 9 \equiv 2$. Check: $5 \cdot 2 = 10 \equiv 3$.
A field of four elements
For bytes we need a field of $256$ elements, and $\mathbb Z_{256}$ isn’t a field. Let’s first try to build a field of four elements, where $\mathbb Z_4$ won’t do either: $2 \cdot 2 = 0$. The hint comes from numbers we already know how to build: $\mathbb C$ was obtained from $\mathbb R$ by adding a root of the equation $x^2 + 1 = 0$, which has no real roots (chapter 15). In the same way the square root of two can be added to $\mathbb Q$.
The set $\mathbb Q(\sqrt2) = \{a + b\sqrt2 : a, b \in \mathbb Q\}$ with the usual addition and multiplication is a field.
The idea: check that the four operations don’t take you out of the set; the other axioms hold because these are real numbers.
Sum and difference: $(a + b\sqrt2) \pm (c + d\sqrt2) = (a \pm c) + (b \pm d)\sqrt2$. Product: $(a + b\sqrt2)(c + d\sqrt2) = (ac + 2bd) + (ad + bc)\sqrt2$, because $\sqrt2 \cdot \sqrt2 = 2$. The coefficients are rational again.
The inverse. Let $a + b\sqrt2 \ne 0$. Multiply by the “conjugate” $a - b\sqrt2$: $(a + b\sqrt2)(a - b\sqrt2) = a^2 - 2b^2$. This is a rational number, and it isn’t zero: if $a^2 = 2b^2$ with $b \ne 0$, then $\left(\frac ab\right)^2 = 2$, but $\sqrt2$ is irrational; and if $b = 0$, then $a^2 - 2b^2 = a^2 \ne 0$. So $\frac{1}{a + b\sqrt2} = \frac{a}{a^2 - 2b^2} - \frac{b}{a^2 - 2b^2}\sqrt2$, again a number of the right form.
If a field $F$ is contained in a field $K$ and the operations in them are the same, $K$ is said to be a field extension of $F$. $\mathbb C$ is an extension of $\mathbb R$, and $\mathbb Q(\sqrt2)$ an extension of $\mathbb Q$ obtained by adding a root of the polynomial $x^2 - 2$.
Now the same thing in $\mathbb Z_2$. The polynomial $x^2 + x + 1$ has no roots there: at $x = 0$ it equals $1$, and at $x = 1$ also $1 + 1 + 1 = 3 \equiv 1$. Add an imaginary root $\alpha$ for which $\alpha^2 + \alpha + 1 = 0$, that is, $\alpha^2 = \alpha + 1$: in $\mathbb Z_2$ minus and plus are the same. The elements of the new field have the form $a + b\alpha$ with $a, b \in \{0, 1\}$; there are four of them: $0$, $1$, $\alpha$, $\alpha + 1$. They add coordinatewise, and multiply like polynomials, after which $\alpha^2$ is replaced by $\alpha + 1$.
| $\times$ | $0$ | $1$ | $\alpha$ | $\alpha + 1$ |
|---|---|---|---|---|
| $0$ | $0$ | $0$ | $0$ | $0$ |
| $1$ | $0$ | $1$ | $\alpha$ | $\alpha + 1$ |
| $\alpha$ | $0$ | $\alpha$ | $\alpha + 1$ | $1$ |
| $\alpha + 1$ | $0$ | $\alpha + 1$ | $1$ | $\alpha$ |
For example, $\alpha(\alpha + 1) = \alpha^2 + \alpha = (\alpha + 1) + \alpha = 1$, because $\alpha + \alpha = 2\alpha = 0$. So $\alpha$ and $\alpha + 1$ are inverses of each other, and $1$ is its own inverse: every non-zero element is invertible. There are no zeros outside the zero row and column. This is a field of four elements, and it’s built quite differently from $\mathbb Z_4$: in it $1 + 1 = 0$.
Will any polynomial do for this trick? No: if the polynomial factors, an imaginary root of one of the factors will produce zero divisors. We need polynomials that don’t factor.
A polynomial of degree at least $1$ with coefficients from a field $F$ is irreducible over $F$ if it can’t be written as a product of two polynomials of smaller degree with coefficients from $F$. Thus $x^2 + x + 1$ is irreducible over $\mathbb Z_2$: a polynomial of degree two that factors would have a root, and there are no roots. But $x^2 + 1 = (x + 1)^2$ is reducible over $\mathbb Z_2$.
Let $p$ be prime and $f$ a polynomial of degree $n$ irreducible over $\mathbb Z_p$. Then the polynomials of degree less than $n$ with coefficients from $\mathbb Z_p$, added in the usual way and multiplied with the remainder on division by $f$ taken afterwards, form a field of $p^n$ elements.
The idea: repeat for polynomials what we did for numbers in the last chapter. Remainders on division by $f$ behave like remainders modulo $n$, and the irreducible polynomial plays the role of a prime.
How many elements. A polynomial of degree less than $n$ is given by $n$ coefficients, each with $p$ options: $p^n$ in all.
The ring axioms. Division with remainder by $f$ works over $\mathbb Z_p$ just as over $\mathbb R$: at each step we divide by the leading coefficient of $f$, and in $\mathbb Z_p$ you can divide by a non-zero element. The remainder is unique. The lemma on remainders from the last chapter carries over word for word: if $g - g'$ and $h - h'$ are divisible by $f$, then so are $(g + h) - (g' + h')$ and $gh - g'h' = g(h - h') + (g - g')h'$. So the remainder of a sum and a product depends only on the remainders, and all the laws of operations on polynomials carry over to remainders.
The inverse. Let $g$ be a non-zero polynomial of degree less than $n$. A common divisor of $g$ and $f$ is a divisor of the irreducible $f$, that is, either a non-zero constant or $f$ times a constant; but $f$ can’t divide a non-zero $g$ of smaller degree. So the greatest common divisor is a constant, and it can be taken to be one. The Euclidean algorithm for polynomials (divide with remainder until the remainder is zero) and the backward pass give, as in Bézout’s identity, polynomials $u$ and $v$ with $ug + vf = 1$. The term $vf$ is divisible by $f$, so the remainder of $u$ on division by $f$ is the inverse of $g$.
A finite field is a field with finitely many elements. The field of $q$ elements is written $GF(q)$ (for Galois field) or $\mathbb F_q$. Thus $GF(p) = \mathbb Z_p$, and our field of four elements is $GF(4)$.
From the polynomial $x^3 + x + 1$, irreducible over $\mathbb Z_2$ (it has no roots, and a polynomial of degree three that factors has a factor of degree one), we get $GF(8)$. From $x^4 + x + 1$, $GF(16)$. Switch the table above to them: for any choice each non-zero row is a permutation of the non-zero elements.
The characteristic of a field is the smallest natural number $p$ for which the sum of $p$ ones, $1 + 1 + \dots + 1$, equals zero. If there’s no such $p$, as in $\mathbb Q$ and $\mathbb R$, the characteristic is taken to be zero. $\mathbb Z_p$ and $GF(4)$ have characteristics $p$ and $2$.
The number of elements of a finite field is a prime power $p^n$, where $p$ is the characteristic of the field.
The idea: inside any finite field sits $\mathbb Z_p$, and the whole field is a vector space over it.
The characteristic is a prime. The sums $1$, $1 + 1$, $1 + 1 + 1$, … can’t all be different, since there are finitely many elements. If the sum of $a$ ones equals the sum of $b$ ones with $a < b$, then the sum of $b - a$ ones is zero, so the characteristic $p$ exists. It’s greater than $1$, because $1 \ne 0$. If $p = ab$ with $1 < a, b < p$, then the sums of $a$ ones and of $b$ ones would be non-zero (by the choice of the smallest $p$), while their product, by the distributive law the sum of $ab$ ones, would be zero. A field has no zero divisors, so $p$ is prime.
$\mathbb Z_p$ sits inside. The sums $0, 1, 1 + 1, \dots$ of fewer than $p$ ones are distinct and add and multiply like remainders modulo $p$: it’s a copy of the field $\mathbb Z_p$.
The count. Elements of the field can be added and multiplied by elements of $\mathbb Z_p$, and all the vector space axioms hold, because they’re special cases of the field axioms. The space is finite, so it has a finite basis $e_1, \dots, e_n$ (add to the set elements not in the span of those already chosen, until the span is the whole field). Each element is written uniquely as $c_1e_1 + \dots + c_ne_n$ with $c_i \in \mathbb Z_p$, and there are $p^n$ such expressions.
Is there a field of $6$ elements?
The number of elements of a finite field is a prime power, and $6 = 2 \cdot 3$ isn’t a prime power. There are fields of $2, 3, 4, 5, 7, 8, 9$ elements, but none of $6$ or $10$.
The converse is true too: for every prime $p$ and natural number $n$ a field of $p^n$ elements exists. For small $n$ an irreducible polynomial is easy to find by trial, as we found $x^2 + x + 1$, and in general another route helps.
For any prime $p$ and natural number $n$ there’s a field of $p^n$ elements.
The proof: the roots of the polynomial $x^{p^n} - x$
The idea: build a field in which the polynomial $x^q - x$, where $q = p^n$, splits into factors of degree one, and see that its roots themselves form a field, and that there are exactly $q$ of them.
A root can always be added. Let $F$ be a field and $g$ a polynomial over it of degree at least $1$. Take an irreducible factor $h$ of $g$. As in the theorem on a field from polynomials modulo an irreducible one (its proof works over any field $F$), the remainders on division by $h$ form a field containing $F$. In it the remainder of the polynomial $x$ is a root of $h$, and so of $g$. Split off a factor of degree one from $g$ and repeat with the quotient. After finitely many steps we get a field $L \supset \mathbb Z_p$ in which $x^q - x$ splits into $q$ factors of degree one.
The roots form a field. In a field of characteristic $p$, $(a + b)^p = a^p + b^p$: by the binomial theorem the other terms contain the coefficients $\binom pk$ for $0 < k < p$, and these are divisible by $p$, since the numerator $p!$ has the factor $p$ and the denominator $k!(p - k)!$ doesn’t. Repeating $n$ times, we get $(a + b)^q = a^q + b^q$. So if $a^q = a$ and $b^q = b$, then also $(a + b)^q = a + b$, $(ab)^q = ab$, $(-a)^q = -a$ (for $p = 2$ this is the same as $a$, since $-1 = 1$), and $(a^{-1})^q = a^{-1}$. The roots of $x^q - x$ are closed under all four operations: they form a field.
There are exactly $q$ of them. Let $r$ be a root. Then $x^q - x = (x - r)^q + r^q - x = (x - r)^q - (x - r) = (x - r)\bigl((x - r)^{q-1} - 1\bigr)$. The second factor at $x = r$ equals $-1 \ne 0$, so $r$ is a simple root, not a multiple one. A polynomial of degree $q$ has split into $q$ factors of degree one, and all the roots are distinct: there are $q$ of them. That’s the field of $p^n$ elements.
The non-zero elements of a finite field form a group under multiplication, and it’s always cyclic: there’s an element $g$ whose powers run through all the non-zero elements. The proof repeats word for word the proof of the existence of a primitive root from the last chapter. Only three things were used there: that the order of an element divides the number of non-zero elements, that a polynomial of degree $d$ over a field has at most $d$ roots (we’ll prove this in the next section for any field), and a count with Euler’s function. In $GF(4)$ the generator is $\alpha$: $\alpha^1 = \alpha$, $\alpha^2 = \alpha + 1$, $\alpha^3 = 1$. That’s why in chips multiplication in a finite field is often done by adding exponents from a table of logarithms, just as people multiplied using Napier’s tables.
A code made of polynomials
Now we have a field in which a “letter” is a byte. How do we build a code from it? In 1960 Irving Reed and Gustave Solomon of MIT’s Lincoln Laboratory published a five-page paper, Polynomial Codes over Certain Finite Fields, with an idea we’ve already seen in the chapter on polynomials: a polynomial of degree less than $k$ is recovered uniquely from its values at any $k$ points.
Declare a message of $k$ symbols of the field to be the coefficients of a polynomial $f$ of degree less than $k$. Send not the coefficients but the values of $f$ at $n > k$ distinct points of the field. The extra $n - k$ values are a reserve: even if some of them get spoiled, the polynomial passing through most of the received points can be found.
Why two? It all rests on a theorem we proved for real polynomials in chapter 14. Over a field it holds just the same, while without a field it breaks: in $\mathbb Z_8$, as we saw, $x^2 - 1$ has four roots.
A non-zero polynomial of degree $d$ with coefficients from a field has at most $d$ distinct roots in that field.
Let’s repeat the proof from chapter 14 and note where the field is needed. Induction on $d$; a polynomial of degree $0$ is a non-zero constant and has no roots. Let $a$ be a root of a polynomial $P$ of degree $d$. Division with remainder by $x - a$ is possible over any field (we divide by the leading coefficient $1$), and the remainder is $P(a) = 0$, so $P(x) = (x - a)Q(x)$ with $Q$ of degree $d - 1$. If $b \ne a$ is another root, then $0 = P(b) = (b - a)Q(b)$. Here the field is needed: $b - a \ne 0$, there are no zero divisors, so $Q(b) = 0$. All the roots of $P$ except $a$ are roots of $Q$; by the inductive hypothesis there are at most $d - 1$ of them, and at most $d$ in all.
Two different codewords of the Reed–Solomon code with parameters $n$ and $k$ differ in at least $n - k + 1$ positions. So the code corrects any $t$ errors with $2t \le n - k$.
Let the codewords come from different polynomials $f$ and $g$ of degree less than $k$. Their difference $f - g$ is a non-zero polynomial of degree less than $k$, and by the previous theorem it has at most $k - 1$ roots. So $f$ and $g$ agree at no more than $k - 1$ points out of $n$, and differ at no fewer than $n - k + 1$. The minimum distance of the code is $d \ge n - k + 1$, and by the theorem on distance and errors the code corrects $t$ errors if $2t + 1 \le n - k + 1$, that is, $2t \le n - k$.
In our example $n = 7$, $k = 3$, and $2t \le 4$: two errors. You can’t squeeze out more: for any code turning $k$ symbols into $n$, the distance is at most $n - k + 1$ (this is called the Singleton bound), so Reed–Solomon codes spend their check symbols optimally.
The decoder in this picture works by brute force: it goes through triples of points, draws the polynomial through each by Lagrange’s formula, and looks for one that passes through at least five points. For $n = 7$ there are only $35$ triples, but for $n = 255$ brute force is hopeless. A fast decoding algorithm was found by Elwyn Berlekamp in 1968, and it’s what made Reed–Solomon codes practical. Note that Lagrange’s formula divides by the differences of the points $x_i - x_j$: here too you can’t do without a field.
It’s hard to list everywhere this code works. On compact discs (1982) two Reed–Solomon codes over $GF(256)$ are interleaved so that a scratch that destroys several thousand bits in a row turns into scattered errors in different codewords, and they’re all corrected. In a QR code you can choose the error-correction level: $L$, $M$, $Q$ or $H$ recover roughly $7$, $15$, $25$ or $30$ per cent of the codewords, which is why a stained or torn code can still be read. A Reed–Solomon code paired with a convolutional code protects the transmissions of the Voyagers, launched in 1977. It also works in DVDs, Blu-ray, digital television and RAID 6 disk arrays.
The CCSDS space communication standard uses a Reed–Solomon code over $GF(256)$ that turns $223$ message bytes into $255$ bytes. How many spoiled bytes in each block does it correct for certain?
$n = 255$, $k = 223$, and there are $n - k = 32$ check bytes. The condition $2t \le 32$ gives $t = 16$. If all eight bits of each of the sixteen spoiled bytes flipped, that’s $128$ bit errors in one block, and all of them are corrected.
Practise encoding and decoding the Hamming code: computing the check bits, finding the syndrome and correcting the error.
Where next
We built fields by adding roots: the square root of two to $\mathbb Q$, the imaginary unit to $\mathbb R$, a root of the polynomial $x^2 + x + 1$ to $\mathbb Z_2$. The quadratic formula also adds a root, a square one. Cardano’s formula for the cubic adds square and cube roots, Ferrari’s formula for the quartic a few more. But for an equation of degree five there’s no formula in radicals. Why is there no formula for the quintic? The answer was found by the same Galois whose name the finite fields bear: he studied the symmetries of the roots and the field extensions these roots generate. That’s the subject of the next chapter.