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 #
isUniquelyDecodable_of_subset— unique decodability passes to subsets (absent upstream: theUniquelyDecodable.leanfile has onlyepsilon_not_mem/flatten_injective).finset_sum_le_one— the binary (α = Bool) specialization of Kraft–McMillan, over a finite set of codewords.indexed_finset_sum_le_one— the same bound with the sum reindexed along an injective codecode : ι → List Bool, over any finite set of indices. Injectivity is what lets the sum move from codewords to indices; unique decodability of the whole range is what lets an arbitrary finite subset inherit Kraft (viaisUniquelyDecodable_of_subset).indexed_tsum_le_one— the countable extension: every finite subtotal is≤ 1and the summands are nonnegative, so the sum over all ofιis≤ 1. This is the form both callers want — a sub-probability over an index type.
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.
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.
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.
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.
The weights of a uniquely-decodable code are summable: nonnegative, with every finite subtotal
bounded by 1 (indexed_finset_sum_le_one).
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.