Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctHash

Quotient Hashing, DictStateInv, and Feistel-Dispatched Memory.Prog Operations #

This module couples the bucket-level Memory.Prog operations of the fixed-capacity succinct dictionary with the two-stage universe-reduced 3-wise independent hash family (Cslib.DataStructure.HashFamily.WordRAM.ReducedKWise) and proves the full dictionary-level state transition, space, initialization, and expected probe-excess bounds.

Main definitions #

Main results #

Section 1: Hash parameters, space_le_succinctWords, and initSteps_le #

Effective quotient bit-width max (quotientBits U n_max) 1 ≥ 1 passed to ReducedKWise.

Reduction target bit-width parameter totalMicroBits n_max + 1 = ⌊log₂ n_max⌋ + 1 passed to ReducedKWise, ensuring n_max + 1 ≤ 2 ^ hashB n_max.

Word-RAM footprint of the 3-wise independent quotient hash family (ReducedKWise.space).

Total Word-RAM footprint totalSpace U V w n_max (hashSpace U w n_max) of the succinct dictionary in w-bit words.

Initialization instruction budget (2 plus ReducedKWise.initTableSteps and ReducedKWise.resampleSteps; with 3 allocation instructions in allocSpan, the total initialization time is initTime = initSteps U n_max + 1).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.qBits_le_of_le_pow {U w n_max : ℕ} (hw : 0 < w) (hU : U ≤ 2 ^ w) :
qBits U n_max ≤ w

Explicit linear bound on initSteps U n_max: initSteps U n_max ≤ 31 * n_max + 1091.

Multiplicative form of initSteps_le: initSteps U n_max ≤ 1091 * (n_max + 1).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.two_le_w_of_fits_space {U V w n_max base : ℕ} (hfit : WordRAM.Fits w (base + space U V w n_max)) :
2 ≤ w
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.hashSpace_le {U w n_max : ℕ} (hw : 0 < w) (hnU : n_max ≤ U) (hU : U ≤ 2 ^ w) :
hashSpace U w n_max ≤ 175 + BitPackedArray.packedWords (2 * n_max) 1 w
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.space_le_succinctWords {U V w n_max : ℕ} (hw : 0 < w) (hnU : n_max ≤ U) (hU : U ≤ 2 ^ w) :
space U V w n_max ≤ Dynamic.succinctWords 81 213 U V w n_max

Succinct word-space bound (space_le_succinctWords): for every 0 < w, n_max ≤ U, and U ≤ 2 ^ w (including Fits w U), the total space space U V w n_max is at most Dynamic.succinctWords 81 213 U V w n_max.

Section 2: Expected probeExcess bound (≤ 5) under ReducedPolySeed #

@[reducible, inline]

Seed space ReducedPolySeed (qBits U n_max) (hashB n_max) (totalMicroBits n_max) 3 of the two-stage quotient hash family.

def Cslib.DataStructure.Dictionary.WordRAM.Succinct.qStage1 (U n_max : ℕ) (α : Probability.ReducedTopSeed (qBits U n_max)) (u : Fin U) :
Fin (2 ^ min (qBits U n_max) (3 * hashB n_max))

Stage 1 multiply-shift reduction mapping u : Fin U via quotientFin U n_max u into Fin (2 ^ min (qBits U n_max) (3 * hashB n_max)).

Stage 2 degree-< 3 trinomial polynomial hash mapping reduced quotients into Fin (2 ^ totalMicroBits n_max).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.tsum_uniform_probeExcess_reducedPolyHash_le_five {U n_max : ℕ} (hnU : n_max ≤ U) (S : Finset (Fin U)) (u : Fin U) (hS : (S.erase u).card ≤ n_max) :
∑' (θ : QuotHashSeed U n_max), (Probability.PMF.uniformOfFintype (QuotHashSeed U n_max)) θ * ↑(SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 S u) ≤ 5

Two-stage expected probeExcess bound (≤ 5): for any S : Finset (Fin U) and u : Fin U with #(S.erase u) ≤ n_max ≤ U, the expected probeExcess under a uniformly chosen θ : QuotHashSeed U n_max is at most 5.

Section 3: bucketMapOfState, DictStateInv, and probe-excess cardinality bounds #

Evaluate the two-stage quotient hash on an arbitrary natural-number quotient q.

noncomputable def Cslib.DataStructure.Dictionary.WordRAM.Succinct.hValOfSeed (U n_max : ℕ) (θ : QuotHashSeed U n_max) (q : ℕ) :

Integer value (evalQuotHash U n_max θ q).val < 2 ^ totalMicroBits n_max.

