The Asymptotic Equipartition Property

What this note builds
  1. 01Sample entropymeasuring the entropy of a whole tape of symbols
  2. 02AEP theoremfor large nn, sample entropy converges to the true entropy
  3. 03Typical setthe representative, realistic tapes and their properties
  4. 04Two-part codea compression scheme that exploits the typical set
· 41 min read · 8,137 words

Motivation: from one keystroke to a whole message

The quantities we built in the notes (entropy, relative entropy, mutual information) are an average per keystroke. But a user never transmits a single keystroke in isolation. They transmit a long message: a sequence of nn symbols X1,X2,…,XnX_1, X_2, \ldots, X_n generated by a source (like an English typist) with a specific probability distribution p(x)p(x).

To transmit this message, the engineer must design a codebook, a dictionary that translates every possible raw typed sequence into a unique string of binary 0s and 1s.

If a typewriter has an alphabet X\mathcal{X}, a message of length nn can be filled in ∣X∣n\lvert \mathcal{X} \rvert^n different ways. If the engineer blindly treats every possible jumble of letters as equally likely, they must assign a fixed-length binary code to every single one of those ∣X∣n\lvert \mathcal{X} \rvert^n messages. This requires a hardcoded length of nlog⁡∣X∣n \log \lvert \mathcal{X} \rvert bits per transmission. This is incredibly expensive, and completely ignores the fact that languages have statistical structure.

IntuitionThe engineering problem

A smart engineer doesn’t use fixed-length codes. They use variable-length codes. They want to assign very short, cheap binary codes to the specific patterns of symbols that the language naturally produces, and relegate the astronomically rare gibberish to long, clunky codes. The system still technically works for every possible message (so it never crashes), but because the clunky codes are almost never used, the average transmission cost plummets.

But to build this codebook, the engineer must solve a fundamental problem: out of the ∣X∣n\lvert \mathcal{X} \rvert^n mathematically possible messages, exactly which ones actually get typed, and what are their probabilities?

The Law of Large Numbers

To answer this, we borrow a foundational concept from statistics: the Law of Large Numbers (LLN).

The LLN states that if you perform the same random experiment many times, the empirical average of the results will strictly converge to the theoretical expected value. If you roll a fair six-sided die once, the result is completely unpredictable. But if you roll it 10,000 times, you know with near absolute certainty that the average of those rolls will be roughly 3.5.

The Asymptotic Equipartition Property (AEP) is the information-theoretic analogue of the Law of Large Numbers. But instead of averaging the raw values of the data, we average the surprise (the negative log probability) of the data.

Law of large numbersAsymptotic Equipartition Property
Object averagedThe values themselves, 1n∑i=1nXi\frac{1}{n}\sum_{i=1}^n X_iThe surprise of the values, −1nlog⁡p(X1,…,Xn)-\frac{1}{n}\log p(X_1, \ldots, X_n)
Converges toE[X]\mathbb{E}[X]H(X)H(X) (Entropy)

Because −1nlog⁡p(X1,…,Xn)-\frac{1}{n}\log p(X_1, \ldots, X_n) strictly settles down to the Entropy H(X)H(X), the overall probability of whatever message we actually observe settles to roughly 2−nH2^{-nH}.

ConventionTape notation

We write xnx^n as shorthand for a sequence x1,x2,…,xnx_1, x_2, \ldots, x_n, and XnX^n for the corresponding random variable representing the whole message. So p(xn)p(x^n) is the probability the operator types that exact sequence, and Xn\mathcal{X}^n is the set of all ∣X∣n\lvert \mathcal{X} \rvert^n possible sequences of length nn.


Intuition check: are all tapes equally likely?

A naive first guess is that the AEP is trivially true because every message is equally likely anyway. It is not, and seeing why sharpens what the theorem is actually claiming.

Let the operator have a two-key machine, X∈{0,1}X \in \{0, 1\}, with p(1)=pp(1) = p and p(0)=qp(0) = q. Since keystrokes are i.i.d., the probability of a specific sequence x1,x2,…,xnx_1, x_2, \ldots, x_n is the product of the per-key probabilities:

p(x1,x2,…,xn)=∏i=1np(xi)=p∑ixi  q n−∑ixip(x_1, x_2, \ldots, x_n) = \prod_{i=1}^n p(x_i) = p^{\sum_i x_i} \; q^{\, n - \sum_i x_i}

ExampleA concrete sequence

The sequence (1,0,1,1,0,1)(1, 0, 1, 1, 0, 1) has probability p4q2p^4 q^2. A sequence of six zeroes has probability q6q^6. These are wildly different numbers whenever p≠qp \neq q, so it is plainly not true that all 2n2^n sequences of length nn are equally probable.

So the AEP is not saying that the sample space is uniform. It is saying something weaker but far more useful: although the 2n2^n possible sequences have very different mathematical probabilities, the sequences that actually get typed in reality almost all share the exact same probability: 2−nH(p)2^{-nH(p)}.

In this binary example, this simply means the number of 11s on a printed message will almost always be close to npnp. And every sequence that has exactly npnp ones naturally carries the exact same mathematical probability.


Convergence of random variables

The AEP is a statement about a sequence of random variables converging.

To understand what is converging, we have to be precise: the raw characters on the wire do not converge. If an operator types binary digits Xi∈{0,1}X_i \in \{0, 1\}, individual keystrokes bounce between 0 and 1 forever.

What converges is a calculated property of the message as a whole. Specifically, we define a new random variable YnY_n: the sample entropy (the average surprise per keystroke across a message of length nn):

Yn=−1nlog⁡p(X1,X2,…,Xn)Y_n = -\frac{1}{n} \log p(X_1, X_2, \ldots, X_n)

We want to prove that as the message length nn grows, this empirical quantity YnY_n settles onto the true, theoretical entropy of the language, H(X)H(X).

Because YnY_n is a random variable, it doesn’t converge like a standard calculus function. In probability theory, there are three distinct mathematical ways a sequence of random variables YnY_n can converge to a constant cc:

DefinitionModes of convergence

Let Y1,Y2,…Y_1, Y_2, \ldots be random variables, and let cc be a target constant (here, c=H(X)c = H(X)):

  1. In probability: Pr⁡{∣Yn−c∣>ϵ}⟶0\Pr\{ \lvert Y_n - c \rvert > \epsilon \} \longrightarrow 0 as n→∞n \to \infty, for any fixed ϵ>0\epsilon > 0.
  2. In mean square: E[(Yn−c)2]⟶0\mathbb{E}\big[(Y_n - c)^2\big] \longrightarrow 0 as n→∞n \to \infty.
  3. With probability 1 (almost surely): Pr⁡{lim⁡n→∞Yn=c}=1\Pr\left\{ \lim_{n \to \infty} Y_n = c \right\} = 1.

Why the three modes differ

The three definitions test completely different engineering concerns: frequency, variance/energy, and infinite timelines.

1. Convergence in probability (Snapshot frequency)

Look at the condition: Pr⁡{∣Yn−c∣>ϵ}→0\Pr\{ \lvert Y_n - c \rvert > \epsilon \} \to 0.

  • What ∣Yn−c∣>ϵ\lvert Y_n - c \rvert > \epsilon means: You set a tight tolerance, say, ϵ=0.01\epsilon = 0.01 bits. An error occurs if your measured sample entropy YnY_n misses the true entropy H(X)H(X) by more than that tiny margin.
  • What the probability measures: It asks: “If I inspect a randomly generated message of length nn, what is the chance its average surprise is outside that narrow band?”
  • What convergence means: As nn grows, the percentage of messages that miss the target band shrinks to zero. It guarantees that for large nn, almost every individual message you inspect is well-behaved.

2. Why “in mean square” is different (Extreme outlier sensitivity)

Mean square convergence demands that the average squared error E[(Yn−c)2]\mathbb{E}[(Y_n - c)^2] goes to zero.

  • The difference: While convergence in probability only counts how often an error occurs, mean square multiplies the probability of an error by the magnitude squared of that error.
  • Why this matters: Imagine an extremely rare message (like an operator accidentally typing a million identical symbols in a row). The probability of this happening might be 2−1,000,0002^{-1,000,000} (effectively zero), but its surprise value could be mathematically enormous. Mean square convergence is overly sensitive to the numerical size of rare tails, whereas convergence in probability simply notes that such catastrophic tails carry near-zero probability mass.

