Documentation

CslibFrontier.Algorithms.Lean.Dijkstra.Native.Binary

Native binary-heap Dijkstra from the memory client #

Dijkstra.Memory.run is realized by instantiating the shared Dijkstra.Native.NativeMethods and Dijkstra.Native.NativeAllocator interfaces with BinaryHeap.Native.HeapLayout (layoutWords), BinaryHeap.Memory.framed, and the native binary-heap update, extraction, and dirty-allocation certificates.

All register layouts, emitted code and clock factors precede runtime graphs, widths and memory. The original word envelope is unchanged. Arithmetic, copies, source initialization and control are charged; the flat endpoint retains the entire final memory and frontier of Dijkstra.Memory.run.

Main definitions #

Main results #

The instruction factor is existential. No claim preserves the old handwritten implementation's literal coefficients, and no Fibonacci-heap native endpoint is asserted here.

References #

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

  • capacity_eq : e.fst = n

    Handle capacity matches n.

  • valid : (⋯ ▸ e.snd).Valid w K

    Underlying layout is valid at width w and key bound K.

Binary-heap instance of Dijkstra.Native.NativeMethods over the 4-word HeapLayout register encoding.

Dirty-allocation adapter connecting BinaryHeap.Memory.allocLayout to nativeMethods.

One fixed native emitter realizes the original allocated binary-heap Dijkstra memory program. The domain retains the original graph input and word-size envelope; native arithmetic, argument delivery, initialization and control are included in its constant instruction factor.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.Binary.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) Memory.run ∧ steps + 1 ≤ C * (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 every graph and word size, computes the shortest-path distances. Its charged prefix, body and halt take log-linear time, and the full final memory/frontier is exactly the state of the original memory program.