Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Algo.dijkstra.dijkstra.Facts definitions

Definition
Algo_dijkstra_dijkstra_Facts

by lunjia · Oct 10, 2026 · Mathlib 0df444a (Lean v4.33.1)

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

Definitions and required structural lemmas from Algo.dijkstra.dijkstra.Facts. Source declarations are retained by compiler-reported ranges; imports are redirected to the corresponding definition bundles. This bundle contains no theorem stubs.

<!-- algo2lean-provenance-v0.1.4 -->

Algo2Lean provenance and reproduction. These definitions target Algo2Lean v0.1.4, using the compiler source at public commit 0f79d5e4242e6477531c9ee4410409f5b1c92f76, and Lean 4.33.1. The versioned compiler location is Algo2Lean v0.1.4. Compile all supplied .algo files and imports to reproduce the raw generated definitions. Release publication and exact website parity require their separately recorded checks; this metadata alone does not assert them. Prove2Me imports and declaration packaging are mechanically adapted, with original hashes, compiler-reported source ranges, and adaptations recorded in transplant provenance. Exact reproduction does not prove the compiler correct.

Definition code
import Definitions.Def_Algo_dijkstra_dijkstra_Generated

set_option autoImplicit true
set_option backward.isDefEq.respectTransparency false
set_option backward.defeqAttrib.useBackward true


-- Generated by Algo2Lean 0.1.4 https://github.com/lunjiah/algo2lean

-- Optional proof certificate; execution remains the generated Step relation.
namespace «Algo».«dijkstra».«dijkstra»

open Algo2LeanCore _root_.Algo2LeanGenerated

/-- Optional determinism evidence for the separately supplied interface code. -/
structure DependencyFacts (dependencies : Dependencies) where
  «PriorityQueue» : InterfaceFacts dependencies.«PriorityQueue».toInterfaceCode

namespace Algo2LeanGenerated

variable (dependencies : Dependencies)

local notation "Frame" => Frame dependencies
local notation "Stack" => Stack dependencies
local notation "Configuration" => Configuration dependencies
local notation "Transcript" => Transcript dependencies
local notation "Step" => Step dependencies
local notation "is__a2l_import_1_PriorityQueue" => is__a2l_import_1_PriorityQueue dependencies

private def next_scan_edges (h : Heap) (s : State_scan_edges) (stack : Stack) : Nat → Configuration
  | 1 => (Algo2LeanCore.resumeConfig h (Result.fn_scan_edges (s.t7)) stack)
  | 2 => (.active h (Frame.fn_scan_edges 1 { s with t7 := () }) stack)
  | 3 => if s.t8 then (.active h (Frame.fn_scan_edges 20 s) stack) else (.active h (Frame.fn_scan_edges 2 s) stack)
  | 4 => (.active h (Frame.fn_scan_edges 3 { s with t8 := (decide ((s.v4 ≠ none))) }) stack)
  | 5 => (.active h (Frame.fn_scan_edges 4 { s with v4 := ((field__a2l_import_0_Edge_next h ((s.v4).getD 0)).getD none) }) stack)
  | 6 => (.active (h.tick "improvements" 1) (Frame.fn_scan_edges 5 s) stack)
  | 7 => (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_push_or_decrease ((s.t12), s.t13, s.t14)) [] (fun value => match value with | .fn_PriorityQueue_push_or_decrease result => (Frame.fn_scan_edges 6 { s with t11 := result }) | _ => .invalid)) stack)
  | 8 => (.active h (Frame.fn_scan_edges 7 { s with t14 := s.v6 }) stack)
  | 9 => (.active h (Frame.fn_scan_edges 8 { s with t13 := s.v5 }) stack)
  | 10 => (.active h (Frame.fn_scan_edges 9 { s with t12 := s.t12 }) stack)
  | 11 => (.active h (Frame.fn_scan_edges 10 { s with t12 := s.v0 }) stack)
  | 12 => (.active (h.tick "queue_updates" 1) (Frame.fn_scan_edges 11 s) stack)
  | 13 => (.active (h.write s.v1 s.v5 s.v6) (Frame.fn_scan_edges 12 s) stack)
  | 14 => if s.t10 then (.active h (Frame.fn_scan_edges 13 s) stack) else (.active h (Frame.fn_scan_edges 5 s) stack)
  | 15 => (.active h (Frame.fn_scan_edges 14 { s with t10 := ((decide (((h.read s.v1 s.v5) < (0 : Int)))) || (decide ((s.v6 < (h.read s.v1 s.v5))))) }) stack)
  | 16 => (.active h (Frame.fn_scan_edges 15 { s with v6 := ((h.read s.v1 s.v3) + ((field__a2l_import_0_Edge_weight h ((s.v4).getD 0)).getD 0)) }) stack)
  | 17 => if s.t9 then (.active h (Frame.fn_scan_edges 16 s) stack) else (.active h (Frame.fn_scan_edges 5 s) stack)
  | 18 => (.active h (Frame.fn_scan_edges 17 { s with t9 := (decide (((h.read s.v2 s.v5) = (0 : Int)))) }) stack)
  | 19 => (.active h (Frame.fn_scan_edges 18 { s with v5 := ((field__a2l_import_0_Edge_target h ((s.v4).getD 0)).getD 0) }) stack)
  | 20 => (.active (h.tick "edges" 1) (Frame.fn_scan_edges 19 s) stack)
  | pc => .active h (.fn_scan_edges pc s) stack

