Documentation

CslibFrontier.Algorithms.Lean.Dijkstra.Native.Export

Flat programs from native Dijkstra memory clients #

The binary-heap and Fibonacci-heap endpoints both realize a memory program that reads the adjacency-list input words, and both export it through the standard initialized-program exporter. exists_program_state is that export: a uniform realization, the program's admissibility and distance outputs, and a bound c G on its memory cost give one flat program whose halting run computes the distances in O(c G + 1) steps and ends in the program's final memory. Each endpoint supplies only its cost bound.

Main results #

theorem Cslib.Algorithms.Lean.Dijkstra.Native.exists_program_state {p : DataStructure.Memory.Prog Unit} (c : Dijkstra.ListInstance → ℕ) (hp : WordRAM.Realization.Realizes WordRAM.Basis.exact (fun (x : Unit) => p) WordRAM.Realization.WordEncoding.encode WordRAM.Realization.WordEncoding.encode (fun (w : ℕ) (x : Unit) (s : DataStructure.Memory.State) => ∃ (G : Dijkstra.ListInstance), s = DataStructure.Memory.State.init G.encode ∧ WordRAM.Fits w (8 * (G.n + G.m + 2) * (G.maxWeight + 2))) fun (x : Unit) (x_1 : DataStructure.Memory.State) => 0) (hspec : ∀ (G : Dijkstra.ListInstance) {w : ℕ}, WordRAM.Fits w (8 * (G.n + G.m + 2) * (G.maxWeight + 2)) → (DataStructure.Memory.spec w).ValidHistory (DataStructure.Memory.State.init G.encode) ((DataStructure.Memory.spec w).clientHistory (DataStructure.Memory.State.init G.encode) p) ∧ (∀ (v : Fin G.n), ((DataStructure.Memory.spec w).clientState (DataStructure.Memory.State.init G.encode) p).mem (G.outAddr v) = WordRAM.Dijkstra.encodeDist (G.dist G.source v)) ∧ (DataStructure.Memory.spec w).totalCost DataStructure.Memory.charge (DataStructure.Memory.State.init G.encode) ((DataStructure.Memory.spec w).clientHistory (DataStructure.Memory.State.init G.encode) p) ≤ c G) :
∃ (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) p ∧ steps + 1 ≤ C * (c G + 1) ∧ ∀ (v : Fin G.n), y.mem (G.outAddr v) = WordRAM.Dijkstra.encodeDist (G.dist G.source v)

The flat export of a native Dijkstra memory client. Let p be uniformly realized on the input words of every graph at every word size that holds 8 (n + m + 2) (W + 2), and on those inputs be admissible, leave the encoded distances at the output cells and cost at most c G memory units. Then one flat exact-basis program, chosen before every graph and word size, halts within C (c G + 1) steps with the encoded distances at the output cells, its final memory and frontier being those of p. The prefix installing the input, the body and the halt are charged.