3. Why “almost surely” is different (The infinite timeline)

Almost sure convergence Pr⁡{lim⁡n→∞Yn=c}=1\Pr\{ \lim_{n \to \infty} Y_n = c \} = 1 is about what happens if you never cut the tape.

  • The difference: Convergence in probability checks a single fixed length nn: if you choose a message of length n=10,000n = 10,000, is it likely inside the band? Yes. But if you keep letting the tape run forever (n→∞n \to \infty on a single physical machine), will the sample entropy eventually wiggle outside the tolerance band ±ϵ\pm \epsilon at least once in the distant future?
  • Why this matters: Almost sure convergence requires that on a single unbroken timeline, there is a point after which the measurement never leaves the band again, ever. That is a much stronger mathematical condition than just requiring a message of fixed size nn to be well-behaved when received.

IntuitionWhy the AEP uses convergence in probability

For transmission and codebook design, a telecom engineer works with packets of a specific, fixed block length nn.

  1. The engineer does not run an infinite continuous stream with no breaks, they package messages into finite blocks of length nn (so almost sure convergence is unnecessarily strict).
  2. The engineer does not care if an astronomically improbable gibberish message has a mathematically huge surprise value (so mean square convergence is the wrong metric).

All the engineer needs is a guarantee on coverage: “If I design short binary codes for messages whose sample entropy is within ϵ\epsilon of H(X)H(X), what fraction of actual transmissions will my codebook successfully handle?”

Convergence in probability provides that exact answer: the probability of receiving a message outside the target band shrinks to zero as block length nn grows.


The AEP theorem

TheoremAsymptotic Equipartition Property

If X1,X2,…X_1, X_2, \ldots are i.i.d. ∼p(x)\sim p(x), then the sample entropy converges to the true entropy in probability:

−1nlog⁡p(X1,X2,…,Xn)⟶H(X)-\frac{1}{n} \log p(X_1, X_2, \ldots, X_n) \longrightarrow H(X)

IntuitionWhat the terms actually mean

  • −log⁡p(X1,…,Xn)-\log p(X_1, \ldots, X_n) (Total Surprise): The actual number of bits of pure information contained in the specific sequence that was just generated.
  • −1nlog⁡p(X1,…,Xn)-\frac{1}{n} \log p(X_1, \ldots, X_n) (Sample Entropy): The total surprise divided by nn. This is the empirical average bits per symbol delivered by this specific sequence.
  • H(X)H(X) (Theoretical Entropy): The true statistical average calculated directly from the language model p(x)p(x) before any message is typed.

The Takeaway: The theorem guarantees that for large nn, almost every sequence actually produced by the source will have a sample entropy extremely close to H(X)H(X).

When you rearrange −1nlog⁡p(sequence)≈H(X)-\frac{1}{n}\log p(\text{sequence}) \approx H(X), you get the probability of any realistic sequence:

p(X1,…,Xn)≈2−nH(X)p(X_1, \ldots, X_n) \approx 2^{-nH(X)}

How this reveals the exact size of the codebook:

Here is where the counting insight appears:

  1. The total probability of all realistic messages combined must add up to nearly 11 (since non-typical gibberish almost never happens).
  2. Every single realistic message carries roughly the same individual probability slice: 2−nH(X)2^{-nH(X)}.

If a total probability cake of size ≈1\approx 1 is sliced into equal pieces of size 2−nH(X)2^{-nH(X)}, basic arithmetic tells you how many pieces there are:

Number of realistic messages≈Total ProbabilitySize of One Slice≈12−nH(X)=2nH(X)\text{Number of realistic messages} \approx \frac{\text{Total Probability}}{\text{Size of One Slice}} \approx \frac{1}{2^{-nH(X)}} = 2^{nH(X)}

This is why it is called the Asymptotic Equipartition Property: the realistic outcomes are partitioned into roughly equal probability pieces.

It solves the codebook sizing problem directly: out of the gargantuan universe of ∣X∣n|\mathcal{X}|^n possible sequences, only about 2nH(X)2^{nH(X)} of them will ever realistically occur. To assign short, unique codewords to every realistic sequence, the engineer only needs an index that can count to 2nH(X)2^{nH(X)}. That requires binary strings of length:

log⁡2(2nH(X))=nH(X) bits\log_2\big(2^{nH(X)}\big) = nH(X) \text{ bits}

Instead of spending nlog⁡∣X∣n \log |\mathcal{X}| bits on fixed-length codes for all possible messages, the engineer now knows they only need about nH(X)nH(X) bits to handle essentially all real-world traffic.

ProofReduce the joint surprise to a sample mean, then apply the weak law

Step 1: Independence survives the logarithm. Functions of independent random variables are themselves independent random variables. The XiX_i are i.i.d., and log⁡p(⋅)\log p(\cdot) is a fixed function applied to each one separately, so the random variables log⁡p(X1),log⁡p(X2),…\log p(X_1), \log p(X_2), \ldots are also i.i.d. This is the step that licenses everything after it.

Step 2: The joint surprise is a sum, because the keystrokes are independent. Independence gives p(x1,…,xn)=∏i=1np(xi)p(x_1, \ldots, x_n) = \prod_{i=1}^n p(x_i), and the logarithm turns that product into a sum, the same additivity that forced hh to be a logarithm in the first place (see the three conditions on hh):

−1nlog⁡p(X1,X2,…,Xn)=−1n∑i=1nlog⁡p(Xi)-\frac{1}{n} \log p(X_1, X_2, \ldots, X_n) = -\frac{1}{n} \sum_{i=1}^n \log p(X_i)

The left side is the surprise of one enormous composite event; the right side is an ordinary sample mean of nn i.i.d. terms. The whole theorem is this rewriting.

Step 3: Apply the weak law of large numbers. A sample mean of i.i.d. terms converges in probability to the expectation of a single term:

−1n∑i=1nlog⁡p(Xi)⟶−E[log⁡p(X)]in probability-\frac{1}{n} \sum_{i=1}^n \log p(X_i) \longrightarrow -\mathbb{E}\big[\log p(X)\big] \quad \text{in probability}

Step 4: Recognize the expectation. By definition −E[log⁡p(X)]=−∑xp(x)log⁡p(x)=H(X)-\mathbb{E}[\log p(X)] = -\sum_x p(x) \log p(x) = H(X). Chaining Steps 2–4:

−1nlog⁡p(X1,…,Xn)⟶H(X)in probability-\frac{1}{n} \log p(X_1, \ldots, X_n) \longrightarrow H(X) \quad \text{in probability}

∎

For an independent and identically distributed (i.i.d.) source, the joint probability of the tape is p(Xn)=∏i=1np(Xi)p(X^n) = \prod_{i=1}^n p(X_i). We define the sample entropy (empirical surprise rate) as:

Hˉn=−1nlog⁡2p(Xn)=1n∑i=1n(−log⁡2p(Xi))\bar{H}_n = -\frac{1}{n} \log_2 p(X^n) = \frac{1}{n} \sum_{i=1}^n \left(-\log_2 p(X_i)\right)

Notice the mathematical structure: Hˉn\bar{H}_n is simply the sample average of nn independent random variables, where each step draws an individual surprise value Si=−log⁡2p(Xi)S_i = -\log_2 p(X_i).

Consider an unbalanced binary source that types 1 with probability p=0.9p = 0.9 and 0 with probability p=0.1p = 0.1:

  • True Entropy: H(X)=−0.9log⁡2(0.9)−0.1log⁡2(0.1)≈0.469 bits/symbolH(X) = -0.9 \log_2(0.9) - 0.1 \log_2(0.1) \approx 0.469\text{ bits/symbol}
  • Per-symbol variance of surprise: σ2=Var(−log⁡2p(Xi))≈0.9043\sigma^2 = \text{Var}(-\log_2 p(X_i)) \approx 0.9043

By the Central Limit Theorem, the distribution of observed sample entropy across many generated tapes follows a normal distribution centered at HH, with variance shrinking as σ2/n\sigma^2 / n:

Hˉn∼N(0.469,  0.9043n)\bar{H}_n \sim \mathcal{N}\left(0.469, \; \frac{0.9043}{n}\right)

