Kruskal minimum spanning forest and edge scan: determinism and call-to-run facts
DefinitionAlgo_kruskal_FactsGenerated execution facts for kruskal.algo, including the relation between a reusable Call witness and any completed Run of the same inputs. The determinism bridge lets ordinary-output and cost corollaries reuse the constructive call theorem without repeating its algorithm analysis.
This bundle depends on the stable algorithm definition and the corresponding facts for imported components. It does not introduce a separate specification of what the program computes.
<!-- 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.
Superseded Kruskal implementation
These facts concern the earlier implementation. The revised complete algorithm and post-sorting scan have their own determinism and call-to-run facts.
Current entry points: Algo_kruskal_Facts_SortedRevision; Algo_kruskal_sorted_Facts.
This post is deprecated in favor of the revised implementation. Its original formal content and proofs remain available for existing imports. The linked results concern the revised implementation; their formal statements need not be identical to this one.
import Definitions.Def_Algo_kruskal_Generated
import Definitions.Def_Algo_union_find_Facts
import Definitions.Def_Algo_sort_indices_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.t14)) stack)
| 2 => (.active h (Frame.fn_kruskal 1 { s with t14 := s.v5 }) stack)
| 3 => if s.t15 then (.active h (Frame.fn_kruskal 27 s) stack) else (.active h (Frame.fn_kruskal 2 s) stack)
| 4 => (.active h (Frame.fn_kruskal 3 { s with t15 := (decide ((s.v8 < s.v4))) }) stack)
| 5 => (.active h (Frame.fn_kruskal 4 { s with v8 := (s.v8 + (1 : Int)) }) stack)
| 6 => (.active h (Frame.import_0 (Algo.«union_find».entry_UnionFind_union ((s.t18), s.t19, s.t20)) [] (fun value => match value with | .fn_UnionFind_union result => (Frame.fn_kruskal 5 { s with t17 := result }) | _ => .invalid)) stack)
| 7 => (.active h (Frame.fn_kruskal 6 { s with t20 := s.v11 }) stack)
| 8 => (.active h (Frame.fn_kruskal 7 { s with t19 := s.v10 }) stack)
| 9 => (.active h (Frame.fn_kruskal 8 { s with t18 := s.t18 }) stack)
| 10 => (.active h (Frame.fn_kruskal 9 { s with t18 := s.v6 }) stack)
| 11 => (.active (h.write s.v5 s.v9 (1 : Int)) (Frame.fn_kruskal 10 s) stack)
| 12 => if s.t16 then (.active h (Frame.fn_kruskal 11 s) stack) else (.active h (Frame.fn_kruskal 5 s) stack)
| 13 => (.active h (Frame.fn_kruskal 12 { s with t16 := (decide ((s.v12 ≠ s.v13))) }) stack)
| 14 => (.active h (Frame.fn_kruskal 13 { s with v13 := s.t21 }) stack)
| 15 => (.active h (Frame.import_0 (Algo.«union_find».entry_UnionFind_find ((s.t22), s.t23)) [] (fun value => match value with | .fn_UnionFind_find result => (Frame.fn_kruskal 14 { s with t21 := result }) | _ => .invalid)) stack)
| 16 => (.active h (Frame.fn_kruskal 15 { s with t23 := s.v11 }) stack)
| 17 => (.active h (Frame.fn_kruskal 16 { s with t22 := s.t22 }) stack)
| 18 => (.active h (Frame.fn_kruskal 17 { s with t22 := s.v6 }) stack)
| 19 => (.active h (Frame.fn_kruskal 18 { s with v12 := s.t24 }) stack)
| 20 => (.active h (Frame.import_0 (Algo.«union_find».entry_UnionFind_find ((s.t25), s.t26)) [] (fun value => match value with | .fn_UnionFind_find result => (Frame.fn_kruskal 19 { s with t24 := result }) | _ => .invalid)) stack)
| 21 => (.active h (Frame.fn_kruskal 20 { s with t26 := s.v10 }) stack)
| 22 => (.active h (Frame.fn_kruskal 21 { s with t25 := s.t25 }) stack)
| 23 => (.active h (Frame.fn_kruskal 22 { s with t25 := s.v6 }) stack)
| 24 => (.active (h.tick "kruskal" 1) (Frame.fn_kruskal 23 s) stack)
| 25 => (.active h (Frame.fn_kruskal 24 { s with v11 := (h.read s.v2 s.v9) }) stack)
| 26 => (.active h (Frame.fn_kruskal 25 { s with v10 := (h.read s.v1 s.v9) }) stack)
| 27 => (.active h (Frame.fn_kruskal 26 { s with v9 := (h.read s.v7 s.v8) }) stack)
| 28 => (.active (h.tick "kruskal" 1) (Frame.fn_kruskal 4 s) stack)
| 29 => (.active h (Frame.fn_kruskal 28 { s with v8 := (0 : Int) }) stack)
| 30 => (.active h (Frame.fn_kruskal 29 { s with v7 := s.t27 }) stack)
| 31 => (.active h (Frame.import_2 (Algo.«sort_indices».entry_sort_indices (s.t28, s.t29)) [] (fun value => match value with | .fn_sort_indices result => (Frame.fn_kruskal 30 { s with t27 := result }))) stack)
| 32 => (.active h (Frame.fn_kruskal 31 { s with t29 := s.v4 }) stack)
| 33 => (.active h (Frame.fn_kruskal 32 { s with t28 := s.v3 }) stack)
| 34 => (.active h (Frame.fn_kruskal 33 { s with v6 := s.t30 }) stack)
| 35 => (.active h (Frame.import_0 (Algo.«union_find».entry_UnionFind s.t31) [] (fun value => match value with | .fn_UnionFind result => (Frame.fn_kruskal 34 { s with t30 := result }) | _ => .invalid)) stack)
| 36 => (.active h (Frame.fn_kruskal 35 { s with t31 := s.v0 }) stack)
| 37 => (.active h (Frame.fn_kruskal 36 { s with v5 := s.t32 }) stack)
| 38 => (.active (h.allocate (fun _ => s.t33)) (Frame.fn_kruskal 37 { s with t32 := h.nextRef }) stack)
| 39 => (.active h (Frame.fn_kruskal 38 { s with t33 := (0 : Int) }) 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_0 frame inner resume =>
ModuleCall.config Frame.import_0 resume stack (Algo.«union_find».Algo2LeanGenerated.next (.active h frame inner))
| .import_2 frame inner resume =>
ModuleCall.config Frame.import_2 resume stack (Algo.«sort_indices».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_true h s stack condition => simp [next, next_kruskal, condition]
| kruskal_pc3_false h s stack condition => simp [next, next_kruskal, condition]
| 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 defined => rfl
| kruskal_pc10 h s stack => rfl
| kruskal_pc11 h s stack defined => rfl
| kruskal_pc12_true h s stack condition => simp [next, next_kruskal, condition]
| kruskal_pc12_false h s stack condition => simp [next, next_kruskal, condition]
| kruskal_pc13 h s stack => rfl
| kruskal_pc14 h s stack => rfl
| kruskal_pc15 h s stack => rfl
| kruskal_pc16 h s stack => rfl
| kruskal_pc17 h s stack defined => rfl
| kruskal_pc18 h s stack => rfl
| kruskal_pc19 h s stack => rfl
| kruskal_pc20 h s stack => rfl
| kruskal_pc21 h s stack => rfl
| kruskal_pc22 h s stack defined => rfl
| kruskal_pc23 h s stack => rfl
| kruskal_pc24 h s stack => rfl
| kruskal_pc25 h s stack defined => rfl
| kruskal_pc26 h s stack defined => rfl
| kruskal_pc27 h s stack defined => rfl
| kruskal_pc28 h s stack => rfl
| kruskal_pc29 h s stack => rfl
| kruskal_pc30 h s stack => rfl
| kruskal_pc31 h s stack => rfl
| kruskal_pc32 h s stack => rfl
| kruskal_pc33 h s stack => rfl
| kruskal_pc34 h s stack => rfl
| kruskal_pc35 h s stack => rfl
| kruskal_pc36 h s stack => rfl
| kruskal_pc37 h s stack => rfl
| kruskal_pc38 h s stack => rfl
| kruskal_pc39 h s stack => rfl
| import_0 h frame inner resume caller after transition =>
exact congrArg (ModuleCall.config Frame.import_0 resume caller) (Algo.«union_find».Algo2LeanGenerated.step_next transition)
| import_2 h frame inner resume caller after transition =>
exact congrArg (ModuleCall.config Frame.import_2 resume caller) (Algo.«sort_indices».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»