AFTD Auto-Formalizing Theoretical Domains

even_graph_four_odd_component_bounds_has_perfect_matching

theoremverified

An even-order finite graph has a perfect matching if, after removing zero vertices, it has no odd component, after removing one or two vertices it has at most two odd components, after removing three it has at most three, and after any vertex deletion it has at most four.

Statement

theorem even_graph_four_odd_component_bounds_has_perfect_matching
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (heven : Even (Nat.card V))
    (hzero : ∀ S : Set V, S.ncard=0 →
      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard = 0)
    (hone : ∀ S : Set V, S.ncard=1 →
      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 2)
    (htwo : ∀ S : Set V, S.ncard=2 →
      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 2)
    (hthree : ∀ S : Set V, S.ncard=3 →
      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 3)
    (hall : ∀ S : Set V,
      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 4) :
    ∃ P : G.Subgraph, P.IsPerfectMatching
Source
OP-1957: matching-criterion assembly for the (5,7) example.
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1

The proof, explained

The proof proceeds by contradiction using Tutte's 1-factor theorem. If $G$ has no perfect matching, then since its order is even, there exists a Tutte violator—a vertex subset $S$ whose deletion leaves strictly more odd components than $|S|$. Because $|V|$ is even, the number of odd components $q(G - S)$ and $|S|$ share the same parity, which forces $q(G - S) \ge |S| + 2$. Case analysis on $|S| \in \{0, 1, 2, 3\}$ and $|S| \ge 4$ then contradicts the given upper bounds in every case.

  1. Assuming $G$ has no perfect matching, there exists a Tutte violator $S \subseteq V$.

    We argue by contradiction, supposing that $G$ has no perfect matching (`hn`). Because $V$ has even cardinality (`heven`), Tutte's theorem (`SimpleGraph.exists_isTutteViolator`) yields a subset $S \subseteq V$ violating Tutte's condition.

    lines 15–18

    uses SimpleGraph.exists_isTutteViolator

      classical
      by_contra hn
      obtain ⟨S, hS⟩ := SimpleGraph.exists_isTutteViolator (G := G)
        (fun M hM => hn ⟨M, hM⟩) heven
  2. In the deleted subgraph $H = G - S$, the number of odd components strictly exceeds $|S|$ and has the same parity as the number of vertices in $H$.

    Let $W = V \setminus S$ be the remaining vertex set and $H$ the induced subgraph $G - S$. By definition of a Tutte violator, the number of odd components of $H$ is strictly greater than $|S|$ (`hS'`). By `SimpleGraph.odd_ncard_oddComponents`, the number of odd components of $H$ has the same parity as the vertex count $|W|$.

    lines 19–22

    uses SimpleGraph.odd_ncard_oddComponents

      let W : Set V := ((⊤ : G.Subgraph).deleteVerts S).verts
      let H := ((⊤ : G.Subgraph).deleteVerts S).coe
      have hS' : S.ncard < H.oddComponents.ncard := hS
      have hpar := SimpleGraph.odd_ncard_oddComponents H
  3. The vertex count of $H$ is $|V| - |S|$, and the number of odd components of $H$ has the same parity as $|V| - |S|$.

    We express $W$ as the set difference $V \setminus S$, showing $|W| = |V| - |S|$ (`hcardW`) and $|S| \le |V|$ (`hSle`) using set difference and universal set cardinality lemmas (`Nat.card_coe_set_eq`, `Set.ncard_diff`, `Set.subset_univ`, `Set.ncard_univ`, `Nat.card_eq_fintype_card`, `Set.ncard_le_ncard`). Since $|V|$ is even (`heven`), $|V| \pmod 2 = 0$ (`hev`) via `Nat.even_iff.mp`. Rewriting the parity condition with `Nat.odd_iff` and `hcardW` expresses parity as a modulo 2 relation between the number of odd components and $|V| - |S|$.

    lines 23–32

    uses Nat.card_coe_set_eq, Set.ncard_diff, Set.subset_univ, Set.ncard_univ, Nat.card_eq_fintype_card, Set.ncard_le_ncard, Nat.even_iff.mp, Nat.odd_iff

      have hcardW : Nat.card W = Fintype.card V - S.ncard := by
        rw [Nat.card_coe_set_eq]
        change (Set.univ \ S).ncard = _
        rw [Set.ncard_diff (Set.subset_univ S), Set.ncard_univ, Nat.card_eq_fintype_card]
      have hSle : S.ncard ≤ Fintype.card V := by
        rw [← Nat.card_eq_fintype_card, ← Set.ncard_univ]
        exact Set.ncard_le_ncard (Set.subset_univ S)
      have hev : Fintype.card V % 2 = 0 := by
        rw [← Nat.card_eq_fintype_card]; exact Nat.even_iff.mp heven
      rw [hcardW, Nat.odd_iff, Nat.odd_iff] at hpar
  4. The case $|S| = 0$ is impossible.

    If $|S| = 0$, hypothesis `hzero` states that $H$ has 0 odd components, contradicting the requirement $|S| < q(H)$ (which would demand $0 < 0$). Linear arithmetic (`omega`) closes this case.

    lines 33–35

      by_cases hs0 : S.ncard=0
      · have hh : H.oddComponents.ncard=0 := hzero S hs0
        omega
  5. The case $|S| = 1$ is impossible.

    If $|S| = 1$, hypothesis `hone` bounds the number of odd components by at most 2. However, since $|V|$ is even, $|V| - 1$ is odd, so $H$ must have an odd number of odd components. Coupled with $q(H) > 1$, this requires $q(H) \ge 3$, contradicting $q(H) \le 2$. Linear arithmetic (`omega`) closes this case.

    lines 36–38

      · by_cases hs1 : S.ncard=1
        · have hh : H.oddComponents.ncard ≤ 2 := hone S hs1
          omega
  6. The case $|S| = 2$ is impossible.

    If $|S| = 2$, hypothesis `htwo` bounds the number of odd components by at most 2. But $|V| - 2$ is even, so $q(H)$ must be even. Coupled with $q(H) > 2$, this requires $q(H) \ge 4$, contradicting $q(H) \le 2$. Linear arithmetic (`omega`) closes this case.

    lines 39–41

        · by_cases hs2 : S.ncard=2
          · have hh : H.oddComponents.ncard ≤ 2 := htwo S hs2
            omega
  7. The case $|S| = 3$ is impossible.

    If $|S| = 3$, hypothesis `hthree` bounds the number of odd components by at most 3. But $|V| - 3$ is odd, so $q(H)$ must be odd. Coupled with $q(H) > 3$, this requires $q(H) \ge 5$, contradicting $q(H) \le 3$. Linear arithmetic (`omega`) closes this case.

    lines 42–44

          · by_cases hs3 : S.ncard=3
            · have hh : H.oddComponents.ncard ≤ 3 := hthree S hs3
              omega
  8. The case $|S| \ge 4$ is impossible, completing the contradiction.

    If $|S| \notin \{0, 1, 2, 3\}$, then $|S| \ge 4$. Hypothesis `hall` bounds the number of odd components by at most 4 for any deleted set. But $q(H) > |S| \ge 4$ requires $q(H) \ge 5$, contradicting $q(H) \le 4$. Linear arithmetic (`omega`) closes this final case.

    lines 45–46

            · have hh : H.oddComponents.ncard ≤ 4 := hall S
              omega
