Documentation

CodeLayer.BinaryKraft

Binary Kraft–McMillan bridges #

Mathlib proves Kraft–McMillan (InformationTheory.IsUniquelyDecodable.finsetSum_one_div_card_pow_length_le_one) for a finite uniquely-decodable code over a finite alphabet, as a statement about Fintype.card α raised to minus the codeword lengths. Every use of it in this development wants one of two things instead: the binary form ∑ (1/2)^|w| ≤ 1, and the sum taken over an index type — a hypothesis class, a type of programs — rather than over the codewords themselves. This module is that adapter, and it stays deliberately light: it imports only Mathlib, so both the universal-prior side and the program-length side (the additive complexity KE) can use it without either importing the other for a generic list lemma.

Contents #

Scope #

These are code-length statements throughout. Nothing here claims that shortest programs, or minimal descriptions, form a uniquely-decodable set — that a code exists with lengths = K(·) is a separate fact, supplied by the caller (a concrete serialization proved uniquely decodable, or an explicit hypothesis). The bound is ≤ 1, not = 1: a uniquely-decodable code need not be complete, and sub-normalization is what the ∝ 2^{−K} prior needs.

A subset of a uniquely-decodable code is uniquely decodable. The unique-decodability test on S only ever quantifies over codewords that lie in S ⊆ T, so it is inherited from T.

theorem BinaryKraft.finset_sum_le_one {S : Finset (List Bool)} (hUD : InformationTheory.IsUniquelyDecodable ↑S) :
∑ w ∈ S, (1 / 2) ^ w.length ≤ 1

Binary Kraft–McMillan: for a finite uniquely-decodable binary code, the weights 2^{−|w|} sum to ≤ 1. Mathlib's inequality specialized at Fintype.card Bool = 2.

theorem BinaryKraft.indexed_finset_sum_le_one {ι : Type u_1} (code : ι → List Bool) (hinj : Function.Injective code) (hUD : InformationTheory.IsUniquelyDecodable (Set.range code)) (F : Finset ι) :
∑ i ∈ F, (1 / 2) ^ (code i).length ≤ 1

Binary Kraft–McMillan, reindexed along an injective code. For code : ι → List Bool injective with uniquely-decodable range, any finite set of indices carries total weight ≤ 1.

The finite image is uniquely decodable because the whole range is (isUniquelyDecodable_of_subset), and injectivity of code transports the sum from the codewords back to the indices.

theorem BinaryKraft.indexed_tsum_le_one {ι : Type u_1} (code : ι → List Bool) (hinj : Function.Injective code) (hUD : InformationTheory.IsUniquelyDecodable (Set.range code)) :
∑' (i : ι), (1 / 2) ^ (code i).length ≤ 1

Binary Kraft–McMillan over the whole index type. For an injective code with uniquely-decodable range, ∑' i, 2^{−|code i|} ≤ 1: the weights 2^{−|code i|} are a sub-probability on ι.

Every finite subtotal is at most one (indexed_finset_sum_le_one) and the summands are nonnegative, so the sum over all of ι is too — no summability hypothesis is needed, since a nonnegative family with bounded finite subtotals is summable.

theorem BinaryKraft.indexed_summable {ι : Type u_1} (code : ι → List Bool) (hinj : Function.Injective code) (hUD : InformationTheory.IsUniquelyDecodable (Set.range code)) :
Summable fun (i : ι) => (1 / 2) ^ (code i).length

The weights of a uniquely-decodable code are summable: nonnegative, with every finite subtotal bounded by 1 (indexed_finset_sum_le_one).

theorem BinaryKraft.indexed_tsum_pos {ι : Type u_1} (code : ι → List Bool) (hinj : Function.Injective code) (hUD : InformationTheory.IsUniquelyDecodable (Set.range code)) (i₀ : ι) :
0 < ∑' (i : ι), (1 / 2) ^ (code i).length

The total mass of the code's weights is positive: every weight is, and the family is summable. Together with indexed_tsum_le_one this says the normalizer of a 2^{−ℓ} prior lies in (0, 1] — the two facts a normalization step needs.