InformationTheory.Shannon.Huffman.SwapNormCompletion
Kraft completion: shorten a feasible code to a complete one #
Main statement #
shorten_to_kraft_one — if ll : β → ℕ is positive with ∑ 2^(-ll x) ≤ 1 and
2 ≤ card β, then there exists l1 ≤ ll (pointwise) with ∑ 2^(-l1 x) = 1.
Implementation notes #
The proof uses a natural-number Kraft sum N(l, M) = ∑ 2^(M - l c) (where M is the maximum
codeword length) linked to the real Kraft sum by realKraft = N / 2^M.
Induction runs on the total codeword length ∑ ll x: in the Kraft < 1 case, shorten the
longest leaf m by 1 (which increments N by 1) and apply the induction hypothesis.
Natural-number Kraft sum vs real Kraft sum #
InformationTheory.Shannon.Huffman.natKraft_cast_eq
sourceCast identity: ((∑ c, 2^(M - l c) : ℕ) : ℝ) = 2^M · ∑ c, (2:ℝ)^(-(l c : ℤ)).
Used by
InformationTheory.Shannon.Huffman.realKraft_le_one_iff_nat_le
sourceEquivalence: real Kraft sum ≤ 1 iff natural-number Kraft sum ≤ 2^M (when M bounds l).
Used by
InformationTheory.Shannon.Huffman.realKraft_eq_one_iff_nat_eq
sourceEquivalence: real Kraft sum = 1 iff natural-number Kraft sum = 2^M (when M bounds l).
Used by
Shortening induction #
InformationTheory.Shannon.Huffman.shorten_to_kraft_one
sourceA positive Kraft-feasible code can be shortened pointwise to a complete code (Kraft = 1).