Math 2.0

Information and communication theory, circuits Source coding and data compression Theorem

Shannon's source coding theorem

Builds on Random variableExpected valueKraft–McMillan inequality

Statement

Let XX be a random variable with values in a finite set 𝒳\mathcal{X} and law pp, and let D≥2D \ge 2 be an integer. Assume that p(x)>0p(x) > 0 for every x∈𝒳x \in \mathcal{X}. Let HD(X)=−∑x∈𝒳p(x)log⁡Dp(x)H_D(X) = -\sum_{x \in \mathcal{X}} p(x) \log_D p(x) be its entropy in base DD. For a code CC that maps each x∈𝒳x \in \mathcal{X} to a string C(x)C(x) over a DD-symbol alphabet, let L(C)=∑xp(x)∣C(x)∣L(C) = \sum_{x} p(x) \abs{C(x)} be its expected length.

  1. Every uniquely decodable code CC for XX satisfies L(C)≥HD(X)L(C) \ge H_D(X).
  2. There is a prefix code CC for XX with L(C)<HD(X)+1L(C) < H_D(X) + 1.
  3. Let X1,X2,…X_1, X_2, \dots be independent with the same law as XX. Let Lk∗L_k^* be the least expected length of a uniquely decodable code for (X1,…,Xk)(X_1, \dots, X_k). Then Lk∗/k→HD(X)L_k^* / k \to H_D(X) as k→∞k \to \infty.

Remarks

For part 1, the Kraft–McMillan inequality gives ∑xD−∣C(x)∣≤1\sum_x D^{-\abs{C(x)}} \le 1. Then L(C)−HD(X)L(C) - H_D(X) is a relative entropy plus the non-negative number −log⁡D∑xD−∣C(x)∣-\log_D \sum_x D^{-\abs{C(x)}}, so it is non-negative by Gibbs' inequality. For part 2, the lengths ℓ(x)=⌈−log⁡Dp(x)⌉\ell(x) = \lceil -\log_D p(x) \rceil satisfy the Kraft inequality, so a prefix code with these lengths exists, and ℓ(x)<−log⁡Dp(x)+1\ell(x) < -\log_D p(x) + 1. Part 3 follows by applying parts 1 and 2 to the block, since its entropy is kHD(X)k H_D(X), which gives kHD(X)≤Lk∗<kHD(X)+1k H_D(X) \le L_k^* < k H_D(X) + 1.

Equality holds in part 1 if and only if p(x)=D−∣C(x)∣p(x) = D^{-\abs{C(x)}} for every xx. Example: if XX takes the values a,b,ca, b, c with probabilities 1/2,1/4,1/41/2, 1/4, 1/4, then H2(X)=3/2H_2(X) = 3/2, and the binary prefix code a↦0a \mapsto 0, b↦10b \mapsto 10, c↦11c \mapsto 11 has expected length exactly 3/23/2. Without unique decodability part 1 fails: the code a↦0a \mapsto 0, b↦1b \mapsto 1, c↦01c \mapsto 01 has expected length 5/4<3/25/4 < 3/2, but it cannot be decoded without ambiguity.

Going deeper

For a student

Part 1 is the converse and part 2 the achievability; together they fix the optimal compression rate as HD(X)H_D(X) per symbol. The Huffman code gives an optimal prefix code for each block, so it also achieves the bound of part 3. Shannon also stated a fixed-length version. Blocks of kk source symbols can be coded with about kHD(X)k H_D(X) code symbols and an error probability tending to 00. This fails at any rate below HD(X)H_D(X) code symbols per source symbol. That version rests on the asymptotic equipartition property. The theorem is the model for the channel coding theorem, which plays the same role for transmission over a noisy channel.

Reading path

To understand this page from the ground up, read these 4 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Expected value concept
  2. Kraft–McMillan inequality statement
  3. Random variable concept
  4. Shannon's source coding theorem statement

Where this leads

2 pages build on this one.

Further reading

  1. Web https://en.wikipedia.org/wiki/Shannon%27s_source_coding_theorem
About this page
TagPC8ASRWARE
URIm2://PC8ASRWARE
Kindstatement, theorem
WritingW0 stub
MSC94A29, 94A24, 68P30
StatusThis copy of the site has no build data. Run m2 status PC8ASRWARE.
UsesRandom variable, Expected value, Kraft–McMillan inequality
Same as
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

Used by