AFTD Auto-Formalizing Theoretical Domains

matching_large_part_two_nonneighbors_forces_four_switch

theoremverified

A perfect matching containing uv admits a four-switch when a large part A contains u, v sees all of A, u has an A-neighbor, and the five vertices outside A include v and two nonadjacent vertices missing all of A.

Statement

theorem matching_large_part_two_nonneighbors_forces_four_switch
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (P : G.Subgraph)
    (hP : P.IsPerfectMatching) (A : Finset V) (u v x y : V)
    (hu : u ∈ A) (hv : v ∉ A) (hx : x ∉ A) (hy : y ∉ A)
    (hcard : Fintype.card V = A.card+5) (hxy : x ≠ y) (hxv : x ≠ v) (hyv : y ≠ v)
    (huv : P.Adj u v) (hxyG : ¬ G.Adj x y)
    (hxA : ∀ a ∈ A, ¬ G.Adj x a) (hyA : ∀ a ∈ A, ¬ G.Adj y a)
    (hvA : ∀ a ∈ A, G.Adj v a) (huA : ∃ a ∈ A, G.Adj u a) :
    ∃ a b, Function.Injective (![u,v,a,b] : Fin 4 → V) ∧
      P.Adj a b ∧ G.Adj v a ∧ G.Adj u b
Source
OP-1957: general large-part form of the saturated residual-twin four-switch; experiment 34829 checks the five-part instance.
Verified
20 Nov 2026
Axioms
Classical.choiceQuot.soundpropext

The proof, explained