noncomputable def Cslib.DataStructure.Dictionary.WordRAM.Succinct.mOfSeed (U n_max : ℕ) (θ : QuotHashSeed U n_max) (q : ℕ) :

Local micro-bucket index hValOfSeed U n_max θ q >>> bucketBits n_max < numMicroPerBucket n_max associated with quotient q.

Per-bucket quotient-to-value map induced by an abstract dictionary state s_abs : Dictionary.State U via feistelReconstruct.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.bucketMapOfState_empty (U n_max : ℕ) (h1 : ℕ → ℕ) :
bucketMapOfState U n_max h1 (empty U) = fun (x x_1 : ℕ) => none
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.bucketMapOfState_update {U n_max : ℕ} (hnU : n_max ≤ U) (h1 : ℕ → ℕ) (s_abs : State U) (u : Fin U) (v_opt : Option ℕ) :
have b := FeistelQuotient.feistelBucket (FeistelQuotient.bucketBits n_max) h1 ↑u; have q := FeistelQuotient.keyQuotient (FeistelQuotient.bucketBits n_max) ↑u; Function.update (bucketMapOfState U n_max h1 s_abs) b (Function.update (bucketMapOfState U n_max h1 s_abs b) q v_opt) = bucketMapOfState U n_max h1 (Function.update s_abs u v_opt)
structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.DictStateInv (U V w₀ n_max base : ℕ) (θ : QuotHashSeed U n_max) (s_abs : State U) (s : Memory.State) :

Full dictionary state invariant coupling s_abs : Dictionary.State U with BucketStateInv at base under quotient hash seed θ.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.dictStateInv_of_zero {U V w₀ n_max base : ℕ} (θ : QuotHashSeed U n_max) {s : Memory.State} (hgm0 : ∀ (i : ℕ), gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem i = 0) (hlm0 : ∀ (p : ℕ × ℕ), lmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem p = 0) :
DictStateInv U V w₀ n_max base θ (empty U) s ∧ slotPotential n_max (gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem) = 0

An all-zero dictionary memory region satisfies DictStateInv for Dictionary.empty U with zero slotPotential.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.chain_and_overflow_le_probeExcess {U V w₀ n_max base : ℕ} (θ : QuotHashSeed U n_max) {L : ℕ → ℕ → List ℕ} {s_abs : State U} {s : Memory.State} (hinv : BucketStateInv U V w₀ n_max (hashSpace U w₀ n_max) base (mOfSeed U n_max θ) L (bucketMapOfState U n_max (hValOfSeed U n_max θ) s_abs) s) (u : Fin U) :
have h1 := hValOfSeed U n_max θ; have b := FeistelQuotient.feistelBucket (FeistelQuotient.bucketBits n_max) h1 ↑u; have q := FeistelQuotient.keyQuotient (FeistelQuotient.bucketBits n_max) ↑u; have m := mOfSeed U n_max θ q; have gm := gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem; (L b m).length ≤ 1 + SuccinctBucket.microCollCount n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u ∧ bCount n_max gm b - SuccinctBucket.effBucketCap n_max ≤ 1 + SuccinctBucket.bucketOvfCount n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u ∧ 8 * (L b m).length + 6 * (bCount n_max gm b - SuccinctBucket.effBucketCap n_max) ≤ 14 + 8 * SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u

Under BucketStateInv ... (bucketMapOfState U n_max (hValOfSeed U n_max θ) s_abs), the length of the micro-chain L b m for key u is at most 1 + microCollCount and the bucket overflow bCount b - effBucketCap n_max is at most 1 + bucketOvfCount.

Section 4: Feistel-dispatched Memory.Prog operations realized via realize #

Well-formedness condition 0 < w₀ ∧ n_max ≤ U ∧ U < 2 ^ w₀ ∧ V ≤ 2 ^ w₀ on the dictionary parameters (U, V, w₀, n_max).

Parameter-free pure Memory.Prog extracting the key quotient keyQuotient (bucketBits n_max) u via right shift d.2 >>> dpBucketBits d.1.

Pure Memory.Prog extracting the key quotient keyQuotient (bucketBits n_max) u via right shift u >>> bucketBits n_max.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.extractQuotGenPre_mk (U V w₀ n_max h_space w u : ℕ) (s : Memory.State) :
ExtractQuotGenPre w (mkDictParams U V w₀ n_max h_space, u) s ↔ ExtractQuotPre n_max w u s

Helper lemma: (h_q &&& (2 ^ b - 1)) ^^^ (u &&& (2 ^ b - 1)) = (h_q % 2 ^ b) ^^^ keyLow b u.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.fits_bucketBits_and_mask {U V w₀ n_max h_space w base : ℕ} (henv : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hw : 0 < w₀) (hnU : n_max ≤ U) (hU : U < 2 ^ w₀) :

