1.10 Entropy, Randomness, and Information

1.10.1 The Entropy Function

Definition 1.10.1 (Discrete Entropy).

The entropy in bits of a discrete random variable X is

H⁢(X)=−∑xPr⁡[X=x]⋅log2⁡Pr⁡[X=x],

where the summation is over the support of X, namely over all values x in the range of X. Equivalently,

H⁢(X)=𝔼[log2⁡1Pr⁡[X]].
Definition 1.10.2 (Binary Entropy).

The binary entropy function H⁢(p) for a random variable that assumes only two possible outcomes, one of which occurs with probability p, is

H⁢(p)=−p⁢log2⁡p−(1−p)⁢log2⁡(1−p).
Exercise 1.10.3 (Exercise 10.5 [MU17]).

If p is chosen uniformly at random from real interval [0,1], derive 𝔼[H⁢(p)].

Proof.

Since H⁢(p)=−p⁢log2⁡p−(1−p)⁢log2⁡(1−p) is symmetric, hence we derive the part on the left hand side by

−∫01p⁢log2⁡p⁢d⁢p=−1ln⁡2⁢∫01p⁢ln⁡p⁢d⁢p=−1ln⁡2⁢(12⁢p2⁢ln⁡p|01−∫0112⁢p2⋅1p⁢𝑑p)=14⁢ln⁡2,

where the second equality holds by integration by parts. Therefore, 𝔼[H⁢(p)]=1/(2⁢ln⁡2). ∎

Exercise 1.10.4 (Exercise 10.2 [MU17]).

Consider an n-sided die, where the ith face comes up with probability pi. Show that the entropy of a die roll is maximized when each face comes up with equal probability.

Proof.

Let X be the random variable for the face showing up for the n-sided die. The probability of the face showing up can be decided by a set of probabilities {pi}i∈I where |I|=n−1, such that k∉I and I∪{k}=[1,n].

On an index j∈I, take partial derivative over pj for H⁢(X),

∂∂pj⁢H⁢(X)=−∂∂pj⁢(pj⁢log2⁡pj)−∂∂pj⁢(pk⁢log2⁡pk)=−1ln⁡2⁢((ln⁡pj+1)−(ln⁡pk+1))=log2⁡pkpj,

where pk=1−∑i∈Ipi. By symmetry, k can be arbitrary over [1,n], hence if the partial derivative is 0 for any pair of j≠k, the only solution would be pi=1/n for any i∈[1,n]. ∎

Remark 1.10.5.

For a fair n-faced die, the entropy is log2⁡n bits of randomness.

Exercise 1.10.6 (Exercise 10.4 [MU17]).

Let pk=(k⁢ln2⁡k)−1, and show that S=∑k≥2pk is finite. Let integer-valued discrete random variable X has distribution Pr⁡[X=k]=pk/S for k≥2, show that H⁢(X) is unbounded.

Proof.

Let g⁢(k)=−(ln⁡k)−1, then g′⁢(k)=(k⁢ln2⁡k)−1. Hence,

S≤∫32∞1k⁢ln2⁡k⁢𝑑k=−1ln⁡k|32∞=1ln⁡3−ln⁡2, (1.9)

which is upper bounded by a bounded value. For the entropy, we have

H⁢(X)=∑k≥2log2⁡(S⁢k⁢ln2⁡k)S⁢k⁢ln2⁡k=1ln⁡2⁢∑k≥2ln⁡(S⁢k⁢ln2⁡k)S⁢k⁢ln2⁡k=1ln⁡2⁢∑k≥2(ln⁡SS⁢k⁢ln2⁡k1+1S⁢k⁢ln⁡k2+2⁢ln⁡ln⁡kS⁢k⁢ln2⁡k3).

The sum over the first term is bounded by eq. 1.9 or by definition of X. For the sum over the third term, the sum over the first few terms with 2≤k<6 is bounded. For k≥6, the sum over the third term is bounded by

∑k≥62⁢ln⁡ln⁡kS⁢k⁢ln2⁡k≤2S⁢∫5∞ln⁡ln⁡kk⁢ln2⁡k⁢𝑑k=2S⁢∫ln⁡5∞ln⁡uu2⁢𝑑u=2S⁢(−ln⁡uu|ln⁡5∞+∫ln⁡5∞1u2⁢𝑑u)=−2S⋅ln⁡u+1u|ln⁡5∞,

where u=ln⁡k, and the summation is finitely bounded. The sum over the second term is

∑k≥21S⁢k⁢ln⁡k≥1S⁢∫2∞1k⁢ln⁡k⁢𝑑k=1S⁢∫ln⁡2∞1u⁢𝑑u=1S⁢ln⁡u|ln⁡2∞,

which is unbounded. We conclude that H⁢(X) is unbounded. ∎

Lemma 1.10.7.

Let X1,X2 be independent random variables, and let Y=(X1,X2). Then H⁢(Y)=H⁢(X1)+H⁢(X2).

Proof.

Let X1 has support Ω1, and X2 has support Ω2. We show by

H⁢(Y) =−∑x1∈Ω1,x2∈Ω2Pr⁡[X1=x1,X2=x2]⋅log2⁡Pr⁡[X1=x1,X2=x2]
=−∑x1∈Ω1,x2∈Ω2Pr⁡[X1=x1]⋅Pr⁡[X2=x2]⋅(log2⁡Pr⁡[X1=x1]+log2⁡Pr⁡[X2=x2])
=−∑x1∈Ω1,x2∈Ω2(Pr⁡[X1=x1]⋅log2⁡Pr⁡[X1=x1]⋅Pr⁡[X2=x2]+Pr⁡[X2=x2]⋅log2⁡Pr⁡[X2=x2]⋅Pr⁡[X1=x1])
=−∑x1∈Ω1Pr⁡[X1=x1]⋅log2⁡Pr⁡[X1=x1]−∑x2∈Ω2Pr⁡[X2=x2]⋅log2⁡Pr⁡[X2=x2]=H⁢(X1)+H⁢(X2),

where the second and the last equality holds by the independence between X1 and X2. ∎

Exercise 1.10.8 (Exercise 10.6 [MU17]).

The conditional entropy H⁢(Y∣X) is defined by

H⁢(Y∣X)=−∑x,yPr⁡[X=x,Y=y]⋅log2⁡Pr⁡[Y=y∣X=x].

If Z=(X,Y), show that H⁢(Z)=H⁢(X)+H⁢(Y∣X).

Proof.

This can be seen as an extended version of lemma 1.10.7. We show by

H⁢(Z) =−∑x,yPr⁡[X=x,Y=y]⋅log2⁡Pr⁡[X=y,Y=y]
=−∑x,yPr⁡[X=x,Y=y]⋅(log2⁡Pr⁡[X=x]+log2⁡Pr⁡[Y=y∣X=x])
=−∑x,y(Pr⁡[X=x]⋅log2⁡Pr⁡[X=x]+Pr⁡[X=x,Y=y]⋅log2⁡Pr⁡[Y=y∣X=x])
=H⁢(X)+H⁢(Y∣X),

where the third equality holds by summing Pr⁡[X=x,Y=y] over y preserves the marginal probability of X. ∎

Corollary 1.10.9 (Chain Rule of Conditional Entropy).
H⁢(X1,…,Xn)=∑i∈[1,n]H⁢(Xi∣X1,…,Xi−1).
Corollary 1.10.10 (Bayes’ Rule of Conditional Entropy).
H⁢(Y∣X)=H⁢(X∣Y)+H⁢(Y)−H⁢(X).
Definition 1.10.11 (Mutual Information).

The mutual information of a pair of random variables (X,Y) is defined by

I⁢(X;Y)=H⁢(X)−H⁢(X∣Y)=H⁢(Y)−H⁢(Y∣X).
Remark 1.10.12.

For mutual information in definition 1.10.11, we can expand the expression by

H⁢(Y)−H⁢(Y∣X) =−∑yPr⁡[Y=y]⋅log2⁡Pr⁡[Y=y]+∑x,yPr⁡[Y=y,X=x]⋅log2⁡Pr⁡[Y=y∣X=x]
=−∑x,yPr⁡[Y=y,X=x]⋅log2⁡Pr⁡[Y=y]+∑x,yPr⁡[Y=y,X=x]⋅log2⁡Pr⁡[Y=y∣X=x]
=−∑x,yPr⁡[Y=y,X=x]⋅(log2⁡Pr⁡[Y=y]−log2⁡Pr⁡[Y=y∣X=x])
=−∑x,yPr⁡[Y=y,X=x]⋅(log2⁡Pr⁡[Y=y]+log2⁡Pr⁡[X=x]−log2⁡Pr⁡[Y=y,X=x])
=∑x,yPr⁡[Y=y,X=x]⋅log2⁡Pr⁡[Y=y,X=x]Pr⁡[Y=y]⋅Pr⁡[X=x].
Definition 1.10.13 (KL Divergence [KL51]).

The Kullback-Leibler (KL) divergence is a statistical distance defined as

D𝖪𝖫⁢(P∥Q)=∑xP⁢(x)⋅log2⁡P⁢(x)Q⁢(x).
Remark 1.10.14 (Mutual Information as KL Divergence).

In KL divergence by definition 1.10.13 and mutual information with remark 1.10.12, if we consider 𝒟(X,Y), that is the joint distribution of (X,Y), and 𝒟X×𝒟Y, which is the marginal distribution of (X,Y), mutual information fits into KL divergence by

D𝖪𝖫⁢(𝒟(X,Y)∥𝒟X×𝒟Y)=I⁢(X;Y).

Moreover, we can again expand the expression in remark 1.10.12 by

H⁢(Y)−H⁢(Y∣X) =∑x,yPr⁡[Y=y,X=x]⋅log2⁡Pr⁡[Y=y,X=x]Pr⁡[Y=y]⋅Pr⁡[X=x]
=∑x,yPr⁡[Y=y∣X=x]⋅Pr⁡[X=x]⋅log2⁡Pr⁡[Y=y∣X=x]Pr⁡[Y=y]
=∑xPr⁡[X=x]⋅(∑yPr⁡[Y=y∣X=x]⋅log2⁡Pr⁡[Y=y∣X=x]Pr⁡[Y=y])
=𝔼[D𝖪𝖫⁢(𝒟Y∣X∥𝒟Y)],

where 𝒟Y∣X is conditional distribution of Y given X with distribution 𝒟X.

Lemma 1.10.15 (Gibbs’ Inequality).

Given 2 distributions P and Q over the same support,

D𝖪𝖫⁢(P∥Q)≥0.
Proof.

By Jensen’s inequality theorem 1.2.5,

∑x∈ΩP⁢(x)⋅log2⁡Q⁢(x)P⁢(x)≤log2⁡(∑x∈ΩP⁢(x)⋅Q⁢(x)P⁢(x))=0.

∎

Corollary 1.10.16 (Monotonicity of Conditional Entropy).
H⁢(Y∣X)≤H⁢(Y).

1.10.2 Entropy and Binomial Coefficients

For lemma 1.7.1, we give a tighter version as follows, to be used soon.

Lemma 1.10.17 (Tighter Stirling’s Formula).
2⁢π⁢n⁢(ne)n≤n!≤2⁢π⁢n⁢(ne)n⋅exp⁡(112⁢n).
Lemma 1.10.18.

For an integer n⁢q∈[0,n], we have

