Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Algo.prim.prim.Generated definitions

Definition
Algo_prim_prim_Generated

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

Definitions and required structural lemmas from Algo.prim.prim.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-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_Algo2LeanLib_Modules
import Definitions.Def_Algo2LeanLib_Interface
import Definitions.Def_Algo_prim_graph_Generated
import Definitions.Def_Algo_dijkstra_priority_queue_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.«prim».«prim»

open _root_.Algo2LeanGenerated

-- Independently compiled module; imported algorithms keep their own transitions.
structure Dependencies where
  «PriorityQueue» : Algo.«dijkstra».«priority_queue».«PriorityQueue».Code

namespace Algo2LeanGenerated

abbrev Ref__a2l_import_0_Edge := Algo.«prim».«graph».Algo2LeanGenerated.Ref_Edge
abbrev Ref__a2l_import_0_Graph := Algo.«prim».«graph».Algo2LeanGenerated.Ref_Graph
abbrev Ref__a2l_import_1_PriorityQueue := ObjectRef

abbrev is__a2l_import_0_Edge := Algo.«prim».«graph».Algo2LeanGenerated.is_Edge
abbrev create__a2l_import_0_Edge := Algo.«prim».«graph».Algo2LeanGenerated.create_Edge
abbrev field__a2l_import_0_Edge_target := Algo.«prim».«graph».Algo2LeanGenerated.field_Edge_target
abbrev set__a2l_import_0_Edge_target := Algo.«prim».«graph».Algo2LeanGenerated.set_Edge_target
abbrev field__a2l_import_0_Edge_weight := Algo.«prim».«graph».Algo2LeanGenerated.field_Edge_weight
abbrev set__a2l_import_0_Edge_weight := Algo.«prim».«graph».Algo2LeanGenerated.set_Edge_weight
abbrev field__a2l_import_0_Edge_next := Algo.«prim».«graph».Algo2LeanGenerated.field_Edge_next
abbrev set__a2l_import_0_Edge_next := Algo.«prim».«graph».Algo2LeanGenerated.set_Edge_next

abbrev is__a2l_import_0_Graph := Algo.«prim».«graph».Algo2LeanGenerated.is_Graph
abbrev create__a2l_import_0_Graph := Algo.«prim».«graph».Algo2LeanGenerated.create_Graph
abbrev field__a2l_import_0_Graph_size := Algo.«prim».«graph».Algo2LeanGenerated.field_Graph_size
abbrev set__a2l_import_0_Graph_size := Algo.«prim».«graph».Algo2LeanGenerated.set_Graph_size
abbrev field__a2l_import_0_Graph_heads := Algo.«prim».«graph».Algo2LeanGenerated.field_Graph_heads
abbrev set__a2l_import_0_Graph_heads := Algo.«prim».«graph».Algo2LeanGenerated.set_Graph_heads

def is__a2l_import_1_PriorityQueue (dependencies : Dependencies) (h : Heap) (ref : ObjectRef) : Prop :=
  dependencies.«PriorityQueue».valid h ref = true

def seq__a2l_import_0_Edge_optional : SequenceType (Option Ref__a2l_import_0_Edge) where
  name := "prim.graph.Edge?"
  encode := fun value => (match value with | some ref => ObjectValue.objectValue ref | none => ObjectValue.noneValue)
  decode := ObjectValue.asNullableObject
  decode_encode := by intro value; cases value <;> rfl

structure State_scan_edges where
  v0 : Ref__a2l_import_1_PriorityQueue := 0 -- queue
  v1 : SeqRef := 0 -- key
  v2 : SeqRef := 0 -- parent
  v3 : SeqRef := 0 -- selected
  v4 : Int := 0 -- vertex
  v5 : (Option Ref__a2l_import_0_Edge) := none -- edge
  v6 : Int := 0 -- target
  v7 : Int := 0 -- weight
  t8 : Unit := () -- temporary
  t9 : Bool := false -- temporary
  t10 : Bool := false -- temporary
  t11 : Bool := false -- temporary
  t12 : Unit := () -- temporary
  t13 : Ref__a2l_import_1_PriorityQueue := 0 -- temporary
  t14 : Int := 0 -- temporary
  t15 : Int := 0 -- temporary

