Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctTailOps

Tail Pool Allocation and Compaction Operations #

This module defines the pure GlobalMeta updates (gmAppendTail, gmRemoveTail) and the corresponding branch-free Memory.Prog operations (appendTailItemProg, removeLastTailItemProg, realized to Word-RAM code via realize) that allocate and compact tail items while preserving TailBijection and SlabBijection.

Main definitions #

Main results #

Section 1: Pure gmAppendTail and gmRemoveTail updates #

Pure GlobalMeta update appending one tail item to bucket b: assigns physical tail offset t_new = gm 1 to descriptor d_new = b * tailCapPerBucket n_max + gm (gmRIdx b) and increments gm (gmRIdx b) and gm 1.

Pure GlobalMeta update removing the last tail item r_del = gm (gmRIdx b) - 1 of bucket b by relocating the last physical tail t_last = gm 1 - 1 into t_del = gm (gmTailPtrIdx n_max b r_del) and decrementing gm (gmRIdx b) and gm 1. When t_del = t_last, the pointer updates are idempotent.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.mul_add_div_mod_of_lt {b c r : ℕ} (hr : r < c) :
(b * c + r) / c = b ∧ (b * c + r) % c = r

Quotient and remainder of a flat two-dimensional index b * c + r when r < c.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.flat_descriptor_inj {n_max b₁ r₁ b₂ r₂ : ℕ} (hr₁ : r₁ < SuccinctBucket.tailCapPerBucket n_max) (hr₂ : r₂ < SuccinctBucket.tailCapPerBucket n_max) (heq : b₁ * SuccinctBucket.tailCapPerBucket n_max + r₁ = b₂ * SuccinctBucket.tailCapPerBucket n_max + r₂) :
b₁ = b₂ ∧ r₁ = r₂
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmAppendTail_preserves_nonTail {n_max : ℕ} (gm : ℕ → ℕ) {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr : gm (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) (ht : gm 1 < SuccinctBucket.maxTailItems n_max) :
gmAppendTail n_max gm b 0 = gm 0 ∧ gmAppendTail n_max gm b 1 = gm 1 + 1 ∧ gmAppendTail n_max gm b (gmRIdx b) = gm (gmRIdx b) + 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gmAppendTail n_max gm b (gmRIdx b') = gm (gmRIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, gmAppendTail n_max gm b (gmQIdx b') = gm (gmQIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, gmAppendTail n_max gm b (gmSlabTopIdx b') = gm (gmSlabTopIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, ∀ s < SuccinctBucket.dirSlabsPerBucket n_max, gmAppendTail n_max gm b (gmSlabDirIdx n_max b' s) = gm (gmSlabDirIdx n_max b' s)) ∧ ∀ (idx : ℕ), gmSlabMetaBase n_max ≤ idx → gmAppendTail n_max gm b idx = gm idx
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.tailBijection_gmAppendTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr : gm (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) (ht : gm 1 < SuccinctBucket.maxTailItems n_max) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) :
TailBijection n_max (gmAppendTail n_max gm b) (fun (b' : ℕ) => gmAppendTail n_max gm b (gmRIdx b')) (gmAppendTail n_max gm b 1)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slabBijection_gmAppendTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr : gm (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) (ht : gm 1 < SuccinctBucket.maxTailItems n_max) (hslab : SlabBijection n_max gm (fun (b' : ℕ) => gm (gmQIdx b')) (gm 0)) :
(∀ (b' s : ℕ), slabPtrOf n_max (gmAppendTail n_max gm b) b' s = slabPtrOf n_max gm b' s) ∧ SlabBijection n_max (gmAppendTail n_max gm b) (fun (b' : ℕ) => gmAppendTail n_max gm b (gmQIdx b')) (gmAppendTail n_max gm b 0)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slotOf_gmAppendTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (hr : gm (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) (ht : gm 1 < SuccinctBucket.maxTailItems 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)) :
slotOf n_max (gmAppendTail n_max gm b) b (gm (gmQIdx b) * SuccinctBucket.slabSize n_max + gm (gmRIdx b)) = n_max - 1 - gm 1 ∧ ∀ b' < FeistelQuotient.numBuckets n_max, ∀ j < bCount n_max gm b', slotOf n_max (gmAppendTail n_max gm b) b' j = slotOf n_max gm b' j
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmRemoveTail_preserves_nonTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr_pos : 1 ≤ gm (gmRIdx b)) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) :
gmRemoveTail n_max gm b 0 = gm 0 ∧ gmRemoveTail n_max gm b 1 = gm 1 - 1 ∧ gmRemoveTail n_max gm b (gmRIdx b) = gm (gmRIdx b) - 1 ∧ (∀ b' < FeistelQuotient.numBuckets n_max, b' ≠ b → gmRemoveTail n_max gm b (gmRIdx b') = gm (gmRIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, gmRemoveTail n_max gm b (gmQIdx b') = gm (gmQIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, gmRemoveTail n_max gm b (gmSlabTopIdx b') = gm (gmSlabTopIdx b')) ∧ (∀ b' < FeistelQuotient.numBuckets n_max, ∀ s < SuccinctBucket.dirSlabsPerBucket n_max, gmRemoveTail n_max gm b (gmSlabDirIdx n_max b' s) = gm (gmSlabDirIdx n_max b' s)) ∧ ∀ (idx : ℕ), gmSlabMetaBase n_max ≤ idx → gmRemoveTail n_max gm b idx = gm idx
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmRemoveTail_tail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr_pos : 1 ≤ gm (gmRIdx b)) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) :
(∀ d < SuccinctBucket.maxTailItems n_max, gmRemoveTail n_max gm b (gmTailPtrFlatIdx n_max d) = if d = gm (gmTailOwnerIdx n_max (gm 1 - 1)) then gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1)) else gm (gmTailPtrFlatIdx n_max d)) ∧ ∀ t < SuccinctBucket.maxTailItems n_max, gmRemoveTail n_max gm b (gmTailOwnerIdx n_max t) = if t = gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1)) then gm (gmTailOwnerIdx n_max (gm 1 - 1)) else gm (gmTailOwnerIdx n_max t)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.tailBijection_gmRemoveTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr_pos : 1 ≤ gm (gmRIdx b)) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) :
TailBijection n_max (gmRemoveTail n_max gm b) (fun (b' : ℕ) => gmRemoveTail n_max gm b (gmRIdx b')) (gmRemoveTail n_max gm b 1)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.slabBijection_gmRemoveTail {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr_pos : 1 ≤ gm (gmRIdx b)) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) (hslab : SlabBijection n_max gm (fun (b' : ℕ) => gm (gmQIdx b')) (gm 0)) :
(∀ (b' s : ℕ), slabPtrOf n_max (gmRemoveTail n_max gm b) b' s = slabPtrOf n_max gm b' s) ∧ SlabBijection n_max (gmRemoveTail n_max gm b) (fun (b' : ℕ) => gmRemoveTail n_max gm b (gmQIdx b')) (gmRemoveTail n_max gm b 0)
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.update_slotOf_gmRemoveTail {α : Type u_1} (arr : ℕ → α) {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hb : b < FeistelQuotient.numBuckets n_max) (hr_pos : 1 ≤ gm (gmRIdx b)) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) (hslab : SlabBijection n_max gm (fun (b' : ℕ) => gm (gmQIdx b')) (gm 0)) (htot : gm 0 * SuccinctBucket.slabSize n_max + gm 1 ≤ n_max) :
(∀ b' < FeistelQuotient.numBuckets n_max, ∀ j < bCount n_max (gmRemoveTail n_max gm b) b', Function.update arr (n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1))) (arr (n_max - 1 - (gm 1 - 1))) (slotOf n_max (gmRemoveTail n_max gm b) b' j) = arr (slotOf n_max gm b' j)) ∧ ∀ g < n_max - gm 1, Function.update arr (n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1))) (arr (n_max - 1 - (gm 1 - 1))) g = arr g

