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 #
Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteStepProg: single stepk < slabSize n_maxof slab demotion.Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteLoopProg:K-step iteration ofdemoteStepProg.Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteSlabProg: complete slab demotion (demoteLoopProgfollowed bygmPopSlabProg).Cslib.DataStructure.Dictionary.WordRAM.Succinct.DemoteSlabInv: entry invariant fordemoteSlabProg(gm (gmRIdx b) = 0 ∧ 0 < gm (gmQIdx b)).
Main results #
Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteStepProg_effect,Cslib.DataStructure.Dictionary.WordRAM.Succinct.realizes_demoteStepGen: single-step invariant preservation andRealizescertificate fordemoteStepProg.Cslib.DataStructure.Dictionary.WordRAM.Succinct.demoteSlabProg_effect,Cslib.DataStructure.Dictionary.WordRAM.Succinct.realizes_demoteSlabGen: full-slab demotion invariant preservation,O(K)memoryCost, andRealizescertificate fordemoteSlabProg.
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:
- Reads
(q_del, v_del)atg_del = p_del * slabSize n_max + uand(q_last, v_last)atg_last = p_last * slabSize n_max + u. - Appends a new tail item
t_new = gm 1to bucketb(g_tail = (n_max - 1) - t_new). - Writes
(q_last, v_last)tog_delfirst, and(q_del, v_del)tog_tailsecond, then returnsk + 1.
Pure state invariant for step k (k < slabSize n_max) of demoteStepProg.
Precondition for demoteStepProg in Realizes.
Parameter-free precondition for demoteStepGenProg.
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 #
Array payload invariant at iteration k ≤ slabSize n_max of the slab-demotion loop.
- other_slabs (p : ℕ) : p < gm₀ 0 - 1 → p ≠ gm₀ (gmSlabTopIdx b) → ∀ u < SuccinctBucket.slabSize n_max, arr (p * SuccinctBucket.slabSize n_max + u) = arr₀ (p * SuccinctBucket.slabSize n_max + u)
- rem_del (u : ℕ) : u < SuccinctBucket.slabSize n_max - k → arr (gm₀ (gmSlabTopIdx b) * SuccinctBucket.slabSize n_max + u) = arr₀ (gm₀ (gmSlabTopIdx b) * SuccinctBucket.slabSize n_max + u)
- rem_last (u : ℕ) : u < SuccinctBucket.slabSize n_max - k → arr ((gm₀ 0 - 1) * SuccinctBucket.slabSize n_max + u) = arr₀ ((gm₀ 0 - 1) * SuccinctBucket.slabSize n_max + u)
- moved_last : gm₀ (gmSlabTopIdx b) < gm₀ 0 - 1 → ∀ (u : ℕ), SuccinctBucket.slabSize n_max - k ≤ u → u < SuccinctBucket.slabSize n_max → arr (gm₀ (gmSlabTopIdx b) * SuccinctBucket.slabSize n_max + u) = arr₀ ((gm₀ 0 - 1) * SuccinctBucket.slabSize n_max + u)
- demoted_tail (r : ℕ) : r < k → arr (n_max - 1 - gm (gmTailPtrIdx n_max b r)) = arr₀ (gm₀ (gmSlabTopIdx b) * SuccinctBucket.slabSize n_max + (SuccinctBucket.slabSize n_max - 1 - r))
Full loop invariant for k ≤ slabSize n_max iterations of demoteStepProg starting from
s₀.
- b_lt : b < FeistelQuotient.numBuckets n_max
- k_le : k ≤ SuccinctBucket.slabSize n_max
- top_b_eq : gmAt base U V w₀ n_max h_space s.mem (gmSlabTopIdx b) = gmAt base U V w₀ n_max h_space s₀.mem (gmSlabTopIdx b)
- tail_other (b' : ℕ) : b' < FeistelQuotient.numBuckets n_max → b' ≠ b → ∀ r < gmAt base U V w₀ n_max h_space s₀.mem (gmRIdx b'), gmAt base U V w₀ n_max h_space s.mem (gmTailPtrIdx n_max b' r) = gmAt base U V w₀ n_max h_space s₀.mem (gmTailPtrIdx n_max b' r)
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).
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.
Pure entry invariant for demoteSlabProg.
Precondition for demoteSlabProg in Realizes.
Parameter-free precondition for demoteSlabGenProg.
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.