Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctSlabPool

Memory.Prog Slab-Stack Metadata Operations (gmPushSlabProg, gmPopSlabProg) #

This module defines the Memory.Prog operations that push and pop full-slab descriptors in GlobalMeta (gmPushSlabProg, gmUnlinkTopSlabProg, gmCompactSlabProg, gmPopSlabProg), proves their exact pure effects (gmPushSlab, gmUnlinkTopSlab, gmCompactSlab, gmPopSlab), and certifies them via the realize tactic.

Main definitions #

Main results #

Section 1: Conditional writeGMProg helpers #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmFrame_writeGMProg_ite {U V w n_max h_space base idx val : ℕ} (P : Prop) [Decidable P] (hw : 0 < w) (hidx : P → idx < SuccinctBucket.globalMetaLen n_max) (s : Memory.State) :
GmFrame U V w n_max h_space base s ((Memory.spec 0).clientState s (if P then writeGMProg U V w n_max h_space ((base, idx), val) else pure ()))
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmAt_writeGMProg_ite {U V w n_max h_space base idx val : ℕ} (P : Prop) [Decidable P] (hw : 0 < w) (hidx : P → idx < SuccinctBucket.globalMetaLen n_max) (hval : P → val < 2 ^ SuccinctBucket.globalPtrBits n_max) (s : Memory.State) :
gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (if P then writeGMProg U V w n_max h_space ((base, idx), val) else pure ())).mem = if P then Function.update (gmAt base U V w n_max h_space s.mem) idx val else gmAt base U V w n_max h_space s.mem
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeGMProg_ite_effect {U V w n_max h_space base idx val : ℕ} (P : Prop) [Decidable P] (hw : 0 < w) (hidx : P → idx < SuccinctBucket.globalMetaLen n_max) (hval : P → val < 2 ^ SuccinctBucket.globalPtrBits n_max) (s : Memory.State) :
have prog := if P then writeGMProg U V w n_max h_space ((base, idx), val) else pure (); have s' := (Memory.spec 0).clientState s prog; s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = if P then Function.update (gmAt base U V w n_max h_space s.mem) idx val else gmAt base U V w n_max h_space s.mem

Section 2: gmPushSlabProg and realizes_gmPushSlabGen #

Parameter-free Memory.Prog operation allocating a new full slab p_new = gm 0 as the new top slab s_new = gm (gmQIdx b) of bucket b = d.2.2 at base = d.2.1.

Memory.Prog operation allocating a new full slab p_new = gm 0 as the new top slab s_new = gm (gmQIdx b) of bucket b = d.2 at base = d.1.

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