As the tape length grows from n=25n = 25 to n=1000n = 1000, the sample entropy distribution concentrates ever more violently into a sharp spike at H≈0.469H \approx 0.469:

Spread of the sample entropy −(1/n) log₂ p(Xⁿ) for p = 0.9 (normal approximation): n = 25 = exp(-(s - 0.469)^2 / (2 * 0.9043 / 25)) / sqrt(2 * pi * 0.9043 / 25); n = 100 = exp(-(s - 0.469)^2 / (2 * 0.9043 / 100)) / sqrt(2 * pi * 0.9043 / 100); n = 1000 = exp(-(s - 0.469)^2 / (2 * 0.9043 / 1000)) / sqrt(2 * pi * 0.9043 / 1000)00.20.40.60.810510sample entropy (bits per symbol)probability density
  • n = 25
  • n = 100
  • n = 1000
Spread of the sample entropy −(1/n) log₂ p(Xⁿ) for p = 0.9 (normal approximation)

IntuitionWhat This Plot Proves: The Emergence of the “Typical Set”

Although there are 2n2^n theoretically possible tapes of length nn, the probability distribution over those tapes behaves in a non-uniform way:

  1. Probability Mass Collapses into a Needle: As nn grows large, virtually 100%100\% of the probability mass concentrates entirely on sequences whose sample entropy lands inside a tight ε\varepsilon-band around H(X)≈0.469 bits/symbolH(X) \approx 0.469\text{ bits/symbol}.

  2. Extreme Sequences Are Vanishingly Rare: While extreme sequences are physically possible, such as a tape of 1,0001,000 consecutive zeros (p=0.11000=10−1000p = 0.1^{1000} = 10^{-1000}) or 1,0001,000 consecutive ones (p=0.91000≈1.7×10−46p = 0.9^{1000} \approx 1.7 \times 10^{-46}), the chance of observing any sequence whose empirical surprise deviates significantly from 0.4690.469 drops to zero.

  3. Equipartition (Equal Sharing of Surprise): Rearranging the sample entropy definition Hˉn=−1nlog⁡2p(xn)≈H(X)\bar{H}_n = -\frac{1}{n} \log_2 p(x^n) \approx H(X) gives:

    p(xn)≈2−nH(X)=2−0.469np(x^n) \approx 2^{-n H(X)} = 2^{-0.469 n}

    Every sequence that actually matters is equally likely. Almost any tape you will ever pull off this machine belongs to this tiny slice of sequences, each carrying essentially the exact same probability of 2−nH2^{-n H}.

  4. The Foundation of Lossless Compression: Because all typical tapes share probability 2−nH2^{-n H} and their cumulative probability sums to nearly 11, there can only be roughly 12−nH=2nH\frac{1}{2^{-n H}} = 2^{n H} such sequences in existence.

    Instead of spending nn bits to represent every conceivable sequence in the full 2n2^n space, an engineer only needs to assign labels to the 2nH2^{n H} typical sequences. This requires only:

    log⁡2(2nH)=nH(X)≈0.469n bits\log_2\left(2^{n H}\right) = n H(X) \approx 0.469 n \text{ bits}


The typical set

The AEP says the sample entropy of a printed tape concentrates on H(X)H(X). That lets us physically partition the space of all possible tapes Xn\mathcal{X}^n into two piles: the tapes whose sample entropy came out close to HH, and everything else.

flowchart LR
  S["All tapes: alphabet^n, count = |X|^n"] --> T["Typical set: sample entropy within epsilon of H"]
  S --> N["Nontypical set: everything else"]
  T --> TP["Probability nearly 1, count about 2^(nH)"]
  N --> NP["Probability nearly 0, count can be huge"]

DefinitionThe typical set Aϵ(n)A_\epsilon^{(n)}

The typical set Aϵ(n)A_\epsilon^{(n)} with respect to p(x)p(x) is the set of sequences (x1,x2,…,xn)∈Xn(x_1, x_2, \ldots, x_n) \in \mathcal{X}^n with the property

2−n(H(X)+ϵ)≤p(x1,x2,…,xn)≤2−n(H(X)−ϵ)2^{-n(H(X) + \epsilon)} \le p(x_1, x_2, \ldots, x_n) \le 2^{-n(H(X) - \epsilon)}

ComponentDetail
SignatureAϵ(n)⊆XnA_\epsilon^{(n)} \subseteq \mathcal{X}^n, a set of tapes, not a number.
Parametersnn, the tape length; ϵ\epsilon, the tolerance we allow on the per-keystroke surprise.
Membership testCompute the tape’s probability and check it lands in the band [2−n(H+ϵ), 2−n(H−ϵ)][2^{-n(H+\epsilon)},\, 2^{-n(H-\epsilon)}]. Taking −1nlog⁡-\frac{1}{n}\log of all three parts turns this into the equivalent test H−ϵ≤−1nlog⁡p(xn)≤H+ϵH - \epsilon \le -\frac{1}{n}\log p(x^n) \le H + \epsilon.

IntuitionWhat membership physically means

A tape is typical if it “sounds like the language.” Its letter frequencies came out close enough to the operator’s blueprint p(x)p(x) that its total surprise per key lands within ϵ\epsilon of H(X)H(X). It is not a statement about the content of the message, only about whether its statistics look ordinary for this source.

WarningThe most probable tape is usually not typical

Take a binary operator with p(1)=0.9p(1) = 0.9. The single most likely tape of length nn is the all-ones tape, with probability 0.9n0.9^n, larger than any other individual tape. But its sample entropy is −1nlog⁡(0.9n)=log⁡(1/0.9)≈0.152-\frac{1}{n}\log(0.9^n) = \log(1/0.9) \approx 0.152 bits, while H(X)=H(0.9)≈0.469H(X) = H(0.9) \approx 0.469 bits. It misses the band entirely and is atypical. “Typical” means representative of the source’s statistics, not most likely as an individual outcome.

While a tape of all 11s has a higher individual probability than any single 90%90\%-ones tape (0.9n≫0.90.9n0.10.1n0.9^n \gg 0.9^{0.9n} 0.1^{0.1n}), there is only one all-ones tape. In contrast, by basic combinatorics, there are (n0.9n)≈2nH(0.9)\binom{n}{0.9n} \approx 2^{n H(0.9)} different arrangements that have roughly 90%90\% ones. Even though each typical tape carries a smaller individual probability, their massive collective count sums to nearly 100%100\% of all real-world outcomes. We return to this exact example in High-probability sets and the typical set below.


Properties of the typical set

TheoremProperties of Aϵ(n)A_\epsilon^{(n)}

#PropertyMathematical StatementPlain English Meaning
1EquiprobabilityFor every xn∈Aϵ(n)x^n \in A_\epsilon^{(n)}:
2−n(H+ϵ)≤p(xn)≤2−n(H−ϵ)2^{-n(H+\epsilon)} \le p(x^n) \le 2^{-n(H-\epsilon)}
Every typical message has virtually the exact same likelihood: p(xn)≈2−nHp(x^n) \approx 2^{-nH}.
2Near-Total MassPr⁡(Xn∈Aϵ(n))>1−ϵ\Pr\big(X^n \in A_\epsilon^{(n)}\big) > 1 - \epsilon
(for large enough nn)
Typical sequences account for practically 100%100\% of all real-world traffic you will ever see.
3Upper Bound on Size∣Aϵ(n)∣≤2n(H+ϵ)\vert{}A_\epsilon^{(n)}\vert{} \le 2^{n(H + \epsilon)}There are at most 2n(H+ϵ)2^{n(H+\epsilon)} typical messages.
4Lower Bound on Size∣Aϵ(n)∣≥(1−ϵ)2n(H−ϵ)\vert{}A_\epsilon^{(n)}\vert{} \ge (1 - \epsilon) 2^{n(H - \epsilon)}There are at least (1−ϵ)2n(H−ϵ)(1-\epsilon)2^{n(H-\epsilon)} typical messages.

IntuitionWhat These Properties Actually Mean for an Engineer

1. Property 1: Why We Don’t Need Variable-Length Codes Inside the Set

