AFTD Auto-Formalizing Theoretical Domains

simple_graph_odd_components_card_le_vertices

theoremverified

A finite graph has at most as many odd connected components as vertices.

Statement

theorem simple_graph_odd_components_card_le_vertices
    {V : Type*} [Fintype V] (G : SimpleGraph V) :
    G.oddComponents.ncard ≤ Fintype.card V
Source
OP-1957: bound the barrier size by the cardinality of the extra component part.
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Used by 2

The proof, explained

The proof bounds the number of odd connected components by the total number of connected components, and then bounds the total number of connected components by the number of vertices. The first bound holds because odd components form a subset of all connected components in a finite graph. The second bound holds because the projection sending each vertex to its connected component is surjective, and a surjective map from a finite set cannot increase cardinality. Transitivity of inequality completes the argument.

  1. The canonical map sending each vertex to its connected component is surjective.

    Classical reasoning is enabled. Given any connected component `c`, its support is nonempty, so there exists some vertex `v` belonging to `c`, which means the projection map `G.connectedComponentMk` maps `v` to `c`.

    lines 4–8

      classical
      have hsurj : Function.Surjective G.connectedComponentMk := by
        intro c
        obtain ⟨v, hv⟩ := c.nonempty_supp
        exact ⟨v, hv⟩
  2. The total number of connected components is at most the number of vertices.

    Because `V` is finite and `G.connectedComponentMk : V → G.ConnectedComponent` is surjective, the cardinality of `G.ConnectedComponent` is at most the cardinality of `V` by `Nat.card_le_card_of_surjective`. Rewriting `Nat.card V` to `Fintype.card V` using `Nat.card_eq_fintype_card` gives the desired bound.

    lines 9–11

    uses Nat.card_eq_fintype_card, Nat.card_le_card_of_surjective

      have hcomp : Nat.card G.ConnectedComponent ≤ Fintype.card V := by
        simpa only [Nat.card_eq_fintype_card] using
          (Nat.card_le_card_of_surjective G.connectedComponentMk hsurj)
  3. The number of odd connected components is at most the total number of connected components.

    The odd components form a subset of all connected components by `Set.subset_univ`. Since the universal set of components is finite (`Set.toFinite`), `Set.ncard_le_ncard` bounds the cardinality of this subset by the cardinality of the universal set, which equals the total number of connected components by `Set.ncard_univ`.

    lines 12–14

    uses Set.ncard_univ, Set.ncard_le_ncard, Set.subset_univ, Set.toFinite

      have hodd : G.oddComponents.ncard ≤ Nat.card G.ConnectedComponent := by
        rw [← Set.ncard_univ]
        exact Set.ncard_le_ncard (Set.subset_univ _) (Set.toFinite _)
  4. The number of odd connected components is at most the number of vertices in G.

    Combining the bound on odd components in terms of all connected components (`hodd`) with the bound on connected components in terms of vertices (`hcomp`) by transitivity yields the theorem.

    line 15

      exact hodd.trans hcomp
Nat.card_eq_fintype_card
For any finite type α, its cardinality as a natural number (`Nat.card`) equals its finite-type cardinality (`Fintype.card`).
Nat.card_le_card_of_surjective
If a function from a finite type to another type is surjective, the cardinality of the target is at most the cardinality of the domain.
Set.ncard_univ
The set cardinality (`ncard`) of the universal set of a type α equals the cardinality of α (`Nat.card α`).
Set.ncard_le_ncard
If s ⊆ t and t is finite, then the cardinality of s is at most the cardinality of t.
Set.subset_univ
Every set of elements of α is a subset of the universal set of α.
Set.toFinite
A set whose coerced subtype is finite is finite as a set.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

theorem simple_graph_odd_components_card_le_vertices    {V : Type*} [Fintype V] (G : SimpleGraph V) :    G.oddComponents.ncard ≤ Fintype.card V := by  classical  have hsurj : Function.Surjective G.connectedComponentMk := by    intro c    obtain ⟨v, hv⟩ := c.nonempty_supp    exact ⟨v, hv⟩  have hcomp : Nat.card G.ConnectedComponent ≤ Fintype.card V := by    simpa only [Nat.card_eq_fintype_card] using      (Nat.card_le_card_of_surjective G.connectedComponentMk hsurj)  have hodd : G.oddComponents.ncard ≤ Nat.card G.ConnectedComponent := by    rw [← Set.ncard_univ]    exact Set.ncard_le_ncard (Set.subset_univ _) (Set.toFinite _)  exact hodd.trans hcomp
See it in the graphDiscuss this resultChallenge it