Documentation

CslibFrontier.Algorithms.Lean.LempelZiv.DistinctParsing

The distinct-parsing bound #

A distinct parsing of a word x is a list of phrases ws with ws.flatten = x and ws.Nodup. Because there are at most k ^ i words of length i over an alphabet of size k, a word of length n cannot be cut into many distinct phrases: the number of phrases c is O(n / log n). This is the combinatorial core of the analysis of Lempel–Ziv incremental parsing (LZ78) in [ZL78] and [CT06], Ch. 13.

The basic finite inequality is m * c ≤ n + 2 * k ^ m for every m (mul_length_le_of_nodup): each phrase of length less than m has a deficit m - |w|, and the total deficit of distinct words is at most ∑_{i < m} (m - i) k ^ i ≤ 2 k ^ m. Choosing m gives the two standard forms:

The arithmetic steps from the first inequality to the other two are stated separately (mul_log_le_of_forall_mul_le, mul_logb_sub_le_of_forall_mul_le), because LZ78's parse is only distinct up to its last phrase and satisfies the first inequality by a variant argument (mul_length_le_of_nodup_dropLast).

Main definitions #

Main results #

References #

The finite inequality m * c ≤ n + 2 * k ^ m #

theorem Cslib.Algorithms.Lean.LempelZiv.DistinctParsing.sum_tsub_length_le_of_nodup {α : Type u_1} [Fintype α] {ws : List (List α)} (hws : ws.Nodup) (m : ℕ) :
(List.map (fun (w : List α) => m - w.length) ws).sum ≤ ∑ i ∈ Finset.range m, (m - i) * Fintype.card α ^ i

Total deficit of distinct words. For pairwise distinct words over an alphabet of size k, the deficits m - |w| sum to at most ∑_{i < m} (m - i) k ^ i.

Distinct-parsing inequality. If ws consists of c pairwise distinct words of total length n over an alphabet of size k ≥ 2, then m * c ≤ n + 2 * k ^ m for every m.

theorem Cslib.Algorithms.Lean.LempelZiv.DistinctParsing.mul_length_le_of_nodup_dropLast {α : Type u_1} [Fintype α] (hα : 2 ≤ Fintype.card α) {ws : List (List α)} (hne : ∀ w ∈ ws, w ≠ []) (hws : ws.dropLast.Nodup) (m : ℕ) :

The distinct-parsing inequality m * c ≤ n + 2 * k ^ m also holds when the phrases are nonempty and only the phrases before the last are pairwise distinct, as in LZ78's parse, whose last phrase may repeat an earlier one.

Arithmetic inversions #

theorem Cslib.Algorithms.Lean.LempelZiv.DistinctParsing.mul_log_le_of_forall_mul_le {k c n : ℕ} (hc : 2 ≤ k → ∀ (m : ℕ), m * c ≤ n + 2 * k ^ m) :
c * Nat.log k c ≤ n + 2 * c

Logarithmic form. If m * c ≤ n + 2 * k ^ m for every m (when k ≥ 2), then c * ⌊log_k c⌋ ≤ n + 2 * c. For k ≤ 1 the floor logarithm is 0 and the bound is trivial.

theorem Cslib.Algorithms.Lean.LempelZiv.DistinctParsing.mul_logb_sub_le_of_forall_mul_le {k c n : ℕ} (hk : 2 ≤ k) (hc : ∀ (m : ℕ), m * c ≤ n + 2 * k ^ m) :
↑c * (Real.logb ↑k ↑n - Real.logb (↑k) (Real.logb ↑k ↑n) - 4) ≤ ↑n

Cover–Thomas form. If m * c ≤ n + 2 * k ^ m for every m, with k ≥ 2, then c * (log_k n - log_k log_k n - 4) ≤ n. The proof takes m = ⌊log_k n - log_k log_k n⌋ - 2, so that 4 (log_k n) k ^ m ≤ n, following [CT06], §13.5.

The slack ε_n = min(1, (log_k log_k n + 4) / log_k n) of [CT06], §13.5 (there with k = 2). It tends to 0 (tendsto_epsilon).

The formula of epsilon, for use outside this module.

theorem Cslib.Algorithms.Lean.LempelZiv.DistinctParsing.le_div_of_forall_mul_le {k c n : ℕ} (hk : 2 ≤ k) (hc : ∀ (m : ℕ), m * c ≤ n + 2 * k ^ m) (hε : epsilon k n < 1) (hn : 2 ≤ n) :
↑c ≤ ↑n / ((1 - epsilon k n) * Real.logb ↑k ↑n)

Cover–Thomas distinct-parsing bound, arithmetic form. If m * c ≤ n + 2 * k ^ m for every m and ε_n < 1, then c ≤ n / ((1 - ε_n) log_k n).

The distinct-parsing bound #

Distinct-parsing bound, logarithmic form. A list of c pairwise distinct words of total length n over an alphabet of size k satisfies c * ⌊log_k c⌋ ≤ n + 2 * c.

Distinct-parsing bound, Cover–Thomas form ([CT06], §13.5, for any alphabet size k ≥ 2). A list of c pairwise distinct words of total length n satisfies c * (log_k n - log_k log_k n - 4) ≤ n.

Distinct-parsing bound ([CT06], §13.5, for any alphabet size k ≥ 2). A distinct parsing of a word of length n ≥ 2 into c phrases has c ≤ n / ((1 - ε_n) log_k n), where ε_n → 0 (tendsto_epsilon).