Documentation

CslibFrontier.DataStructure.Dictionary.SuccinctWhpFallback

Small-Regime Array, In-Place Slot Permutation, and CSR Fallback Model #

This module develops three pure building blocks for the with-high-probability fixed-capacity succinct dynamic dictionary (Cslib.DataStructure.Dictionary.SuccinctWhp):

  1. Small-regime deterministic array (SmallDictState): when n_max < whpThreshold c, the dictionary stores up to n_max (present, key, value) triples scanned in n_max < whpThreshold c deterministic steps (failureProb = 0).
  2. In-place cycle-following slot rearrangement (permuteByTarget): rearranges qArr and vArr in place across n_max physical slots along any injective partial map {s < n_max | active s} → Fin n_max, using a single 1-bit active marker array and fixed n_max-iteration loops. Both fastMode → fallbackMode compaction and fallbackMode → fastMode self-healing instantiate this single primitive.
  3. Compressed-sparse-row (CsrState) fallback dictionary and overflow-free GoodSeedOnState checker: stores arbitrary bucket loads (X_0, …, X_{M - 1}) (∑ X_b ≤ n_max) in 1 · OPT + o(n_max) bits via bucket prefix sums fbStart[0 .. M] plus Feistel quotients and values, with exact Dynamic.step refinement for every seed θ and an overflow-free decision procedure for GoodSeedOnState.

Main definitions #

Main results #

Section 1: Small-regime deterministic dictionary (n_max < whpThreshold c) #

Pure state of the small-regime bit-packed array dictionary (0 .. n_max - 1).

  • present : ℕ → ℕ

    Occupancy bit (0 = empty, non-zero = active) at slot i < n_max.

  • keys : ℕ → ℕ

    Stored key < U at slot i < n_max.

  • vals : ℕ → ℕ

    Stored value < V at slot i < n_max.

Single step of the n_max-slot scan at index i, maintaining (foundIdx1, freeIdx1) where 0 encodes none and idx + 1 encodes some idx.

Prefix scan over 0 .. k - 1 returning (foundIdx1, freeIdx1).

Small-regime lookup of u_val.

Small-regime insertion / overwrite of (u_val, v_val).

Small-regime deletion of u_val.

Representation invariant relating SmallDictState to dict : Dictionary.State U.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.smallQuery_spec {U V n_max : ℕ} {st : SmallDictState} {dict : State U} (hv : ValidSmallState U V n_max st dict) (u : Fin U) :
smallQuery n_max st ↑u = dict u

Small-regime lookup matches dict u.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.smallDelete_spec {U V n_max : ℕ} {st : SmallDictState} {dict : State U} (hv : ValidSmallState U V n_max st dict) (u : Fin U) :
ValidSmallState U V n_max (smallDelete n_max st ↑u) (Function.update dict u none)

Small-regime deletion preserves ValidSmallState and refines Function.update dict u none.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.smallInsert_spec {U V n_max : ℕ} {st : SmallDictState} {dict : State U} (hv : ValidSmallState U V n_max st dict) {u : Fin U} {v : ℕ} (hvalid : Dynamic.valid V n_max dict (Dynamic.Op.insert u v)) :
ValidSmallState U V n_max (smallInsert n_max st (↑u) v) (Function.update dict u (some v))

Small-regime insertion preserves ValidSmallState and refines Function.update dict u (some v) whenever Dynamic.valid V n_max dict (.insert u v).

Section 2: In-place cycle-following slot rearrangement (permuteByTarget) #

@[reducible, inline]

State tuple (running, curDest, curQ, curV, act, qArr, vArr) for permuteInnerStep.

Single step of a cycle-following chain along dest.

def Cslib.DataStructure.Dictionary.SuccinctWhp.permuteOuterStep (n_max : ℕ) (dest : ℕ → ℕ) (s : ℕ) (triple : (ℕ → Bool) × (ℕ → ℕ) × (ℕ → ℕ)) :
(ℕ → Bool) × (ℕ → ℕ) × (ℕ → ℕ)

Outer step at source slot s: if act s is still true, extracts (qArr s, vArr s) and runs n_max inner chain steps.

def Cslib.DataStructure.Dictionary.SuccinctWhp.permuteOuterLoop (n_max : ℕ) (dest : ℕ → ℕ) :
ℕ → (ℕ → Bool) × (ℕ → ℕ) × (ℕ → ℕ) → (ℕ → Bool) × (ℕ → ℕ) × (ℕ → ℕ)

Run permuteOuterStep across s = 0 .. k - 1.

def Cslib.DataStructure.Dictionary.SuccinctWhp.permuteByTarget (n_max : ℕ) (dest : ℕ → ℕ) (act₀ : ℕ → Bool) (qArr vArr : ℕ → ℕ) :
(ℕ → ℕ) × (ℕ → ℕ)

