Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.Program

Fibonacci Heap: Static-Array Word-RAM Program and State Representation #

This file defines the uniform Basis.exact Word-RAM implementation (code : PQCode .exact rFib) of a static-array Fibonacci heap on n handles (space n = 9 * n + 1 words at [base, base + 9 * n + 1)), together with its concrete state projection (RawState.ofData), representation invariant (FibInv), potential function (potential), per-operation amortized time bounds, and memory/register framing lemmas.

Memory layout ([base, base + 9 * n + 1)) #

Main definitions #

Main results #

References #

Register file (rFib = 42) and footprint size #

@[reducible, inline]

Total register count of the standalone/subroutine Fibonacci heap machine.

@[reducible, inline]

Persistent register holding handle-universe size n.

@[reducible, inline]

Persistent frontier register (base before allocSpan, base + space n after).

@[reducible, inline]

Persistent base address of key[0..n-1] (base).

@[reducible, inline]

Persistent base address of par[0..n-1] (base + n).

@[reducible, inline]

Persistent base address of child[0..n-1] (base + 2 * n).

@[reducible, inline]

Persistent base address of left[0..n-1] (base + 3 * n).

@[reducible, inline]

Persistent base address of right[0..n-1] (base + 4 * n).

@[reducible, inline]

Persistent base address of deg[0..n-1] (base + 5 * n).

@[reducible, inline]

Persistent base address of mark[0..n-1] (base + 6 * n).

@[reducible, inline]

Persistent base address of inHeap[0..n-1] (base + 7 * n).

@[reducible, inline]

Persistent base address of cons[0..n] (base + 8 * n).

@[reducible, inline]

Persistent constant register 0.

@[reducible, inline]

Persistent constant register 1.

@[reducible, inline]

Persistent nullable minimum-root pointer (0 = empty, m + 1 = some m).

@[reducible, inline]

Persistent root-list length counter (numRoots).

@[reducible, inline]

Persistent marked-node counter (numMarked).

@[reducible, inline]

Persistent live-element count (sz).

@[reducible, inline]

Caller high tag bit (≠ 0 selects extractMin).

@[reducible, inline]

Caller middle tag bit.

@[reducible, inline]

Caller low tag bit.

@[reducible, inline]

Caller handle argument register (v.val).

@[reducible, inline]

Caller key argument register (k).

@[reducible, inline]

Output flag register (output = outFlag).

@[reducible, inline]

Output handle register (u.val for non-empty extractMin).

@[reducible, inline]

Output key register (k for present getKey and non-empty extractMin).

@[reducible, inline]

Scratch pointer register for generic SubroutineCode.zeroFillCode.

@[reducible, inline]

Scratch zero register for generic SubroutineCode.zeroFillCode.

@[reducible, inline]

Scratch one register for generic SubroutineCode.zeroFillCode.

@[reducible, inline]

Outer scratch register: extracted vertex z or cascading-cut target cur.

@[reducible, inline]

Outer scratch register: parent p in decreaseKey or rStart in extractMin.

@[reducible, inline]

Outer loop counter (rem) in extractMin Phase A.

@[reducible, inline]

Outer current-node register (iterCur) or cascading-cut loop guard.

@[reducible, inline]

Outer saved-next-node register (iterNxt) in extractMin Phase A.

@[reducible, inline]

Maximum degree tracker (maxDeg / limit) in extractMin.

@[reducible, inline]

Degree index (d / curD) in scatterRootCode and extractMin Phase B.

@[reducible, inline]

Inner helper scratch register 0 (addresses).

@[reducible, inline]

Inner helper scratch register 1.

@[reducible, inline]

Inner helper scratch register 2.

@[reducible, inline]

Inner helper scratch register 3.

@[reducible, inline]

Inner helper scratch register 4.

@[reducible, inline]

Inner helper scratch register 5.

@[reducible, inline]

Inner helper scratch register 6.

Persistent registers are 0..16 (false); caller/scratch registers are 17..41 (true).

Static memory footprint on n handles: 9 * n + 1 words.

Structured Basis.exact Fibonacci-heap subprograms #

Advance frontierReg from base to base + 9 * n + 1 using only + nReg and + #1, avoiding constants > 1 so small word widths (w ≥ 1 when n = 0) never fault.

Initialize array-base pointers and zero scalar heap counters (O(1) steps).

Set flagReg ← 1 if (uReg, kuReg) strictly precedes (vReg, kvReg) lexicographically (ku < kv ∨ (ku = kv ∧ u < v)), and flagReg ← 0 otherwise. Writes only flagReg.

Splice fresh vertex uReg immediately after hReg in a non-empty circular doubly-linked list (left[u] := h; left[right[h]] := u; right[u] := right[h]; right[h] := u). Writes only s0, s2.

Insert root uReg into the root circular list, update minRootReg under IndexedMinPQ.PrioLT, and increment numRootsReg. Writes only s0..s5, minRootReg, numRootsReg.

insert v k: initializes singleton root argV with key argK, splices into root list, and increments szReg.

Cut child zReg from parent pReg (par[zReg] = pReg + 1, minRootReg ≥ 1), splicing zReg into the root circular list, clearing par[zReg] and mark[zReg] (updating numMarkedReg if needed), and incrementing numRootsReg. Writes only s0..s4, numMarkedReg, numRootsReg.

Evaluate cascading-cut guard iterCur ← 1 iff par[zReg] ≠ 0 ∧ mark[zReg] ≠ 0, else 0.

decreaseKey v k: lowers key[argV] ← argK, cuts argV and runs cascading cuts if parent order under IndexedMinPQ.PrioLT is violated, and updates minRootReg.

