InformationTheory.Shannon.Huffman.Length
Huffman code lengths #
Constructs the binary Huffman code length function huffmanLength for a finite alphabet α
equipped with a probability measure, following Cover–Thomas. This file holds the
recursive construction and its positivity invariant; the Kraft sum and the cost-level recurrence
live in KraftSum and ExpectedLength.
Main definitions #
groupKey— deterministic comparison key (lex on probability then colex) used to break ties inhuffmanStep.HuffmanGrouping— invariant on the working multiset: no-duplicates, nonempty groups, pairwise-disjoint carriers.huffmanStep— one merge step: extracts the two minimum-probability groups and returns the merged multiset together with a proof thatHuffmanGroupingis preserved.huffmanLengthAux— recursion on the multiset; assigns a codeword length to eachα-element.initMultiset— initial multiset of singleton groups({a}, P.real {a}).huffmanLength— the published codeword-length functionhuffmanLengthAux (initMultiset P).
Main statements #
groupKey_injective—groupKeyis injective (probability + colex breaks all ties).huffmanStep_min_fst/huffmanStep_min_snd— the two extracted groups have minimum probability ins(resp.s.erase .val.1).huffmanLength_pos—huffmanLength P a > 0whencard α ≥ 2.
Implementation notes #
The merge step uses groupKey (a lex order on ℝ ×ₗ Colex (Finset α)) rather than a plain
probability ordering so that the minimum selection is deterministic even under probability ties.
This is essential for the carrier-crossing cost argument (huffmanCost_eq_of_prob_multiset).
InformationTheory.Shannon.Huffman.groupKey
sourceDeterministic comparison key for huffmanStep: primary key is probability p.2 (ascending),
tie-break is toColex p.1 (colex order). The resulting Prod.Lex total order on
ℝ ×ₗ Colex (Finset α) makes the minimum selection unique even under probability ties.
Instances For
Used by
InformationTheory.Shannon.Huffman.groupKey_injective
sourceUsed by
InformationTheory.Shannon.Huffman.groupKey_le_imp_snd_le
sourceUsed by
Internal implementation: Multiset-based Huffman recursion #
InformationTheory.Shannon.Huffman.HuffmanGrouping
sourceInvariant on a working group multiset: no duplicates, every group is nonempty, and distinct groups have disjoint carriers.
Equations
Instances For
Used by
InformationTheory.Shannon.Huffman.HuffmanGrouping.nodup
sourceUsed by
InformationTheory.Shannon.Huffman.HuffmanGrouping.nonempty
sourceUsed by
InformationTheory.Shannon.Huffman.HuffmanGrouping.disjoint
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanMerged_notMem_eraseErase
sourceUsed by
InformationTheory.Shannon.Huffman.kraftTerm_of_const_depth
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanStep
sourceOne Huffman merge step: extracts the two minimum-groupKey groups from s and returns
the merged multiset together with membership witnesses and the proof that HuffmanGrouping
is preserved. Requires s.card ≥ 2 and HuffmanGrouping s.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
InformationTheory.Shannon.Huffman.huffmanStep_spec
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanStep_key_min_fst
source.val.1 minimizes groupKey over all of s.
Used by
InformationTheory.Shannon.Huffman.huffmanStep_min_fst
source.val.1 has minimum probability in s.
Used by
InformationTheory.Shannon.Huffman.huffmanStep_key_min_snd
source.val.2.1 minimizes groupKey over s.erase .val.1.
Used by
InformationTheory.Shannon.Huffman.huffmanStep_min_snd
source.val.2.1 has minimum probability in s.erase .val.1.
Used by
InformationTheory.Shannon.Huffman.huffmanStep_grouping
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanStep_card_eq
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanStep_card_lt
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanLengthAux
sourceInternal recursion on s.card: assigns a codeword length to each α-element by strong
induction on s.card, merging the two minimum-probability groups at each step. Returns the
zero function on out-of-spec inputs (where HuffmanGrouping s fails).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
InformationTheory.Shannon.Huffman.initMultiset
sourceInitial working multiset: each element a : α maps to the singleton group
({a}, P.real {a}).
Equations
- InformationTheory.Shannon.Huffman.initMultiset P = Multiset.map (fun (a : α) => ({a}, P.real {a})) Finset.univ.val
Instances For
Used by
Unfolding lemmas and structural invariants for huffmanLengthAux #
InformationTheory.Shannon.Huffman.huffmanLengthAux_eq_step
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanLengthAux_eq_zero
sourceUsed by
Main definition #
InformationTheory.Shannon.Huffman.huffmanLength
sourceBinary Huffman codeword-length function: huffmanLengthAux applied to the initial
singleton-group multiset of P.
Equations
Instances For
Used by
Main theorems #
InformationTheory.Shannon.Huffman.huffmanLengthAux_pos_of_mem
sourceUsed by
InformationTheory.Shannon.Huffman.mem_initMultiset
sourceUsed by
InformationTheory.Shannon.Huffman.initMultiset_huffmanGrouping
sourceUsed by
InformationTheory.Shannon.Huffman.huffmanLength_pos
sourcehuffmanLength P a > 0 when Fintype.card α ≥ 2.