Documentation

CslibFrontier.Algorithms.Lean.Dijkstra.Native.Domain

Shared reached-state reasoning for native Dijkstra clients #

These are the original binary consumer's abstract history, key-bound and scan/round facts, shared with the Fibonacci consumer. They use the existing indexed-queue specification and refinements, without assuming a heap representation or a zero potential. They certify source and domain transport, not native instruction bounds.

Main definitions #

Main results #

The original relaxation history supplies the reached insert or decrease-key precondition.

The suffix of the original adjacency scan after the first i edges.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.remainingEdges_cons {n K V : ℕ} (u : Fin n) (du b i : ℕ) (hi : i < b) :
remainingEdges u du b i = do relaxEdge u du i remainingEdges u du b (i + 1)

A nonempty scan suffix exposes its next relaxation and remaining suffix.

A valid scan suffix retains the refinement invariant and next suffix validity.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.scan_valid_remainingEdges {n K V : ℕ} {pq : DataStructure.PriorityQueue.IndexedMinPQ.State n} {dist : DataStructure.Dictionary.State n} {adj : DataStructure.AdjacencyList.State n} (u : Fin n) (du : ℕ) (hv : (spec n K V).ValidHistory (pq, dist, adj) ((spec n K V).clientHistory (pq, dist, adj) (scan u du))) :
(spec n K V).ValidHistory (pq, dist, adj) ((spec n K V).clientHistory (pq, dist, adj) (remainingEdges u du (adj u).length 0))

An admissible scan u du history supplies an admissible remainingEdges suffix from 0.

Every word-level round lowers the remaining-round counter, including the empty exit.

One original abstract extraction and scan, with its early-exit round counter.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.loop_eq_step {n K V : ℕ} (a : ℕ) (ha : a ≠ 0) :
loop a = do let b ← abstractLoopStep a loop b

A positive original loop exposes one complete round before its remainder.

An admissible indexed-queue step preserves the bound on every present key.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.composite_step_keys {n K V : ℕ} (s : (spec n K V).State) (o : (spec n K V).Op) (hv : (spec n K V).valid s o) (hb : ∀ (v : Fin n) (k : ℕ), s.1 v = some k → k ≤ K) (v : Fin n) (k : ℕ) :
((spec n K V).stepFn s o).1.1 v = some k → k ≤ K

A Dijkstra-interface step preserves the bound on every queued key.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.history_keys {n K V : ℕ} (s : (spec n K V).State) (os : List (spec n K V).Op) (hv : (spec n K V).ValidHistory s os) (hb : ∀ (v : Fin n) (k : ℕ), s.1 v = some k → k ≤ K) (v : Fin n) (k : ℕ) :
((spec n K V).run s os).1.1 v = some k → k ≤ K

An admissible Dijkstra history preserves the bound on every queued key.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.client_keys {n K V : ℕ} {α : Type} (s : (spec n K V).State) (p : (spec n K V).Client α) (hv : (spec n K V).ValidHistory s ((spec n K V).clientHistory s p)) (hb : ∀ (v : Fin n) (k : ℕ), s.1 v = some k → k ≤ K) (v : Fin n) (k : ℕ) :
((spec n K V).clientState s p).1 v = some k → k ≤ K

A valid Dijkstra client preserves the bound on every queued key.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.scan_while_safe {n K V w : ℕ} (M : DataStructure.Refinement (spec n K V) (DataStructure.Memory.spec w)) (u : Fin n) (du b : ℕ) (step : ℕ → DataStructure.Memory.Prog Unit) (safe : ℕ → ℕ → DataStructure.Memory.State → Prop) (heq : ∀ (i : ℕ), step i = DataStructure.link M.methods (relaxEdge u du i)) (hsafe : ∀ (i : ℕ) (s : (DataStructure.Memory.spec w).State), i < b → M.inv s → (spec n K V).ValidHistory (M.abs s) ((spec n K V).clientHistory (M.abs s) (relaxEdge u du i)) → safe w i s) (s : DataStructure.Memory.State) (hi : M.inv s) (hfit : WordRAM.Fits w b) (hv : (spec n K V).ValidHistory (M.abs s) ((spec n K V).clientHistory (M.abs s) (remainingEdges u du b 0))) (hm : (DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (WordRAM.Realization.boundedWhile (fun (b i : ℕ) => i < b) (fun (x : ℕ × ℕ) => do step x.2 pure (x.2 + 1)) b b 0))) :
WordRAM.Realization.whileSafe (fun (b i : ℕ) => i < b) (fun (x : ℕ × ℕ) => do step x.2 pure (x.2 + 1)) (fun (w : ℕ) (x : ℕ × ℕ) (s : DataStructure.Memory.State) => safe w x.2 s ∧ WordRAM.Fits w (x.2 + 1)) w b b 0 s

