Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctSlabMove

Slab Promotion Loop in Memory.Prog #

This module implements the K-step (K = slabSize n_max) slab promotion (promoteStepProg, promoteLoopProg, and promoteSlabProg) in Memory.Prog, proves that it preserves SlotStoreInv, bCount, and all logical (quotAt, valAt) entries via slotOf, and certifies its Word-RAM realization via realize and Realizes.iterate₀. Slab demotion (demoteSlabProg) is implemented in CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctSlabDemote.

Main definitions #

Main results #

Section 1: Single step of slab promotion (promoteStepProg) #

Parameter-free single step k < slabSize n_max of slab promotion for x = ((dp, (base, b)), k).

One step k < slabSize n_max of slab promotion for x = ((base, b), k):

  1. Reads the payload (q_u, v_u) at low tail item u = (slabSize n_max - 1) - k and the payload (q_top, v_top) at the last tail item r_top = slabSize n_max + u = gm (gmRIdx b) - 1.
  2. Copies (q_top, v_top) into tail item u.
  3. Calls removeLastTailItemProg (base, b) to compact and remove tail item r_top.
  4. Writes (q_u, v_u) into physical slab slot gm 0 * slabSize n_max + k and returns k + 1.
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteStepGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 : ℕ) :
promoteStepGenProg ((mkDictParams U V w n_max h_space, d1), d2) = promoteStepProg U V w n_max h_space (d1, d2)

Pure state invariant for step k (k < slabSize n_max) of promoteStepProg.

Precondition for promoteStepProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteStepGenPre_mk (U V w₀ n_max h_space w : ℕ) (d1 : ℕ × ℕ) (d2 : ℕ) (s : Memory.State) :
PromoteStepGenPre w ((mkDictParams U V w₀ n_max h_space, d1), d2) s ↔ PromoteStepPre U V w₀ n_max h_space w d1.1 d1.2 d2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteStepProg_effect {U V w n_max h_space base b k : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : PromoteStepInv U V w n_max h_space base b k s) :
have gm := gmAt base U V w n_max h_space s.mem; have qA := quotAt base U w n_max h_space s.mem; have vA := valAt base U V w n_max h_space s.mem; have u := SuccinctBucket.slabSize n_max - 1 - k; have r_top := SuccinctBucket.slabSize n_max + u; have g_u := n_max - 1 - gm (gmTailPtrIdx n_max b u); have g_top := n_max - 1 - gm (gmTailPtrIdx n_max b r_top); have g_del := n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1)); have g_last := n_max - 1 - (gm 1 - 1); have g_slab := gm 0 * SuccinctBucket.slabSize n_max + k; have s' := (Memory.spec 0).clientState s (promoteStepProg U V w n_max h_space ((base, b), k)); (Memory.spec 0).clientResult s (promoteStepProg U V w n_max h_space ((base, b), k)) = k + 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) ∧ quotAt base U w n_max h_space s'.mem = Function.update (Function.update (Function.update qA g_u (qA g_top)) g_del (Function.update qA g_u (qA g_top) g_last)) g_slab (qA g_u) ∧ valAt base U V w n_max h_space s'.mem = Function.update (Function.update (Function.update vA g_u (vA g_top)) g_del (Function.update vA g_u (vA g_top) g_last)) g_slab (vA g_u) ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ gmAt base U V w n_max h_space s'.mem = gmRemoveTail n_max gm b

Under PromoteStepInv U V w n_max h_space base b k s (k < slabSize n_max, gm (gmRIdx b) = 2 * slabSize n_max - k), promoteStepProg returns k + 1 in memoryCost = 66 (memoryCost_promoteStepProg). It preserves frontier, lmAt, and memory outside [base + offQuot h_space, base + totalSpace U V w n_max h_space). It moves tail item u = (slabSize n_max - 1) - k of bucket b to physical slab slot gm 0 * slabSize n_max + k, compacts the last tail item r_top = slabSize n_max + u into u, and updates gmAt to gmRemoveTail n_max gm b.

Section 2: PromoteArrInv, PromoteLoopInv, and promoteSlabProg #

structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.PromoteArrInv {α : Type u_1} (n_max b : ℕ) (gm₀ : ℕ → ℕ) (arr₀ : ℕ → α) (k : ℕ) (gm : ℕ → ℕ) (arr : ℕ → α) :

