The LZ78 bit code and its length #
encodeBits e x writes the LZ78 (pointer, symbol) pairs of x as bits ([ZL78];
[CT06], Ch. 13). The i-th pair (counting from 1) has a pointer in
{0, …, i - 1}, written in ⌈log₂ i⌉ bits, and a symbol, written in ⌈log₂ k⌉ bits through a
fixed numbering e : α ≃ Fin k of the alphabet; numbers are written least significant bit first
(Cslib.BitString.lowBits). The widths depend only on the position, so the decoder needs no
separators. For k ≥ 2 every pair has at least one bit and decodeBits recovers the input.
The length of the code of an input of length n with c phrases is exactly
∑_{i=1}^{c} (⌈log₂ i⌉ + ⌈log₂ k⌉) ≤ c (⌈log₂ c⌉ + ⌈log₂ k⌉). With the distinct-parsing bound
c log_k c ≤ n + 2c this gives ⌈log₂ k⌉ (n + 4c), and with c ≤ n / ((1 - ε_n) log_k n)
the worst-case length ⌈log₂ k⌉ n (1 + 4 / ((1 - ε_n) log_k n)) = ⌈log₂ k⌉ n (1 + o(1)): LZ78
never expands its input by more than a vanishing fraction over the fixed-length code of
⌈log₂ k⌉ n bits.
Main definitions #
Cslib.Algorithms.Lean.LempelZiv.LZ78.pairsToBits,Cslib.Algorithms.Lean.LempelZiv.LZ78.bitsToPairs: the bit code of (pointer, symbol) pairs.Cslib.Algorithms.Lean.LempelZiv.LZ78.encodeBits,Cslib.Algorithms.Lean.LempelZiv.LZ78.decodeBits: the LZ78 bit code.
Main results #
Cslib.Algorithms.Lean.LempelZiv.LZ78.decodeBits_encodeBits: the bit code is lossless.Cslib.Algorithms.Lean.LempelZiv.LZ78.length_encodeBits: the exact length.Cslib.Algorithms.Lean.LempelZiv.LZ78.length_encodeBits_le: at mostc (⌈log₂ c⌉ + ⌈log₂ k⌉).Cslib.Algorithms.Lean.LempelZiv.LZ78.length_encodeBits_le_mul_add: at most⌈log₂ k⌉ (n + 4c).Cslib.Algorithms.Lean.LempelZiv.LZ78.length_encodeBits_le_mul_one_add,Cslib.Algorithms.Lean.LempelZiv.LZ78.tendsto_four_div_one_sub_epsilon_mul_logb,Cslib.Algorithms.Lean.LempelZiv.LZ78.exists_length_encodeBits_le: the worst-case length is⌈log₂ k⌉ n (1 + o(1)).
References #
LZ78 bit encoder.
The LZ78 bit code is lossless for an alphabet of size k ≥ 2.
The exact length of the LZ78 bit code: ∑_{i=1}^{c} (⌈log₂ i⌉ + ⌈log₂ k⌉), where c is
the number of phrases.
The LZ78 bit code of an input with c phrases has at most c (⌈log₂ c⌉ + ⌈log₂ k⌉) bits.
Finite length bound. For an alphabet of size k ≥ 2, the LZ78 bit code of an input of
length n with c phrases has at most ⌈log₂ k⌉ (n + 4c) bits.
Worst-case length n (1 + o(1)). For an alphabet of size k ≥ 2 and an input of length
n ≥ 2 with ε_n < 1, the LZ78 bit code has at most
⌈log₂ k⌉ n (1 + 4 / ((1 - ε_n) log_k n)) bits; the overhead factor tends to 0
(tendsto_four_div_one_sub_epsilon_mul_logb).
The overhead factor 4 / ((1 - ε_n) log_k n) of the worst-case LZ78 length tends to 0.
The LZ78 code length is ⌈log₂ k⌉ n (1 + o(1)) in the worst case: there is a sequence
δ n → 0 such that every input of length n over an alphabet of size k ≥ 2 has a bit code of
at most ⌈log₂ k⌉ n (1 + δ n) bits.