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:
- Root scattering (
scatterRootCode_exec): each collision step isPlacing.collidefollowed by a link, which the machine performs asLinksAs; the final store into an empty slot isPlacing.place. The result isConsolidated, and the step count satisfiest + 50 * slotTrees'.length ≤ 63 + 50 * slotTrees.length. - Minimum extraction (
extractMinCode_exec):FibRawInv.detachsplits the heap atz = minRoot - 1(which agrees withIndexedMinPQ.findMin). The two scatter loops are driven byDetached.scatterChildren,Scattering.unmark/stepandDetached.scatterRoots, the slot scan byDetached.gatheringandGathering.take, andDetached.finishrebuildsFibRawInv. The scan covers only0 .. maxDeg, at most2 * Nat.log 2 (IndexedMinPQ.dom s).card + 2slots, sot + potential y ≤ 410 * (Nat.log 2 (IndexedMinPQ.dom s).card + 1) + potential x.
Main results #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.scatterRootCode_exec: amortized root scattering, asConsolidated.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.extractMinCode_exec:O(log |dom s| + 1)amortizedextractMinspecification in the current number of stored elements.
References #
Root scattering (scatterBody_wp and scatterRootCode_exec) #
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.