AFTD Auto-Formalizing Theoretical Domains

Kruskal.processEdges_acc

theoremverifiedimported Lean

Accumulator splits off as a reversed prefix. Fix $n \in \bbn$, and let $\mathit{es}$ be a list of weighted edges over $n$ vertices, $\mathit{uf}$ a union-find state on $n$ nodes, and $\mathit{acc}$ a list of weighted edges over $n$ vertices. Then running the edge-selection sweep on $\mathit{es}$ from state $\mathit{uf}$ with initial accumulator $\mathit{acc}$ yields the reversal of $\mathit{acc}$ concatenated (on the left) with the result of running the same sweep on $\mathit{es}$ from the same state $\mathit{uf}$ but with the empty accumulator.

Statement

set_option relaxedAutoImplicit false in
set_option autoImplicit false in
lemma Kruskal.processEdges_acc {n : ℕ} (edges : List (WEdge n)) (uf : UF n)
    (acc : List (WEdge n)) :
    processEdges edges uf acc = acc.reverse ++ processEdges edges uf []
Source
TCSlib, `Kruskal.processEdges_acc`
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.
Verified
07 Oct 2026
Axioms
propext
Built on 5
  • 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.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.UF.merge$\mathtt{merge}\,\mathit{uf}\,i\,j$ unifies the components of nodes $i$ and $j$ by reassigning every node whose representative equals…
Used by 1
  • Kruskal.processEdges_take_weightWeight 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…

Lean source view module on GitHub

set_option relaxedAutoImplicit false inset_option autoImplicit false inlemma Kruskal.processEdges_acc {n : ℕ} (edges : List (WEdge n)) (uf : UF n)    (acc : List (WEdge n)) :    processEdges edges uf acc = acc.reverse ++ processEdges edges uf [] := by  induction edges generalizing uf acc with  | nil => simp [processEdges]  | cons e edges ih =>    simp only [processEdges]    split_ifs with h    · rw [ih (uf.merge e.u e.v) (e :: acc), ih (uf.merge e.u e.v) [e]]; simp    · exact ih uf acc
See it in the graphDiscuss this resultChallenge it