Union-find: exact mutable find and full-compression contract
ProvedUnionFindAnalysis.find_contractFor a represented object and an in-range vertex , a terminating UnionFind.find.Call returns the initial model's representative of and rewrites every parent pointer on the visited path to that root. The theorem provides a finite path witness of length , the matching compressed model, and the same final heap's representation and storage effect. Only the parent array may change.
Its exact increment function findCosts p is on uf_find, on uf_compress and zero on every other clock. This is the operational foundation for the inverse-Ackermann bound, not a supplied runtime assumption.
The precondition Rep heap layout model connects an allocated object and distinct allocated parent/rank arrays to a valid forest on Fin n. Validity includes representative consistency, strictly increasing rank along nonroot parent links, and the root-mass rank bound. It does not assume a particular operation history. Vertex arguments belong to Fin n; no such argument exists when .
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_Algo_union_find_Analysis import Theorems.Thm_Algo2Lean_UnionFind_compress_valid set_option autoImplicit true set_option backward.isDefEq.respectTransparency false set_option backward.defeqAttrib.useBackward true set_option autoImplicit false
theorem UnionFindAnalysis.find_contract :
∀ {n : Nat} (heap : Algo2LeanGenerated.Heap) (layout : UnionFindAnalysis.Layout)
(model : Algo2Lean.UnionFind.State n),
UnionFindAnalysis.Rep heap layout model →
∀ (vertex : Fin n),
Exists.{1} fun length =>
Exists.{1} fun after =>
Algo2Lean.UnionFind.Find model vertex (model.representative vertex) length ∧
Algo.union_find.UnionFind.find.Call heap
(Prod.mk.{0, 0} layout.object (↑(↑vertex : Nat) : Int)) after
(↑(↑(model.representative vertex) : Nat) : Int) ∧
UnionFindAnalysis.Rep after layout
(UnionFindAnalysis.findResult model vertex length) ∧
UnionFindAnalysis.Storage heap after (List.cons.{0} layout.parent List.nil.{0}) ∧
heap.Increments after (UnionFindAnalysis.findCosts length) := by
sorry