Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Algo.kruskal.Facts definitions

Definition
Algo_kruskal_Facts_SortedRevision

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

Definitions and required structural lemmas from Algo.kruskal.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_kruskal_Generated_SortedRevision
import Definitions.Def_Algo_sort_indices_Facts
import Definitions.Def_Algo_kruskal_sorted_Facts

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».«kruskal»

open Algo2LeanCore _root_.Algo2LeanGenerated

namespace Algo2LeanGenerated

private def next_kruskal (h : Heap) (s : State_kruskal) (stack : Stack) : Nat → Configuration
  | 1 => (Algo2LeanCore.resumeConfig h (Result.fn_kruskal (s.t6)) stack)
  | 2 => (.active h (Frame.import_3 (Algo.«kruskal_sorted».entry_kruskal_sorted (s.t7, s.t8, s.t9, s.t10, s.t11, s.t12)) [] (fun value => match value with | .fn_kruskal_sorted result => (Frame.fn_kruskal 1 { s with t6 := result }))) stack)
  | 3 => (.active h (Frame.fn_kruskal 2 { s with t12 := s.v5 }) stack)
  | 4 => (.active h (Frame.fn_kruskal 3 { s with t11 := s.v4 }) stack)
  | 5 => (.active h (Frame.fn_kruskal 4 { s with t10 := s.v3 }) stack)
  | 6 => (.active h (Frame.fn_kruskal 5 { s with t9 := s.v2 }) stack)
  | 7 => (.active h (Frame.fn_kruskal 6 { s with t8 := s.v1 }) stack)
  | 8 => (.active h (Frame.fn_kruskal 7 { s with t7 := s.v0 }) stack)
  | 9 => (.active h (Frame.fn_kruskal 8 { s with v5 := s.t13 }) stack)
  | 10 => (.active h (Frame.import_1 (Algo.«sort_indices».entry_sort_indices (s.t14, s.t15)) [] (fun value => match value with | .fn_sort_indices result => (Frame.fn_kruskal 9 { s with t13 := result }))) stack)
  | 11 => (.active h (Frame.fn_kruskal 10 { s with t15 := s.v4 }) stack)
  | 12 => (.active h (Frame.fn_kruskal 11 { s with t14 := s.v3 }) stack)
  | pc => .active h (.fn_kruskal pc s) stack

/-- A total projection used only to certify uniqueness of actual transitions. -/
def next : Configuration → Configuration
  | .done h result => .done h result
  | .active h frame stack => match frame with
    | .invalid => .active h .invalid stack
    | .fn_kruskal pc s => next_kruskal h s stack pc
    | .import_1 frame inner resume =>
      ModuleCall.config Frame.import_1 resume stack (Algo.«sort_indices».Algo2LeanGenerated.next (.active h frame inner))
    | .import_3 frame inner resume =>
      ModuleCall.config Frame.import_3 resume stack (Algo.«kruskal_sorted».Algo2LeanGenerated.next (.active h frame inner))

/-- Each generated rule agrees with the projection; guards remain in Step. -/
theorem step_next {before after : Configuration} (transition : Step before after) :
    next before = after := by
  cases transition with
  | kruskal_pc1 h s stack defined => rfl
  | kruskal_pc2 h s stack => rfl
  | kruskal_pc3 h s stack => rfl
  | kruskal_pc4 h s stack => rfl
  | kruskal_pc5 h s stack => rfl
  | kruskal_pc6 h s stack => rfl
  | kruskal_pc7 h s stack => rfl
  | kruskal_pc8 h s stack => rfl
  | kruskal_pc9 h s stack => rfl
  | kruskal_pc10 h s stack => rfl
  | kruskal_pc11 h s stack => rfl
  | kruskal_pc12 h s stack => rfl
  | import_1 h frame inner resume caller after transition =>
    exact congrArg (ModuleCall.config Frame.import_1 resume caller) (Algo.«sort_indices».Algo2LeanGenerated.step_next transition)
  | import_3 h frame inner resume caller after transition =>
    exact congrArg (ModuleCall.config Frame.import_3 resume caller) (Algo.«kruskal_sorted».Algo2LeanGenerated.step_next transition)

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

end Algo2LeanGenerated

end «Algo».«kruskal»

namespace Algo.«kruskal»

open Algo2LeanCore _root_.Algo2LeanGenerated Algo2LeanGenerated

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

end Algo.«kruskal»
Source
https://github.com/lunjiah/algo2lean/blob/9755b41d188977ae1aafdaf9eccdac0b0edb0420/examples/kruskal/kruskal.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