Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Prim: correctness and running time for a reusable queue interface

Proved
PrimAnalysis.prim_complete

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

For a represented connected undirected graph with signed integer weights, a valid root, an empty represented priority queue with sufficient capacity, and separate initialized key/parent/selected sequences, the compiled generic Prim call terminates and returns a minimum spanning parent sequence. The independently stated queue contracts supply the only queue assumptions. The same Call preserves the graph and all storage in the saved caller snapshot, returns the supplied parent reference, and satisfies OperationCounts. With initial queue potential Φ, per-update budget U, per-pop budget P, V vertices and E stored adjacency occurrences, backend-weighted work W satisfies W ≤ Φ + U(E+1) + PV. These are explicit source events; the bound does not count every machine instruction. CLRS fourth edition, Chapter 21, §21.2.

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

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

set_option autoImplicit false
Formal statement
theorem PrimAnalysis.prim_complete :
    ∀ {dependencies : Algo.prim.prim.Dependencies} {client : PrimAnalysis.Client}
      (model : PriorityQueueAnalysis.Model dependencies.PriorityQueue client.queue client.protection),
      PriorityQueueAnalysis.Contracts model PrimAnalysis.reservedClocks →
        LE.le.{0} client.size model.capacity →
          ∀ (before : PrimAnalysis.QueueState model),
            PrimAnalysis.Storage model before →
              Eq.{1} (PrimAnalysis.QueueState.entries model before) List.nil.{0} →
                (Eq.{1} (before.heap.read client.key) fun x => (0 : Int)) →
                  (Eq.{1} (before.heap.read client.parent) fun x => (-1 : Int)) →
                    (Eq.{1} (before.heap.read client.selected) fun x => (0 : Int)) →
                      LE.le.{0} (0 : Int) client.root →
                        LT.lt.{0} client.root client.size →
                          PrimGraph.Symmetric client.size client.adjacency →
                            Algo2Lean.Kruskal.ConnectedOn client.size.toNat
                                (PrimGraph.inputEdges client.size client.adjacency) →
                              Exists.{1} fun after =>
                                Algo.prim.prim.prim.Call dependencies before.heap
                                    (Prod.mk.{0, 0} client.graph
                                      (Prod.mk.{0, 0} client.root
                                        (Prod.mk.{0, 0} client.queue
                                          (Prod.mk.{0, 0} client.key
                                            (Prod.mk.{0, 0} client.parent client.selected)))))
                                    after client.parent ∧
                                  PrimGraph.GraphRep after client.graph client.size client.heads
                                      client.adjacency ∧
                                    PrimAnalysis.MinimumSpanningParents client.size client.adjacency
                                        client.root (after.read client.parent) ∧
                                      PrimAnalysis.OperationCounts before.heap after client.size.toNat
                                          (Algo2Lean.Dijkstra.edgeBudget client.adjacency
                                            (Algo2Lean.Dijkstra.vertexRange client.size)) ∧
                                        LE.le.{0} (PrimAnalysis.work model before.heap after)
                                            (HAdd.hAdd.{0, 0, 0}
                                              (HAdd.hAdd.{0, 0, 0}
                                                (PrimAnalysis.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.parent after.nextRef ∧
                                            client.caller.Footprint after List.nil.{0} List.nil.{0}
                                              List.nil.{0} := by
  sorry
Source
https://github.com/lunjiah/algo2lean/blob/d832a5655d7cac6d032e728a4798128147b27922/examples/analysis/prim/prim.lean#L195-L313
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