Overview
A classical error-correcting code adds structured redundancy to data so that a limited number of corrupted symbols can be detected or repaired. Almost all codes used in practice, and all the codes quantum error correction borrows, are linear: the set of codewords is a subspace of , and membership is tested by a set of linear parity checks. This page collects the definitions, the standard families and the bounds on code parameters. It is written for readers heading towards quantum codes, where a classical code reappears twice: its parity checks become stabilizer generators, and its dual decides whether those generators commute.
The probabilistic side of the subject, channels, capacity and the cost of decoding, is treated in Coding Theory. The field arithmetic behind the algebraic families is in Finite Fields and Coding Algebra.
Intuition
Spread the messages out. If any two codewords differ in at least positions, then changing fewer than positions of a codeword never produces another codeword, so the change is noticed; and changing fewer than positions leaves the word closer to the original codeword than to any other, so the change can be undone.
For a linear code this geometry becomes linear algebra. The receiver computes the syndrome of the received word, the vector of parity-check values. The syndrome is zero on codewords, so it depends only on the error, not on the message: it names the coset of the code in which the received word lies. Decoding is the choice of the most plausible error in that coset. Quantum error correction keeps this picture intact. A syndrome that reveals the error and nothing about the encoded data is what allows a quantum state to be corrected without being measured.
Two design philosophies run through the subject. Algebraic codes (Hamming, Reed–Solomon, BCH, Reed–Muller) have checks chosen so that the distance can be proved and decoding done by solving equations. Sparse-graph codes (LDPC) have checks that each touch few bits, chosen so that a simple iterative decoder works well on typical errors, with no attempt to maximise the distance.
Prerequisites
Linear algebra over a field: subspaces, rank, kernels, and the fact that these behave over as they do over , with the one exception that a nonzero vector can be orthogonal to itself. Reed–Solomon and BCH codes need finite fields beyond . The repetition code lesson is a gentle first example of a code, a syndrome and a decoder.
Mathematical Definitions
Let be the finite field with elements. For the Hamming weight is the number of nonzero coordinates of , and the Hamming distance is , the number of coordinates in which and differ.
A linear code of length and dimension over is a -dimensional subspace . Its elements are codewords, its rate is , and its minimum distance is
the two expressions agreeing because . Such a code is called an code; the subscript is dropped when .
- A generator matrix is a matrix whose rows form a basis of , so that .
- A parity-check matrix is a matrix with columns such that . It has rank ; it may have more than rows, the extra ones being redundant checks.
- The syndrome of a word is . It vanishes exactly on and is constant on each coset .
The two descriptions are related by . A code that is not required to be a subspace, with codewords and minimum distance , is written .
Equip with the bilinear form . The dual of a linear code is
If has dimension then is a linear code of dimension , and . A generator matrix of is a parity-check matrix of , and the other way round.
The form is not positive definite: over , , so every word of even weight is orthogonal to itself. A code and its dual can therefore intersect, and can even contain one another:
- is self-orthogonal (or weakly self-dual) if ;
- is dual-containing if ;
- is self-dual if , which forces .
is dual-containing exactly when is self-orthogonal. In terms of a parity-check matrix of , the code is dual-containing if and only if . The relation holds in every case, whether or not the two codes intersect.
Families
Let and . The binary Hamming code of order is the linear code , where is an matrix whose columns are the nonzero vectors of , each once. Different orderings of the columns give codes that differ by a permutation of coordinates.
Its parameters are . The distance is 3 because the columns of are nonzero and distinct, so no two are dependent, while any two columns sum to a third. A single error in position has syndrome equal to the -th column, which identifies . The code meets the Hamming bound with equality and is therefore perfect. It was introduced by Hamming.
For , with columns in the order of the binary numerals of ,
a code.
The dual of the Hamming code is the simplex code , generated by ; all its nonzero words have weight . For the simplex code is contained in the Hamming code, that is, the Hamming code is dual-containing: any two rows of , equal or not, have an even number of common ones. Adding an overall parity bit gives the extended Hamming code .
Let and . A Boolean polynomial in variables is an -linear combination of the monomials , ; its degree is the largest that occurs. The Reed–Muller code of order is
the set of truth tables of such polynomials, with coordinates indexed by the points of . It is a binary linear code with
The codes are nested, , and for the dual is
Special cases: is the repetition code, the even-weight code, the whole space, and the extended Hamming code . The code is the self-dual code.
The codes were introduced by Muller, with a decoding procedure by Reed; proofs of the parameters and of the duality are in Huffman and Pless. The nesting and duality relations make them a standard source of classical codes for CSS constructions, and the divisibility of their codeword weights by powers of two is what lies behind transversal non-Clifford gates in codes built from them (see logical gates).
Let be a finite field, let be distinct (so ) and let . The Reed–Solomon code with these evaluation points and dimension is
It is a linear code with parameters . A nonzero polynomial of degree less than has at most roots, so the evaluation map is injective (the dimension is ) and every nonzero codeword has at least nonzero coordinates; the Singleton bound shows the distance is no larger. The code is therefore maximum distance separable. The construction is due to Reed and Solomon.
Two special cases are common.
- All field elements, . Then the dual is again a Reed–Solomon code on the same points, , because for .
- All nonzero elements, , ordered as powers of a primitive element . The code is then cyclic, and is the BCH code over whose defining roots are .
The length is limited by the field size. Long binary codes are obtained from Reed–Solomon codes over by writing each symbol as bits, at the price of a guarantee on symbol errors rather than bit errors.
Let be a prime power and a positive integer coprime to . Let be the multiplicative order of modulo , so that contains a primitive -th root of unity . Fix integers and .
The BCH code over of length and designed distance is the cyclic code
Its generator polynomial is the least common multiple of the minimal polynomials over of . The code is narrow-sense if and primitive if .
By the BCH bound the minimum distance is at least ; it can be larger. Each minimal polynomial has degree at most , so the dimension is at least . For binary narrow-sense codes is a root whenever is, which improves this to for designed distance .
Examples: the binary primitive narrow-sense BCH code with is the Hamming code of length ; with and one obtains a code. For , , the minimal polynomials are linear and the BCH codes are the cyclic Reed–Solomon codes.
The binary codes were found by Bose and Ray-Chaudhuri and, independently, by Hocquenghem; see Huffman and Pless for the general theory and for algebraic decoding.
Let be an parity-check matrix of a binary linear code. Its Tanner graph is the bipartite graph with variable nodes (the columns, one per code bit), check nodes (the rows), and an edge between check and variable exactly when . A word is a codeword if and only if, at every check node, the bits on the neighbouring variable nodes sum to zero.
A family of codes with parity-check matrices of growing length is a low-density parity-check (LDPC) family if there is a constant , independent of , such that every row and every column of every has at most ones; equivalently, the Tanner graphs have bounded degree. The family is -regular if every variable node has degree and every check node degree . Counting edges gives , so the rate is at least the design rate , with equality when the rows of are independent.
Sparsity is a property of the matrix , not of the code: the same code has many parity-check matrices, most of them dense, and the performance of iterative decoders depends on which one is used. "LDPC" is meaningful only for a family, since any single matrix has bounded weights.
LDPC codes were introduced by Gallager together with iterative decoding; the graph description is due to Tanner. A modern account is Richardson and Urbanke. The quantum counterpart, where two sparse check matrices must also be orthogonal, is the subject of quantum LDPC codes.
BCH codes are cyclic codes: codes invariant under a cyclic shift of the coordinates, which are the ideals of a polynomial ring and are described on the finite-fields page.
Theorems
Let be an linear code with parity-check matrix .
- Syndromes label cosets. For a codeword and an error , . Two errors have the same syndrome if and only if .
- Distance from the check matrix. is the smallest number of columns of that are linearly dependent.
- Detection. Every nonzero error of weight at most has a nonzero syndrome, and some error of weight has syndrome zero.
- Correction. The errors of weight at most have pairwise distinct syndromes, and so can all be corrected, if and only if .
- Erasures. If at most coordinates of a codeword are erased, the codeword is determined by the remaining coordinates; some set of erased coordinates does not have this property.
- is a linear code with parity-check matrix and minimum distance .
- Errors are additive, , and an erasure is the loss of a coordinate whose position is known.
Proof · Proof that the minimum distance governs detection, correction and erasure recovery
1. The map is linear with kernel . Hence , and if and only if , that is, .
2. Write for the columns of . A word lies in exactly when , which is a linear dependence among the columns indexed by the support of . A nonzero codeword of weight therefore exhibits dependent columns, and a dependence among columns with all coefficients nonzero is a codeword of weight . The smallest such is on one side the minimum weight and on the other the smallest number of dependent columns.
3. An error has if and only if , and nonzero codewords have weight at least , with equality for some codeword.
4. Suppose and let have weight at most . Then , so and by item 1 the syndromes differ. A decoder that maps each syndrome to the unique error of weight at most producing it, and subtracts that error, recovers . Conversely, if , take a codeword of weight and split its support into a set of size and a set of size , both at most . Let agree with on the first set and vanish elsewhere, and put . Both have weight at most , they are distinct, and , so they share a syndrome and cannot both be corrected.
5. Let be the set of erased positions, . If two codewords agree outside , then is a codeword supported inside , of weight at most , hence zero. So the unerased coordinates determine the codeword. If is the support of a codeword of weight , then and agree outside and cannot be told apart.
The remaining results constrain which triples are possible. Two are upper bounds on the size of a code and one is a guarantee that good codes exist.
Equivalently . The bound is named after Singleton. A code attaining it is maximum distance separable (MDS): any coordinates of a codeword determine the rest. Reed–Solomon codes are MDS for every admissible length and dimension. Over the only MDS codes are the trivial ones: the repetition codes , the single-parity-check codes and the full space .
The bound does not depend on the alphabet size, which makes it weak for small and long codes; there the Hamming bound is stronger. Its quantum counterpart, the quantum Singleton bound, reads , with twice the redundancy.
- Any code over an alphabet of size with minimum distance ; linearity is not needed. Here , which is the dimension when is linear.
Proof · Proof of the Singleton bound
Let have minimum distance , with . Delete the last coordinates of every codeword; this defines a map . If then and can differ only in the deleted coordinates, so , which forces . Thus is injective and
With this is .
The same argument applied to any coordinates shows that in a code meeting the bound the projection onto every set of coordinates is a bijection, which is the "separable" property of MDS codes.
The sum counts the words within Hamming distance of a fixed word. For a binary linear code the bound reads : there must be at least as many syndromes as errors to be told apart. It goes back to Hamming.
A code meeting the bound with equality is perfect: every word lies within distance of exactly one codeword. The Hamming codes are perfect with , since .
Unlike its quantum analogue, the quantum Hamming bound, which in general is proved only for non-degenerate codes, this bound holds for every classical code.
- Any code over an alphabet of size with minimum distance ; linearity is not needed. For a linear code, .
Proof · Proof of the Hamming bound
For let . A word at distance exactly from is obtained by choosing positions and, in each, one of the other symbols, so
Let be codewords and suppose . The Hamming distance is a metric, so , contradicting the minimum distance. The balls around the codewords are therefore pairwise disjoint subsets of , and
Equality holds exactly when the balls cover .
The displayed form, for linear codes, is the refinement due to Varshamov of the counting argument of Gilbert; Gilbert's own version states that a code with at least codewords and distance exists. Both are treated in Huffman and Pless.
Asymptotic form. Let be the binary entropy. For every and every there are binary linear codes of arbitrarily large length with relative distance and rate
This follows from the finite bound and the estimate for .
Example. For , , the left side is , so a binary code with distance at least 5 exists. The bound is not tight here: the binary BCH code of length 15 and designed distance 5 has dimension 7.
The same counting idea, applied to isotropic subspaces instead of parity-check columns, gives the quantum Gilbert–Varshamov bound.
- is a prime power, , and .
- This is a sufficient condition for existence; codes with better parameters than it guarantees do exist.
Proof · Proof of the Gilbert–Varshamov bound for linear codes
Put . We construct column vectors such that every of them are linearly independent.
Take . Suppose have been chosen, , with every of them linearly independent. A vector is a forbidden choice for if it is a linear combination of at most of the chosen columns, since exactly then together with those columns would form a dependent set of at most columns. The number of linear combinations of exactly columns with nonzero coefficients is at most , so the number of forbidden vectors, including , is at most
Hence some vector of is not forbidden; choose it as . Every of are then linearly independent: a dependent set not containing is excluded by the induction hypothesis, and one containing it would express , or a dependence among earlier columns, through at most earlier columns.
After steps let be the matrix with columns and . No columns of are dependent, so by the characterisation of the minimum distance has distance at least . Its dimension is .
Between the Gilbert–Varshamov guarantee and the upper bounds lies a gap. For binary codes of relative distance the achievable rate is at least , and at most by the Hamming bound; sharper upper bounds are known, but the exact trade-off between rate and relative distance for long binary codes is not.
The identity is due to MacWilliams. For binary codes it reads .
Example. The Hamming code has . Substituting,
the weight enumerator of the simplex code: its seven nonzero words all have weight 4.
Uses. Because the coefficients of are counts, they are nonnegative; imposing this on a hypothetical weight distribution gives linear constraints that rule out codes, the basis of linear-programming bounds. Inequivalent codes can share a weight enumerator, so the identity relates weight distributions, not codes. Shor and Laflamme found an analogous pair of enumerators and identity for quantum codes.
- is a linear code and its dual for the form .
- , where is the number of codewords of weight .
Proof · Proof of the MacWilliams identity for binary codes
Let be linear.
Step 1: a sum over of signs. For ,
If every term is . Otherwise pick with ; the substitution permutes and multiplies the sum by , so the sum is zero.
Step 2: transform of the weight function. Fix numbers and let with , . For define . The sum factorises over coordinates:
Step 3: combine. Summing over the code and exchanging the order of summation,
by Step 1. The left side is by Step 2 and the right side is . Since this holds for all numbers , it is an identity of polynomials.
Worked Examples
The [7, 4, 3] Hamming code
Take the parity-check matrix displayed in the definition of the Hamming code. Its columns are the binary numerals of .
A codeword. satisfies all three checks: the first row of has zeros in positions 1 to 3, the second gives and the third .
Decoding. Suppose is received. Its syndrome is
the binary numeral of 6. The only single-bit error with this syndrome is a flip of bit 6, and flipping it back returns . The eight syndromes correspond to "no error" and the seven single-bit errors, which is the statement that the code is perfect: .
Two errors are miscorrected. If bits 6 and 7 are both flipped the syndrome is , the decoder flips bit 1, and the result is a codeword at distance 3 from . A distance-3 code used for correction cannot also detect double errors.
The dual and the weight enumerators. The rows of generate the simplex code. Each row has weight 4 and any two rows share two ones, so : the simplex code lies inside the Hamming code. Listing the 16 codewords of the Hamming code gives one of weight 0, seven of weight 3, seven of weight 4 and one of weight 7; the MacWilliams identity turns this distribution into "one word of weight 0, seven of weight 4" for the dual, as computed in the record above.
Why this matters for quantum codes. The containment is exactly the hypothesis of the CSS construction with the same code used for bit flips and phase flips; applied to this code it yields the Steane code.
Checking the bounds on small parameters
For a binary code with and : the Singleton bound gives , the Hamming bound gives , so , and the Gilbert–Varshamov condition holds for . Here all three agree with the truth, . For , the Gilbert–Varshamov bound guarantees while the BCH code achieves and the Hamming bound allows , since requires .
Algorithms and Implementations
Syndrome decoding. For short codes, store for each syndrome a lowest-weight error producing it (a coset leader) and subtract it. The table has entries, which limits the method to small redundancy.
Algebraic decoding. Reed–Solomon and BCH codes can be decoded up to half their designed distance in time polynomial in by solving a system of equations for the error positions; see Huffman and Pless.
Iterative decoding on the Tanner graph. For an LDPC code the decoder passes messages along the edges of the Tanner graph. On an erasure channel the rule is simple: a check all of whose neighbours but one are known determines the missing one; repeat until no such check remains. This succeeds unless the erased positions contain a nonempty set of variable nodes such that every check adjacent to the set has at least two neighbours in it (a stopping set), which is a property of the matrix and not only of the code. For channels with bit flips the messages are probabilities, updated by belief propagation; the computation is exact when the graph is a tree and a heuristic when it has cycles. Gallager introduced both the codes and the decoders, and Richardson and Urbanke give the modern analysis. The cost per iteration is proportional to the number of edges, hence linear in for an LDPC family.
Applications
- CSS codes. Two classical codes with give a quantum code whose parameters are read off from theirs (Calderbank and Shor, Steane); see CSS codes.
- Stabilizer codes. A general stabilizer code is a classical additive code over that is self-orthogonal for a suitable inner product.
- Quantum LDPC codes. Sparse classical parity-check matrices are the raw material of product constructions; see quantum LDPC codes.
- Decoders. Belief propagation and its variants are reused, with modifications, for quantum codes; see quantum decoders.
Computational Complexity
Encoding a linear code is a matrix multiplication. Decoding an arbitrary linear code to the nearest codeword, and even computing its minimum distance, are NP-hard; the precise statements are on the Coding Theory page. Every practical family obtains efficient decoding from structure: algebraic structure for Reed–Solomon and BCH codes, sparsity for LDPC codes.
Limitations and Common Pitfalls
- Distance is a worst-case figure. Minimum distance guarantees correction of every pattern of up to errors. On a random-error channel what matters is the probability of the patterns the decoder fails on, and codes of modest distance with good iterative decoders can outperform codes of large distance decoded only up to half the distance.
- A code has many parity-check matrices. The distance and the dual depend only on the code; the Tanner graph, the behaviour of iterative decoding and, for the quantum codes built from it, the weights of the stabilizer generators depend on the chosen matrix.
- Self-orthogonal does not mean zero. Over a nonzero code can lie inside its own dual. Intuition from real inner-product spaces, where , fails; only survives.
- Erasures and errors are different budgets. A distance- code repairs erasures but only errors at unknown positions. Quoting "corrects " without saying which is a common slip.
- Bounds are not constructions. The Gilbert–Varshamov bound asserts that good codes exist and says nothing about decoding them; codes meeting it are not automatically usable.
- The Singleton bound ignores the alphabet. It is attained only when the alphabet is large enough; for binary codes it is far from the truth.