Fibonacci-heap extractMin over a record of named cells #
extractMin n removes the minimum root z and consolidates
Fredman and Tarjan Cormen et al., Section 19.2:
scatterList … truewalksz's children along their sibling list, makes each an unmarked root, andscatters it into the degree tablecons. Scattering links the tree with the table's tree of equal degree (link,linkAs) until it reaches an empty slot.scatterList … falsedoes the same for the other roots, walking the root list fromz's right neighbour.gatherscans the table up to the largest degree placed, moving each tree to a new root list withaddRoot, and empties the table.
The largest degree placed is a program value, returned by scatter and threaded through the
loops, so the record layout is the same as for the other operations.
The lemmas here only evaluate the programs: each wp_* lemma reads and writes cells, and cites
the forest mathematics of Consolidation.lean for what the phase does to the forest and the
table (LinksAs.linked, Placing.place, Placing.collide, Scattering.unmark,
Scattering.step, Gathering.take, FibRawInv.detach, Detached.finish). The loop lemmas are
inductions on the loops' fuel and counters.
Each link costs 14 operations and removes a tree; each scattered root costs at most 9 more;
each table slot costs at most 13. With credit = 24 per root, the roots' credits pay for
their scattering, and the amortized cost is at most 92 * (log₂ m + 1) on a queue of m
handles (extractCharge), by the Fibonacci degree bound.
The module adapts Renfei Zhou's native formalization (WordRAM/FibonacciHeap, its
Program.lean and Consolidate.lean) to the record level: his extraction and consolidation
programs (extractMinCode, the scattering and gathering loops) and their forest and table
reasoning become the programs and loop lemmas here, and his table invariant SlotInv and its
lemmas are reused unchanged.
Main definitions #
linkAs,link,scatter,scatterList,gather,extractMin: record programs.extractCharge: the amortized charge92 * (Nat.log 2 m + 1).
Main results #
wp_link,wp_scatter,wp_scatterList,wp_gather: linking and the three phases.wp_extractMin:extractMinimplementsIndexedMinPQ.stepwith amortized costextractCharge.
References #
Programs #
Make root x the newest child of root u.
Link the roots a and b of equal degree: the one that precedes becomes the parent of the
other. Returns the new root.
Place root u in the consolidation table: while the slot of its degree holds a root, empty
the slot, link the two roots and continue with the new root. Returns the largest degree placed,
at least md. fuel bounds the number of links.
The amortized charge of extractMin on a queue with m handles.
Making x the newest child of u evaluates to LinksAs in at most nine operations.
Linking two roots of equal degree evaluates, in at most eleven operations, to Linked:
the one that precedes becomes the parent.
Scattering one root. Placing a tree into the table consolidates its nodes and the
table's. Each link costs 14 operations and removes a tree, so the cost is at most 3 plus 14
per tree removed.
Scattering a list of roots. Walking the trees rest along their roots' right pointers
(each first made an unmarked root if prep) and scattering each consolidates them with the
table. Apart from links, each root costs 4 operations, or 9 with prep.
Gathering the table. Scanning the slots d, …, md moves every tree of the table to the
root list, leaving the table empty, in at most 13 operations per slot.
Extracting the minimum. extractMin n implements IndexedMinPQ.step on .extractMin,
preserves the invariant, and costs at most extractCharge of the queue's size, amortized.