Paper
Part IErrors, Information and Channels

Probability for Coding

November 14, 202652 min readbeginner

Two flips in three bits defeat a majority vote. This chapter builds the probability behind that sentence, from events and the binomial distribution to the Gaussian tail, the union bound and the Chernoff bound.

The previous chapter, Why Codes Exist, computed every error probability with two moves, multiplying the chances of bit flips that have nothing to do with each other and adding the chances of error patterns that cannot happen together. Those moves gave the decoded error of the repetition code, 3p2−2p33p^2 - 2p^3, and the miss rate of a parity check, because every situation was small enough to list. A 72-bit memory word has 2722^{72} possible error patterns and a frame of a thousand bits has 210002^{1000}, and no list reaches that far.

This chapter turns the two moves into a toolkit that scales. It starts with events on three bits, where every probability can be checked by hand, then counts errors with the binomial distribution, summarizes a count by its expectation and variance, and proves the law of large numbers, which explains why a measured bit error rate settles down to the true one. The Gaussian distribution enters as the model of noise on a voltage, with the Q-function as its tail. The chapter closes with the union bound and the Chernoff bound, the two inequalities the rest of the book leans on whenever an exact sum is out of reach.

Every theorem is proved, after a number that can be checked by hand. The algebra needed is powers, the exponential function and the natural logarithm, and the Gaussian section explains the one idea from calculus it uses, the integral as an area. Every number in the chapter is recomputed by ch02_probability_for_coding.py, in the python/ folder of the companion repository ecc-book-lab, which prints each value beside the one the text states and stops at the first disagreement. The charts are drawn by ch02_charts.py in the same folder.

01.Events on Three Bits

Send the codeword 000 of the three-bit repetition code over the binary symmetric channel of the previous chapter, BSC(0.1)\text{BSC}(0.1), which flips each bit with probability p=0.1p = 0.1 and leaves it alone with probability 0.90.9. The receiver sees one of eight patterns. A pattern with ww flipped bits has probability 0.1w 0.93−w0.1^w \, 0.9^{3-w}, so the received word 000 has probability 0.93=0.7290.9^3 = 0.729, each of 100, 010 and 001 has probability 0.1×0.92=0.0810.1 \times 0.9^2 = 0.081, each of 110, 101 and 011 has probability 0.12×0.9=0.0090.1^2 \times 0.9 = 0.009, and 111 has probability 0.13=0.0010.1^3 = 0.001. The eight numbers add to 1, as they must, because some pattern always arrives.

That list is the whole experiment. Any question about one use of the channel, such as whether the decoder will fail, is answered by adding the probabilities of the patterns where the answer is yes. The vocabulary below names the pieces, so that the same reasoning reaches lists too long to write down.

The set of every possible outcome is the sample space, written Ω\Omega, the capital Greek letter omega. Here Ω\Omega holds the eight received patterns. A single outcome is written ω\omega, the lower-case omega, and the statement "ω\omega belongs to the set EE" is written ω∈E\omega \in E. An event is any set of outcomes, the set for which some yes-or-no question has the answer yes.

Three facts follow at once. The whole sample space has probability P(Ω)=1P(\Omega) = 1, the empty event has probability 0, and two events EE and FF that share no outcome, called disjoint, satisfy P(E∪F)=P(E)+P(F)P(E \cup F) = P(E) + P(F), where E∪FE \cup F, the union, is the set of outcomes in EE or FF or both. The last fact holds because each outcome of the union appears in exactly one of the two sums.

Two events on the three bits carry the rest of this section. Event AA is "the first bit flipped," the set {100,110,101,111}\{100, 110, 101, 111\}, with probability 0.081+0.009+0.009+0.001=0.10.081 + 0.009 + 0.009 + 0.001 = 0.1, which had to equal pp and so checks the list. Event BB is "the majority decoder fails," which happens when two or more bits flip, the set {110,101,011,111}\{110, 101, 011, 111\}, with probability 3×0.009+0.001=0.0283 \times 0.009 + 0.001 = 0.028, the decoded error of R3R_3 found in the previous chapter. Figure 1 shows both events.

The eight outcomes of sending 000 over a channel that flips each bit with probability 0.1, arranged in rows by the number of flips, each with its probability. Event A, the first bit flipped, is the right-hand group. Event B, two or more flips, is the bottom two rows. The two events share the outcomes 110, 101 and 111. 000 010001100 011110101 111 0.729 0.0810.0810.081 0.0090.0090.009 0.001 0 flips 1 flip 2 flips 3 flips first bit not flipped A: first bit flipped, P(A) = 0.1 B: decoder fails, two or more flips, P(B) = 0.028 A and B share 110, 101 and 111, so P(A and B) = 0.019
Figure 1. The eight outcomes of sending 000 through , in rows by the number of flips. Event , the first bit flipped, has probability 0.1, event , the decoder fails, has probability 0.028, and the three outcomes they share carry 0.019.

Complements, Intersections and Unions

The complement of an event BB, written BcB^c and read "not BB," is the set of outcomes outside BB, here the event that the decoder succeeds. Since BB and BcB^c are disjoint and together make up Ω\Omega, P(Bc)=1−P(B)=0.972P(B^c) = 1 - P(B) = 0.972. The complement is often the easier side of a question, which is how the previous chapter found the chance of at least one error in a terabyte.

The intersection A∩BA \cap B is the set of outcomes in both events. Here it is {110,101,111}\{110, 101, 111\}, the cases where the first bit flipped and the decoder failed, with probability 0.009+0.009+0.001=0.0190.009 + 0.009 + 0.001 = 0.019. The union A∪BA \cup B is {100,110,101,111,011}\{100, 110, 101, 111, 011\}, with probability 0.081+0.009+0.009+0.001+0.009=0.1090.081 + 0.009 + 0.009 + 0.001 + 0.009 = 0.109. Adding P(A)+P(B)=0.128P(A) + P(B) = 0.128 gives too much, because the three shared outcomes were counted once in each event.

Proof. The union splits into three disjoint pieces, the outcomes in AA only, written A∩BcA \cap B^c, the outcomes in both, A∩BA \cap B, and the outcomes in BB only, Ac∩BA^c \cap B. Additivity gives P(A∪B)=P(A∩Bc)+P(A∩B)+P(Ac∩B)P(A \cup B) = P(A \cap B^c) + P(A \cap B) + P(A^c \cap B). The event AA splits the same way into A∩BcA \cap B^c and A∩BA \cap B, so P(A)=P(A∩Bc)+P(A∩B)P(A) = P(A \cap B^c) + P(A \cap B), and likewise P(B)=P(Ac∩B)+P(A∩B)P(B) = P(A^c \cap B) + P(A \cap B). Adding the last two equations gives P(A)+P(B)=P(A∪B)+P(A∩B)P(A) + P(B) = P(A \cup B) + P(A \cap B), which rearranges to the theorem. ■\blacksquare

The check on the example is 0.1+0.028−0.019=0.1090.1 + 0.028 - 0.019 = 0.109, which matches the direct sum.

Conditional Probability

Suppose a test reveals that the first bit flipped, and nothing about the other two. The outcomes still possible are those of AA, totaling 0.1, and the failing ones among them total 0.019. Rescaling the survivors so that they add to 1 gives a failure probability of 0.019/0.1=0.190.019 / 0.1 = 0.19. Direct reasoning agrees, since the decoder now fails unless both other bits arrive intact, so failure has probability 1−0.92=0.191 - 0.9^2 = 0.19, up from 0.028.

