Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.SoftHeap.ExtractMin

Minimum-Extraction Specification for Word-RAM Soft Heaps #

Proves shExtractMin_spec: extracting the item at the minimum-ckey root returns an SHExtractResult with origKey ≤ popKey ≤ ckey' for all surviving entries, preserves SHInv and pool framing, removes the extracted item up to multiset permutation, and satisfies memoryCost + totalPhi h.rankThreshold roots' ≤ totalPhi h.rankThreshold roots + 250 independently of h.rankThreshold.

Main results #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.SoftHeap.shExtractMin_spec {w ic₀ nc₀ maxItems maxNodes fuel : ℕ} {h : SHHandle} {roots : List SHTree} {created : ℕ → ℕ} {s : Memory.State} (hinv : SHInv w ic₀ nc₀ maxItems maxNodes h roots created s) (hfuel_ge : shFuelBound h.rankThreshold maxItems ≤ fuel) (hf_fit : WordRAM.Fits w fuel) :
(Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s (shExtractMin (h, fuel))) ∧ shExtractMinSafe w (h, fuel) s ∧ have res := (Memory.spec 0).clientResult s (shExtractMin (h, fuel)); have h' := res.handle; have found := res.found; have val := res.val; have popKey := res.key; have s' := (Memory.spec 0).clientState s (shExtractMin (h, fuel)); h'.itemBase = h.itemBase ∧ h'.nodeBase = h.nodeBase ∧ h'.itemCount = h.itemCount ∧ 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 = [] → found = 0 ∧ val = 0 ∧ popKey = 0 ∧ h' = h ∧ s' = s ∧ WordRAM.Realization.memoryCost (shExtractMin (h, fuel)) s = 0) ∧ (roots ≠ [] → found = 1 ∧ ∃ (it₀ : SHItem) (roots' : List SHTree), (it₀, popKey) ∈ forestEntries roots ∧ it₀.val = val ∧ it₀.origKey ≤ popKey ∧ (∀ p ∈ forestEntries roots, popKey ≤ p.2) ∧ SHInv w ic₀ nc₀ maxItems maxNodes h' roots' created s' ∧ (it₀ :: forestItems roots').Perm (forestItems roots) ∧ (∀ p ∈ forestEntries roots', ∃ (c₀ : ℕ), (p.1, c₀) ∈ forestEntries roots ∧ c₀ ≤ p.2) ∧ ↑(WordRAM.Realization.memoryCost (shExtractMin (h, fuel)) s) + totalPhi h.rankThreshold roots' ≤ totalPhi h.rankThreshold roots + 250)

Full specification of shExtractMin: extracts a minimum-key item (when non-empty), maintains SHInv and pool framing, preserves item membership up to removal of the popped item, never decreases any surviving entry's ckey, and spends O(1) amortized memory operations (+ 250).