AFTD Auto-Formalizing Theoretical Domains

two_common_neighbor_twins_matching_restricts_to_remainder

theoremverified

Suppose a perfect matching contains uv, the vertices outside S are the four distinct vertices x,y,p,q, and x and y each have precisely p,q as their graph neighbors. If u,v lie in S, then S minus u,v induces a perfect matching.

Statement

theorem two_common_neighbor_twins_matching_restricts_to_remainder
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)
    (P : G.Subgraph) (hP : P.IsPerfectMatching)
    (S : Finset V) (x y p q u v : V)
    (hdistinct : ([x, y, p, q] : List V).Nodup)
    (hdisj : Disjoint S ({x, y, p, q} : Finset V))
    (hcover : S ∪ {x, y, p, q} = Finset.univ)
    (hu : u ∈ S) (hv : v ∈ S) (huv : P.Adj u v)
    (hx : ∀ z, G.Adj x z ↔ z = p ∨ z = q)
    (hy : ∀ z, G.Adj y z ↔ z = p ∨ z = q) :
    ∃ M : (G.induce {a | a ∈ S ∧ a ≠ u ∧ a ≠ v}).Subgraph,
      M.IsPerfectMatching
Source
First equality-witness residual matching restriction in the OP-1957 two-bridge campaign.
Verified
20 Nov 2026
Axioms
Classical.choiceQuot.soundpropext

The proof, explained