The opposite case, where the test shows that the first bit arrived intact, gives P(B∣Ac)=P(Ac∩B)/P(Ac)P(B \mid A^c) = P(A^c \cap B) / P(A^c). The only failing pattern with an intact first bit is 011, so this is 0.009/0.9=0.010.009 / 0.9 = 0.01, which is p2p^2, the chance that both remaining bits flip.

The two conditional probabilities rebuild the unconditional one. Weighting each by the probability of its condition gives 0.19×0.1+0.01×0.9=0.0280.19 \times 0.1 + 0.01 \times 0.9 = 0.028, which is P(B)P(B) again.

Proof. Every outcome of BB lies in exactly one AiA_i, so BB is the disjoint union of the pieces B∩A1,…,B∩AmB \cap A_1, \ldots, B \cap A_m, and additivity gives P(B)=∑iP(B∩Ai)P(B) = \sum_i P(B \cap A_i). The definition of conditional probability, multiplied through by P(Ai)P(A_i), says P(B∩Ai)=P(B∣Ai) P(Ai)P(B \cap A_i) = P(B \mid A_i) \, P(A_i). Substituting each term gives the theorem. ■\blacksquare

Now reverse the question. Given that the decoder failed, how likely is it that the first bit flipped? The definition gives P(A∣B)=P(A∩B)/P(B)=0.019/0.028=19/28=0.6786P(A \mid B) = P(A \cap B) / P(B) = 0.019 / 0.028 = 19/28 = 0.6786, up from 0.1, because a failure needs at least two flips, and two of the three two-flip patterns, as well as 111, involve the first bit.

Proof. The definition of conditional probability, applied in both directions, gives P(A∣B) P(B)=P(A∩B)P(A \mid B) \, P(B) = P(A \cap B) and P(B∣A) P(A)=P(A∩B)P(B \mid A) \, P(A) = P(A \cap B). The two left-hand sides are therefore equal, and dividing by P(B)P(B) gives the theorem. ■\blacksquare

Bayes' rule is the step every decoder takes, because a channel gives the probability of what is received given what was sent, while a receiver needs the reverse.

Independence

In the reversal above, learning BB changed the probability of AA. Events for which the knowledge changes nothing are the ones the channel model is built from.

The events AA and BB fail the test, since P(A) P(B)=0.1×0.028=0.0028P(A)\,P(B) = 0.1 \times 0.028 = 0.0028 while P(A∩B)=0.019P(A \cap B) = 0.019. The event CC, "the second bit flipped," passes it, since A∩C={110,111}A \cap C = \{110, 111\} has probability 0.009+0.001=0.01=P(A) P(C)0.009 + 0.001 = 0.01 = P(A)\,P(C). Flips of different bits are independent, as the channel promises.

For more than two events the definition needs a stronger form. Events E1,…,EnE_1, \ldots, E_n are mutually independent when, for every choice of some of them, the probability that all the chosen events occur is the product of their probabilities. The binary symmetric channel assumes this of the events FiF_i, "bit ii flipped," each of probability pp, and that is where the pattern probability of 110 comes from. The event "110 received" is what remains of F1∩F2F_1 \cap F_2 after removing F1∩F2∩F3F_1 \cap F_2 \cap F_3, so

P(F1∩F2∩F3c)=P(F1∩F2)−P(F1∩F2∩F3)=p2−p3=p2(1−p).P(F_1 \cap F_2 \cap F_3^c) = P(F_1 \cap F_2) - P(F_1 \cap F_2 \cap F_3) = p^2 - p^3 = p^2 (1-p).

Mutual independence is genuinely stronger than independence of every pair. At p=1/2p = 1/2, take F1F_1, F2F_2 and the event GG that bits 1 and 2 agree. Each has probability 1/21/2 and every pair intersects with probability 1/41/4, so the three are independent in pairs. Yet all three occur exactly when bits 1 and 2 both flip, with probability 1/41/4, not the product 1/81/8.

02.Counting Errors with the Binomial Distribution

A decoder usually asks how many bits flipped. A random variable is a rule that assigns a number to every outcome. Let XX be the number of flipped bits among the three, so X(000)=0X(000) = 0, X(100)=1X(100) = 1 and X(110)=2X(110) = 2. The event X=2X = 2 is the set {110,101,011}\{110, 101, 011\}, with probability 3×0.009=0.0273 \times 0.009 = 0.027, and the four values give P(X=0)=0.729P(X=0) = 0.729, P(X=1)=0.243P(X=1) = 0.243, P(X=2)=0.027P(X=2) = 0.027 and P(X=3)=0.001P(X=3) = 0.001, the last column of the table in the previous chapter.

The formula below does the same job for any number of bits. It uses the factorial n!n!, the product 1×2×⋯×n1 \times 2 \times \cdots \times n, with 0!=10! = 1 by convention, and the binomial coefficient (nk)\binom{n}{k}, read "nn choose kk," which counts the ways to choose kk positions out of nn.

Proof. First the count. Choose the kk flipped positions one at a time. There are nn choices for the first, n−1n - 1 for the second, and so on down to n−k+1n - k + 1 for the last, so there are n(n−1)⋯(n−k+1)=n!/(n−k)!n(n-1)\cdots(n-k+1) = n!/(n-k)! ordered choices. Each set of kk positions is reached in k!k! of these orders, by the same count applied to its own kk positions, so there are n!/(k! (n−k)!)n! / (k!\,(n-k)!) distinct sets.

Next one pattern. A pattern with flips in a given set of kk positions is the intersection of kk events "bit ii flipped" and n−kn - k events "bit ii did not flip." By mutual independence its probability is the product pk(1−p)n−kp^k (1-p)^{n-k}, the same for every such pattern.

Finally the sum. The event X=kX = k is the disjoint union of the (nk)\binom{n}{k} patterns with exactly kk flips, so additivity gives (nk)\binom{n}{k} times the common pattern probability. To see that the probabilities add to 1, expand (x+y)n(x + y)^n as a product of nn factors (x+y)(x + y). Each term of the expansion picks xx from some of the factors and yy from the rest, and the terms that pick xx from exactly kk factors number (nk)\binom{n}{k}, which proves the binomial theorem (x+y)n=∑k(nk)xkyn−k(x+y)^n = \sum_{k} \binom{n}{k} x^k y^{n-k}. Setting x=px = p and y=1−py = 1 - p gives ∑kP(X=k)=(p+1−p)n=1\sum_k P(X = k) = (p + 1 - p)^n = 1. ■\blacksquare

For n=3n = 3 and p=0.1p = 0.1 the formula gives (32) 0.12 0.9=3×0.009=0.027\binom{3}{2} \, 0.1^2 \, 0.9 = 3 \times 0.009 = 0.027, as the list did. Table 1 applies it to a byte on a channel with p=0.01p = 0.01.

Table 1. The number of flips in a byte sent through

Flips kkPatterns (8k)\binom{8}{k}P(X=k)P(X = k)
010.922745
180.074565
2280.0026361
3565.3255×10−55.3255 \times 10^{-5}
4706.7242×10−76.7242 \times 10^{-7}
5 or more935.4612×10−95.4612 \times 10^{-9}

Source: computed from the binomial distribution and reproduced by ch02_probability_for_coding.py.

