Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Union-find with union by rank and full path compression: named-line observations

Definition
Algo_union_find_Points

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

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

Named source locations and local-state observations for union_find.algo. A standalone source label denotes the state before its following statement. Location predicates and getters describe the supplied configuration without requiring a whole transcript or a reachability hypothesis.

These optional observations help local proofs inspect intermediate states. They are compiled separately from the stable algorithm definitions, so a proof can change labels without changing its main call or output statement.

<!-- 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.

Platform compatibility. The source label # @initialize is presented here as UnionFind.__init__.At.init_loop because Prove2Me reserves the word initialize. Only this observation identifier and its proof references are renamed; its predicate, the algorithm, and the immutable Algo2Lean v0.1.4 release remain unchanged. No Lean initialize command existed or was enabled.

Definition code
import Definitions.Def_Algo_union_find_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.«union_find»

open _root_.Algo2LeanGenerated Algo2LeanGenerated

-- Named locations are independent of the compiled module body.

-- Before source line 20, column 9; location only, not reachability.
def UnionFind.__init__.At.init_loop : Configuration → Prop
  | .active _ (.fn_UnionFind___init__ 4 _) _ => True
  | _ => False
def UnionFind.__init__.Local.self : Configuration → Option Ref_UnionFind
  | .active _ (.fn_UnionFind___init__ pc s) _ => if pc = 4 then some s.v0 else none
  | _ => none
def UnionFind.__init__.Local.size : Configuration → Option Int
  | .active _ (.fn_UnionFind___init__ pc s) _ => if pc = 4 then some s.v1 else none
  | _ => none
def UnionFind.__init__.Local.vertex : Configuration → Option Int
  | .active _ (.fn_UnionFind___init__ pc s) _ => if pc = 4 then some s.v2 else none
  | _ => none

-- Before source line 31, column 9; location only, not reachability.
def UnionFind.find.At.follow : Configuration → Prop
  | .active _ (.fn_UnionFind_find 13 _) _ => True
  | _ => False
-- Before source line 35, column 9; location only, not reachability.
def UnionFind.find.At.compress : Configuration → Prop
  | .active _ (.fn_UnionFind_find 4 _) _ => True
  | _ => False
def UnionFind.find.Local.self : Configuration → Option Ref_UnionFind
  | .active _ (.fn_UnionFind_find pc s) _ => if pc = 4 ∨ pc = 13 then some s.v0 else none
  | _ => none
def UnionFind.find.Local.vertex : Configuration → Option Int
  | .active _ (.fn_UnionFind_find pc s) _ => if pc = 4 ∨ pc = 13 then some s.v1 else none
  | _ => none
def UnionFind.find.Local.parent : Configuration → Option SeqRef
  | .active _ (.fn_UnionFind_find pc s) _ => if pc = 4 ∨ pc = 13 then some s.v2 else none
  | _ => none
def UnionFind.find.Element.parent (state : Configuration) (index : Int) : Option Int :=
  (_root_.Algo.«union_find».UnionFind.find.Local.parent state).map (fun ref => state.heap.read ref index)
def UnionFind.find.Local.root : Configuration → Option Int
  | .active _ (.fn_UnionFind_find pc s) _ => if pc = 4 then some s.v3 else none
  | _ => none

-- Before source line 48, column 9; location only, not reachability.
def UnionFind.union.At.link : Configuration → Prop
  | .active _ (.fn_UnionFind_union 10 _) _ => True
  | _ => False
def UnionFind.union.Local.self : Configuration → Option Ref_UnionFind
  | .active _ (.fn_UnionFind_union pc s) _ => if pc = 10 then some s.v0 else none
  | _ => none
def UnionFind.union.Local.a : Configuration → Option Int
  | .active _ (.fn_UnionFind_union pc s) _ => if pc = 10 then some s.v1 else none
  | _ => none
def UnionFind.union.Local.b : Configuration → Option Int
  | .active _ (.fn_UnionFind_union pc s) _ => if pc = 10 then some s.v2 else none
  | _ => none
def UnionFind.union.Local.left : Configuration → Option Int
  | .active _ (.fn_UnionFind_union pc s) _ => if pc = 10 then some s.v3 else none
  | _ => none
def UnionFind.union.Local.right : Configuration → Option Int
  | .active _ (.fn_UnionFind_union pc s) _ => if pc = 10 then some s.v4 else none
  | _ => none

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