Quantum Error Correction · Chapter 1

Classical Error Correction

Long before quantum computers, engineers had to solve a very similar problem: how do you send a message through a noisy channel and still trust what comes out the other end? This chapter builds the classical toolkit — parity checks, repetition codes, the Hamming code, and the general theory of linear codes — and introduces ideas like rate, minimum distance, and error syndromes that quantum error correction borrows directly.

≈ 20 min read6 worked examplesOriginal PDF ↗

Before going to Quantum Error Correction we will just take a step back and look at Classical Error Correction in order to understand in general the ideas of error correction.

1.1 Background and Motivation

We now talk about the communication system model. In Shannon's 1948 paper on “A Mathematical Theory of Communication” he introduced a schematic diagram for a general communication system as shown in the figure below. By communication system we will mean a system of the type indicated schematically in the figure. It consists of essentially five parts:

Block diagram of a general communication system: an information source feeds a transmitter, the signal crosses a channel disturbed by a noise source, and a receiver reconstructs the message for the destination.
Figure — Schematic diagram for a general communication system
  1. An information source which produces a message or a sequence of messages to be communicated to the receiving terminal. The message may be of various types: (a) A sequence of letters as in a telegraph or teletype system; (b) A single function of time \(f(t)\) as in radio or telephony; (c) A function of time and other variables as in black and white television — here the message may be thought of as a function \(f(x,y,t)\) of two space coordinates and time, the light intensity at point \((x,y)\) at time \(t\) on a pickup tube plate; (d) Two or more functions of time, say \(f(t), g(t), h(t)\) — this is the case in “three-dimensional” sound transmission or if the system is intended to service several individual channels in multiplex; (e) Several functions of several variables — in color television the message consists of three functions \(f(x,y,t), g(x,y,t), h(x,y,t)\) defined in a three-dimensional continuum — we may also think of these three functions as components of a vector field defined in the region — similarly, several black and white television sources would produce “messages” consisting of a number of functions of three variables; (f) Various combinations also occur, for example in television with an associated audio channel.
  2. A transmitter which operates on the message in some way to produce a signal suitable for transmission over the channel. In telephony this operation consists merely of changing sound pressure into a proportional electrical current. In telegraphy we have an encoding operation which produces a sequence of dots, dashes and spaces on the channel corresponding to the message. In a multiplex PCM system the different speech functions must be sampled, compressed, quantized and encoded, and finally interleaved properly to construct the signal. Vocoder systems, television and frequency modulation are other examples of complex operations applied to the message to obtain the signal.
  3. The channel is merely the medium used to transmit the signal from transmitter to receiver. It may be a pair of wires, a coaxial cable, a band of radio frequencies, a beam of light, etc.
  4. The receiver ordinarily performs the inverse operation of that done by the transmitter, reconstructing the message from the signal.
  5. The destination is the person (or thing) for whom the message is intended.

For analyzing, it is first necessary to represent the various elements involved as mathematical entities, suitably idealized from their physical counterparts. We may roughly classify communication systems into three main categories: discrete, continuous and mixed. By a discrete system we will mean one in which both the message and the signal are a sequence of discrete symbols. A typical case is telegraphy where the message is a sequence of letters and the signal a sequence of dots, dashes and spaces. A continuous system is one in which the message and signal are both treated as continuous functions, e.g., radio or television. A mixed system is one in which both discrete and continuous variables appear, e.g., PCM transmission of speech.

We consider only the discrete case. This case has applications not only in communication theory, but also in the theory of computing machines, the design of telephone exchanges and other fields.

This naturally leads to the field of Coding theory. Coding is the representation using symbols, often 0s and 1s. What are the requirements for information transmission:

  1. Cost of transmission should be low
  2. Information should be transmitted reliably in the presence of channel noise
  3. Information should be transmitted securely in the presence of an adversary/eavesdropper