The table explains two numbers from the previous chapter. A byte holds at least one error with probability 1−0.922745=0.0772551 - 0.922745 = 0.077255, which is 1−0.9981 - 0.99^8, and almost all of the parity check's miss rate, 0.0026368, is the row k=2k = 2, at 0.0026361. Each row is a small correction to the one above it, which is why a code that handles the few most likely error counts handles nearly everything.

The Shape of the Distribution

Figure 2 plots the distribution for a 20-bit block on a poor channel, p=0.1p = 0.1. The bars rise from P(X=0)=0.1216P(X = 0) = 0.1216 to a peak of 0.28520.2852 at k=2k = 2 and then fall, through 0.19010.1901, 0.08980.0898 and 0.03190.0319, down to 0.00040.0004 at k=8k = 8.

Bar chart of the binomial probabilities P(X = k) for n = 20 and p = 0.1. The bars rise to a peak of 0.285 at k = 2, the mean np, and fall away quickly, so that five or more flips have total probability 0.0432. number of flipped bits k among n = 20 bits, each flipped with p = 0.1 probability P(X = k) 0 0.05 0.10 0.15 0.20 0.25 0.30 0 1 2 3 4 5 6 7 8 9 10 0.122 0.270 0.285 0.190 0.090 0.032 0.009 mode and mean: k = np = 2 orange bars: at least 5 flips, total probability 0.0432
Figure 2. The number of flips in 20 bits through . The most likely count is 2, which is also the mean , and five or more flips together have probability 0.0432. Data: computed from the binomial distribution by ch02_charts.py in the companion repository.

The peak is located without computing every bar. Dividing two neighboring values of Equation 4 cancels most of the factorials,

P(X=k+1)P(X=k)=(nk+1)(nk)⋅p1−p=n−kk+1⋅p1−p,\frac{P(X = k+1)}{P(X = k)} = \frac{\binom{n}{k+1}}{\binom{n}{k}} \cdot \frac{p}{1-p} = \frac{n-k}{k+1} \cdot \frac{p}{1-p},

because (nk+1)/(nk)=k! (n−k)!(k+1)! (n−k−1)!=n−kk+1\binom{n}{k+1} / \binom{n}{k} = \frac{k!\,(n-k)!}{(k+1)!\,(n-k-1)!} = \frac{n-k}{k+1}. With n=20n = 20 and p/(1−p)=1/9p/(1-p) = 1/9, the ratio is 20/9=2.2220/9 = 2.22 at k=0k = 0, 19/18=1.0619/18 = 1.06 at k=1k = 1 and 18/27=0.66718/27 = 0.667 at k=2k = 2, and it keeps shrinking as kk grows. The bars grow while the ratio exceeds 1, so the peak is at k=2k = 2. For coding the tail matters more, since a code that corrects any four errors in this block fails with probability P(X≥5)=0.0432P(X \ge 5) = 0.0432.

03.Expectation and Variance

Two numbers summarize a distribution, where its values sit on average and how far they stray. For the three bits, weighting each count by its probability and adding gives 0×0.729+1×0.243+2×0.027+3×0.001=0.30 \times 0.729 + 1 \times 0.243 + 2 \times 0.027 + 3 \times 0.001 = 0.3. Over many uses the flips would average near 0.3, a claim the law of large numbers makes precise, and the answer is 3×0.13 \times 0.1, three bits each contributing 0.1 flips on average. That is no coincidence.

The value 3×0.13 \times 0.1 comes from splitting the count into pieces. For each bit position ii, define the indicator XiX_i, which is 1 if bit ii flipped and 0 if not. The count of flips is the sum of the indicators, X=X1+X2+⋯+XnX = X_1 + X_2 + \cdots + X_n, as Figure 3 shows for one received byte. Each indicator has expectation 1×p+0×(1−p)=p1 \times p + 0 \times (1 - p) = p. What remains is to show that the expectation of a sum is the sum of the expectations.

An 8-bit word as sent and as received, with the third and eighth bits flipped. Below them, one indicator per position is 1 where the bit flipped and 0 elsewhere, so adding the indicators counts the flips, which here number 2. 1234 5678 bit position sent received indicator 1011 0010 101 001 000 000 01 11 X1X2 X3X4 X5X6 X7X8 orange marks a flipped bit Adding the indicator row counts the flips, X = 2 Each indicator has mean p, so X has mean 8p
Figure 3. Counting flips with indicators. Each position contributes 1 if its bit flipped and 0 if not, so the indicator row adds up to the number of flips, here 2. Since each indicator has mean , the count has mean .

The proof rests on a second way to compute an expectation, one outcome at a time instead of one value at a time. Each value kk collects the outcomes ω\omega with X(ω)=kX(\omega) = k, so k P(X=k)=∑ω:X(ω)=kX(ω) P(ω)k \, P(X = k) = \sum_{\omega : X(\omega) = k} X(\omega) \, P(\omega), where the sum runs over the outcomes with that value. Adding over all values reaches every outcome exactly once, so

E[X]=∑ω∈ΩX(ω) P(ω).E[X] = \sum_{\omega \in \Omega} X(\omega) \, P(\omega).

Proof. By the outcome-by-outcome form, E[X+Y]=∑ω(X(ω)+Y(ω))P(ω)=∑ωX(ω)P(ω)+∑ωY(ω)P(ω)=E[X]+E[Y]E[X + Y] = \sum_{\omega} \bigl(X(\omega) + Y(\omega)\bigr) P(\omega) = \sum_{\omega} X(\omega) P(\omega) + \sum_{\omega} Y(\omega) P(\omega) = E[X] + E[Y], by splitting one sum into two. Likewise E[cX]=∑ωc X(ω)P(ω)=c∑ωX(ω)P(ω)=c E[X]E[cX] = \sum_{\omega} c\,X(\omega) P(\omega) = c \sum_{\omega} X(\omega) P(\omega) = c\,E[X]. ■\blacksquare

Proof. Write XX as the sum of its indicators and apply linearity n−1n - 1 times, E[X]=E[X1]+⋯+E[Xn]=p+⋯+p=npE[X] = E[X_1] + \cdots + E[X_n] = p + \cdots + p = np. ■\blacksquare

The proof never touched the binomial probabilities, which is the strength of linearity. It justifies the previous chapter's error counts, such as 28.8 errors in an hour of 2.88×10132.88 \times 10^{13} bits on a link with p=10−12p = 10^{-12}, even though the count in any given hour could be anything from zero upward.

Spread

The mean says nothing about how far a count strays from it. For the three bits, the squared distances of the four possible counts from the mean 0.3 are (0−0.3)2=0.09(0 - 0.3)^2 = 0.09, (1−0.3)2=0.49(1 - 0.3)^2 = 0.49, (2−0.3)2=2.89(2 - 0.3)^2 = 2.89 and (3−0.3)2=7.29(3 - 0.3)^2 = 7.29. Weighting them by their probabilities gives 0.09×0.729+0.49×0.243+2.89×0.027+7.29×0.001=0.270.09 \times 0.729 + 0.49 \times 0.243 + 2.89 \times 0.027 + 7.29 \times 0.001 = 0.27. Squaring keeps distances above and below the mean from canceling.

For the three bits, σ=0.27=0.5196\sigma = \sqrt{0.27} = 0.5196 flips. A second formula for the variance is usually quicker.

