AFTD Auto-Formalizing Theoretical Domains

Kruskal.WEdge

structureimported Lean

A weighted edge over $n$ vertices is a structure with two endpoints $u, v : \mathrm{Fin}\,n$ and a natural-number weight $w : \mathbb{N}$.

Statement

set_option relaxedAutoImplicit false in
set_option autoImplicit false in
structure Kruskal.WEdge (n : ℕ)
Defined in
TCSlib, `Kruskal.WEdge`
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
none listed
Used by 34
  • Kruskal.exchange_take_headHead-edge exchange preserves reachability. Let $\mathit{base}$ and $\mathit{rest}$ be lists of weighted edges on $n$ vertices, and let $g$…
  • Kruskal.totalWeight_eraseTotal weight after removing an edge. Let $\mathit{edges}$ be a list of weighted edges over $n$ vertices, and let $e$ be a weighted edge…
  • Kruskal.symAdj_monoMonotonicity of symmetric adjacency. Fix $n \in \bbn$ and two vertices $u, v \in \mathrm{Fin}\,n$, and let $e_1$ and $e_2$ be lists of…
  • Kruskal.erase_append_permMoving a member to the end is a permutation. Let $l$ be a finite list of weighted edges over $n$ vertices, and let $e$ be a weighted edge…
  • Kruskal.kruskal$\mathtt{kruskal}\,n\,\mathit{edges}$ sorts the edge list by weight and then runs processEdges on the sorted list starting from…
  • Kruskal.exchange_with_baseBase-relative exchange of an edge in Kruskal's algorithm. Let $\mathit{base}$ and $S$ be lists of weighted edges on $n$ vertices, and let…
  • Kruskal.SymAdjGiven a list of weighted edges $\mathit{edges}$ on $n$ vertices, $\mathtt{SymAdj}\,\mathit{edges}\,u\,v$ holds when there exists an edge…
  • 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.reach_mem_iffReachability depends only on the edge set. Fix $n \in \bbn$, and let $l_1$ and $l_2$ be two lists of weighted edges on the vertex set…
  • 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.uf_exchangeUnion-find form of the exchange argument. Let $\mathit{uf}\colon \mathrm{Fin}\,n \to \bbn$ be a union-find state whose classes coincide…
  • Kruskal.kruskal_optimalOptimality of Kruskal's algorithm. Let $E$ be a list of weighted edges on $n$ vertices, and let $S$ be another such list in which every…
  • Kruskal.mergeAll_permPermutation invariance of edge merging. Fix $n$ and an initial union-find state $\mathit{uf} : \mathrm{Fin}\,n \to \bbn$. If two lists of…
  • Kruskal.symAdj_symmSymmetry of symmetric adjacency. Fix a list of weighted edges on $n$ vertices, and let $u$ and $v$ be two vertices. Recall that $u$ and…
  • Kruskal.SpansLike$\mathtt{SpansLike}\,F\,E$ holds when the edge list $F$ is at least as connected as $E$: for every pair of vertices $u, v$, if $u$ and $v$…
  • 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.reach_monoMonotonicity of reachability under edge addition. Fix $n$, let $e_1$ and $e_2$ be lists of weighted edges on the vertex set…
  • Kruskal.mergeAll_cons_eqPeeling the leading edge off a merge fold. Let $\mathit{uf} : \mathrm{Fin}\,n \to \bbn$ be a union-find state on $n$ nodes, let $e$ be a…
  • Kruskal.reach_cons_iffHead–tail decomposition of reachability. Let $g$ be a weighted edge on $n$ vertices with endpoints $p$ and $q$, let $\mathit{rest}$ be a…
  • 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.processEdges_optimalOptimality of the greedy edge-selection sweep. Let $\mathit{edges}$ be a list of weighted edges on $n$ vertices, sorted in nondecreasing…
  • Kruskal.reach_of_memEndpoints of a listed edge are reachable. Let $\mathit{edges}$ be a list of weighted edges on $n$ vertices, and let $e$ be a weighted edge…
  • Kruskal.processEdges_skipSkipping an intra-component edge in the sweep. Fix a number of nodes $n$, a union-find state $\mathit{uf} : \mathrm{Fin}\,n \to \bbn$, a…
  • Kruskal.mergeAll_init_iffCorrectness of union-find merging from the initial state. Fix a natural number $n$, and let $\mathit{edges}$ be a list of weighted edges…
  • Kruskal.reduce_to_restDropping a redundant edge from a candidate set. Let $\mathit{uf}$ be a union-find state on $n$ nodes, let $e$ be a weighted edge with…
  • Kruskal.mergeAll_iff_reachMerging preserves the reachability invariant. Fix $n$ and let $uf : \mathrm{Fin}\,n \to \bbn$ be a union-find state assigning each of the…
  • 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…
  • Kruskal.reach_symmSymmetry of reachability. Let $\mathit{edges}$ be a list of weighted edges on $n$ vertices, and call two vertices reachable when they are…
  • Kruskal.totalWeightThe total weight of an edge list is the sum of the weights of all its edges:…
  • 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.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,…
  • Kruskal.exchange_take_head'Edge exchange preserving reachability, reversed orientation. Fix $n$ and consider weighted edges on a vertex set of size $n$, each edge…
  • Kruskal.reach_liftLifting reachability along an edge set. Let $\mathit{edges}$ and $\mathit{edges}'$ be two lists of weighted edges on $n$ vertices, and…
  • Kruskal.Reach$\mathtt{Reach}\,\mathit{edges}$ is the reflexive--transitive closure of $\mathtt{SymAdj}\,\mathit{edges}$; that is,…

Lean source view module on GitHub

set_option relaxedAutoImplicit false in
set_option autoImplicit false in
structure Kruskal.WEdge (n : ℕ) where
  u : Fin n
  v : Fin n
  weight : ℕ
  deriving Repr, DecidableEq
See it in the graphDiscuss this resultChallenge it