structure State_prim where
  v0 : Ref__a2l_import_0_Graph := 0 -- graph
  v1 : Int := 0 -- root
  v2 : Ref__a2l_import_1_PriorityQueue := 0 -- queue
  v3 : SeqRef := 0 -- key
  v4 : SeqRef := 0 -- parent
  v5 : SeqRef := 0 -- selected
  v6 : Int := 0 -- vertex
  t7 : SeqRef := 0 -- temporary
  t8 : Bool := false -- temporary
  t9 : Bool := false -- temporary
  t10 : Ref__a2l_import_1_PriorityQueue := 0 -- temporary
  t11 : Unit := () -- temporary
  t12 : Ref__a2l_import_1_PriorityQueue := 0 -- temporary
  t13 : SeqRef := 0 -- temporary
  t14 : SeqRef := 0 -- temporary
  t15 : SeqRef := 0 -- temporary
  t16 : Int := 0 -- temporary
  t17 : (Option Ref__a2l_import_0_Edge) := none -- temporary
  t18 : Int := 0 -- temporary
  t19 : Ref__a2l_import_1_PriorityQueue := 0 -- temporary
  t20 : Unit := () -- temporary
  t21 : Ref__a2l_import_1_PriorityQueue := 0 -- temporary
  t22 : Int := 0 -- temporary
  t23 : Int := 0 -- temporary

inductive Frame (dependencies : Dependencies) where
  | invalid
  | fn_scan_edges (pc : Nat) (state : State_scan_edges)
  | fn_prim (pc : Nat) (state : State_prim)
  | interface_PriorityQueue (frame : dependencies.«PriorityQueue».Frame) (inner : (Algo2LeanCore.Stack dependencies.«PriorityQueue».Frame Algo.«dijkstra».«priority_queue».«PriorityQueue».Result)) (resume : Algo.«dijkstra».«priority_queue».«PriorityQueue».Result → Frame dependencies)

inductive Result where
  | fn_scan_edges (value : Unit)
  | fn_prim (value : SeqRef)

abbrev Configuration (dependencies : Dependencies) := Algo2LeanCore.Config Heap (Frame dependencies) Result
abbrev Stack (dependencies : Dependencies) := Algo2LeanCore.Stack (Frame dependencies) Result
abbrev Transcript (dependencies : Dependencies) := List (Configuration dependencies)

variable (dependencies : Dependencies)

local notation "Frame" => Frame dependencies
local notation "Stack" => Stack dependencies
local notation "Configuration" => Configuration dependencies
local notation "Transcript" => Transcript dependencies
local notation "is__a2l_import_1_PriorityQueue" => is__a2l_import_1_PriorityQueue dependencies

