Kruskal.mergeAll_perm
theoremverifiedimported Lean
Permutation invariance of edge merging. Fix $n$ and an initial union-find state $\mathit{uf} : \mathrm{Fin}\,n \to \bbn$. If two lists of weighted edges $l_1$ and $l_2$ over $n$ vertices are permutations of one another, then folding each list into $\mathit{uf}$ by merging the endpoints of every edge in turn yields two union-find states that induce the same partition of the nodes; that is, for all $i, j : \mathrm{Fin}\,n$, the two states assign $i$ and $j$ equal representatives under one exactly when they do under the other.
Statement
set_option relaxedAutoImplicit false in set_option autoImplicit false in lemma Kruskal.mergeAll_perm {n : ℕ} (uf : UF n) {l1 l2 : List (WEdge n)} (hp : l1.Perm l2) : UF.SamePartition (uf.mergeAll l1) (uf.mergeAll l2)
- Source
- TCSlib, `Kruskal.mergeAll_perm`
- Lean proof
- By Harsha Polavaram, from github.com/Shilun-Allan-Li/tcslib at
c8a02591b1e5(Copyright (c) 2026 Harsha Polavaram. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.25.0.Kruskal.mergeAll_perm← Kruskal.mergeAll_perm (TCSlib/GraphTheory/Kruskal/UnionFind.lean:111): verbatim
- Verified
- 16 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 10
- Kruskal.UFThe union-find state for $n$ nodes is defined as a function $\mathrm{Fin}\,n \to \mathbb{N}$ mapping each node to its current…
- Kruskal.UF.SamePartition$\mathtt{SamePartition}\,\mathit{uf}_1\,\mathit{uf}_2$ holds when two union-find states induce the same equivalence relation on nodes: for…
- Kruskal.UF.mergeAll$\mathtt{mergeAll}\,\mathit{uf}\,\mathit{es}$ folds a list of weighted edges $\mathit{es}$ into the union-find $\mathit{uf}$ by calling…
- Kruskal.WEdgeA weighted edge over $n$ vertices is a structure with two endpoints $u, v : \mathrm{Fin}\,n$ and a natural-number weight…
- Kruskal.UF.SamePartition.transTransitivity of the same-partition relation. Let $n$ be a natural number, and let…
- Kruskal.mergeAll_congrMerging edges preserves equal partitions. Let $\mathit{uf}_1, \mathit{uf}_2 : \mathrm{Fin}\,n \to \bbn$ be two union-find states over $n$…
- Kruskal.merge_swap_partitionMerge order is irrelevant to the induced partition. Let $n$ be a natural number, let $\mathit{uf}\colon \mathrm{Fin}\,n \to \bbn$ be a…
- Kruskal.UF.find_defFind equals direct lookup. Let $\mathit{uf} \colon \mathrm{Fin}\,n \to \bbn$ be a union-find state on $n$ nodes, and let $i$ be one of its…
- Kruskal.UF.merge$\mathtt{merge}\,\mathit{uf}\,i\,j$ unifies the components of nodes $i$ and $j$ by reassigning every node whose representative equals…
- Kruskal.UF.SamePartition.rflReflexivity of the same-partition relation. Fix $n \in \bbn$, and recall that a union-find state on $n$ nodes is a function…
- Used by 1
- Kruskal.processEdges_optimalOptimality of the greedy edge-selection sweep. Let $\mathit{edges}$ be a list of weighted edges on $n$ vertices, sorted in nondecreasing…
Lean source view module on GitHub
set_option relaxedAutoImplicit false in set_option autoImplicit false in lemma Kruskal.mergeAll_perm {n : ℕ} (uf : UF n) {l1 l2 : List (WEdge n)} (hp : l1.Perm l2) : UF.SamePartition (uf.mergeAll l1) (uf.mergeAll l2) := by induction hp generalizing uf with | nil => rfl | cons _ _ ih => exact ih _ | swap a b _ => exact mergeAll_congr _ (merge_swap_partition uf b a) | trans _ _ ih1 ih2 => exact (ih1 _).trans (ih2 _)