Helper lemma: Fits w (bucketBits n_max) and Fits w (2 ^ bucketBits n_max - 1) from DictEnvGen.

Parameter-free Feistel-dispatched query in Memory.Prog (d = (dp, ((base, u), h_q))).

Feistel-dispatched query in Memory.Prog (d = ((base, u), h_q)): computes b = (h_q &&& (2 ^ b_bits - 1)) ^^^ (u &&& (2 ^ b_bits - 1)), q = u >>> b_bits, and m = h_q >>> b_bits, then runs queryBodyProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.queryWithHashGenPre_mk (U V w₀ n_max w : ℕ) (d : (ℕ × ℕ) × ℕ) (s : Memory.State) :
QueryWithHashGenPre w (mkDictParams U V w₀ n_max (hashSpace U w₀ n_max), d) s ↔ QueryWithHashPre U V w₀ n_max w d s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.validProg_queryWithHash {U V w n_max : ℕ} {d : (ℕ × ℕ) × ℕ} {s : Memory.State} (hpre : QueryWithHashPre U V w n_max w d s) :
ValidProg w (dictFrontier U V w n_max (hashSpace U w n_max) d.1.1) s (queryWithHashProg U V w n_max d)

Parameter-free Feistel-dispatched insert in Memory.Prog (d = (dp, (((base, u), v_new), h_q))).

Feistel-dispatched insert in Memory.Prog (d = (((base, u), v_new), h_q)).

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.insertWithHashGenPre_mk (U V w₀ n_max w : ℕ) (d : ((ℕ × ℕ) × ℕ) × ℕ) (s : Memory.State) :
InsertWithHashGenPre w (mkDictParams U V w₀ n_max (hashSpace U w₀ n_max), d) s ↔ InsertWithHashPre U V w₀ n_max w d s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.validProg_insertWithHash {U V w n_max : ℕ} {d : ((ℕ × ℕ) × ℕ) × ℕ} {s : Memory.State} (hpre : InsertWithHashPre U V w n_max w d s) :
ValidProg w (dictFrontier U V w n_max (hashSpace U w n_max) d.1.1.1) s (insertWithHashProg U V w n_max d)

Parameter-free Phase 1 of Feistel-dispatched delete in Memory.Prog (d = (dp, ((base, u), h_q))).

Phase 1 of Feistel-dispatched delete in Memory.Prog (d = ((base, u), h_q)): computes (b, q, m) from (u, h_q) and runs deletePrepProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.validProg_deletePrepWithHash {U V w n_max : ℕ} {d : (ℕ × ℕ) × ℕ} {s : Memory.State} (hpre : QueryWithHashPre U V w n_max w d s) :
ValidProg w (dictFrontier U V w n_max (hashSpace U w n_max) d.1.1) s (deletePrepWithHashProg U V w n_max d)

Parameter-free Phase 2 of Feistel-dispatched delete in Memory.Prog (d = (dp, ((((base, u), h_q), ((found, j_del), phys_del)), h_q_last))).

Phase 2 of Feistel-dispatched delete in Memory.Prog (d = ((((base, u), h_q), ((found, j_del), phys_del)), h_q_last)): computes (b, m) from (u, h_q) and m_last = h_q_last >>> bucketBits n_max, then runs deleteFinishProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.validProg_deleteFinishWithHash {U V w n_max : ℕ} {d : (((ℕ × ℕ) × ℕ) × (ℕ × ℕ) × ℕ) × ℕ} {s : Memory.State} (hpre : DeleteFinishWithHashPre U V w n_max w d s) :
ValidProg w (dictFrontier U V w n_max (hashSpace U w n_max) d.1.1.1.1) s (deleteFinishWithHashProg U V w n_max d)

Section 5: Dictionary-level DictStateInv + probeExcess transition specifications #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.queryWithHashProg_dict_spec {U V w₀ n_max w base : ℕ} (hwf : DictParamsWf U V w₀ n_max) (henv : DictEnvGen w (mkDictParams U V w₀ n_max (hashSpace U w₀ n_max)) base) (θ : QuotHashSeed U n_max) {s_abs : State U} {s : Memory.State} (hinv : DictStateInv U V w₀ n_max base θ s_abs s) (u : Fin U) :
have h_q := hValOfSeed U n_max θ (FeistelQuotient.keyQuotient (FeistelQuotient.bucketBits n_max) ↑u); have d := ((base, ↑u), h_q); have prog := queryWithHashProg U V w₀ n_max d; QueryWithHashPre U V w₀ n_max w d s ∧ (Memory.spec 0).clientState s prog = s ∧ (Memory.spec 0).clientResult s prog = s_abs u ∧ WordRAM.Realization.memoryCost prog s ≤ 26 + 8 * SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u

