Documentation

CslibFrontier.Algorithms.Lean.Dijkstra.Native.Fibonacci

Native Fibonacci-heap Dijkstra from the existing framed memory client #

Dijkstra.Native.Fibonacci.run is realized by instantiating the shared Dijkstra.Native.NativeMethods and Dijkstra.Native.NativeAllocator interfaces with the 2-word HeapLayout record (word_enc_structure layoutWords), FibonacciHeap.framed, and the native Fibonacci-heap update, extraction, and dirty-reservation certificates.

The original amortized potential pays for memory operations; the native code separately charges arithmetic, argument copies, loop control and initialization. Flat exports retain the original graph input and word envelope, include their real prefix and halt, and preserve the full final memory.

Main definitions #

Main results #

References #

Runtime layout of an allocated indexed Fibonacci heap: vertex capacity capacity and base address base of its 9 * capacity + 5 contiguous cells.

  • capacity : ℕ

    Maximum number of handles n.

  • base : ℕ

    Base address of the heap's storage block.

@[reducible, inline]

The tuple word encoding of the fields of layoutWords.

Static validity predicate for a runtime Fibonacci-heap handle e at word width w, vertex capacity n, and key bound K.

  • capacity_eq : e.capacity = n

    Handle capacity matches n.

  • fits_n : WordRAM.Fits w n

    Vertex capacity n fits in w bits.

  • fits_K : WordRAM.Fits w K

    Key bound K fits in w bits.

  • fits_window : WordRAM.Fits w (e.base + (9 * n + 5))

    End of the 9 * n + 5 cell block fits in w bits.

Fibonacci-heap instance of Dijkstra.Native.NativeMethods over the 2-word HeapLayout register encoding.

Dirty-reservation adapter connecting Memory.allocDirty (9 * n + 5) to nativeMethods.

One native emitter realizes the original Fibonacci-heap Dijkstra memory client. Its domain retains the unchanged graph encoding and word envelope. Arithmetic, argument delivery, dirty allocation and early-exit loop control are included in the uniform instruction factor.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.Fibonacci.exists_program_state :
∃ (r : ℕ) (C : ℕ) (pc : ℕ) (prog : WordRAM.Program WordRAM.Basis.exact r) (frontier : Fin r), ∀ (G : Dijkstra.ListInstance) (w : ℕ), WordRAM.Fits w (8 * (G.n + G.m + 2) * (G.maxWeight + 2)) → ∃ (y : WordRAM.Data r) (steps : ℕ), WordRAM.Runs w prog (WordRAM.State.init G.encode) { pc := pc, data := y } steps ∧ WordRAM.step w prog { pc := pc, data := y } = WordRAM.Outcome.halt 0 ∧ WordRAM.Realization.memoryState frontier y = (DataStructure.Memory.spec w).clientState (DataStructure.Memory.State.init G.encode) run ∧ steps + 1 ≤ C * (G.m + min G.n (G.m + 1) * (Nat.log 2 G.n + 1)) ∧ ∀ (v : Fin G.n), y.mem (G.outAddr v) = WordRAM.Dijkstra.encodeDist (G.dist G.source v)

One flat exact-basis program, chosen before all graphs and widths, computes every distance within the sharper reachable-vertex Fibonacci bound. Its actual prefix, memory client and halt are charged, and its entire final memory/frontier is the original memory client's final state. As in the statement specification, placing the raw graph words in Data.init is uncharged.