inductive Step : Configuration → Configuration → Prop where
  | scan_edges_pc1 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 1 s) stack) (Algo2LeanCore.resumeConfig h (Result.fn_scan_edges (s.t8)) stack)
  | scan_edges_pc2 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 2 s) stack) (.active h (Frame.fn_scan_edges 1 { s with t8 := () }) stack)
  | scan_edges_pc3_true (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t9 = true) :
      Step (.active h (Frame.fn_scan_edges 3 s) stack) (.active h (Frame.fn_scan_edges 21 s) stack)
  | scan_edges_pc3_false (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t9 = false) :
      Step (.active h (Frame.fn_scan_edges 3 s) stack) (.active h (Frame.fn_scan_edges 2 s) stack)
  | scan_edges_pc4 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 4 s) stack) (.active h (Frame.fn_scan_edges 3 { s with t9 := (decide ((s.v5 ≠ none))) }) stack)
  | scan_edges_pc5 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : (((s.v5).isSome = true) ∧ ((field__a2l_import_0_Edge_next h ((s.v5).getD 0)).isSome = true))) :
      Step (.active h (Frame.fn_scan_edges 5 s) stack) (.active h (Frame.fn_scan_edges 4 { s with v5 := ((field__a2l_import_0_Edge_next h ((s.v5).getD 0)).getD none) }) stack)
  | scan_edges_pc6 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 6 s) stack) (.active (h.tick "improvements" 1) (Frame.fn_scan_edges 5 s) stack)
  | scan_edges_pc7 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 7 s) stack) (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_push_or_decrease ((s.t13), s.t14, s.t15)) [] (fun value => match value with | .fn_PriorityQueue_push_or_decrease result => (Frame.fn_scan_edges 6 { s with t12 := result }) | _ => .invalid)) stack)
  | scan_edges_pc8 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 8 s) stack) (.active h (Frame.fn_scan_edges 7 { s with t15 := s.v7 }) stack)
  | scan_edges_pc9 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 9 s) stack) (.active h (Frame.fn_scan_edges 8 { s with t14 := s.v6 }) stack)
  | scan_edges_pc10 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : (is__a2l_import_1_PriorityQueue h (s.t13))) :
      Step (.active h (Frame.fn_scan_edges 10 s) stack) (.active h (Frame.fn_scan_edges 9 { s with t13 := s.t13 }) stack)
  | scan_edges_pc11 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 11 s) stack) (.active h (Frame.fn_scan_edges 10 { s with t13 := s.v0 }) stack)
  | scan_edges_pc12 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 12 s) stack) (.active (h.tick "queue_updates" 1) (Frame.fn_scan_edges 11 s) stack)
  | scan_edges_pc13 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : s.v2 < h.nextRef) :
      Step (.active h (Frame.fn_scan_edges 13 s) stack) (.active (h.write s.v2 s.v6 s.v4) (Frame.fn_scan_edges 12 s) stack)
  | scan_edges_pc14 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : s.v1 < h.nextRef) :
      Step (.active h (Frame.fn_scan_edges 14 s) stack) (.active (h.write s.v1 s.v6 s.v7) (Frame.fn_scan_edges 13 s) stack)
  | scan_edges_pc15_true (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t11 = true) :
      Step (.active h (Frame.fn_scan_edges 15 s) stack) (.active h (Frame.fn_scan_edges 14 s) stack)
  | scan_edges_pc15_false (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t11 = false) :
      Step (.active h (Frame.fn_scan_edges 15 s) stack) (.active h (Frame.fn_scan_edges 5 s) stack)
  | scan_edges_pc16 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : (((s.v2 < h.nextRef))) ∧ (((decide (((h.read s.v2 s.v6) < (0 : Int)))) = false → ((s.v1 < h.nextRef))))) :
      Step (.active h (Frame.fn_scan_edges 16 s) stack) (.active h (Frame.fn_scan_edges 15 { s with t11 := ((decide (((h.read s.v2 s.v6) < (0 : Int)))) || (decide ((s.v7 < (h.read s.v1 s.v6))))) }) stack)
  | scan_edges_pc17 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : (((s.v5).isSome = true) ∧ ((field__a2l_import_0_Edge_weight h ((s.v5).getD 0)).isSome = true))) :
      Step (.active h (Frame.fn_scan_edges 17 s) stack) (.active h (Frame.fn_scan_edges 16 { s with v7 := ((field__a2l_import_0_Edge_weight h ((s.v5).getD 0)).getD 0) }) stack)
  | scan_edges_pc18_true (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t10 = true) :
      Step (.active h (Frame.fn_scan_edges 18 s) stack) (.active h (Frame.fn_scan_edges 17 s) stack)
  | scan_edges_pc18_false (h : Heap) (s : State_scan_edges) (stack : Stack) (condition : s.t10 = false) :
      Step (.active h (Frame.fn_scan_edges 18 s) stack) (.active h (Frame.fn_scan_edges 5 s) stack)
  | scan_edges_pc19 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : ((s.v3 < h.nextRef))) :
      Step (.active h (Frame.fn_scan_edges 19 s) stack) (.active h (Frame.fn_scan_edges 18 { s with t10 := (decide (((h.read s.v3 s.v6) = (0 : Int)))) }) stack)
  | scan_edges_pc20 (h : Heap) (s : State_scan_edges) (stack : Stack) (defined : (((s.v5).isSome = true) ∧ ((field__a2l_import_0_Edge_target h ((s.v5).getD 0)).isSome = true))) :
      Step (.active h (Frame.fn_scan_edges 20 s) stack) (.active h (Frame.fn_scan_edges 19 { s with v6 := ((field__a2l_import_0_Edge_target h ((s.v5).getD 0)).getD 0) }) stack)
  | scan_edges_pc21 (h : Heap) (s : State_scan_edges) (stack : Stack) :
      Step (.active h (Frame.fn_scan_edges 21 s) stack) (.active (h.tick "edges" 1) (Frame.fn_scan_edges 20 s) stack)
  | prim_pc1 (h : Heap) (s : State_prim) (stack : Stack) (defined : s.t7 < h.nextRef) :
      Step (.active h (Frame.fn_prim 1 s) stack) (Algo2LeanCore.resumeConfig h (Result.fn_prim (s.t7)) stack)
  | prim_pc2 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 2 s) stack) (.active h (Frame.fn_prim 1 { s with t7 := s.v4 }) stack)
  | prim_pc3_true (h : Heap) (s : State_prim) (stack : Stack) (condition : s.t8 = true) :
      Step (.active h (Frame.fn_prim 3 s) stack) (.active h (Frame.fn_prim 22 s) stack)
  | prim_pc3_false (h : Heap) (s : State_prim) (stack : Stack) (condition : s.t8 = false) :
      Step (.active h (Frame.fn_prim 3 s) stack) (.active h (Frame.fn_prim 2 s) stack)
  | prim_pc4 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 4 s) stack) (.active h (Frame.fn_prim 3 { s with t8 := (!s.t9) }) stack)
  | prim_pc5 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 5 s) stack) (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_is_empty (s.t10)) [] (fun value => match value with | .fn_PriorityQueue_is_empty result => (Frame.fn_prim 4 { s with t9 := result }) | _ => .invalid)) stack)
  | prim_pc6 (h : Heap) (s : State_prim) (stack : Stack) (defined : (is__a2l_import_1_PriorityQueue h (s.t10))) :
      Step (.active h (Frame.fn_prim 6 s) stack) (.active h (Frame.fn_prim 5 { s with t10 := s.t10 }) stack)
  | prim_pc7 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 7 s) stack) (.active h (Frame.fn_prim 6 { s with t10 := s.v2 }) stack)
  | prim_pc8 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 8 s) stack) (.active (h.tick "queue_empty_checks" 1) (Frame.fn_prim 7 s) stack)
  | prim_pc9 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 9 s) stack) (.active h (Frame.fn_scan_edges 4 ({ v0 := s.t12, v1 := s.t13, v2 := s.t14, v3 := s.t15, v4 := s.t16, v5 := s.t17 } : State_scan_edges)) ((fun value => match value with | .fn_scan_edges result => (Frame.fn_prim 8 { s with t11 := result }) | _ => .invalid) :: stack))
  | prim_pc10 (h : Heap) (s : State_prim) (stack : Stack) (defined : ((((field__a2l_import_0_Graph_heads h (s.v0)).isSome = true))) ∧ ((seq__a2l_import_0_Edge_optional.get h ((field__a2l_import_0_Graph_heads h (s.v0)).getD 0) s.v6).isSome = true)) :
      Step (.active h (Frame.fn_prim 10 s) stack) (.active h (Frame.fn_prim 9 { s with t17 := ((seq__a2l_import_0_Edge_optional.get h ((field__a2l_import_0_Graph_heads h (s.v0)).getD 0) s.v6).getD none) }) stack)
  | prim_pc11 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 11 s) stack) (.active h (Frame.fn_prim 10 { s with t16 := s.v6 }) stack)
  | prim_pc12 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 12 s) stack) (.active h (Frame.fn_prim 11 { s with t15 := s.v5 }) stack)
  | prim_pc13 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 13 s) stack) (.active h (Frame.fn_prim 12 { s with t14 := s.v4 }) stack)
  | prim_pc14 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 14 s) stack) (.active h (Frame.fn_prim 13 { s with t13 := s.v3 }) stack)
  | prim_pc15 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 15 s) stack) (.active h (Frame.fn_prim 14 { s with t12 := s.v2 }) stack)
  | prim_pc16 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 16 s) stack) (.active (h.tick "settlements" 1) (Frame.fn_prim 15 s) stack)
  | prim_pc17 (h : Heap) (s : State_prim) (stack : Stack) (defined : s.v5 < h.nextRef) :
      Step (.active h (Frame.fn_prim 17 s) stack) (.active (h.write s.v5 s.v6 (1 : Int)) (Frame.fn_prim 16 s) stack)
  | prim_pc18 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 18 s) stack) (.active h (Frame.fn_prim 17 { s with v6 := s.t18 }) stack)
  | prim_pc19 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 19 s) stack) (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_pop_min (s.t19)) [] (fun value => match value with | .fn_PriorityQueue_pop_min result => (Frame.fn_prim 18 { s with t18 := result }) | _ => .invalid)) stack)
  | prim_pc20 (h : Heap) (s : State_prim) (stack : Stack) (defined : (is__a2l_import_1_PriorityQueue h (s.t19))) :
      Step (.active h (Frame.fn_prim 20 s) stack) (.active h (Frame.fn_prim 19 { s with t19 := s.t19 }) stack)
  | prim_pc21 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 21 s) stack) (.active h (Frame.fn_prim 20 { s with t19 := s.v2 }) stack)
  | prim_pc22 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 22 s) stack) (.active (h.tick "queue_pops" 1) (Frame.fn_prim 21 s) stack)
  | prim_pc23 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 23 s) stack) (.active (h.tick "queue_empty_checks" 1) (Frame.fn_prim 7 s) stack)
  | prim_pc24 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 24 s) stack) (.active h (Frame.interface_PriorityQueue (dependencies.«PriorityQueue».entry_PriorityQueue_push_or_decrease ((s.t21), s.t22, s.t23)) [] (fun value => match value with | .fn_PriorityQueue_push_or_decrease result => (Frame.fn_prim 23 { s with t20 := result }) | _ => .invalid)) stack)
  | prim_pc25 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 25 s) stack) (.active h (Frame.fn_prim 24 { s with t23 := (0 : Int) }) stack)
  | prim_pc26 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 26 s) stack) (.active h (Frame.fn_prim 25 { s with t22 := s.v1 }) stack)
  | prim_pc27 (h : Heap) (s : State_prim) (stack : Stack) (defined : (is__a2l_import_1_PriorityQueue h (s.t21))) :
      Step (.active h (Frame.fn_prim 27 s) stack) (.active h (Frame.fn_prim 26 { s with t21 := s.t21 }) stack)
  | prim_pc28 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 28 s) stack) (.active h (Frame.fn_prim 27 { s with t21 := s.v2 }) stack)
  | prim_pc29 (h : Heap) (s : State_prim) (stack : Stack) :
      Step (.active h (Frame.fn_prim 29 s) stack) (.active (h.tick "queue_updates" 1) (Frame.fn_prim 28 s) stack)
  | prim_pc30 (h : Heap) (s : State_prim) (stack : Stack) (defined : s.v3 < h.nextRef) :
      Step (.active h (Frame.fn_prim 30 s) stack) (.active (h.write s.v3 s.v1 (0 : Int)) (Frame.fn_prim 29 s) stack)
  | interface_PriorityQueue (h : Heap) (frame : dependencies.«PriorityQueue».Frame) (inner : (Algo2LeanCore.Stack dependencies.«PriorityQueue».Frame Algo.«dijkstra».«priority_queue».«PriorityQueue».Result))
      (resume : Algo.«dijkstra».«priority_queue».«PriorityQueue».Result → Frame) (caller : Stack) (after : (Algo2LeanCore.Config Heap dependencies.«PriorityQueue».Frame Algo.«dijkstra».«priority_queue».«PriorityQueue».Result))
      (transition : dependencies.«PriorityQueue».Step (.active h frame inner) after) :
      Step (.active h (Frame.interface_PriorityQueue frame inner resume) caller)
        (Algo2LeanCore.ModuleCall.config Frame.interface_PriorityQueue resume caller after)

