InformationTheory.Shannon.ShannonCode.Basic
Shannon code (per-symbol prefix code achievability) #
For a probability distribution P on a finite alphabet α, the Shannon codeword length
l(a) := ⌈−logb D P(a)⌉₊ satisfies H_D(P) ≤ E[L] < H_D(P) + 1
(Cover–Thomas).
Main definitions #
entropyD— D-ary Shannon entropyH_D(P) := −∑ a, P.real {a} · logb D P(a).shannonLength— Shannon codeword lengthl(a) := ⌈−logb D P(a)⌉₊.expectedLength— expected lengthE[L] := ∑ a, P.real {a} · l(a).kraftSum— Kraft sumK_D(l) := ∑ a, D^{−l(a)}.
Main statements #
shannonLength_kraft_le_one— Shannon lengths satisfy Kraft:K_D(shannonLength) ≤ 1.entropyD_le_expectedLength_of_kraft— Gibbs lower bound: Kraft-feasiblelsatisfiesH_D(P) ≤ E[L].expectedLength_shannon_lt_entropyD_add_one— Shannon upper bound (full support):E[L_Shannon] < H_D(P) + 1.shannonCode_expected_length_bounds— sandwich:H_D(P) ≤ E[L_Shannon] < H_D(P) + 1.
Implementation notes #
The development works at the codeword-length level (α → ℕ) because Mathlib's
kraft_mcmillan_inequality uses a Finset (List α) representation. The reverse direction
(constructing a prefix code from a Kraft-feasible length function) is in
ShannonCode/KraftReverse.lean. We use Real.logb D for the D-ary logarithm throughout,
localizing the Real.log D factor. The upper bound (strict inequality) requires full
support ∀ a, P.real {a} > 0; the lower bound does not.
Definitions #
InformationTheory.Shannon.ShannonCode.entropyD
sourceD-ary Shannon entropy (finite-alphabet, Real-valued):
H_D(P) := -Σ a, P.real {a} · logb D P(a).
Equations
Instances For
Used by
InformationTheory.Shannon.ShannonCode.shannonLength
sourceShannon codeword length l(a) := ⌈−logb D P(a)⌉₊ : ℕ.
When P.real {a} = 0, Mathlib sets logb D 0 = 0 so l(a) = 0.
Instances For
Used by
InformationTheory.Shannon.ShannonCode.expectedLength
sourceExpected length E[L] := ∑ a, P.real {a} · l(a).
Instances For
Used by
InformationTheory.Shannon.ShannonCode.kraftSum
sourceKraft sum K_D(l) := ∑ a, D^{−l(a)} (Real-valued).
Equations
- InformationTheory.Shannon.ShannonCode.kraftSum D l = ∑ a : α, D ^ (-↑(l a))
Instances For
Used by
Auxiliary lemmas #
InformationTheory.Shannon.ShannonCode.logb_le_div_log
sourceGibbs log inequality in base D: logb D x ≤ (x − 1) / log D for D > 1, x > 0.
Used by
InformationTheory.Shannon.ShannonCode.rpow_neg_logb_eq
sourceD ^ (− logb D x) = x⁻¹ for D > 1, x > 0.
Used by
InformationTheory.Shannon.ShannonCode.rpow_natCast_shannonLength_ge_inv
sourcex⁻¹ ≤ D ^ ⌈−logb D x⌉₊ for D > 1, x > 0.
Used by
InformationTheory.Shannon.ShannonCode.zpow_neg_natCast_eq_rpow
sourceD ^ (−(l : ℤ)) = D ^ (−(l : ℝ)) for D > 0, l : ℕ.
Used by
Kraft feasibility of Shannon lengths #
InformationTheory.Shannon.ShannonCode.rpow_neg_shannonLength_le_real
sourceD ^ (−shannonLength D P a) ≤ P.real {a} for P.real {a} > 0.
Used by
InformationTheory.Shannon.ShannonCode.shannonLength_kraft_le_one
sourceShannon code Kraft inequality: D > 1, P a probability measure with full support
implies ∑ a, D ^ (−shannonLength D P a) ≤ 1.
Used by
Gibbs lower bound #
InformationTheory.Shannon.ShannonCode.entropyD_le_expectedLength_of_kraft
sourceGibbs lower bound: for D > 1, probability measure P with full support, and
any Kraft-feasible lengths l, we have H_D(P) ≤ E[L].
Used by
Shannon upper bound #
InformationTheory.Shannon.ShannonCode.expectedLength_shannon_lt_entropyD_add_one
sourceShannon code upper bound: D > 1, probability measure P with full support ⟹
E[L_Shannon] < H_D(P) + 1.
Used by
Sandwich theorem #
InformationTheory.Shannon.ShannonCode.shannonCode_expected_length_bounds
sourceShannon code sandwich (Cover–Thomas): for a probability measure P
with full support on a finite alphabet, the Shannon codeword lengths satisfy
H_D(P) ≤ E[L_Shannon] < H_D(P) + 1.