Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.Cut

Fibonacci Heap: decreaseKey and Cascading Cuts #

This file proves the exact-Word-RAM specification decreaseKeyCode_exec (O(1) amortized time under potential = 80 * (numRoots + 2 * numMarked)). The proofs step the machine code; the forest reasoning is that of the record heap (Cslib.DataStructure.PriorityQueue.FibonacciHeap, DecreaseKey.lean), applied to the machine state read as RawState.ofData n base x:

Main definitions #

Main results #

References #

Local framing and proof-only helpers #

evalCascGuard specification #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.evalCascGuard_exec {n base w : ℕ} {x : WordRAM.Data rFib} (hb : WordRAM.Data.Bounded w x) (hbr : BaseRegs n base x) {cur : Fin n} (hz_reg : x.regs zReg = ↑cur) :
have st := RawState.ofData n base x; have gval := if st.par cur ≠ 0 ∧ st.mark cur ≠ 0 then 1 else 0; ∃ (y : WordRAM.Data rFib), WordRAM.ExecWithin w evalCascGuard x y 8 ∧ BaseRegs n base y ∧ RawState.ofData n base y = st ∧ y.mem = x.mem ∧ y.regs iterCur = gval ∧ ∀ (r : Fin rFib), r ≠ s0 → r ≠ s1 → r ≠ s2 → r ≠ iterCur → y.regs r = x.regs r

evalCascGuard sets iterCur ← 1 iff par[cur] ≠ 0 ∧ mark[cur] ≠ 0, and 0 otherwise, in at most 8 instructions while preserving BaseRegs, RawState.ofData, and all registers other than s0, s1, s2, iterCur.

cutNodeCode machine execution #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.cutNodeCode_raw {n base w : ℕ} {x : WordRAM.Data rFib} (hb : WordRAM.Data.Bounded w x) (hbr : BaseRegs n base x) {cur p m : Fin n} {rtail : List (Fin n)} (hz_reg : x.regs zReg = ↑cur) (hp_reg : x.regs pReg = ↑p) (hdp_pos : 1 ≤ (RawState.ofData n base x).deg p) (hdp_le : (RawState.ofData n base x).deg p ≤ n) (hdp2 : 2 ≤ (RawState.ofData n base x).deg p → ∃ (h : Fin n) (tail : List (Fin n)), (RawState.ofData n base x).child p = ↑h + 1 ∧ IsCircList (RawState.ofData n base x).left (RawState.ofData n base x).right (h :: tail) ∧ cur ∈ h :: tail ∧ 2 ≤ (h :: tail).length ∧ ∀ u ∈ h :: tail, (RawState.ofData n base x).par u = ↑p + 1) (hmin : (RawState.ofData n base x).minRoot = ↑m + 1) (hcirc_r : IsCircList (RawState.ofData n base x).left (RawState.ofData n base x).right (m :: rtail)) (hroots_par0 : ∀ u ∈ m :: rtail, (RawState.ofData n base x).par u = 0) (hpar_cur : (RawState.ofData n base x).par cur = ↑p + 1) (hin_cur : (RawState.ofData n base x).inHeap cur ≠ 0) (hmk_cur : (RawState.ofData n base x).mark cur ≤ 1) (hnm : (RawState.ofData n base x).numMarked = markedCount (RawState.ofData n base x)) (hnr_le : (RawState.ofData n base x).numRoots + 1 ≤ n) :
∃ (y : WordRAM.Data rFib), WordRAM.ExecWithin w cutNodeCode x y 36 ∧ BaseRegs n base y ∧ WordRAM.Modifies { base := base, length := space n }.footprint x.mem y.mem ∧ (∀ (r : Fin rFib), r ≠ s0 → r ≠ s1 → r ≠ s2 → r ≠ s3 → r ≠ s4 → r ≠ numMarkedReg → r ≠ numRootsReg → y.regs r = x.regs r) ∧ (((RawState.ofData n base x).mark cur ≠ 0 → potential y + unitCredit = potential x) ∧ ((RawState.ofData n base x).mark cur = 0 → potential y = potential x + unitCredit)) ∧ FibonacciHeap.CutsNode (RawState.ofData n base x) cur p m rtail (RawState.ofData n base y)

Raw machine specification of cutNodeCode: cuts cur (zReg) from p (pReg) and splices cur after m (minRootReg = m.val + 1) in at most 36 instructions. Its effect is CutsNode, as for the record program cut: the machine state after the cut is cutState, and cutsNode_cutState does the list reasoning.

Final minRootReg update tail and decreaseKeyCode_exec #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.decreaseKeyCode_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 : (∃ (k₀ : ℕ), s v = some k₀ ∧ k ≤ k₀) ∧ k ≤ K_max) (hv_reg : x.regs argV = ↑v) (hk_reg : x.regs argK = k) :
∃ (y : WordRAM.Data rFib) (t : ℕ), WordRAM.ExecWithin w decreaseKeyCode 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 ≤ 330 + potential x

decreaseKeyCode lowers key[v] to k ≤ k₀ (s v = some k₀), performs cascading cuts when parent heap order is violated, updates minRootReg, and restores FibInv in amortized time t + potential y ≤ 330 + potential x. The forest reasoning is the record heap's: the machine writes the new key first, so the forest is read with the old keys ({ st with key := st₀.key }) as Cascading, each cut is CutsNode.cascading, the cascade ends with Cascading.clear_root or Cascading.mark, and Cascading.lowerRootKey or FibRawInv.lowerKey_noCut stores the key.