2n⁢H⁢(q)2⁢n≤(nn⁢q)≤2n⁢H⁢(q).
Proof.

We begin with the upper bound. Since

1=(q+(1−q))n≥(nn⁢q)⁢qn⁢q⁢(1−q)n⁢(1−q),

then

log2⁡(nn⁢q)≤−n⁢q⁢log2⁡q−n⁢(1−q)⁢log2⁡(1−q)=n⁢H⁢(q).

The lower bound is trivial when n=1, and it is also trivial when q=0 or 1 for n≥2. We derive the lower bound for n≥2 and q∈(0,1) using the following upper and lower bounds by lemma 1.10.17:

n! ≥2⁢π⁢n⁢(ne)n
(n⁢q)! ≤2⁢π⁢n⁢q⋅(n⁢qe)n⁢q⋅exp⁡(112⁢n⁢q)
(n⁢(1−q))! ≤2⁢π⁢n⁢(1−q)⋅(n⁢(1−q)e)n⁢(1−q)⋅exp⁡(112⁢n⁢(1−q)),

and therefore

(nn⁢q)≥12⁢π⁢n⁢q⁢(1−q)⋅exp⁡(−112⁢n⁢q⁢(1−q))⋅(1q)n⁢q⋅(11−q)n⁢(1−q)=2n⁢H⁢(q)2⁢π⁢n⁢q⁢(1−q)⋅exp⁡(−112⁢n⁢q⁢(1−q)). (1.10)

Let k=q⁢(1−q) such that 0<k≤1/4, then

dd⁢k⁢(1k⋅exp⁡(−112⁢n⁢k))=−12⁢k3/2⋅exp⁡(−112⁢n⁢k)+1k⋅exp⁡(−112⁢n⁢k)⋅112⁢n⁢k2=1k3/2⋅exp⁡(−112⁢n⁢k)⋅(112⁢n⁢k−12),

which is negative for k≥(6⁢n)−1, and k≥(n−1)/n2≥(6⁢n)−1 when q∈(0,1), so eq. 1.10 is minimized when k=1/4, giving

(nn⁢q)≥2n⁢H⁢(q)π⁢n/2⋅exp⁡(−13⁢n).

Moreover,

(2⁢nπ⁢n/2)⋅exp⁡(−13⁢n)=8π⋅exp⁡(−13⁢n)>1

for all n≥1, then

(nn⁢q)≥2n⁢H⁢(q)2⁢n.

∎

Corollary 1.10.19.

When 0≤q≤1/2,

2n⁢H⁢(q)2⁢n≤(n⌈n⁢q⌉),(n⌊n⁢q⌋)≤2n⁢H⁢(q).

When 1/2≤q≤1,

2n⁢H⁢(q)2⁢n≤(n⌊n⁢q⌋),(n⌈n⁢q⌉)≤2n⁢H⁢(q).

1.10.3 Entropy: A Measure of Randomness

Definition 1.10.20 (Variable-Length Fair-Bit Extraction Function).

Let |𝐲| be the number of bits in a sequence of bits 𝐲. An extraction function 𝖤𝗑𝗍 takes as input the value of a random variable X, and outputs a sequence of bits. For every sequence of bits 𝐲 with |𝐲|=k,

Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲∣|𝖤𝗑𝗍⁢(X)|=k]=2−k,

whenever Pr⁡[|𝖤𝗑𝗍⁢(X)|=k]>0.

Remark 1.10.21.

We can view the input X as the outcomes of n biased coin flips, and the output 𝐲 as k fair coin flips. In this sense, if the biased coin comes up heads with probability p, the entropy of the input is n⁢H⁢(p), which is the maximum possible expected number of fair bits that any extraction function can output.

There is no guarantee that 𝖤𝗑𝗍 is efficient (runs in polynomial time).

Example 1.10.22.

Consider a construction of 𝖤𝗑𝗍 for X uniformly distributed over [0,11]. The elements in [0,7] can be represented in 3 bits, while we can associate the 4 probabilities in [8,11] with 2 bits. Associate each input [0,11] to each 2 or 3 bit output, such that they output with the same probability. Hence, the probability of outputting 3 bits is 2/3, while the probability of outputting 2 bits is 1/3, and

Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲∣|𝖤𝗑𝗍⁢(X)|=k]=2−k

for k being 2 or 3, such that definition 1.10.20 is satisfied.

Theorem 1.10.23.

Suppose the value of a random variable X is uniform over [0,m−1], such that H⁢(X)=log2⁡m, then there is an extraction function for X that outputs on average at least ⌊log2⁡m⌋−1=⌊H⁢(X)⌋−1 independent and unbiased bits.

Proof.

Suppose m is a power of 2, the extraction function trivially outputs the value’s ⌊log2⁡m⌋ bits representation.

In the general case where m is not a power of 2, we first show in an inductive way. Let α=⌊log2⁡m⌋, Y be the random variable for the length of output bits, and for the elements in [2α,m−1], the theorem 1.10.23 still holds, that

𝔼[Y]≥2αm⁢α+m−2αm⁢(⌊log2⁡(m−2α)⌋−1)=α−m−2αm⁢(α−⌊log2⁡(m−2α)⌋+1).

Let β=⌊log2⁡(m−2α)⌋, then since

2β+12β+1+2α≥m−2αm≥2β2β+2α,

we have

𝔼[Y]≥α−m−2αm⁢(α−β+1)≥α−2β+12β+1+2α⁢(α−β+1)=α−11+2α−β−1⁢(α−β+1)≥α−1,

as 2α−β−1≥α−β holds for any α>β.

We show in an explicit construction. Consider k distinct indices {βi}i∈[1,k]⊆[0,α] in descending order, satisfying

m=∑i∈[1,k]2βi,si=∑j∈[1,i]2βj,

such that [0,m−1] is partitioned into k subsets, and the ith subset is [si−1,si−1], of size 2βi, then

𝔼[Y]=∑i∈[1,k]2βim⁢βi,

and since β1=α,

𝔼[Y]−(α−1)=2β1m+∑i∈[2,k]2βim⁢(βi−(α−1))=1m⁢(2β1−∑i∈[2,k]2βi⁢((α−1)−βi)).

Considering

2β1−∑i∈[2,k]2βi⁢((α−1)−βi)≥2α−∑i∈[0,α−2]2i⋅(α−1−i)=2α−((2α−1)−α)=α+1>0,

then 𝔼[Y]>α−1. ∎

Exercise 1.10.24 (Exercise 10.9 [MU17]).

We have shown in theorem 1.10.23 that an extraction function for a random variable X uniform over [0,m−1] extracts on average at least ⌊H⁢(X)⌋−1 unbiased bits. Show that there is an extraction function for {Xi}i∈[1,k] independent random variables uniform over [0,m−1] extracting on average at least k⁢⌊H⁢(X)⌋−1 unbiased bits.

Proof.

Apparently, one can invoke k times the extraction function in theorem 1.10.23, and by linearity of expectation, outputting on average at least k⁢⌊H⁢(X)⌋−k unbiased bits. The idea is to construct W over [0,mk−1] by

W=X1+m⁢X2+m2⁢X3+⋯+mk−1⁢Xk,

and H⁢(W)=H⁢(X1,…,Xk)=k⁢log2⁡m. The average number of output bits by theorem 1.10.23 is

⌊k⁢log2⁡m⌋−1≥k⁢⌊log2⁡m⌋−1.

∎

Exercise 1.10.25 (Exercise 10.10 [MU17]).

Suppose we have an oracle of generating independent fair coin flips, and m is not a power of 2.

  • •

    Show that one cannot uniformly sample over [0,m−1] with exactly k fair coin flips, for any fixed k.

  • •

    Show that one cannot uniformly sample over [0,m−1] with at most k fair coin flips, for any fixed k.

  • •

    Give an algorithm using fair coins to sample uniformly over [0,m−1], with expected flips at most 2⁢⌈log2⁡m⌉.

Proof.

We first rule out the case that 2k<m, as it is impossible to associate 2k outcomes with m numbers.

If one tries to uniformly sample over [0,m−1] with exactly k fair coins, m∤2k as m is not a power of 2, and one cannot associate m numbers with 2k outcomes in an equal-sized partition manner.

In the at most k flips case, pad each execution to exactly k flips: if the algorithm stops after ℓ flips with ℓ<k, then all 2k−ℓ possible continuations are counted as producing the same outcome. Hence each output a corresponds to some integer number Na of the 2k length-k bit strings, so

Pr⁡[outputting ⁢a]=Na⋅2−k.

Uniformity requires Na/2k=1/m for every a, so m∣2k, which is impossible because m is not a power of 2, failing in the same manner as the exact k tosses.

An algorithm sampling uniformly over [0,m−1] is rejection sampling: keep tossing ⌈log2⁡m⌉ fair coins, until the outputting integer is within range [0,m−1]. A round being rejected has probability at most 1/2, and the expected number of rounds is therefore at most 2, thus the expected runtime is at most 2⁢⌈log2⁡m⌉. ∎

Exercise 1.10.26 (Exercise 10.11 [MU17]).

Suppose we have an oracle of generating independent fair coin flips.

  • •

    Give an algorithm using the fair coin that simulates flipping a biased coin that comes up heads with probability p. The expected number of flips should be at most 2.

  • •

    Give an algorithm using the coin to sample uniformly over [0,m−1] with expected flips at most ⌈log2⁡m⌉+2.

Proof.

Write p into its binary form, such that there exists bits {bi}i≥1, to binary decompose p into the form ∑i≥1bi/2i. Keep tossing independent fair coins {Xi}i≥1 until Xi≠bi. If Xi>bi, the biased coin comes up tails, otherwise heads. Since Pr⁡[Xi≠bi]=1/2, the expected number of sampling is at most 2, as there might be finite number of {bi}i≥1.

A first attempt at sampling uniformly over [0,m−1] is an extension of the biased coin sampling, with probability m/2α the biased coin comes up heads, where α=⌈log2⁡m⌉. In each attempt, fair coins are tossed sequentially, and they are used both to simulate the biased coin, and maintained as the prefix of an α-bit integer.

  • •

    If the biased coin comes up tails, then any completion of the current prefix ties to an integer at least m, so restart.

  • •

    If the biased coin comes up heads, the generated number is within [0,m−1]; keep tossing until α fair coins have been sampled, and output the resulting α-bit integer.

Let Ai=(Yi,Zi) be the random variable for the ith biased coin simulation, where Yi is the number of fair coins tossed, and Zi is the outcome of the biased coin simulation. Let T be a stopping time for A1,A2,… on the first heads of the biased coin. Then the total number of fair coin flips is

W=∑i∈[1,T]Yi+(α−YT)=∑i∈[1,T−1]Yi+α.

Since Zi is heads with probability m/2α, then 𝔼[T]=2α/m≤2. Moreover, for each Yi,

𝔼[Yi]=∑k∈[1,α]k2k+α2α=2−22α.

Since 𝔼[T] and 𝔼[Yi] are both bounded, by theorem 1.13.18,

𝔼[∑i∈[1,T]Yi]=𝔼[Yi]⋅𝔼[T]=2αm⋅(2−22α).

By linearity of expectation,

𝔼[W]=2αm⋅(2−22α)+α−𝔼[YT]≤α+2⋅2α−1m−1≤α+3