private def next_dijkstra (h : Heap) (s : State_dijkstra) (stack : Stack) : Nat → Configuration
  | 1 => (Algo2LeanCore.resumeConfig h (Result.fn_dijkstra (s.t6)) stack)
  | 2 => (.active h (Frame.fn_dijkstra 1 { s with t6 := s.v3 }) stack)
  | 3 => if s.t7 then (.active h (Frame.fn_dijkstra 21 s) stack) else (.active h (Frame.fn_dijkstra 2 s) stack)
  | 4 => (.active h (Frame.fn_dijkstra 3 { s with t7 := (!s.t8) }) stack)
  | 5 => (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_is_empty (s.t9)) [] (fun value => match value with | .fn_PriorityQueue_is_empty result => (Frame.fn_dijkstra 4 { s with t8 := result }) | _ => .invalid)) stack)
  | 6 => (.active h (Frame.fn_dijkstra 5 { s with t9 := s.t9 }) stack)
  | 7 => (.active h (Frame.fn_dijkstra 6 { s with t9 := s.v2 }) stack)
  | 8 => (.active (h.tick "queue_empty_checks" 1) (Frame.fn_dijkstra 7 s) stack)
  | 9 => (.active h (Frame.fn_scan_edges 4 ({ v0 := s.t11, v1 := s.t12, v2 := s.t13, v3 := s.t14, v4 := s.t15 } : State_scan_edges)) ((fun value => match value with | .fn_scan_edges result => (Frame.fn_dijkstra 8 { s with t10 := result }) | _ => .invalid) :: stack))
  | 10 => (.active h (Frame.fn_dijkstra 9 { s with t15 := ((seq__a2l_import_0_Edge_optional.get h ((field__a2l_import_0_Graph_heads h (s.v0)).getD 0) s.v5).getD none) }) stack)
  | 11 => (.active h (Frame.fn_dijkstra 10 { s with t14 := s.v5 }) stack)
  | 12 => (.active h (Frame.fn_dijkstra 11 { s with t13 := s.v4 }) stack)
  | 13 => (.active h (Frame.fn_dijkstra 12 { s with t12 := s.v3 }) stack)
  | 14 => (.active h (Frame.fn_dijkstra 13 { s with t11 := s.v2 }) stack)
  | 15 => (.active (h.tick "settlements" 1) (Frame.fn_dijkstra 14 s) stack)
  | 16 => (.active (h.write s.v4 s.v5 (1 : Int)) (Frame.fn_dijkstra 15 s) stack)
  | 17 => (.active h (Frame.fn_dijkstra 16 { s with v5 := s.t16 }) stack)
  | 18 => (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_pop_min (s.t17)) [] (fun value => match value with | .fn_PriorityQueue_pop_min result => (Frame.fn_dijkstra 17 { s with t16 := result }) | _ => .invalid)) stack)
  | 19 => (.active h (Frame.fn_dijkstra 18 { s with t17 := s.t17 }) stack)
  | 20 => (.active h (Frame.fn_dijkstra 19 { s with t17 := s.v2 }) stack)
  | 21 => (.active (h.tick "queue_pops" 1) (Frame.fn_dijkstra 20 s) stack)
  | 22 => (.active (h.tick "queue_empty_checks" 1) (Frame.fn_dijkstra 7 s) stack)
  | 23 => (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_push_or_decrease ((s.t19), s.t20, s.t21)) [] (fun value => match value with | .fn_PriorityQueue_push_or_decrease result => (Frame.fn_dijkstra 22 { s with t18 := result }) | _ => .invalid)) stack)
  | 24 => (.active h (Frame.fn_dijkstra 23 { s with t21 := (0 : Int) }) stack)
  | 25 => (.active h (Frame.fn_dijkstra 24 { s with t20 := s.v1 }) stack)
  | 26 => (.active h (Frame.fn_dijkstra 25 { s with t19 := s.t19 }) stack)
  | 27 => (.active h (Frame.fn_dijkstra 26 { s with t19 := s.v2 }) stack)
  | 28 => (.active (h.tick "queue_updates" 1) (Frame.fn_dijkstra 27 s) stack)
  | 29 => (.active (h.write s.v3 s.v1 (0 : Int)) (Frame.fn_dijkstra 28 s) stack)
  | pc => .active h (.fn_dijkstra pc s) stack

