Algo.kruskal.Generated definitions
DefinitionAlgo_kruskal_Generated_SortedRevisionDefinitions and required structural lemmas from Algo.kruskal.Generated. Source declarations are retained by compiler-reported ranges; imports are redirected to the corresponding definition bundles. This bundle contains no theorem stubs.
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.
import Definitions.Def_Algo2LeanLib_Modules
import Definitions.Def_Algo_sort_indices_Generated
import Definitions.Def_Algo_kruskal_sorted_Generated
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
namespace Algo.«kruskal»
open _root_.Algo2LeanGenerated
-- Independently compiled module; imported algorithms keep their own transitions.
namespace Algo2LeanGenerated
abbrev Ref__a2l_import_0_MinHeap := Algo.«indexed_heap».Algo2LeanGenerated.Ref_MinHeap
abbrev Ref__a2l_import_2_UnionFind := Algo.«union_find».Algo2LeanGenerated.Ref_UnionFind
abbrev is__a2l_import_0_MinHeap := Algo.«indexed_heap».Algo2LeanGenerated.is_MinHeap
abbrev create__a2l_import_0_MinHeap := Algo.«indexed_heap».Algo2LeanGenerated.create_MinHeap
abbrev field__a2l_import_0_MinHeap_vertices := Algo.«indexed_heap».Algo2LeanGenerated.field_MinHeap_vertices
abbrev set__a2l_import_0_MinHeap_vertices := Algo.«indexed_heap».Algo2LeanGenerated.set_MinHeap_vertices
abbrev field__a2l_import_0_MinHeap_positions := Algo.«indexed_heap».Algo2LeanGenerated.field_MinHeap_positions
abbrev set__a2l_import_0_MinHeap_positions := Algo.«indexed_heap».Algo2LeanGenerated.set_MinHeap_positions
abbrev field__a2l_import_0_MinHeap_keys := Algo.«indexed_heap».Algo2LeanGenerated.field_MinHeap_keys
abbrev set__a2l_import_0_MinHeap_keys := Algo.«indexed_heap».Algo2LeanGenerated.set_MinHeap_keys
abbrev field__a2l_import_0_MinHeap_size := Algo.«indexed_heap».Algo2LeanGenerated.field_MinHeap_size
abbrev set__a2l_import_0_MinHeap_size := Algo.«indexed_heap».Algo2LeanGenerated.set_MinHeap_size
abbrev is__a2l_import_2_UnionFind := Algo.«union_find».Algo2LeanGenerated.is_UnionFind
abbrev create__a2l_import_2_UnionFind := Algo.«union_find».Algo2LeanGenerated.create_UnionFind
abbrev field__a2l_import_2_UnionFind_parent := Algo.«union_find».Algo2LeanGenerated.field_UnionFind_parent
abbrev set__a2l_import_2_UnionFind_parent := Algo.«union_find».Algo2LeanGenerated.set_UnionFind_parent
abbrev field__a2l_import_2_UnionFind_rank := Algo.«union_find».Algo2LeanGenerated.field_UnionFind_rank
abbrev set__a2l_import_2_UnionFind_rank := Algo.«union_find».Algo2LeanGenerated.set_UnionFind_rank
abbrev field__a2l_import_2_UnionFind_size := Algo.«union_find».Algo2LeanGenerated.field_UnionFind_size
abbrev set__a2l_import_2_UnionFind_size := Algo.«union_find».Algo2LeanGenerated.set_UnionFind_size
structure State_kruskal where
v0 : Int := 0 -- size
v1 : SeqRef := 0 -- sources
v2 : SeqRef := 0 -- targets
v3 : SeqRef := 0 -- weights
v4 : Int := 0 -- count
v5 : SeqRef := 0 -- order
t6 : SeqRef := 0 -- temporary
t7 : Int := 0 -- temporary
t8 : SeqRef := 0 -- temporary
t9 : SeqRef := 0 -- temporary
t10 : SeqRef := 0 -- temporary
t11 : Int := 0 -- temporary
t12 : SeqRef := 0 -- temporary
t13 : SeqRef := 0 -- temporary
t14 : SeqRef := 0 -- temporary
t15 : Int := 0 -- temporary
inductive Frame where
| invalid
| fn_kruskal (pc : Nat) (state : State_kruskal)
| import_1 (frame : Algo.«sort_indices».Algo2LeanGenerated.Frame) (inner : Algo.«sort_indices».Algo2LeanGenerated.Stack) (resume : Algo.«sort_indices».Algo2LeanGenerated.Result → Frame)
| import_3 (frame : Algo.«kruskal_sorted».Algo2LeanGenerated.Frame) (inner : Algo.«kruskal_sorted».Algo2LeanGenerated.Stack) (resume : Algo.«kruskal_sorted».Algo2LeanGenerated.Result → Frame)
inductive Result where
| fn_kruskal (value : SeqRef)
abbrev Configuration := Algo2LeanCore.Config Heap (Frame) Result
abbrev Stack := Algo2LeanCore.Stack (Frame) Result
abbrev Transcript := List (Configuration)
inductive Step : Configuration → Configuration → Prop where
| kruskal_pc1 (h : Heap) (s : State_kruskal) (stack : Stack) (defined : s.t6 < h.nextRef) :
Step (.active h (Frame.fn_kruskal 1 s) stack) (Algo2LeanCore.resumeConfig h (Result.fn_kruskal (s.t6)) stack)
| kruskal_pc2 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 2 s) stack) (.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)
| kruskal_pc3 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 3 s) stack) (.active h (Frame.fn_kruskal 2 { s with t12 := s.v5 }) stack)
| kruskal_pc4 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 4 s) stack) (.active h (Frame.fn_kruskal 3 { s with t11 := s.v4 }) stack)
| kruskal_pc5 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 5 s) stack) (.active h (Frame.fn_kruskal 4 { s with t10 := s.v3 }) stack)
| kruskal_pc6 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 6 s) stack) (.active h (Frame.fn_kruskal 5 { s with t9 := s.v2 }) stack)
| kruskal_pc7 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 7 s) stack) (.active h (Frame.fn_kruskal 6 { s with t8 := s.v1 }) stack)
| kruskal_pc8 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 8 s) stack) (.active h (Frame.fn_kruskal 7 { s with t7 := s.v0 }) stack)
| kruskal_pc9 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 9 s) stack) (.active h (Frame.fn_kruskal 8 { s with v5 := s.t13 }) stack)
| kruskal_pc10 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 10 s) stack) (.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)
| kruskal_pc11 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 11 s) stack) (.active h (Frame.fn_kruskal 10 { s with t15 := s.v4 }) stack)
| kruskal_pc12 (h : Heap) (s : State_kruskal) (stack : Stack) :
Step (.active h (Frame.fn_kruskal 12 s) stack) (.active h (Frame.fn_kruskal 11 { s with t14 := s.v3 }) stack)
| import_1 (h : Heap) (frame : Algo.«sort_indices».Algo2LeanGenerated.Frame) (inner : Algo.«sort_indices».Algo2LeanGenerated.Stack)
(resume : Algo.«sort_indices».Algo2LeanGenerated.Result → Frame) (caller : Stack) (after : Algo.«sort_indices».Algo2LeanGenerated.Configuration)
(transition : Algo.«sort_indices».Algo2LeanGenerated.Step (.active h frame inner) after) :
Step (.active h (Frame.import_1 frame inner resume) caller)
(Algo2LeanCore.ModuleCall.config Frame.import_1 resume caller after)
| import_3 (h : Heap) (frame : Algo.«kruskal_sorted».Algo2LeanGenerated.Frame) (inner : Algo.«kruskal_sorted».Algo2LeanGenerated.Stack)
(resume : Algo.«kruskal_sorted».Algo2LeanGenerated.Result → Frame) (caller : Stack) (after : Algo.«kruskal_sorted».Algo2LeanGenerated.Configuration)
(transition : Algo.«kruskal_sorted».Algo2LeanGenerated.Step (.active h frame inner) after) :
Step (.active h (Frame.import_3 frame inner resume) caller)
(Algo2LeanCore.ModuleCall.config Frame.import_3 resume caller after)
theorem terminal (h : Heap) (result : Result) :
Algo2LeanCore.Terminal Step (.done h result) := by
intro next transition
cases transition
theorem import_1_simulates :
Algo2LeanCore.ModuleCall.Simulates Frame.import_1 Algo.«sort_indices».Algo2LeanGenerated.Step Step := by
apply Algo2LeanCore.ModuleCall.Delegates.simulates
· exact Step.import_1
· exact Algo.«sort_indices».Algo2LeanGenerated.terminal
theorem import_3_simulates :
Algo2LeanCore.ModuleCall.Simulates Frame.import_3 Algo.«kruskal_sorted».Algo2LeanGenerated.Step Step := by
apply Algo2LeanCore.ModuleCall.Delegates.simulates
· exact Step.import_3
· exact Algo.«kruskal_sorted».Algo2LeanGenerated.terminal
end Algo2LeanGenerated
open Algo2LeanGenerated
def entry_kruskal (input : Int × SeqRef × SeqRef × SeqRef × Int) : Frame :=
(Frame.fn_kruskal 12 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2 } : State_kruskal))
def kruskal.ValidInput (h : Heap) (input : Int × SeqRef × SeqRef × SeqRef × Int) : Prop := input.2.1 < h.nextRef ∧ input.2.2.1 < h.nextRef ∧ input.2.2.2.1 < h.nextRef
def kruskal.initial (h : Heap) (input : Int × SeqRef × SeqRef × SeqRef × Int) : Configuration :=
Algo2LeanCore.start h (Frame.fn_kruskal 12 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2 } : State_kruskal))
def kruskal.Run (h : Heap) (input : Int × SeqRef × SeqRef × SeqRef × Int) (h' : Heap) (output : SeqRef) : Prop :=
_root_.Algo.«kruskal».kruskal.ValidInput h input ∧ Algo2LeanCore.Reaches Step (_root_.Algo.«kruskal».kruskal.initial h input) (.done h' (Result.fn_kruskal output))
def kruskal.ValidHeapTranscript (h : Heap) (input : Int × SeqRef × SeqRef × SeqRef × Int) (trace : Transcript) : Prop :=
_root_.Algo.«kruskal».kruskal.ValidInput h input ∧ ∃ final, Algo2LeanCore.Valid Step (_root_.Algo.«kruskal».kruskal.initial h input) trace final
def kruskal.Call (h : Heap) (input : Int × SeqRef × SeqRef × SeqRef × Int) (h' : Heap) (output : SeqRef) : Prop :=
_root_.Algo.«kruskal».kruskal.ValidInput h input ∧ Algo2LeanCore.Summary Step h (Frame.fn_kruskal 12 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2 } : State_kruskal)) h' (Result.fn_kruskal output)
-- Complete this function from the supplied local state, under any caller stack.
def kruskal.CallFrom (state : Configuration) (finalHeap : Heap) (output : SeqRef) : Prop :=
match state with
| .active heap (Frame.fn_kruskal pc locals) _ =>
Algo2LeanCore.Summary Step heap (Frame.fn_kruskal pc locals) finalHeap (Result.fn_kruskal output)
| _ => False
-- The value view gives each sequence input its own object.
def kruskal.load (input : Int × Seq × Seq × Seq × Int) : Heap × (Int × SeqRef × SeqRef × SeqRef × Int) :=
let h0 : Heap := {}
let h1 := h0.allocate input.2.1
let h2 := h1.allocate input.2.2.1
let h3 := h2.allocate input.2.2.2.1
(h3, (input.1, (0 : SeqRef), (1 : SeqRef), (2 : SeqRef), input.2.2.2.2))
def kruskal.ValidTranscript (my_input : Int × Seq × Seq × Seq × Int) (trace : Transcript) : Prop :=
let loaded := _root_.Algo.«kruskal».kruskal.load my_input
_root_.Algo.«kruskal».kruskal.ValidHeapTranscript loaded.1 loaded.2 trace
def kruskal.Returns (my_input : Int × Seq × Seq × Seq × Int) (my_output : Seq) : Prop :=
let loaded := _root_.Algo.«kruskal».kruskal.load my_input
∃ finalHeap result, _root_.Algo.«kruskal».kruskal.Run loaded.1 loaded.2 finalHeap result ∧ finalHeap.store result = my_output
-- Output and clock increments from one completed execution.
def kruskal.ReturnsWithCost (my_input : Int × Seq × Seq × Seq × Int) (my_output : Seq) (costs : Clocks) : Prop :=
let loaded := _root_.Algo.«kruskal».kruskal.load my_input
∃ finalHeap result, _root_.Algo.«kruskal».kruskal.Run loaded.1 loaded.2 finalHeap result ∧ finalHeap.store result = my_output ∧ Heap.cost loaded.1 finalHeap = costs
theorem kruskal.ReturnsWithCost.returns {input output costs}
(run : _root_.Algo.«kruskal».kruskal.ReturnsWithCost input output costs) : _root_.Algo.«kruskal».kruskal.Returns input output := by
obtain ⟨heap, result, execution, value, _⟩ := run
exact ⟨heap, result, execution, value⟩
theorem kruskal.Returns.withCost {input output}
(run : _root_.Algo.«kruskal».kruskal.Returns input output) : ∃ costs, _root_.Algo.«kruskal».kruskal.ReturnsWithCost input output costs := by
obtain ⟨heap, result, execution, value⟩ := run
exact ⟨Heap.cost (_root_.Algo.«kruskal».kruskal.load input).1 heap, heap, result, execution, value, rfl⟩
theorem kruskal.Call.run {before input after output}
(call : _root_.Algo.«kruskal».kruskal.Call before input after output) :
_root_.Algo.«kruskal».kruskal.Run before input after output :=
⟨call.1, call.2.root⟩
end Algo.«kruskal»