local notation "Step" => Step dependencies

theorem terminal (h : Heap) (result : Result) :
    Algo2LeanCore.Terminal Step (.done h result) := by
  intro next transition
  cases transition

theorem interface_PriorityQueue_simulates :
    Algo2LeanCore.ModuleCall.Simulates Frame.interface_PriorityQueue dependencies.«PriorityQueue».Step Step := by
  apply Algo2LeanCore.ModuleCall.Delegates.simulates
  · exact Step.interface_PriorityQueue
  · exact dependencies.«PriorityQueue».terminal

end Algo2LeanGenerated

open Algo2LeanGenerated

variable (dependencies : Dependencies)

local notation "Frame" => Frame dependencies
local notation "Stack" => Stack dependencies
local notation "Configuration" => Configuration dependencies
local notation "Transcript" => Transcript dependencies
local notation "Step" => Step dependencies
local notation "is__a2l_import_1_PriorityQueue" => is__a2l_import_1_PriorityQueue dependencies

def entry_scan_edges (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) : Frame :=
  (Frame.fn_scan_edges 4 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_scan_edges))

local notation "entry_scan_edges" => entry_scan_edges dependencies
def scan_edges.ValidInput (h : Heap) (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) : Prop := is__a2l_import_1_PriorityQueue h input.1 ∧ input.2.1 < h.nextRef ∧ input.2.2.1 < h.nextRef ∧ input.2.2.2.1 < h.nextRef ∧ (∀ ref ∈ input.2.2.2.2.2, is__a2l_import_0_Edge h ref)
def scan_edges.initial (h : Heap) (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) : Configuration :=
  Algo2LeanCore.start h (Frame.fn_scan_edges 4 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_scan_edges))