To find a 4-switch (u, v, a, b) with matching edge ab ∈ P and graph edges va, ub ∈ G, we first show that the 5-element complement V \ A consists precisely of v, the non-adjacent pair x, y, and their matching partners p, q. We then pick a neighbor b ∈ A of u and consider its matching partner a in P. By testing a against each of the five vertices outside A, we show that a cannot lie outside A without contradicting matching uniqueness or the non-adjacency of x, y to A, so a ∈ A. Since v sees all of A, the four distinct vertices u, v, a, b form the desired 4-switch.

  1. Any 4-tuple of pairwise distinct elements defines an injective map from Fin 4.

    To show that the tuple map ![a,b,c,d] : Fin 4 → V is injective, we consider two indices i and j with ![a,b,c,d] i = ![a,b,c,d] j. Exhaustive case analysis on all 16 index pairs (i, j) in Fin 4 × Fin 4 shows that whenever i = j the equality holds by reflexivity, while whenever i ≠ j the equality contradicts one of the six assumed pairwise distinctness hypotheses (hab, hac, had, hbc, hbd, hcd).

    lines 5–10

      intro i j hij
      fin_cases i <;> fin_cases j
      exacts [rfl, absurd hij hab, absurd hij hac, absurd hij had,
        absurd hij hab.symm, rfl, absurd hij hbc, absurd hij hbd,
        absurd hij hac.symm, absurd hij hbc.symm, rfl, absurd hij hcd,
        absurd hij had.symm, absurd hij hbd.symm, absurd hij hcd.symm, rfl]
  2. In the perfect matching P, matching partners are unique: if a is matched to both b and c in P, then b = c.

    Because P is a perfect matching (SimpleGraph.Subgraph.isPerfectMatching_iff.mp), each vertex is incident to exactly one edge in P, so any two matching edges sharing an endpoint must share both endpoints.

    lines 22–24

    uses SimpleGraph.Subgraph.isPerfectMatching_iff.mp

      classical
      have hmate : ∀ {a b c : V}, P.Adj a b → P.Adj a c → b = c :=
        fun {a b c} h1 h2 => (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP a).unique h1 h2
  3. The vertices x and y have matching partners p and q in P that lie outside A, with p ≠ x, q ≠ y, p ≠ y, and q ≠ x.

    By the perfect matching property, x and y have matching partners p and q in P. Since matching edges are graph edges in G (via P.adj_sub) and neither x nor y has any neighbors in A, neither p nor q can belong to A. Edges in a simple graph have distinct endpoints, so p ≠ x and q ≠ y. If p = y, then xy would be a matching edge and hence an edge in G, contradicting that x and y are non-adjacent in G; thus p ≠ y, and similarly q ≠ x.

    lines 25–32

    uses SimpleGraph.Subgraph.isPerfectMatching_iff.mp, P.adj_sub

      obtain ⟨p,hxp,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) x
      obtain ⟨q,hyq,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) y
      have hp : p ∉ A := fun h => hxA p h (P.adj_sub hxp)
      have hq : q ∉ A := fun h => hyA q h (P.adj_sub hyq)
      have hpx : p ≠ x := (P.adj_sub hxp).ne.symm
      have hqy : q ≠ y := (P.adj_sub hyq).ne.symm
      have hpy : p ≠ y := fun e => hxyG (e ▸ P.adj_sub hxp)
      have hqx : q ≠ x := fun e => hxyG ((e ▸ P.adj_sub hyq).symm)
  4. The matching partners p and q are both distinct from v, and p ≠ q.

    If p = v, then x is matched to v in P; since u is also matched to v in P, uniqueness of matching partners implies x = u, contradicting that u ∈ A while x ∉ A. The same argument gives q ≠ v. If p = q, then both x and y are matched to p, so x = y by uniqueness of partners, contradicting x ≠ y.

    lines 33–46

      have hpv : p ≠ v := by
        intro e
        subst p
        have h : x = u := hmate hxp.symm huv.symm
        exact hx (h ▸ hu)
      have hqv : q ≠ v := by
        intro e
        subst q
        have h : y = u := hmate hyq.symm huv.symm
        exact hy (h ▸ hu)
      have hpq : p ≠ q := by
        intro e
        subst q
        exact hxy (hmate hxp.symm hyq.symm)
  5. The complement C = V \ A has cardinality 5. automation

    The cardinality of the difference C = V \ A is |V| - |A ∩ V| = |V| - |A| by Finset.card_sdiff, Finset.inter_univ, and Finset.card_univ. Since |V| = |A| + 5 by hypothesis, linear arithmetic (omega) concludes |C| = 5.

    lines 47–52

    uses Finset.card_sdiff, Finset.inter_univ, Finset.card_univ

      let C : Finset V := Finset.univ \ A
      have hC : C.card = 5 := by
        dsimp [C]
        rw [Finset.card_sdiff]
        simp only [Finset.inter_univ, Finset.card_univ]
        omega
  6. The complement C is precisely the set {v, x, y, p, q}.

    The five vertices v, x, y, p, q all lie outside A and thus belong to C, establishing {v, x, y, p, q} ⊆ C using Finset.mem_insert and Finset.mem_singleton. Since all ten pairs among these five vertices are distinct (using Ne.symm where necessary), the set has cardinality 5. A subset of size 5 of a 5-element set is the entire set (Finset.eq_of_subset_of_card_le), so C = {v, x, y, p, q}.

    lines 53–62

    uses Finset.mem_insert, Finset.mem_singleton, Ne.symm, Finset.eq_of_subset_of_card_le

      have hsub : ({v,x,y,p,q} : Finset V) ⊆ C := by
        intro z hz
        simp only [Finset.mem_insert, Finset.mem_singleton] at hz
        rcases hz with rfl | rfl | rfl | rfl | rfl <;> simp [C, hv, hx, hy, hp, hq]
      have hfive : ({v,x,y,p,q} : Finset V).card = 5 := by
        simp [hxv, hyv, hxy, hpv, hpx, hpy, hqv, hqx, hqy, hpq,
          Ne.symm hxv, Ne.symm hyv, Ne.symm hxy, Ne.symm hpv, Ne.symm hpx,
          Ne.symm hpy, Ne.symm hqv, Ne.symm hqx, Ne.symm hqy, Ne.symm hpq]
      have hCeq : C = ({v,x,y,p,q} : Finset V) :=
        (Finset.eq_of_subset_of_card_le hsub (by rw [hC, hfive])).symm
  7. There is a neighbor b ∈ A of u with b ≠ u, and its matching partner a in P satisfies a ≠ b and a ≠ u.

    By hypothesis, u has a neighbor in A; choose b ∈ A with G.Adj u b. Since G is loopless, b ≠ u. Let a be the matching partner of b in P (SimpleGraph.Subgraph.isPerfectMatching_iff.mp). Since ab is an edge of G (P.adj_sub), a ≠ b. If a = u, then b is matched to u; but v is matched to u, so uniqueness of partners forces b = v, contradicting b ∈ A and v ∉ A. Thus a ≠ u.

    lines 63–72

    uses SimpleGraph.Subgraph.isPerfectMatching_iff.mp, P.adj_sub

      obtain ⟨b,hb,hub⟩ := huA
      have hbu : b ≠ u := hub.ne.symm
      obtain ⟨a,hba,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) b
      have hbaG := P.adj_sub hba
      have haba : a ≠ b := hbaG.ne.symm
      have hau : a ≠ u := by
        intro e
        subst a
        have h : b = v := hmate hba.symm huv
        exact hv (h ▸ hb)
  8. The matching partner a belongs to A.

    Suppose for contradiction that a ∉ A. Then a belongs to the complement C = {v, x, y, p, q}. We eliminate all five possibilities: if a = v, then b is matched to v, forcing b = u (since u is matched to v), which contradicts b ≠ u; if a = x or a = y, then b is a neighbor of x or y, contradicting that neither x nor y has neighbors in A; if a = p, then b is matched to p, forcing b = x (as x is matched to p), contradicting b ∈ A and x ∉ A; and if a = q, similarly b = y, contradicting b ∈ A and y ∉ A. Hence a ∈ A.

    lines 73–83

    uses Finset.mem_insert, Finset.mem_singleton

      have haA : a ∈ A := by
        by_contra ha
        have haC : a ∈ C := by simp [C, ha]
        rw [hCeq] at haC
        simp only [Finset.mem_insert, Finset.mem_singleton] at haC
        rcases haC with e | e | e | e | e
        · subst a; have h : b = u := hmate hba.symm huv.symm; exact hbu h
        · subst a; exact hxA b hb hbaG.symm
        · subst a; exact hyA b hb hbaG.symm
        · subst a; have h : b = x := hmate hba.symm hxp.symm; exact hx (h ▸ hb)
        · subst a; have h : b = y := hmate hba.symm hyq.symm; exact hy (h ▸ hb)
  9. The vertices a and b witness the required four-switch.

    Since a, b, u ∈ A while v ∉ A, v is distinct from each of a, b, u (using P.adj_sub for u ≠ v). Together with a ≠ b, a ≠ u, and b ≠ u, all six pairs of vertices among u, v, a, b are distinct, so the tuple map is injective by in1047_largepart_tuple4_injective. Furthermore, ab is a matching edge in P, va is an edge in G because a ∈ A and v is adjacent to all of A, and ub is an edge in G by choice of b.

    lines 84–88

    uses P.adj_sub, in1047_largepart_tuple4_injective

      have huvne : u ≠ v := (P.adj_sub huv).ne
      have hav : a ≠ v := fun e => hv (e ▸ haA)
      have hbv : b ≠ v := fun e => hv (e ▸ hb)
      exact ⟨a,b,in1047_largepart_tuple4_injective u v a b huvne hau.symm hbu.symm
        hav.symm hbv.symm haba, hba.symm, hvA a haA, hub⟩