Section 2: Memory.Prog tail allocation and compaction operations (realize) #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.ntails_lt_maxTailItems_of_r_lt {n_max : ℕ} {gm : ℕ → ℕ} {b : ℕ} (hb : b < FeistelQuotient.numBuckets n_max) (hr_lt : gm (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) (htail : TailBijection n_max gm (fun (b' : ℕ) => gm (gmRIdx b')) (gm 1)) :
@[reducible, inline]

Base address d.2.1 in a parameter-free (DictParams, (base, b)) bucket call.

@[reducible, inline]

Bucket index d.2.2 in a parameter-free (DictParams, (base, b)) bucket call.

Parameter-free Memory.Prog operation appending one tail item to bucket b = tailCallBucket d at base = tailCallBase d.

Memory.Prog operation appending one tail item to bucket b = d.2 at base = d.1 (0 < bucketBits n_max) and returning the newly allocated physical tail offset t_new = gm 1.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.appendTailItemProg_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) (htail : TailBijection 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 (gmRIdx b)) (gmAt base U V w n_max h_space s.mem 1)) (hr_lt : gmAt base U V w n_max h_space s.mem (gmRIdx b) < SuccinctBucket.tailCapPerBucket n_max) :
have s' := (Memory.spec 0).clientState s (appendTailItemProg U V w n_max h_space (base, b)); (Memory.spec 0).clientResult s (appendTailItemProg U V w n_max h_space (base, b)) = gmAt base U V w n_max h_space s.mem 1 ∧ 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 = gmAppendTail n_max (gmAt base U V w n_max h_space s.mem) b

Pure state effect and return value of appendTailItemProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.appendTailItemGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
AppendTailItemGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ AppendTailItemPre U V w₀ n_max h_space w d.1 d.2 s

Parameter-free Memory.Prog operation removing the last tail item of bucket b = tailCallBucket d at base = tailCallBase d.

Memory.Prog operation removing the last tail item of bucket b = d.2 at base = d.1 (0 < bucketBits n_max, 1 ≤ gm (gmRIdx b)), compacting the tail pool by moving the payload at physical slot (n_max - 1) - (gm 1 - 1) into (n_max - 1) - t_del and updating GlobalMeta via gmRemoveTail.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.removeLastTailItemProg_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) (htail : TailBijection 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 (gmRIdx b)) (gmAt base U V w n_max h_space s.mem 1)) (hr_pos : 1 ≤ gmAt base U V w n_max h_space s.mem (gmRIdx b)) :
have gm := gmAt base U V w n_max h_space s.mem; have s' := (Memory.spec 0).clientState s (removeLastTailItemProg U V w n_max h_space (base, b)); 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 (quotAt base U w n_max h_space s.mem) (n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1))) (quotAt base U w n_max h_space s.mem (n_max - 1 - (gm 1 - 1))) ∧ valAt base U V w n_max h_space s'.mem = Function.update (valAt base U V w n_max h_space s.mem) (n_max - 1 - gm (gmTailPtrIdx n_max b (gm (gmRIdx b) - 1))) (valAt base U V w n_max h_space s.mem (n_max - 1 - (gm 1 - 1))) ∧ 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

Pure state effect of removeLastTailItemProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.removeLastTailItemGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
RemoveLastTailItemGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ RemoveLastTailItemPre U V w₀ n_max h_space w d.1 d.2 s