A refinement and the original remaining scan justify every reached native step domain. The proof excludes truncation by the actual increasing index, not by assuming a loop result.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.loop_while_safe {n K V w : ℕ} {ε : Type} (M : DataStructure.Refinement (spec n K V) (DataStructure.Memory.spec w)) (e : ε) (guard : ε → ℕ → Prop) [(e : ε) → DecidablePred (guard e)] (body : ε × ℕ → DataStructure.Memory.Prog ℕ) (safe : ℕ → ε × ℕ → DataStructure.Memory.State → Prop) (hguard : ∀ (a : ℕ), guard e a ↔ 0 < a) (heq : ∀ (a : ℕ), body (e, a) = DataStructure.link M.methods (abstractLoopStep a)) (hdown : ∀ (a : ℕ) (s : (DataStructure.Memory.spec 0).State), (DataStructure.Memory.spec 0).clientResult s (body (e, a)) ≤ a - 1) (hsafe : ∀ (a : ℕ) (s : (DataStructure.Memory.spec w).State), 0 < a → M.inv s → (∀ (v : Fin n) (k : ℕ), (M.abs s).1 v = some k → k ≤ K) → (spec n K V).ValidHistory (M.abs s) ((spec n K V).clientHistory (M.abs s) (abstractLoopStep a)) → safe w (e, a) s) (a₀ : ℕ) (s : DataStructure.Memory.State) (hi : M.inv s) (hk : ∀ (v : Fin n) (k : ℕ), (M.abs s).1 v = some k → k ≤ K) (hv : (spec n K V).ValidHistory (M.abs s) ((spec n K V).clientHistory (M.abs s) (loop a₀))) (hm : (DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (WordRAM.Realization.boundedWhile guard body e a₀ a₀))) :
WordRAM.Realization.whileSafe guard body safe w e a₀ a₀ s

The original remaining-round history and a strictly decreasing native counter justify a complete early-exit loop. The existing key invariant is retained through every abstract step.

Running an erased native extractMin on an admissible abstractLoopStep state either yields none or yields some (u.val, du) for some u : Fin n with du ≤ K and an admissible scan u du in the post-extraction state.

theorem Cslib.Algorithms.Lean.Dijkstra.Native.initial_loop_safe_insert {K V w f : ℕ} (G : Dijkstra.ListInstance) (hK : G.n * G.maxWeight ≤ K) (hV : G.n * G.maxWeight < V) (M : DataStructure.Refinement (spec G.n K V) (DataStructure.Memory.spec w)) (ins0 : DataStructure.Memory.Prog Unit) (hset : M.methods (Sum.inr (Sum.inl (DataStructure.Dictionary.Op.insert G.source 0))) = DataStructure.Memory.write (f + ↑G.source) 1) (hins : M.methods (Sum.inl (DataStructure.PriorityQueue.IndexedMinPQ.Op.insert G.source 0)) = ins0) (s : DataStructure.Memory.State) (hi : M.inv s) (habs : M.abs s = init G) :
have t := (DataStructure.Memory.spec 0).clientState { mem := Function.update s.mem (f + ↑G.source) 1, frontier := s.frontier } ins0; M.inv t ∧ (∀ (v : Fin G.n) (k : ℕ), (M.abs t).1 v = some k → k ≤ K) ∧ (spec G.n K V).ValidHistory (M.abs t) ((spec G.n K V).clientHistory (M.abs t) (loop G.n))

Installing the source distance word at f + G.source.val and executing the queue insertion ins0 leaves an admissible main loop with queued keys bounded by K.