Kruskal.processEdges_take_weight
Weight contributed by an accepted edge. Fix a natural number $n$ and a union-find state $\mathit{uf}$ over $n$ nodes, and let $e$ be a weighted edge over $n$ vertices — with endpoints $u_e, v_e$ and weight $w_e$ — followed by a list $\mathit{rest}$ of further weighted edges. Suppose the endpoints of $e$ lie in different components, that is, $\mathit{uf}(u_e) \ne \mathit{uf}(v_e)$. Then the total weight of the edge-selection sweep applied to the list $e :: \mathit{rest}$ starting from $\mathit{uf}$ and an empty accumulator equals $w_e$ plus the total weight of the sweep applied to $\mathit{rest}$ starting from an empty accumulator and the state obtained by merging the components of $u_e$ and $v_e$ in $\mathit{uf}$.
Statement
set_option relaxedAutoImplicit false in set_option autoImplicit false in lemma Kruskal.processEdges_take_weight {n : ℕ} {e : WEdge n} {rest : List (WEdge n)} {uf : UF n} (h : uf.find e.u ≠ uf.find e.v) : totalWeight (processEdges (e :: rest) uf []) = e.weight + totalWeight (processEdges rest (uf.merge e.u e.v) [])
- Source
- TCSlib, `Kruskal.processEdges_take_weight`
- 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.processEdges_take_weight← Kruskal.processEdges_take_weight (TCSlib/GraphTheory/Kruskal/Optimality.lean:77): verbatim
- Verified
- 07 Oct 2026
- Axioms
propext- Built on 9
- 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.find$\mathtt{find}\,\mathit{uf}\,i$ returns the representative of node $i$ in the union-find state $\mathit{uf}$, defined simply as…
- Kruskal.totalWeight_nilTotal weight of the empty edge list. Over any number of vertices $n$, the total weight of the empty list of weighted edges is $0$; that…
- Kruskal.processEdges$\mathtt{processEdges}\,\mathit{es}\,\mathit{uf}\,\mathit{acc}$ scans the edge list $\mathit{es}$ left-to-right: an edge $e$ is added to…
- 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.WEdgeA weighted edge over $n$ vertices is a structure with two endpoints $u, v : \mathrm{Fin}\,n$ and a natural-number weight…
- Kruskal.totalWeightThe total weight of an edge list is the sum of the weights of all its edges:…
- 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.processEdges_accAccumulator splits off as a reversed prefix. Fix $n \in \bbn$, and let $\mathit{es}$ be a list of weighted edges over $n$ vertices,…
- 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
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
set_option relaxedAutoImplicit false inset_option autoImplicit false inlemma Kruskal.processEdges_take_weight {n : ℕ} {e : WEdge n} {rest : List (WEdge n)} {uf : UF n} (h : uf.find e.u ≠ uf.find e.v) : totalWeight (processEdges (e :: rest) uf []) = e.weight + totalWeight (processEdges rest (uf.merge e.u e.v) []) := by rw [show processEdges (e :: rest) uf [] = if uf.find e.u ≠ uf.find e.v then processEdges rest (uf.merge e.u e.v) [e] else processEdges rest uf [] from rfl, if_pos h, processEdges_acc, List.reverse_singleton] rfl