Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Proposition 12.3 — edges and components of a spanning forest

Proved
AppliedComb.GraphAlg.spanning_forest_edges

by mikedeng1 · Sep 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

combinatoricsgraph-theoryp2o-batch-books5p2o-gran-per-chapterp2o-plan-bookp2o-v1spanning-trees

Let G=(V,E)G = (V, E)G=(V,E) be a graph on n≥1n \ge 1n≥1 vertices and let H=(V,S)H = (V, S)H=(V,S) be a spanning forest of GGG. Then

0≤∣S∣≤n−1,0 \le |S| \le n - 1,0≤∣S∣≤n−1,

if ∣S∣=n−k|S| = n - k∣S∣=n−k then HHH has exactly kkk connected components, and in particular HHH is a spanning tree of GGG if and only if ∣S∣=n−1|S| = n - 1∣S∣=n−1.

This is the counting fact behind both minimum spanning tree algorithms of the chapter: a spanning forest grows into a spanning tree exactly when it reaches n−1n - 1n−1 edges.

Formalization Note. nnn is Fintype.card V, ∣S∣|S|∣S∣ is Nat.card H.edgeSet, and the number of components is Nat.card H.ConnectedComponent. The hypothesis ∣S∣=n−k|S| = n - k∣S∣=n−k is written ∣S∣+k=n|S| + k = n∣S∣+k=n to avoid truncated subtraction in N\mathbb{N}N; the lower bound 0≤∣S∣0 \le |S|0≤∣S∣ is automatic. The book's n−1n - 1n−1 upper bound presupposes n≥1n \ge 1n≥1, which is the hypothesis 0 < n.

Preamble
import Mathlib
import Definitions.Def_AppliedComb_GraphAlg_SpanningTree
Formal statement
namespace AppliedComb.GraphAlg

/-- Keller–Trotter, p. 240, Proposition 12.3. Let `G = (V, E)` be a graph on `n` vertices and
`H = (V, S)` a spanning forest. Then `0 ≤ |S| ≤ n − 1`; if `|S| = n − k` then `H` has `k`
components; in particular `H` is a spanning tree iff it has `n − 1` edges. `|S| = n − k` is
written `|S| + k = n` (no truncated subtraction); `n ≥ 1` as the bound `|S| ≤ n − 1` requires. -/
theorem spanning_forest_edges {V : Type*} [Fintype V] (G H : SimpleGraph V) (n : ℕ)
    (hn : Fintype.card V = n) (hpos : 0 < n) (hH : IsSpanningForest G H) :
    Nat.card H.edgeSet ≤ n - 1 ∧
      (∀ k : ℕ, Nat.card H.edgeSet + k = n → Nat.card H.ConnectedComponent = k) ∧
      (IsSpanningTree G H ↔ Nat.card H.edgeSet = n - 1) := by sorry

end AppliedComb.GraphAlg
Source
Keller & Trotter, Applied Combinatorics (2017 Edition), p. 240, Proposition 12.3
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setup:

  • VVV is a finite vertex type, and nnn is a natural number with ∣V∣=n|V| = n∣V∣=n and n>0n > 0n>0.
  • GGG and HHH are simple graphs on VVV.
  • HHH is a spanning forest of GGG: every edge of HHH is an edge of GGG, and HHH contains no cycle.

Write ∣E(H)∣|E(H)|∣E(H)∣ for the number of edges of HHH, and c(H)c(H)c(H) for the number of connected components of HHH. The theorem asserts all three of the following.

∣E(H)∣≤n−1.|E(H)| \le n - 1.∣E(H)∣≤n−1.
  1. For every natural number kkk: if ∣E(H)∣+k=n|E(H)| + k = n∣E(H)∣+k=n, then c(H)=kc(H) = kc(H)=k.
  2. HHH is a spanning tree of GGG if and only if ∣E(H)∣=n−1|E(H)| = n-1∣E(H)∣=n−1. Being a spanning tree means: every edge of HHH is an edge of GGG, and HHH is connected, acyclic, and has a nonempty vertex set.

Since n≥1n \ge 1n≥1, the subtraction n−1n-1n−1 is ordinary subtraction. In item 2 at most one kkk can satisfy the hypothesis, namely k=n−∣E(H)∣k = n - |E(H)|k=n−∣E(H)∣.

Degenerate cases.

  • The empty vertex type is excluded by n>0n > 0n>0.
  • For n=1n = 1n=1, the assertions say three things: HHH has 000 edges; if 0+k=10 + k = 10+k=1 then HHH has exactly one component; and HHH is a spanning tree of GGG exactly when it has 000 edges.
  • Item 2 says nothing for any kkk with ∣E(H)∣+k≠n|E(H)| + k \ne n∣E(H)∣+k=n.
  • GGG enters only through the hypothesis that HHH's edges lie in GGG, and through the containment requirement in the definition of spanning tree.
Human review
  • Endorsed by Shuze Chen · Oct 2, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 2, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me