SimpleGraph.exists_isTutteViolator
In a finite graph of even order with no perfect matching, there exists a Tutte violator: a vertex subset whose deletion leaves strictly more odd connected components than vertices removed.
SimpleGraph.odd_ncard_oddComponents
The number of odd connected components of a finite graph has the same parity as the total number of its vertices.
Nat.card_coe_set_eq
The cardinality of a set viewed as a subtype equals its set cardinality (`ncard`).
Set.ncard_diff
For a finite subset $s \subseteq t$, the cardinality of the difference $t \setminus s$ is $|t| - |s|$.
Set.subset_univ
Every set of elements of a type is a subset of the universal set of that type.
Set.ncard_univ
The set cardinality of the universal set of a type equals the cardinality of the type.
Nat.card_eq_fintype_card
For a finite type, the general cardinality `Nat.card` equals the `Fintype` cardinality.
Set.ncard_le_ncard
If $s \subseteq t$ and $t$ is finite, then $|s| \le |t|$.
Nat.even_iff.mp
If a natural number is even, its remainder modulo 2 is 0.
Nat.odd_iff
A natural number is odd if and only if its remainder modulo 2 is 1.

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 even_graph_four_odd_component_bounds_has_perfect_matching    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (heven : Even (Nat.card V))    (hzero : ∀ S : Set V, S.ncard=0 →      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard = 0)    (hone : ∀ S : Set V, S.ncard=1 →      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 2)    (htwo : ∀ S : Set V, S.ncard=2 →      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 2)    (hthree : ∀ S : Set V, S.ncard=3 →      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 3)    (hall : ∀ S : Set V,      ((⊤ : G.Subgraph).deleteVerts S).coe.oddComponents.ncard ≤ 4) :    ∃ P : G.Subgraph, P.IsPerfectMatching := by  classical  by_contra hn  obtain ⟨S, hS⟩ := SimpleGraph.exists_isTutteViolator (G := G)    (fun M hM => hn ⟨M, hM⟩) heven  let W : Set V := ((⊤ : G.Subgraph).deleteVerts S).verts  let H := ((⊤ : G.Subgraph).deleteVerts S).coe  have hS' : S.ncard < H.oddComponents.ncard := hS  have hpar := SimpleGraph.odd_ncard_oddComponents H  have hcardW : Nat.card W = Fintype.card V - S.ncard := by    rw [Nat.card_coe_set_eq]    change (Set.univ \ S).ncard = _    rw [Set.ncard_diff (Set.subset_univ S), Set.ncard_univ, Nat.card_eq_fintype_card]  have hSle : S.ncard ≤ Fintype.card V := by    rw [← Nat.card_eq_fintype_card, ← Set.ncard_univ]    exact Set.ncard_le_ncard (Set.subset_univ S)  have hev : Fintype.card V % 2 = 0 := by    rw [← Nat.card_eq_fintype_card]; exact Nat.even_iff.mp heven  rw [hcardW, Nat.odd_iff, Nat.odd_iff] at hpar  by_cases hs0 : S.ncard=0  · have hh : H.oddComponents.ncard=0 := hzero S hs0    omega  · by_cases hs1 : S.ncard=1    · have hh : H.oddComponents.ncard ≤ 2 := hone S hs1      omega    · by_cases hs2 : S.ncard=2      · have hh : H.oddComponents.ncard ≤ 2 := htwo S hs2        omega      · by_cases hs3 : S.ncard=3        · have hh : H.oddComponents.ncard ≤ 3 := hthree S hs3          omega        · have hh : H.oddComponents.ncard ≤ 4 := hall S          omega
See it in the graphDiscuss this resultChallenge it