where the second inequality holds by 𝔼[YT]≥1, and the last inequality holds by 2α−1<m≤2α.

This falls short of the desired α+2 bound, because rejected attempts discard all previously sampled bits. We now give a recycling version that keeps the remaining randomness after rejection. Consider the following algorithm:

  • •

    Let c←0 and v←1. Keep looping:

    • –

      Sample b←r{0,1}, and update c←c×2+b, v←v×2.

    • –

      Continue looping if v<m, otherwise if v≥m:

      • *

        If c≥m, update c←c−m, v←v−m.

      • *

        Otherwise, output c.

The invariant here is c is always uniform over [0,v−1], and the algorithm is rejection sampling over [0,m−1].

Indeed, if c is uniform over [0,v−1], then after sampling b←r{0,1}, the value 2⁢c+b is uniform over [0,2⁢v−1]. On v≥m, conditioning on c<m gives a uniform output over [0,m−1]; conditioning on c≥m makes c−m uniform over [0,v−m−1], preserving the invariant.

The new algorithm always runs α steps up to the first comparison against m, then let T be the step for the output. We have the following observation: At the tth step, we have 2t possible bit strings, separated into 2 classes:

  • •

    Resolved prefixes: On reading the prefix of a t-bit string, the algorithm stops at some bit and outputs a sample. Any continuation for a resolved prefix is considered stopped.

  • •

    Unresolved prefixes: The algorithm does not output after consuming all of the t bits as inputs.

Lemma 1.10.27.

After the first α bits, the unresolved prefixes at the tth step form a possibly empty interval [⌊2t/m⌋⁢m,2t−1].

Proof.

We prove by induction. Let qt=⌊2t/m⌋. When t=α, the unresolved prefixes are [m,2α−1], since qα=1.

Suppose the claim holds for t=t′. After tossing one more fair coin, each unresolved prefix has two continuations, so before the next rejection step the unresolved interval doubles to

[2⁢qt′⁢m,2t′+1−1].

Once the algorithm sees an entire block of size m in the interval at the bottom of the interval, the block is removed, as that goes to the new resolved prefixes. Hence the unresolved interval that remains is

[qt′+1⁢m,2t′+1−1].

This proves the induction step. ∎

With lemma 1.10.27, we upper bound the number of unresolved prefixes at the tth step vt by m, and thus

𝔼[T] =∑t≥0Pr⁡[T>t]=α+∑t≥αPr⁡[T>t]
=α+Pr⁡[T>α]+∑t>αPr⁡[T>t]
≤α+2α−m2α+∑t≥α+1m2t=α+1.

The last equality can be roughly relaxed to an upper bound of α+2, as m/2t≤1/2 for t>α, and the sum of the last 2 terms is upper bounded by 2. ∎

Theorem 1.10.28.

Suppose a coin comes up heads with probability p>1/2. For any constant δ>0 and sufficiently large n,

  • •

    There exists an extraction function that on input sequences of n independent flips, outputs an average of at least (1−δ)⁢n⁢H⁢(p) independent random bits.

  • •

    The average number of bits output by any extraction function on an input of n independent flips is at most n⁢H⁢(p).

Proof.

We begin by describing an extraction function that extracts on average at least (1−δ)⁢n⁢H⁢(p) random bits from n flips of the biased coin. After n flips, the number of heads coming up concentrates around n⁢p, which means the outcome is most likely to be one of the (nn⁢p) sequences with n⁢p heads up.

Conditioned that k heads coming up, the sequence with k heads is uniformly distributed over all (nk) sequences, which can be bijectively mapped to [0,(nk)−1]. We apply the randomness extraction function for uniform random variable in theorem 1.10.23 to extract on average ⌊log2⁡(nk)⌋−1 fair bits. Moreover, by lemma 1.10.18, we bound the number of fair bits within the range of [(1−δ)⁢n⁢H⁢(q),n⁢H⁢(q)], where q=k/n.

We now formalize the derivation of the bounds for the number of fair bits extracted from n flips of biased coins with probability p coming up heads. Let Z be a random variable representing the number of heads flipped, and let B be the random variable representing the bits extracted by the extraction function, then by conditional expectation,

𝔼[B]=∑x∈[0,n]Pr⁡[Z=x]⋅𝔼[B∣Z=x],

and by theorem 1.10.23,

𝔼[B∣Z=x]≥⌊log2⁡(nx)⌋−1.

Now consider the fact that the number of heads concentrates around n⁢p, to lower bound the average number of fair bits extracted, we consider only x∈[⌈(p−ε)⁢n⌉,⌊(p+ε)⁢n⌋], where ε≤min⁡(p−1/2,1−p). By monotonicity,

𝔼[B∣Z=x]≥⌊log2⁡(nx)⌋−1≥⌊log2⁡(n⌊n⁢(p+ε)⌋)⌋−1=𝔼[B∣Z=⌊n⁢(p+ε)⌋]. (1.11)

By standard Chernoff’s bound, let γ=ε/p and μ=n⁢p,

Pr⁡[|Z−n⁢p|≥ε⁢n]≤(e−γ(1−γ)1−γ)μ+(eγ(1+γ)1+γ)μ≤exp⁡(−n⁢ε23⁢p)+exp⁡(−n⁢ε22⁢p).

Alternatively, by KL Divergence driven Chernoff’s bound in 1.4.4,

Pr⁡[|Z−n⁢p|≥ε⁢n]≤2⁢exp⁡(−2⁢n⁢ε2).

Moreover, we can further lower bound eq. 1.11 by theorem 1.10.23, that

𝔼[B∣Z=⌊n⁢(p+ε)⌋]≥⌊log2⁡(n⌊(p+ε)⁢n⌋)⌋−1≥log2⁡(n⌊(p+ε)⁢n⌋)−2≥log2⁡2n⁢H⁢(p+ε)2⁢n−2=n⁢H⁢(p+ε)−12⁢log2⁡n−3. (1.12)

Therefore,

𝔼[B] ≥∑x∈[⌈(p−ε)⁢n⌉,⌊(p+ε)⁢n⌋]Pr⁡[Z=x]⋅𝔼[B∣Z=x]
≥Pr⁡[|Z−n⁢p|≤ε⁢n]⋅𝔼[B∣Z=⌊(p+ε)⁢n⌋]
≥(1−2⁢exp⁡(−2⁢n⁢ε2))⋅(n⁢H⁢(p+ε)−12⁢log2⁡n−3),

where the last inequality holds by eq. 1.12. We conclude that, for any δ>0, we have

𝔼[B]≥(1−δ)⁢n⁢H⁢(p)

for sufficiently small ε and sufficiently large n.

We now show no extraction function on average obtains more than n⁢H⁢(p) fair bits. Suppose input bits 𝐱 occurs with probability q, and the extraction function outputs 𝐲 corresponding to input 𝐱, then by definition 1.10.20,

Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲∣|𝖤𝗑𝗍⁢(X)|=k]=2−k,

that conditioned the output number of bits from the extraction function is k, the probability of outputting 𝐲 is 2−k. Hence, for a fixed 𝐲 with k bits, the probability of outputting 𝐲 is immediate by the probability of outputting k bits,

Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲]=Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲,|𝖤𝗑𝗍⁢(X)|=k]=2−k⋅Pr⁡[|𝖤𝗑𝗍⁢(X)|=k]≤2−k.

Moreover, since

Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲]≥Pr⁡[X=𝐱]=q,

then q≤2−k, giving an upper bound on k≤−log2⁡q. Therefore,

𝔼[B]=∑𝐱Pr⁡[X=𝐱]⋅𝔼[B∣X=𝐱]≤−∑𝐱Pr⁡[X=𝐱]⋅log2⁡Pr⁡[X=𝐱]=H⁢(X)=n⁢H⁢(p),

where the second inequality is by upper bounding the output length, and the last equality holds by lemma 1.10.7. ∎

Exercise 1.10.29 (Exercise 10.12 [MU17]).

Consider the extraction function 𝒜 whose input is a sequence of n independent flips of a coin that comes up heads with probability p>1/2. Break the sequence X1,…,Xn into ⌊n/2⌋ pairs, such that Ai=(X2⁢i−1,X2⁢i), and consider the pairs in order. If Ai is heads and tails, it outputs a 0; if Ai is tails and heads, it outputs a 1; otherwise, move up to the next pair.

  • •

    Show that the bits extracted by 𝒜 are independent and unbiased, and the expected number of bits extracted is

    ⌊n/2⌋⁢2⁢p⁢(1−p)≈n⁢p⁢(1−p).
  • •

    We derive another set of flips Y1,… from X1,…,Xn: Let j,k be 1, and repeat until j>⌊n/2⌋: If Aj is both heads, Yk is heads and increment j and k; if Aj is both tails, Yk is tails and increment j and k; otherwise increment j.

    The intuition here is to take some randomness 𝒜 cannot use effectively and reuse it. Show that the bits produced by running 𝒜 over Y1,… are independent and unbiased, and further argue that they are independent of those produced by running 𝒜 over X1,…,Xn.

  • •

    We derive another set of flips Z1,…,Z⌊n/2⌋ from X1,…,Xn: Zi is heads if Ai is both heads or tails, otherwise tails. Show that the bits produced by running 𝒜 over Z1,…,Z⌊n/2⌋ are independent and unbiased, and further argue that they are independent of those produced by running 𝒜 over X1,…,Xn, and Y1,….

  • •

    After we run 𝒜 over Y1,… and Z1,…,Z⌊n/2⌋, we can recursively derive two further sequences from each of the sequences, namely Y1,… and Z1,…,Z⌊n/2⌋, in the same way, run 𝒜 on those, and so on.

    Let A⁢(p) be the average number of bits extracted for each flip in the sequence X1,…,Xn, in the limit as the length of the sequence X1,…,Xn goes to infinity. Let q=1−p, and argue that A⁢(p) satisfies the recurrence

    A⁢(p)=p⁢q+p2+q22⁢A⁢(p2p2+q2)+12⁢A⁢(p2+q2).
  • •

    Show that H⁢(p) satisfies the same recurrence as A⁢(p).

Proof.

First, for the bits directly extracted by 𝒜, since the Ai are mutually independent, and for Ai=(X2⁢i−1,X2⁢i), the biased coin tosses are mutually independent, each output bit by 𝒜 is independent of the others. The probability of a bit sampled by 𝒜 being 1 is the same as the probability of a bit sampled by 𝒜 being 0; both are p⁢(1−p), requiring a head and a tail in Ai, so the bits are unbiased. Since a bit is output with probability 2⁢p⁢(1−p) by 𝒜, by linearity of expectation, the expected number of bits extracted is ⌊n/2⌋⁢2⁢p⁢(1−p).

To show the bits produced by 𝒜 over Y1,… are independent and unbiased, we first show Y1,… are independent. Since X1,…,Xn are independent, then A1,…,A⌊n/2⌋ are independent. Since the retained Ai are both heads or both tails, then Y1,… are independent, so are the output by 𝒜 over Y1,…. To show the outputs by 𝒜 from Y1,… are unbiased, since each Yi can be modeled by a biased coin with probability p2/(p2+q2) coming up heads, applying the same argument for 𝒜 producing unbiased bits over X1,…,Xn, the outputs by 𝒜 over Y1,… are unbiased.

