Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctSlabOps

Amortized O(1) Slot Allocation and Deallocation in Memory.Prog #

This module combines the tail-item operations (appendTailItemProg, removeLastTailItemProg) and the K-step slab promotion/demotion loops (promoteSlabProg, demoteSlabProg) into the high-level bucket-local slot operations:

Main definitions #

Main results #

Section 1: totalSlots, hysteresis potential bounds, and lastSlotOfProg #

Total number of active slots across all buckets in GlobalMeta:

  • gm 0 in the single-bucket regime (bucketBits n_max = 0);
  • gm 0 * slabSize n_max + gm 1 in the multi-bucket regime (0 < bucketBits n_max).
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.totalSlots_of_zero (n_max : ℕ) {gm : ℕ → ℕ} (hzero : ∀ (i : ℕ), gm i = 0) :
totalSlots n_max gm = 0
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.totalSlots_le {n_max : ℕ} {gm : ℕ → ℕ} (hinv : SlotStoreInv n_max gm) :
totalSlots n_max gm ≤ n_max
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.bCount_le_totalSlots {n_max : ℕ} {gm : ℕ → ℕ} (hinv : SlotStoreInv n_max gm) (b : ℕ) (hb : b < FeistelQuotient.numBuckets n_max) :
bCount n_max gm b ≤ totalSlots n_max gm
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pos_gmRIdx_of_pos_bCount {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hinv : SlotStoreInv n_max gm) (hb : b < FeistelQuotient.numBuckets n_max) (hbc : 1 ≤ bCount n_max gm b) :
1 ≤ gm (gmRIdx b)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slotPotential_pushBack_le {n_max b : ℕ} {gm gm' : ℕ → ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (hb_upd : gm' (gmQIdx b) = (SuccinctBucket.pushBackCounts (SuccinctBucket.slabSize n_max) (gm (gmQIdx b)) (gm (gmRIdx b))).1 ∧ gm' (gmRIdx b) = (SuccinctBucket.pushBackCounts (SuccinctBucket.slabSize n_max) (gm (gmQIdx b)) (gm (gmRIdx b))).2) (hother : ∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm' (gmQIdx b') = gm (gmQIdx b') ∧ gm' (gmRIdx b') = gm (gmRIdx b')) :

Global potential bound when bucket b transitions according to pushBackCounts.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slotPotential_popBack_le {n_max b : ℕ} {gm gm' : ℕ → ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (hr1 : 1 ≤ gm (gmRIdx b)) (hr2 : gm (gmRIdx b) < 2 * SuccinctBucket.slabSize n_max) (hb_upd : gm' (gmQIdx b) = (SuccinctBucket.popBackCounts (SuccinctBucket.slabSize n_max) (gm (gmQIdx b)) (gm (gmRIdx b))).1 ∧ gm' (gmRIdx b) = (SuccinctBucket.popBackCounts (SuccinctBucket.slabSize n_max) (gm (gmQIdx b)) (gm (gmRIdx b))).2) (hother : ∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm' (gmQIdx b') = gm (gmQIdx b') ∧ gm' (gmRIdx b') = gm (gmRIdx b')) :

Global potential bound when bucket b transitions according to popBackCounts.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.nslabs_eq_sum {n_max : ℕ} {gm q_fn : ℕ → ℕ} {n_slabs : ℕ} (hslab : SlabBijection n_max gm q_fn n_slabs) :
n_slabs = ∑ b ∈ Finset.range (FeistelQuotient.numBuckets n_max), q_fn b

Under SlabBijection, n_slabs equals the sum of per-bucket slab counts q_fn b.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.ntails_eq_sum {n_max : ℕ} {gm r_fn : ℕ → ℕ} {n_tails : ℕ} (htail : TailBijection n_max gm r_fn n_tails) :
n_tails = ∑ b ∈ Finset.range (FeistelQuotient.numBuckets n_max), r_fn b

Under TailBijection, n_tails equals the sum of per-bucket tail counts r_fn b.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.total_eq_sum_bCount {n_max : ℕ} {gm : ℕ → ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (htail : TailBijection n_max gm (fun (b : ℕ) => gm (gmRIdx b)) (gm 1)) (hslab : SlabBijection n_max gm (fun (b : ℕ) => gm (gmQIdx b)) (gm 0)) :
gm 0 * SuccinctBucket.slabSize n_max + gm 1 = ∑ b ∈ Finset.range (FeistelQuotient.numBuckets n_max), bCount n_max gm b

In the multi-bucket regime (0 < bucketBits n_max), the total active slot count gm 0 * slabSize n_max + gm 1 equals the sum of per-bucket item counts bCount n_max gm b.

Under SlotStoreInv n_max gm, totalSlots n_max gm equals the sum of bCount n_max gm b over all buckets b < numBuckets n_max.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteSlabProg_tot_eq {U V w n_max h_space base b : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : PromoteSlabInv U V w n_max h_space base b s) :
gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (promoteSlabProg U V w n_max h_space (base, b))).mem 0 * SuccinctBucket.slabSize n_max + gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (promoteSlabProg U V w n_max h_space (base, b))).mem 1 = gmAt base U V w n_max h_space s.mem 0 * SuccinctBucket.slabSize n_max + gmAt base U V w n_max h_space s.mem 1

promoteSlabProg preserves gm 0 * slabSize n_max + gm 1.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteSlabProg_tot_eq {U V w n_max h_space base b : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : DemoteSlabInv U V w n_max h_space base b s) :
gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (demoteSlabProg U V w n_max h_space (base, b))).mem 0 * SuccinctBucket.slabSize n_max + gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (demoteSlabProg U V w n_max h_space (base, b))).mem 1 = gmAt base U V w n_max h_space s.mem 0 * SuccinctBucket.slabSize n_max + gmAt base U V w n_max h_space s.mem 1