Rearrange (qArr, vArr) in place across 0 .. n_max - 1 so every s < n_max with act₀ s = true lands at dest s.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.permuteByTarget_spec {n_max : ℕ} {dest : ℕ → ℕ} {act₀ : ℕ → Bool} {q₀ v₀ : ℕ → ℕ} {Q_bnd V_bnd : ℕ} (hinj : ∀ s₁ < n_max, ∀ s₂ < n_max, act₀ s₁ = true → act₀ s₂ = true → dest s₁ = dest s₂ → s₁ = s₂) (hqv₀ : ∀ (i : ℕ), q₀ i < Q_bnd ∧ v₀ i < V_bnd) :
match permuteByTarget n_max dest act₀ q₀ v₀ with | (q', v') => (∀ s < n_max, act₀ s = true → q' (dest s) = q₀ s ∧ v' (dest s) = v₀ s) ∧ ∀ (i : ℕ), q' i < Q_bnd ∧ v' i < V_bnd

Exact in-place permutation theorem (permuteByTarget_spec): if dest is injective on A₀ = {s < n_max | act₀ s = true} and maps A₀ into < n_max, then permuteByTarget places (q₀ s, v₀ s) at dest s for every s ∈ A₀ while preserving global value bounds (Q_bnd, V_bnd).

Section 3: Compressed-sparse-row (CsrState) fallback dictionary and GoodSeedOnState #

Compressed-sparse-row bucket fallback state over M = numBucketsWhp n_max Feistel buckets.

  • fbStart : ℕ → ℕ

    Bucket boundary prefix sums fbStart 0 = 0 ≤ fbStart 1 ≤ … ≤ fbStart M ≤ n_max.

  • qArr : ℕ → ℕ

    Stored Feistel quotients < 2 ^ quotBitsWhp U n_max.

  • vArr : ℕ → ℕ

    Stored values < V.

Scan len slots starting at lo for qArr (lo + k) == q_val, returning 0 if absent or (lo + k) + 1 for the matching index.