def scan_edges.Run (h : Heap) (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) (h' : Heap) (output : Unit) : Prop :=
  _root_.Algo.«prim».«prim».scan_edges.ValidInput dependencies h input ∧ Algo2LeanCore.Reaches Step (_root_.Algo.«prim».«prim».scan_edges.initial dependencies h input) (.done h' (Result.fn_scan_edges output))
def scan_edges.ValidHeapTranscript (h : Heap) (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) (trace : Transcript) : Prop :=
  _root_.Algo.«prim».«prim».scan_edges.ValidInput dependencies h input ∧ ∃ final, Algo2LeanCore.Valid Step (_root_.Algo.«prim».«prim».scan_edges.initial dependencies h input) trace final
def scan_edges.Call (h : Heap) (input : Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) (h' : Heap) (output : Unit) : Prop :=
  _root_.Algo.«prim».«prim».scan_edges.ValidInput dependencies h input ∧ Algo2LeanCore.Summary Step h (Frame.fn_scan_edges 4 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_scan_edges)) h' (Result.fn_scan_edges output)
-- Complete this function from the supplied local state, under any caller stack.
def scan_edges.CallFrom (state : Configuration) (finalHeap : Heap) (output : Unit) : Prop :=
  match state with
  | .active heap (Frame.fn_scan_edges pc locals) _ =>
      Algo2LeanCore.Summary Step heap (Frame.fn_scan_edges pc locals) finalHeap (Result.fn_scan_edges output)
  | _ => False
-- Object inputs carry their heap, preserving shared references and cycles.
def scan_edges.load (input : Heap × (Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge))) : Heap × (Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge)) := input
def scan_edges.ValidTranscript (my_input : Heap × (Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge))) (trace : Transcript) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».scan_edges.load my_input
  _root_.Algo.«prim».«prim».scan_edges.ValidHeapTranscript dependencies loaded.1 loaded.2 trace
