Insertion Specification for Word-RAM Soft Heaps #
Proves shInsert_spec: inserting (val, origKey) into a valid soft heap preserves SHInv,
updates root links and suffix minima, frames writes within InSHPool, preserves surviving entry
keys up to non-decreasing ckey, and satisfies
memoryCost + totalPhi h.rankThreshold roots' ≤ totalPhi h.rankThreshold roots + (240 * h.rankThreshold + 520).
Main results #
Cslib.DataStructure.PriorityQueue.WordRAM.SoftHeap.shInsert_spec: full correctness, permutation, key-monotonicity, framing, andO(h.rankThreshold)amortized memory-cost specification forshInsert.
theorem Cslib.DataStructure.PriorityQueue.WordRAM.SoftHeap.shInsert_spec {w ic₀ nc₀ maxItems maxNodes val origKey fuel : ℕ} {h : SHHandle} {roots : List SHTree} {created : ℕ → ℕ} {s : Memory.State} (hinv : SHInv w ic₀ nc₀ maxItems maxNodes h roots created s) (hcap : h.itemCount < maxItems) (he_fit : WordRAM.Fits w val) (hk_fit : WordRAM.Fits w origKey) (hfuel_ge : shFuelBound h.rankThreshold maxItems ≤ fuel) (hf_fit : WordRAM.Fits w fuel) :
have d := (h, val, origKey, fuel);
(Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s (shInsert d)) ∧ shInsertSafe w d s ∧ have h' := (Memory.spec 0).clientResult s (shInsert d);
have s' := (Memory.spec 0).clientState s (shInsert d);
h'.itemBase = h.itemBase ∧ h'.nodeBase = h.nodeBase ∧ h'.itemCount = h.itemCount + 1 ∧ h.nodeCount < h'.nodeCount ∧ h'.rankThreshold = h.rankThreshold ∧ s'.frontier = s.frontier ∧ (∀ (a : ℕ), s'.mem a ≠ s.mem a → InSHPool ic₀ nc₀ maxItems maxNodes h a) ∧ ∃ (roots' : List SHTree) (created' : ℕ → ℕ),
SHInv w ic₀ nc₀ maxItems maxNodes h' roots' created' s' ∧ (forestItems roots').Perm
({ id := h.itemCount + 1, val := val, origKey := origKey } :: forestItems roots) ∧ (∀ p ∈ forestEntries roots',
p.1 = { id := h.itemCount + 1, val := val, origKey := origKey } ∧ origKey ≤ p.2 ∨ ∃ (c₀ : ℕ), (p.1, c₀) ∈ forestEntries roots ∧ c₀ ≤ p.2) ∧ ↑(WordRAM.Realization.memoryCost (shInsert d) s) + totalPhi h.rankThreshold roots' ≤ totalPhi h.rankThreshold roots + (240 * ↑h.rankThreshold + 520)
Insert (val, origKey) into the soft heap, maintaining SHInv, reporting entry keys and
permutation of items, framing all writes inside InSHPool, and paying O(h.rankThreshold + 1)
amortized memory cost (≤ +(240 * h.rankThreshold + 520) potential slack).