To show the bits produced by 𝒜 over Y1,… are independent of the bits produced by 𝒜 over X1,…,Xn, observe that the former uses only the same-faced Ai, while the latter uses only the distinct-faced Ai. In the latter case, HT and TH are equally likely, and the corresponding Ai are independent across index i. In the former case, the same-faced Ai are independent across index i, and the values of these Ai are independent of the orders of the distinct-faced Ai. Hence, the bits extracted by 𝒜 over Y1,… are independent of the bits extracted by 𝒜 over X1,…,Xn.

To show the bits produced by 𝒜 over Z1,…,Z⌊n/2⌋ are independent and unbiased, we show Z1,…,Z⌊n/2⌋ are independent of each other, as A1,…,A⌊n/2⌋ are independent. Each Zi can be modeled by a biased coin coming up heads with probability p2+q2, then the bits extracted by 𝒜 are independent and unbiased.

To show the bits produced by 𝒜 over Z1,…,Z⌊n/2⌋ are independent of the bits from 𝒜 over X1,…,Xn, for a bit produced by 𝒜 over Z1,…,Z⌊n/2⌋, supposing it is extracted through (Zi,Zi+1), which are determined by (Ai,Ai+1), then it is possible that the bit overlaps with the bits extracted over Ai and/or Ai+1. Since the Ai are independent of each other, then all the other bits extracted over X1,…,Xn are independent of the bit extracted over (Zi,Zi+1). Conditioned that the bit extracted over (Zi,Zi+1) overlaps with the bit extracted from Ai, then Ai can be HT or TH, the bit extracted from Ai can be 0 or 1, and Zi is tails regardless, and thus the bit extracted over (Zi,Zi+1) is 1, which is independent of the bit extracted from Ai. Symmetrically, if the bit extracted over (Zi,Zi+1) overlaps with the bit extracted over Ai+1, the same argument applies, that the bit extracted over (Zi,Zi+1) is 0.

To show the bits produced by 𝒜 over Z1,…,Z⌊n/2⌋ are independent of the bits from 𝒜 over Y1,…, the strategy is similar to the last independence argument. Supposing a bit is extracted through (Zi,Zi+1), determined by (Ai,Ai+1), then by Ai being independent of each other, it suffices to only argue that the bit is independent of the bit extracted from Y1,… using a Yj that comes from Ai or Ai+1. Supposing Aj is overlapped, regardless of Aj being HH or TT, Zj is heads, and the bit extracted from (Zj,Zj+1) is 0, independent of the bit extracted using Yj. Symmetrically, if the overlap is with the second coordinate, then that coordinate is heads, and the bit extracted from the Z pair is 1.

For Y1,…, the biased coin comes up heads with probability p2/(p2+q2), and the expected number of retained Yi is (p2+q2)⁢n/2. For Z1,…,Z⌊n/2⌋, the biased coin has probability p2+q2 of coming up heads. For 𝒜 directly extracting from X1,…,Xn, the expected number of bits extracted is ⌊n/2⌋⁢2⁢p⁢q≈n⁢p⁢q. Thus, when n→∞, the average number of bits extracted per flip approaches

p⁢q+p2+q22⁢A⁢(p2p2+q2)+12⁢A⁢(p2+q2).

To show that A⁢(p)=H⁢(p), we have

p2+q22⁢H⁢(p2p2+q2) =−p2⁢log2⁡p−q2⁢log2⁡q+p2+q22⁢log2⁡(p2+q2),
12⁢H⁢(p2+q2) =−p2+q22⁢log2⁡(p2+q2)−p⁢q⁢log2⁡(2⁢p⁢q),

and finally

A⁢(p) =p⁢q−p2⁢log2⁡p−q2⁢log2⁡q−p⁢q⁢log2⁡(2⁢p⁢q)
=−p2⁢log2⁡p−q2⁢log2⁡q−p⁢q⁢log2⁡p⁢q
=−(p2+p⁢q)⁢log2⁡p−(q2+p⁢q)⁢log2⁡q
=−p⁢log2⁡p−q⁢log2⁡q=H⁢(p).

∎

Remark 1.10.30.

1.10.29 is called the Peres extractor [Von51, Eli72, Per92]. The von Neumann method [Von51] extracts the bits pairwise from X1,…,Xn, but throws away the randomness from the structure of the bit string, and there are two leftover sources of randomness: One is the structure of both heads or both tails, which gives Y1,…, and the other is the structure of being equal or not, which gives Z1,…,Z⌊n/2⌋. The von Neumann method took care of the symmetry case of a head and a tail, and the two leftovers are taken care of in the Peres extractor.

Exercise 1.10.31 (Exercise 10.13 [MU17]).

Suppose we only have a biased 6-sided die with entropy h>0 instead of a fair coin. Modify the extraction function in theorem 1.10.28 so that it extracts, on average, almost h random bits per roll from a sequence of die rolls.

Proof.

We consider a variant construction based on theorem 1.10.28, where we roll the die n times. Conditioned on seeing nk occurrences of the kth face, the sequence is uniformly distributed over all

N=(nn1;n2;n3;n4;n5;n6)

sequences. We apply the theorem 1.10.23 extractor to extract the random variable uniform over [0,N−1].

Let Zk be the random variable for the number of times the kth face comes up, pk be the probability that the kth face comes up, and B be the random variable for the bits extracted. Define

𝒯ε={(n1,…,n6):∑k∈[1,6]nk=n, and ⁢∀k∈[1,6],|nk−n⁢pk|≤ε⁢n}.

By conditional expectation,

𝔼[B] =∑n1,…,n6𝔼[B∣Z1=n1,…,Z6=n6]⋅Pr⁡[Z1=n1,…,Z6=n6]
≥min(n1,…,n6)∈𝒯ε⁢𝔼[B∣Z1=n1,…,Z6=n6]⋅(1−∑k∈[1,6]Pr⁡[|Zk−n⁢pk|≥ε⁢n])
≥min(n1,…,n6)∈𝒯ε⁡(⌊log2⁡(nn1;…;n6)⌋−1)⋅(1−∑k∈[1,6]Pr⁡[|Zk−n⁢pk|≥ε⁢n]),

where the second inequality holds by union bounding, and the third inequality holds by theorem 1.10.23.

We now consider a variant of lemma 1.10.18 for the biased 6-sided die.

Lemma 1.10.32.

For integers {n⁢qi}i∈[1,6] in [0,n] and ∑i∈[1,6]qi=1, we have

12⁢n5/2⋅2n⁢H⁢(q1,…,q6)≤(nn⁢q1;…;n⁢q6)≤2n⁢H⁢(q1,…,q6),

where H⁢(q1,…,q6)=−∑i∈[1,6]qi⁢log2⁡qi.

Proof.

We begin with the upper bound. Since

1=(q1+…+q6)n≥(nn⁢q1;…;n⁢q6)⁢∏i∈[1,6]qin⁢qi,

then we complete the upper bound proof by

log2⁡(nn⁢q1;…;n⁢q6)≤−n⁢∑i∈[1,6]qi⁢log2⁡qi=n⁢H⁢(q1,…,q6).

The lower bound is trivial for n∈[1,6]. Let I⊆[1,6] be the subset of indices such that n⁢qi>0. By lemma 1.10.17,

n!≥2⁢π⁢n⁢(ne)n,(n⁢qi)!≤2⁢π⁢n⁢qi⁢(n⁢qie)n⁢qi⁢exp⁡(112⁢n⁢qi),

and therefore

(nn⁢q1;…;n⁢q6)≥(12⁢π⁢n)|I|−1⋅∏i∈I(1qi⋅exp⁡(−112⁢n⁢qi))⋅∏i∈Iqi−n⁢qi=2n⁢H⁢(q1,…,q6)(2⁢π⁢n)(|I|−1)/2⋅∏i∈I(1qi⋅exp⁡(−112⁢n⁢qi)).

By AM-GM inequality,

∏i∈Iqi≤(1|I|⁢∑i∈Iqi)|I|≤|I|−|I|,

then

(nn⁢q1;…;n⁢q6)≥2n⁢H⁢(q1,…,q6)(2⁢π⁢n)(|I|−1)/2⋅∏i∈I(1qi⋅exp⁡(−112⁢n⁢qi))≥2n⁢H⁢(q1,…,q6)⋅|I||I|/2(2⁢π⁢n)(|I|−1)/2⋅∏i∈Iexp⁡(−112⁢n⁢qi).

On the other hand, since each n⁢qi≥1 for i∈I, then

(nn⁢q1;…;n⁢q6) ≥2n⁢H⁢(q1,…,q6)⋅|I||I|/2(2⁢π⁢n)(|I|−1)/2⋅∏i∈Iexp⁡(−112⁢n⁢qi)
≥2n⁢H⁢(q1,…,q6)⋅|I||I|/2(2⁢π⁢n)(|I|−1)/2⋅exp⁡(−|I|12)
=2n⁢H⁢(q1,…,q6)n(|I|−1)/2⋅2⁢π⋅(|I|2⁢π⁢exp⁡(1/6))|I|/2,

and for |I|∈[1,6] the coefficient

2⁢π⋅(|I|2⁢π⁢exp⁡(1/6))|I|/2≥12,

which completes the proof. ∎

By the KL-divergence-driven Chernoff bound in 1.4.4,

Pr⁡[|Zk−n⁢pk|≥ε⁢n]≤2⁢exp⁡(−2⁢n⁢ε2).

Together with lemma 1.10.32,

𝔼[B] ≥min(n1,…,n6)∈𝒯ε⁡(⌊log2⁡(nn1;…;n6)⌋−1)⋅(1−∑k∈[1,6]Pr⁡[|Zk−n⁢pk|≥ε⁢n])
≥min(n1,…,n6)∈𝒯ε⁡(n⁢H⁢(q1,…,q6)−52⁢log2⁡n−3)⋅(1−12⁢exp⁡(−2⁢n⁢ε2)),

where qk=nk/n. Since H is continuous over [0,1]6, there exists a constant γε→0 as ε→0, such that

𝔼[B] ≥min(n1,…,n6)∈𝒯ε⁡(n⁢H⁢(q1,…,q6)−52⁢log2⁡n−3)⋅(1−12⁢exp⁡(−2⁢n⁢ε2))
≥(n⁢(h−γε)−52⁢log2⁡n−3)⋅(1−12⁢exp⁡(−2⁢n⁢ε2)),

proving the lower bound.

To show an extraction function extracts on average at most n⁢h fair bits, the idea is similar to the theorem 1.10.28. Let X be the random variable of the outcome of n die rolls, then for an input-output pair (𝐱,𝐲) with |𝐲|=k,

Pr⁡[X=𝐱]≤Pr⁡[𝖤𝗑𝗍⁢(X)=𝐲]≤2−k,

the second inequality was discussed in theorem 1.10.28 from the conditional probability and definition 1.10.20, then

k=𝔼[B∣X=𝐱]≤−log2⁡Pr⁡[X=𝐱].

By conditional expectation,

𝔼[B]=∑𝐱Pr⁡[X=𝐱]⋅𝔼[B∣X=𝐱]≤−∑𝐱Pr⁡[X=𝐱]⋅log2⁡Pr⁡[X=𝐱]=H⁢(X)=n⁢h,

where the last equality is from lemma 1.10.7, and we complete the proof. ∎

1.10.4 Entropy: A Limit of Data Compression

Example 1.10.33.