Proof. Expand the square and apply linearity, treating μ\mu as a constant, E[(X−μ)2]=E[X2]−2μ E[X]+μ2=E[X2]−2μ2+μ2=E[X2]−μ2E\bigl[(X - \mu)^2\bigr] = E[X^2] - 2\mu\,E[X] + \mu^2 = E[X^2] - 2\mu^2 + \mu^2 = E[X^2] - \mu^2. For the second claim, cXcX has mean cμc\mu, so Var⁡(cX)=E[(cX−cμ)2]=c2E[(X−μ)2]\operatorname{Var}(cX) = E\bigl[(cX - c\mu)^2\bigr] = c^2 E\bigl[(X - \mu)^2\bigr]. ■\blacksquare

The check is E[X2]=1×0.243+4×0.027+9×0.001=0.36E[X^2] = 1 \times 0.243 + 4 \times 0.027 + 9 \times 0.001 = 0.36, and 0.36−0.32=0.270.36 - 0.3^2 = 0.27. Means add for any random variables, but variances add only for independent ones. Random variables XX and YY are independent when P(X=x and Y=y)=P(X=x) P(Y=y)P(X = x \text{ and } Y = y) = P(X = x) \, P(Y = y) for every pair of values xx and yy, as the indicators of different bits on a binary symmetric channel are.

Proof. Group the outcomes by the pair of values (x,y)(x, y). Then E[XY]=∑x∑yxy P(X=x and Y=y)=∑x∑yxy P(X=x)P(Y=y)E[XY] = \sum_x \sum_y x y \, P(X = x \text{ and } Y = y) = \sum_x \sum_y x y \, P(X = x) P(Y = y), and the double sum factors as (∑xx P(X=x))(∑yy P(Y=y))=E[X] E[Y]\bigl(\sum_x x\,P(X = x)\bigr)\bigl(\sum_y y\,P(Y = y)\bigr) = E[X]\,E[Y]. ■\blacksquare

Proof. Write μX\mu_X and μY\mu_Y for the two means. By the lemma on the second moment and linearity,

Var⁡(X+Y)=E[X2]+2E[XY]+E[Y2]−μX2−2μXμY−μY2=Var⁡(X)+Var⁡(Y)+2(E[XY]−μXμY).\operatorname{Var}(X+Y) = E[X^2] + 2E[XY] + E[Y^2] - \mu_X^2 - 2\mu_X\mu_Y - \mu_Y^2 = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\bigl(E[XY] - \mu_X\mu_Y\bigr).

The last bracket is zero by the product lemma. For nn variables, add them one at a time. Under mutual independence the partial sum X1+⋯+XkX_1 + \cdots + X_k is independent of Xk+1X_{k+1}, so each new term adds its own variance. ■\blacksquare

Proof. An indicator takes only the values 0 and 1, so Xi2=XiX_i^2 = X_i and E[Xi2]=pE[X_i^2] = p. The lemma gives Var⁡(Xi)=p−p2=p(1−p)\operatorname{Var}(X_i) = p - p^2 = p(1-p). The indicators are mutually independent, so their variances add to np(1−p)np(1-p). ■\blacksquare

For three bits, 3×0.1×0.9=0.273 \times 0.1 \times 0.9 = 0.27, matching the direct sum. For the fast link, Table 2 sets each mean beside its standard deviation.

Table 2. Errors on a link at bits per second with

SpanBits NNMean NpNpStandard deviationStandard deviation over mean
One terabyte8×10128 \times 10^{12}82.8280.354
One hour2.88×10132.88 \times 10^{13}28.85.3670.186
One day6.912×10146.912 \times 10^{14}691.226.290.038

Source: computed from the binomial mean and variance and reproduced by ch02_probability_for_coding.py.

The last column falls as the span grows. The standard deviation is close to Np\sqrt{Np}, since 1−p1 - p is all but 1, so it grows as the square root of the number of bits while the mean grows in proportion, and their ratio shrinks like 1/Np1/\sqrt{Np}, from about a third of the mean for a terabyte to under 4% for a day.

04.The Law of Large Numbers

A test bench measures a bit error rate by dividing the errors found by the bits sent. Whether that fraction approaches the true pp, and how many bits it needs, depends on turning a mean and a variance into a statement about probability, which the next two inequalities do.

Markov's Inequality

Take a frame of 1000 bits on a channel with p=0.01p = 0.01, so the mean number of errors is 1000×0.01=101000 \times 0.01 = 10. Suppose nothing else is known except that the count is never negative. If more than half of all frames carried 20 or more errors, those frames alone would push the average above 12×20=10\tfrac{1}{2} \times 20 = 10. So at most half do.

Proof. Split the defining sum of E[X]E[X] into the values below aa and the values at or above it. The first part is at least zero, because X≥0X \ge 0, and in the second each value is at least aa, so

E[X]=∑kk P(X=k) ≥ ∑k≥ak P(X=k) ≥ a∑k≥aP(X=k)=a P(X≥a).E[X] = \sum_k k\,P(X = k) \ \ge\ \sum_{k \ge a} k\,P(X = k) \ \ge\ a \sum_{k \ge a} P(X = k) = a\,P(X \ge a).

Dividing by aa gives the theorem. ■\blacksquare

The frame example gives P(X≥20)≤10/20=0.5P(X \ge 20) \le 10/20 = 0.5, more than a hundred times the exact binomial value 0.0032884, because the inequality uses nothing but the mean. The proof has a picture. The step that is 1 for x≥ax \ge a and 0 below never exceeds the line x/ax/a when x≥0x \ge 0, and averaging both sides over the distribution of XX is the proof. Figure 4 draws the step with three curves above it, and the closer a curve hugs the step where the probability sits, the better its bound.

The step function that is 0 below a = 2 and 1 from a on, drawn with the three functions that lie above it everywhere, namely the line x over a used by Markov, the parabola used by Chebyshev, and the exponential used by Chernoff. value x of a nonnegative random variable (a = 2, mean 1) height of each function 0 0.5 1 1.5 2 2.5 0 1 2 3 4 step: 1 when x is at least a Chebyshev Chernoff Markov
Figure 4. Three functions that lie above the step , drawn for and mean . Markov's line , Chebyshev's parabola and the Chernoff exponential with each bound by their average value. Data: computed by ch02_charts.py in the companion repository.

Chebyshev's Inequality

The variance adds information that the mean lacks, and applying Markov's inequality to the squared distance from the mean puts it to work.

Proof. The random variable Y=(X−μ)2Y = (X - \mu)^2 is never negative and has mean σ2\sigma^2. The event ∣X−μ∣≥d|X - \mu| \ge d is the same as Y≥d2Y \ge d^2, so Markov's inequality applied to YY with a=d2a = d^2 gives P(∣X−μ∣≥d)=P(Y≥d2)≤σ2/d2P(|X - \mu| \ge d) = P(Y \ge d^2) \le \sigma^2 / d^2. ■\blacksquare

For the frame, the variance is 1000×0.01×0.99=9.91000 \times 0.01 \times 0.99 = 9.9. Twenty or more errors means a distance of at least 10 above the mean, so P(X≥20)≤P(∣X−10∣≥10)≤9.9/100=0.099P(X \ge 20) \le P(|X - 10| \ge 10) \le 9.9/100 = 0.099. That is five times better than Markov and still about thirty times the exact 0.0032884.