Earlier in Information, Entropy, Relative Entropy, and Mutual Information, we saw the “whole-bit trap”: encoding letters one-by-one with probabilities like p=1/e≈0.368p = 1/e \approx 0.368 wastes bits because computers cannot emit 1.441.44 fractional bits per character.

The typical set solves this by grouping symbols into large blocks (e.g., n=10,000n = 10,000).

  • In a block of 10,00010,000, every typical sequence has the same probability: p≈2−10000Hp \approx 2^{-10000 H}.
  • Because no typical message is more likely than another, you do not need variable-length codes inside the set.
  • You simply assign every typical sequence a fixed-length serial number: sequence #1 is 000...001, sequence #2 is 000...010, etc. The fractional bit problem vanishes because rounding 10,000×H10,000 \times H to the nearest whole integer introduces negligible overhead across the block.

2. Property 2: What 1−ϵ1 - \epsilon Actually Guarantees

ϵ\epsilon is your small allowed margin of error (for example, ϵ=0.01\epsilon = 0.01).

  • Property 2 says that the probability of seeing a typical sequence is greater than 1−0.01=0.991 - 0.01 = 0.99 (over 99%99\%).
  • If you want a more reliable system with 99.99%99.99\% certainty (ϵ=0.0001\epsilon = 0.0001), you do not change the math, you simply transmit longer blocks (nn). As nn grows, typical messages swallow nearly 100%100\% of all probability mass.

3. Properties 3 & 4: Sizing Your Hardware (The “Bricks” Analogy)

Think of total probability as total weight and each typical sequence as an individual brick:

  • The total weight of all typical bricks combined is between 1−ϵ1 - \epsilon and 1.01.0 (from Property 2).
  • From Property 1, every individual brick weighs between a lightest weight of pmin⁡=2−n(H+ϵ)p_{\min} = 2^{-n(H+\epsilon)} and a heaviest weight of pmax⁡=2−n(H−ϵ)p_{\max} = 2^{-n(H-\epsilon)}.

Now, how many bricks can there be?

  • Property 3 (Upper Bound : Sizing your memory): To find the maximum possible number of bricks, assume the total weight is as large as possible (1.01.0) and each brick is as light as possible (pmin⁡p_{\min}): Max Count=Max Total WeightMin Individual Weight=12−n(H+ϵ)=2n(H+ϵ)\text{Max Count} = \frac{\text{Max Total Weight}}{\text{Min Individual Weight}} = \frac{1}{2^{-n(H+\epsilon)}} = 2^{n(H+\epsilon)} Engineering takeaway: Your lookup table only needs enough memory addresses to hold 2n(H+ϵ)2^{n(H+\epsilon)} entries. You will never need more than n(H+ϵ)n(H+\epsilon) bits to index them.

  • Property 4 (Lower Bound : Proving the savings are real): Could the typical set be trivially small (e.g., just 10 sequences)? To find the minimum possible number of bricks, assume the total weight is at its lower threshold (1−ϵ1 - \epsilon) and each brick is as heavy as possible (pmax⁡p_{\max}): Min Count=Min Total WeightMax Individual Weight=1−ϵ2−n(H−ϵ)=(1−ϵ)2n(H−ϵ)\text{Min Count} = \frac{\text{Min Total Weight}}{\text{Max Individual Weight}} = \frac{1 - \epsilon}{2^{-n(H-\epsilon)}} = (1 - \epsilon)2^{n(H-\epsilon)} Engineering takeaway: The typical set cannot collapse. Its size is guaranteed to be around 2nH2^{nH}.

Put the size next to the coverage: the typical set holds almost all the probability, yet as a fraction of all 2n2^n binary tapes it is only about 2nH/2n=2−n(1−H)2^{nH}/2^n = 2^{-n(1-H)}. Unless the source is a fair coin (H=1H = 1 as we showed in the binary entropy plot), this ratio drops exponentially to zero as nn grows:

Typical tapes as a fraction of all 2ⁿ tapes ≈ 2^(−n(1 − H)): p = 0.9 (H ≈ 0.469) = 2^(-n * (1 - 0.469)); p = 0.7 (H ≈ 0.881) = 2^(-n * (1 - 0.881)); p = 0.5 (H = 1: every tape is typical) = 1 + 0 * n010203040506000.51tape length nfraction of all tapes
  • p = 0.9 (H ≈ 0.469)
  • p = 0.7 (H ≈ 0.881)
  • p = 0.5 (H = 1: every tape is typical)
Typical tapes as a fraction of all 2ⁿ tapes ≈ 2^(−n(1 − H))

For a source with p=0.9p = 0.9 (H≈0.469 bitsH \approx 0.469\text{ bits}) and a modest tape length of n=60n = 60:

  • The Vanishing Slice: The typical set accounts for only: ∣Aϵ(60)∣260≈2−60(1−0.469)=2−31.86≈13,800,000,000\frac{|A_\epsilon^{(60)}|}{2^{60}} \approx 2^{-60(1 - 0.469)} = 2^{-31.86} \approx \frac{1}{3,800,000,000} It comprises barely one out of every four billion possible binary sequences.

  • The Overwhelming Mass: Despite being an infinitesimal sliver of all possible sequences, this tiny subset carries over 99%99\% of the entire probability mass.

  • Why Compression Works: Compression does not work by inventing complicated tricks for every single one of the 2n2^n theoretical sequences. Instead, it simply ignores the vast, empty wasteland of atypical sequences and assigns short, fixed-length binary index labels solely to the typical set. This cuts the required transmission length from nn bits down to just nH(X)n H(X) bits with negligible probability of error.

ProofComplete proof of all four properties

Part 1: The Equiprobability Band By definition, a sequence belongs to Aϵ(n)A_\epsilon^{(n)} if its probability satisfies: 2−n(H+ϵ)≤p(x1,…,xn)≤2−n(H−ϵ)2^{-n(H + \epsilon)} \le p(x_1, \ldots, x_n) \le 2^{-n(H - \epsilon)} Since the base-2 logarithm is strictly increasing, taking log⁡2\log_2 across the inequality preserves the order: −n(H+ϵ)≤log⁡p(x1,…,xn)≤−n(H−ϵ)-n(H + \epsilon) \le \log p(x_1, \ldots, x_n) \le -n(H - \epsilon) Multiplying through by −1n-\frac{1}{n} is multiplying by a negative number, which reverses both inequality signs: H+ϵ≥−1nlog⁡p(x1,…,xn)≥H−ϵH + \epsilon \ge -\frac{1}{n} \log p(x_1, \ldots, x_n) \ge H - \epsilon Rewriting in standard ascending order yields Property 1: H(X)−ϵ≤−1nlog⁡p(x1,…,xn)≤H(X)+ϵH(X) - \epsilon \le -\frac{1}{n} \log p(x_1, \ldots, x_n) \le H(X) + \epsilon

Part 2: High Probability Mass The AEP theorem proves that −1nlog⁡p(Xn)→H(X)-\frac{1}{n}\log p(X^n) \to H(X) in probability. By definition of convergence in probability, for any tolerance ϵ>0\epsilon > 0 and any allowed failure probability δ>0\delta > 0, there exists an integer n0n_0 such that for all n≥n0n \ge n_0: Pr⁡(∣−1nlog⁡p(Xn)−H(X)∣<ϵ)>1−δ\Pr\left( \left\lvert -\frac{1}{n}\log p(X^n) - H(X) \right\rvert < \epsilon \right) > 1 - \delta By Part 1, the condition ∣−1nlog⁡p(Xn)−H(X)∣≤ϵ\lvert -\frac{1}{n}\log p(X^n) - H(X) \rvert \le \epsilon is precisely the condition that Xn∈Aϵ(n)X^n \in A_\epsilon^{(n)}. Thus: Pr⁡{Aϵ(n)}>1−δ\Pr\big\{ A_\epsilon^{(n)} \big\} > 1 - \delta Since this statement holds for any arbitrarily small δ>0\delta > 0, we can choose δ=ϵ\delta = \epsilon for convenience, yielding Pr⁡{Aϵ(n)}>1−ϵ\Pr\{A_\epsilon^{(n)}\} > 1 - \epsilon for all sufficiently large nn.