Consider a biased coin that comes up heads with probability 3/4. Let HH map to 0, HT map to 10, TH map to 110, and TT map to 111. Then on average, the number of bits we use for each pair of flips is

1⋅916+2⋅316+3⋅316+3⋅116=2716<2.

This is an example of compression, as on average a biased coin flip can be represented with less than 1 fair coin flip.

Moreover, it is worth noting that this construction allows for breaking a sequence of biased coin flips into pairs, and concatenating the compression results. The result can be uniquely decoded by simply parsing from left to right. For example, 011110 stands for HHTTHT. The construction preserves the property that the bit representation of any pair of coin flips is not a prefix of the bit representation of any other pair of coin flips.

Representations with this property are called prefix codes.

Exercise 1.10.34 (Exercise 10.15 [MU17]).

We wish to compress a sequence of i.i.d. random variables X1,…, where each Xj takes on one of n possible values, into a prefix code like example 1.10.33. We map the ith value among all n values to a codeword, which is a sequence of ℓi bits. Prove that the ℓi must satisfy

∑i∈[1,n]2−ℓi≤1.
Proof.

Consider a binary tree of depth ℓmax=max{ℓi}i∈[1,n], then the length of a codeword is the distance to the root, and a codeword is a prefix of the path to leaves: 0 stands for the left subtree, and 1 stands for the right subtree. For a codeword of length ℓi, there are 2ℓmax−ℓi leaves whose root-to-leaf paths begin with that codeword. These sets of leaves are disjoint, since otherwise one codeword would be a prefix of another codeword, contradicting the prefix code property.

Now that every leaf in the binary tree is owned by at most 1 codeword, the number of owned leaves are

∑i∈[1,n]2ℓmax−ℓi≤2ℓmax,

which completes the proof. ∎

Remark 1.10.35.

The 1.10.34 is also called Kraft-McMillan inequality [Kra49, Mcm56].

Definition 1.10.36.

A compression function 𝖢𝗈𝗆 takes as input a sequence of n coin flips, given as an element of {H,T}n, and outputs a sequence of bits, such that each input sequence of n flips yields distinct output sequences.

We consider the case of compressing the outcome of a sequence of biased coin flips, similar to theorem 1.10.28.

Theorem 1.10.37.

Suppose a coin comes up heads with probability p>1/2. For any constant δ>0 and n sufficiently large,

  • •

    There exists a compression function 𝖢𝗈𝗆 such that the expected number of output bits on an input sequence of n independent coin flips is at most (1+δ)⁢n⁢H⁢(p).

  • •

    The expected number of output bits by any compression function on an input sequence of n independent coin flips is at least (1−δ)⁢n⁢H⁢(p).

Proof.

We begin with the upper bound, with an explicit construction of a compression function.

Let ε>0 be a sufficiently small constant with p−ε>1/2. On input a sequence of independent coin flips, output the first bit as a flag bit, 0 when the input has at least ⌈n⁢(p−ε)⌉ heads, 1 otherwise. When the first flag bit is 1, the compression function translates a head to a 1, and a tail to a 0, which requires n+1 bits to output. When the first flag bit is 0, let the number of coin flip sequences be m, and map a sequence to a value in [0,m−1].

If there are less than ⌈n⁢(p−ε)⌉ heads, we upper bound the probability using Chernoff’s bound by

Pr⁡[X−n⁢p<−n⁢ε]≤(e−γ(1−γ)1−γ)μ≤exp⁡(−μ⁢γ22)=exp⁡(−n⁢ε22⁢p),

where γ=ε/p, and μ=n⁢p.

If there are at least ⌈n⁢(p−ε)⌉ heads, we upper bound the number of coin flip sequences by

∑k∈[⌈n⁢(p−ε)⌉,n](nk)≤∑k∈[⌈n⁢(p−ε)⌉,n](n⌈n⁢(p−ε)⌉)≤n2⁢(n⌈n⁢(p−ε)⌉)≤n2⋅2n⁢H⁢(p−ε)=2n⁢H⁢(p−ε)+log2⁡n−1≤2⌊n⁢H⁢(p−ε)+log2⁡n⌋,

where the second and the third inequality holds by p−ε>1/2, and the fourth inequality holds by corollary 1.10.19. Including the flag bit, it takes at most n⁢H⁢(p−ε)+log2⁡n+1 bits for the sequences with at least ⌈n⁢(p−ε)⌉ heads.

Let B be the number of output bits of the compression function. The upper bound of its expectation is

𝔼[B] ≤exp⁡(−n⁢ε22⁢p)⋅(n+1)+(1−exp⁡(−n⁢ε22⁢p))⋅(n⁢H⁢(p−ε)+log2⁡n+1)
=1+exp⁡(−n⁢ε22⁢p)⋅n+(1−exp⁡(−n⁢ε22⁢p))⋅(n⁢H⁢(p)+n⁢γε+log2⁡n)
=1+n⁢H⁢(p)+exp⁡(−n⁢ε22⁢p)⋅n⁢(1−H⁢(p))+(1−exp⁡(−n⁢ε22⁢p))⋅(n⁢γε+log2⁡n),

where the γε is a constant similar to the one in 1.10.31, since H is continuous and monotone over [1/2,1], γε→0 as ε→0. For ε sufficiently small, when n is sufficiently large, the first boxed term approaches to 0, and the second boxed term is upper bounded by δ⁢n⁢H⁢(p) for some constant δ.

We now show the lower bound. It suffices to consider a compression function minimizing the expected output number of bits. We observe a fact: if an input string 𝐬1 is more likely than 𝐬2, then the output number of bits on input 𝐬2 should be at least as long as the one of 𝐬1. Otherwise, swapping the two outputs decreases the expectation. Since the probability of deriving a specific sequence with k heads is pk⁢(1−p)n−k, it is more likely for a string to have more heads. Hence, by Chernoff’s bound,

Pr⁡[X>⌊n⁢(p+ε)⌋]≤Pr⁡[X−n⁢p>n⁢ε−1]≤(eγ(1+γ)1+γ)μ≤exp⁡(−μ⁢γ23)=exp⁡(−n⁢(ε−1/n)23⁢p),

where μ=n⁢p, γ=ε/p−1/n⁢p, and ε sufficiently small so that p+ε<1.

Another fact: for a random variable uniform over [1,m], on average any compression function outputs at least log2⁡m−3 bits. By mapping to [0,m−1], and let ℓ be the first integer that 2+2+4+…+2ℓ≥m, hence ℓ≥log2⁡m−1. Hence, the average output bit of the compression function is at least ℓ−2. Averaged over sequences with ⌊n⁢(p+ε)⌋ heads, the compression function outputs at least

log2⁡(n⌊n⁢(p+ε)⌋)−3≥log2⁡2n⁢H⁢(p+ε)2⁢n−3=n⁢H⁢(p+ε)−12⁢log2⁡n−4

bits. By the ordering of an optimal compression function, sequences with fewer heads have average output length at least this large. The expected number of output bits of the compression function is lower bounded by ignoring the strings with more than ⌊n⁢(p+ε)⌋ heads, then

(1−exp⁡(−n⁢(ε−1/n)23⁢p))⋅(n⁢H⁢(p+ε)−12⁢log2⁡n−4).

By choosing a sufficiently small ε, and then a sufficiently large n, we can lower bound the expected number of output bits to (1−δ)⁢n⁢H⁢(p). ∎

Exercise 1.10.38 (Exercise 10.14 [MU17]).

Suppose we only have a biased 6-sided die with entropy h>0 instead of a fair coin. Modify the compression function in theorem 1.10.37 so that it compresses a sequence of die rolls to almost n⁢h bits on average.

Proof.

We begin with the lower bound by reusing lemma 1.10.32 and the ideas in 1.10.31 and theorem 1.10.37. Let Zi be the random variable for the number of times the ith face comes up, pi be the probability that the ith face comes up, and B be the random variable for the bits of the compression outcome. Recall the 𝒯ε defined in 1.10.31, by union bound over Chernoff’s bound in 1.4.4,

Pr⁡[(Z1,…,Z6)∈𝒯ε]=1−Pr⁡[(Z1,…,Z6)∉𝒯ε]≥1−∑i∈[1,6]Pr⁡[|Zi−n⁢pi|≥n⁢ε]≥1−12⁢exp⁡(−2⁢n⁢ε2).

Moreover, by previous discussion in theorem 1.10.37, a compression function minimizing the expected output bits outputs fewer bits on inputs that are more likely than the others, then let (n1,…,n6) be the face counts that

∏i∈[1,6]pini=max(k1,…,k6)∈𝒯ε⁢∏i∈[1,6]piki,

and conditioned on (k1,…,k6), the inputs are uniform over (nk1;…;k6) sequences, hence within the 𝒯ε, the compression function outputs at least

𝔼[B∣Z1=k1,…,Z6=k6]≥log2⁡(nn1;…;n6)−3≥log2⁡(12⁢n5/2⋅2n⁢H⁢(q1,…,q6))−3=n⁢H⁢(q1,…,q6)−52⁢log2⁡n−4,

where the second inequality holds by lemma 1.10.32, and qi=ni/n. Since this choice maximizes the probability of each individual sequence with these counts, every other sequence in 𝒯ε is less likely, so its output length is at least the average output length over this type. Then

𝔼[B] ≥∑(k1,…,k6)∈𝒯ε𝔼[B∣Z1=k1,…,Z6=k6]⋅Pr⁡[Z1=k1,…,Z6=k6]
≥(n⁢H⁢(q1,…,q6)−52⁢log2⁡n−4)⋅(1−12⁢exp⁡(−2⁢n⁢ε2))
=(n⁢(h−γε)−52⁢log2⁡n−4)⋅(1−12⁢exp⁡(−2⁢n⁢ε2)),

where γε is a constant such that γε→0 when ε→0 as H is continuous over [0,1]6. Hence, for a sufficiently small ε, and a sufficiently large n, there exists δ such that the lower bound (1−δ)⁢n⁢h is proved.

Now for the upper bound, we follow the main architecture of theorem 1.10.28, by introducing a flag bit separating the case where the dice rolling sequence is not in 𝒯ε and the case where the dice rolling sequence is in 𝒯ε. If some count deviates too far, then output in its vanilla form where each face is represented in 3 bits. Otherwise, we count the number of possible sequences in 𝒯ε to be m, and map a sequence to a value in [0,m−1], and we have

m=∑(k1,…,k6)∈𝒯ε(nk1;…;k6)≤(2⁢ε⁢n+1)5⁢(nn1;…;n6)≤(2⁢ε⁢n+1)5⋅2n⁢H⁢(q1,…,q6),

where n1,…,n6 maximizes (nk1;…;k6) over 𝒯ε, the last inequality holds by lemma 1.10.32, and qi=ni/n. Hence,

𝔼[B] ≤1+12⁢exp⁡(−2⁢ε2⁢n)⋅3⁢n+(log2⁡((2⁢ε⁢n+1)5⋅2n⁢H⁢(q1,…,q6))+1)
=2+12⁢exp⁡(−2⁢ε2⁢n)⋅3⁢n+5⁢log2⁡(2⁢ε⁢n+1)+n⁢H⁢(q1,…,q6)
=2+12⁢exp⁡(−2⁢ε2⁢n)⋅3⁢n+5⁢log2⁡(2⁢ε⁢n+1)+n⁢(h+γε),

