Shannon's Variable-Length Source Coding Theorem (Converse & Shannon–Fano)

proved in Lean

No lossless code can have average codeword length below the source entropy, and a simple prefix code (Shannon–Fano) comes within one code symbol of it. Entropy is therefore the fundamental limit of lossless compression.

Claude E. Shannon; Robert M. Fano (1948) · Ch. 5 · Data Compression & Source Coding · Cover & Thomas, Theorems 5.3.1 & 5.4.1

Statement

For any finite distribution $P$ and $D$-ary alphabet ($D \ge 2$):

How the proof works

The converse pairs Kraft–McMillan with Gibbs' inequality (klDivergence_nonneg). Achievability sets $\ell(x) = \lceil -\log_D P(x) \rceil$ and invokes exists_prefixFree_code_of_kraft.

Lean declarations (5)

The key theorems in the Lean library. Each is compiled with Lean 4, uses only the standard axioms propext, Classical.choice and Quot.sound, and is re-checked by leanchecker. Click a name to see the full proof on GitHub.

Related open problems (3)

Open problems that build on, generalize, or are analogous to this theorem.