Fibonacci Heap: Shared Primitives, Initialization, Queries, and Insertion #
This file proves the exact-Word-RAM specifications for:
- shared primitives (
prioLTFlag,insertIntoNonEmptyList,addRootAndUpdateMin) reused acrossinsert,decreaseKey, andextractMin; allocSpan,initSetup, andincCur(O(1)fresh initialization on zeroed memory);isEmptyCode,getKeyCode, andinsertCode.
Main definitions #
- Shared code fragments are defined in
CslibFrontier/DataStructure/PriorityQueue/WordRAM/FibonacciHeap/Program.leanand verified here againstFibInv.
Main results #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.prioLTFlag_exec,insertIntoNonEmptyList_exec,addRootAndUpdateMin_exec: shared list and priority primitives.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.allocSpan_exec,initSetup_exec,incCur_eval: initialization specifications forStateTransitionImpl.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.isEmptyCode_exec,getKeyCode_exec,insertCode_exec:O(1)query and amortized insertion specifications.
References #
Shared primitives: prioLTFlag, insertIntoNonEmptyList, addRootAndUpdateMin #
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.prioLTFlag_exec {n base w : ℕ} {x : WordRAM.Data rFib} (hbr : BaseRegs n base x) (uReg kuReg vReg kvReg flagReg : Fin rFib) :
prioLTFlag uReg kuReg vReg kvReg flagReg sets flagReg ← 1 iff (u, ku) strictly precedes
(v, kv) under IndexedMinPQ.PrioLT, and 0 otherwise, within 6 instructions.
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.prioLTFlag_preserves {r uReg kuReg vReg kvReg flagReg : Fin rFib} (hf : r ≠ flagReg) :
WordRAM.Code.Preserves r (prioLTFlag uReg kuReg vReg kvReg flagReg)
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.insertIntoNonEmptyList_preserves {r hReg uReg : Fin rFib} (h0 : r ≠ s0) (h2 : r ≠ s2) :
WordRAM.Code.Preserves r (insertIntoNonEmptyList hReg uReg)
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.insertIntoNonEmptyList_exec {n base w : ℕ} {x : WordRAM.Data rFib} (hb : WordRAM.Data.Bounded w x) (hbr : BaseRegs n base x) {hReg uReg : Fin rFib} (hh0 : hReg ≠ s0) (hh2 : hReg ≠ s2) (hu0 : uReg ≠ s0) (hu2 : uReg ≠ s2) {h u r : Fin n} (hh_val : x.regs hReg = ↑h) (hu_val : x.regs uReg = ↑u) (hr : (RawState.ofData n base x).right h = ↑r) :
∃ (y : WordRAM.Data rFib),
WordRAM.ExecWithin w (insertIntoNonEmptyList hReg uReg) x y 10 ∧ BaseRegs n base y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ RawState.ofData n base y = have __src := RawState.ofData n base x;
{ key := __src.key, par := __src.par, child := __src.child,
left := Function.update (Function.update (RawState.ofData n base x).left u ↑h) r ↑u,
right := Function.update (Function.update (RawState.ofData n base x).right u ↑r) h ↑u, deg := __src.deg,
mark := __src.mark, inHeap := __src.inHeap, cons := __src.cons, minRoot := __src.minRoot,
numRoots := __src.numRoots, numMarked := __src.numMarked, sz := __src.sz }
insertIntoNonEmptyList hReg uReg splices u immediately after h, whose right neighbour is
r, in 10 instructions, modifying only left[u], left[r], right[u], right[h] and scratch
registers s0, s2.
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.addRootAndUpdateMin_exec {n base w : ℕ} {x : WordRAM.Data rFib} (hb : WordRAM.Data.Bounded w x) (hbr : BaseRegs n base x) {uReg : Fin rFib} (hu_sc : uReg ≠ s0 ∧ uReg ≠ s1 ∧ uReg ≠ s2 ∧ uReg ≠ s3 ∧ uReg ≠ s4 ∧ uReg ≠ s5 ∧ uReg ≠ minRootReg ∧ uReg ≠ numRootsReg) {u : Fin n} (hu_val : x.regs uReg = ↑u) (hroot :
(RawState.ofData n base x).minRoot = 0 ∨ ∃ (m : Fin n) (rtail : List (Fin n)),
(RawState.ofData n base x).minRoot = ↑m + 1 ∧ IsCircList (RawState.ofData n base x).left (RawState.ofData n base x).right (m :: rtail)) (hnr : (RawState.ofData n base x).numRoots + 1 ≤ n) :
∃ (y : WordRAM.Data rFib),
WordRAM.ExecWithin w (addRootAndUpdateMin uReg) x y 28 ∧ BaseRegs n base y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ FibonacciHeap.AddsRoot (RawState.ofData n base x) u (RawState.ofData n base y)
addRootAndUpdateMin uReg adds root u to the root list in at most 28 instructions: its
effect on the heap is AddsRoot, the same as the record program addRoot.
allocSpan, initSetup, and incCur #
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.incCur_eval {w : ℕ} {x : WordRAM.Data rFib} (hone : x.regs oneReg = 1) (hfit : WordRAM.Fits w (x.regs curReg + 1)) :
WordRAM.Op.eval w (WordRAM.Op.exactBin WordRAM.BinOp.add curReg curReg oneReg) x = some (x.set curReg (x.regs curReg + 1))
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.allocSpan_exec {n w base : ℕ} (hS : WordRAM.Fits w (base + space n)) {x : WordRAM.Data rFib} (_hx : WordRAM.Data.Bounded w x) (hfr : x.regs frontierReg = base) (hpar : ∀ (j : Fin 1), x.regs (![nReg] j) = ![n] j) :
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.initSetup_exec {n K_max w base : ℕ} {x₁ : WordRAM.Data rFib} (hx₁ : WordRAM.Data.Bounded w x₁) (hb₁ : x₁.regs baseReg = base) (hfr₁ : x₁.regs frontierReg = base + space n) (hpar₁ : ∀ (j : Fin 1), x₁.regs (![nReg] j) = ![n] j) (hz : ∀ a ∈ { base := base, length := space n }.footprint, x₁.mem a = 0) :
∃ (y : WordRAM.Data rFib),
WordRAM.ExecWithin w initSetup x₁ y 14 ∧ y.regs frontierReg = base + space n ∧ FibInv n K_max w base (IndexedMinPQ.empty n) y ∧ potential y ≤ 0 ∧ WordRAM.Modifies { base := base, length := space n }.footprint x₁.mem y.mem
isEmptyCode, getKeyCode, and insertCode #
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.isEmptyCode_exec {n K_max w base : ℕ} {s : IndexedMinPQ.State n} {x : WordRAM.Data rFib} (hinv : FibInv n K_max w base s x) :
∃ (y : WordRAM.Data rFib) (t : ℕ),
WordRAM.ExecWithin w isEmptyCode x y t ∧ code.decode IndexedMinPQ.Op.isEmpty y.regs = some (decide (IndexedMinPQ.dom s = ∅)) ∧ FibInv n K_max w base s y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ t + potential y ≤ 3 + potential x
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.getKeyCode_exec {n K_max w base : ℕ} {s : IndexedMinPQ.State n} {x : WordRAM.Data rFib} (v : Fin n) (hinv : FibInv n K_max w base s x) (hv_reg : x.regs argV = ↑v) :
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.insertCode_exec {n K_max w base : ℕ} {s : IndexedMinPQ.State n} {x : WordRAM.Data rFib} (v : Fin n) (k : ℕ) (hinv : FibInv n K_max w base s x) (hval : s v = none ∧ k ≤ K_max) (hv_reg : x.regs argV = ↑v) (hk_reg : x.regs argK = k) :
∃ (y : WordRAM.Data rFib) (t : ℕ),
WordRAM.ExecWithin w insertCode x y t ∧ FibInv n K_max w base (Function.update s v (some k)) y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ t + potential y ≤ 121 + potential x