def scan_edges.Returns (my_input : Heap × (Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge))) (my_output : Unit) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».scan_edges.load my_input
  ∃ finalHeap, _root_.Algo.«prim».«prim».scan_edges.Run dependencies loaded.1 loaded.2 finalHeap my_output

-- Output and clock increments from one completed execution.
def scan_edges.ReturnsWithCost (my_input : Heap × (Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef × Int × (Option Ref__a2l_import_0_Edge))) (my_output : Unit) (costs : Clocks) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».scan_edges.load my_input
  ∃ finalHeap, _root_.Algo.«prim».«prim».scan_edges.Run dependencies loaded.1 loaded.2 finalHeap my_output ∧ Heap.cost loaded.1 finalHeap = costs
theorem scan_edges.ReturnsWithCost.returns {dependencies : Dependencies} {input output costs}
    (run : _root_.Algo.«prim».«prim».scan_edges.ReturnsWithCost dependencies input output costs) : _root_.Algo.«prim».«prim».scan_edges.Returns dependencies input output := by
  obtain ⟨heap, execution, _⟩ := run
  exact ⟨heap, execution⟩
theorem scan_edges.Returns.withCost {dependencies : Dependencies} {input output}
    (run : _root_.Algo.«prim».«prim».scan_edges.Returns dependencies input output) : ∃ costs, _root_.Algo.«prim».«prim».scan_edges.ReturnsWithCost dependencies input output costs := by
  obtain ⟨heap, execution⟩ := run
  exact ⟨Heap.cost (_root_.Algo.«prim».«prim».scan_edges.load input).1 heap, heap, execution, rfl⟩

theorem scan_edges.Call.run {dependencies : Dependencies} {before input after output}
    (call : _root_.Algo.«prim».«prim».scan_edges.Call dependencies before input after output) :
    _root_.Algo.«prim».«prim».scan_edges.Run dependencies before input after output :=
  ⟨call.1, call.2.root⟩

def entry_prim (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) : Frame :=
  (Frame.fn_prim 30 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_prim))