Part 3: Upper Bound on Size The total probability of all possible sequences in the entire universe Xn\mathcal{X}^n must sum to 1: 1=∑xn∈Xnp(xn)1 = \sum_{x^n \in \mathcal{X}^n} p(x^n) Restricting this sum strictly to the typical subset can only decrease the sum: 1≥∑xn∈Aϵ(n)p(xn)1 \ge \sum_{x^n \in A_\epsilon^{(n)}} p(x^n) By the membership condition, every typical sequence has an individual probability bounded below by p(xn)≥2−n(H+ϵ)p(x^n) \ge 2^{-n(H + \epsilon)}. Replacing each term with this minimum floor: 1≥∑xn∈Aϵ(n)2−n(H+ϵ)1 \ge \sum_{x^n \in A_\epsilon^{(n)}} 2^{-n(H + \epsilon)} Because the term 2−n(H+ϵ)2^{-n(H + \epsilon)} is a constant that does not depend on xnx^n, summing it over all elements in Aϵ(n)A_\epsilon^{(n)} simply multiplies it by the total count ∣Aϵ(n)∣\lvert A_\epsilon^{(n)} \rvert: 1≥∣Aϵ(n)∣⋅2−n(H(X)+ϵ)1 \ge \lvert A_\epsilon^{(n)} \rvert \cdot 2^{-n(H(X) + \epsilon)} Multiplying both sides by 2n(H(X)+ϵ)2^{n(H(X) + \epsilon)} proves the upper bound: ∣Aϵ(n)∣≤2n(H(X)+ϵ)\big\lvert A_\epsilon^{(n)} \big\rvert \le 2^{n(H(X) + \epsilon)}

Part 4: Lower Bound on Size From Part 2, for sufficiently large nn, the total probability mass contained inside the typical set exceeds 1−ϵ1 - \epsilon: 1−ϵ<Pr⁡{Aϵ(n)}=∑xn∈Aϵ(n)p(xn)1 - \epsilon < \Pr\big\{ A_\epsilon^{(n)} \big\} = \sum_{x^n \in A_\epsilon^{(n)}} p(x^n) By the membership condition, every typical sequence has an individual probability bounded above by p(xn)≤2−n(H−ϵ)p(x^n) \le 2^{-n(H - \epsilon)}. Replacing each term with this maximum ceiling: 1−ϵ<∑xn∈Aϵ(n)2−n(H−ϵ)1 - \epsilon < \sum_{x^n \in A_\epsilon^{(n)}} 2^{-n(H - \epsilon)} Factoring out the constant ceiling collapses the sum into a direct count: 1−ϵ<∣Aϵ(n)∣⋅2−n(H(X)−ϵ)1 - \epsilon < \lvert A_\epsilon^{(n)} \rvert \cdot 2^{-n(H(X) - \epsilon)} Multiplying both sides by 2n(H(X)−ϵ)2^{n(H(X) - \epsilon)} completes the lower bound: ∣Aϵ(n)∣≥(1−ϵ)2n(H(X)−ϵ)\big\lvert A_\epsilon^{(n)} \big\rvert \ge (1 - \epsilon) 2^{n(H(X) - \epsilon)}

∎


Consequence: data compression

The problem: We now have a set of about 2nH2^{nH} tapes that soaks up nearly all the probability. But a set is not yet a product. The telecom engineer needs an actual code: a concrete mapping from every tape xnx^n the machine might print to a binary string they can push down the wire. Two hard constraints:

  • It must be one-to-one, so the receiver can invert it. We cannot simply refuse to encode the atypical tapes, rare is not impossible, and a code that silently fails on them is not a code.
  • It must be cheap on average, since the telecom is charged per pulse actually sent, not per codeword slot reserved.

The tension is that these pull in opposite directions: covering every tape is what forces the nlog⁡∣X∣n \log \lvert \mathcal{X} \rvert cost in the first place. The resolution is to cover everything but charge differently for the two piles.

The two-part code

Order the elements within each pile by some fixed convention (lexicographic, say), and represent a tape by its index within its own pile, prefixed by a flag bit saying which pile it came from.

PileSizeIndex costFlagTotal length
Typical Aϵ(n)A_\epsilon^{(n)}≤2n(H+ϵ)\le 2^{n(H + \epsilon)}≤n(H+ϵ)+1\le n(H + \epsilon) + 1 bits0≤n(H+ϵ)+2\le n(H + \epsilon) + 2 bits
Atypical Aϵ(n)c{A_\epsilon^{(n)}}^c≤∣X∣n\le \lvert \mathcal{X} \rvert^n≤nlog⁡∣X∣+1\le n \log \lvert \mathcal{X} \rvert + 1 bits1≤nlog⁡∣X∣+2\le n \log \lvert \mathcal{X} \rvert + 2 bits

To see the actual bits, take the p=0.9p = 0.9 operator with ϵ=0.05\epsilon = 0.05 and a short tape, n=10n = 10. Only tapes with exactly one 0 have sample entropy within ϵ\epsilon of H≈0.469H \approx 0.469, so the typical pile holds just 1010 tapes and ⌈log⁡210⌉=4\lceil \log_2 10 \rceil = 4 index bits suffice (inside the n(H+ϵ)+1≈6.2n(H + \epsilon) + 1 \approx 6.2 bound). In lexicographic order, 1111011111 is tape number 44 of that pile, counting from 00:

Typical tape 1111011111 → 5 bits
0flag0100index in typical pile
Atypical tape 1110111011 → 11 bits
1flag1110111011the tape itself
Fixed-length code, any tape → 10 bits
1111011111the tape itself
The two-part code for n = 10, p = 0.9, ε = 0.05

The receiver reads the flag first, which tells it whether 44 or 1010 more bits follow. At n=10n = 10 the typical pile only carries 10⋅0.99⋅0.1≈39%10 \cdot 0.9^9 \cdot 0.1 \approx 39\% of the probability, so this length shows the layout, not the savings; those need the large nn of the theorem.

NoteWhere the two extra bits come from

One bit is the flag. The other is a ceiling: indexing 2n(H+ϵ)2^{n(H+\epsilon)} items needs ⌈n(H+ϵ)⌉\lceil n(H + \epsilon) \rceil bits, and n(H+ϵ)n(H + \epsilon) need not be an integer, so n(H+ϵ)+1n(H + \epsilon) + 1 safely covers it. Same for the atypical pile.

IntuitionWhat the flag bit is physically doing

The initial bit is a length flag: it tells the receiver, before they have decoded anything, which of the two codeword lengths to read off the wire. That is what makes the scheme one-to-one and easily decodable despite the two piles having different codeword lengths.

RemarkWe are being deliberately wasteful, and it doesn’t matter

Notice that we indexed the atypical set by brute-force enumeration over all of Xn\mathcal{X}^n, ignoring the fact that ∣Aϵ(n)c∣\lvert {A_\epsilon^{(n)}}^c \rvert is strictly smaller than ∣Xn∣\lvert \mathcal{X}^n \rvert. We are paying full price for a pile we could have indexed more cleverly. Surprisingly, this crude treatment is still good enough to yield an efficient description, because the pile it wastes bits on has probability under ϵ\epsilon, so the waste is multiplied by almost nothing.

Expected Codeword Length: Why the Math Works

The two-part code assigns two completely different lengths:

  • If a tape is typical, it costs a short length: ≤n(H+ϵ)+2\le n(H + \epsilon) + 2 bits.
  • If a tape is atypical, it costs a long, uncompressed length: ≤nlog⁡2∣X∣+2\le n \log_2 \vert{}\mathcal{X}\vert{} + 2 bits.

An engineer might worry: Won’t the massive length of the atypical pile ruin our average bitrate whenever an atypical tape occurs?

Because atypical tapes occur with probability less than ϵ\epsilon, their massive bit cost is multiplied by a vanishingly small probability, making their total impact on average bandwidth negligible.


TheoremShannon’s Source Coding Theorem (Lossless Block Coding)

Let Xn=(X1,X2,…,Xn)X^n = (X_1, X_2, \dots, X_n) be an i.i.d. source with entropy H(X)H(X), and let ϵ>0\epsilon > 0.

There exists an invertible (one-to-one) code mapping every sequence xnx^n into a binary string such that the expected code length per symbol satisfies:

E[1nl(Xn)]≤H(X)+ϵ′\mathbb{E}\left[ \frac{1}{n} l(X^n) \right] \le H(X) + \epsilon'