where γε is a constant such that γε→0 when ε→0 as H is continuous over [0,1]6. Hence, for a sufficiently small ε, and a sufficiently large n, there exists δ such that the upper bound (1+δ)⁢n⁢h is proved. ∎

Exercise 1.10.39 (Exercise 10.16 [MU17]).

We wish to compress a sequence of i.i.d. random variables X1,…, where each Xj takes on one of n values. The ith value occurs with probability pi, where p1≥p2≥…≥pn. The compressed result follows. Let Ti=∑j∈[1,i−1]pj, and let the ith codeword to be the first ℓi=⌈log2⁡(1/pi)⌉ bits of Ti. Show that it is a prefix code example 1.10.33. Let z be the average number of bits used for each Xj. Show that H⁢(X)≤z≤H⁢(X)+1.

Proof.

We observe that, for the binary representation of pi, the first positive bit is the ℓith bit. Since the first positive bit is the ith bit for any value in [2−i,2−i+1), proving the claim. Moreover, as p1≥…≥pn, then ℓ1≤…≤ℓn, and it suffices to show that any pair of neighboring adjacent codewords does not violate the prefix code property.

On a pair of Ti and Ti+1=Ti+pi, since Ti≤Ti+2−ℓi≤Ti+pi, the first ℓi bits are distinct for the ith and (i+1)th codeword, proving the prefix code property.

Now for the average number of bits output by the compression function,

z=∑i∈[1,n]pi⁢⌈log2⁡(1/pi)⌉≥−∑i∈[1,n]pi⁢log2⁡pi=H⁢(X),

as ⌈log2⁡(1/pi)⌉≥−log2⁡pi. Moreover, by ⌈log2⁡(1/pi)⌉≤−log2⁡pi+1, then

z=∑i∈[1,n]pi⁢⌈log2⁡(1/pi)⌉≤∑i∈[1,n]pi⁢(−log2⁡pi+1)=H⁢(X)+1,

and we proved H⁢(X)≤z≤H⁢(X)+1. ∎

Exercise 1.10.40 (Exercise 10.3 [MU17]).

Flip a fair coin repeatedly X times until the first heads occurs. Find H⁢(X).

Now a friend flips the fair coin repeatedly until the first heads occurs. One wants to determine how many flips required, and is allowed to ask a series of yes-no questions of the following form: give the friend a set of integers, and the friend answers “yes” iff the number of flips is in the set, and “no” otherwise. Find a strategy such that the expected number of questions asked before determining the number of flips is H⁢(X). Give an intuitive explanation of why one cannot come up with a strategy that would ask fewer than H⁢(X) questions on average.

Proof.

X follows geometrically distributed random variable with success probability 1/2, then 𝔼[X]=2, and

H⁢(X)=−∑i≥1Pr⁡[X=i]⋅log2⁡Pr⁡[X=i]=∑i≥112i⋅i=2.

Intuitively, on the kth question, ask if X=k, then the number of questions is same distributed as X. For a strategy, it is impossible to have a same terminating transcript of the yes-no answers from distinct values of X. Moreover, a terminating transcript cannot be continued, as it converges to a single value, ruling out other values, namely other suffixes. Hence, they form a prefix code. By 1.10.39, at least H⁢(X)=2 questions are needed on average. ∎

Exercise 1.10.41 (Exercise 10.17 [MU17]).

Arithmetic coding is a standard compression method. In the case where the string to be compressed is a sequence of biased coin flips, it can be described as follows. For a sequence of i.i.d. Bernoulli trials X1,…,Xn with success probability 1−p. The sequences can be ordered lexicographically, so that for 𝐱,𝐲∈{0,1}n, we say 𝐱<𝐲 if xi=0 and yi=1 in the first coordinate i that xi≠yi. If z𝐱 is the number of zeroes in the string 𝐱, define p⁢(𝐱)=pz𝐱⁢(1−p)n−z𝐱, and q⁢(𝐱)=∑𝐲<𝐱p⁢(𝐲).

  • •

    Suppose we are given 𝐱 sequentially, explain how to compute q⁢(𝐱) in O⁢(n) time.

  • •

    Argue that [q⁢(𝐱),q⁢(𝐱)+p⁢(𝐱)) are disjoint subintervals over [0,1), show that X‾=(X1,…,Xn) can be represented by any point in [q⁢(X‾),q⁢(X‾)+p⁢(X‾)), and a codeword can be chosen in the interval by the first ⌈log2⁡(1/p⁢(X‾))⌉+1 bits, such that the codeword is a prefix code.

  • •

    On a codeword, show how to decompress to determine the corresponding X‾.

  • •

    Using a Chernoff’s bound, argue that log2⁡(1/p⁢(X‾)) is close to n⁢H⁢(p) with high probability.

Proof.

To derive q⁢(𝐱) in O⁢(n), count i∈[1,n]: when xi=0, move forward; otherwise, add p⁢∏j∈[1,i−1]qj to q⁢(𝐱), where qj is the probability corresponding to xj. Eventually, one sub-hypercube at a time, and

q⁢(𝐱)=p⁢∑i∈[1,n]xi⁢∏j∈[1,i−1]qj.

Let 𝐱+1 be defined as adding by 1 to the number with binary representation 𝐱, then q⁢(𝐱) is monotonically increasing for each 𝐱∈[0,2n−1], such that [q⁢(𝐱),q⁢(𝐱)+p⁢(𝐱)) are disjoint, as q⁢(𝐱+1)=q⁢(𝐱)+p⁢(𝐱), and q⁢(𝟏)+p⁢(𝟏)=1.

By 1.10.39, the first positive bit of p⁢(𝐱) is ℓ𝐱=⌈log2⁡(1/p⁢(𝐱))⌉, then there exists a dyadic interval of length 2−(ℓ𝐱+1) in [q⁢(𝐱),q⁢(𝐱)+p⁢(𝐱)), as 2−ℓ𝐱≤p⁢(𝐱). The codeword can be chosen by the lower bound of the dyadic interval, requiring ℓ𝐱+1 bits. If a codeword 𝐜0 is a prefix of a codeword 𝐜1, then 𝐜1 in a dyadic interval of 𝐜0, while the exterior intervals are disjoint, which is a contradiction.

Decoding the codeword c is in the reverse order of deriving q⁢(𝐱): Count i∈[1,n], and let the left endpoint a=0. If c≥a+p⁢∏j∈[1,i−1]qj, the ith bit is 1, qi←1−p, and add p⁢∏j∈[1,i−1]qj to a; otherwise, the ith bit is 0 and qi←p.

Let Z be the number of tails in [0,n], then 𝔼[Z]=n⁢p, and

Y=log2⁡(1/p⁢(X‾))=−log2⁡p⋅Z−log2⁡(1−p)⋅(n−Z)=−n⁢log2⁡(1−p)+Z⁢log2⁡1−pp,

such that 𝔼[Y]=n⁢H⁢(p). If p=1/2, Y=n⁢H⁢(p)=n deterministically. Otherwise, as Z=∑i∈[1,n]Zi for independent Zi being 1 on the ith flip, we can apply Chernoff’s bound, such that

Pr⁡[|Y−n⁢H⁢(p)|≥δ⁢n⁢p⁢|log2⁡1−pp|]=Pr⁡[|Z−n⁢p|≥δ⁢n⁢p]≤(eδ(1+δ)1+δ)n⁢p+(e−δ(1−δ)1−δ)n⁢p≤2⁢exp⁡(−δ23⁢n⁢p).

∎

1.10.5 Shannon’s Theorem

Consider the following type of channel.

Definition 1.10.42.

The input to a binary symmetric channel with parameter p is a sequence of bits x1,… and the output is a sequence of bits y1,… such that Pr⁡[xi=yi]=1−p independently for each i.

Consider encoding functions that bring redundancy to help protect against the introduction of errors.

Definition 1.10.43.

A (k,n) encoding function 𝖤𝗇𝖼:{0,1}k→{0,1}n takes as input a sequence of k bits and outputs a sequence of n bits. Conversely, a (k,n) decoding function 𝖣𝖾𝖼:{0,1}n→{0,1}k takes as input a sequence of n bits and outputs a sequence of k bits.

Exercise 1.10.44 (Exercise 10.18 [MU17]).

Alice wants to send Bob the result of a fair coin flip over a binary symmetric channel that flips each bit with probability p<1/2. To avoid errors in transmission, she encodes heads as a sequence of 2⁢k+1 zeroes and tails as a sequence of 2⁢k+1 ones.

  • •

    Consider the case where k=1. For each possible received sequence of 3 bits, determine the probability that Alice flipped a heads conditioned on Bob receiving that sequence.

  • •

    Bob decodes by examining the 3 bits. If two or three of the bits are 0, Bob decides the corresponding coin flip was heads. Prove that this rule minimizes the probability of error for each flip.

  • •

    Argue that, for general k, Bob minimizes the probability of error by deciding the flip was heads if at least k+1 of the bits are 0.

  • •

    Give a formula for the probability that Bob makes an error that holds for general k.

Proof.

Let n=2⁢k+1, 𝐲∈{0,1}n, nzero⁢(𝐲) be the number of zeroes of the 𝐲, X be a fair coin outcome, tails on X=0, otherwise heads, and Y‾=(Y1,…,Yn) be the received bits. Hence,

Pr⁡[Y‾=𝐲|X=1] =(1−p)nzero⁢(𝐲)⋅pn−nzero⁢(𝐲),
Pr⁡[Y‾=𝐲|X=0] =pnzero⁢(𝐲)⋅(1−p)n−nzero⁢(𝐲),

and by Bayes’ Rule,

Pr⁡[X=1|Y‾=𝐲]=(1−p)nzero⁢(𝐲)⋅pn−nzero⁢(𝐲)(1−p)nzero⁢(𝐲)⋅pn−nzero⁢(𝐲)+pnzero⁢(𝐲)⋅(1−p)n−nzero⁢(𝐲).

Consider decoding the flip: if at least m bits are 0, then we have heads; otherwise we have tails. Then

Pr⁡[error] =Pr⁡[X=0∧nzero⁢(Y‾)≥m]+Pr⁡[X=1∧nzero⁢(Y‾)<m]
=12⁢∑i∈[m,n](ni)⋅pi⋅(1−p)n−i+12⁢∑i∈[0,m−1](ni)⋅(1−p)i⋅pn−i
=12+12⁢∑i∈[m,n](ni)⋅(pi⋅(1−p)n−i−(1−p)i⋅pn−i).

Since p<1/2, then pi⋅(1−p)n−i<(1−p)i⋅pn−i for i≥k+1, which proves the error minimizing when m=k+1. ∎

Lemma 1.10.45.

For a binary symmetric channel with parameter p<1/2 and for any constant δ,γ>0, when n is sufficiently large, for any k≤n⁢(1−H⁢(p)−δ) and a uniformly distributed k-bit input message, there exist (k,n) encoding and decoding functions such that the probability the receiver fails to obtain the correct message is at most γ.

Proof.

We begin by describing a probabilistic algorithm constructing 2k codewords in {0,1}n, one for each message, and the inefficient encoding and decoding functions.