demoteSlabProg preserves gm 0 * slabSize n_max + gm 1.

Parameter-free Memory.Prog operation resolving the physical slot slotOf n_max gm b (bCount n_max gm b - 1) of the last item in a non-empty bucket b = d.2.2 at base = d.2.1 (1 ≤ bCount n_max gm b).

Memory.Prog operation resolving the physical slot slotOf n_max gm b (bCount n_max gm b - 1) of the last item in a non-empty bucket b = d.2 at base = d.1 (1 ≤ bCount n_max gm b).

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.lastSlotOfGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
lastSlotOfGenProg (mkDictParams U V w n_max h_space, d) = lastSlotOfProg U V w n_max h_space d
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.lastSlotOfGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
LastSlotOfGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ DictEnvGen w (mkDictParams U V w₀ n_max h_space) d.1 ∧ SlotStoreInv n_max (gmAt d.1 U V w₀ n_max h_space s.mem) ∧ d.2 < FeistelQuotient.numBuckets n_max ∧ 1 ≤ bCount n_max (gmAt d.1 U V w₀ n_max h_space s.mem) d.2
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.ite_bucketBits_mk {α : Sort u_1} (U V w n_max h_space : ℕ) (t e : α) :
(if dpBucketBits (mkDictParams U V w n_max h_space) = 0 then t else e) = if FeistelQuotient.bucketBits n_max = 0 then t else e

Specialize a packed bucket guard together with its decision instance.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_lastSlotOfProg {U V w n_max h_space : ℕ} (d : ℕ × ℕ) (s : Memory.State) (hinv : SlotStoreInv n_max (gmAt d.1 U V w n_max h_space s.mem)) (hb : d.2 < FeistelQuotient.numBuckets n_max) (hbc : 1 ≤ bCount n_max (gmAt d.1 U V w n_max h_space s.mem) d.2) :
(Memory.spec 0).clientResult s (lastSlotOfProg U V w n_max h_space d) = slotOf n_max (gmAt d.1 U V w n_max h_space s.mem) d.2 (bCount n_max (gmAt d.1 U V w n_max h_space s.mem) d.2 - 1)

Section 2: pushBackSlotProg via realize #

