Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.BasicOps

Fibonacci Heap: Shared Primitives, Initialization, Queries, and Insertion #

This file proves the exact-Word-RAM specifications for:

Main definitions #

Main results #

References #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.owns_arr_addr {n base k idx : ℕ} (hk : k < 8) (hidx : idx < n) :
base ≤ base + k * n + idx ∧ base + k * n + idx < base + space n
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.owns_cons_addr {n base d : ℕ} (hd : d ≤ n) :
base ≤ base + 8 * n + d ∧ base + 8 * n + d < base + space n
theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.out_of_footprint (n base : ℕ) {a : ℕ} (ha : a < base ∨ base + space n ≤ a) :
a < base ∨ base + 9 * n + 1 ≤ a

An address outside the heap block [base, base + space n) lies below base or at least base + 9 * n + 1.

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) :
let ltProp := x.regs kuReg < x.regs kvReg ∨ x.regs kuReg = x.regs kvReg ∧ x.regs uReg < x.regs vReg; have bval := if ltProp then 1 else 0; WordRAM.ExecWithin w (prioLTFlag uReg kuReg vReg kvReg flagReg) x (x.set flagReg bval) 6

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_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.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) :
∃ (x₁ : WordRAM.Data rFib), WordRAM.ExecWithin w allocSpan x x₁ 12 ∧ x₁.mem = x.mem ∧ x₁.regs baseReg = base ∧ x₁.regs frontierReg = base + space n ∧ ∀ (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.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) :
∃ (y : WordRAM.Data rFib) (t : ℕ), WordRAM.ExecWithin w getKeyCode x y t ∧ code.decode (IndexedMinPQ.Op.getKey v) y.regs = some (s v) ∧ FibInv n K_max w base s y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ t + potential y ≤ 7 + potential x
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