The proof first establishes an auxiliary lemma: because x and y are distinct twins whose only neighbors are p and q, the perfect matching P on G must match {x, y, p, q} entirely within itself. To show that the remaining vertices R = S \ {u, v} induce a perfect matching, we restrict P to G[R]. For any vertex z ∈ R, its matched neighbor w in P cannot lie outside S (since {x, y, p, q} is matched to itself and disjoint from S), nor can w be u or v (since u and v are already matched to each other in P). Therefore w ∈ R, which proves that every vertex of R has a unique matched neighbor in R.

  1. x ≠ y

    Since the list [x, y, p, q] contains no duplicate elements, its first two elements x and y must be distinct.

    lines 9–11

    uses List.nodup_cons, List.mem_cons, not_or

      have hxy : x ≠ y := by
        simp only [List.nodup_cons, List.mem_cons, not_or] at hdistinct
        exact hdistinct.1.1
  2. x and y have distinct matched partners wx and wy in P, each belonging to {p, q}

    Since P is a perfect matching, x and y have unique matched neighbors wx and wy in P. Because P is a subgraph of G, these edges are also edges of G, so by the neighborhood condition on x and y, both wx and wy must be in {p, q}. Furthermore, wx ≠ wy because otherwise the vertex wx would be incident to two distinct edges in the matching P (connecting to x and y with x ≠ y), which contradicts the definition of a matching.

    lines 12–22

    uses SimpleGraph.Subgraph.isPerfectMatching_iff

      have hP_mat := hP.1
      rw [SimpleGraph.Subgraph.isPerfectMatching_iff] at hP
      obtain ⟨wx, hxwx, hx_uniq⟩ := hP x
      obtain ⟨wy, hywy, hy_uniq⟩ := hP y
      have hwx_adj : G.Adj x wx := P.adj_sub hxwx
      have hwy_adj : G.Adj y wy := P.adj_sub hywy
      rw [hx] at hwx_adj
      rw [hy] at hwy_adj
      have hwx_ne_wy : wx ≠ wy := by
        rintro rfl
        exact hxy (hP_mat.eq_of_adj_right hxwx hywy)
  3. Any edge of P incident to a vertex in {x, y, p, q} has its other endpoint in {x, y, p, q}

    Let w ∈ {x, y, p, q} and suppose P contains an edge between w and z. We analyze the four possible values of w: if w = x, uniqueness of matching partners implies z = wx ∈ {p, q}; if w = y, then z = wy ∈ {p, q}; if w = p or w = q, since wx and wy are distinct elements of {p, q}, one of them must equal w, meaning w is matched in P to x or y, so by matching uniqueness z must be x or y. In all cases, z lies in {x, y, p, q}.

    lines 23–45

    uses Finset.mem_insert, Finset.mem_singleton

      intro w hw z hz
      simp only [Finset.mem_insert, Finset.mem_singleton] at hw
      rcases hw with rfl | rfl | rfl | rfl
      · have : z = wx := hx_uniq z hz
        rw [this]
        rcases hwx_adj with rfl | rfl <;> simp
      · have : z = wy := hy_uniq z hz
        rw [this]
        rcases hwy_adj with rfl | rfl <;> simp
      · rcases hwx_adj with rfl | rfl
        · have : z = x := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hxwx)
          simp [this]
        · rcases hwy_adj with rfl | rfl
          · have : z = y := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hywy)
            simp [this]
          · exact (hwx_ne_wy rfl).elim
      · rcases hwx_adj with rfl | rfl
        · rcases hwy_adj with rfl | rfl
          · exact (hwx_ne_wy rfl).elim
          · have : z = y := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hywy)
            simp [this]
        · have : z = x := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hxwx)
          simp [this]
  4. The four vertices {x, y, p, q} are matched only to each other in P

    We apply the auxiliary lemma two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched to G, P, and the vertices x, y, p, q, using the assumptions that they are distinct and that x and y share neighborhood {p, q}.

    lines 59–60

    uses two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched

      have h4 := two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched
        G P hP x y p q hdistinct hx hy
  5. We define the candidate subgraph M on G[R], where R = S \ {u, v}, inheriting adjacency from P

    Let R be the set of vertices in S other than u and v. We define the subgraph M of the induced subgraph G[R] with full vertex set R and edges inherited from P, and propose M as the witness for the existential goal.

    lines 61–69

    uses Set.mem_univ

      let R : Set V := {a | a ∈ S ∧ a ≠ u ∧ a ≠ v}
      let M : (G.induce R).Subgraph := {
        verts := Set.univ
        Adj a b := P.Adj a.1 b.1
        adj_sub := fun h => P.adj_sub h
        edge_vert := fun _ => Set.mem_univ _
        symm := ⟨fun _ _ h => P.symm.symm _ _ h⟩
      }
      use M
  6. To show M is a perfect matching, it suffices to find for every z ∈ R a unique neighbor in M; let w be the unique neighbor of z in P

    By SimpleGraph.Subgraph.isPerfectMatching_iff, M is a perfect matching if and only if each vertex of R has a unique neighbor in M. For any z ∈ R, the fact that P is a perfect matching on G gives a unique partner w ∈ V adjacent to z in P.

    lines 70–73

    uses SimpleGraph.Subgraph.isPerfectMatching_iff

      have hP_mat := hP.1
      rw [SimpleGraph.Subgraph.isPerfectMatching_iff] at hP ⊢
      rintro ⟨z, hz_mem, hz_u, hz_v⟩
      obtain ⟨w, hzw, hw_uniq⟩ := hP z
  7. The matched partner w of z belongs to S

    Suppose for contradiction that w ∉ S. Since S ∪ {x, y, p, q} = V, w must belong to {x, y, p, q}. By our lemma on {x, y, p, q}, any neighbor of w in P must also belong to {x, y, p, q}, which forces z ∈ {x, y, p, q}. But z ∈ S and S is disjoint from {x, y, p, q}, a contradiction.

    lines 74–82

    uses Finset.mem_univ, Finset.mem_union, Finset.disjoint_right.mp

      have hw_S : w ∈ S := by
        by_contra hw_not_S
        have hw_univ : w ∈ S ∪ ({x, y, p, q} : Finset V) := by rw [hcover]; exact Finset.mem_univ w
        simp only [Finset.mem_union] at hw_univ
        have hw_in_4 : w ∈ ({x, y, p, q} : Finset V) := hw_univ.resolve_left hw_not_S
        have hz_in_4 := h4 w hw_in_4 z (P.symm.symm _ _ hzw)
        have hz_4_finset : z ∈ ({x, y, p, q} : Finset V) := by
          rcases hz_in_4 with rfl | rfl | rfl | rfl <;> simp
        exact Finset.disjoint_right.mp hdisj hz_4_finset hz_mem
  8. w ≠ u and w ≠ v, hence w ∈ R

    If w = u, then P contains edges between z and u as well as between u and v; since P is a matching, this forces z = v, contradicting z ∈ R (which requires z ≠ v). Similarly, if w = v, then matching uniqueness forces z = u, contradicting z ≠ u. Since w ∈ S, w ≠ u, and w ≠ v, we have w ∈ R.

    lines 83–91

      have hw_u : w ≠ u := by
        rintro rfl
        have : z = v := hP_mat.eq_of_adj_left (P.symm.symm _ _ hzw) huv
        exact hz_v this
      have hw_v : w ≠ v := by
        rintro rfl
        have : z = u := hP_mat.eq_of_adj_left (P.symm.symm _ _ hzw) (P.symm.symm _ _ huv)
        exact hz_u this
      have hw_R : w ∈ R := ⟨hw_S, hw_u, hw_v⟩
  9. w is the unique neighbor of z in M, concluding that M is a perfect matching

    The vertex w ∈ R is adjacent to z in M because P contains the edge zw. If any other w' ∈ R were adjacent to z in M, it would also be adjacent in P, forcing w' = w by uniqueness of matching partners in P. By Subtype.ext, the corresponding elements of the subtype R are equal.

    lines 92–95

    uses Subtype.ext

      use ⟨w, hw_R⟩
      refine ⟨hzw, ?_⟩
      rintro ⟨w', hw'_R⟩ hw'_adj
      exact Subtype.ext (hw_uniq w' hw'_adj)