The real use of Chebyshev's inequality is that it holds for every distribution with that mean and variance. Setting d=kσd = k\sigma shows that no random variable lands kk or more standard deviations from its mean with probability above 1/k21/k^2. For a day on the fast link, four standard deviations are 4×26.29=105.24 \times 26.29 = 105.2 errors, so the day's count lies between 691.2−105.2=586.0691.2 - 105.2 = 586.0 and 691.2+105.2=796.4691.2 + 105.2 = 796.4 except with probability at most 1/16=0.06251/16 = 0.0625, and a count outside that range is strong evidence that the error rate is not 10−1210^{-12}.

Averages Settle Down

Proof. By linearity, E[Xˉn]=1n(nμ)=μE[\bar{X}_n] = \tfrac{1}{n}(n\mu) = \mu. By the variance of a sum and the rule Var⁡(cX)=c2Var⁡(X)\operatorname{Var}(cX) = c^2 \operatorname{Var}(X), Var⁡(Xˉn)=1n2(nσ2)=σ2/n\operatorname{Var}(\bar{X}_n) = \tfrac{1}{n^2}(n\sigma^2) = \sigma^2/n. Chebyshev's inequality with d=εd = \varepsilon gives the bound. ■\blacksquare

Here ε\varepsilon, the Greek letter epsilon, is the tolerance. However small it is, a long enough run makes a miss as unlikely as desired. In Figure 5, three simulated runs of a channel with p=0.1p = 0.1 wander over their first few dozen bits and then settle, and by 10,000 bits each sits inside a band of half-width 2p(1−p)/n=0.0062\sqrt{p(1-p)/n} = 0.006 around the true value.

The fraction of flipped bits among the first k bits, for three simulated runs of a channel with p = 0.1, for k from 10 to 10000. The runs wander early and settle toward 0.1, inside a band that narrows as one over the square root of k. number of bits sent k (log scale) fraction of the k bits that flipped 0 0.1 0.2 0.3 0.4 101 102 103 104 p = 0.1 p plus two standard deviations p minus two standard deviations three simulated runs
Figure 5. The measured fraction of flipped bits in three simulated runs of . The band marks two standard deviations of the average, , which narrows to at . Data: simulated with fixed seeds by ch02_charts.py in the companion repository.

For a bit error rate measurement, let XiX_i be the indicator that bit ii arrived wrong, so μ=p\mu = p and σ2=p(1−p)\sigma^2 = p(1-p), and Xˉn\bar{X}_n is the measured error fraction. Asking for the measurement to land within ε\varepsilon of pp except with probability δ\delta, the Greek letter delta, means making the right side of Equation 9 at most δ\delta, which needs

n≥p(1−p)ε2δ.n \ge \frac{p(1-p)}{\varepsilon^2 \delta}.

To measure p=10−3p = 10^{-3} to within ε=10−4\varepsilon = 10^{-4} with failure probability δ=0.05\delta = 0.05, Chebyshev asks for n≥0.000999/(10−8×0.05)=1,998,000n \ge 0.000999 / (10^{-8} \times 0.05) = 1{,}998{,}000 bits. The demand is generous, because it holds for any distribution. At n=106n = 10^6 bits the standard deviation of the measured fraction is already p(1−p)/n=3.16×10−5\sqrt{p(1-p)/n} = 3.16 \times 10^{-5}, so the tolerance sits more than three standard deviations away. Sharper statements need the shape of the distribution.

05.The Gaussian and the Q-Function

Underneath a bit flip there is usually a voltage. Suppose a transmitter sends a 1 as +1+1 volt and a 0 as −1-1 volt, and the wire adds a random noise voltage with mean 0 and standard deviation σ=0.5\sigma = 0.5 volt. The receiver decides 1 when the voltage it sees is above 0 and 0 otherwise. When a 1 is sent, the decision is wrong if the noise falls below −1-1 volt, more than two standard deviations below its mean. For the noise found in practice that happens with probability Q(2)=0.02275Q(2) = 0.02275, the shaded area in Figure 6.

Two bell-shaped densities of the received voltage, centered on +1 and on minus 1, each with noise standard deviation 0.5. The part of the +1 curve below the threshold at 0 is shaded, and its area, Q(2) = 0.0228, is the probability of a decision error. received voltage r probability density 0 0.4 0.8 1.2 −3 −2 −1 0 1 2 3 sent +1 sent −1 threshold 0 decide 0 decide 1 red area: +1 sent, received below 0, probability Q(2) = 0.0228
Figure 6. Received voltage for a 1 sent as and a 0 sent as , with Gaussian noise of standard deviation 0.5. The shaded tail of the curve below the threshold is the probability of a wrong decision, . Data: computed by ch02_charts.py in the companion repository.

Densities

A voltage takes values in a continuous range, so any one exact value has probability zero. Probabilities come instead from a density, a curve f(x)≥0f(x) \ge 0 with total area 1, and the probability of landing between aa and bb is the area under the curve between them, written ∫abf(x) dx\int_a^b f(x)\,dx. The symbol ∫\int, an elongated S for "sum," stands for the limit of adding many thin rectangles of width dxdx and height f(x)f(x). Every earlier rule carries over with sums replaced by areas, so E[X]=∫xf(x) dxE[X] = \int x f(x)\,dx, Var⁡(X)=∫(x−μ)2f(x) dx\operatorname{Var}(X) = \int (x - \mu)^2 f(x)\,dx, and linearity holds as before.

The standard curve peaks at ϕ(0)=1/2π=0.3989\phi(0) = 1/\sqrt{2\pi} = 0.3989 and falls off symmetrically, faster than any power of xx. The received voltage for a sent 1 in the opening example is N(1,0.25)N(1, 0.25), a copy of the standard curve half as wide and twice as tall.

Proof. Let I=∫−∞∞e−x2/2 dxI = \int_{-\infty}^{\infty} e^{-x^2/2}\,dx. Its square is a volume over the whole plane, I2=∫ ⁣ ⁣∫e−(x2+y2)/2 dx dyI^2 = \int\!\!\int e^{-(x^2 + y^2)/2}\,dx\,dy, and the trick is to compute that volume in rings. The height e−(x2+y2)/2e^{-(x^2+y^2)/2} depends only on the distance r=x2+y2r = \sqrt{x^2 + y^2} from the origin. The thin ring between radius rr and r+drr + dr has circumference 2πr2\pi r, width drdr and therefore area 2πr dr2\pi r\,dr, so

I2=∫0∞e−r2/2 2πr dr=2π[−e−r2/2]0∞=2π(0+1)=2π,I^2 = \int_0^\infty e^{-r^2/2}\, 2\pi r\,dr = 2\pi \Bigl[-e^{-r^2/2}\Bigr]_0^\infty = 2\pi(0 + 1) = 2\pi,

where the bracket evaluates an antiderivative at the two ends, checked by differentiating −e−r2/2-e^{-r^2/2} to get re−r2/2r e^{-r^2/2}. So I=2πI = \sqrt{2\pi}, and dividing by 2π\sqrt{2\pi} makes the total area of ϕ\phi equal to 1. The mean ∫x ϕ(x) dx\int x\,\phi(x)\,dx is 0, because ϕ(−x)=ϕ(x)\phi(-x) = \phi(x) and the contributions of xx and −x-x cancel. For the variance, note that differentiating gives ϕ′(x)=−x ϕ(x)\phi'(x) = -x\,\phi(x). Integration by parts, which is the product rule for derivatives read backward, ∫u v′ dx=[uv]−∫u′ v dx\int u\,v'\,dx = [uv] - \int u'\,v\,dx, with u=xu = x and v=−ϕv = -\phi, gives