local notation "entry_prim" => entry_prim dependencies
def prim.ValidInput (h : Heap) (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) : Prop := is__a2l_import_0_Graph h input.1 ∧ is__a2l_import_1_PriorityQueue h input.2.2.1 ∧ input.2.2.2.1 < h.nextRef ∧ input.2.2.2.2.1 < h.nextRef ∧ input.2.2.2.2.2 < h.nextRef
def prim.initial (h : Heap) (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) : Configuration :=
  Algo2LeanCore.start h (Frame.fn_prim 30 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_prim))
def prim.Run (h : Heap) (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) (h' : Heap) (output : SeqRef) : Prop :=
  _root_.Algo.«prim».«prim».prim.ValidInput dependencies h input ∧ Algo2LeanCore.Reaches Step (_root_.Algo.«prim».«prim».prim.initial dependencies h input) (.done h' (Result.fn_prim output))
def prim.ValidHeapTranscript (h : Heap) (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) (trace : Transcript) : Prop :=
  _root_.Algo.«prim».«prim».prim.ValidInput dependencies h input ∧ ∃ final, Algo2LeanCore.Valid Step (_root_.Algo.«prim».«prim».prim.initial dependencies h input) trace final
def prim.Call (h : Heap) (input : Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) (h' : Heap) (output : SeqRef) : Prop :=
  _root_.Algo.«prim».«prim».prim.ValidInput dependencies h input ∧ Algo2LeanCore.Summary Step h (Frame.fn_prim 30 ({ v0 := input.1, v1 := input.2.1, v2 := input.2.2.1, v3 := input.2.2.2.1, v4 := input.2.2.2.2.1, v5 := input.2.2.2.2.2 } : State_prim)) h' (Result.fn_prim output)
-- Complete this function from the supplied local state, under any caller stack.
def prim.CallFrom (state : Configuration) (finalHeap : Heap) (output : SeqRef) : Prop :=
  match state with
  | .active heap (Frame.fn_prim pc locals) _ =>
      Algo2LeanCore.Summary Step heap (Frame.fn_prim pc locals) finalHeap (Result.fn_prim output)
  | _ => False
-- Object inputs carry their heap, preserving shared references and cycles.
def prim.load (input : Heap × (Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef)) : Heap × (Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef) := input
def prim.ValidTranscript (my_input : Heap × (Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef)) (trace : Transcript) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».prim.load my_input
  _root_.Algo.«prim».«prim».prim.ValidHeapTranscript dependencies loaded.1 loaded.2 trace
def prim.Returns (my_input : Heap × (Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef)) (my_output : Seq) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».prim.load my_input
  ∃ finalHeap result, _root_.Algo.«prim».«prim».prim.Run dependencies loaded.1 loaded.2 finalHeap result ∧ finalHeap.store result = my_output

-- Output and clock increments from one completed execution.
def prim.ReturnsWithCost (my_input : Heap × (Ref__a2l_import_0_Graph × Int × Ref__a2l_import_1_PriorityQueue × SeqRef × SeqRef × SeqRef)) (my_output : Seq) (costs : Clocks) : Prop :=
  let loaded := _root_.Algo.«prim».«prim».prim.load my_input
  ∃ finalHeap result, _root_.Algo.«prim».«prim».prim.Run dependencies loaded.1 loaded.2 finalHeap result ∧ finalHeap.store result = my_output ∧ Heap.cost loaded.1 finalHeap = costs
theorem prim.ReturnsWithCost.returns {dependencies : Dependencies} {input output costs}
    (run : _root_.Algo.«prim».«prim».prim.ReturnsWithCost dependencies input output costs) : _root_.Algo.«prim».«prim».prim.Returns dependencies input output := by
  obtain ⟨heap, result, execution, value, _⟩ := run
  exact ⟨heap, result, execution, value⟩
theorem prim.Returns.withCost {dependencies : Dependencies} {input output}
    (run : _root_.Algo.«prim».«prim».prim.Returns dependencies input output) : ∃ costs, _root_.Algo.«prim».«prim».prim.ReturnsWithCost dependencies input output costs := by
  obtain ⟨heap, result, execution, value⟩ := run
  exact ⟨Heap.cost (_root_.Algo.«prim».«prim».prim.load input).1 heap, heap, result, execution, value, rfl⟩

theorem prim.Call.run {dependencies : Dependencies} {before input after output}
    (call : _root_.Algo.«prim».«prim».prim.Call dependencies before input after output) :
    _root_.Algo.«prim».«prim».prim.Run dependencies before input after output :=
  ⟨call.1, call.2.root⟩

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