The answer to each of these requirements is the following flavours of coding theory:

  1. Source Coding: Enables to compress the message to save on transmission.
  2. Channel Coding: Enables to send the message reliably by introducing some mechanism to counter channel noise.
  3. Secrecy Coding (aka Cryptography): Enables to encrypt the message to transmit it securely in the presence of an adversary.

Out of these three we will focus only on the first two parts i.e. Source Coding and Channel Coding, which lead to Classical Error Correction. These two are closely related to Information theory. We assume that the Channel Noise follows a model known to both Information Source and Destination. This noise may be deterministic or random; if random, it follows a probabilistic model. The effect of noise is to introduce errors in the transmitted message and thus, the goal of channel coding is to reduce or eliminate the effects of channel noise.

Say Alice wishes to communicate with Bob a message made up of discrete symbols (0s and 1s). We will then use Source and Channel Coding to transmit the message. For the purpose of these notes, we ignore Secrecy Coding aka Cryptography as Quantum Cryptography is in itself an entire field. We ignore the requirement of information to be transmitted securely in the presence of an adversary/eavesdropper. We wish to transmit the information at low cost and reliably in the presence of channel noise, which can be achieved through Source Coding and Channel Coding. There are three types of channel codes:

  1. Error-Detecting Codes: Allows Bob to detect errors in the received message, which is useful in random noise situations.
  2. Error-Correcting Codes: Allows Bob to correct errors in the received message, which is useful in random noise situations.
  3. Constrained Codes: Alice encodes the message in such a way as to prevent errors from corrupting the message, which is useful in deterministic noise situations.
Important

All coding schemes work by adding redundancy to the message to compensate for errors i.e. more symbols are transmitted than are in the original message.

In plain terms: you can never make noise disappear, but you can outvote it. Every code in this chapter — and every quantum code later — works by sending extra, carefully structured symbols so that even if the channel corrupts a few of them, the receiver can still figure out what was meant.

1.2 Error-Detecting Code

Consider the following Error-Detecting Code

Encoder appending a parity bit to a 7-bit message so that the transmitted 8-bit codeword has an even number of ones.
Figure — A simple Error-Detecting Code

We wish to encode a message made up of a 7-bit binary sequence \((b_1,b_2,b_3,b_4,b_5,b_6,b_7)\). As shown in the figure above, the encoder adds an 8th bit, called a parity bit, \(b_8\), so that \((b_1,b_2,\ldots,b_8)\) contains an even number of 1s. Thus, the encoder encodes the \(7\)-bit message to an \(8\)-bit message by adding a parity bit which is \(1\) if there are an odd number of \(1\)s in the \(7\)-bit message and \(0\) if there are an even number of \(1\)s in the message. Mathematically, we can write the following

\[ \sum_{i=1}^{8} b_i = 0\ (\text{mod }2) \]

Note that the addition is done in modulo \(2\). The channel noise model here is assumed to randomly flip bits from \(0\rightarrow 1\) and \(1\rightarrow 0\). We now define Rate.

Definition — Rate

The number of message bits per coded bits.

For example, here the rate is \(7/8\) because we have \(7\) message bits and the codeword after encoding is of \(8\) bits. Now consider the following example for a simple error-detecting code:

Worked example of the parity-check code: a codeword is sent, the channel flips a bit, and the receiver's parity check reveals that an error occurred.
Figure — Error Detecting Code example

We define the decoder as follows

\[ c = \begin{cases} y, & \text{if } y \text{ has even parity}\\ \text{ERROR}, & \text{if } y \text{ has odd parity} \end{cases} \]

We now define an error to occur when the received message is not the same as the intended message. In this case we assume the channel model that random bit flips of \(0\) to \(1\) or \(1\) to \(0\) may occur. Now there are various errors that can occur. Note that this code detects an odd number of errors. That is, if an odd number of \(0\)s change to \(1\)s or an odd number of \(1\)s change to \(0\)s. The code can detect that an error has occurred but it cannot detect where the error has occurred. Also, it cannot detect an error in cases such as when a \(0\) flips to \(1\) and a \(1\) flips to \(0\), maintaining the parity but changing the message. In this case, it cannot detect an error. Only in the cases when the parity changes to odd can it detect an error. In all other errors, when the parity remains even it assumes that the codeword is correct (even though there could be cases where the flips occur in such a way that the parity did not change but the message did. For example, in the above case when the codeword \(10110001\) changes to \(10101001\), note that the parity is still even but clearly the message has changed). Thus, the decoder designed above can detect an error only when \(y\) has odd parity; in all other cases, it assumes that no error has occurred. When the decoder detects an error, it sends a message to the encoder to resend the message.

