Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.SoftHeap.Defill

Zipper Invariant and Specification for Soft-Heap defill #

Tracks the iterative defill cursor via a zipper (ZipFrame, ZipCurValid, ZipInv) and proves defill_spec: restoring non-leaf item-list size ≥ targetSize rank while maintaining SHTree.Valid, tree framing, key monotonicity, and memoryCost + t'.phi ≤ t₀.phi + 6.

Main definitions #

Main results #

Validity invariant for the active cursor subtree inside defill (allowing items.length of the cursor node itself to be temporarily below targetSize rt when non-leaf).

theorem Cslib.DataStructure.PriorityQueue.WordRAM.SoftHeap.defill_spec {rt w itemBase nodeBase fuel : ℕ} {t₀ : SHTree} {s : Memory.State} (h16 : WordRAM.Fits w 16) (hmem : Memory.WellFormed w s) (hval₀ : ZipCurValid rt 0 t₀) (hnd₀ : t₀.nodeIds.Nodup) (hid₀ : t₀.itemIds.Nodup) (hmem₀ : TreeMemRep rt itemBase nodeBase s.mem t₀) (hn_lt : ∀ id ∈ t₀.nodeIds, nodeBase + 12 * id + 11 < s.frontier) (hi_lt : ∀ it ∈ t₀.allItems, itemBase + 3 * it.id + 2 < s.frontier) (hdisj : ∀ id ∈ t₀.nodeIds, ∀ it ∈ t₀.allItems, ∀ j < 12, ∀ k < 3, nodeBase + 12 * id + j ≠ itemBase + 3 * it.id + k) (hf_fit : WordRAM.Fits w fuel) (hfuel : SHTree.phi rt t₀ + 5 ≤ 5 * ↑fuel) :
have d := ![itemBase, nodeBase, t₀.rootId, fuel]; (Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s (defill d)) ∧ defillSafe w d s ∧ have s' := (Memory.spec 0).clientState s (defill d); s'.frontier = s.frontier ∧ (∀ (a : ℕ), s'.mem a ≠ s.mem a → (∃ id ∈ t₀.nodeIds, ∃ j < 9, a = nodeBase + 12 * id + j) ∨ ∃ it ∈ t₀.allItems, a = itemBase + 3 * it.id + 2) ∧ ∃ (t' : SHTree), t'.rootId = t₀.rootId ∧ t'.rank = t₀.rank ∧ SHTree.Valid rt 0 t' ∧ popDeficit rt t' = 0 ∧ (t₀.items ≠ [] → t₀.ckey ≤ t'.ckey) ∧ t'.nodeIds.Nodup ∧ (∀ id ∈ t'.nodeIds, id ∈ t₀.nodeIds) ∧ (∀ id ∈ t₀.nodeIds, id ∉ t'.nodeIds → s'.mem (nodeBase + 12 * id + 4) = 0) ∧ (∀ (k : ℕ), SHTree.countRank k t' ≤ SHTree.countRank k t₀) ∧ t'.allItems.Perm t₀.allItems ∧ (∀ p ∈ t'.allEntries, ∃ (c₀ : ℕ), (p.1, c₀) ∈ t₀.allEntries ∧ c₀ ≤ p.2) ∧ TreeMemRep rt itemBase nodeBase s'.mem t' ∧ ↑(WordRAM.Realization.memoryCost (defill d) s) + SHTree.phi rt t' ≤ SHTree.phi rt t₀ + 6

Full specification of defill: starting from a root tree t₀ satisfying ZipCurValid 0 t₀, defill produces a valid refilled tree t' satisfying popDeficit rt t' = 0, modifies only cells inside t₀ (+0..+8 on t₀.nodeIds and +2 on t₀.allItems), zeroes head on deleted leaves, and spends memoryCost + t'.phi rt ≤ t₀.phi rt + 6.