∫−∞∞x2ϕ(x) dx=∫−∞∞x⋅xϕ(x) dx=[−x ϕ(x)]−∞∞+∫−∞∞ϕ(x) dx=0+1=1,\int_{-\infty}^{\infty} x^2 \phi(x)\,dx = \int_{-\infty}^{\infty} x \cdot x\phi(x)\,dx = \Bigl[-x\,\phi(x)\Bigr]_{-\infty}^{\infty} + \int_{-\infty}^{\infty} \phi(x)\,dx = 0 + 1 = 1,

since x ϕ(x)x\,\phi(x) vanishes at both ends. ■\blacksquare

Every Gaussian is a stretched and shifted standard one. If ZZ is standard, then X=μ+σZX = \mu + \sigma Z has mean μ\mu and variance σ2\sigma^2 by linearity and the scaling rule, and substituting x=μ+σzx = \mu + \sigma z in the area P(X≤t)=∫−∞(t−μ)/σϕ(z) dzP(X \le t) = \int_{-\infty}^{(t - \mu)/\sigma} \phi(z)\,dz turns it into ∫−∞t1σϕ((x−μ)/σ) dx\int_{-\infty}^{t} \tfrac{1}{\sigma}\phi\bigl((x - \mu)/\sigma\bigr)\,dx, whose integrand is exactly Equation 10. So a question about any Gaussian becomes a question about ZZ, by measuring distances from the mean in units of σ\sigma.

Thermal noise in a receiver is close to Gaussian because it is the sum of the tiny voltages of an enormous number of electrons moving independently. The central limit theorem says that for mutually independent terms with a common distribution of mean μ\mu and variance σ2\sigma^2, the probabilities of (X1+⋯+Xn−nμ)/(σn)(X_1 + \cdots + X_n - n\mu)/(\sigma\sqrt{n}) approach those of ZZ as nn grows, whatever that distribution is. Its proof needs tools beyond this chapter and is given by Grinstead and Snell [1]. The theorem also makes a binomial count with large nn look roughly Gaussian, with limits that the warning at the end of this section examines.

The Q-Function

For a Gaussian XX with mean μ\mu and standard deviation σ\sigma, P(X>μ+xσ)=Q(x)P(X > \mu + x\sigma) = Q(x), and by the symmetry of ϕ\phi the lower tail is the same, P(X<μ−xσ)=Q(x)P(X < \mu - x\sigma) = Q(x). In the opening example the noise must fall 1/0.5=21/0.5 = 2 standard deviations below its mean, so the error probability is Q(2)=0.02275Q(2) = 0.02275. Table 3 shows the error probability collapsing as the noise shrinks.

Table 3. Decision error for volt signals as the noise standard deviation shrinks

Noise σ\sigma (volts)Distance to threshold 1/σ1/\sigmaError probability Q(1/σ)Q(1/\sigma)
110.1587
0.520.02275
0.42.50.00621
1/31/330.00135
0.2543.167×10−53.167 \times 10^{-5}
0.252.867×10−72.867 \times 10^{-7}
1/61/669.866×10−109.866 \times 10^{-10}

Source: computed from the standard Gaussian and reproduced by ch02_probability_for_coding.py.

Halving the noise from 0.5 to 0.25 volt cuts the error probability by a factor of Q(2)/Q(4)=718Q(2)/Q(4) = 718. The same steep curve returns whenever coded and uncoded systems are compared later in the book.

The Q-function is not on a calculator's keyboard, so on paper it is bounded, and the bounds below are tight exactly where coding needs them, far out in the tail.

Proof. The upper bound uses t/x>1t/x > 1 for t>xt > x, so Q(x)=∫x∞ϕ(t) dt<∫x∞txϕ(t) dtQ(x) = \int_x^\infty \phi(t)\,dt < \int_x^\infty \tfrac{t}{x}\phi(t)\,dt. Since −ϕ-\phi has derivative t ϕ(t)t\,\phi(t), the last integral is 1x[−ϕ(t)]x∞=ϕ(x)/x\tfrac{1}{x}\bigl[-\phi(t)\bigr]_x^\infty = \phi(x)/x.