A single parity bit is the cheapest possible alarm system: it rings whenever an odd number of bits flipped. It can't tell you which bit flipped, and it stays silent if two flips cancel out in the parity count. That's why it only detects errors — the fix is simply "please send that again".

These kinds of error-detecting codes have applications in computer network communication protocols and International Standard Book Numbers (ISBN). Network protocols such as TCP/IP use error-detecting codes extensively to determine if data packets sent across a network have been corrupted or not. The usual remedy for receipt of a corrupted data packet is to request retransmission. ISBN-10 numbers have 10 digits and are of the form x-xxx-xxxxx-x. The first nine digits in an ISBN record information about the book: country, publisher, title, and edition. The tenth digit is a check digit.

Memoryless Binary symmetric channels

Say Alice wants to send a \(k\)-bit message to Bob. The message is to be transmitted across a memoryless Binary Symmetric Channel. Each bit transmitted across the channel gets flipped with probability \(p\), independently of other bits. Say \(k=10000\) and \(p=0.001\). Say the transmission is uncoded, thus the rate \(=1\). The probability that the entire \(k\)-bit message is recovered by Bob:

\[ P_C=(1-p)^k=0.000045 \]

for \(k=10000\) and \(p=0.001\).

For an example of a situation in which the chances of making an error can be decreased using a repetition code, suppose that our goal is to communicate a single bit to a hypothetical receiver, and we're able to transmit bits through a so-called binary symmetric channel, which flips each bit sent through it independently with some probability \(p\). That is, with probability \(1-p\) the receiver gets whatever bit was sent through the channel, but with probability \(p\) the bit flips and the receiver gets the opposite bit value.

Classical repetition codes

We'll begin the lesson with classical repetition codes, which form the basis for the 9-qubit Shor code.

Encoding and Decoding

Repetition codes are extremely basic examples of error-correcting codes. The idea is that we can protect bits against error by simply repeating each bit some fixed number of times. In particular, let's first consider the \(3\)-bit repetition code. Here we encode one bit into three by repeating the bit three times, so \(0\) is encoded as \(000\) and \(1\) is encoded as \(111\).

If nothing goes wrong we can obviously distinguish the two possibilities for the original bit from their encodings. The point is that if there was an error and one of the three bits flipped, meaning that a \(0\) changes into a \(1\) or a \(1\) changes to \(0\), then we can still figure out what the original bit was by determining which one of the two binary values appears twice. Equivalently, we can decode by computing the majority value (i.e., the binary value that appears most frequently)

\[ abc \rightarrow \text{majority}(a,b,c) \]

Of course, if \(2\) or \(3\) bits of the encoding flip, then the decoding won't work properly and the wrong bit will be recovered, but if at most \(1\) of the \(3\) bits flips, the decoding will be correct. Thus, this code can correct single errors and the rate is \(\frac{1}{3}\). This is a typical property of error-correcting codes: they may allow for the correction of errors, but only if there aren't too many of them.

So, if we choose not to use the \(3\)-bit repetition code, and simply send whatever bit we have in mind through the channel, the receiver therefore receives the wrong bit with probability \(p\). On the other hand, if we first encode the bit we want to send using the \(3\)-bit repetition code, and then send each of the three bits of the encoding through the channel, then each of them flips independently with probability \(p\). The chances of a bit-flip are now greater because there are now three bits that might flip rather than one — but if at most one bit flips then the receiver will decode correctly. So, an error persists after decoding only if two or more of the bits flip during transmission.