where ϵ′\epsilon' can be made arbitrarily small by choosing nn sufficiently large.

In plain English: In the limit of long blocks, you can compress a stream down to an average rate of H(X)H(X) bits per symbol with zero data loss.


Visualizing the Amortization of Overhead

For our operator with p=0.9p = 0.9 (H≈0.469H \approx 0.469 bits/symbol) and ϵ=0.05\epsilon = 0.05:

  • An uncompressed fixed-length code costs log⁡2(2)=1.0 bit/symbol\log_2(2) = 1.0\text{ bit/symbol} regardless of nn.
  • The two-part code adds an overhead of 22 extra bits (1 flag bit + 1 rounding bit) spread across the entire block of nn characters.
  • As nn grows, this overhead 2n\frac{2}{n} quickly shrinks to zero, and the average bits per symbol plunge toward the true entropy floor H=0.469H = 0.469:
Bits per symbol for a typical tape, p = 0.9, ε = 0.05: two-part code: H + ε + 2/n = 0.469 + 0.05 + 2 / n; fixed-length code: log₂ |X| = 1 = 1 + 0 * n; entropy H = 0.469 + 0 * n2040608010000.511.5tape length nbits per symbol
  • two-part code: H + ε + 2/n
  • fixed-length code: log₂ |X| = 1
  • entropy H
Bits per symbol for a typical tape, p = 0.9, ε = 0.05

ProofStep-by-Step Proof of the Expected Codeword Length Bound

Step 1: Write down the definition of expected length. The average number of bits transmitted per block across all possible sequences xn∈Xnx^n \in \mathcal{X}^n is:

E[l(Xn)]=∑xn∈Xnp(xn) l(xn)\mathbb{E}\big[l(X^n)\big] = \sum_{x^n \in \mathcal{X}^n} p(x^n)\, l(x^n)

Step 2: Partition the world into the two piles. Every sequence falls into either the typical set Aϵ(n)A_\epsilon^{(n)} or the atypical set Aϵ(n)c{A_\epsilon^{(n)}}^c. The sum splits cleanly:

E[l(Xn)]=∑xn∈Aϵ(n)p(xn) l(xn)  +  ∑xn∈Aϵ(n)cp(xn) l(xn)\mathbb{E}\big[l(X^n)\big] = \sum_{x^n \in A_\epsilon^{(n)}} p(x^n)\, l(x^n) \;+\; \sum_{x^n \in {A_\epsilon^{(n)}}^c} p(x^n)\, l(x^n)

Step 3: Plug in the maximum codeword length for each pile. From our table, typical codewords never exceed n(H+ϵ)+2n(H + \epsilon) + 2 bits, and atypical codewords never exceed nlog⁡2∣X∣+2n \log_2 \vert{}\mathcal{X}\vert{} + 2 bits. Replacing each length with its worst-case bound:

≤∑xn∈Aϵ(n)p(xn)(n(H+ϵ)+2)  +  ∑xn∈Aϵ(n)cp(xn)(nlog⁡2∣X∣+2)\le \sum_{x^n \in A_\epsilon^{(n)}} p(x^n)\big(n(H + \epsilon) + 2\big) \;+\; \sum_{x^n \in {A_\epsilon^{(n)}}^c} p(x^n)\big(n \log_2 \vert{}\mathcal{X}\vert{} + 2\big)

Step 4: Factor out the length constants. Since the bracketed lengths are identical constants across all items in their respective piles, pull them outside the summations:

=(n(H+ϵ)+2)∑xn∈Aϵ(n)p(xn)⏟Pr⁡(Aϵ(n))  +  (nlog⁡2∣X∣+2)∑xn∈Aϵ(n)cp(xn)⏟Pr⁡(Aϵ(n)c)= \left(n(H + \epsilon) + 2\right) \underbrace{\sum_{x^n \in A_\epsilon^{(n)}} p(x^n)}_{\Pr(A_\epsilon^{(n)})} \;+\; \left(n \log_2 \vert{}\mathcal{X}\vert{} + 2\right) \underbrace{\sum_{x^n \in {A_\epsilon^{(n)}}^c} p(x^n)}_{\Pr({A_\epsilon^{(n)}}^c)}

Step 5: Apply probability bounds (where the miracle happens).

  • For the typical pile, use the trivial ceiling: Pr⁡(Aϵ(n))≤1\Pr(A_\epsilon^{(n)}) \le 1.
  • For the atypical pile, Property 2 of the typical set guarantees: Pr⁡(Aϵ(n)c)≤ϵ\Pr({A_\epsilon^{(n)}}^c) \le \epsilon.

Substituting these values:

E[l(Xn)]≤1⋅(n(H+ϵ)+2)  +  ϵ⋅(nlog⁡2∣X∣+2)\mathbb{E}\big[l(X^n)\big] \le 1 \cdot \big(n(H + \epsilon) + 2\big) \;+\; \epsilon \cdot \big(n \log_2 \vert{}\mathcal{X}\vert{} + 2\big)

Distributing and combining the constant terms (2+2ϵ≤2+2(1)=42 + 2\epsilon \le 2 + 2(1) = 4, or simply factoring +2+2 since probabilities sum to 1):

E[l(Xn)]≤n(H+ϵ)+ϵ nlog⁡2∣X∣+2\mathbb{E}\big[l(X^n)\big] \le n(H + \epsilon) + \epsilon\, n \log_2 \vert{}\mathcal{X}\vert{} + 2

Step 6: Compute the per-symbol average bit rate. Divide the total expected length by the block length nn:

E[1nl(Xn)]≤H(X)+ϵ+ϵlog⁡2∣X∣+2n⏟ϵ′\mathbb{E}\left[\frac{1}{n} l(X^n)\right] \le H(X) + \underbrace{\epsilon + \epsilon \log_2 \vert{}\mathcal{X}\vert{} + \frac{2}{n}}_{\epsilon'}

Step 7: Vanish the excess overhead ϵ′\epsilon'. Notice what makes up ϵ′=ϵ(1+log⁡2∣X∣)+2n\epsilon' = \epsilon(1 + \log_2 \vert{}\mathcal{X}\vert{}) + \frac{2}{n}:

  1. ∣X∣\vert{}\mathcal{X}\vert{} is a fixed constant of the alphabet (e.g., ∣X∣=2\vert{}\mathcal{X}\vert{} = 2 for binary). We can pick ϵ\epsilon arbitrarily small upfront so that ϵ(1+log⁡2∣X∣)\epsilon(1 + \log_2 \vert{}\mathcal{X}\vert{}) is as close to 00 as we desire.
  2. With ϵ\epsilon fixed, we choose nn large enough so that the overhead term 2n→0\frac{2}{n} \to 0.

Thus, ϵ′\epsilon' can be made as small as desired, completing the proof.

∎


IntuitionThe Economic Takeaway for the Telecom Network

  • Without typical set coding: A naive engineer builds a codebook for all ∣X∣n\vert{}\mathcal{X}\vert{}^n possible sequences. For a binary source, this forces a rate of log⁡2(2)=1.0 bit per symbol\log_2(2) = 1.0\text{ bit per symbol} for every message sent.
  • With typical set coding: The engineer bills approximately H(X)H(X) bits per symbol on average.

The difference between the uncompressed rate and the compressed rate:

Δ=log⁡2∣X∣−H(X)\Delta = \log_2 \vert{}\mathcal{X}\vert{} - H(X)

is the redundancy of the source. It represents the wasted bandwidth caused by predictability in the message stream.

Notice the critical guarantee: no information was sacrificed to achieve this saving. The code remains strictly 1-to-11\text{-to-}1 and fully invertible. If an exceedingly rare sequence (like 1,000 zeros) appears, the receiver still decodes it perfectly because the flag bit 1 routes the decoder to the uncompressed dictionary. We simply refuse to optimize bandwidth for events that almost never happen.


High-probability sets and the typical set

The Problem:
The typical set Aϵ(n)A_\epsilon^{(n)} contains roughly 2nH(X)2^{n H(X)} sequences and captures almost all probability (>1−ϵ> 1 - \epsilon). But nowhere did we prove it is the smallest set with this property.

Could a clever engineer beat Shannon’s bound? What if, instead of filtering sequences by their sample-entropy band, they greedily picked the absolute most probable sequences one by one until they accumulated 99%99\% of the probability mass? Could that hand-picked set be dramatically smaller, say, requiring only 0.3n0.3 n bits instead of nH(X)n H(X) bits?

To settle this, we analyze the absolute best competitor that could ever exist.

The Competitor: The Smallest High-Probability Set Bδ(n)B_\delta^{(n)}

DefinitionSmallest High-Probability Set Bδ(n)B_\delta^{(n)}

For any allowed error tolerance δ>0\delta > 0, let Bδ(n)⊂XnB_\delta^{(n)} \subset \mathcal{X}^n be the smallest possible set of length-nn sequences whose total probability mass is at least 1−δ1 - \delta:

Pr⁡{Bδ(n)}≥1−δ\Pr\big\{ B_\delta^{(n)} \big\} \ge 1 - \delta

How the Two Sets Are Built (And Why They Differ)

  • Aϵ(n)A_\epsilon^{(n)} is a middle-band set: It collects sequences whose sample entropy lands inside a narrow band around H(X)H(X). It does not care whether an individual sequence is the single most likely tape in the universe.
  • Bδ(n)B_\delta^{(n)} is a greedy top-of-the-list set: It sorts all ∣X∣n\vert{}\mathcal{X}\vert{}^n possible sequences from highest probability to lowest probability and grabs from the top until the cumulative probability hits 1−δ1 - \delta.

Because their selection rules are completely different, the two sets do not contain the same elements.

The Theorem: You Cannot Beat 2nH2^{nH}

Even though Bδ(n)B_\delta^{(n)} greedily grabs the most probable sequences first, it cannot be significantly smaller than the typical set.

TheoremLower Bound on Any High-Probability Set

Let X1,X2,…,XnX_1, X_2, \dots, X_n be an i.i.d. source with entropy H(X)H(X). For any error threshold δ<12\delta < \frac{1}{2} and any δ′>0\delta' > 0:

1nlog⁡2∣Bδ(n)∣>H(X)−δ′\frac{1}{n} \log_2 \big\lvert B_\delta^{(n)} \big\rvert > H(X) - \delta'

for all sufficiently large nn.

In plain English: Any set capturing at least (1−δ)(1 - \delta) of the probability mass must contain at least ≈2nH(X)\approx 2^{n H(X)} sequences. No codebook covering the stream with high probability can ever require fewer than H(X)H(X) bits per symbol.


ProofFormal Proof via the Intersection Argument

We prove that Bδ(n)B_\delta^{(n)} must contain at least (1−δ−ϵ)2n(H−ϵ)(1 - \delta - \epsilon) 2^{n(H - \epsilon)} sequences by looking at where it overlaps with the typical set Aϵ(n)A_\epsilon^{(n)}.

Step 1: The two sets must heavily overlap.
Recall that for large nn, the typical set carries nearly all mass: Pr⁡{Aϵ(n)}>1−ϵ\Pr\big\{ A_\epsilon^{(n)} \big\} > 1 - \epsilon By definition, the greedy competitor also carries nearly all mass: Pr⁡{Bδ(n)}≥1−δ\Pr\big\{ B_\delta^{(n)} \big\} \ge 1 - \delta

Using the probability rule Pr⁡(A∩B)=Pr⁡(A)+Pr⁡(B)−Pr⁡(A∪B)\Pr(A \cap B) = \Pr(A) + \Pr(B) - \Pr(A \cup B) and the fact that Pr⁡(A∪B)≤1\Pr(A \cup B) \le 1:

Pr⁡{Aϵ(n)∩Bδ(n)}≥Pr⁡{Aϵ(n)}+Pr⁡{Bδ(n)}−1\Pr\big\{ A_\epsilon^{(n)} \cap B_\delta^{(n)} \big\} \ge \Pr\big\{ A_\epsilon^{(n)} \big\} + \Pr\big\{ B_\delta^{(n)} \big\} - 1 Pr⁡{Aϵ(n)∩Bδ(n)}>(1−ϵ)+(1−δ)−1=1−δ−ϵ\Pr\big\{ A_\epsilon^{(n)} \cap B_\delta^{(n)} \big\} > (1 - \epsilon) + (1 - \delta) - 1 = 1 - \delta - \epsilon

Since δ<12\delta < \frac{1}{2} and ϵ\epsilon can be chosen arbitrarily small, the overlapping region carries a substantial, positive fraction of the total probability mass (strictly bounded away from zero).

Step 2: Every sequence in that overlap is lightweight.
Every element xnx^n inside the overlap Aϵ(n)∩Bδ(n)A_\epsilon^{(n)} \cap B_\delta^{(n)} is by definition an element of Aϵ(n)A_\epsilon^{(n)}. From Property 1 of the typical set, no typical sequence can have probability larger than:

p(xn)≤2−n(H−ϵ)p(x^n) \le 2^{-n(H - \epsilon)}

Step 3: Sum the weights to bound the size.
Write out the probability of the overlap:

1−δ−ϵ<Pr⁡{Aϵ(n)∩Bδ(n)}=∑xn∈Aϵ(n)∩Bδ(n)p(xn)1 - \delta - \epsilon < \Pr\big\{ A_\epsilon^{(n)} \cap B_\delta^{(n)} \big\} = \sum_{x^n \in A_\epsilon^{(n)} \cap B_\delta^{(n)}} p(x^n)

Replace each term with its maximum possible weight 2−n(H−ϵ)2^{-n(H - \epsilon)}:

1−δ−ϵ<∑xn∈Aϵ(n)∩Bδ(n)2−n(H−ϵ)=∣Aϵ(n)∩Bδ(n)∣⋅2−n(H−ϵ)1 - \delta - \epsilon < \sum_{x^n \in A_\epsilon^{(n)} \cap B_\delta^{(n)}} 2^{-n(H - \epsilon)} = \big\lvert A_\epsilon^{(n)} \cap B_\delta^{(n)} \big\rvert \cdot 2^{-n(H - \epsilon)}

Rearranging:

∣Aϵ(n)∩Bδ(n)∣>(1−δ−ϵ)⋅2n(H−ϵ)\big\lvert A_\epsilon^{(n)} \cap B_\delta^{(n)} \big\rvert > (1 - \delta - \epsilon) \cdot 2^{n(H - \epsilon)}

Step 4: Conclude for the full set Bδ(n)B_\delta^{(n)}.
Because the intersection is a subset of Bδ(n)B_\delta^{(n)} (so ∣Bδ(n)∣≥∣Aϵ(n)∩Bδ(n)∣\lvert B_\delta^{(n)} \rvert \ge \lvert A_\epsilon^{(n)} \cap B_\delta^{(n)} \rvert):

∣Bδ(n)∣>(1−δ−ϵ)⋅2n(H−ϵ)\big\lvert B_\delta^{(n)} \big\rvert > (1 - \delta - \epsilon) \cdot 2^{n(H - \epsilon)}

Taking 1nlog⁡2\frac{1}{n}\log_2 on both sides:

1nlog⁡2∣Bδ(n)∣>log⁡2(1−δ−ϵ)n+H(X)−ϵ\frac{1}{n} \log_2 \big\lvert B_\delta^{(n)} \big\rvert > \frac{\log_2(1 - \delta - \epsilon)}{n} + H(X) - \epsilon

As n→∞n \to \infty, the term log⁡2(1−δ−ϵ)n→0\frac{\log_2(1 - \delta - \epsilon)}{n} \to 0. By picking ϵ<δ′\epsilon < \delta', we establish that 1nlog⁡2∣Bδ(n)∣>H(X)−δ′\frac{1}{n} \log_2 \vert{}B_\delta^{(n)}\vert{} > H(X) - \delta', completing the proof.

∎


First-Order Exponential Equality (≐\doteq)

Because both ∣Aϵ(n)∣\vert{}A_\epsilon^{(n)}\vert{} and ∣Bδ(n)∣\vert{}B_\delta^{(n)}\vert{} have counts governed by the exponent nH(X)n H(X), information theory uses a special asymptotic notation.

DefinitionFirst-Order Exponential Equality (≐\doteq)

Two sequences of numbers ana_n and bnb_n are equal to first order in the exponent (written an≐bna_n \doteq b_n) if:

lim⁡n→∞1nlog⁡2anbn=0\lim_{n \to \infty} \frac{1}{n} \log_2 \frac{a_n}{b_n} = 0

IntuitionWhy Engineers Care About ≐\doteq

This notation deliberately ignores sub-exponential polynomial pre-factors.

For instance, if an=2nHa_n = 2^{nH} and bn=n50⋅2nHb_n = n^{50} \cdot 2^{nH}, then an≐bna_n \doteq b_n because:

1nlog⁡2(n50⋅2nH2nH)=50log⁡2nn→n→∞0\frac{1}{n} \log_2 \left( \frac{n^{50} \cdot 2^{nH}}{2^{nH}} \right) = \frac{50 \log_2 n}{n} \xrightarrow{n \to \infty} 0

For hardware design, indexing ana_n costs nHn H bits, while indexing bnb_n costs nH+50log⁡2nn H + 50 \log_2 n bits. Dividing by nn shows that the extra cost per symbol is 50log⁡2nn→0\frac{50 \log_2 n}{n} \to 0. Polynomial differences cost zero extra bits per symbol in the long run.

Using this notation, the conclusion is:

∣Bδ(n)∣  ≐  ∣Aϵ(n)∣  ≐  2nH(X)\big\lvert B_\delta^{(n)} \big\rvert \;\doteq\; \big\lvert A_\epsilon^{(n)} \big\rvert \;\doteq\; 2^{n H(X)}

The smallest high-probability set and the typical set are of the exact same size to first order in the exponent. The typical set is already asymptotically optimal.

Comparison: Where Do the Two Sets Actually Differ?

Consider our binary source typing 1 with probability p=0.9p = 0.9 and 0 with probability p=0.1p = 0.1, where H(X)≈0.469 bitsH(X) \approx 0.469\text{ bits}.

FeatureThe Typical Set Aϵ(n)A_\epsilon^{(n)}The Smallest Set Bδ(n)B_\delta^{(n)}
Membership RuleTapes with roughly 90%90\% ones (sample entropy near 0.4690.469).The most probable individual tapes, picked greedily from highest to lowest.
Contains all-ones tape 11...11?NO. Its sample entropy is −log⁡2(0.9)≈0.152 bits-\log_2(0.9) \approx 0.152\text{ bits}, which fails the band condition ∣0.152−0.469∣≤ϵ\vert{}0.152 - 0.469\vert{} \le \epsilon.YES. It is the single most probable tape in the entire sample space (p=0.9np = 0.9^n).
Contains the 90%90\%-ones tapes?YES. This is the core band.YES. Because all-ones and near-all-ones tapes are not enough to reach 99%99\% mass, it is forced to include the 90%90\%-ones tapes.
Asymptotic Size≐2n(0.469)\doteq 2^{n(0.469)}≐2n(0.469)\doteq 2^{n(0.469)}

IntuitionReconciling the Difference

  • Bδ(n)B_\delta^{(n)} contains exceptional high-probability outliers (like 111...111) that Aϵ(n)A_\epsilon^{(n)} excludes.
  • However, the number of such extreme outliers is exponentially tiny compared to the massive combinatorial swarm of sequences containing ≈90%\approx 90\% ones.
  • To reach 99%99\% probability mass, Bδ(n)B_\delta^{(n)} is forced to swallow that exact same combinatorial swarm of ≈90%\approx 90\% ones. Because that bulk dominates the count, the size of both sets is driven entirely by 2nH(X)2^{nH(X)}.

WarningScope and Open Questions: Where the Weak AEP Leaves Us

To see where this leaves the broader theory we are deevloping, in the core result of the Asymptotic Equipartition Property (AEP):

By the Weak Law of Large Numbers, the sample entropy of an nn-symbol sequence converges in probability to the source entropy:

−1nlog⁡2p(X1,X2,…,Xn)→PH(X)-\frac{1}{n} \log_2 p(X_1, X_2, \ldots, X_n) \xrightarrow{P} H(X)

This gave us the typical set Aϵ(n)A_\epsilon^{(n)}: a narrow band containing roughly 2nH(X)2^{nH(X)} sequences that collectively absorb nearly all probability mass (>1−ϵ> 1 - \epsilon), with each typical sequence carrying approximately equal probability 2−nH(X)2^{-nH(X)}.

The theorem above closed the main loophole of that construction: even if you discard the typical set entirely and greedily pick the absolute most probable sequences (Bδ(n)B_\delta^{(n)}), you still need at least 2n(H(X)−δ′)2^{n(H(X) - \delta')} sequences to cover (1−δ)(1 - \delta) of the mass.

However, two critical assumptions limit what we have actually established so far:

  1. We Assumed Independent, Identically Distributed (i.i.d.) Keystrokes:
    The proof of the weak AEP relies directly on the Weak Law framework for independent random variables. But human language and digital data are never i.i.d., letters follow grammar, phonetics, and syntax, creating deep memory across adjacent symbols.

    What remains open: Can typical set machinery handle memory and temporal correlation? (The answer is yes, but it requires replacing the single-variable entropy H(X)H(X) with the entropy rate H=lim⁡n→∞1nH(X1,…,Xn)\mathcal{H} = \lim_{n \to \infty} \frac{1}{n} H(X_1, \dots, X_n) via the generalized Shannon-McMillan-Breiman theorem for stationary ergodic processes).

  2. We Solved Fixed-Length Block Indexing, Not Variable-Length Prefix Coding:
    We proved that if you design a fixed-size index (a block code) that assigns a fixed number of bits to a high-probability subset, you cannot use fewer than nH(X)n H(X) bits without suffering an unacceptable probability of decode error.

    What remains open: What if an engineer abandons fixed blocks altogether and assigns variable-length binary strings directly to symbols or sequences (e.g., short codes for common words, long codes for rare words, like Morse code or Huffman coding)? Proving that no uniquely decodable prefix code can ever achieve an average expected description length below H(X)H(X) bits requires establishing Kraft’s inequality and the formal Source Coding Theorem Converse.


Summary

ObjectStatementReads as
AEP−1nlog⁡p(Xn)→H(X)-\frac{1}{n}\log p(X^n) \to H(X) in probabilitySample entropy of a long tape converges to the source’s blueprint entropy.
Typical set2−n(H+ϵ)≤p(xn)≤2−n(H−ϵ)2^{-n(H+\epsilon)} \le p(x^n) \le 2^{-n(H-\epsilon)}Tapes whose statistics look ordinary for this source.
ProbabilityPr⁡{Aϵ(n)}>1−ϵ\Pr\{A_\epsilon^{(n)}\} > 1 - \epsilonThe typical pile is almost everything that happens.
Size (upper)∣Aϵ(n)∣≤2n(H+ϵ)\lvert A_\epsilon^{(n)} \rvert \le 2^{n(H+\epsilon)}There are not many realistic tapes.
Size (lower)∣Aϵ(n)∣≥(1−ϵ)2n(H−ϵ)\lvert A_\epsilon^{(n)} \rvert \ge (1-\epsilon)2^{n(H-\epsilon)}But there are not too few either, the count really is ≈2nH\approx 2^{nH}.
Source codeE[1nl(Xn)]≤H(X)+ϵ′\mathbb{E}\big[\tfrac{1}{n} l(X^n)\big] \le H(X) + \epsilon'A one-to-one code averaging about nHnH bits per tape exists.
Optimality∣Bδ(n)∣≐∣Aϵ(n)∣≐2nH\lvert B_\delta^{(n)} \rvert \doteq \lvert A_\epsilon^{(n)} \rvert \doteq 2^{nH}No smaller high-probability set beats the typical set in the exponent.

Constants to keep to hand:

  • Typical codeword length: ≤n(H+ϵ)+2\le n(H + \epsilon) + 2 bits (index ++ flag ++ ceiling).
  • Atypical codeword length: ≤nlog⁡∣X∣+2\le n \log \lvert \mathcal{X} \rvert + 2 bits.
  • Slack in the source coding theorem: ϵ′=ϵ+ϵlog⁡∣X∣+2n\epsilon' = \epsilon + \epsilon \log \lvert \mathcal{X} \rvert + \frac{2}{n}, shrink ϵ\epsilon first, then grow nn.

References

← All notes