Array payload invariant at iteration k ≤ slabSize n_max of the slab-promotion loop.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteArrInv_zero {α : Type u_1} (n_max b : ℕ) (gm₀ : ℕ → ℕ) (arr₀ : ℕ → α) :
PromoteArrInv n_max b gm₀ arr₀ 0 gm₀ arr₀
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteArrInv_step {α : Type u_1} {n_max b k : ℕ} {gm₀ gm : ℕ → ℕ} {arr₀ arr : ℕ → α} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (hk : k < SuccinctBucket.slabSize 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)) (h0 : gm 0 = gm₀ 0) (hq : ∀ b' < FeistelQuotient.numBuckets n_max, gm (gmQIdx b') = gm₀ (gmQIdx b')) (hr_other : ∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm (gmRIdx b') = gm₀ (gmRIdx b')) (hr_b : gm (gmRIdx b) = 2 * SuccinctBucket.slabSize n_max - k) (htot : gm 0 * SuccinctBucket.slabSize n_max + k + gm 1 ≤ n_max) (harr : PromoteArrInv n_max b gm₀ arr₀ k gm arr) :
have u := SuccinctBucket.slabSize n_max - 1 - k; have r_top := SuccinctBucket.slabSize n_max + u; have g_u := n_max - 1 - gm (gmTailPtrIdx n_max b u); have g_top := n_max - 1 - gm (gmTailPtrIdx n_max b r_top); have g_del := n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1)); have g_last := n_max - 1 - (gm 1 - 1); have g_slab := gm 0 * SuccinctBucket.slabSize n_max + k; have arr₁ := Function.update arr g_u (arr g_top); have arr₂ := Function.update arr₁ g_del (arr₁ g_last); have arr₃ := Function.update arr₂ g_slab (arr g_u); PromoteArrInv n_max b gm₀ arr₀ (k + 1) (gmRemoveTail n_max gm b) arr₃
structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.PromoteLoopInv (U V w₀ n_max h_space base b : ℕ) (s₀ : Memory.State) (k : ℕ) (s : Memory.State) :

Loop invariant at step k ≤ slabSize n_max of promoteLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteStepInv_of_loopInv {U V w₀ n_max h_space base b k : ℕ} {s₀ s : Memory.State} (hinv : PromoteLoopInv U V w₀ n_max h_space base b s₀ k s) (hk : k < SuccinctBucket.slabSize n_max) :
PromoteStepInv U V w₀ n_max h_space base b k s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteLoopInv_step {U V w₀ n_max h_space base b k : ℕ} {s₀ s : Memory.State} (hw : 0 < w₀) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hinv : PromoteLoopInv U V w₀ n_max h_space base b s₀ k s) (hk : k < SuccinctBucket.slabSize n_max) :
have s' := (Memory.spec 0).clientState s (promoteStepProg U V w₀ n_max h_space ((base, b), k)); (Memory.spec 0).clientResult s (promoteStepProg U V w₀ n_max h_space ((base, b), k)) = k + 1 ∧ PromoteLoopInv U V w₀ n_max h_space base b s₀ (k + 1) s'
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.iterate_promoteStepProg_spec {U V w₀ n_max h_space w base b : ℕ} {s₀ : Memory.State} (hw : 0 < w₀) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (m k : ℕ) (s : Memory.State) :
k + m ≤ SuccinctBucket.slabSize n_max → PromoteLoopInv U V w₀ n_max h_space base b s₀ k s → PromoteLoopInv U V w₀ n_max h_space base b s₀ (k + m) ((Memory.spec 0).clientState s (WordRAM.Realization.iterate (promoteStepProg U V w₀ n_max h_space) (base, b) m k)) ∧ WordRAM.Realization.memoryCost (WordRAM.Realization.iterate (promoteStepProg U V w₀ n_max h_space) (base, b) m k) s = 66 * m ∧ (DictEnvGen w (mkDictParams U V w₀ n_max h_space) base → WordRAM.Realization.iterationSafe (promoteStepProg U V w₀ n_max h_space) (fun (w : ℕ) (x : (ℕ × ℕ) × ℕ) (s : Memory.State) => PromoteStepPre U V w₀ n_max h_space w x.1.1 x.1.2 x.2 s) w (base, b) m k s)

Parameter-free wrapper for iterate promoteStepGenProg with signature (((dp, (base, b)), k), m) → Memory.Prog ℕ matching Realizes.iterate₀.

