AFTD Auto-Formalizing Theoretical Domains

finite_subset_has_maximum_matching

theoremverified

Every vertex subset of a finite graph contains a maximum matching.

Statement

theorem finite_subset_has_maximum_matching
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (S : Finset V) :
    ∃ M : G.Subgraph, M.IsMatching ∧ M.verts ⊆ (S : Set V) ∧
      ∀ N : G.Subgraph, N.IsMatching → N.verts ⊆ (S : Set V) → N.edgeSet.ncard ≤ M.edgeSet.ncard
Source
Balanced-cut matching symmetry for OP-1957; https://arxiv.org/abs/2611.22690.
Verified
26 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2
Used by 10

The proof, explained

The proof defines a predicate P(n) asserting the existence of a matching within S having n edges. Since every matching satisfies 2|E| = |V| ≤ |S|, the number of edges in any matching on S cannot exceed |S|. The empty subgraph witnesses P(0), so the greatest size k ≤ |S| satisfying P is obtained via Nat.findGreatest; any matching M witnessing P(k) is maximum, as a larger matching on S would contradict the maximality of k.

  1. Define a predicate P(n) asserting the existence of an n-edge matching supported on S.

    Under classical logic, define P(n) to be the proposition that there exists a subgraph M of G that is a matching, has all its vertices in S, and has exactly n edges.

    lines 5–7

      set_option maxHeartbeats 4000000 in
        classical
        let P : ℕ → Prop := fun n => ∃ M : G.Subgraph, M.IsMatching ∧ M.verts ⊆ (S : Set V) ∧ M.edgeSet.ncard = n
  2. P(0) holds, witnessed by the empty subgraph.

    The empty subgraph ⊥ has no vertices and no edges. Thus, it vacuously satisfies the matching condition, its vertices are trivially contained in S, and its edge set has cardinality 0.

    lines 8–13

        have hzero : P 0 := by
          refine ⟨⊥,?_,?_,?_⟩
          · intro v hv
            simp at hv
          · simp
          · simp
  3. There exists a valid matching M attaining the maximum edge count bounded by |S|, which serves as the candidate maximum matching.

    Since 0 ≤ |S| and P(0) holds, Nat.findGreatest_spec ensures that P holds at the maximal value k ≤ |S| satisfying P, namely Nat.findGreatest P |S|. We unpack this to obtain a matching M with k edges, and propose M as the witness, reducing the goal to showing that M has at least as many edges as any other valid matching.

    lines 14–16

    uses Nat.findGreatest_spec

        have hP : P (Nat.findGreatest P S.card) := Nat.findGreatest_spec (by omega : 0 ≤ S.card) hzero
        obtain ⟨M,hM,hMS,hMcard⟩ := hP
        refine ⟨M,hM,hMS,?_⟩
  4. Any matching N whose vertices lie in S has at most |S| edges.

    Let N be any matching with vertices in S. By in1076_matching_twice_card, 2 * |E(N)| = |V(N)|. Since V(N) ⊆ S and S is finite, Set.ncard_le_ncard, Set.toFinite, and Set.ncard_coe_finset show that |V(N)| ≤ |S|. Combining these gives 2 * |E(N)| ≤ |S|, which implies |E(N)| ≤ |S| by linear arithmetic.

    lines 17–22

    uses in1076_matching_twice_card, Set.ncard_le_ncard, Set.toFinite, Set.ncard_coe_finset

        intro N hN hNS
        have hNbound : N.edgeSet.ncard ≤ S.card := by
          have he := in1076_matching_twice_card hN
          have hv := Set.ncard_le_ncard hNS (Set.toFinite _)
          rw [Set.ncard_coe_finset] at hv
          omega
  5. Every valid matching N satisfies |E(N)| ≤ |E(M)|, completing the proof.

    Suppose for contradiction that |E(N)| > |E(M)|. Since |E(M)| = Nat.findGreatest P |S| and |E(N)| ≤ |S|, Nat.findGreatest_is_greatest implies that P(|E(N)|) is false. However, N witnesses that P(|E(N)|) is true, giving a contradiction.

    lines 23–26

    uses Nat.findGreatest_is_greatest

        by_contra hn
        have hgt : Nat.findGreatest P S.card < N.edgeSet.ncard := by omega
        have hno := Nat.findGreatest_is_greatest hgt hNbound
        exact hno ⟨N,hN,hNS,rfl⟩
Nat.findGreatest_spec
If a predicate P on ℕ holds at some m ≤ n, then P holds at the largest integer ≤ n satisfying P (given by Nat.findGreatest P n).
in1076_matching_twice_card
In any matching in a finite graph, the number of vertices is twice the number of edges.
Set.ncard_le_ncard
If a subset s is contained in a finite set t, then the cardinality of s is at most the cardinality of t.
Set.toFinite
A set is finite if its corresponding subtype is finite.
Set.ncard_coe_finset
The cardinality of a coerced Finset as a Set equals its cardinality as a Finset.
Nat.findGreatest_is_greatest
Any integer k ≤ n strictly greater than Nat.findGreatest P n does not satisfy P.

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 finite_subset_has_maximum_matching    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (S : Finset V) :    ∃ M : G.Subgraph, M.IsMatching ∧ M.verts ⊆ (S : Set V) ∧      ∀ N : G.Subgraph, N.IsMatching → N.verts ⊆ (S : Set V) → N.edgeSet.ncard ≤ M.edgeSet.ncard := by  set_option maxHeartbeats 4000000 in    classical    let P : ℕ → Prop := fun n => ∃ M : G.Subgraph, M.IsMatching ∧ M.verts ⊆ (S : Set V) ∧ M.edgeSet.ncard = n    have hzero : P 0 := by      refine ⟨⊥,?_,?_,?_⟩      · intro v hv        simp at hv      · simp      · simp    have hP : P (Nat.findGreatest P S.card) := Nat.findGreatest_spec (by omega : 0 ≤ S.card) hzero    obtain ⟨M,hM,hMS,hMcard⟩ := hP    refine ⟨M,hM,hMS,?_⟩    intro N hN hNS    have hNbound : N.edgeSet.ncard ≤ S.card := by      have he := in1076_matching_twice_card hN      have hv := Set.ncard_le_ncard hNS (Set.toFinite _)      rw [Set.ncard_coe_finset] at hv      omega    by_contra hn    have hgt : Nat.findGreatest P S.card < N.edgeSet.ncard := by omega    have hno := Nat.findGreatest_is_greatest hgt hNbound    exact hno ⟨N,hN,hNS,rfl⟩
See it in the graphDiscuss this resultChallenge it