The probability that two bits flip during the transmission is \(3p^2(1-p)\), which is \(p^2(1-p)\) for each of the three choices for the bit that doesn't flip, while the probability that all three bits flip is \(p^3\). The total probability of two or three bit flips is therefore

\[ 1-P_{b,C}=3p^2(1-p) + p^3 = 3p^2-2p^3 \]

Thus, the probability that an entire \(k\)-bit message is decoded correctly is

\[ P_C=(P_{b,C})^k\approx 0.97 \]

for \(k=10000\) and \(p=0.001\). Note that \(30000\) coded bits are actually transmitted since the rate is \(\frac{1}{3}\).

Compare the two numbers: sending the 10000-bit message raw succeeds with probability 0.000045 — essentially never — while tripling every bit lifts that to about 97%. The price is bandwidth: you now send 30000 bits. Error correction is always this trade: reliability bought with redundancy.

For values of \(p\) smaller than one-half this results in a decrease in the probability that the receiver ends up with the wrong bit. There will still be a chance of an error in this case, but the code decreases the likelihood. (For values of \(p\) greater than one-half, on the other hand, the code actually increases the likelihood that the receiver gets the wrong bit.) See the figure below.

Graph of decoded error probability versus channel flip probability p, showing the 3-bit repetition code curve dipping below the uncoded straight line for p less than one half.
Figure — Error probability vs p

1.3 Error-Correcting Code

The Length-7 Hamming Code

This code was discovered by Richard Hamming in 1950. It encodes a \(4\)-bit message into a \(7\)-bit codeword:

\[ u_1u_2u_3u_4\rightarrow u_1u_2u_3u_4p_1p_2p_3 \]

where \(u_i\), \(i=1,2,3,4\) are information bits and \(p_i\), \(i=1,2,3\) are parity bits. Thus, the rate for the code is \(\frac{4}{7}\). Consider the figure below. For each choice of \((u_1,u_2,u_3,u_4)\), there is a unique choice of \((p_1,p_2,p_3)\) that makes each circle have an even number of \(1\)s.

Venn diagram of three overlapping circles: the four information bits sit in the intersection regions and each circle gets one parity bit so that every circle contains an even number of ones.
Figure — Length-7 Hamming Code

This can be written as follows in the form of equations:

\[ \begin{aligned} u_1+u_2+u_4+p_1 &\equiv 0 \quad \text{(mod 2)}\\ u_1+u_3+u_4+p_2 &\equiv 0 \quad \text{(mod 2)}\\ u_2+u_3+u_4+p_3 &\equiv 0 \quad \text{(mod 2)} \end{aligned} \]

For example, if the information bits are \(u_1=1, u_2=0, u_3=0, u_4=0\) then the codeword in the Hamming code will be \(1000110\) where \(p_1=1, p_2=1, p_3=0\).

Now, consider the following decoder for the Hamming code. Let Alice send information \((u_1,u_2,u_3,u_4)\) which gets encoded to \((u_1,u_2,u_3,u_4,p_1,p_2,p_3)\) in the encoder. Thus, the codeword is \((u_1,u_2,u_3,u_4,p_1,p_2,p_3)\). We assume the channel noise model that flips bits at random \((0\rightarrow 1,\ 1\rightarrow 0)\). Suppose that Alice sends \(1000110\), but Bob receives \(1100110\). Note that the second bit is flipped from \(0\) to \(1\). In order to decode we follow the following procedure. Consider the figure below. We use the following rules to decode. Thus, the decoder (Bob) uses the following decoding model:

  1. Identify circles with wrong parity.
  2. Flip the bit common to those circles only.
Venn diagram decoding example: two of the three circles have odd parity, and the bit lying only in those two circles is flipped back to restore even parity everywhere.
Figure — 7-bit Hamming Code Example