List.nodup_cons
A list with head a and tail l has no duplicates if and only if a does not occur in l and l has no duplicates.
List.mem_cons
An element belongs to the list b :: l if and only if it equals b or belongs to l.
not_or
The negation of a disjunction p ∨ q is equivalent to ¬p ∧ ¬q.
SimpleGraph.Subgraph.isPerfectMatching_iff
A subgraph is a perfect matching if and only if every vertex in the graph has a unique neighbor in the subgraph.
Finset.mem_insert
An element belongs to the finset insert b s if and only if it equals b or belongs to s.
Finset.mem_singleton
An element belongs to the singleton finset {a} if and only if it equals a.
two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched
If x, y, p, q are distinct vertices such that x and y only have p and q as neighbors, then any edge in a perfect matching incident to {x, y, p, q} has both endpoints in {x, y, p, q}.
Set.mem_univ
Every element of a type belongs to the universal set Set.univ.
Finset.mem_univ
Every element of a finite type belongs to the universal finset Finset.univ.
Finset.mem_union
An element belongs to the union of two finsets s ∪ t if and only if it belongs to s or to t.
Finset.disjoint_right.mp
If two finsets are disjoint, any element in the second finset does not belong to the first.
Subtype.ext
Two elements of a subtype are equal if their underlying values are equal.

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