Let {Xi}i∈[0,2k−1] be the distinct codewords sampled uniformly at random from {0,1}n. The encoding function 𝖤𝗇𝖼:{0,1}k→{0,1}n is a lookup table mapping the k-bit inputs to their corresponding codewords. The decoding function 𝖣𝖾𝖼:{0,1}n→{0,1}k∪{⊥} maintains the look up table, iterates through the codewords, and checks if a codeword differing from the received n bits in between [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] bits. If there is only one codeword in this interval, output the corresponding k-bit message; otherwise, decoding function fails and outputs ⊥. Since the decoding runtime is exponential in k, the decoding is not efficient, and we are not requiring it to be efficient.

When it comes to decoding failure or failure to obtain the correct message, it falls into 2 cases:

  • •

    The noisy channel made less than n⁢(p−ε) or more than n⁢(p+ε) errors.

  • •

    There are other codeword(s) that are differing from the received n bits in between [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] bits.

The goal is to prove the existence of a set of codewords, whose probability of failures above is at most γ. The strategy here is probabilistic method, via averaging argument lemma 1.6.12, if probability of failures above on average among all {Xi}i∈[0,2k−1] is at most γ, then there must exist a set of codewords whose failure probability is at most γ. The first failure event can be upper bounded via concentration inequalities, while the second failure event can be upper bounded via counting argument.

We continue by introducing notation and random variable formulations. Let Δ⁢(𝐬0,𝐬1) be the Hamming weight of 𝐬0⊕𝐬1 for the number of positions 𝐬0 and 𝐬1 differing from each other. We say (𝐬0,𝐬1) pair has weight

w⁢(𝐬0,𝐬1)=pΔ⁢(𝐬0,𝐬1)⋅(1−p)n−Δ⁢(𝐬0,𝐬1),

corresponding to the probability of 𝐬0 being altered into 𝐬1 by the binary symmetric channel. Let {Si}i∈[0,2k−1] be the sets of n bits that decodes to Xi, which are n bits that are close to Xi, and are far from other Xj. Let {Wi}i∈[0,2k−1] be the set of probabilities that Xi fails in decoding correctly, where

Wi=∑𝐫∉Siw⁢(Xi,𝐫).

It can also be expressed in a way that, let 1i,𝐫 be an indicator 0/1 random variable that is 1 iff 𝐫∉Si, then

Wi=∑𝐫∈{0,1}n1i,𝐫⋅w⁢(Xi,𝐫).

Note that, both {Si}i∈[0,2k−1] and {Wi}i∈[0,2k−1] are random variables dependent on {Xi}i∈[0,2k−1].

WLOG, we analyze with respect to X0, as by symmetry the following results applies to other Xi. Write

W0=∑𝐫∈T110,𝐫⋅w⁢(X0,𝐫)+∑𝐫∈T210,𝐫⋅w⁢(X0,𝐫), (1.13)

where T1={𝐬:|Δ⁢(X0,𝐬)−n⁢p|>n⁢ε}, and T2={𝐬:|Δ⁢(X0,𝐬)−n⁢p|≤n⁢ε}.

For the first term, let {Zi}i∈[1,n] be independent Bernoulli trials with success probability p, then Z=∑i∈[1,n]Zi is the random variable for the number of bits flipped by the channel, and by Chernoff’s bound, for 0<ε<p,

∑𝐫∈T110,𝐫⋅w⁢(X0,𝐫)=∑𝐫∈T1w⁢(X0,𝐫)=Pr⁡[|Z−n⁢p|>n⁢ε]≤(eθ(1+θ)1+θ)n⁢p+(e−θ(1−θ)1−θ)n⁢p≤2⁢exp⁡(−μ⁢θ23), (1.14)

where θ=ε/p and μ=n⁢p. For any threshold 0<ε<p, there is n sufficiently large such that 2⁢exp⁡(−μ⁢θ2/3)≤γ/2.

For the second term, consider the following symmetry: On a set of codewords {Xi}i∈[0,2k−1], we have {Xi′}i∈[0,2k−1] such that Xi′←Xi⊕X0, and X0′=𝟎. Then {Si′}i∈[0,2k−1] can be obtained by XORing X0 with elements in {Si}i∈[0,2k−1], and the W0 can be expressed by

W0=∑𝐫∈T1′10,𝐫⋅w⁢(𝟎,𝐫)+∑𝐫∈T2′10,𝐫⋅w⁢(𝟎,𝐫).

where T1′={𝐬:|Δ⁢(𝟎,𝐬)−n⁢p|>n⁢ε}, and T2′={𝐬:|Δ⁢(𝟎,𝐬)−n⁢p|≤n⁢ε}. The symmetry holds for the claim in the first term, while the symmetry allows us to argue the second term with respect to X0′=𝟎, then

∑𝐫∈T2′10,𝐫⋅w⁢(𝟎,𝐫)

is a random variable depending on {Xi′}i∈[1,2k−1]. Moreover, for a 𝐫∈T2′, averaging over {Xi′}i∈[1,2k−1],

𝔼[10,𝐫⋅w⁢(𝟎,𝐫)]=w⁢(𝟎,𝐫)⋅Pr⁡[∃i∈[1,2k−1],|Δ⁢(Xi′,𝐫)−n⁢p|≤n⁢ε].

Supposing we have

Pr⁡[∃i∈[1,2k−1],|Δ⁢(Xi′,𝐫)−n⁢p|≤n⁢ε]≤γ2,

then the second term can be upper bounded by

∑𝐫∈T2′𝔼[10,𝐫⋅w⁢(𝟎,𝐫)]≤∑𝐫∈T2′w⁢(𝟎,𝐫)⋅γ2≤γ2.

We continue by upper bounding the number of possible n bits around 𝐫, such that we upper bound the second term:

∑k∈[⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋](nk)≤(2⁢ε⁢n+1)⋅(n⌈n⁢(p+ε)⌉)≤(2⁢ε⁢n+1)⋅2n⁢H⁢(p+ε),

threshold ε is chosen such that ⌈n⁢(p+ε)⌉≤n/2, and the second inequality holds by corollary 1.10.19. The probability of a particular codeword Xi′ with i>0 having a Hamming distance [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] to 𝐫 causing a decoding failure, when 𝟎 is sent is at most

(2⁢ε⁢n+1)⋅2n⁢(H⁢(p+ε)−1)=(2⁢ε⁢n+1)⋅2n⁢(H⁢(p)+γε−1),

where γε is a constant similar to the one appearing in theorem 1.10.28 and theorem 1.10.37. Union bounding over all other codewords, the probability of other codeword failing decoding 𝟎 is upper bounded by

∑𝐫∈T2′𝔼[10,𝐫⋅w⁢(𝟎,𝐫)]≤(2k−1)⋅(2⁢ε⁢n+1)⋅2n⁢(H⁢(p)+γε−1)≤(2⁢ε⁢n+1)⋅2n⁢(γε−δ), (1.15)

where the last inequality holds by k≤n⁢(1−H⁢(p)−δ). Since eq. 1.15 approaches 0 as n→∞ with δ>γε, then it is at most γ/2 on a sufficiently large n, and by symmetry, we conclude

∑𝐫∈T2𝔼[10,𝐫⋅w⁢(X0,𝐫)]≤γ2. (1.16)

Combining eqs. 1.13, 1.14 and 1.16, on a sufficiently large n, the probability of decoding incorrectly X0 is

𝔼[W0]=∑𝐫∈{0,1}n𝔼[10,𝐫⋅w⁢(X0,𝐫)]≤γ.

Since the k-bit message is uniform over {0,1}k, the probability of decoding incorrectly is averaging over all 𝔼[Wi] by

2−k⁢∑i∈[0,2k−1]𝔼[Wi]≤γ.

By an averaging argument lemma 1.6.12, there must exist a set of codewords {𝐱i}i∈[0,2k−1], such that

∑i∈[0,2k−1](Wi∣X0=𝐱0,…,X2k−1=𝐱2k−1)≤2k⁢γ.

∎

The decoding failure probability in lemma 1.10.45 is obtained by averaging over all k-bit messages and all possible codeword samplings. We will obtain a stronger result than lemma 1.10.45 in theorem 1.10.46: for all i∈[0,2k−1],

(Wi∣X0=𝐱0,…,X2k−1=𝐱2k−1)≤γ

holds simultaneously.

Theorem 1.10.46 (Shannon’s Theorem [Sha48a, Sha48b]).

For a binary symmetric channel with parameter p<1/2 and for any constants δ,γ>0, when n is sufficiently large:

  • •

    for any k≤n⁢(1−H⁢(p)−δ), there exist (k,n) encoding and decoding functions such that the probability the receiver fails to obtain the correct message is at most γ for every k-bit input message; and

  • •

    there are no (k,n) encoding and decoding functions with k≥n⁢(1−H⁢(p)+δ) such that the probability decoding correctly is at least γ for a k-bit input message chosen uniformly at random.

Proof.

WLOG we let {𝐱i}i∈[0,2k−1] be sorted in increasing order of Wi. Hence, for i∈[0,2k−1−1], each 𝐱i has Wi≤2⁢γ, or otherwise we contradict by

∑i∈[2k−1,2k−1](Wi∣X0=𝐱0,…,X2k−1=𝐱2k−1)≥2⁢γ⋅2k−1=2k⁢γ.

In this way, we prove there exist encoding and decoding functions for k−1 bits messages over 2k−1 codewords, and the probability of each codeword being decoded incorrectly is simultaneously at most 2⁢γ, when k≤n⁢(1−H⁢(p)−δ). Since δ and γ can be any constant, the first part of the proof is completed.

Having the first part of the proof finished, we move on to the second part of the proof, which is the converse of lemma 1.10.45. We begin by an observation in lemma 1.10.45 to build an intuition: The decoding function maps the received n bits to the only one codeword within [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] many errors, and the number of such n bits is lower bounded by

∑k∈[⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋](nk)≥(n⌈n⁢p⌉)≥2n⁢H⁢(p)2⁢n,

where the last inequality holds by corollary 1.10.19. Since there are 2k possible messages, and k≥n⁢(1−H⁢(p)+δ), on a sufficiently large n,

2k⋅2n⁢H⁢(p)2⁢n≥2n⁢δ2⁢n⋅2n≥2n.

Hence, given k≥n⁢(1−H⁢(p)+δ) and n sufficiently large, conditioned that the number of bits flipped by the channel is within [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋], there is no such set of codewords always decode successfully, namely it is getting too dense, such that in the “unique decoding” range defined in lemma 1.10.45, there are more than 1 valid codeword.

More specifically, we can show how to rule out lemma 1.10.45. Let Ci be the set of received n-bit strings that are correctly decoded to the codeword 𝐱i in lemma 1.10.45, then the probability of successful decoding is

12k⁢∑i∈[0,2k−1]∑𝐫∈Ciw⁢(𝐱i,𝐫)

by averaging over all 2k messages. Since for any 𝐫∈Ci, it is within [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] many bit flips from 𝐱i,

w⁢(𝐱i,𝐫)=pΔ⁢(𝐱i,𝐫)⋅(1−p)n−Δ⁢(𝐱i,𝐫)≤pn⁢(p−ε)⋅(1−p)n⁢(1−p+ε)=(1−pp)n⁢ε⋅2−n⁢H⁢(p),

then the averaging probability is upper bounded by

