Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctSlabDemote

Memory.Prog Slab Demotion Loop (demoteStepProg, demoteLoopProg, demoteSlabProg) #

This module implements the K = slabSize n_max-step slab-demotion loop for the fixed-capacity succinct dictionary using Memory.Prog, iterate, and the realize tactic (Realizes.iterate₀). When a bucket b has gm (gmRIdx b) = 0 tail items and 1 ≤ gm (gmQIdx b) full slabs after removing its last tail item, demoteSlabProg moves the K items from the top slab p_del = gm (gmSlabTopIdx b) into the tail of bucket b, compacts the physical slab pool by copying the K items of p_last = gm 0 - 1 into p_del, and pops the top slab descriptor via gmPopSlabProg.

Main definitions #

Main results #

Section 1: Single step demoteStepProg #

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

One iteration (0 ≤ k < slabSize n_max) of the slab-demotion loop for bucket b = x.1.2 at base = x.1.1 with loop index k = x.2. For u = (slabSize n_max - 1) - k, p_del = gm (gmSlabTopIdx b), and p_last = gm 0 - 1:

  1. Reads (q_del, v_del) at g_del = p_del * slabSize n_max + u and (q_last, v_last) at g_last = p_last * slabSize n_max + u.
  2. Appends a new tail item t_new = gm 1 to bucket b (g_tail = (n_max - 1) - t_new).
  3. Writes (q_last, v_last) to g_del first, and (q_del, v_del) to g_tail second, then returns k + 1.
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteStepGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 : ℕ) :
demoteStepGenProg ((mkDictParams U V w n_max h_space, d1), d2) = demoteStepProg U V w n_max h_space (d1, d2)

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

Precondition for demoteStepProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteStepGenPre_mk (U V w₀ n_max h_space w : ℕ) (d1 : ℕ × ℕ) (d2 : ℕ) (s : Memory.State) :
DemoteStepGenPre w ((mkDictParams U V w₀ n_max h_space, d1), d2) s ↔ DemoteStepPre U V w₀ n_max h_space w d1.1 d1.2 d2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteStepProg_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 : DemoteStepInv 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 p_del := gm (gmSlabTopIdx b); have p_last := gm 0 - 1; have g_del := p_del * SuccinctBucket.slabSize n_max + u; have g_last := p_last * SuccinctBucket.slabSize n_max + u; have g_tail := n_max - 1 - gm 1; have s' := (Memory.spec 0).clientState s (demoteStepProg U V w n_max h_space ((base, b), k)); (Memory.spec 0).clientResult s (demoteStepProg 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 qA g_del (qA g_last)) g_tail (qA g_del) ∧ valAt base U V w n_max h_space s'.mem = Function.update (Function.update vA g_del (vA g_last)) g_tail (vA g_del) ∧ 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 = gmAppendTail n_max gm b

Under DemoteStepInv U V w n_max h_space base b k s (k < slabSize n_max, gm (gmRIdx b) = k, 1 ≤ gm (gmQIdx b)), demoteStepProg returns k + 1 in memoryCost = 48 (memoryCost_demoteStepProg). It preserves frontier, lmAt, and memory outside [base + offQuot h_space, base + totalSpace U V w n_max h_space). It copies entry u = (slabSize n_max - 1) - k of the last full slab p_last = gm 0 - 1 into p_del = gm (gmSlabTopIdx b), moves the old entry of p_del into the new tail slot g_tail = (n_max - 1) - gm 1, and updates gmAt to gmAppendTail n_max gm b.

Section 2: DemoteArrInv, DemoteLoopInv, and demoteSlabProg #

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

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

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteArrInv_zero {α : Type u_1} (n_max b : ℕ) (gm₀ : ℕ → ℕ) (arr₀ : ℕ → α) :
DemoteArrInv n_max b gm₀ arr₀ 0 gm₀ arr₀
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteArrInv_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) (h1_ge : gm₀ 1 ≤ gm 1) (htop_b : gm (gmSlabTopIdx b) = gm₀ (gmSlabTopIdx b)) (hr_b : gm (gmRIdx b) = k) (hqb_pos : 1 ≤ gm (gmQIdx b)) (htot : (gm 0 - 1) * SuccinctBucket.slabSize n_max + (SuccinctBucket.slabSize n_max - k) + gm 1 ≤ n_max) (harr : DemoteArrInv n_max b gm₀ arr₀ k gm arr) :
have u_k := SuccinctBucket.slabSize n_max - 1 - k; have g_del := gm (gmSlabTopIdx b) * SuccinctBucket.slabSize n_max + u_k; have g_last := (gm 0 - 1) * SuccinctBucket.slabSize n_max + u_k; have g_tail := n_max - 1 - gm 1; have arr' := Function.update (Function.update arr g_del (arr g_last)) g_tail (arr g_del); DemoteArrInv n_max b gm₀ arr₀ (k + 1) (gmAppendTail n_max gm b) arr'
structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.DemoteLoopInv (U V w₀ n_max h_space base b : ℕ) (s₀ : Memory.State) (k : ℕ) (s : Memory.State) :