Precondition for gmPushSlabProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmPushSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
GmPushSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ GmPushSlabPre U V w₀ n_max h_space w d.1 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmPushSlabProg_effect {U V w n_max h_space base b : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (s : Memory.State) (hslab : SlabBijection n_max (gmAt base U V w n_max h_space s.mem) (fun (b' : ℕ) => gmAt base U V w n_max h_space s.mem (gmQIdx b')) (gmAt base U V w n_max h_space s.mem 0)) (hp_lt : gmAt base U V w n_max h_space s.mem 0 < SuccinctBucket.maxFullSlabs n_max) :
have s' := (Memory.spec 0).clientState s (gmPushSlabProg U V w n_max h_space (base, b)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmPushSlab n_max (gmAt base U V w n_max h_space s.mem) b

Under SlabBijection and gm 0 < maxFullSlabs n_max (b < numBuckets n_max), gmPushSlabProg runs in memoryCost ≤ 38 (memoryCost_gmPushSlabProg_le) and preserves frontier, quotAt, valAt, lmAt, and memory outside [base + offGM U V w n_max h_space, base + totalSpace U V w n_max h_space). It updates gmAt to gmPushSlab n_max gm b, allocating p_new = gm 0 as the new top slab of bucket b.

Section 3: gmUnlinkTopSlabProg, gmCompactSlabProg, gmPopSlabProg #

Parameter-free Memory.Prog operation unlinking the top slab of bucket b = d.2.2 at base = d.2.1.

Memory.Prog operation unlinking the top slab of bucket b = d.2 at base = d.1 and returning its physical slab index p_del = gm (gmSlabTopIdx b).

@[simp]
@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmPopSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
GmPopSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ GmPopSlabPre U V w₀ n_max h_space w d.1 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmUnlinkTopSlabProg_effect {U V w n_max h_space base b : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (s : Memory.State) (hslab : SlabBijection n_max (gmAt base U V w n_max h_space s.mem) (fun (b' : ℕ) => gmAt base U V w n_max h_space s.mem (gmQIdx b')) (gmAt base U V w n_max h_space s.mem 0)) (hq_pos : 1 ≤ gmAt base U V w n_max h_space s.mem (gmQIdx b)) :
have s' := (Memory.spec 0).clientState s (gmUnlinkTopSlabProg U V w n_max h_space (base, b)); (Memory.spec 0).clientResult s (gmUnlinkTopSlabProg U V w n_max h_space (base, b)) = gmAt base U V w n_max h_space s.mem (gmSlabTopIdx b) ∧ s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmUnlinkTopSlab n_max (gmAt base U V w n_max h_space s.mem) b

Pure first half of gmCompactSlab when p_del < p_last: updates the directory and top pointer of b_last.

Pure second half of gmCompactSlab when p_del < p_last: updates the neighbor links of bel_last and abv_last and copies the 4 metadata fields of p_last into p_del.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmRelinkMovedSlab_preserves_meta {n_max : ℕ} (gmA : ℕ → ℕ) {p_del p_last : ℕ} (hb_last : gmA (gmSlabOwnerBIdx n_max p_last) < FeistelQuotient.numBuckets n_max) :
have gm₂ := gmRelinkMovedSlab n_max gmA p_del p_last; gm₂ 0 = gmA 0 ∧ gm₂ (gmQIdx (gmA (gmSlabOwnerBIdx n_max p_last))) = gmA (gmQIdx (gmA (gmSlabOwnerBIdx n_max p_last))) ∧ ∀ (idx : ℕ), gmSlabMetaBase n_max ≤ idx → gm₂ idx = gmA idx
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmCompactSlab_eq_parts {n_max : ℕ} (gmA : ℕ → ℕ) {p_del : ℕ} (hlt : p_del < gmA 0 - 1) (hb_last : gmA (gmSlabOwnerBIdx n_max (gmA 0 - 1)) < FeistelQuotient.numBuckets n_max) :
Function.update (gmLinkMovedNeighbors n_max (gmRelinkMovedSlab n_max gmA p_del (gmA 0 - 1)) p_del (gmA 0 - 1)) 0 (gmA 0 - 1) = gmCompactSlab n_max gmA p_del

Parameter-free Memory.Prog helper performing gmRelinkMovedSlab for d = (dp, ((base, p_del), p_last)).

Memory.Prog helper performing gmRelinkMovedSlab for d = ((base, p_del), p_last).

def Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmMovedSlabInv (U V w₀ n_max h_space base p_del p_last : ℕ) (s : Memory.State) :

Pure bounds invariant for gmRelinkMovedSlabProg and gmLinkMovedNeighborsProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmMovedSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : (ℕ × ℕ) × ℕ) (s : Memory.State) :
GmMovedSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ GmMovedSlabPre U V w₀ n_max h_space w d.1.1 d.1.2 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmRelinkMovedSlabProg_effect {U V w n_max h_space base p_del p_last : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : GmMovedSlabInv U V w n_max h_space base p_del p_last s) :
have s' := (Memory.spec 0).clientState s (gmRelinkMovedSlabProg U V w n_max h_space ((base, p_del), p_last)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmRelinkMovedSlab n_max (gmAt base U V w n_max h_space s.mem) p_del p_last

Parameter-free Memory.Prog helper performing gmLinkMovedNeighbors for d = (dp, ((base, p_del), p_last)).

Memory.Prog helper performing gmLinkMovedNeighbors for d = ((base, p_del), p_last).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmLinkMovedNeighborsProg_effect {U V w n_max h_space base p_del p_last : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : GmMovedSlabInv U V w n_max h_space base p_del p_last s) :
have s' := (Memory.spec 0).clientState s (gmLinkMovedNeighborsProg U V w n_max h_space ((base, p_del), p_last)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmLinkMovedNeighbors n_max (gmAt base U V w n_max h_space s.mem) p_del p_last

Parameter-free Memory.Prog operation compacting the slab pool by relocating the metadata of p_last = gm 0 - 1 into p_del = d.2.2 (when p_del < p_last) and decrementing gm 0.

Memory.Prog operation compacting the slab pool by relocating the metadata of p_last = gm 0 - 1 into p_del = d.2 (when p_del < p_last) and decrementing gm 0.

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

Pure bounds invariant for gmCompactSlabProg.

Precondition for gmCompactSlabProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmCompactSlabGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
GmCompactSlabGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ GmCompactSlabPre U V w₀ n_max h_space w d.1 d.2 s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmCompactSlabProg_effect {U V w n_max h_space base p_del : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (s : Memory.State) (hpre : GmCompactSlabInv U V w n_max h_space base p_del s) :
have s' := (Memory.spec 0).clientState s (gmCompactSlabProg U V w n_max h_space (base, p_del)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmCompactSlab n_max (gmAt base U V w n_max h_space s.mem) p_del

Parameter-free Memory.Prog operation popping the top slab of bucket b = d.2.2 at base = d.2.1 and compacting the physical slab pool.

Memory.Prog operation popping the top slab of bucket b = d.2 at base = d.1 and compacting the physical slab pool.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmPopSlabGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
gmPopSlabGenProg (mkDictParams U V w n_max h_space, d) = gmPopSlabProg U V w n_max h_space d
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmCompactSlabInv_of_slabBijection {U V w₀ n_max h_space base b : ℕ} (hw : 0 < w₀) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (s : Memory.State) (hslab : SlabBijection n_max (gmAt base U V w₀ n_max h_space s.mem) (fun (b' : ℕ) => gmAt base U V w₀ n_max h_space s.mem (gmQIdx b')) (gmAt base U V w₀ n_max h_space s.mem 0)) (hq_pos : 1 ≤ gmAt base U V w₀ n_max h_space s.mem (gmQIdx b)) :
GmCompactSlabInv U V w₀ n_max h_space base ((Memory.spec 0).clientResult s (gmUnlinkTopSlabProg U V w₀ n_max h_space (base, b))) ((Memory.spec 0).clientState s (gmUnlinkTopSlabProg U V w₀ n_max h_space (base, b)))
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmCompactSlabPre_of_gmPopSlabPre {U V w₀ n_max h_space w base b : ℕ} {s : Memory.State} (hw : 0 < w₀) (h : GmPopSlabPre U V w₀ n_max h_space w base b s) :
GmCompactSlabPre U V w₀ n_max h_space w base ((Memory.spec 0).clientResult s (gmUnlinkTopSlabProg U V w₀ n_max h_space (base, b))) ((Memory.spec 0).clientState s (gmUnlinkTopSlabProg U V w₀ n_max h_space (base, b)))
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmPopSlabProg_effect {U V w n_max h_space base b : ℕ} (hw : 0 < w) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (s : Memory.State) (hslab : SlabBijection n_max (gmAt base U V w n_max h_space s.mem) (fun (b' : ℕ) => gmAt base U V w n_max h_space s.mem (gmQIdx b')) (gmAt base U V w n_max h_space s.mem 0)) (hq_pos : 1 ≤ gmAt base U V w n_max h_space s.mem (gmQIdx b)) :
have s' := (Memory.spec 0).clientState s (gmPopSlabProg U V w n_max h_space (base, b)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max 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 = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ 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 = gmPopSlab n_max (gmAt base U V w n_max h_space s.mem) b

Under SlabBijection and 1 ≤ gm (gmQIdx b) (b < numBuckets n_max), gmPopSlabProg runs in memoryCost ≤ 68 (memoryCost_gmPopSlabProg_le) and preserves frontier, quotAt, valAt, lmAt, and memory outside [base + offGM U V w n_max h_space, base + totalSpace U V w n_max h_space). It updates gmAt to gmPopSlab n_max gm b, unlinking the top slab p_del of bucket b and compacting p_last = gm 0 - 1 into p_del.