12k⁢∑i∈[0,2k−1]∑𝐫∈Ciw⁢(𝐱i,𝐫)≤12k⁢∑i∈[0,2k−1](1−pp)n⁢ε⋅2−n⁢H⁢(p)⋅|Ci|≤12k⋅(1−pp)n⁢ε⋅2−n⁢H⁢(p)⋅2n=((1−pp)ε⋅2−δ)n, (1.17)

where the last inequality holds by k≥n⁢(1−H⁢(p)+δ), so conditioned that

(1−pp)ε⋅2−δ<1, (1.18)

then when n is sufficiently large, the probability is upper bounded by γ.

We proceed by analyzing the general case. For the set of codewords {𝐱i}i∈[0,2k−1], let Si be the set of n bits that are uniquely decoded to 𝐱i, and Si,1∩Si,2=∅, Si=Si,1∪Si,2 be defined as follows: Si,1={𝐫∈Si:|Δ⁢(𝐱i,𝐫)−p⁢n|>ε⁢n}, and Si,2={𝐫∈Si:|Δ⁢(𝐱i,𝐫)−p⁢n|≤ε⁢n}. Then the probability of successful decoding is

12k⁢∑i∈[0,2k−1]∑𝐫∈Siw⁢(𝐱i,𝐫)=12k⁢∑i∈[0,2k−1]∑𝐫∈Si,1w⁢(𝐱i,𝐫)+12k⁢∑i∈[0,2k−1]∑𝐫∈Si,2w⁢(𝐱i,𝐫),

where the first term is upper bounded by Chernoff’s bound with the same bound in eq. 1.14, and the second term is upper bounded in the same procedure of eq. 1.17, conditioned that eq. 1.18 holds. ∎

Exercise 1.10.47 (Exercise 10.19 [MU17]).

Consider the following channel. The sender can send a symbol from [0,4], the channel introduces errros: when the symbol k is sent, the recipient receives k+1mod5 with probability 1/2, or k−1mod5 with probability 1/2. The errors on each symbol are mutually independent of each other.

Define the encoding and decoding functions for this channel by: A (j,n) encoding function maps a number in [0,j−1] into a sequence in [0,4]n. A (j,n) decoding function maps a sequence in [0,4]n into a number in [0,j−1].

There are (1,1) encoding and decoding functions with zero probability of error, as the decoder maps 1 and 4 to 0, and maps 0 and 2 to 1. Hence at least 1 bit can be sent without error per channel use. Show that:

  • •

    There are (5,2) encoding and decoding functions with zero probability of error. Argue that more than one bit of information can be sent per use of the channel.

  • •

    If there exists (j,n) encoding and decoding functions with zero probability of error, then n≥log2⁡j/(log2⁡5−1).

Proof.

Consider the (5,2) encoding and decoding function. The (5,2) encoder encodes a with a pair (a,2⁢amod5). The (5,2) decoder performs by the following lookup table

encode received decode to
(0,0) (1,1),(1,4),(4,1),(4,4) 0
(1,2) (2,3),(2,1),(0,3),(0,1) 1
(2,4) (3,0),(3,3),(1,0),(1,3) 2
(3,1) (4,2),(4,0),(2,2),(2,0) 3
(4,3) (0,4),(0,2),(3,4),(3,2) 4

.

The encoding scheme can also be instantiated by (a,3⁢amod5) 999 The story is, I brute-forced adding constant, additive inverse, multiplicative inverse, and finally scalar multiplication. .

In fact, the channel operates over a cycle graph C5, mapping a to a±1mod5 each with probability 1/2. Moreover, since we want a set of codewords avoiding overlapping received symbols on the decoding side, we can construct the following graph for the single coordinate (1,1) encoding and decoding, by pairing up symbols bringing “confusion” after transmitted through the channel. Hence, {0,1} is an independent set of size 2 over the C5 illustrated as folows, and it happens to be the codewords for (1,1) encoding and decoding.

Diagram
Diagram

On a pair of C5 confusion graphs, we want to define a graph product such that any neighboring (i,j) brings overlaps on the decoding side. On a pair of (u,v) and (u′,v′), they are adjacent iff

  • •

    u=u′, v and v′ are adjacent on C5 confusion graph;

  • •

    v=v′, u and u′ are adjacent on C5 confusion graph;

  • •

    u and u′, v and v′ are both adjacent on C5 confusion graph.

We then define the symbol ⊠ such that C5⊠C5 is illustrated as follows:

Diagram

The new codewords form an independent set of size 5 on C5⊠C5, each C5 is ordered as 0,2,4,1,3 so that adjacency corresponds to difference ±2mod5.

When it comes to general (j,n) encoding and decoding functions, supposing it exists, then there must be j⋅2n≤5n, such that for each of the j values, the decoding boundary is 2n, and the total area of decoding is no more than 5n, or confusion must exists, and hence

n≥log2⁡jlog2⁡5−1.

∎

Remark 1.10.48.

The 1.10.47 is the classical zero-error capacity viewpoint of Shannon [Sha56]. The pentagon case C5 was solved by Lovász [Lov79].

Exercise 1.10.49 (Exercise 10.20 [MU17]).

A binary erasure channel transfers a sequences of n bits. Each bit either arrives successfully without error or fails to arrive, and is replaced with a “?” symbol. Failure occur independently with probability p. Define (k,n) encoding and decoding functions for BEC similar to ones in the BSC, except that 𝖣𝖾𝖼:{0,1,?}n→{0,1}k∪{⊥}. Prove that, for any p>0 and any constants δ,γ>0, if n is sufficiently large, then there exists (k,n) encoding and decoding functions with k≤n⁢(1−p−δ) such that the probability that the receiver fails to obtain the correct message is at most γ for every possible k-bit message.

Proof.

The proof architecture is similar to lemmas 1.10.45 and 1.10.46, with a same setup of the randomized codewords, and the same encoding function. The decoder finds a codeword that has within [⌈n⁢(p−ε)⌉,⌊n⁢(p+ε)⌋] number of “?”, and the other symbols must match. If there is one such codeword, output the corresponding message; otherwise, reject by ⊥.

We reuse a few notations in lemma 1.10.45: Applying Hamming weight Δ over 𝐱i∈{0,1}n and 𝐬i←𝐱i⊕𝐫i where 𝐫i∈{0,?}n, and ⊕ overrides ? to a symbol in {0,1}. Then the weight defined in between 𝐱i and 𝐬i is

w⁢(𝐱i,𝐬i)=pΔ⁢(𝐱i,𝐬i)⋅(1−p)n−Δ⁢(𝐱i,𝐬i).

Let {Si}i∈[0,2k−1] be the set of {0,1,?}n decodable to Xi, {Wi}i∈[0,2k−1] be the set of probabilities that Xi fails in decoding correctly, where

Wi=∑𝐫∈{0,?}n,Xi⊕𝐫∉Siw⁢(Xi,Xi⊕𝐫).

It can also be expressed in the way that, let 1i,𝐫 be an indicator 0/1 random variable that is 1 iff Xi⊕𝐫∉Si, then

Wi=∑𝐫∈{0,?}n1i,𝐫⋅w⁢(Xi,Xi⊕𝐫)=∑𝐫∈T11i,𝐫⋅w⁢(Xi,Xi⊕𝐫)+∑𝐫∈T21i,𝐫⋅w⁢(Xi,Xi⊕𝐫),

by letting T1={𝐫∈{0,?}n:|Δ⁢(𝟎,𝐫)−n⁢p|>n⁢ε} and T2={𝐫∈{0,?}n:|Δ⁢(𝟎,𝐫)−n⁢p|≤n⁢ε}.

WLOG we analyze X0, as by symmetry the same analysis hold for all other Xi.

The first term is bounded in the same way as eq. 1.14 via Chernoff’s bound. Let {Zi}i∈[1,n] be the independent Bernoulli trials with success probability p, then Z=∑i∈[1,n]Zi is the number “?”s, for 0<ε<p,

∑𝐫∈T110,𝐫⋅w⁢(X0,X0⊕𝐫)=∑𝐫∈T1w⁢(X0,X0⊕𝐫)=Pr⁡[|Z−n⁢p|>n⁢ε]≤(eθ(1+θ)1+θ)n⁢p+(e−θ(1−θ)1−θ)n⁢p≤2⁢exp⁡(−μ⁢θ23),

For any threshold 0<ε<p, there is n sufficiently large such that 2⁢exp⁡(−μ⁢θ2/3)≤γ/2.

It suffices to argue with respect to X0=𝟎 for the second term by the same symmetry discussed in lemma 1.10.45, then the random variable

∑𝐫∈T210,𝐫⋅w⁢(𝟎,𝐫)

is dependent on {Xi}i∈[1,2k−1]. For 𝐫∈T2, averaging over {Xi}i∈[1,2k−1],

𝔼[10,𝐫⋅w⁢(𝟎,𝐫)]=w⁢(𝟎,𝐫)⋅Pr⁡[∃i∈[1,2k−1],|Δ⁢(Xi,𝐫)−n⁢p|≤n⁢ε].

Supposing we have

Pr⁡[∃i∈[1,2k−1],|Δ⁢(Xi,𝐫)−n⁢p|≤n⁢ε]≤γ2,

then the second term can be upper bounded by

∑𝐫∈T2𝔼[10,𝐫⋅w⁢(𝟎,𝐫)]≤∑𝐫∈T2w⁢(𝟎,𝐫)⋅γ2≤γ2.

We continue by upper bounding the number of possible n bits to derive 𝐫 by 2Δ⁢(𝟎,𝐫)≤2n⁢(p+ε), then the probability of a particular codeword Xi with i>0 being able to produce 𝐫 is at most 2n⁢(p+ε−1). Union bounding over all other codewords, the probability of other codeword failing decoding 𝟎 is upper bounded by

(2k−1)⋅2n⁢(p+ε−1)≤2k⋅2n⁢(p+ε−1)≤2n⁢(ε−δ),

where the last inequality is by k≤n⁢(1−p−δ). Since 2n⁢(ε−δ)→0 as n→∞ if δ>ε, then it is at most γ/2 on an n. By symmetry, we conclude

∑𝐫∈T2𝔼[10,𝐫⋅w⁢(X0,X0⊕𝐫)]≤γ2.

Combining the separated cases, we have

𝔼[W0]=∑𝐫∈T1𝔼[10,𝐫⋅w⁢(X0,X0⊕𝐫)]+∑𝐫∈T2𝔼[10,𝐫⋅w⁢(X0,X0⊕𝐫)]≤γ.

By symmetry and linearity of expectation,

∑i∈[0,2k−1]𝔼[Wi]≤2k⁢γ.

By the same ranking argument in theorem 1.10.46, there exists a set of codewords with at least 2k−1 codewords with Wi≤2⁢γ, and we choose the half of the set of codewords with small Wi, and we complete the proof. ∎

Exercise 1.10.50 (Exercise 10.21 [MU17]).

In lemmas 1.10.45 and 1.10.46, we let decoder find a codeword with Hamming distance to the bits received within [n⁢(p−ε),n⁢(p+ε)]. Instead, let decoder find the codeword by looking for the codeword with least number of differences, and break ties arbitrarily. Show how to modify the proof for lemmas 1.10.45 and 1.10.46 to obtain a similar result.

Proof.

Just use the Hamming ball of radius ⌊n⁢(p+ε)⌋ around the codeword. The “too far” Chernoff case still decays exponentionally fast, and the “in radius” case should approach 0 as n→∞. ∎