lemma two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched    {V : Type*} [DecidableEq V] (G : SimpleGraph V)    (P : G.Subgraph) (hP : P.IsPerfectMatching)    (x y p q : V)    (hdistinct : ([x, y, p, q] : List V).Nodup)    (hx : ∀ z, G.Adj x z ↔ z = p ∨ z = q)    (hy : ∀ z, G.Adj y z ↔ z = p ∨ z = q) :    ∀ w ∈ ({x, y, p, q} : Finset V), ∀ z, P.Adj w z → z = x ∨ z = y ∨ z = p ∨ z = q := by  have hxy : x ≠ y := by    simp only [List.nodup_cons, List.mem_cons, not_or] at hdistinct    exact hdistinct.1.1  have hP_mat := hP.1  rw [SimpleGraph.Subgraph.isPerfectMatching_iff] at hP  obtain ⟨wx, hxwx, hx_uniq⟩ := hP x  obtain ⟨wy, hywy, hy_uniq⟩ := hP y  have hwx_adj : G.Adj x wx := P.adj_sub hxwx  have hwy_adj : G.Adj y wy := P.adj_sub hywy  rw [hx] at hwx_adj  rw [hy] at hwy_adj  have hwx_ne_wy : wx ≠ wy := by    rintro rfl    exact hxy (hP_mat.eq_of_adj_right hxwx hywy)  intro w hw z hz  simp only [Finset.mem_insert, Finset.mem_singleton] at hw  rcases hw with rfl | rfl | rfl | rfl  · have : z = wx := hx_uniq z hz    rw [this]    rcases hwx_adj with rfl | rfl <;> simp  · have : z = wy := hy_uniq z hz    rw [this]    rcases hwy_adj with rfl | rfl <;> simp  · rcases hwx_adj with rfl | rfl    · have : z = x := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hxwx)      simp [this]    · rcases hwy_adj with rfl | rfl      · have : z = y := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hywy)        simp [this]      · exact (hwx_ne_wy rfl).elim  · rcases hwx_adj with rfl | rfl    · rcases hwy_adj with rfl | rfl      · exact (hwx_ne_wy rfl).elim      · have : z = y := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hywy)        simp [this]    · have : z = x := hP_mat.eq_of_adj_left hz (P.symm.symm _ _ hxwx)      simp [this]theorem two_common_neighbor_twins_matching_restricts_to_remainder    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V)    (P : G.Subgraph) (hP : P.IsPerfectMatching)    (S : Finset V) (x y p q u v : V)    (hdistinct : ([x, y, p, q] : List V).Nodup)    (hdisj : Disjoint S ({x, y, p, q} : Finset V))    (hcover : S ∪ {x, y, p, q} = Finset.univ)    (hu : u ∈ S) (hv : v ∈ S) (huv : P.Adj u v)    (hx : ∀ z, G.Adj x z ↔ z = p ∨ z = q)    (hy : ∀ z, G.Adj y z ↔ z = p ∨ z = q) :    ∃ M : (G.induce {a | a ∈ S ∧ a ≠ u ∧ a ≠ v}).Subgraph,      M.IsPerfectMatching := by  have h4 := two_common_neighbor_twins_matching_restricts_to_remainder_four_verts_matched    G P hP x y p q hdistinct hx hy  let R : Set V := {a | a ∈ S ∧ a ≠ u ∧ a ≠ v}  let M : (G.induce R).Subgraph := {    verts := Set.univ    Adj a b := P.Adj a.1 b.1    adj_sub := fun h => P.adj_sub h    edge_vert := fun _ => Set.mem_univ _    symm := ⟨fun _ _ h => P.symm.symm _ _ h⟩  }  use M  have hP_mat := hP.1  rw [SimpleGraph.Subgraph.isPerfectMatching_iff] at hP ⊢  rintro ⟨z, hz_mem, hz_u, hz_v⟩  obtain ⟨w, hzw, hw_uniq⟩ := hP z  have hw_S : w ∈ S := by    by_contra hw_not_S    have hw_univ : w ∈ S ∪ ({x, y, p, q} : Finset V) := by rw [hcover]; exact Finset.mem_univ w    simp only [Finset.mem_union] at hw_univ    have hw_in_4 : w ∈ ({x, y, p, q} : Finset V) := hw_univ.resolve_left hw_not_S    have hz_in_4 := h4 w hw_in_4 z (P.symm.symm _ _ hzw)    have hz_4_finset : z ∈ ({x, y, p, q} : Finset V) := by      rcases hz_in_4 with rfl | rfl | rfl | rfl <;> simp    exact Finset.disjoint_right.mp hdisj hz_4_finset hz_mem  have hw_u : w ≠ u := by    rintro rfl    have : z = v := hP_mat.eq_of_adj_left (P.symm.symm _ _ hzw) huv    exact hz_v this  have hw_v : w ≠ v := by    rintro rfl    have : z = u := hP_mat.eq_of_adj_left (P.symm.symm _ _ hzw) (P.symm.symm _ _ huv)    exact hz_u this  have hw_R : w ∈ R := ⟨hw_S, hw_u, hw_v⟩  use ⟨w, hw_R⟩  refine ⟨hzw, ?_⟩  rintro ⟨w', hw'_R⟩ hw'_adj  exact Subtype.ext (hw_uniq w' hw'_adj)
See it in the graphDiscuss this resultChallenge it