We can clearly see that the blue and green circles are the ones with wrong parity and thus, the bit common only to these two circles is as shown in the figure above. Thus, we flip that \(1\) to \(0\) and we now have all the circles satisfying the parity. Hence, we have corrected the code and recovered the original message. Like in the case of \(3\)-bit repetition codes based on majority, we can only correct single errors. If there are errors in more than one bit then they cannot be corrected. But there is an interesting case: consider the case when there are errors in two bits. In that case, we may not be able to correct the errors but we can still detect errors and thus can request retransmission. In the case when the errors are in more than \(2\) bits we may not be able to either detect or correct an error that has occurred.

The pattern of "which parity checks failed" is doing all the work here: each of the seven bit positions trips a different combination of circles, so the failure pattern points straight at the flipped bit. This pattern is exactly what will later be called a syndrome, and syndrome-based correction is the beating heart of quantum error correction too.

Now consider we wish to transmit a \(k\)-bit message: we first divide the message into \(4\)-bit blocks, encode using a \(7\)-bit codeword, and transmit. Thus, \(k/4\) codewords i.e. \(7k/4\) coded bits are transmitted. Recall that we can correct one-bit errors. Thus, the probability that the codeword is transmitted correctly or with at most one bit error is

\[ \Pr[\text{at most one of the 7 bits is flipped}]=(1-p)^7 + 7p(1-p)^6 \]

Hence, the probability that the entire \(k\)-bit message is recovered correctly by Bob is

\[ P_C=[(1-p)^7+7p(1-p)^6]^{k/4}\approx 0.95 \]

for \(k=10000\) and \(p=0.001\) where we transmitted \(7k/4=7\times 10000/4=17500\) coded bits.

Important — Shannon's Noisy Channel Coding Theorem

We assume the channel model to be a memoryless binary symmetric channel with crossover probability \(p\). Then the Channel Capacity of the Binary Symmetric Channel is given as:

\[ C(p)=1+p\log_2 p+(1-p)\log_2(1-p) \]
Theorem

If rate \(R \lt C(p)\) and \(k\) is sufficiently large, there exists a code which can encode \(k\) message bits into \(n=k/R\) coded bits to be transmitted across the channel, such that a decoder at the channel output can recover all \(k\) message bits correctly with probability close to \(1\).

Note that \(C(0.001)\approx 0.9886\). This means that to ensure that a \(10000\)-bit message can be recovered correctly with probability close to \(1\), it should be enough to transmit about \(10000/0.9886 \approx 10150\) coded bits.

Shannon's theorem is a stunning promise: the repetition code needed 30000 bits and the Hamming scheme 17500, but in principle a mere ~10150 bits suffice to send 10000 bits almost perfectly through this noisy channel. The catch is that Shannon's proof doesn't hand you the code — finding practical codes that approach this limit took another half-century of work.

The goal of coding theory is to design coding schemes that can approach Shannon's performance guarantees, while still being relatively easy to implement in practice. We are interested in low complexity, and good error-correction capability.

1.4 Linear Codes

Let \(\mathbb{F}_q\) denote a finite field of size \(q\). For concreteness, take \(q=2\), i.e. \(\mathbb{F}_2\) is the binary field \(\{0,1\}\) with modulo-2 arithmetic. We will denote \(\mathbb{F}_q^n = \{(x_1,x_2,\ldots,x_n): x_i \in \mathbb{F}_q\}\). Clearly, the number of elements, \(|\mathbb{F}_q^n|=|\mathbb{F}_q|^n =q^n\).

Definition — Linear Code

A linear code \(\mathcal{C}\) of block length \(n\) over \(\mathbb{F}_q\) is a linear subspace of \(\mathbb{F}_q^n\). For each pair \(\mathbf{c_1},\mathbf{c_2}\in \mathcal{C}\) and for any \(\alpha_1,\alpha_2 \in \mathbb{F}_q\), we also have \(\alpha_1\mathbf{c_1}+\alpha_2\mathbf{c_2}\in\mathcal{C}\).

The dimension of a code \(\mathcal{C}\) is the dimension of \(\mathcal{C}\) as a linear subspace of \(\mathbb{F}_q^n\) over \(\mathbb{F}_q\); denoted by \(\dim(\mathcal{C})\) or \(\dim_{\mathbb{F}_q}(\mathcal{C})\).

