Documentation

CslibFrontier.DataStructure.Dictionary.Spillover

Pătrașcu Power-of-Two Spillover Representation #

This file formalizes the power-of-two spillover encoding of Mihai Pătrașcu, Succincter ([Patrascu2008, Lemma 3]), as specialized in Tianxiao Li, Jingxun Liang, Huacheng Yu, and Renfei Zhou, Dynamic Dictionary with Subconstant Wasted Bits per Key ([LiLiangYuZhou2024, Section 3.4, Lemma 3.8 and Footnote 4]; arXiv:2310.20536v1, PDF p. 11 / printed p. 10).

Given a finite payload universe Fin X (1 ≤ X) and spillover parameter r_sp ≥ 1, we set M := memBits X r_sp (0 when X ≤ r_sp, and ⌊log₂(X / r_sp)⌋ otherwise) and K := spillUniv X r_sp := ⌈X / 2 ^ M⌉. Because the memory-bit modulus 2 ^ M is an exact power of two, encode splits x < X into (x / 2 ^ M, x % 2 ^ M) ∈ Fin K × Fin (2 ^ M), decodeVal reconstructs k * 2 ^ M + m with exact round-trip identity, K ≤ 2 * r_sp, and the bit-redundancy M + log₂ K - log₂ X is at most 2 / r_sp bits (with multiplicative ℕ, ℚ, and Nat.clog 2 batch forms for n independent payloads at r_sp = n).

Scope note #

This module supplies the pure mathematical spillover primitive for the large-parameter-regime dynamic dictionary of [LiLiangYuZhou2024, Section 5]. Word-RAM O(1) bit-shift and bit-mask evaluation, variable-length adapter trees, strong history independence, dynamic resizing, and super-polynomial key universes are not formalized here.

Main definitions #

Main results #

References #

Number of raw memory bits M = ⌊log₂(X / r_sp)⌋ in the power-of-two spillover split of Fin X with parameter r_sp (equals 0 when X ≤ r_sp, [LiLiangYuZhou2024, Footnote 4]).

Spillover universe size K = ⌈X / 2 ^ M⌉ for universe X and parameter r_sp.

@[simp]
theorem Cslib.DataStructure.Dictionary.Spillover.memBits_of_le {X r_sp : ℕ} (h : X ≤ r_sp) :
memBits X r_sp = 0

memBits X r_sp equals Nat.log 2 (X / r_sp) definitionally.

@[simp]

K * 2 ^ M overshoots X by strictly less than 2 ^ M.

theorem Cslib.DataStructure.Dictionary.Spillover.encode_div_lt {X : ℕ} (r_sp : ℕ) (x : Fin X) :
↑x / 2 ^ memBits X r_sp < spillUniv X r_sp
def Cslib.DataStructure.Dictionary.Spillover.encode {X : ℕ} (r_sp : ℕ) (x : Fin X) :
Fin (spillUniv X r_sp) × Fin (2 ^ memBits X r_sp)

Encode x : Fin X into spillover index k = x / 2 ^ M and memory word m = x % 2 ^ M.

Reconstruct the raw natural number k * 2 ^ M + m from a (k, m) spillover pair.

def Cslib.DataStructure.Dictionary.Spillover.decode? {X : ℕ} (r_sp : ℕ) (km : Fin (spillUniv X r_sp) × Fin (2 ^ memBits X r_sp)) :

Checked partial inverse of encode, returning some x when k * 2 ^ M + m < X.

@[simp]
@[simp]
theorem Cslib.DataStructure.Dictionary.Spillover.encode_decodeVal {X r_sp : ℕ} (km : Fin (spillUniv X r_sp) × Fin (2 ^ memBits X r_sp)) (h : decodeVal km < X) :
encode r_sp ⟨decodeVal km, h⟩ = km
@[simp]
theorem Cslib.DataStructure.Dictionary.Spillover.decode?_encode {X : ℕ} (r_sp : ℕ) (x : Fin X) :
decode? r_sp (encode r_sp x) = some x
theorem Cslib.DataStructure.Dictionary.Spillover.decode?_eq_some_iff {X : ℕ} (r_sp : ℕ) (km : Fin (spillUniv X r_sp) × Fin (2 ^ memBits X r_sp)) (x : Fin X) :
decode? r_sp km = some x ↔ encode r_sp x = km

