InformationTheory.Shannon.LZ78.ConverseUDObject
LZ78 converse UD-object #
This file builds the uniquely-decodable code object underlying LZ78 and
applies Mathlib's McMillan inequality to it, obtaining a Kraft bound and an
expectation-level source-coding converse for the LZ78 per-phrase
(parent, symbol) token code.
What this delivers #
§1 —
uniquelyDecodable_of_constantLength(general, reusable; Mathlib has no such constructor): any set of lists all of the same positive constant lengthKisUniquelyDecodable. This is the classic block-code fact and the mathematical core here — it is exactly the UD certificate the LZ78 token stream needs (lz78PhraseStringsitself is prefix-complete and not UD; the encoded fixed-width token set is).§2 introduces
boolEncode/finBoolCode, a concreteK-bit binary codem ↦ (range K).map (testBit m). Constant lengthK; injective onm < 2^K(Nat.eq_of_testBit_eq).finBoolCodeencodes anyFintypewhose card is≤ 2^Kas fixed-width binary, injectively.§3 builds the LZ78 token code: for a dictionary of size
cover alphabetα, the(c+1)·|α|possible(parent ∈ Fin (c+1), symbol ∈ α)tokens encode injectively intoK = LZ78Phrase.bitLength c |α|bits ((c+1)·|α| ≤ 2^KviaNat.lt_pow_succ_log_self). Its image is UD (§1), so McMillan (McMillanKraftBridge) giveskraftSum 2 (fun _ => K) ≤ 1and the Gibbs converseentropyD 2 P ≤ E[L] = Kfor the real LZ78 token code.Kis exactly the per-phrase bit cost used inlz78GreedyEncodingLength = c · K(LZ78/AsymptoticOptimality/EncodingLength.lean).
Relation to the LZ78 block-rate converse #
The §3 converse is an expectation-level bound: it instantiates
McMillanKraftBridge.entropyD_le_expectedLength_of_uniquelyDecodable at an
explicitly constructed UD code rather than at an abstract UniquelyDecodable
hypothesis. The LZ78 block-rate converse (Cover–Thomas,
lz78Greedy_converse_ae in LZ78/AsymptoticOptimality/ParentBridgeConverse.lean)
is instead an a.s.-eventual, per-realization liminf bound. Passing from the
token-level Kraft bound to it needs the averaged ⟶ a.s. lift (Barron /
competitive optimality), which runs through the polynomial block Kraft bound
lz78_block_kraft_poly and Borel–Cantelli, not through this file.
§1. Constant-length codes are uniquely decodable #
InformationTheory.uniquelyDecodable_of_constantLength
sourceA constant-length code is uniquely decodable (the block-code fact;
Mathlib has no such constructor). If every codeword in S has the same
positive length K, then distinct concatenations of codewords from S
yield distinct strings.
Proof: equal flattens force equal codeword counts (length is
K · count), and List.append_inj peels off equal-length heads one at a
time.
Used by
§2. Fixed-width binary code #
InformationTheory.boolEncode
sourceThe K-bit binary encoding of m: the booleans testBit m 0, …, testBit m (K-1). Constant length K.
Equations
- InformationTheory.boolEncode K m = List.map m.testBit (List.range K)
Instances For
Used by
InformationTheory.boolEncode_length
sourceUsed by
InformationTheory.boolEncode_injOn
sourceboolEncode is injective on m < 2^K: agreeing on the low K bits
plus both having no bits ≥ K (since m < 2^K) forces m = m'.
Used by
InformationTheory.finBoolCode
sourceA fixed-width binary code for a Fintype: index each element via
Fintype.equivFin, then K-bit encode. Constant length K.
Equations
- InformationTheory.finBoolCode α' K a = InformationTheory.boolEncode K ↑((Fintype.equivFin α') a)
Instances For
Used by
InformationTheory.finBoolCode_length
sourceUsed by
InformationTheory.injective_finBoolCode
sourcefinBoolCode is injective when |α'| ≤ 2^K (so every index fits in
K bits).
Used by
InformationTheory.uniquelyDecodable_finBoolCode
sourceThe image of finBoolCode is uniquely decodable (constant length
K > 0).
Used by
§3. The LZ78 (parent, symbol) token code #
InformationTheory.Shannon.lz78_token_card_le_pow
sourceThe token count fits the per-phrase bit budget: a dictionary of size c
has c+1 parent slots (incl. the empty-prefix root) times a symbols, and
(c+1)·a ≤ 2^(bitLength c a) since bitLength c a = (log₂(c+1)+1)+(log₂ a+1)
and n ≤ 2^(log₂ n + 1) (Nat.lt_pow_succ_log_self).
Used by
InformationTheory.Shannon.lz78TokenCode
sourceThe real LZ78 token code: a (parent, symbol) token for a dictionary
of size c is encoded as a fixed-width K = bitLength c |α|-bit binary word.
The parent ranges over Fin (c+1) (the c existing entries plus the
empty-prefix root), the symbol over α.
Equations
Instances For
Used by
InformationTheory.Shannon.lz78TokenCode_length
sourceEvery LZ78 token codeword has length K = bitLength c |α|.
Used by
InformationTheory.Shannon.lz78Token_card_le
sourceThe cardinality bound for the LZ78 token alphabet, |Fin (c+1) × α| ≤ 2^K.
Used by
InformationTheory.Shannon.injective_lz78TokenCode
sourceThe LZ78 token code is injective.
Used by
InformationTheory.Shannon.uniquelyDecodable_lz78TokenCode
sourceThe LZ78 token codeword set is uniquely decodable (constant length
K > 0).
Used by
InformationTheory.Shannon.lz78TokenCode_entropyD_le_expectedLength
sourceThe expectation-level source-coding converse for the LZ78 token code.
For any probability measure P (full support) on the LZ78 token alphabet, the
binary entropy is bounded by the (constant) token code length:
entropyD 2 P ≤ E[L] = bitLength c |α|.
This is the Cover–Thomas converse, instantiated at the LZ78
(parent, symbol) token code via the McMillan bridge. The block-rate form
(Cover–Thomas, lz78Greedy_converse_ae) needs the averaged ⟶ a.s.
lift and is not addressed here.