AFTD Auto-Formalizing Theoretical Domains

maximum_matching_forbids_one_edge_two_uncovered_exchange

theoremverified

A maximum matching cannot contain an edge whose two endpoints have distinct uncovered neighbors.

Statement

theorem maximum_matching_forbids_one_edge_two_uncovered_exchange
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (S : Finset V) (M : G.Subgraph) (hM : M.IsMatching)
    (hMS : M.verts ⊆ (S : Set V))
    (hmax : ∀ T : G.Subgraph, T.IsMatching → T.verts ⊆ (S : Set V) → T.edgeSet.ncard ≤ M.edgeSet.ncard)
    (u v a b : V) (huS : u ∈ S) (hvS : v ∈ S)
    (hu : u ∉ M.verts) (hv : v ∉ M.verts) (huv : u ≠ v)
    (hab : M.Adj a b) (hua : G.Adj u a) (hvb : G.Adj v b) : False
Source
Maximum-matching exchange for OP-1957; https://arxiv.org/abs/1011.3384.
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
Used by 2

The proof, explained

Suppose for contradiction that a maximum matching M on S contains an edge {a, b} whose endpoints have distinct uncovered neighbors u and v in S. Deleting {a, b} from M leaves a residual matching D with one fewer edge that covers neither a nor b. Adding the two disjoint edges {u, a} and {v, b} yields a new matching D ⊔ E on S with |M| + 1 edges, contradicting the maximality of M.

  1. The endpoints a and b are distinct vertices covered by the matching M.

    Enable classical logic. Since (a, b) is an edge of M, both a and b are vertices of M. Moreover, since they are connected by an edge in the simple graph G, they are distinct (a ≠ b).

    lines 9–13

      set_option maxHeartbeats 4000000 in
        classical
        have haM : a ∈ M.verts := M.edge_vert hab
        have hbM : b ∈ M.verts := M.edge_vert hab.symm
        have habne : a ≠ b := G.ne_of_adj (M.adj_sub hab)
  2. Deleting the edge {a, b} from M produces a matching D whose vertices are contained in M.

    By residual_matching_num_single_edge_exchange_iff_critical_del, removing the single edge {a, b} from M yields a subgraph D that is also a matching, with edges D.edgeSet = M.edgeSet \ {{a, b}}. Every vertex in D is incident to some edge of D, which is also an edge of M, so D.verts ⊆ M.verts.

    lines 14–20

    uses residual_matching_num_single_edge_exchange_iff_critical_del, SimpleGraph.Subgraph.mem_edgeSet.mpr, SimpleGraph.Subgraph.mem_edgeSet.mp

        obtain ⟨D,hD,hDedge⟩ := residual_matching_num_single_edge_exchange_iff_critical_del hM ({s(a,b)} : Set (Sym2 V))
        have hDsub : D.verts ⊆ M.verts := by
          intro x hx
          obtain ⟨y,hxy,_⟩ := hD hx
          have hh : s(x,y) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hxy
          rw [hDedge] at hh
          exact M.edge_vert (SimpleGraph.Subgraph.mem_edgeSet.mp hh.1)
  3. Neither a nor b is a vertex in the residual matching D.

    If a were in D.verts, it would be incident to an edge {a, z} in D, which is also an edge in M. But in matching M, a is incident to b, so by uniqueness of matching partners, z = b. This would force {a, b} to be in D.edgeSet = M.edgeSet \ {{a, b}}, a contradiction. The exact same argument, using symmetry of unordered pairs (Sym2.eq_swap), shows b ∉ D.verts.

    lines 21–39

    uses SimpleGraph.Subgraph.mem_edgeSet.mpr, SimpleGraph.Subgraph.mem_edgeSet.mp, Sym2.eq_swap

        have haD : a ∉ D.verts := by
          intro ha
          obtain ⟨z,haz,_⟩ := hD ha
          have hh : s(a,z) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr haz
          rw [hDedge] at hh
          have hazM : M.Adj a z := SimpleGraph.Subgraph.mem_edgeSet.mp hh.1
          have hz : z=b := (hM haM).unique hazM hab
          subst z
          exact hh.2 (by simp)
        have hbD : b ∉ D.verts := by
          intro hb
          obtain ⟨z,hbz,_⟩ := hD hb
          have hh : s(b,z) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hbz
          rw [hDedge] at hh
          have hbzM : M.Adj b z := SimpleGraph.Subgraph.mem_edgeSet.mp hh.1
          have hz : z=a := (hM hbM).unique hbzM hab.symm
          subst z
          apply hh.2
          simp [Sym2.eq_swap]
  4. The residual matching D has exactly one fewer edge than M, so |D.edgeSet| + 1 = |M.edgeSet|.

    The edge {a, b} is in M.edgeSet, so the singleton {{a, b}} is a subset of the finite set M.edgeSet. Applying Set.ncard_sdiff_add_ncard_of_subset to {{a, b}} ⊆ M.edgeSet shows that |M.edgeSet \ {{a, b}}| + 1 = |M.edgeSet|.

    lines 40–44

    uses SimpleGraph.Subgraph.mem_edgeSet.mpr, Set.ncard_sdiff_add_ncard_of_subset, Set.toFinite

        have he : s(a,b) ∈ M.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hab
        have hcard : D.edgeSet.ncard + 1 = M.edgeSet.ncard := by
          have hs : ({s(a,b)} : Set (Sym2 V)) ⊆ M.edgeSet := by simpa using he
          have hh := Set.ncard_sdiff_add_ncard_of_subset hs (Set.toFinite M.edgeSet)
          simpa [← hDedge] using hh
  5. The two cross edges {u, a} and {v, b} form a 2-edge matching E on {u, v, a, b}.

    Define sequences f = ![u, v] and g = ![a, b]. Both f and g are injective because u ≠ v and a ≠ b. Their ranges are disjoint because u, v are uncovered by M while a, b belong to M.verts. Since u ~ a and v ~ b in G, indexed_disjoint_cross_edges_form_matching packages these two edges into a matching E with 2 edges and vertices {u, v, a, b}.

    lines 45–59

    uses indexed_disjoint_cross_edges_form_matching

        let f : Fin 2 → V := ![u,v]
        let g : Fin 2 → V := ![a,b]
        have hf : Function.Injective f := by
          intro i j hij
          fin_cases i <;> fin_cases j <;> simp_all [f]
        have hg : Function.Injective g := by
          intro i j hij
          fin_cases i <;> fin_cases j <;> simp_all [g]
        have hfg : ∀ i j, f i ≠ g j := by
          intro i j heq
          fin_cases i <;> fin_cases j <;> simp_all [f,g]
        have hadj : ∀ i, G.Adj (f i) (g i) := by
          intro i
          fin_cases i <;> simp_all [f,g]
        obtain ⟨E,hE,hEcard,hEverts⟩ := indexed_disjoint_cross_edges_form_matching G 2 f g hf hg hfg hadj
  6. The vertex sets of D and E are disjoint.

    Using Set.disjoint_left.mpr, we show no vertex of E can be in D. The vertices of E are {u, v, a, b}. Any vertex in {u, v} cannot be in D.verts because D.verts ⊆ M.verts and u, v ∉ M.verts. Neither a nor b can be in D.verts because both were shown to be excluded from D.

    lines 60–67

    uses Set.disjoint_left.mpr

        have hDE : Disjoint D.verts E.verts := by
          apply Set.disjoint_left.mpr
          intro x hxD hxE
          rw [hEverts] at hxE
          rcases hxE with ⟨i,hi⟩ | ⟨i,hi⟩
          · have hxM := hDsub hxD
            fin_cases i <;> simp_all [f]
          · fin_cases i <;> simp_all [g]
  7. The union D ⊔ E is a matching contained in S with |D.edgeSet| + 2 edges.

    By extendible_graph_matchable_deletion_inherits_extendibility_sup_ncard, the union of the vertex-disjoint matchings D and E is a matching whose size is |D.edgeSet| + |E.edgeSet| = |D.edgeSet| + 2. All vertices of D ⊔ E belong to S because D.verts ⊆ M.verts ⊆ S, u, v ∈ S by assumption, and a, b ∈ M.verts ⊆ S.

    lines 68–79

    uses extendible_graph_matchable_deletion_inherits_extendibility_sup_ncard

        have hsup := extendible_graph_matchable_deletion_inherits_extendibility_sup_ncard D E hD hE hDE
        have hsub : (D ⊔ E).verts ⊆ (S : Set V) := by
          intro x hx
          change x ∈ D.verts ∪ E.verts at hx
          rcases hx with hxD | hxE
          · exact hMS (hDsub hxD)
          · rw [hEverts] at hxE
            rcases hxE with ⟨i,hi⟩ | ⟨i,hi⟩
            · fin_cases i <;> simp_all [f]
            · have haS := hMS haM
              have hbS := hMS hbM
              fin_cases i <;> simp_all [g]
  8. Contradiction with the maximality of M.

    By the maximality of M among matchings contained in S, |(D ⊔ E).edgeSet| ≤ |M.edgeSet|. Substituting the computed cardinalities gives |D.edgeSet| + 2 ≤ |D.edgeSet| + 1, which omega refutes by linear integer arithmetic.

    lines 80–82

        have hh := hmax (D ⊔ E) hsup.1 hsub
        rw [hsup.2,hEcard] at hh
        omega