An \([n,k]\) linear code is a linear code of blocklength \(n\) and dimension \(k\).

Proposition

An \([n,k]\) linear code \(\mathcal{C}\) over \(\mathbb{F}_q\) has \(q^k\) codewords.

Proof

Each codeword of an \([n,k]\) linear code \(\mathcal{C}\) can be uniquely expressed as a linear combination

\[ \mathbf{c}=\alpha_1\mathbf{c_1}+\alpha_2\mathbf{c_2}+\ldots+\alpha_k\mathbf{c_k} \]

with \(\alpha_j\in\mathbb{F}_q\ \forall j\). Thus, there is a \(1\)–\(1\) correspondence between codewords \(\mathbf{c}\in\mathcal{C}\) and \(k\)-tuples of coefficients \((\alpha_1,\ldots,\alpha_k)\in\mathbb{F}_q^k\). Hence \(|\mathcal{C}|=|\mathbb{F}_q^k|=q^k\). ∎

The rate of an \([n,k]\) linear code over \(\mathbb{F}_q\) is

\[ R=\frac{k}{n} \]
Worked Example

The repetition code over \(\mathbb{F}_2:\{00\ldots0,11\ldots1\}\). This is a linear code over \(\mathbb{F}_2\) with block length \(n\) and dimension \(1\). In other words, this is an \([n,1]\) binary linear code.

Worked Example

The single parity-check code over \(\mathbb{F}_2\):

\[ \mathcal{C}=\{x_1x_2\ldots x_n: x_1+x_2+\ldots+x_n\equiv 0 \text{ (mod 2)}\}=\operatorname{nullspace}(H) \]

where \(H=\begin{bmatrix} 1 &1 & \ldots & 1 \end{bmatrix}\). By the rank-nullity theorem,

\[ \dim(\mathcal{C})=n-\operatorname{rank}(H)=n-1 \]

Thus, \(\mathcal{C}\) is an \([n,n-1]\) binary linear code.

Worked Example — The Length-7 Hamming code

Recall that a binary word \(x_1,x_2,\ldots,x_7\) is in the Hamming code iff

\[ \begin{aligned} x_1+x_2+x_4+x_5 &\equiv 0\quad \text{(mod 2)}\\ x_1+x_3+x_4+x_6 &\equiv 0\quad \text{(mod 2)}\\ x_2+x_3+x_4+x_7 &\equiv 0\quad \text{(mod 2)} \end{aligned} \]

rewriting these equations in matrix form (over \(\mathbb{F}_2\)) as

\[ \begin{bmatrix} 1 &1 & 0 & 1 & 1 & 0 & 0 \\ 1 & 0 & 1 & 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\x_6 \\ x_7 \end{bmatrix} =\begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} \]

The binary word \(x_1x_2x_3x_4x_5x_6x_7\) is in the Hamming code \(\mathcal{C}\) iff the above equations are satisfied.

In other words, the Hamming code \(\mathcal{C}\) is equal to \(\operatorname{nullspace}_{\mathbb{F}_2}(H)\). Consequently, by the rank-nullity theorem, \(\dim(\mathcal{C})=n-\operatorname{rank}_{\mathbb{F}_2}(H)=7-3=4\). Thus, \(\mathcal{C}\) is a \([7,4]\) linear code.

A linear code is just a subspace: pick a parity-check matrix \(H\), and the codewords are exactly the vectors that \(H\) sends to zero. That one idea replaces listing \(q^k\) codewords with storing a small matrix, and it means all the machinery of linear algebra — rank, nullspace, dimension — becomes coding-theory machinery for free.

Minimum Distance

Let \(\mathbf{c}=(c_1,c_2,\ldots,c_n)\) and \(\mathbf{c'}=(c_1',c_2',\ldots,c_n')\) be words in \(\mathbb{F}^n\).

Definition — Hamming Distance