Shift (qArr, vArr) down by 1 across i₀ .. i₀ + cnt - 1 (arr'[i₀ + k] = arr[i₀ + k + 1]).

Shift (qArr, vArr) up by 1 from N down across cnt elements (idx = N - k).

Adjust fbStart (b + 1 + k) by -1 (if dec = true) or +1 (if dec = false) for k = 0 .. cnt - 1.

CSR fallback lookup of (b, q_val).

CSR fallback deletion of (b, q_val) across M buckets.

CSR fallback insertion / overwrite of (b, q_val, v_val) across M buckets.

def Cslib.DataStructure.Dictionary.SuccinctWhp.ValidCsrState (U V n_max : ℕ) (h1 : ℕ → ℕ) (csr : CsrState) (dict : State U) :

Exact invariant relating CsrState to dict : Dictionary.State U under bucket hash h1.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.fbStart_mono_of_adj {M : ℕ} {f : ℕ → ℕ} (hadj : ∀ b < M, f b ≤ f (b + 1)) (a b : ℕ) :
a ≤ b → b ≤ M → f a ≤ f b
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrShiftDown_apply (i₀ cnt : ℕ) (qArr vArr : ℕ → ℕ) (x : ℕ) :
((csrShiftDown i₀ cnt (qArr, vArr)).1 x = if i₀ ≤ x ∧ x < i₀ + cnt then qArr (x + 1) else qArr x) ∧ (csrShiftDown i₀ cnt (qArr, vArr)).2 x = if i₀ ≤ x ∧ x < i₀ + cnt then vArr (x + 1) else vArr x
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrShiftUp_apply (N cnt : ℕ) (hcnt : cnt ≤ N) (qArr vArr : ℕ → ℕ) (x : ℕ) :
((csrShiftUp N cnt (qArr, vArr)).1 x = if N - cnt < x ∧ x ≤ N then qArr (x - 1) else qArr x) ∧ (csrShiftUp N cnt (qArr, vArr)).2 x = if N - cnt < x ∧ x ≤ N then vArr (x - 1) else vArr x
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidCsrState.bucket_and_dom_card {U V n_max : ℕ} {h1 : ℕ → ℕ} {csr : CsrState} {dict : State U} (hv : ValidCsrState U V n_max h1 csr dict) :
(∀ (b : Fin (numBucketsWhp n_max)), {u ∈ dom dict | FeistelQuotient.feistelBucket (bWhp n_max) h1 ↑u = ↑b}.card = csr.fbStart (↑b + 1) - csr.fbStart ↑b) ∧ (dom dict).card = csr.fbStart (numBucketsWhp n_max)

Exact bucket-slice bijection for ValidCsrState: for every b : Fin (numBucketsWhp n_max), (Dictionary.dom dict).filter (feistelBucket = b) has cardinality csr.fbStart (b + 1) - csr.fbStart b, and #(Dictionary.dom dict) = csr.fbStart M.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrQuery_spec {U V n_max : ℕ} {h1 : ℕ → ℕ} {csr : CsrState} {dict : State U} (hv : ValidCsrState U V n_max h1 csr dict) (u : Fin U) :
csrQuery csr (FeistelQuotient.feistelBucket (bWhp n_max) h1 ↑u) (FeistelQuotient.keyQuotient (bWhp n_max) ↑u) = dict u

CSR fallback lookup matches dict u for every seed h1.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrDelete_spec {U V n_max : ℕ} {h1 : ℕ → ℕ} {csr : CsrState} {dict : State U} (hv : ValidCsrState U V n_max h1 csr dict) (u : Fin U) :

CSR fallback deletion preserves ValidCsrState and refines Function.update dict u none for every seed h1.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrInsert_spec {U V n_max : ℕ} (hnU : n_max ≤ U) {h1 : ℕ → ℕ} {csr : CsrState} {dict : State U} (hv : ValidCsrState U V n_max h1 csr dict) {u : Fin U} {v : ℕ} (hvalid : Dynamic.valid V n_max dict (Dynamic.Op.insert u v)) :
ValidCsrState U V n_max h1 (csrInsert (numBucketsWhp n_max) csr (FeistelQuotient.feistelBucket (bWhp n_max) h1 ↑u) (FeistelQuotient.keyQuotient (bWhp n_max) ↑u) v) (Function.update dict u (some v))

CSR fallback insertion preserves ValidCsrState and refines Function.update dict u (some v) whenever n_max ≤ U and Dynamic.valid V n_max dict (.insert u v).

Overflow-free GoodSeedOnState decision & salt-discovery procedure on CsrState #

Overflow-free single-bucket load-balance test (M * X_b ≤ N + M * δ ∧ N ≤ M * X_b + M * δ) using only division and remainder < max (N + 1) M.

Scan b = 0 .. k - 1 to find the bucket b satisfying fbStart b ≤ i ∧ i < fbStart (b + 1).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrBucketOfIdx_spec {M : ℕ} {fbStart : ℕ → ℕ} (h0 : fbStart 0 = 0) (_hadj : ∀ b < M, fbStart b ≤ fbStart (b + 1)) (k : ℕ) :
k ≤ M → ∀ i < fbStart k, have b := csrBucketOfIdx fbStart i k; b < k ∧ fbStart b ≤ i ∧ i < fbStart (b + 1)
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrBucketOfIdx_congr {f₁ f₂ : ℕ → ℕ} {i k : ℕ} (h : ∀ b ≤ k, f₁ b = f₂ b) :
csrBucketOfIdx f₁ i k = csrBucketOfIdx f₂ i k

csrBucketOfIdx depends only on fbStart 0 .. fbStart k.

Check all buckets 0 .. k - 1 for checkBalancedBucketNat M δ N (fbStart (b + 1) - fbStart b).

Check rKeyOf j != rKeyOf i across j = 0 .. k - 1.

Check pairwise distinctness of f on 0 .. k - 1.

Search s = 0 .. k - 1 for the first salt s making fpAt s pairwise distinct on lo .. lo + len - 1, returning 0 if none exists or s + 1 if found.

Pure overflow-free GoodSeedOnState check and per-bucket collision-free salt finder on CsrState. Returns (ok, saltOfBucket).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrBucketOfIdx_eq_of_in_range {M : ℕ} {fbStart : ℕ → ℕ} (h0 : fbStart 0 = 0) (hadj : ∀ b < M, fbStart b ≤ fbStart (b + 1)) {b i : ℕ} (hb : b < M) (hlo : fbStart b ≤ i) (hhi : i < fbStart (b + 1)) :
csrBucketOfIdx fbStart i M = b
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.checkGoodSeedOnState_spec {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {csr : CsrState} {dict : State U} (hv : ValidCsrState U V n_max (bktHash c U n_max θ.1) csr dict) :
match checkGoodSeedOnState c U n_max θ csr with | (ok, salts) => (ok = true ↔ GoodSeedOnState c U n_max θ dict) ∧ (ok = true → ∀ (b : Fin (numBucketsWhp n_max)), ∃ (hs : salts ↑b < sMaxWhp c n_max), Set.InjOn (fpHash c U n_max θ.2 ⟨salts ↑b, hs⟩) ↑({u ∈ dom dict | FeistelQuotient.feistelBucket (bWhp n_max) (bktHash c U n_max θ.1) ↑u = ↑b}))

Exact soundness and completeness of checkGoodSeedOnState: for any ValidCsrState, (checkGoodSeedOnState c U n_max θ csr).1 = true ↔ GoodSeedOnState c U n_max θ dict, and when true, (checkGoodSeedOnState ...).2 b is a valid collision-free salt < sMaxWhp c n_max for every bucket b.