AFTD Auto-Formalizing Theoretical Domains

Kruskal.exchange_take_head

theoremverifiedimported Lean

Head-edge exchange preserves reachability. Let $\mathit{base}$ and $\mathit{rest}$ be lists of weighted edges on $n$ vertices, and let $g$ and $e$ be two further weighted edges, with respective endpoints $u_g, v_g$ and $u_e, v_e$. Suppose that, using only the edges in the concatenation $\mathit{base} \mathbin{+\!\!+} \mathit{rest}$, the vertex $u_e$ is connected to $u_g$ and the vertex $v_g$ is connected to $v_e$. Then for every pair of vertices $a, b$ that are connected using the edges of $\mathit{base} \mathbin{+\!\!+} (g :: \mathit{rest})$, the vertices $a$ and $b$ are also connected using the edges of $\mathit{base} \mathbin{+\!\!+} \mathit{rest} \mathbin{+\!\!+} [e]$.

Statement

set_option relaxedAutoImplicit false in
set_option autoImplicit false in
lemma Kruskal.exchange_take_head {n : ℕ} {base rest : List (WEdge n)} {g e : WEdge n}
    (h1 : Reach (base ++ rest) e.u g.u) (h2 : Reach (base ++ rest) g.v e.v) :
    ∀ a b, Reach (base ++ g :: rest) a b → Reach (base ++ rest ++ [e]) a b
Source
TCSlib, `Kruskal.exchange_take_head`
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
Classical.choiceQuot.soundpropext
Built on 7
  • 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.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.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.WEdgeA weighted edge over $n$ vertices is a structure with two endpoints $u, v : \mathrm{Fin}\,n$ and a natural-number weight…
  • 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,…
  • Kruskal.SymAdjGiven a list of weighted edges $\mathit{edges}$ on $n$ vertices, $\mathtt{SymAdj}\,\mathit{edges}\,u\,v$ holds when there exists an edge…
Used by 2
  • 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.exchange_take_head'Edge exchange preserving reachability, reversed orientation. Fix $n$ and consider weighted edges on a vertex set of size $n$, each edge…

Lean source view module on GitHub

set_option relaxedAutoImplicit false inset_option autoImplicit false inlemma Kruskal.exchange_take_head {n : ℕ} {base rest : List (WEdge n)} {g e : WEdge n}    (h1 : Reach (base ++ rest) e.u g.u) (h2 : Reach (base ++ rest) g.v e.v) :    ∀ a b, Reach (base ++ g :: rest) a b → Reach (base ++ rest ++ [e]) a b := by  have mono : ∀ {x y}, Reach (base ++ rest) x y → Reach (base ++ rest ++ [e]) x y :=    fun h => reach_mono h fun _ hx => List.mem_append_left _ hx  have he_adj : Reach (base ++ rest ++ [e]) e.u e.v :=    reach_of_mem (by simp)  intro a b h  apply reach_lift (edges := base ++ g :: rest) _ h  intro c d ⟨f, hmem, hadj⟩  by_cases hfg : f = g  · subst hfg    rcases hadj with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩    · exact ((reach_symm (mono h1)).trans he_adj).trans (reach_symm (mono h2))    · exact ((mono h2).trans (reach_symm he_adj)).trans (mono h1)  · refine Relation.ReflTransGen.single ⟨f, ?_, hadj⟩    simp only [List.mem_append, List.mem_cons] at hmem ⊢    tauto
See it in the graphDiscuss this resultChallenge it