The Fibonacci heap as an amortized refinement over memory #
The five operations of Basic.lean, DecreaseKey.lean and ExtractMin.lean implement the
indexed min-priority queue indexedMinPQSpec n K over the heap's record (refinement), with
amortized charges O(1) for every operation but extractMin, which is charged
O(log m) on a queue of m handles (amortized). The potential is
credit * (numRoots + 2 * numMarked) record operations.
Placing the record in memory at a base address (layout) and composing with
Record.refinement gives the heap over Memory.spec w (memRefinement). The potentials stack
across the composition (Refinement.Amortized.comp): every memory operation is one record
operation, so the charges are the same in memory units (mem_amortized).
The heap reads and writes only its 9 n + 5 cells (footprint). It is the record's framed
structure (Record.framed) with the heap's programs on top (Memory.Framed.comp), so it joins
products with other structures in one memory (Memory.Framed.prod), and its potential, read
through the record, is local to its footprint (potential_local). allocator allocates the
record in zeroed cells, which hold the empty queue (framed_alloc), as a Memory.Allocator;
its cost certificate is amortized_allocator.
Main definitions #
methods: the record programs of the five operations.charge: the amortized charges1,2,43,104andextractCharge.refinement: the heap over its record.layout: the record at9 n + 5consecutive cells from a base address.memRefinement: the heap over memory.footprint,framed: the heap as a framed structure over memory.allocator: allocation of an empty heap, as aMemory.Allocator.
Main results #
wp_methods: every operation meets its specification, invariant and amortized charge.amortized,mem_amortized,framed_amortized: the amortized costs over the record and over memory.framed_footprint,framed_room: the framed heap's footprint isfootprint, with no room.potential_local: the potential reads only the footprint.framed_alloc: zeroed cells hold the empty heap.amortized_allocator: the allocated heap's charges, with no potential once allocated.
The heap's operations as record programs.
The amortized charge of each operation, in record operations.
Every operation meets IndexedMinPQ.step, preserves the invariant, and costs at most its
charge, amortized.
The Fibonacci heap over its record.
Amortized costs over the record: one unit per record operation, with potential
credit * (numRoots + 2 * numMarked).
In memory #
The record at 9 n + 5 consecutive cells from base: the eight arrays, the table, and the
four scalars.
The Fibonacci heap over memory, at base address base.
Amortized costs over memory. The potentials stack across the composition: every memory unit is one record operation.
A framed structure in memory #
The heap's cells: 9 n + 5 consecutive addresses from base.
The heap's record at base as a framed structure over memory.
The Fibonacci heap as a framed structure over memory: the heap's programs over its record,
framed by the record's footprint, so it composes with other structures in one memory
(Memory.Framed.prod).
The framed heap's footprint is its 9 n + 5 cells.
The framed heap reserves no room beyond its footprint.
The framed heap's potential reads only its footprint, as Memory.Framed.amortized_prod
needs.
The framed heap's amortized costs are those of mem_amortized.
Allocation #
The all-zero record is the empty heap.
Allocation of an empty heap: 9 n + 5 zeroed cells at the frontier, all arrays at once.
The heap at the old frontier holds the empty queue.
Allocating the heap's record: 9 n + 5 zeroed cells at the frontier, the count sz last.
Allocating an empty heap: its record in 9 n + 5 zeroed cells at the frontier, with the
heap's programs on top.
The allocated heap is empty.
The allocated heap's costs: the charges of charge in memory units, with no potential
once allocated.