Exact bijection between Fin X and valid spillover pairs {km // decodeVal km < X}.

@[simp]
theorem Cslib.DataStructure.Dictionary.Spillover.coe_equiv {X r_sp : ℕ} (x : Fin X) :
↑((equiv X r_sp) x) = encode r_sp x
@[simp]
theorem Cslib.DataStructure.Dictionary.Spillover.val_equiv_symm {X r_sp : ℕ} (km : { km : Fin (spillUniv X r_sp) × Fin (2 ^ memBits X r_sp) // decodeVal km < X }) :
↑((equiv X r_sp).symm km) = decodeVal ↑km

Spillover universe and bit-redundancy bounds (Lemma 3.8) #

When r_sp ≤ X, r_sp ≤ spillUniv X r_sp.

When r_sp * 2 ^ M < X (for r_sp ≤ X, i.e. when X ≠ r_sp * 2 ^ M), r_sp < spillUniv X r_sp.

Upper bound K ≤ 2 * r_sp in Lemma 3.8.

theorem Cslib.DataStructure.Dictionary.Spillover.mul_spillUniv_mul_two_pow_le {X r_sp : ℕ} (hr : 1 ≤ r_sp) :
r_sp * (spillUniv X r_sp * 2 ^ memBits X r_sp) ≤ (r_sp + 1) * X

Exact multiplicative ℕ redundancy bound: r_sp * (K * 2 ^ M) ≤ (r_sp + 1) * X.

theorem Cslib.DataStructure.Dictionary.Spillover.spillUniv_mul_two_pow_div_le_rat {X r_sp : ℕ} (hX : 1 ≤ X) (hr : 1 ≤ r_sp) :
↑(spillUniv X r_sp * 2 ^ memBits X r_sp) / ↑X ≤ 1 + 1 / ↑r_sp

Rational ratio form of Lemma 3.8: (K * 2 ^ M) / X ≤ 1 + 1 / r_sp.

When X ≤ r_sp, the spillover representation incurs zero bit redundancy (Footnote 4).

theorem Cslib.DataStructure.Dictionary.Spillover.memBits_add_logb_spillUniv_le {X r_sp : ℕ} (hX : 1 ≤ X) (hr : 1 ≤ r_sp) :
↑(memBits X r_sp) + Real.logb 2 ↑(spillUniv X r_sp) ≤ Real.logb 2 ↑X + 2 / ↑r_sp

Logarithmic bit-redundancy bound (Lemma 3.8 of Li–Liang–Yu–Zhou 2024; Lemma 3 of Pătrașcu 2008): M + log₂ K ≤ log₂ X + 2 / r_sp.

Batch ℕ bound across n payloads at spillover parameter r_sp = n: (K * 2 ^ M) ^ n ≤ 3 * X ^ n (since (1 + 1 / n) ^ n ≤ e < 3).

theorem Cslib.DataStructure.Dictionary.Spillover.clog_mul_spillUniv_pow_add_le {A X n : ℕ} (hA : 1 ≤ A) (hX : 1 ≤ X) (hn : 1 ≤ n) :
Nat.clog 2 (A * spillUniv X n ^ n) + n * memBits X n ≤ Nat.clog 2 (A * X ^ n) + 2

Ceiling-logarithm batch bound: combining a header factor A ≥ 1 (such as C(U', n)) with n spillovers of universe K = spillUniv X n and n * M memory bits adds at most 2 bits over the exact information-theoretic ceiling ⌈log₂ (A * X ^ n)⌉.