← All solved theorems
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$):
- Converse: Every injective uniquely decodable code $c$ satisfies $\mathbb{E}[|c(X)|] \ge H(P) / \log_2 D$.
- Achievability: There exists an injective prefix-free code $c$ with $\mathbb{E}[|c(X)|] < H(P) / \log_2 D + 1$ (on positive support, and $\le H(P)/\log_2 D + 1$ on all of $\mathcal{X}$ even with zero-mass atoms).
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.
theorem source_coding_converse {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β]
(hβ : 2 ≤ Fintype.card β) (P : ProbDist α)
(c : α → List β) (hc : Function.Injective c)
(hud : InformationTheory.IsUniquelyDecodable
((Finset.univ.image c : Finset (List β)) : Set (List β))) :
shannonEntropy P / log2 (Fintype.card β : ℝ) ≤
∑ a : α, P.pmf a * ((c a).length : ℝ) := by …
theorem source_coding_converse_prefixFree {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β]
(hβ : 2 ≤ Fintype.card β) (P : ProbDist α)
(c : α → List β) (hc : Function.Injective c)
(hpf : InformationTheory.IsPrefixFree
((Finset.univ.image c : Finset (List β)) : Set (List β))) :
shannonEntropy P / log2 (Fintype.card β : ℝ) ≤
∑ a : α, P.pmf a * ((c a).length : ℝ) := by …
theorem shannon_fano_achievability {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β]
(hβ : 2 ≤ Fintype.card β) (P : ProbDist α) (hpos : ∀ a, 0 < P.pmf a) :
∃ c : α → List β,
Function.Injective c ∧
InformationTheory.IsPrefixFree ((Finset.univ.image c : Finset (List β)) : Set (List β)) ∧
∑ a : α, P.pmf a * ((c a).length : ℝ) <
shannonEntropy P / log2 (Fintype.card β : ℝ) + 1 := by …
theorem shannon_fano_achievability_support {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β]
(hβ : 2 ≤ Fintype.card β) (P : ProbDist α) :
∃ c : {a : α // 0 < P.pmf a} → List β,
Function.Injective c ∧
InformationTheory.IsPrefixFree ((Finset.univ.image c : Finset (List β)) : Set (List β)) ∧
∑ a : {a : α // 0 < P.pmf a}, P.pmf a.1 * ((c a).length : ℝ) <
shannonEntropy P / log2 (Fintype.card β : ℝ) + 1 := by …
theorem shannon_fano_achievability_le {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β]
(hβ : 2 ≤ Fintype.card β) (P : ProbDist α) :
∃ c : α → List β,
Function.Injective c ∧
InformationTheory.IsPrefixFree ((Finset.univ.image c : Finset (List β)) : Set (List β)) ∧
∑ a : α, P.pmf a * ((c a).length : ℝ) ≤
shannonEntropy P / log2 (Fintype.card β : ℝ) + 1 := by …
Related open problems (3)
Open problems that build on, generalize, or are analogous to this theorem.