residual_matching_num_single_edge_exchange_iff_critical_del
Deleting any set of edges from a matching yields a subgraph that is also a matching, with those edges removed.
SimpleGraph.Subgraph.mem_edgeSet.mpr
If two vertices are adjacent in a subgraph, then the unordered pair connecting them belongs to its edge set.
SimpleGraph.Subgraph.mem_edgeSet.mp
If an unordered pair belongs to the edge set of a subgraph, then its endpoints are adjacent in that subgraph.
Sym2.eq_swap
An unordered pair is symmetric in its endpoints: s(a, b) = s(b, a).
Set.ncard_sdiff_add_ncard_of_subset
For any subset s of a finite set t, the cardinality of t \ s plus the cardinality of s equals the cardinality of t.
Set.toFinite
A set whose coerced subtype is finite is a finite set.
indexed_disjoint_cross_edges_form_matching
A family of disjoint edges connecting two injective, disjoint sequences of vertices forms a matching subgraph whose vertices are the endpoints.
Set.disjoint_left.mpr
Two sets are disjoint if no element of the first belongs to the second.
extendible_graph_matchable_deletion_inherits_extendibility_sup_ncard
The union of two vertex-disjoint matchings is a matching, and its edge count is the sum of their edge counts.

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 maximum_matching_forbids_one_edge_two_uncovered_exchange    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (S : Finset V) (M : G.Subgraph) (hM : M.IsMatching)    (hMS : M.verts ⊆ (S : Set V))    (hmax : ∀ T : G.Subgraph, T.IsMatching → T.verts ⊆ (S : Set V) → T.edgeSet.ncard ≤ M.edgeSet.ncard)    (u v a b : V) (huS : u ∈ S) (hvS : v ∈ S)    (hu : u ∉ M.verts) (hv : v ∉ M.verts) (huv : u ≠ v)    (hab : M.Adj a b) (hua : G.Adj u a) (hvb : G.Adj v b) : False := by  set_option maxHeartbeats 4000000 in    classical    have haM : a ∈ M.verts := M.edge_vert hab    have hbM : b ∈ M.verts := M.edge_vert hab.symm    have habne : a ≠ b := G.ne_of_adj (M.adj_sub hab)    obtain ⟨D,hD,hDedge⟩ := residual_matching_num_single_edge_exchange_iff_critical_del hM ({s(a,b)} : Set (Sym2 V))    have hDsub : D.verts ⊆ M.verts := by      intro x hx      obtain ⟨y,hxy,_⟩ := hD hx      have hh : s(x,y) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hxy      rw [hDedge] at hh      exact M.edge_vert (SimpleGraph.Subgraph.mem_edgeSet.mp hh.1)    have haD : a ∉ D.verts := by      intro ha      obtain ⟨z,haz,_⟩ := hD ha      have hh : s(a,z) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr haz      rw [hDedge] at hh      have hazM : M.Adj a z := SimpleGraph.Subgraph.mem_edgeSet.mp hh.1      have hz : z=b := (hM haM).unique hazM hab      subst z      exact hh.2 (by simp)    have hbD : b ∉ D.verts := by      intro hb      obtain ⟨z,hbz,_⟩ := hD hb      have hh : s(b,z) ∈ D.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hbz      rw [hDedge] at hh      have hbzM : M.Adj b z := SimpleGraph.Subgraph.mem_edgeSet.mp hh.1      have hz : z=a := (hM hbM).unique hbzM hab.symm      subst z      apply hh.2      simp [Sym2.eq_swap]    have he : s(a,b) ∈ M.edgeSet := SimpleGraph.Subgraph.mem_edgeSet.mpr hab    have hcard : D.edgeSet.ncard + 1 = M.edgeSet.ncard := by      have hs : ({s(a,b)} : Set (Sym2 V)) ⊆ M.edgeSet := by simpa using he      have hh := Set.ncard_sdiff_add_ncard_of_subset hs (Set.toFinite M.edgeSet)      simpa [← hDedge] using hh    let f : Fin 2 → V := ![u,v]    let g : Fin 2 → V := ![a,b]    have hf : Function.Injective f := by      intro i j hij      fin_cases i <;> fin_cases j <;> simp_all [f]    have hg : Function.Injective g := by      intro i j hij      fin_cases i <;> fin_cases j <;> simp_all [g]    have hfg : ∀ i j, f i ≠ g j := by      intro i j heq      fin_cases i <;> fin_cases j <;> simp_all [f,g]    have hadj : ∀ i, G.Adj (f i) (g i) := by      intro i      fin_cases i <;> simp_all [f,g]    obtain ⟨E,hE,hEcard,hEverts⟩ := indexed_disjoint_cross_edges_form_matching G 2 f g hf hg hfg hadj    have hDE : Disjoint D.verts E.verts := by      apply Set.disjoint_left.mpr      intro x hxD hxE      rw [hEverts] at hxE      rcases hxE with ⟨i,hi⟩ | ⟨i,hi⟩      · have hxM := hDsub hxD        fin_cases i <;> simp_all [f]      · fin_cases i <;> simp_all [g]    have hsup := extendible_graph_matchable_deletion_inherits_extendibility_sup_ncard D E hD hE hDE    have hsub : (D ⊔ E).verts ⊆ (S : Set V) := by      intro x hx      change x ∈ D.verts ∪ E.verts at hx      rcases hx with hxD | hxE      · exact hMS (hDsub hxD)      · rw [hEverts] at hxE        rcases hxE with ⟨i,hi⟩ | ⟨i,hi⟩        · fin_cases i <;> simp_all [f]        · have haS := hMS haM          have hbS := hMS hbM          fin_cases i <;> simp_all [g]    have hh := hmax (D ⊔ E) hsup.1 hsub    rw [hsup.2,hEcard] at hh    omega
See it in the graphDiscuss this resultChallenge it