Helper Memory.Prog for the multi-bucket prefix of pushBackSlotProg: appends one tail item to bucket b = d.1.1.2 at base = d.1.1.1, writes (q_val, v_val) = (d.1.2, d.2) into its physical slot, and returns the updated tail count r_b_new = gm' (gmRIdx b).

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackTailWriteGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) :
pushBackTailWriteGenProg (((mkDictParams U V w n_max h_space, d1), d2), d3) = pushBackTailWriteProg U V w n_max h_space ((d1, d2), d3)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackTailWriteProg_effect {U V w n_max h_space base b q_val v_val : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hinv : SlotStoreInv n_max (gmAt base U V w n_max h_space s.mem)) (hb : b < FeistelQuotient.numBuckets n_max) (htot : totalSlots n_max (gmAt base U V w n_max h_space s.mem) < n_max) (hq_lt : q_val < 2 ^ FeistelQuotient.quotientBits U n_max) (hv_lt : v_val < 2 ^ FeistelQuotient.valBits V) :
have gm₀ := gmAt base U V w n_max h_space s.mem; have d := (((base, b), q_val), v_val); have s₁ := (Memory.spec 0).clientState s (pushBackTailWriteProg U V w n_max h_space d); have gm₁ := gmAt base U V w n_max h_space s₁.mem; (Memory.spec 0).clientResult s (pushBackTailWriteProg U V w n_max h_space d) = gm₀ (gmRIdx b) + 1 ∧ s₁.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot h_space ≤ a ∧ a < base + totalSpace U V w n_max h_space) → s₁.mem a = s.mem a) ∧ lmAt base U V w n_max h_space s₁.mem = lmAt base U V w n_max h_space s.mem ∧ gm₁ = gmAppendTail n_max gm₀ b ∧ TailBijection n_max gm₁ (fun (b' : ℕ) => gm₁ (gmRIdx b')) (gm₁ 1) ∧ SlabBijection n_max gm₁ (fun (b' : ℕ) => gm₁ (gmQIdx b')) (gm₁ 0) ∧ gm₁ 0 * SuccinctBucket.slabSize n_max + gm₁ 1 = gm₀ 0 * SuccinctBucket.slabSize n_max + gm₀ 1 + 1 ∧ gm₁ (gmQIdx b) = gm₀ (gmQIdx b) ∧ gm₁ (gmRIdx b) = gm₀ (gmRIdx b) + 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm₁ (gmQIdx b') = gm₀ (gmQIdx b') ∧ gm₁ (gmRIdx b') = gm₀ (gmRIdx b')) ∧ bCount n_max gm₁ b = bCount n_max gm₀ b + 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → bCount n_max gm₁ b' = bCount n_max gm₀ b') ∧ quotAt base U w n_max h_space s₁.mem (slotOf n_max gm₁ b (bCount n_max gm₀ b)) = q_val ∧ valAt base U V w n_max h_space s₁.mem (slotOf n_max gm₁ b (bCount n_max gm₀ b)) = v_val ∧ ∀ b' < FeistelQuotient.numBuckets n_max, ∀ j < bCount n_max gm₀ b', quotAt base U w n_max h_space s₁.mem (slotOf n_max gm₁ b' j) = quotAt base U w n_max h_space s.mem (slotOf n_max gm₀ b' j) ∧ valAt base U V w n_max h_space s₁.mem (slotOf n_max gm₁ b' j) = valAt base U V w n_max h_space s.mem (slotOf n_max gm₀ b' j)

Pure state effect and return value of pushBackTailWriteProg.

Precondition for pushBackSlotProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackSlotGenPre_mk (U V w₀ n_max h_space w : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) (s : Memory.State) :
PushBackSlotGenPre w (((mkDictParams U V w₀ n_max h_space, d1), d2), d3) s ↔ PushBackSlotPre U V w₀ n_max h_space w ((d1, d2), d3) s
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackTailWriteGenPre_mk (U V w₀ n_max h_space w : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) (s : Memory.State) :
PushBackTailWriteGenPre w (((mkDictParams U V w₀ n_max h_space, d1), d2), d3) s ↔ PushBackSlotPre U V w₀ n_max h_space w ((d1, d2), d3) s ∧ 0 < FeistelQuotient.bucketBits n_max

Parameter-free Memory.Prog operation appending (q_val, v_val) = (d.1.2, d.2) at logical slot bCount n_max gm b of bucket b = d.1.1.2.2 at base = d.1.1.2.1.