SimpleGraph.Subgraph.isPerfectMatching_iff.mp
In a subgraph that is a perfect matching, every vertex has a unique incident matching edge.
P.adj_sub
An edge in the subgraph P is also an edge in the ambient graph G.
Finset.card_sdiff
The cardinality of the set difference t \ s equals the cardinality of t minus the cardinality of s ∩ t.
Finset.inter_univ
The intersection of any finite set with the universal set is the set itself.
Finset.card_univ
The cardinality of the universal finset on a finite type equals the cardinality of the type.
Finset.mem_insert
An element belongs to insert b s if and only if it equals b or belongs to s.
Finset.mem_singleton
An element belongs to the singleton {a} if and only if it equals a.
Ne.symm
Inequality is symmetric: if a ≠ b, then b ≠ a.
Finset.eq_of_subset_of_card_le
If a finite set s is a subset of t and |t| ≤ |s|, then s = t.
in1047_largepart_tuple4_injective
A 4-tuple of pairwise distinct elements defines an injective function from Fin 4.

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

private theorem in1047_largepart_tuple4_injective {V : Type*} (a b c d : V)    (hab : a ≠ b) (hac : a ≠ c) (had : a ≠ d)    (hbc : b ≠ c) (hbd : b ≠ d) (hcd : c ≠ d) :    Function.Injective (![a,b,c,d] : Fin 4 → V) := by  intro i j hij  fin_cases i <;> fin_cases j  exacts [rfl, absurd hij hab, absurd hij hac, absurd hij had,    absurd hij hab.symm, rfl, absurd hij hbc, absurd hij hbd,    absurd hij hac.symm, absurd hij hbc.symm, rfl, absurd hij hcd,    absurd hij had.symm, absurd hij hbd.symm, absurd hij hcd.symm, rfl]theorem matching_large_part_two_nonneighbors_forces_four_switch    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) (P : G.Subgraph)    (hP : P.IsPerfectMatching) (A : Finset V) (u v x y : V)    (hu : u ∈ A) (hv : v ∉ A) (hx : x ∉ A) (hy : y ∉ A)    (hcard : Fintype.card V = A.card+5) (hxy : x ≠ y) (hxv : x ≠ v) (hyv : y ≠ v)    (huv : P.Adj u v) (hxyG : ¬ G.Adj x y)    (hxA : ∀ a ∈ A, ¬ G.Adj x a) (hyA : ∀ a ∈ A, ¬ G.Adj y a)    (hvA : ∀ a ∈ A, G.Adj v a) (huA : ∃ a ∈ A, G.Adj u a) :    ∃ a b, Function.Injective (![u,v,a,b] : Fin 4 → V) ∧      P.Adj a b ∧ G.Adj v a ∧ G.Adj u b := by  classical  have hmate : ∀ {a b c : V}, P.Adj a b → P.Adj a c → b = c :=    fun {a b c} h1 h2 => (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP a).unique h1 h2  obtain ⟨p,hxp,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) x  obtain ⟨q,hyq,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) y  have hp : p ∉ A := fun h => hxA p h (P.adj_sub hxp)  have hq : q ∉ A := fun h => hyA q h (P.adj_sub hyq)  have hpx : p ≠ x := (P.adj_sub hxp).ne.symm  have hqy : q ≠ y := (P.adj_sub hyq).ne.symm  have hpy : p ≠ y := fun e => hxyG (e ▸ P.adj_sub hxp)  have hqx : q ≠ x := fun e => hxyG ((e ▸ P.adj_sub hyq).symm)  have hpv : p ≠ v := by    intro e    subst p    have h : x = u := hmate hxp.symm huv.symm    exact hx (h ▸ hu)  have hqv : q ≠ v := by    intro e    subst q    have h : y = u := hmate hyq.symm huv.symm    exact hy (h ▸ hu)  have hpq : p ≠ q := by    intro e    subst q    exact hxy (hmate hxp.symm hyq.symm)  let C : Finset V := Finset.univ \ A  have hC : C.card = 5 := by    dsimp [C]    rw [Finset.card_sdiff]    simp only [Finset.inter_univ, Finset.card_univ]    omega  have hsub : ({v,x,y,p,q} : Finset V) ⊆ C := by    intro z hz    simp only [Finset.mem_insert, Finset.mem_singleton] at hz    rcases hz with rfl | rfl | rfl | rfl | rfl <;> simp [C, hv, hx, hy, hp, hq]  have hfive : ({v,x,y,p,q} : Finset V).card = 5 := by    simp [hxv, hyv, hxy, hpv, hpx, hpy, hqv, hqx, hqy, hpq,      Ne.symm hxv, Ne.symm hyv, Ne.symm hxy, Ne.symm hpv, Ne.symm hpx,      Ne.symm hpy, Ne.symm hqv, Ne.symm hqx, Ne.symm hqy, Ne.symm hpq]  have hCeq : C = ({v,x,y,p,q} : Finset V) :=    (Finset.eq_of_subset_of_card_le hsub (by rw [hC, hfive])).symm  obtain ⟨b,hb,hub⟩ := huA  have hbu : b ≠ u := hub.ne.symm  obtain ⟨a,hba,_⟩ := (SimpleGraph.Subgraph.isPerfectMatching_iff.mp hP) b  have hbaG := P.adj_sub hba  have haba : a ≠ b := hbaG.ne.symm  have hau : a ≠ u := by    intro e    subst a    have h : b = v := hmate hba.symm huv    exact hv (h ▸ hb)  have haA : a ∈ A := by    by_contra ha    have haC : a ∈ C := by simp [C, ha]    rw [hCeq] at haC    simp only [Finset.mem_insert, Finset.mem_singleton] at haC    rcases haC with e | e | e | e | e    · subst a; have h : b = u := hmate hba.symm huv.symm; exact hbu h    · subst a; exact hxA b hb hbaG.symm    · subst a; exact hyA b hb hbaG.symm    · subst a; have h : b = x := hmate hba.symm hxp.symm; exact hx (h ▸ hb)    · subst a; have h : b = y := hmate hba.symm hyq.symm; exact hy (h ▸ hb)  have huvne : u ≠ v := (P.adj_sub huv).ne  have hav : a ≠ v := fun e => hv (e ▸ haA)  have hbv : b ≠ v := fun e => hv (e ▸ hb)  exact ⟨a,b,in1047_largepart_tuple4_injective u v a b huvne hau.symm hbu.symm    hav.symm hbv.symm haba, hba.symm, hvA a haA, hub⟩
See it in the graphDiscuss this resultChallenge it