Wrapper for iterate (promoteStepProg U V w n_max h_space) with signature (((base, b), k), m) → Memory.Prog ℕ matching Realizes.iterate₀.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteLoopGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) :
promoteLoopGenProg (((mkDictParams U V w n_max h_space, d1), d2), d3) = promoteLoopProg U V w n_max h_space ((d1, d2), d3)
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.iterationSafe_promoteStepGenProg_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (m k : ℕ) (s : Memory.State) :
WordRAM.Realization.iterationSafe promoteStepGenProg PromoteStepGenPre w (mkDictParams U V w₀ n_max h_space, d) m k s ↔ WordRAM.Realization.iterationSafe (promoteStepProg U V w₀ n_max h_space) (fun (w : ℕ) (x : (ℕ × ℕ) × ℕ) (s : Memory.State) => PromoteStepPre U V w₀ n_max h_space w x.1.1 x.1.2 x.2 s) w d m k s

Parameter-free Memory.Prog operation promoting K = slabSize n_max tail items of bucket b = d.2.2 at base = d.2.1 into a new full slab.

Memory.Prog operation promoting K = slabSize n_max tail items of bucket b = d.2 at base = d.1 (gm (gmRIdx b) = 2 * K) into a new full slab via promoteLoopProg followed by gmPushSlabProg.

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

Pure entry invariant for promoteSlabProg.

Precondition for promoteSlabProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
PromoteSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ PromoteSlabPre U V w₀ n_max h_space w d.1 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteLoopInv_zero {U V w₀ n_max h_space base b : ℕ} {s₀ : Memory.State} (hpre : PromoteSlabInv U V w₀ n_max h_space base b s₀) :
PromoteLoopInv U V w₀ n_max h_space base b s₀ 0 s₀
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slotOf_gmPushSlab_preserve {α : Type u_1} {n_max b : ℕ} {gm₀ gm : ℕ → ℕ} {arr₀ arr : ℕ → α} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets 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)) (h0 : gm 0 = gm₀ 0) (hq : ∀ b' < FeistelQuotient.numBuckets n_max, gm (gmQIdx b') = gm₀ (gmQIdx b')) (hr_other : ∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm (gmRIdx b') = gm₀ (gmRIdx b')) (hr_b : gm (gmRIdx b) = SuccinctBucket.slabSize n_max) (_hr0_b : gm₀ (gmRIdx b) = 2 * SuccinctBucket.slabSize n_max) (htot : (gm 0 + 1) * SuccinctBucket.slabSize n_max + gm 1 ≤ n_max) (harr : PromoteArrInv n_max b gm₀ arr₀ (SuccinctBucket.slabSize n_max) gm arr) (b' : ℕ) :
b' < FeistelQuotient.numBuckets n_max → ∀ j < bCount n_max (gmPushSlab n_max gm b) b', arr (slotOf n_max (gmPushSlab n_max gm b) b' j) = arr₀ (slotOf n_max gm₀ b' j)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.promoteSlabProg_effect {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) :
have gm₀ := gmAt base U V w n_max h_space s.mem; have s' := (Memory.spec 0).clientState s (promoteSlabProg U V w n_max h_space (base, b)); 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' ∧ gm' (gmQIdx b) = gm₀ (gmQIdx b) + 1 ∧ gm' (gmRIdx b) = SuccinctBucket.slabSize n_max ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gm' (gmQIdx b') = gm₀ (gmQIdx b') ∧ gm' (gmRIdx b') = gm₀ (gmRIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, 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 (promoteSlabProg U V w n_max h_space (base, b)) s ≤ 66 * SuccinctBucket.slabSize n_max + 38

Under PromoteSlabInv U V w n_max h_space base b s (gm (gmRIdx b) = 2 * slabSize n_max), promoteSlabProg runs in memoryCost ≤ 66 * slabSize n_max + 38 and preserves frontier, lmAt, and memory outside [base + offQuot h_space, base + totalSpace U V w n_max h_space). It restores SlotStoreInv n_max gm' with gm' (gmQIdx b) = gm₀ (gmQIdx b) + 1, gm' (gmRIdx b) = slabSize n_max, and unchanged (gmQIdx b', gmRIdx b') for b' ≠ b. It also preserves bCount and every logical (quotAt, valAt) entry at slotOf across all buckets.