Memory.Prog operation appending (q_val, v_val) = (d.1.2, d.2) at logical slot bCount n_max gm b of bucket b = d.1.1.2 at base = d.1.1.1, promoting K tail items into a new full slab when r_b + 1 = 2 * K.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackSlotGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) :
pushBackSlotGenProg (((mkDictParams U V w n_max h_space, d1), d2), d3) = pushBackSlotProg U V w n_max h_space ((d1, d2), d3)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.pushBackSlotProg_effect {U V w n_max h_space base b q_val v_val : ℕ} (hw : 0 < w) (s : Memory.State) (hinv : SlotStoreInv n_max (gmAt base U V w n_max h_space s.mem)) (hb : b < FeistelQuotient.numBuckets n_max) (htot : totalSlots n_max (gmAt base U V w n_max h_space s.mem) < n_max) (hq_lt : q_val < 2 ^ FeistelQuotient.quotientBits U n_max) (hv_lt : v_val < 2 ^ FeistelQuotient.valBits V) :
have gm₀ := gmAt base U V w n_max h_space s.mem; have d := (((base, b), q_val), v_val); have s' := (Memory.spec 0).clientState s (pushBackSlotProg U V w n_max h_space d); have gm' := gmAt base U V w n_max h_space s'.mem; s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot h_space ≤ a ∧ a < base + totalSpace U V w n_max h_space) → s'.mem a = s.mem a) ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ SlotStoreInv n_max gm' ∧ totalSlots n_max gm' = totalSlots n_max gm₀ + 1 ∧ bCount n_max gm' b = bCount n_max gm₀ b + 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → bCount n_max gm' b' = bCount n_max gm₀ b') ∧ quotAt base U w n_max h_space s'.mem (slotOf n_max gm' b (bCount n_max gm₀ b)) = q_val ∧ valAt base U V w n_max h_space s'.mem (slotOf n_max gm' b (bCount n_max gm₀ b)) = v_val ∧ (∀ b' < FeistelQuotient.numBuckets n_max, ∀ j < bCount n_max gm₀ b', quotAt base U w n_max h_space s'.mem (slotOf n_max gm' b' j) = quotAt base U w n_max h_space s.mem (slotOf n_max gm₀ b' j) ∧ valAt base U V w n_max h_space s'.mem (slotOf n_max gm' b' j) = valAt base U V w n_max h_space s.mem (slotOf n_max gm₀ b' j)) ∧ WordRAM.Realization.memoryCost (pushBackSlotProg U V w n_max h_space d) s + 66 * slotPotential n_max gm' ≤ 66 * slotPotential n_max gm₀ + 134

Pure state effect and amortized memoryCost bound of pushBackSlotProg.

Section 3: popBackSlotProg via realize #

Parameter-free Memory.Prog operation removing the last logical slot bCount n_max gm b - 1 of a non-empty bucket b = d.2.2 at base = d.2.1.

Memory.Prog operation removing the last logical slot bCount n_max gm b - 1 of a non-empty bucket b = d.2 at base = d.1, demoting the top full slab into K = slabSize n_max tail items when r_b - 1 = 0 ∧ 0 < q_b.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.popBackSlotGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
popBackSlotGenProg (mkDictParams U V w n_max h_space, d) = popBackSlotProg U V w n_max h_space d

Precondition for popBackSlotProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.popBackSlotGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
PopBackSlotGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ PopBackSlotPre U V w₀ n_max h_space w d s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.popBackSlotProg_effect {U V w n_max h_space base b : ℕ} (hw : 0 < w) (s : Memory.State) (hinv : SlotStoreInv n_max (gmAt base U V w n_max h_space s.mem)) (hb : b < FeistelQuotient.numBuckets n_max) (hbc : 1 ≤ bCount n_max (gmAt base U V w n_max h_space s.mem) b) :
have gm₀ := gmAt base U V w n_max h_space s.mem; have d := (base, b); have s' := (Memory.spec 0).clientState s (popBackSlotProg U V w n_max h_space d); have gm' := gmAt base U V w n_max h_space s'.mem; s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot h_space ≤ a ∧ a < base + totalSpace U V w n_max h_space) → s'.mem a = s.mem a) ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ SlotStoreInv n_max gm' ∧ totalSlots n_max gm' + 1 = totalSlots n_max gm₀ ∧ bCount n_max gm' b = bCount n_max gm₀ b - 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → bCount n_max gm' b' = bCount n_max gm₀ b') ∧ (∀ b' < FeistelQuotient.numBuckets n_max, ∀ j < bCount n_max gm' b', quotAt base U w n_max h_space s'.mem (slotOf n_max gm' b' j) = quotAt base U w n_max h_space s.mem (slotOf n_max gm₀ b' j) ∧ valAt base U V w n_max h_space s'.mem (slotOf n_max gm' b' j) = valAt base U V w n_max h_space s.mem (slotOf n_max gm₀ b' j)) ∧ WordRAM.Realization.memoryCost (popBackSlotProg U V w n_max h_space d) s + 66 * slotPotential n_max gm' ≤ 66 * slotPotential n_max gm₀ + 174

Pure state effect and amortized memoryCost bound of popBackSlotProg.