Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.Consolidate

Degree-indexed root consolidation and extractMin for a Fibonacci heap #

This file proves the correctness, memory-safety, and O(log |dom s| + 1) amortized instruction bound of scatterRootCode and extractMinCode in the current number of stored elements sz = (IndexedMinPQ.dom s).card Fredman and Tarjan Cormen et al., Section 19.2.

The proofs step the machine code; the forest reasoning is that of the record heap (Cslib.DataStructure.PriorityQueue.FibonacciHeap, Consolidation.lean), applied to the machine state read as RawState.ofData n base x:

Main results #

References #

Root scattering (scatterBody_wp and scatterRootCode_exec) #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.scatterRootCode_exec {n sz base w maxDeg₀ : ℕ} {x : WordRAM.Data rFib} {T₀ : FHTree n} {slotTrees₀ : List (FHTree n)} {z : Fin n} (hb : WordRAM.Data.Bounded w x) (hbr : BaseRegs n base x) (hP : FibonacciHeap.Placing sz z (RawState.ofData n base x) T₀ slotTrees₀ maxDeg₀) (hx_ic : x.regs iterCur = ↑T₀.root) (hx_md : x.regs maxDegReg = maxDeg₀) :
∃ (y : WordRAM.Data rFib) (slotTrees' : List (FHTree n)) (maxDeg' : ℕ) (t : ℕ), WordRAM.ExecWithin w scatterRootCode x y t ∧ t + slotCredit * slotTrees'.length ≤ 63 + slotCredit * slotTrees₀.length ∧ WordRAM.Data.Bounded w y ∧ BaseRegs n base y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ (∀ (r : Fin rFib), ↑r < 33 → y.regs r = x.regs r) ∧ y.regs maxDegReg = maxDeg' ∧ FibonacciHeap.Consolidated sz (RawState.ofData n base x) (RawState.ofData n base y) (forestNodes (T₀ :: slotTrees₀)) slotTrees' maxDeg'

scatterRootCode places the valid root tree T₀ (iterCur = T₀.root.val) into the consolidation table, linking equal-degree roots and updating maxDegReg: the result is Consolidated, in t + 50 * slotTrees'.length ≤ 63 + 50 * slotTrees₀.length instructions, and all registers < 33 are preserved.

Consolidation scatter loops (childScatterLoop and rootScatterLoop) #

Phase B slot gathering (gatherSlotsLoop_exec) #

extractMinCode correctness and O(log n) amortized bound #

extractMinCode implements .extractMin on FibInv within 410 * (Nat.log 2 (IndexedMinPQ.dom s).card + 1) amortized instructions (t + potential y ≤ 410 * (Nat.log 2 (IndexedMinPQ.dom s).card + 1) + potential x). The forest reasoning is that of the record heap: FibRawInv.detach splits the heap at its minimum root, the three loops produce Consolidated, Consolidated and Gathered, and Detached.finish reassembles FibRawInv.