Scatter root iterCur into cons, linking equal-degree roots under IndexedMinPQ.PrioLT until reaching an empty slot and updating maxDegReg. Writes only s0..s6, curDReg, maxDegReg.

extractMin: returns 0 when empty, or removes z = minRootReg - 1, scatters z's children and the numRoots - 1 remaining roots into cons, and scans 0 .. maxDeg to rebuild the root circular list and minRootReg while restoring cons = 0 in O(log n) steps.

Uniform PQCode .exact rFib bundle for the static-array Fibonacci heap.

Concrete state projection, representation invariant, and amortized bounds #

Project Data rFib at (n, base) to a logical RawState n.

Persistent base-address and constant registers 0..12 hold their initialized values.

Full Word-RAM representation invariant for FibonacciHeap at (n, K_max, w, base).

@[reducible, inline]

Amortized credit per root (80 instructions; marked nodes carry 2 * unitCredit = 160).

@[reducible, inline]

Internal consolidation-slot credit (50 instructions per occupied degree slot).

Concrete integer potential 80 * (numRoots + 2 * numMarked).

Fresh-initialization instruction bound (allocSpan 12 + initSetup 14 = 26).

Instruction bound for isEmpty (including dispatch).

Instruction bound for getKey (including dispatch).

Amortized instruction bound for insert (including dispatch and +80 root potential).

Amortized instruction bound for decreaseKey (including dispatch and cascading cuts).

Amortized instruction bound for extractMin (O(log n + 1)).

Per-operation amortized instruction charge for FibonacciHeap, charging tExt (IndexedMinPQ.dom s).card on .extractMin in terms of the current number of stored elements (IndexedMinPQ.dom s).card.

The current number of stored elements (IndexedMinPQ.dom s).card is at most n, so charge n s .extractMin ≤ tExt n.

Footprint framing and RawState.ofData update lemmas #

A value at most base + 9 * n, such as an address in one of the nine arrays, fits a word.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.BaseRegs.set_non_base {n base : ℕ} {x : WordRAM.Data rFib} (hbr : BaseRegs n base x) {d : Fin rFib} (hd : 13 ≤ ↑d) (v : ℕ) :
BaseRegs n base (x.set d v)
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.BaseRegs.set_iff {n base : ℕ} {x : WordRAM.Data rFib} {d : Fin rFib} (hd : 13 ≤ ↑d) (v : ℕ) :
BaseRegs n base (x.set d v) ↔ BaseRegs n base x

Setting a register outside the base registers 0..12 keeps BaseRegs.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_set_minRoot {n base : ℕ} (x : WordRAM.Data rFib) (v : ℕ) :
RawState.ofData n base (x.set minRootReg v) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := v, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_set_numRoots {n base : ℕ} (x : WordRAM.Data rFib) (v : ℕ) :
RawState.ofData n base (x.set numRootsReg v) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := v, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_set_numMarked {n base : ℕ} (x : WordRAM.Data rFib) (v : ℕ) :
RawState.ofData n base (x.set numMarkedReg v) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := v, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_set_sz {n base : ℕ} (x : WordRAM.Data rFib) (v : ℕ) :
RawState.ofData n base (x.set szReg v) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := v }

The ofData_write_* lemmas: a write into one of the nine arrays updates that field of RawState.ofData and leaves the other eight arrays alone, because the arrays occupy disjoint address ranges. Each proof unfolds RawState.ofData, clears the eight untouched fields with Function.update_of_ne (omega), and splits once on the written index for the updated field.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_key {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + ↑v) val) = have __src := RawState.ofData n base x; { key := Function.update (RawState.ofData n base x).key v val, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_par {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := Function.update (RawState.ofData n base x).par v val, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_child {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 2 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := Function.update (RawState.ofData n base x).child v val, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_left {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 3 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := Function.update (RawState.ofData n base x).left v val, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_right {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 4 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := Function.update (RawState.ofData n base x).right v val, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_deg {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 5 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := Function.update (RawState.ofData n base x).deg v val, mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_mark {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 6 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := Function.update (RawState.ofData n base x).mark v val, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_inHeap {n base : ℕ} (x : WordRAM.Data rFib) (v : Fin n) (val : ℕ) :
RawState.ofData n base (x.write (base + 7 * n + ↑v) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := Function.update (RawState.ofData n base x).inHeap v val, cons := __src.cons, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_write_cons {n base d : ℕ} (hd : d ≤ n) (x : WordRAM.Data rFib) (val : ℕ) :
RawState.ofData n base (x.write (base + 8 * n + d) val) = have __src := RawState.ofData n base x; { key := __src.key, par := __src.par, child := __src.child, left := __src.left, right := __src.right, deg := __src.deg, mark := __src.mark, inHeap := __src.inHeap, cons := Function.update (RawState.ofData n base x).cons d val, minRoot := __src.minRoot, numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.ofData_supported {n base : ℕ} {x x' : WordRAM.Data rFib} (hreg : ∀ (i : Fin rFib), inputReg i = false → x'.regs i = x.regs i) (hmem : ∀ a ∈ { base := base, length := space n }.footprint, x'.mem a = x.mem a) :
RawState.ofData n base x' = RawState.ofData n base x
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.FibInv.supported {n K_max w base : ℕ} {s : IndexedMinPQ.State n} {x x' : WordRAM.Data rFib} (hreg : ∀ (i : Fin rFib), inputReg i = false → x'.regs i = x.regs i) (hmem : ∀ a ∈ { base := base, length := space n }.footprint, x'.mem a = x.mem a) (hb' : WordRAM.Data.Bounded w x') (h : FibInv n K_max w base s x) :
FibInv n K_max w base s x'

Setting a caller or scratch register keeps the potential.