The Hamming distance between \(\mathbf{c}\) and \(\mathbf{c'}\) is defined to be

\[ d(\mathbf{c},\mathbf{c'})=|\{i:c_i\neq c_i'\}| \]
Definition — Hamming Weight

The Hamming weight of \(\mathbf{c}\) is defined to be

\[ w(\mathbf{c})=d(\mathbf{c},\mathbf{0})=|\{i:c_i\neq 0\}| \]
Definition — Minimum Distance

The minimum distance of a linear code \(\mathcal{C}\) is

\[ d_{min}(\mathcal{C})=\min_{\mathbf{c},\mathbf{c'}\in\mathcal{C}:\mathbf{c}\neq \mathbf{c'}} d(\mathbf{c},\mathbf{c'})=\min_{\mathbf{c}\in\mathcal{C}:\mathbf{c}\neq \mathbf{0}}w(\mathbf{c}) \]

An \([n,k,d]\) linear code is an \([n,k]\) linear code with minimum distance \(d\).

Minimum distance measures how far apart the two closest codewords are — how many symbols you'd have to corrupt to turn one legal codeword into another. The bigger this gap, the more noise a code can absorb before two messages become confusable. For linear codes there's a shortcut: the distance equals the smallest weight of any nonzero codeword.
Worked Example

The repetition code over \(\mathbb{F}_2 :\{00\ldots0,11\ldots1\}\) is an \([n,1,n]\) binary linear code.

Worked Example

The single parity-check code over \(\mathbb{F}_2\):

\[ \mathcal{C}=\{x_1x_2\ldots x_n:x_1+x_2+\ldots+x_n\equiv 0\quad \text{(mod 2)}\} \]

Since there are no codewords of (odd) weight 1, and all binary words of (even) weight 2 are in the code, \(d_{min}(\mathcal{C})=2\). Thus, this is an \([n,n-1,2]\) binary linear code.

Worked Example — The Length-7 Hamming code

A binary word \(x_1x_2x_3x_4x_5x_6x_7\) is in the Hamming code \(\mathcal{C}\) iff

\[ \begin{bmatrix} 1 &1 & 0 & 1 & 1 & 0 & 0 \\ 1 & 0 & 1 & 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\x_6 \\ x_7 \end{bmatrix} =\begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} \]

i.e. \(Hx^T=\mathbf{0}\), we can simplify the above expression into

\[ x_1\begin{bmatrix} 1\\1\\0\end{bmatrix} + x_2\begin{bmatrix} 1\\0\\1\end{bmatrix} +x_3\begin{bmatrix}0 \\ 1 \\ 1 \end{bmatrix} + x_4\begin{bmatrix} 1\\1\\1 \end{bmatrix} + x_5 \begin{bmatrix} 1\\0\\0\end{bmatrix} +x_6\begin{bmatrix}0\\1\\0\end{bmatrix} +x_7\begin{bmatrix}0\\0\\1\end{bmatrix} =\begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} \]

Now, note that \(\mathcal{C}\) has no codewords of weight \(1\), as no column of \(H\) is \(\mathbf{0}\). \(\mathcal{C}\) has no codewords of weight \(2\), as no two columns of \(H\) are identical. \(\mathcal{C}\) does have codewords of weight \(3\): e.g., the first three columns of \(H\) sum to \(\mathbf{0}\) over \(\mathbb{F}_2\), so \(1110000\) is in \(\mathcal{C}\). Hence, \(d_{min}(\mathcal{C})=3\). Thus, the Hamming code is a \([7,4,3]\) binary linear code.

Let \(\mathcal{C}\) be a linear code over \(\mathbb{F}\) with parity-check matrix \(H\), i.e., \(\mathcal{C}=\operatorname{nullspace}_{\mathbb{F}}(H)\).

Theorem

The minimum distance of \(\mathcal{C}\) is equal to the smallest number of columns of \(H\) that are linearly dependent over \(\mathbb{F}\). Equivalently, \(d_{min}(\mathcal{C})\) is the largest integer \(d\) such that every collection of \(d-1\) columns of \(H\) is linearly independent over \(\mathbb{F}\).

If \(\mathcal{C}=\operatorname{nullspace}_{\mathbb{F}}(H)\), then \(H\) is called a parity-check matrix for \(\mathcal{C}\).

Error Correction

Given a length \(n\) code \(\mathcal{C}\). An error is an event of changing an entry in a codeword. A codeword \(\mathbf{c}\in\mathcal{C}\) is transmitted, and \(\mathbf{y}\in\mathbb{F}^n\) is received. The number of errors that have occurred is \(d(\mathbf{y},\mathbf{c})\).

Definition

A code \(\mathcal{C}\) is \(t\)-error-correcting if there exists a decoding map \(\mathcal{D}:\mathbb{F}^n\rightarrow \mathcal{C}\) such that whenever \(d(\mathbf{y},\mathbf{c})\leq t\), we have \(\mathcal{D}(\mathbf{y})=\mathbf{c}\).

Proposition

An \([n,k,d]\) code is \(t\)-error-correcting for \(t \lt d/2\).

Proof

A codeword \(\mathbf{c}\in\mathcal{C}\) is transmitted, and \(\mathbf{y}\in\mathbb{F}^n\) is received. The number of errors that have occurred is \(d(\mathbf{y},\mathbf{c})\). Decode \(\mathbf{y}\) to the closest codeword: \(\hat{\mathbf{c}}=\arg \min_{\mathbf{c'}\in\mathcal{C}}d(\mathbf{y},\mathbf{c'})\). If \(d(\mathbf{y},\mathbf{c}) \lt d/2\), then \(\hat{\mathbf{c}}=\mathbf{c}\). ∎

Picture each codeword as the center of a ball of radius \(d/2\). Because any two codewords are at least \(d\) apart, these balls never overlap — so as long as fewer than \(d/2\) symbols get corrupted, the received word still sits inside the right ball, and "snap to the nearest codeword" recovers the message uniquely.

Erasures

An erasure is an error whose location is known. Usually represented by a ‘?’ symbol:

A transmitted codeword in which some positions have been erased and replaced by question-mark symbols at known locations.
Figure — Erasure
Proposition

Let \(\mathcal{C}\) be an \([n,k,d]\) code over \(\mathbb{F}\). There is a decoder for \(\mathcal{C}\) that corrects any occurrence of up to \(d-1\) erasures.

Proof

Let \(\Phi=\mathbb{F}\cup \{?\}\). Consider the decoder defined for each \(\mathbf{y}\in \Phi^n\) as

\[ \mathcal{D}(\mathbf{y})=\begin{cases} \mathbf{c} &\text{if } \mathbf{c} \text{ is the unique codeword that agrees with } \mathbf{y} \text{ on all unerased positions}\\ \text{ERROR} &\text{otherwise} \end{cases} \]

Suppose that \(\mathbf{c}\) was transmitted and at most \(d-1\) of its coordinates were erased. The received word \(\mathbf{y}\) contains at most \(d-1\) ‘?’ symbols, and agrees with \(\mathbf{c}\) on all the unerased positions. If there were another \(\mathbf{c'}\in\mathcal{C}\) that also agreed with \(\mathbf{y}\) on all the unerased positions, then \(\mathbf{c}\) and \(\mathbf{c'}\) could differ only in those positions where \(\mathbf{y}\) has ‘?’ symbols. Then, \(d(\mathbf{c},\mathbf{c'})\leq d-1\), which contradicts \(d_{min}(\mathcal{C})=d\). Thus, \(\mathbf{c}\) is the unique codeword that agrees with \(\mathbf{y}\) in all unerased coordinates, and hence \(\mathcal{D}(\mathbf{y})=\mathbf{c}\). ∎

Erasures are gentler than errors: you already know where the damage is, you just don't know the missing values. That extra knowledge roughly doubles your power — a distance-\(d\) code fixes up to \(d-1\) erasures but fewer than \(d/2\) unknown-location errors.

Key Takeaways