Full loop invariant for k ≤ slabSize n_max iterations of demoteStepProg starting from s₀.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteLoopInv_to_stepInv {U V w₀ n_max h_space base b k : ℕ} {s₀ s : Memory.State} (hloop : DemoteLoopInv U V w₀ n_max h_space base b s₀ k s) (hk : k < SuccinctBucket.slabSize n_max) :
DemoteStepInv U V w₀ n_max h_space base b k s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteLoopInv_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) (hloop : DemoteLoopInv 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 (demoteStepProg U V w₀ n_max h_space ((base, b), k)); (Memory.spec 0).clientResult s (demoteStepProg U V w₀ n_max h_space ((base, b), k)) = k + 1 ∧ DemoteLoopInv U V w₀ n_max h_space base b s₀ (k + 1) s'

Parameter-free Memory.Prog loop executing n iterations of demoteStepGenProg starting from index k: d = (((dp, (base, b)), k), n).

Memory.Prog loop executing n iterations of demoteStepProg starting from index k: d = (((base, b), k), n).

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteLoopGenProg_mk (U V w n_max h_space : ℕ) (d1 : ℕ × ℕ) (d2 d3 : ℕ) :
demoteLoopGenProg (((mkDictParams U V w n_max h_space, d1), d2), d3) = demoteLoopProg U V w n_max h_space ((d1, d2), d3)
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.iterationSafe_demoteStepGenProg_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (m k : ℕ) (s : Memory.State) :
WordRAM.Realization.iterationSafe demoteStepGenProg DemoteStepGenPre w (mkDictParams U V w₀ n_max h_space, d) m k s ↔ WordRAM.Realization.iterationSafe (demoteStepProg U V w₀ n_max h_space) (fun (w : ℕ) (x : (ℕ × ℕ) × ℕ) (s : Memory.State) => DemoteStepPre U V w₀ n_max h_space w x.1.1 x.1.2 x.2 s) w d m k s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.iterate_demoteStepProg_spec {U V w₀ n_max h_space base b w : ℕ} {s₀ : Memory.State} (hw : 0 < w₀) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (n k : ℕ) (s : Memory.State) (hnk : k + n ≤ SuccinctBucket.slabSize n_max) (hloop : DemoteLoopInv U V w₀ n_max h_space base b s₀ k s) :
have prog := WordRAM.Realization.iterate (demoteStepProg U V w₀ n_max h_space) (base, b) n k; DemoteLoopInv U V w₀ n_max h_space base b s₀ (k + n) ((Memory.spec 0).clientState s prog) ∧ WordRAM.Realization.memoryCost prog s = 48 * n ∧ (DictEnvGen w (mkDictParams U V w₀ n_max h_space) base → WordRAM.Realization.iterationSafe (demoteStepProg U V w₀ n_max h_space) (fun (w : ℕ) (x : (ℕ × ℕ) × ℕ) (s : Memory.State) => DemoteStepPre U V w₀ n_max h_space w x.1.1 x.1.2 x.2 s) w (base, b) n k s)

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

Memory.Prog operation demoting the top full slab of bucket b = d.2 at base = d.1 (gm (gmRIdx b) = 0, 1 ≤ gm (gmQIdx b)) into K = slabSize n_max tail items via demoteLoopProg followed by gmPopSlabProg.

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

Pure entry invariant for demoteSlabProg.

Precondition for demoteSlabProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
DemoteSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ DemoteSlabPre U V w₀ n_max h_space w d.1 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteLoopInv_zero {U V w₀ n_max h_space base b : ℕ} {s₀ : Memory.State} (hpre : DemoteSlabInv U V w₀ n_max h_space base b s₀) :
DemoteLoopInv U V w₀ n_max h_space base b s₀ 0 s₀
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slotOf_gmPopSlab_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)) (_htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) (hslab₀ : SlabBijection n_max gm₀ (fun (b' : ℕ) => gm₀ (gmQIdx b')) (gm₀ 0)) (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')) (htop_b : gm (gmSlabTopIdx b) = gm₀ (gmSlabTopIdx 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) = 0) (hqb_pos : 1 ≤ gm₀ (gmQIdx b)) (hslabPtr : ∀ (b' s_idx : ℕ), slabPtrOf n_max gm b' s_idx = slabPtrOf n_max gm₀ b' s_idx) (htail_other : ∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → ∀ r < gm₀ (gmRIdx b'), gm (gmTailPtrIdx n_max b' r) = gm₀ (gmTailPtrIdx n_max b' r)) (harr : DemoteArrInv n_max b gm₀ arr₀ (SuccinctBucket.slabSize n_max) gm arr) (b' : ℕ) :
b' < FeistelQuotient.numBuckets n_max → ∀ j < bCount n_max (gmPopSlab n_max gm b) b', arr (slotOf n_max (gmPopSlab n_max gm b) b' j) = arr₀ (slotOf n_max gm₀ b' j)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteSlabProg_effect {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) :
have gm₀ := gmAt base U V w n_max h_space s.mem; have s' := (Memory.spec 0).clientState s (demoteSlabProg 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 (demoteSlabProg U V w n_max h_space (base, b)) s ≤ 48 * SuccinctBucket.slabSize n_max + 68

Under DemoteSlabInv U V w n_max h_space base b s (gm (gmRIdx b) = 0 and 1 ≤ gm (gmQIdx b)), demoteSlabProg runs in memoryCost ≤ 48 * slabSize n_max + 68 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.