Dictionary-level specification of queryWithHashProg: establishes QueryWithHashPre, leaves s unchanged, returns s_abs u, and uses at most 26 + 8 * probeExcess memory cost.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.insertWithHashProg_dict_spec {U V w₀ n_max w base : ℕ} (hwf : DictParamsWf U V w₀ n_max) (henv : DictEnvGen w (mkDictParams U V w₀ n_max (hashSpace U w₀ n_max)) base) (θ : QuotHashSeed U n_max) {s_abs : State U} {s : Memory.State} (hinv : DictStateInv U V w₀ n_max base θ s_abs s) (u : Fin U) (v : ℕ) (hval : (Dynamic.spec U V n_max).valid s_abs (Dynamic.Op.insert u v)) :
have h_q := hValOfSeed U n_max θ (FeistelQuotient.keyQuotient (FeistelQuotient.bucketBits n_max) ↑u); have d := (((base, ↑u), v), h_q); have prog := insertWithHashProg U V w₀ n_max d; have s' := (Memory.spec 0).clientState s prog; have gm₀ := gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem; have gm' := gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s'.mem; InsertWithHashPre U V w₀ n_max w d s ∧ s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot (hashSpace U w₀ n_max) ≤ a ∧ a < base + space U V w₀ n_max) → s'.mem a = s.mem a) ∧ DictStateInv U V w₀ n_max base θ (Function.update s_abs u (some v)) s' ∧ WordRAM.Realization.memoryCost prog s + 66 * slotPotential n_max gm' ≤ 66 * slotPotential n_max gm₀ + 184 + 8 * SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u

Dictionary-level specification of insertWithHashProg: establishes InsertWithHashPre, preserves DictStateInv for Function.update s_abs u (some v), preserves memory outside the dictionary table arrays, and satisfies the amortized memoryCost + 66 * slotPotential bound.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.deleteWithHashProg_dict_spec {U V w₀ n_max w base : ℕ} (hwf : DictParamsWf U V w₀ n_max) (henv : DictEnvGen w (mkDictParams U V w₀ n_max (hashSpace U w₀ n_max)) base) (θ : QuotHashSeed U n_max) {s_abs : State U} {s : Memory.State} (hinv : DictStateInv U V w₀ n_max base θ s_abs s) (u : Fin U) :
have h_q := hValOfSeed U n_max θ (FeistelQuotient.keyQuotient (FeistelQuotient.bucketBits n_max) ↑u); have d_prep := ((base, ↑u), h_q); have prog_prep := deletePrepWithHashProg U V w₀ n_max d_prep; ∃ (found : ℕ) (j_del : ℕ) (phys_del : ℕ) (q_last : ℕ), have prep := (((found, j_del), phys_del), q_last); have h_q_last := hValOfSeed U n_max θ q_last; have d_fin := ((((base, ↑u), h_q), (found, j_del), phys_del), h_q_last); have prog_fin := deleteFinishWithHashProg U V w₀ n_max d_fin; have s' := (Memory.spec 0).clientState s prog_fin; have gm₀ := gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s.mem; have gm' := gmAt base U V w₀ n_max (hashSpace U w₀ n_max) s'.mem; (Memory.spec 0).clientResult s prog_prep = prep ∧ QueryWithHashPre U V w₀ n_max w d_prep s ∧ (Memory.spec 0).clientState s prog_prep = s ∧ q_last < 2 ^ FeistelQuotient.quotientBits U n_max ∧ DeleteFinishWithHashPre U V w₀ n_max w d_fin s ∧ s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot (hashSpace U w₀ n_max) ≤ a ∧ a < base + space U V w₀ n_max) → s'.mem a = s.mem a) ∧ DictStateInv U V w₀ n_max base θ (Function.update s_abs u none) s' ∧ WordRAM.Realization.memoryCost prog_prep s + WordRAM.Realization.memoryCost prog_fin s + 66 * slotPotential n_max gm' ≤ 66 * slotPotential n_max gm₀ + 270 + 8 * SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) u

Dictionary-level specification of the two-phase delete (deletePrepWithHashProg followed by deleteFinishWithHashProg): establishes both preconditions, preserves DictStateInv for Function.update s_abs u none, preserves memory outside the dictionary table arrays, and bounds the combined amortized memoryCost by 270 + 8 * probeExcess.