Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Dijkstra: correctness and running time for a reusable queue interface

Proved
ComposableDijkstraAnalysis.dijkstra_complete

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

For a represented graph with nonnegative integer weights, a valid source, a represented empty queue with sufficient capacity, and distinct allocated distance/settled sequences initially equal to -1/0, the compiled generic Dijkstra call terminates and computes shortest distances. The queue must satisfy the independently stated operation contracts. The same call preserves the graph and every location allocated in the saved client.caller snapshot, returns the supplied distance sequence, and satisfies OperationCounts. The distance and settled work sequences themselves may change.

With initial queue potential Φ, update budget U, pop budget P, V vertices and E adjacency entries, its backend-weighted work W obeys

W≤Φ+U(E+1)+PV.W\leq\Phi+U(E+1)+PV.W≤Φ+U(E+1)+PV.

These are named source events; they do not count all machine instructions. Concrete queue contracts discharge the hypotheses without repeating this graph proof.

<!-- 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.

Preamble
import Definitions.Def_Algo_dijkstra_dijkstra_Analysis
import Theorems.Thm_ComposableDijkstraAnalysis_extraction_progress

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

set_option autoImplicit false
Formal statement
theorem ComposableDijkstraAnalysis.dijkstra_complete :
    ∀ {dependencies : Algo.dijkstra.dijkstra.Dependencies} {client : ComposableDijkstraAnalysis.Client}
      (model : PriorityQueueAnalysis.Model dependencies.PriorityQueue client.queue client.protection),
      PriorityQueueAnalysis.Contracts model ComposableDijkstraAnalysis.reservedClocks →
        LE.le.{0} client.size model.capacity →
          ∀ (before : ComposableDijkstraAnalysis.QueueState model) (source : Int),
            ComposableDijkstraAnalysis.Storage model before →
              Eq.{1} (ComposableDijkstraAnalysis.QueueState.entries model before) List.nil.{0} →
                (Eq.{1} (before.heap.read client.distance) fun x => (-1 : Int)) →
                  (Eq.{1} (before.heap.read client.settled) fun x => (0 : Int)) →
                    LE.le.{0} (0 : Int) source →
                      LT.lt.{0} source client.size →
                        Exists.{1} fun after =>
                          Algo.dijkstra.dijkstra.dijkstra.Call dependencies before.heap
                              (Prod.mk.{0, 0} client.graph
                                (Prod.mk.{0, 0} source
                                  (Prod.mk.{0, 0} client.queue
                                    (Prod.mk.{0, 0} client.distance client.settled))))
                              after client.distance ∧
                            ComposableDijkstraAnalysis.GraphRep after client.graph client.size
                                client.heads client.adjacency ∧
                              Algo2Lean.Dijkstra.ShortestDistances
                                  (Algo2Lean.Dijkstra.representedEdges client.size client.adjacency)
                                  source (after.read client.distance) ∧
                                ComposableDijkstraAnalysis.OperationCounts before.heap after
                                    client.size.toNat
                                    (Algo2Lean.Dijkstra.edgeBudget client.adjacency
                                      (Algo2Lean.Dijkstra.vertexRange client.size)) ∧
                                  LE.le.{0} (ComposableDijkstraAnalysis.work model before.heap after)
                                      (HAdd.hAdd.{0, 0, 0}
                                        (HAdd.hAdd.{0, 0, 0}
                                          (ComposableDijkstraAnalysis.QueueState.potential model before)
                                          (HMul.hMul.{0, 0, 0} model.updateBudget
                                            (HAdd.hAdd.{0, 0, 0}
                                              (Algo2Lean.Dijkstra.edgeBudget client.adjacency
                                                (Algo2Lean.Dijkstra.vertexRange client.size))
                                              (1 : Nat))))
                                        (HMul.hMul.{0, 0, 0} model.popBudget client.size.toNat)) ∧
                                    LT.lt.{0} client.distance after.nextRef ∧
                                      client.caller.Footprint after List.nil.{0} List.nil.{0}
                                        List.nil.{0} := by
  sorry
Source
https://github.com/lunjiah/algo2lean/blob/0f79d5e4242e6477531c9ee4410409f5b1c92f76/examples/analysis/dijkstra/dijkstra.lean#L1053-L1159
Human review
  • Endorsed by Shuze Chen · Oct 11, 2026

    Confirmed by the moderator at approval.

  • Endorsed by lunjia · Oct 11, 2026

    Confirmed by the mission captain (proposal self-audit).

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