/-- A total projection used only to certify uniqueness of actual transitions. -/
def next (facts : DependencyFacts dependencies) : Configuration → Configuration
  | .done h result => .done h result
  | .active h frame stack => match frame with
    | .invalid => .active h .invalid stack
    | .fn_scan_edges pc s => next_scan_edges dependencies h s stack pc
    | .fn_dijkstra pc s => next_dijkstra dependencies h s stack pc
    | .interface_PriorityQueue frame inner resume =>
      ModuleCall.config Frame.interface_PriorityQueue resume stack (facts.«PriorityQueue».next (.active h frame inner))

/-- Each generated rule agrees with the projection; guards remain in Step. -/
theorem step_next (facts : DependencyFacts dependencies) {before after : Configuration} (transition : Step before after) :
    next dependencies facts before = after := by
  cases transition with
  | scan_edges_pc1 h s stack => rfl
  | scan_edges_pc2 h s stack => rfl
  | scan_edges_pc3_true h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc3_false h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc4 h s stack => rfl
  | scan_edges_pc5 h s stack defined => rfl
  | scan_edges_pc6 h s stack => rfl
  | scan_edges_pc7 h s stack => rfl
  | scan_edges_pc8 h s stack => rfl
  | scan_edges_pc9 h s stack => rfl
  | scan_edges_pc10 h s stack defined => rfl
  | scan_edges_pc11 h s stack => rfl
  | scan_edges_pc12 h s stack => rfl
  | scan_edges_pc13 h s stack defined => rfl
  | scan_edges_pc14_true h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc14_false h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc15 h s stack defined => rfl
  | scan_edges_pc16 h s stack defined => rfl
  | scan_edges_pc17_true h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc17_false h s stack condition => simp [next, next_scan_edges, condition]
  | scan_edges_pc18 h s stack defined => rfl
  | scan_edges_pc19 h s stack defined => rfl
  | scan_edges_pc20 h s stack => rfl
  | dijkstra_pc1 h s stack defined => rfl
  | dijkstra_pc2 h s stack => rfl
  | dijkstra_pc3_true h s stack condition => simp [next, next_dijkstra, condition]
  | dijkstra_pc3_false h s stack condition => simp [next, next_dijkstra, condition]
  | dijkstra_pc4 h s stack => rfl
  | dijkstra_pc5 h s stack => rfl
  | dijkstra_pc6 h s stack defined => rfl
  | dijkstra_pc7 h s stack => rfl
  | dijkstra_pc8 h s stack => rfl
  | dijkstra_pc9 h s stack => rfl
  | dijkstra_pc10 h s stack defined => rfl
  | dijkstra_pc11 h s stack => rfl
  | dijkstra_pc12 h s stack => rfl
  | dijkstra_pc13 h s stack => rfl
  | dijkstra_pc14 h s stack => rfl
  | dijkstra_pc15 h s stack => rfl
  | dijkstra_pc16 h s stack defined => rfl
  | dijkstra_pc17 h s stack => rfl
  | dijkstra_pc18 h s stack => rfl
  | dijkstra_pc19 h s stack defined => rfl
  | dijkstra_pc20 h s stack => rfl
  | dijkstra_pc21 h s stack => rfl
  | dijkstra_pc22 h s stack => rfl
  | dijkstra_pc23 h s stack => rfl
  | dijkstra_pc24 h s stack => rfl
  | dijkstra_pc25 h s stack => rfl
  | dijkstra_pc26 h s stack defined => rfl
  | dijkstra_pc27 h s stack => rfl
  | dijkstra_pc28 h s stack => rfl
  | dijkstra_pc29 h s stack defined => rfl
  | interface_PriorityQueue h frame inner resume caller after transition =>
    exact congrArg (ModuleCall.config Frame.interface_PriorityQueue resume caller) (facts.«PriorityQueue».step_next transition)

