AFTD Auto-Formalizing Theoretical Domains

forced_matching_edge_common_nonneighbor_degree_bound_is_bridge

theoremverified

A forced perfect-matching edge is a bridge if the number of its common nonneighbors is less than r and each common nonneighbor has degree at least r; no degree assumption is imposed on other vertices.

Statement

theorem forced_matching_edge_common_nonneighbor_degree_bound_is_bridge
    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj]
    (r : ℕ) (u v : V)
    (hdeg : ∀ x, (Gᶜ).Adj u x → (Gᶜ).Adj v x → r ≤ G.degree x) (huv : G.Adj u v)
    (hP : ∃ P : G.Subgraph, P.IsPerfectMatching ∧ P.Adj u v)
    (hforced : ¬ ∃ P : (G.deleteEdges {s(u,v)}).Subgraph, P.IsPerfectMatching)
    (hco : ({w | (Gᶜ).Adj u w ∧ (Gᶜ).Adj v w} : Set V).ncard < r) :
    ¬ (G.deleteEdges {s(u,v)}).Reachable u v
Source
OP-1957; localized strengthening of forced_matching_edge_common_nonneighbors_below_min_degree_is_bridge for the boundary residual route.
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1

The proof, explained

To prove that the forced edge uv is a bridge, we suppose for contradiction that u and v are connected in G' = G \ {uv}. Tutte's 1-factor theorem applied to G' yields a barrier S ⊆ V with strictly more than |S| odd components, and S cannot contain u or v because G has a 1-factor. Parity considerations show that G' - S has at least |S| + 2 odd components, so there is an odd component D that does not contain u or v and has no edges to either of them. All neighbors of any vertex x ∈ D outside S must remain inside D, giving deg(x) ≤ (|D| - 1) + |S| ≤ |C| < r, which contradicts the hypothesis that common non-neighbors have degree at least r.

  1. Supposing for contradiction that u and v are reachable in G' = G \ {uv}, Tutte's theorem yields a barrier S ⊆ V for G'.

    We assume for contradiction that u and v are connected by a path in G' = G \ {uv}. Since G has a 1-factor P containing uv, the total number of vertices |V| is even. By the forcedness hypothesis, G' has no 1-factor; hence by Tutte's 1-factor theorem (exists_isTutteViolator), there exists a Tutte violator S ⊆ V in G', meaning the number of odd components of G' - S strictly exceeds |S|.

    lines 9–18

    uses exists_isTutteViolator, Nat.card_eq_fintype_card, SimpleGraph.deleteEdges_adj, Sym2.eq_iff

      classical
      intro hreach
      obtain ⟨P, hPm, -⟩ := hP
      have hG'adj : ∀ x y, (G.deleteEdges {s(u,v)}).Adj x y ↔ G.Adj x y ∧ s(x, y) ≠ s(u, v) := by
        intro x y; simp [SimpleGraph.deleteEdges_adj]
      have hsym : ∀ x y : V, s(x, y) = s(u, v) → (x = u ∧ y = v) ∨ (x = v ∧ y = u) := by
        intro x y h; simpa [Sym2.eq_iff] using h
      have heven : Even (Nat.card V) := by rw [Nat.card_eq_fintype_card]; exact hPm.even_card
      obtain ⟨S, hS⟩ := exists_isTutteViolator (G := G.deleteEdges {s(u,v)})
        (fun M hM => hforced ⟨M, hM⟩) heven
  2. Neither u nor v belongs to S.

    If u ∈ S or v ∈ S, deleting S from G also removes the edge uv, which means the vertex-deleted subgraph G - S is identical to G' - S. But then S would also be a Tutte violator in G, contradicting the existence of the 1-factor P in G (not_isTutteViolator_of_isPerfectMatching). Thus u ∉ S and v ∉ S.

    lines 19–44

    uses not_isTutteViolator_of_isPerfectMatching

      -- u and v are not in S
      have hnotS : ¬ (u ∈ S ∨ v ∈ S) := by
        intro huvS
        apply not_isTutteViolator_of_isPerfectMatching hPm S
        unfold IsTutteViolator at hS ⊢
        have heq : ((⊤ : G.Subgraph).deleteVerts S).coe =
            ((⊤ : (G.deleteEdges {s(u,v)}).Subgraph).deleteVerts S).coe := by
          ext x y
          change (_ ∧ _ ∧ G.Adj x.1 y.1) ↔ (_ ∧ _ ∧ (G.deleteEdges {s(u,v)}).Adj x.1 y.1)
          constructor
          · rintro ⟨hx, hy, hxy⟩
            refine ⟨hx, hy, (hG'adj _ _).mpr ⟨hxy, fun he => ?_⟩⟩
            have hx' : x.1 ∉ S := hx.2
            have hy' : y.1 ∉ S := hy.2
            rcases hsym _ _ he with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;>
              rcases huvS with h | h
            · exact hx' (h1 ▸ h)
            · exact hy' (h2 ▸ h)
            · exact hy' (h2 ▸ h)
            · exact hx' (h1 ▸ h)
          · rintro ⟨hx, hy, hxy⟩
            exact ⟨hx, hy, ((hG'adj _ _).mp hxy).1⟩
        rw [heq]
        exact hS
      have huS : u ∉ S := fun h => hnotS (Or.inl h)
      have hvS : v ∉ S := fun h => hnotS (Or.inr h)
  3. In the induced subgraph H = G'[V \ S], u and v have connected components cu and cv.

    We define W = V \ S and consider the induced subgraph H = G'[W]. Since u, v ∉ S, both vertices belong to W, and we denote their connected components in H by cu and cv.

    lines 45–59

      set G' := G.deleteEdges {s(u,v)} with hG'def
      let W : Set V := ((⊤ : G'.Subgraph).deleteVerts S).verts
      let H := ((⊤ : G'.Subgraph).deleteVerts S).coe
      have hHadj : ∀ x y : W, H.Adj x y ↔ G'.Adj x.1 y.1 := by
        intro x y
        change (_ ∧ _ ∧ G'.Adj x.1 y.1) ↔ _
        exact ⟨fun h => h.2.2, fun h => ⟨x.2, y.2, h⟩⟩
      have hW : ∀ x : V, x ∈ W ↔ x ∉ S := by
        intro x
        change x ∈ (Set.univ \ S) ↔ _
        simp
      let uW : W := ⟨u, (hW u).2 huS⟩
      let vW : W := ⟨v, (hW v).2 hvS⟩
      let cu := H.connectedComponentMk uW
      let cv := H.connectedComponentMk vW
  4. The induced subgraph H has at least |S| + 2 odd components.

    By parity (odd_ncard_oddComponents), the number of odd components of H has the same parity as |W| = |V| - |S|. Since |V| is even, |W| ≡ |S| (mod 2), so the number of odd components of H has the same parity as |S|. Since S is a Tutte violator, the number of odd components strictly exceeds |S|, and having the same parity rules out |S| + 1, so H has at least |S| + 2 odd components.

    lines 60–77

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

      have hS' : S.ncard < H.oddComponents.ncard := hS
      -- parity: at least |S| + 2 odd components
      have hpar := 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
      have hN : S.ncard + 2 ≤ H.oddComponents.ncard := by
        by_contra hlt
        have h1 : H.oddComponents.ncard = S.ncard + 1 := by omega
        rw [h1] at hpar
        omega
  5. The set A of odd components of H avoiding cu and cv has cardinality at least |S| and is non-empty, yielding an odd component D ∈ A.

    Since {cu, cv} contains at most 2 components, the set A of odd components excluding cu and cv has size at least (|S| + 2) - 2 = |S|. If |S| > 0, then |A| ≥ |S| > 0. If |S| = 0, then S is empty, so H = G'; by the reachability assumption, u and v are connected in G', which implies cu = cv, so {cu, cv} has size 1. In this case |A| ≥ 2 - 1 = 1 > 0. Thus in either case |A| > 0, so there is at least one odd component D ∈ A.

    lines 78–106

    uses Set.ncard_union_le, Set.ncard_insert_le, Set.ncard_singleton, Nat.eq_zero_or_pos, Set.ncard_eq_zero, Set.toFinite, Set.notMem_empty, ConnectedComponent.eq.mpr, Set.pair_eq_singleton, Set.nonempty_of_ncard_ne_zero

      -- the odd components avoiding u and v
      let A := H.oddComponents \ {cu, cv}
      have hAle : H.oddComponents.ncard ≤ A.ncard + ({cu, cv} : Set H.ConnectedComponent).ncard := by
        calc H.oddComponents.ncard ≤ (A ∪ {cu, cv}).ncard := by
              apply Set.ncard_le_ncard _ (Set.toFinite _)
              intro c hc
              by_cases h : c ∈ ({cu, cv} : Set H.ConnectedComponent)
              · exact Or.inr h
              · exact Or.inl ⟨hc, h⟩
          _ ≤ A.ncard + ({cu, cv} : Set H.ConnectedComponent).ncard := Set.ncard_union_le _ _
      have hpair : ({cu, cv} : Set H.ConnectedComponent).ncard ≤ 2 := by
        calc ({cu, cv} : Set H.ConnectedComponent).ncard ≤ ({cv} : Set H.ConnectedComponent).ncard + 1 :=
              Set.ncard_insert_le _ _
          _ = 2 := by rw [Set.ncard_singleton]
      have hAs : S.ncard ≤ A.ncard := by omega
      have hApos : 0 < A.ncard := by
        rcases Nat.eq_zero_or_pos S.ncard with h0 | hpos
        · have hS0 : S = ∅ := (Set.ncard_eq_zero (Set.toFinite S)).mp h0
          have hcucv : cu = cv := by
            let φ : G' →g H :=
              { toFun := fun x => ⟨x, (hW x).2 (by rw [hS0]; exact Set.notMem_empty x)⟩
                map_rel' := fun {x y} h => (hHadj _ _).2 h }
            have hr : H.Reachable (φ u) (φ v) := hreach.map φ
            exact ConnectedComponent.eq.mpr hr
          have h1 : ({cu, cv} : Set H.ConnectedComponent).ncard = 1 := by
            rw [hcucv, Set.pair_eq_singleton, Set.ncard_singleton]
          omega
        · omega
      obtain ⟨D, hDA⟩ := Set.nonempty_of_ncard_ne_zero (Nat.pos_iff_ne_zero.mp hApos)
  6. Any vertex in a component of H distinct from cu and cv is neither u nor v and is non-adjacent in G to both u and v.

    If a vertex x in such a component were u or v, its component would be cu or cv. If x were adjacent to u in G, then since x ≠ u and x ≠ v, the edge xu cannot be the deleted edge uv, so xu is an edge in G' and in H. But then x would be reachable from u in H, implying its component is cu, a contradiction. Symmetrically, x cannot be adjacent to v in G.

    lines 107–147

    uses ConnectedComponent.mem_supp_iff, Subtype.ext, congrArg, ConnectedComponent.eq.mpr, SimpleGraph.Adj.reachable, Set.mem_insert_iff, Set.mem_singleton_iff

      -- vertices of components other than cu, cv
      have hfar : ∀ c : H.ConnectedComponent, c ≠ cu → c ≠ cv → ∀ x : W, x ∈ c.supp →
          x.1 ≠ u ∧ x.1 ≠ v ∧ ¬ G.Adj x.1 u ∧ ¬ G.Adj x.1 v := by
        intro c hcu hcv x hx
        rw [ConnectedComponent.mem_supp_iff] at hx
        have hxu : x.1 ≠ u := by
          intro h
          apply hcu
          rw [← hx]
          exact congrArg H.connectedComponentMk (Subtype.ext h)
        have hxv : x.1 ≠ v := by
          intro h
          apply hcv
          rw [← hx]
          exact congrArg H.connectedComponentMk (Subtype.ext h)
        refine ⟨hxu, hxv, ?_, ?_⟩
        · intro hadj
          apply hcu
          rw [← hx]
          apply ConnectedComponent.eq.mpr
          apply SimpleGraph.Adj.reachable
          rw [hHadj]
          refine (hG'adj _ _).mpr ⟨hadj, fun he => ?_⟩
          rcases hsym _ _ he with ⟨h1, -⟩ | ⟨h1, -⟩
          · exact hxu h1
          · exact hxv h1
        · intro hadj
          apply hcv
          rw [← hx]
          apply ConnectedComponent.eq.mpr
          apply SimpleGraph.Adj.reachable
          rw [hHadj]
          refine (hG'adj _ _).mpr ⟨hadj, fun he => ?_⟩
          rcases hsym _ _ he with ⟨h1, -⟩ | ⟨h1, -⟩
          · exact hxu h1
          · exact hxv h1
      have hDodd : D ∈ H.oddComponents := hDA.1
      have hDne : D ≠ cu ∧ D ≠ cv := by
        have h := hDA.2
        simp only [Set.mem_insert_iff, Set.mem_singleton_iff, not_or] at h
        exact h
  7. Every vertex of each component in A is a common non-neighbor of u and v, and |D| + (|A| - 1) ≤ |C|.

    By the separation property, every vertex in any component of A belongs to the set C of common non-neighbors of u and v. Choosing one representative vertex from each component in A \ {D} yields a set of size |A| - 1 that is disjoint from the vertex set of D (since distinct components are disjoint). Because both D and these representatives lie in C, we obtain |D| + (|A| - 1) ≤ |C|.

    lines 148–187

    uses compl_adj, Ne.symm, ConnectedComponent.mem_supp_iff, Subtype.ext, Set.disjoint_left, Set.mem_singleton_iff, Set.mem_insert_iff, Set.ncard_le_ncard, Set.toFinite, Set.ncard_union_eq, Set.ncard_image_of_injOn, Set.ncard_sdiff_singleton_of_mem

      -- the common non-neighbour set
      let C : Set V := {w | (Gᶜ).Adj u w ∧ (Gᶜ).Adj v w}
      have hinC : ∀ c : H.ConnectedComponent, c ≠ cu → c ≠ cv → ∀ x : W, x ∈ c.supp → x.1 ∈ C := by
        intro c hcu hcv x hx
        obtain ⟨hxu, hxv, hau, hav⟩ := hfar c hcu hcv x hx
        exact ⟨(compl_adj G u x.1).2 ⟨Ne.symm hxu, fun h => hau h.symm⟩,
          (compl_adj G v x.1).2 ⟨Ne.symm hxv, fun h => hav h.symm⟩⟩
      -- a representative of every component
      have hrep : ∀ c : H.ConnectedComponent, ∃ x : W, x ∈ c.supp := fun c => c.nonempty_supp
      choose rep hrep using hrep
      let Dset : Set V := Subtype.val '' D.supp
      let R : Set V := (fun c => (rep c).1) '' (A \ {D})
      have hRinj : Set.InjOn (fun c => (rep c).1) (A \ {D}) := by
        intro c _ c' _ h
        have h1 := hrep c
        have h2 := hrep c'
        rw [ConnectedComponent.mem_supp_iff] at h1 h2
        have : rep c = rep c' := Subtype.ext h
        rw [← h1, ← h2, this]
      have hdisj : Disjoint Dset R := by
        rw [Set.disjoint_left]
        rintro z ⟨x, hx, rfl⟩ ⟨c, hc, hcz⟩
        have h1 := hrep c
        have hx' := hx
        rw [ConnectedComponent.mem_supp_iff] at h1 hx'
        have : rep c = x := Subtype.ext hcz
        apply hc.2
        rw [Set.mem_singleton_iff, ← h1, this, hx']
      have hsubC : Dset ∪ R ⊆ C := by
        rintro z (⟨x, hx, rfl⟩ | ⟨c, hc, rfl⟩)
        · exact hinC D hDne.1 hDne.2 x hx
        · have hcA := hc.1
          have hcne := hcA.2
          simp only [Set.mem_insert_iff, Set.mem_singleton_iff, not_or] at hcne
          exact hinC c hcne.1 hcne.2 (rep c) (hrep c)
      have hCcard : Dset.ncard + (A.ncard - 1) ≤ C.ncard := by
        have h1 := Set.ncard_le_ncard hsubC (Set.toFinite C)
        rw [Set.ncard_union_eq hdisj (Set.toFinite _) (Set.toFinite _),
          Set.ncard_image_of_injOn hRinj, Set.ncard_sdiff_singleton_of_mem hDA] at h1
        exact h1
  8. Every vertex x in D has degree at most (|D| - 1) + |S| in G.

    Any neighbor y of x in G either lies in S or in W = V \ S. If y ∈ W, then because x ∈ D avoids u and v, the edge xy is not uv, so xy belongs to G' and hence to H. Consequently, y must lie in the same component of H as x, which is D. Since y ≠ x, y belongs to D \ {x}. Hence the entire neighborhood of x in G is contained in (D \ {x}) ∪ S, yielding deg_G(x) ≤ (|D| - 1) + |S|.

    lines 188–218

    uses SimpleGraph.mem_neighborSet, ConnectedComponent.mem_supp_iff, ConnectedComponent.eq.mpr, SimpleGraph.Adj.reachable, Set.mem_singleton_iff, Set.ncard_le_ncard, Set.toFinite, Set.ncard_union_le, Set.ncard_sdiff_singleton_of_mem, Set.ncard_eq_toFinset_card', SimpleGraph.card_neighborFinset_eq_degree, SimpleGraph.neighborFinset_eq_filter

      -- degree bound inside D
      obtain ⟨x, hxD⟩ := D.nonempty_supp
      have hnb : G.neighborSet x.1 ⊆ (Dset \ {x.1}) ∪ S := by
        intro y hy
        rw [SimpleGraph.mem_neighborSet] at hy
        by_cases hyS : y ∈ S
        · exact Or.inr hyS
        · left
          obtain ⟨hxu, hxv, -, -⟩ := hfar D hDne.1 hDne.2 x hxD
          refine ⟨⟨⟨y, (hW y).2 hyS⟩, ?_, rfl⟩, ?_⟩
          · rw [ConnectedComponent.mem_supp_iff] at hxD ⊢
            rw [← hxD]
            apply ConnectedComponent.eq.mpr
            apply SimpleGraph.Adj.reachable
            rw [hHadj]
            refine (hG'adj _ _).mpr ⟨hy.symm, fun he => ?_⟩
            rcases hsym _ _ he with ⟨-, h1⟩ | ⟨-, h1⟩
            · exact hxv h1
            · exact hxu h1
          · rw [Set.mem_singleton_iff]
            exact fun h => hy.ne h.symm
      have hdegx : G.degree x.1 ≤ (Dset.ncard - 1) + S.ncard := by
        have h1 := Set.ncard_le_ncard hnb (Set.toFinite _)
        have h2 := Set.ncard_union_le (Dset \ {x.1}) S
        have hxmem : x.1 ∈ Dset := ⟨x, hxD, rfl⟩
        rw [Set.ncard_sdiff_singleton_of_mem hxmem] at h2
        have h3 : (G.neighborSet x.1).ncard = G.degree x.1 := by
          rw [Set.ncard_eq_toFinset_card', ← SimpleGraph.card_neighborFinset_eq_degree,
            SimpleGraph.neighborFinset_eq_filter]
          simp
        omega
  9. A contradiction is reached from the degree bound on x ∈ D and the small number of common non-neighbors.

    Picking any vertex x in the non-empty component D, x is a common non-neighbor of u and v, so the hypothesis hdeg gives r ≤ deg_G(x). Chain the inequalities: r ≤ deg_G(x) ≤ (|D| - 1) + |S| ≤ (|D| - 1) + |A| ≤ |C| < r. This gives r < r, an immediate arithmetic contradiction.

    lines 219–223

    uses Set.ncard_pos, Set.toFinite

      have hDpos : 0 < Dset.ncard := Set.ncard_pos (Set.toFinite _) |>.mpr ⟨x.1, x, hxD, rfl⟩
      have hxC := hinC D hDne.1 hDne.2 x hxD
      have := hdeg x.1 hxC.1 hxC.2
      have hco' : C.ncard < r := hco
      omega
exists_isTutteViolator
If a finite graph of even order has no 1-factor, there exists a Tutte violator S such that |S| < c_odd(G - S)
Nat.card_eq_fintype_card
For a finite type, the general cardinality Nat.card equals Fintype.card
SimpleGraph.deleteEdges_adj
An edge exists in G \ s if and only if it is an edge in G and not in s
Sym2.eq_iff
Two unordered pairs s(x, y) and s(z, w) are equal iff (x = z ∧ y = w) ∨ (x = w ∧ y = z)
not_isTutteViolator_of_isPerfectMatching
A graph containing a 1-factor has no Tutte violator
odd_ncard_oddComponents
The number of odd components in a finite graph has the same parity as the total number of vertices
Nat.card_coe_set_eq
The Nat.card of a set coerced to a subtype equals its set cardinality ncard
Set.ncard_diff
If s ⊆ t and s is finite, then |t \ s| = |t| - |s|
Set.subset_univ
Any set is a subset of the universal set
Set.ncard_univ
The cardinality of the universal set is the cardinality of the type
Set.ncard_le_ncard
If s ⊆ t and t is finite, then |s| ≤ |t|
Nat.even_iff
A natural number is even if and only if its remainder modulo 2 is 0
Nat.odd_iff
A natural number is odd if and only if its remainder modulo 2 is 1
Set.ncard_union_le
The cardinality of s ∪ t is at most |s| + |t|
Set.ncard_insert_le
Inserting one element into a set increases its cardinality by at most 1
Set.ncard_singleton
A singleton set has cardinality 1
Nat.eq_zero_or_pos
Every natural number is either zero or strictly positive
Set.ncard_eq_zero
A finite set has cardinality 0 if and only if it is empty
Set.toFinite
A set whose subtype is finite is finite
Set.notMem_empty
No element belongs to the empty set
ConnectedComponent.eq.mpr
If two vertices are reachable from each other, their connected components are equal
Set.pair_eq_singleton
The doubleton {a, a} equals the singleton {a}
Set.nonempty_of_ncard_ne_zero
A set of non-zero cardinality is non-empty
ConnectedComponent.mem_supp_iff
A vertex belongs to the support of a component iff its component is that component
Subtype.ext
Two subtype elements are equal if their underlying values are equal
congrArg
A function applied to equal arguments yields equal values
SimpleGraph.Adj.reachable
Adjacent vertices are reachable from one another
Set.mem_insert_iff
An element belongs to insert a s iff it equals a or belongs to s
Set.mem_singleton_iff
An element belongs to {b} iff it equals b
compl_adj
Two vertices are adjacent in the complement graph iff they are distinct and non-adjacent in the graph
Ne.symm
Inequality is symmetric: if a ≠ b then b ≠ a
Set.disjoint_left
Two sets are disjoint iff no element of the first belongs to the second
Set.ncard_union_eq
The cardinality of the union of disjoint finite sets is the sum of their cardinalities
Set.ncard_image_of_injOn
The image of a set under an injective map has the same cardinality as the domain set
Set.ncard_sdiff_singleton_of_mem
Removing an element that belongs to a set decreases its cardinality by 1
SimpleGraph.mem_neighborSet
A vertex belongs to the neighborhood of v iff it is adjacent to v
Set.ncard_eq_toFinset_card'
The set cardinality ncard equals the card of the associated Finset
SimpleGraph.card_neighborFinset_eq_degree
The cardinality of the neighbor Finset of v equals the degree of v
SimpleGraph.neighborFinset_eq_filter
The neighbor Finset of v is the set of all vertices adjacent to v
Set.ncard_pos
A finite set has cardinality > 0 iff it is non-empty

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 forced_matching_edge_common_nonneighbor_degree_bound_is_bridge    {V : Type*} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj]    (r : ℕ) (u v : V)    (hdeg : ∀ x, (Gᶜ).Adj u x → (Gᶜ).Adj v x → r ≤ G.degree x) (huv : G.Adj u v)    (hP : ∃ P : G.Subgraph, P.IsPerfectMatching ∧ P.Adj u v)    (hforced : ¬ ∃ P : (G.deleteEdges {s(u,v)}).Subgraph, P.IsPerfectMatching)    (hco : ({w | (Gᶜ).Adj u w ∧ (Gᶜ).Adj v w} : Set V).ncard < r) :    ¬ (G.deleteEdges {s(u,v)}).Reachable u v := open SimpleGraph in by  classical  intro hreach  obtain ⟨P, hPm, -⟩ := hP  have hG'adj : ∀ x y, (G.deleteEdges {s(u,v)}).Adj x y ↔ G.Adj x y ∧ s(x, y) ≠ s(u, v) := by    intro x y; simp [SimpleGraph.deleteEdges_adj]  have hsym : ∀ x y : V, s(x, y) = s(u, v) → (x = u ∧ y = v) ∨ (x = v ∧ y = u) := by    intro x y h; simpa [Sym2.eq_iff] using h  have heven : Even (Nat.card V) := by rw [Nat.card_eq_fintype_card]; exact hPm.even_card  obtain ⟨S, hS⟩ := exists_isTutteViolator (G := G.deleteEdges {s(u,v)})    (fun M hM => hforced ⟨M, hM⟩) heven  -- u and v are not in S  have hnotS : ¬ (u ∈ S ∨ v ∈ S) := by    intro huvS    apply not_isTutteViolator_of_isPerfectMatching hPm S    unfold IsTutteViolator at hS ⊢    have heq : ((⊤ : G.Subgraph).deleteVerts S).coe =        ((⊤ : (G.deleteEdges {s(u,v)}).Subgraph).deleteVerts S).coe := by      ext x y      change (_ ∧ _ ∧ G.Adj x.1 y.1) ↔ (_ ∧ _ ∧ (G.deleteEdges {s(u,v)}).Adj x.1 y.1)      constructor      · rintro ⟨hx, hy, hxy⟩        refine ⟨hx, hy, (hG'adj _ _).mpr ⟨hxy, fun he => ?_⟩⟩        have hx' : x.1 ∉ S := hx.2        have hy' : y.1 ∉ S := hy.2        rcases hsym _ _ he with ⟨h1, h2⟩ | ⟨h1, h2⟩ <;>          rcases huvS with h | h        · exact hx' (h1 ▸ h)        · exact hy' (h2 ▸ h)        · exact hy' (h2 ▸ h)        · exact hx' (h1 ▸ h)      · rintro ⟨hx, hy, hxy⟩        exact ⟨hx, hy, ((hG'adj _ _).mp hxy).1⟩    rw [heq]    exact hS  have huS : u ∉ S := fun h => hnotS (Or.inl h)  have hvS : v ∉ S := fun h => hnotS (Or.inr h)  set G' := G.deleteEdges {s(u,v)} with hG'def  let W : Set V := ((⊤ : G'.Subgraph).deleteVerts S).verts  let H := ((⊤ : G'.Subgraph).deleteVerts S).coe  have hHadj : ∀ x y : W, H.Adj x y ↔ G'.Adj x.1 y.1 := by    intro x y    change (_ ∧ _ ∧ G'.Adj x.1 y.1) ↔ _    exact ⟨fun h => h.2.2, fun h => ⟨x.2, y.2, h⟩⟩  have hW : ∀ x : V, x ∈ W ↔ x ∉ S := by    intro x    change x ∈ (Set.univ \ S) ↔ _    simp  let uW : W := ⟨u, (hW u).2 huS⟩  let vW : W := ⟨v, (hW v).2 hvS⟩  let cu := H.connectedComponentMk uW  let cv := H.connectedComponentMk vW  have hS' : S.ncard < H.oddComponents.ncard := hS  -- parity: at least |S| + 2 odd components  have hpar := 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  have hN : S.ncard + 2 ≤ H.oddComponents.ncard := by    by_contra hlt    have h1 : H.oddComponents.ncard = S.ncard + 1 := by omega    rw [h1] at hpar    omega  -- the odd components avoiding u and v  let A := H.oddComponents \ {cu, cv}  have hAle : H.oddComponents.ncard ≤ A.ncard + ({cu, cv} : Set H.ConnectedComponent).ncard := by    calc H.oddComponents.ncard ≤ (A ∪ {cu, cv}).ncard := by          apply Set.ncard_le_ncard _ (Set.toFinite _)          intro c hc          by_cases h : c ∈ ({cu, cv} : Set H.ConnectedComponent)          · exact Or.inr h          · exact Or.inl ⟨hc, h⟩      _ ≤ A.ncard + ({cu, cv} : Set H.ConnectedComponent).ncard := Set.ncard_union_le _ _  have hpair : ({cu, cv} : Set H.ConnectedComponent).ncard ≤ 2 := by    calc ({cu, cv} : Set H.ConnectedComponent).ncard ≤ ({cv} : Set H.ConnectedComponent).ncard + 1 :=          Set.ncard_insert_le _ _      _ = 2 := by rw [Set.ncard_singleton]  have hAs : S.ncard ≤ A.ncard := by omega  have hApos : 0 < A.ncard := by    rcases Nat.eq_zero_or_pos S.ncard with h0 | hpos    · have hS0 : S = ∅ := (Set.ncard_eq_zero (Set.toFinite S)).mp h0      have hcucv : cu = cv := by        let φ : G' →g H :=          { toFun := fun x => ⟨x, (hW x).2 (by rw [hS0]; exact Set.notMem_empty x)⟩            map_rel' := fun {x y} h => (hHadj _ _).2 h }        have hr : H.Reachable (φ u) (φ v) := hreach.map φ        exact ConnectedComponent.eq.mpr hr      have h1 : ({cu, cv} : Set H.ConnectedComponent).ncard = 1 := by        rw [hcucv, Set.pair_eq_singleton, Set.ncard_singleton]      omega    · omega  obtain ⟨D, hDA⟩ := Set.nonempty_of_ncard_ne_zero (Nat.pos_iff_ne_zero.mp hApos)  -- vertices of components other than cu, cv  have hfar : ∀ c : H.ConnectedComponent, c ≠ cu → c ≠ cv → ∀ x : W, x ∈ c.supp →      x.1 ≠ u ∧ x.1 ≠ v ∧ ¬ G.Adj x.1 u ∧ ¬ G.Adj x.1 v := by    intro c hcu hcv x hx    rw [ConnectedComponent.mem_supp_iff] at hx    have hxu : x.1 ≠ u := by      intro h      apply hcu      rw [← hx]      exact congrArg H.connectedComponentMk (Subtype.ext h)    have hxv : x.1 ≠ v := by      intro h      apply hcv      rw [← hx]      exact congrArg H.connectedComponentMk (Subtype.ext h)    refine ⟨hxu, hxv, ?_, ?_⟩    · intro hadj      apply hcu      rw [← hx]      apply ConnectedComponent.eq.mpr      apply SimpleGraph.Adj.reachable      rw [hHadj]      refine (hG'adj _ _).mpr ⟨hadj, fun he => ?_⟩      rcases hsym _ _ he with ⟨h1, -⟩ | ⟨h1, -⟩      · exact hxu h1      · exact hxv h1    · intro hadj      apply hcv      rw [← hx]      apply ConnectedComponent.eq.mpr      apply SimpleGraph.Adj.reachable      rw [hHadj]      refine (hG'adj _ _).mpr ⟨hadj, fun he => ?_⟩      rcases hsym _ _ he with ⟨h1, -⟩ | ⟨h1, -⟩      · exact hxu h1      · exact hxv h1  have hDodd : D ∈ H.oddComponents := hDA.1  have hDne : D ≠ cu ∧ D ≠ cv := by    have h := hDA.2    simp only [Set.mem_insert_iff, Set.mem_singleton_iff, not_or] at h    exact h  -- the common non-neighbour set  let C : Set V := {w | (Gᶜ).Adj u w ∧ (Gᶜ).Adj v w}  have hinC : ∀ c : H.ConnectedComponent, c ≠ cu → c ≠ cv → ∀ x : W, x ∈ c.supp → x.1 ∈ C := by    intro c hcu hcv x hx    obtain ⟨hxu, hxv, hau, hav⟩ := hfar c hcu hcv x hx    exact ⟨(compl_adj G u x.1).2 ⟨Ne.symm hxu, fun h => hau h.symm⟩,      (compl_adj G v x.1).2 ⟨Ne.symm hxv, fun h => hav h.symm⟩⟩  -- a representative of every component  have hrep : ∀ c : H.ConnectedComponent, ∃ x : W, x ∈ c.supp := fun c => c.nonempty_supp  choose rep hrep using hrep  let Dset : Set V := Subtype.val '' D.supp  let R : Set V := (fun c => (rep c).1) '' (A \ {D})  have hRinj : Set.InjOn (fun c => (rep c).1) (A \ {D}) := by    intro c _ c' _ h    have h1 := hrep c    have h2 := hrep c'    rw [ConnectedComponent.mem_supp_iff] at h1 h2    have : rep c = rep c' := Subtype.ext h    rw [← h1, ← h2, this]  have hdisj : Disjoint Dset R := by    rw [Set.disjoint_left]    rintro z ⟨x, hx, rfl⟩ ⟨c, hc, hcz⟩    have h1 := hrep c    have hx' := hx    rw [ConnectedComponent.mem_supp_iff] at h1 hx'    have : rep c = x := Subtype.ext hcz    apply hc.2    rw [Set.mem_singleton_iff, ← h1, this, hx']  have hsubC : Dset ∪ R ⊆ C := by    rintro z (⟨x, hx, rfl⟩ | ⟨c, hc, rfl⟩)    · exact hinC D hDne.1 hDne.2 x hx    · have hcA := hc.1      have hcne := hcA.2      simp only [Set.mem_insert_iff, Set.mem_singleton_iff, not_or] at hcne      exact hinC c hcne.1 hcne.2 (rep c) (hrep c)  have hCcard : Dset.ncard + (A.ncard - 1) ≤ C.ncard := by    have h1 := Set.ncard_le_ncard hsubC (Set.toFinite C)    rw [Set.ncard_union_eq hdisj (Set.toFinite _) (Set.toFinite _),      Set.ncard_image_of_injOn hRinj, Set.ncard_sdiff_singleton_of_mem hDA] at h1    exact h1  -- degree bound inside D  obtain ⟨x, hxD⟩ := D.nonempty_supp  have hnb : G.neighborSet x.1 ⊆ (Dset \ {x.1}) ∪ S := by    intro y hy    rw [SimpleGraph.mem_neighborSet] at hy    by_cases hyS : y ∈ S    · exact Or.inr hyS    · left      obtain ⟨hxu, hxv, -, -⟩ := hfar D hDne.1 hDne.2 x hxD      refine ⟨⟨⟨y, (hW y).2 hyS⟩, ?_, rfl⟩, ?_⟩      · rw [ConnectedComponent.mem_supp_iff] at hxD ⊢        rw [← hxD]        apply ConnectedComponent.eq.mpr        apply SimpleGraph.Adj.reachable        rw [hHadj]        refine (hG'adj _ _).mpr ⟨hy.symm, fun he => ?_⟩        rcases hsym _ _ he with ⟨-, h1⟩ | ⟨-, h1⟩        · exact hxv h1        · exact hxu h1      · rw [Set.mem_singleton_iff]        exact fun h => hy.ne h.symm  have hdegx : G.degree x.1 ≤ (Dset.ncard - 1) + S.ncard := by    have h1 := Set.ncard_le_ncard hnb (Set.toFinite _)    have h2 := Set.ncard_union_le (Dset \ {x.1}) S    have hxmem : x.1 ∈ Dset := ⟨x, hxD, rfl⟩    rw [Set.ncard_sdiff_singleton_of_mem hxmem] at h2    have h3 : (G.neighborSet x.1).ncard = G.degree x.1 := by      rw [Set.ncard_eq_toFinset_card', ← SimpleGraph.card_neighborFinset_eq_degree,        SimpleGraph.neighborFinset_eq_filter]      simp    omega  have hDpos : 0 < Dset.ncard := Set.ncard_pos (Set.toFinite _) |>.mpr ⟨x.1, x, hxD, rfl⟩  have hxC := hinC D hDne.1 hDne.2 x hxD  have := hdeg x.1 hxC.1 hxC.2  have hco' : C.ncard < r := hco  omega
See it in the graphDiscuss this resultChallenge it