Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Kruskal after sorting: shared terminating call and explicit running time

Proved
KruskalSortedAnalysis.call_complete

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

One reusable execution theorem supplies the minimum spanning forest, fresh storage, caller preservation, explicit budget and unchanged unrelated clocks. Both public contracts use this same proof.

This result is part of the Algo2Lean formalization of CLRS, fourth edition, Chapter 21, §21.2. It is a supporting reusable contract for the separately stated total and post-sorting runtime theorems. Union-find correctness and inverse-Ackermann amortization are imported from the existing published component, and the full algorithm also imports the existing sorting contract.

<!-- 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_kruskal_sorted_Analysis
import Theorems.Thm_UnionFindAnalysis_find_contract
import Theorems.Thm_UnionFindAnalysis_union_summary_amortized
import Theorems.Thm_UnionFindAnalysis_constructor_summary
import Theorems.Thm_UnionFindAnalysis_constructor_rep
import Theorems.Thm_Algo2Lean_Kruskal_Scan_minimum_spanning_forest
import Theorems.Thm_Algo2Lean_UnionFind_compressPath_amortized

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

set_option autoImplicit false
Formal statement
theorem KruskalSortedAnalysis.call_complete :
    ∀ (heap : Algo2LeanGenerated.Heap) (size count : Int)
      (sources targets weights order : Algo2LeanGenerated.SeqRef),
      Algo.kruskal_sorted.kruskal_sorted.ValidInput heap
          (Prod.mk.{0, 0} size
            (Prod.mk.{0, 0} sources
              (Prod.mk.{0, 0} targets (Prod.mk.{0, 0} weights (Prod.mk.{0, 0} count order))))) →
        KruskalInput.WellFormed size count (heap.read sources) (heap.read targets) →
          SortIndicesAnalysis.SortedPermutation (heap.read weights) count (heap.read order) →
            Exists.{1} fun final =>
              Exists.{1} fun chosen =>
                Exists.{1} fun selected =>
                  Algo.kruskal_sorted.kruskal_sorted.Call heap
                      (Prod.mk.{0, 0} size
                        (Prod.mk.{0, 0} sources
                          (Prod.mk.{0, 0} targets
                            (Prod.mk.{0, 0} weights (Prod.mk.{0, 0} count order)))))
                      final chosen ∧
                    Algo2Lean.Kruskal.MinimumSpanningForest
                        (KruskalInput.edges (heap.read sources) (heap.read targets) (heap.read weights)
                          count)
                        selected ∧
                      KruskalAnalysis.Flags (final.read chosen) selected ∧
                        LE.le.{0} (KruskalSortedAnalysis.runtime final.clocks)
                            (HAdd.hAdd.{0, 0, 0} (KruskalSortedAnalysis.runtime heap.clocks)
                              (KruskalSortedAnalysis.runtimeBound size.toNat count.toNat)) ∧
                          heap.Footprint final List.nil.{0} List.nil.{0} List.nil.{0} ∧
                            LE.le.{0} heap.nextRef chosen ∧
                              LT.lt.{0} chosen final.nextRef ∧
                                ∀ (clock : String),
                                  ¬Membership.mem.{0, 0}
                                        (List.cons.{0} "uf_init"
                                          (List.cons.{0} "uf_find"
                                            (List.cons.{0} "uf_compress"
                                              (List.cons.{0} "uf_union"
                                                (List.cons.{0} "kruskal" List.nil.{0})))))
                                        clock →
                                    Eq.{1} (final.clocks clock) (heap.clocks clock) := by
  sorry
Source
https://github.com/lunjiah/algo2lean/blob/9755b41d188977ae1aafdaf9eccdac0b0edb0420/examples/kruskal/analysis/kruskal_sorted.lean#L81-L160
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