Documentation

Complexity.Algorithms.WordRAM.PriorityQueue.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.

Instances For
    @[reducible, inline]

    Persistent register holding handle-universe size n.

    Instances For
      @[reducible, inline]

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

      Instances For
        @[reducible, inline]

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

        Instances For
          @[reducible, inline]

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

          Instances For
            @[reducible, inline]

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

            Instances For
              @[reducible, inline]

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

              Instances For
                @[reducible, inline]

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

                Instances For
                  @[reducible, inline]

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

                  Instances For
                    @[reducible, inline]

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

                    Instances For
                      @[reducible, inline]

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

                      Instances For
                        @[reducible, inline]

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

                        Instances For
                          @[reducible, inline]

                          Persistent constant register 0.

                          Instances For
                            @[reducible, inline]

                            Persistent constant register 1.

                            Instances For
                              @[reducible, inline]

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

                              Instances For
                                @[reducible, inline]

                                Persistent root-list length counter (numRoots).

                                Instances For
                                  @[reducible, inline]

                                  Persistent marked-node counter (numMarked).

                                  Instances For
                                    @[reducible, inline]

                                    Persistent live-element count (sz).

                                    Instances For
                                      @[reducible, inline]

                                      Caller high tag bit (≠ 0 selects extractMin).

                                      Instances For
                                        @[reducible, inline]

                                        Caller middle tag bit.

                                        Instances For
                                          @[reducible, inline]

                                          Caller low tag bit.

                                          Instances For
                                            @[reducible, inline]

                                            Caller handle argument register (v.val).

                                            Instances For
                                              @[reducible, inline]

                                              Caller key argument register (k).

                                              Instances For
                                                @[reducible, inline]

                                                Output flag register (output = outFlag).

                                                Instances For
                                                  @[reducible, inline]

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

                                                  Instances For
                                                    @[reducible, inline]

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

                                                    Instances For
                                                      @[reducible, inline]

                                                      Scratch pointer register for generic SubroutineCode.zeroFillCode.

                                                      Instances For
                                                        @[reducible, inline]

                                                        Scratch zero register for generic SubroutineCode.zeroFillCode.

                                                        Instances For
                                                          @[reducible, inline]

                                                          Scratch one register for generic SubroutineCode.zeroFillCode.

                                                          Instances For
                                                            @[reducible, inline]

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

                                                            Instances For
                                                              @[reducible, inline]

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

                                                              Instances For
                                                                @[reducible, inline]

                                                                Outer loop counter (rem) in extractMin Phase A.

                                                                Instances For
                                                                  @[reducible, inline]

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

                                                                  Instances For
                                                                    @[reducible, inline]

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

                                                                    Instances For
                                                                      @[reducible, inline]

                                                                      Maximum degree tracker (maxDeg / limit) in extractMin.

                                                                      Instances For
                                                                        @[reducible, inline]

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

                                                                        Instances For
                                                                          @[reducible, inline]

                                                                          Inner helper scratch register 0 (addresses).

                                                                          Instances For
                                                                            @[reducible, inline]

                                                                            Inner helper scratch register 1.

                                                                            Instances For
                                                                              @[reducible, inline]

                                                                              Inner helper scratch register 2.

                                                                              Instances For
                                                                                @[reducible, inline]

                                                                                Inner helper scratch register 3.

                                                                                Instances For
                                                                                  @[reducible, inline]

                                                                                  Inner helper scratch register 4.

                                                                                  Instances For
                                                                                    @[reducible, inline]

                                                                                    Inner helper scratch register 5.

                                                                                    Instances For
                                                                                      @[reducible, inline]

                                                                                      Inner helper scratch register 6.

                                                                                      Instances For

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

                                                                                        Instances For

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

                                                                                          Instances For

                                                                                            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.

                                                                                            Instances For

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

                                                                                              Instances For

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

                                                                                                Instances For

                                                                                                  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.

                                                                                                  Instances For

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

                                                                                                    Instances For

                                                                                                      getKey v: loads outFlag ← inHeap[argV] and, if present, outK ← key[argV].

                                                                                                      Instances For

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

                                                                                                        Instances For

                                                                                                          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.

                                                                                                          Instances For

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

                                                                                                            Instances For

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

                                                                                                              Instances For

                                                                                                                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.

                                                                                                                Instances For

                                                                                                                  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.

                                                                                                                  Instances For

                                                                                                                    Unified dispatcher over 1-bit tags (tag2, tag1, tag0).

                                                                                                                    Instances For

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

                                                                                                                      Instances For

                                                                                                                        Concrete state projection, representation invariant, and amortized bounds #

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

                                                                                                                        Instances For

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

                                                                                                                          Instances For

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

                                                                                                                            Instances For
                                                                                                                              @[reducible, inline]

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

                                                                                                                              Instances For
                                                                                                                                @[reducible, inline]

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

                                                                                                                                Instances For

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

                                                                                                                                  Instances For

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

                                                                                                                                    Instances For

                                                                                                                                      Instruction bound for isEmpty (including dispatch).

                                                                                                                                      Instances For

                                                                                                                                        Instruction bound for getKey (including dispatch).

                                                                                                                                        Instances For

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

                                                                                                                                          Instances For

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

                                                                                                                                            Instances For

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

                                                                                                                                              Instances For

                                                                                                                                                Per-operation amortized instruction charge for FibonacciHeap.

                                                                                                                                                Instances For

                                                                                                                                                  Exact-ALU step rules, footprint framing, and RawState.ofData update lemmas #

                                                                                                                                                  theorem Cslib.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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 }
                                                                                                                                                  theorem Cslib.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.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.Algorithms.WordRAM.PriorityQueue.FibonacciHeap.FibInv.supported {n K_max w base : ℕ} {s : Lean.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'