/-- Imported determinism composes without reopening imported transition rules. -/
theorem deterministic (facts : DependencyFacts dependencies) : Deterministic Step := by
  intro before left right first second
  exact (step_next dependencies facts first).symm.trans (step_next dependencies facts second)

end Algo2LeanGenerated

end «Algo».«dijkstra».«dijkstra»

namespace Algo.«dijkstra».«dijkstra»

open Algo2LeanCore _root_.Algo2LeanGenerated Algo2LeanGenerated

variable (dependencies : Dependencies)

local notation "Frame" => Frame dependencies
local notation "Stack" => Stack dependencies
local notation "Configuration" => Configuration dependencies
local notation "Transcript" => Transcript dependencies
local notation "Step" => Step dependencies
local notation "is__a2l_import_1_PriorityQueue" => is__a2l_import_1_PriorityQueue dependencies

variable {dependencies}

theorem scan_edges.Run.eq_of_call (facts : DependencyFacts dependencies) {before after expectedHeap input output expected}
    (run : _root_.Algo.«dijkstra».«dijkstra».scan_edges.Run dependencies before input after output)
    (call : _root_.Algo.«dijkstra».«dijkstra».scan_edges.Call dependencies before input expectedHeap expected) :
    after = expectedHeap ∧ output = expected := by
  have same := Reaches.eq_of_terminal (step := Step) (deterministic dependencies facts)
    run.2 call.2.root (terminal dependencies _ _) (terminal dependencies _ _)
  cases same
  exact ⟨rfl, rfl⟩

theorem dijkstra.Run.eq_of_call (facts : DependencyFacts dependencies) {before after expectedHeap input output expected}
    (run : _root_.Algo.«dijkstra».«dijkstra».dijkstra.Run dependencies before input after output)
    (call : _root_.Algo.«dijkstra».«dijkstra».dijkstra.Call dependencies before input expectedHeap expected) :
    after = expectedHeap ∧ output = expected := by
  have same := Reaches.eq_of_terminal (step := Step) (deterministic dependencies facts)
    run.2 call.2.root (terminal dependencies _ _) (terminal dependencies _ _)
  cases same
  exact ⟨rfl, rfl⟩

end Algo.«dijkstra».«dijkstra»
Source
https://github.com/lunjiah/algo2lean/blob/0f79d5e4242e6477531c9ee4410409f5b1c92f76/examples/dijkstra/dijkstra.algo

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me