Shannon's source coding theorem, corrected
ProvedSourceCoding.shannon_source_coding_theorem_v2For a source with at least 2 symbols, over uniquely decodable codes .
import Mathlib
import Definitions.Def_SourceCoding_entropy
namespace SourceCoding
/-- **Shannon's source coding theorem** (Shannon, 1948) — corrected, superseding
`SourceCoding.shannon_source_coding_theorem`, which omitted the hypothesis that the source has
at least two symbols: `Nonempty ι` alone permits `Fintype.card ι = 1`, forcing `p ≡ 1` and
entropy `0`, so the achievability conjunct would demand a codeword of length `0` — impossible,
since a uniquely decodable code can never contain the empty codeword
(`InformationTheory.UniquelyDecodable.epsilon_not_mem`). With `2 ≤ Fintype.card ι`, full
support forces every `p i < 1` strictly, so the Shannon–Fano lengths `⌈-log_D (p i)⌉` are all
at least `1` and the classical argument goes through. For a source with probability
distribution `p : ι → ℝ` (`p i > 0`, `∑ p i = 1`, at least two symbols) and a `D`-ary code
alphabet (`D = Fintype.card α ≥ 2`): every uniquely decodable code assigning distinct
codewords to the source symbols has expected length at least the source's entropy `H_D(p)`,
and there exists a uniquely decodable code whose expected length is within one symbol of this
bound, `< H_D(p) + 1`. -/
theorem shannon_source_coding_theorem_v2
{ι : Type} [Fintype ι] [Nonempty ι] (p : ι → ℝ) (hp_pos : ∀ i, 0 < p i)
(hp_sum : ∑ i, p i = 1) (hι : 2 ≤ Fintype.card ι)
{α : Type} [Fintype α] [Nonempty α] (hD : 2 ≤ Fintype.card α) :
(∀ c : ι → List α, Function.Injective c →
InformationTheory.UniquelyDecodable (Set.range c) →
entropy p (Fintype.card α) ≤ ∑ i, p i * (c i).length) ∧
(∃ c : ι → List α, Function.Injective c ∧
InformationTheory.UniquelyDecodable (Set.range c) ∧
∑ i, p i * (c i).length < entropy p (Fintype.card α) + 1) := by
sorry
end SourceCoding
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
Read‑back.
The bundle first fixes two auxiliary definitions and then states a theorem about them.
Entropy. For a finite index type with a Fintype instance, a function , and a natural number , entropy p D is defined as , where is Real.logb D, i.e. with coerced from to . No hypothesis is built into this definition itself (e.g. it does not require or ); it is a bare real-valued formula, applied at zero or on non‑positive/degenerate it would just evaluate the formula literally (with the usual Lean/Mathlib conventions for of a non‑positive argument or with ).
Unique decodability. For a type and a set of "codewords", InformationTheory.UniquelyDecodable S says: for every pair of lists-of-lists such that every element occurring in lies in and every element occurring in lies in , if the concatenation (flatten) of equals the concatenation of as a single list of 's, then as lists (same codewords, in the same order, same length). Equivalently: the concatenation map, restricted to finite sequences drawn from , is injective.
Theorem shannon_source_coding_theorem_v2. The hypotheses are: is a type with a Fintype instance and a Nonempty instance; ; hp_pos asserts for every (strict positivity at every index, no index may have ); hp_sum asserts exactly; hι asserts , i.e. the index/source alphabet has at least two elements — this is a hypothesis in addition to the Nonempty ι instance and is strictly stronger than it (so Nonempty ι is logically redundant given hι, though both appear as separate premises in the signature). Separately, is a type with Fintype and Nonempty instances, and hD asserts (the target/code alphabet also has at least two elements; again Nonempty α is redundant given hD). With , the conclusion is a conjunction of two separate statements, each quantifying its own, independently-chosen function — the bound in the first conjunct is not the same as, nor tied to, the bound in the second:
-
(Universal / lower-bound clause) For every that is injective (
Function.Injective c, i.e. ) and whose range is uniquely decodable in the sense above, it holds that (a non-strict inequality; is the length of the list ). -
(Existential / near-achievability clause) There exists a that is injective and whose range is uniquely decodable, and for this particular , (a strict inequality).
The two clauses are joined by ∧ at the top level of the theorem's statement, so the theorem asserts both (1) and (2) hold simultaneously; nothing links the witness of clause (2) to the universally-quantified 's of clause (1) beyond each independently satisfying injectivity and unique decodability of its range.
Confirmed by the mission captain (proposal self-audit).