The lower bound starts from the derivative of ϕ(t)/t\phi(t)/t, which is (t ϕ′(t)−ϕ(t))/t2=−ϕ(t)(1+1/t2)\bigl(t\,\phi'(t) - \phi(t)\bigr)/t^2 = -\phi(t)\bigl(1 + 1/t^2\bigr). Integrating from xx to infinity gives ∫x∞(1+1/t2)ϕ(t) dt=ϕ(x)/x\int_x^\infty \bigl(1 + 1/t^2\bigr)\phi(t)\,dt = \phi(x)/x. For t>xt > x the factor 1+1/t21 + 1/t^2 is less than 1+1/x21 + 1/x^2, so ϕ(x)/x<(1+1/x2)Q(x)\phi(x)/x < \bigl(1 + 1/x^2\bigr) Q(x), which rearranges to Q(x)>x ϕ(x)/(1+x2)Q(x) > x\,\phi(x)/(1 + x^2).

For the last bound, substitute t=x+ut = x + u, so that Q(x)=∫0∞ϕ(x+u) duQ(x) = \int_0^\infty \phi(x + u)\,du. Expanding the square in the exponent, ϕ(x+u)=ϕ(u) e−x2/2 e−xu\phi(x + u) = \phi(u)\,e^{-x^2/2}\,e^{-xu}, and e−xu≤1e^{-xu} \le 1 for u≥0u \ge 0. Hence Q(x)≤e−x2/2∫0∞ϕ(u) du=12e−x2/2Q(x) \le e^{-x^2/2}\int_0^\infty \phi(u)\,du = \tfrac{1}{2}e^{-x^2/2}, because half the area of ϕ\phi lies to the right of 0. ■\blacksquare

Table 4. The Q-function and its bounds

xxLower x ϕ(x)1+x2\frac{x\,\phi(x)}{1+x^2}Q(x)Q(x)Upper ϕ(x)x\frac{\phi(x)}{x}12e−x2/2\frac{1}{2}e^{-x^2/2}
11.210×10−11.210 \times 10^{-1}1.587×10−11.587 \times 10^{-1}2.420×10−12.420 \times 10^{-1}3.033×10−13.033 \times 10^{-1}
22.160×10−22.160 \times 10^{-2}2.275×10−22.275 \times 10^{-2}2.700×10−22.700 \times 10^{-2}6.767×10−26.767 \times 10^{-2}
31.330×10−31.330 \times 10^{-3}1.350×10−31.350 \times 10^{-3}1.477×10−31.477 \times 10^{-3}5.554×10−35.554 \times 10^{-3}
43.149×10−53.149 \times 10^{-5}3.167×10−53.167 \times 10^{-5}3.346×10−53.346 \times 10^{-5}1.677×10−41.677 \times 10^{-4}
52.859×10−72.859 \times 10^{-7}2.867×10−72.867 \times 10^{-7}2.973×10−72.973 \times 10^{-7}1.863×10−61.863 \times 10^{-6}
69.853×10−109.853 \times 10^{-10}9.866×10−109.866 \times 10^{-10}1.013×10−91.013 \times 10^{-9}7.615×10−97.615 \times 10^{-9}

Source: computed from the standard Gaussian and reproduced by ch02_probability_for_coding.py.

Table 4 and Figure 7 show the squeeze. At x=6x = 6 the upper bound is only 1.026 times QQ, and QQ only 1.0013 times the lower bound. The simpler bound 12e−x2/2\tfrac{1}{2}e^{-x^2/2} is looser by a growing factor, but it shows the essential fall like e−x2/2e^{-x^2/2} with the easiest algebra to carry through a calculation.

Q(x) for x from 0 to 6 on a logarithmic scale, falling from one half to about one in a billion, squeezed between an upper and a lower bound that meet as x grows, with the looser bound one half of exp of minus x squared over 2 above all three. x tail probability 10−10 10−8 10−6 10−4 10−2 1 0 1 2 3 4 5 6 Q(x), the exact tail upper bound phi(x) / x lower bound x phi(x) / (1 + x squared) bound one half of exp(−x squared / 2)
Figure 7. The Q-function between its upper bound and lower bound , which close in as grows, with the simpler bound above. Data: computed by ch02_charts.py in the companion repository.

06.The Union Bound

The decoder for R3R_3 fails when some pair of bits both flip, which is the union of three events, "bits 1 and 2 flipped," "bits 1 and 3 flipped" and "bits 2 and 3 flipped." Each has probability p2=0.01p^2 = 0.01, so adding them gives 3p2=0.033p^2 = 0.03, against the exact 0.028. As Figure 8 shows, the sum counts the pattern 111 three times where the union counts it once, an excess of 2×0.001=0.0022 \times 0.001 = 0.002. Adding the probabilities of overlapping events can only overcount.

The three events that a particular pair of bits flipped, for the repetition code R3 on a channel with p = 0.1. Each event holds one two-flip pattern of probability 0.009 and the pattern 111 of probability 0.001, so adding the three events counts 111 three times and gives 0.03. The union holds each pattern once and has probability 0.028. bits 1 and 2 flipped bits 1 and 3 flipped bits 2 and 3 flipped the union 110101011 110101011 111111111 111 0.0090.0090.009 0.0010.0010.001 0.0090.0090.0090.001 0.0100.0100.010 sum of the three 0.030 111 counted three times union 0.028 = sum 0.030 minus the overcount 2 × 0.001
Figure 8. Adding the three pair events of at counts the pattern 111 three times, giving 0.030 against the union's 0.028. The overcount, , is why the union bound is an upper bound.

Proof. For two events, inclusion–exclusion gives P(A1∪A2)=P(A1)+P(A2)−P(A1∩A2)≤P(A1)+P(A2)P(A_1 \cup A_2) = P(A_1) + P(A_2) - P(A_1 \cap A_2) \le P(A_1) + P(A_2), since no probability is negative. Suppose the bound holds for m−1m - 1 events. Writing the union of mm events as the union of two, U=A1∪⋯∪Am−1U = A_1 \cup \cdots \cup A_{m-1} and AmA_m, the two-event case gives P(U∪Am)≤P(U)+P(Am)P(U \cup A_m) \le P(U) + P(A_m), and the assumption bounds P(U)P(U) by the sum of the first m−1m - 1 probabilities. By induction the bound holds for every mm. ■\blacksquare

Proof. At least tt flips occur exactly when some set of tt positions all flip. For each of the (nt)\binom{n}{t} sets SS of tt positions, the event "every bit in SS flipped" has probability ptp^t by mutual independence, whatever the other bits do. The union bound over all the sets gives the theorem. ■\blacksquare

The bound is excellent when errors are rare, because the overcount comes from outcomes lying in two events at once, which are rarer still. Server memory protects each 64-bit word with an 8-bit check, a 72-bit code that corrects one error and detects two [2]. If each stored bit is upset with probability q=10−6q = 10^{-6} between checks, independently, the chance of any error is at most 72q=7.2×10−572q = 7.2 \times 10^{-5}, against an exact 7.19974×10−57.19974 \times 10^{-5}, and the chance of two or more, beyond correction, is at most (722)q2=2.556×10−9\binom{72}{2} q^2 = 2.556 \times 10^{-9}, against an exact 2.55588×10−92.55588 \times 10^{-9}. The same bound gives the leading term of the previous chapter's R5R_5 formula, since five copies fail with three or more flips, at most (53)p3=10−5\binom{5}{3}p^3 = 10^{-5} at p=0.01p = 0.01 against an exact 9.8506×10−69.8506 \times 10^{-6}.

The bound is worthless when the events are common. For the previous chapter's server with 16 memory modules, each with an 8% chance of an error in a year, it gives 16×0.08=1.2816 \times 0.08 = 1.28, while the exact value under independence is 1−0.9216=0.73661 - 0.92^{16} = 0.7366. The union bound is a tool for rare events, the regime every working code is designed for.

07.The Chernoff Bound

Table 5 puts the tools of this chapter side by side on two tail probabilities, the chance of at least twice the mean number of errors in 1000 bits and in 10,000 bits on a channel with p=0.01p = 0.01.

Table 5. Bounds on twice the mean number of errors,

MethodP(X≥20)P(X \ge 20), n=1000n = 1000P(X≥200)P(X \ge 200), n=10,000n = 10{,}000
Markov0.50.5
Chebyshev0.0990.0099
Chernoff0.02001.008×10−171.008 \times 10^{-17}
Exact0.00328845.630×10−195.630 \times 10^{-19}
Gaussian approximation7.41×10−47.41 \times 10^{-4}4.6×10−244.6 \times 10^{-24}

Source: computed from the binomial distribution and the bounds in this chapter and reproduced by ch02_probability_for_coding.py.

Markov's bound does not improve with length at all, and Chebyshev's improves only in proportion to nn. The exact tail falls by a factor of more than 101510^{15} between the two columns, and only the Chernoff bound keeps pace, staying above the truth, as a bound must, by a factor of about 18 at n=10,000n = 10{,}000. The Gaussian approximation lands below the truth. Figure 9 shows the same contrast across a range of thresholds for the 1000-bit frame.

Bounds on the probability of at least k errors among 1000 bits with p = 0.01, for k from 11 to 40 on a logarithmic scale. Markov and Chebyshev stay near one in ten or above, while the Chernoff bound falls steeply and runs parallel to the exact tail a little above it. threshold k: at least k errors among n = 1000 bits at p = 0.01 probability 10−14 10−12 10−10 10−8 10−6 10−4 10−2 1 10 15 20 25 30 35 40 Markov Chebyshev Chernoff exact tail k = 20
Figure 9. Bounds on the probability of at least errors among 1000 bits with . Markov and Chebyshev flatten out, while the Chernoff bound falls with the exact tail and stays a little above it. Data: computed by ch02_charts.py in the companion repository.

The idea, due to Chernoff [3], is to apply Markov's inequality to esXe^{sX} for a positive number ss chosen afterward, since an exponential separates a tail value from the mean far more sharply than a line or a parabola can. For numbers aa and pp strictly between 0 and 1, the resulting exponent is the relative entropy of aa from pp, measured in natural logarithms,

D(a ∥ p)=aln⁡ap+(1−a)ln⁡1−a1−p.D(a \,\|\, p) = a \ln\frac{a}{p} + (1 - a)\ln\frac{1-a}{1-p}.

Proof. For any s>0s > 0 the function esxe^{sx} is increasing, so the event X≥anX \ge an is the same as esX≥esane^{sX} \ge e^{san}. Markov's inequality applied to the positive random variable esXe^{sX} gives P(X≥an)≤E[esX]/esanP(X \ge an) \le E[e^{sX}] / e^{san}.

Write X=X1+⋯+XnX = X_1 + \cdots + X_n with indicators. Then esX=esX1⋯esXne^{sX} = e^{sX_1} \cdots e^{sX_n}, a product of independent factors, so the product lemma, applied one factor at a time, gives E[esX]=∏iE[esXi]E[e^{sX}] = \prod_i E[e^{sX_i}]. Each factor is E[esXi]=(1−p)e0+p es=1−p+pesE[e^{sX_i}] = (1 - p)e^0 + p\,e^s = 1 - p + p e^s. Therefore

P(X≥an)≤((1−p+pes)e−sa)nfor every s>0.P(X \ge an) \le \Bigl( \bigl(1 - p + p e^s\bigr) e^{-sa} \Bigr)^n \quad \text{for every } s > 0.

The best ss minimizes the logarithm of the bracket, g(s)=ln⁡(1−p+pes)−sag(s) = \ln(1 - p + pe^s) - sa. Setting its derivative pes/(1−p+pes)−ape^s/(1 - p + pe^s) - a to zero and solving gives es=a(1−p)/(p(1−a))e^s = a(1-p)/\bigl(p(1-a)\bigr), which exceeds 1 because a>pa > p, so this ss is positive. With that choice, 1−p+pes=(1−p)+a(1−p)/(1−a)=(1−p)/(1−a)1 - p + pe^s = (1 - p) + a(1-p)/(1-a) = (1-p)/(1-a), and the bracket becomes

1−p1−a(p(1−a)a(1−p))a=(pa)a(1−p1−a)1−a=e−D(a∥p).\frac{1-p}{1-a} \left(\frac{p(1-a)}{a(1-p)}\right)^{a} = \left(\frac{p}{a}\right)^{a} \left(\frac{1-p}{1-a}\right)^{1-a} = e^{-D(a \| p)}.

Raising it to the power nn gives the theorem. ■\blacksquare

The bound has teeth because D(a ∥ p)>0D(a \,\|\, p) > 0 whenever a>pa > p. At s=0s = 0 the function gg equals ln⁡1=0\ln 1 = 0 and has slope p−a<0p - a < 0, so gg dips below zero for small positive ss, and its minimum, −D(a ∥ p)-D(a \,\|\, p), is negative. The probability that the fraction of flipped bits reaches aa therefore falls exponentially in nn, at a rate set by how far aa is from pp.

For the 1000-bit frame with p=0.01p = 0.01 and the threshold a=0.02a = 0.02, the optimal es=0.02×0.99/(0.01×0.98)=2.0204e^s = 0.02 \times 0.99 / (0.01 \times 0.98) = 2.0204, so s=0.7033s = 0.7033, and (1−p)/(1−a)=1.0102(1 - p)/(1 - a) = 1.0102. The exponent is D(0.02 ∥ 0.01)=0.02ln⁡2+0.98ln⁡(0.98/0.99)=0.0039136D(0.02 \,\|\, 0.01) = 0.02 \ln 2 + 0.98 \ln(0.98/0.99) = 0.0039136, so nD=3.9136nD = 3.9136 and the bound is e−3.9136=0.0200e^{-3.9136} = 0.0200. That is five times better than Chebyshev at this length, and multiplying the length by ten raises the exponent to 39.13639.136 and the bound to 1.008×10−171.008 \times 10^{-17}.

The Repetition Code, Again

The majority decoder of RnR_n, for odd nn, fails when more than half the copies flip, which implies X≥n/2X \ge n/2. Setting a=1/2a = 1/2 in the Chernoff bound gives an exponent that simplifies neatly,

D(12 ∥ p)=12ln⁡12p+12ln⁡12(1−p)=−12ln⁡(4p(1−p)),D\bigl(\tfrac{1}{2} \,\big\|\, p\bigr) = \tfrac{1}{2}\ln\frac{1}{2p} + \tfrac{1}{2}\ln\frac{1}{2(1-p)} = -\tfrac{1}{2}\ln\bigl(4p(1-p)\bigr),

and so

Pe(Rn)≤e−nD(1/2∥p)=(4p(1−p))n/2.P_e(R_n) \le e^{-n D(1/2 \| p)} = \bigl(4p(1-p)\bigr)^{n/2}.

That is the bound the previous chapter proved by a counting argument written for the occasion. At p=0.1p = 0.1, D(12 ∥ 0.1)=−ln⁡(0.36)/2=0.5108D(\tfrac{1}{2} \,\|\, 0.1) = -\ln(0.36)/2 = 0.5108, and for R25R_{25} the bound is 0.3612.5=2.843×10−60.36^{12.5} = 2.843 \times 10^{-6}, against an exact failure probability of 1.621×10−71.621 \times 10^{-7}. It is about eighteen times too large but has the right exponential rate, and it took one line. The relative entropy returns in Information and Entropy, which builds it from first principles, and in Capacity and Shannon's Theorem.

08.Looking Ahead

This chapter treated a channel as a list of flip probabilities. The next chapter, Channels, Signals and Likelihoods, opens the channel up. The binary symmetric channel is joined by the binary erasure channel, in which a bit is either delivered correctly or visibly lost, and the Z-channel, in which only one direction of flip occurs, as when charge leaks out of a memory cell but never in. The voltage example becomes the additive white Gaussian noise channel with binary phase-shift keying, together with signal space, the matched filter and the proof that the receiver built from them makes the fewest errors possible. The signal-to-noise ratio, measured in coding as the energy per bit over the noise density, Eb/N0E_b/N_0, replaces the bare σ\sigma of Table 3, and comparing hard decisions, which keep only the bit, with soft decisions, which keep the voltage, shows how much a threshold throws away.

Bayes' rule becomes the receiver's main tool. The probability of a received voltage given each possible bit is a likelihood, and the log-likelihood ratio packs everything the receiver knows about one bit into a single signed number. The warning about bursts becomes the Gilbert–Elliott channel, a two-state model that switches between a good state and a bad one, and the chapter closes with the fault models of memory, stuck-at faults, transient upsets and multi-bit upsets, which decide what a memory code must survive. Lin and Costello [4] treat this material at greater length.

09.Worked Examples

10.Exercises

References

  1. [1]Grinstead, Charles M. and Snell, J. Laurie (2006). “Grinstead and Snell's Introduction to Probability.” The CHANCE Project. Version dated 4 July 2006 of the second edition published by the American Mathematical Society, free under the GNU Free Documentation License. https://math.dartmouth.edu/~prob/prob/prob.pdf
  2. [2]Hsiao, M. Y. (1970). “A Class of Optimal Minimum Odd-weight-column SEC-DED Codes.” IBM Journal of Research and Development, 14(4), pp. 395–401. doi:10.1147/rd.144.0395
  3. [3]Chernoff, Herman (1952). “A Measure of Asymptotic Efficiency for Tests of a Hypothesis Based on the Sum of Observations.” The Annals of Mathematical Statistics, 23(4), pp. 493–507. doi:10.1214/aoms/1177729330
  4. [4]Lin, Shu and Costello, Jr., Daniel J. (2004). “Error Control Coding: Fundamentals and Applications.” 2nd edition. Pearson Prentice Hall.

— Anirban

Hardware–software at the seam where compilers meet microcode.

FeedbackBook modePaper
error-correction-codinginformation-and-channels