AFTD Auto-Formalizing Theoretical Domains

op874_external_color_class_lower_bound

theoremverified

For every color in a strong six-color truncation state on a finite loopless cubic multigraph, at least one sixth of the base vertices' number of external edges have that color. The bound is attained in small simple bridgeless examples.

Statement

theorem op874_external_color_class_lower_bound
    {V E Ω : Type*} [Fintype V] [Fintype E] [Fintype Ω]
    [DecidableEq V] [DecidableEq E] [DecidableEq Ω]
    (hΩ : Fintype.card Ω = 6)
    (ends : E → Sym2 V) (left right : E → V)
    (hends : ∀ e, ends e = s(left e,right e))
    (hloop : ∀ e, left e ≠ right e)
    (hcubic : ∀ v, Set.ncard {e | v ∈ ends e} = 3)
    (c h : V → E → Ω)
    (hc : ∀ v e f, v ∈ ends e → v ∈ ends f → c v e = c v f → e = f)
    (hcons : ∀ e, c (left e) e = c (right e) e)
    (hh : ∀ v e f, v ∈ ends e → v ∈ ends f → h v e = h v f → e = f)
    (hch : ∀ v e f, v ∈ ends e → v ∈ ends f → h v e ≠ c v f)
    (hs : truncation_local_states_define_strong_coloring ends c h)
    (a : Ω) :
    Fintype.card V ≤ 6 * (Finset.univ.filter (fun e : E => c (left e) e = a)).card
Source
Local-state criterion for OP-874, https://arxiv.org/abs/2610.41950, Section 2.
Verified
28 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2

The proof, explained

The theorem establishes that in any strong 6-color truncation state on a finite loopless cubic graph, each color $a \in \Omega$ appears on at least $|V|/6$ external edges. Let $M$ be the set of external edges of color $a$, let $R$ be their endpoints, and let $S = V \setminus R$ be the remaining vertices. Because edge colors are proper at each vertex, $M$ forms a matching, so $|R| = 2|M|$, and since $S$ contains no endpoints of edges of color $a$, a prior lemma shows that the induced subgraph on $S$ has $|E_S| \le |S|$ edges. A double-counting argument for the edge cut between $S$ and $R$ yields the balance equation $3|S| + 2|E_R| = 3|R| + 2|E_S|$. Substituting $|E_R| \ge |M|$, $|E_S| \le |S|$, and $|R| = 2|M|$ implies $|S| \le 4|M|$, which together with $|V| = |S| + |R|$ produces $|V| \le 6|M|$.

  1. Define the set $M$ of color-$a$ edges, their endpoint set $R$, the complement $S = V \setminus R$, and the induced edge sets $E_S$ and $E_R$.

    We let $M$ be the set of edges of color $a$, $R$ be the set of endpoints of edges in $M$, $S = V \setminus R$ be the set of vertices not incident to any color-$a$ edge, $E_S$ be the edges with both endpoints in $S$, and $E_R$ be the edges with both endpoints in $R$.

    lines 17–23

      open Finset in
      let M := univ.filter (fun e : E => c (left e) e = a)
      let R := M.biUnion (fun e => {left e, right e})
      let S := univ \ R
      let ES := univ.filter (fun e => left e ∈ S ∧ right e ∈ S)
      let ER := univ.filter (fun e => left e ∈ R ∧ right e ∈ R)
    
  2. $|R| = 2|M|$; that is, $M$ is a matching, so each edge in $M$ contributes two distinct endpoints to $R$.

    By assumption `hloop`, every edge has distinct endpoints, so each edge's pair of endpoints has cardinality 2 (`card_pair`). Furthermore, the pairs of endpoints for distinct edges in $M$ are disjoint (`Finset.disjoint_left`): if two distinct edges in $M$ shared a vertex $v$, both edges would have color $a$ at $v$, contradicting the local coloring condition `hc` that all edges incident to $v$ receive distinct colors. Thus, the union of endpoint pairs is a disjoint union, giving $|R| = 2|M|$ (`card_biUnion`, `sum_congr`).

    lines 24–48

    uses card_biUnion, card_pair, Finset.disjoint_left, sum_congr

      have hR : R.card = 2 * M.card := by
        rw [card_biUnion]
        · have : (∑ u ∈ M, ({left u, right u} : Finset V).card) = ∑ u ∈ M, 2 := by
            refine sum_congr rfl (fun e he => ?_)
            rw [card_pair (hloop e)]
          rw [this, sum_const, smul_eq_mul, mul_comm]
        · intro e1 he1 e2 he2 hne
          dsimp [Function.onFun]
          rw [mem_coe, mem_filter] at he1 he2
          rw [Finset.disjoint_left]
          intro v hv1 hv2
          rw [mem_insert, mem_singleton] at hv1 hv2
          have h1 : v ∈ ends e1 := by rw [hends]; rcases hv1 with rfl | rfl <;> simp
          have h2 : v ∈ ends e2 := by rw [hends]; rcases hv2 with rfl | rfl <;> simp
          have hc1 : c v e1 = a := by
            rcases hv1 with rfl | rfl
            · exact he1.2
            · rw [← hcons e1]; exact he1.2
          have hc2 : c v e2 = a := by
            rcases hv2 with rfl | rfl
            · exact he2.2
            · rw [← hcons e2]; exact he2.2
          have heq : e1 = e2 := hc v e1 e2 h1 h2 (hc1.trans hc2.symm)
          exact hne heq
    
  3. $|M| \le |E_R|$.

    By definition of $R$, both endpoints of every edge $e \in M$ belong to $R$. Thus $M \subseteq E_R$, so $|M| \le |E_R|$ (`card_le_card`).

    lines 49–58

    uses card_le_card

      have hMER : M.card ≤ ER.card := by
        apply card_le_card
        intro e he
        rw [mem_filter]
        refine ⟨mem_univ e, ?_, ?_⟩
        · rw [mem_biUnion]
          exact ⟨e, he, by simp⟩
        · rw [mem_biUnion]
          exact ⟨e, he, by simp⟩
    
  4. $|E_S| \le |S|$.

    No vertex in $S$ is incident to an edge colored $a$, since any such edge would belong to $M$ and have its endpoints in $R$. Applying the helper lemma `op874_missing_color_induced_edges_le_vertices` to the set $S$ and color $a$ (using the fact that the graph is cubic and loopless via `Sym2.mk_isDiag_iff`) yields $|E_S| \le |S|$.

    lines 59–80

    uses Sym2.mk_isDiag_iff, op874_missing_color_induced_edges_le_vertices

      have hES_le : ES.card ≤ S.card := by
        have hloop' : ∀ e, ¬ (ends e).IsDiag := by
          intro e; rw [hends, Sym2.mk_isDiag_iff]; exact hloop e
        have hends' : ∀ e ∈ ES, ∃ u ∈ S, ∃ v ∈ S, ends e = s(u, v) := by
          intro e he
          rw [mem_filter] at he
          exact ⟨left e, he.2.1, right e, he.2.2, hends e⟩
        have hmiss : ∀ v ∈ S, ∀ e, v ∈ ends e → c v e ≠ a := by
          intro v hv e hve hca
          rw [mem_sdiff, mem_biUnion] at hv
          apply hv.2
          refine ⟨e, ?_, ?_⟩
          · rw [mem_filter]
            refine ⟨mem_univ e, ?_⟩
            rw [hends e, Sym2.mem_iff] at hve
            rcases hve with rfl | rfl
            · exact hca
            · rw [hcons]; exact hca
          · rw [hends e, Sym2.mem_iff] at hve
            rcases hve with rfl | rfl <;> simp
        exact op874_missing_color_induced_edges_le_vertices hΩ ends hloop' hcubic c h hc hh hch hs S ES a hends' hmiss
    
  5. For any vertex subset $A \subseteq V$, the sum over all edges of the number of their endpoints in $A$ equals $3|A|$.

    For each edge $e$, the number of endpoints in $A$ is expressed as the sum over $v \in V$ of the indicator that $v \in A$ and $v$ is incident to $e$ (`Sym2.mem_iff`, `sum_add_distrib`). Exchanging the order of summation over edges and vertices (`sum_comm`), each vertex $v \in A$ contributes its degree in the multigraph. Because the graph is cubic (`hcubic`, `Set.ncard_coe_finset`, `card_filter`), each vertex in $A$ has degree 3, so summing over $A$ yields $3|A|$ (`sum_ite`, `sum_congr`).

    lines 81–127

    uses Set.ncard_coe_finset, Sym2.mem_iff, sum_add_distrib, sum_comm, sum_congr, card_filter, sum_ite

      have hsum_deg : ∀ A : Finset V,
          (∑ e ∈ univ, ((if left e ∈ A then 1 else 0) + (if right e ∈ A then 1 else 0))) = 3 * A.card := by
        intro A
        have hcubic' : ∀ v, (univ.filter (fun e : E => v ∈ ends e)).card = 3 := by
          intro v
          have hv := hcubic v
          have h : {e : E | v ∈ ends e} = (univ.filter (fun e : E => v ∈ ends e) : Set E) := by ext e; simp
          rw [h, Set.ncard_coe_finset] at hv
          exact hv
        have hinner : ∀ e : E, ((if left e ∈ A then 1 else 0) + (if right e ∈ A then 1 else 0)) =
            ∑ v ∈ univ, if v ∈ A ∧ v ∈ ends e then 1 else 0 := by
          intro e
          have hmem : ∀ v, v ∈ ends e ↔ v = left e ∨ v = right e := by
            intro v; rw [hends e, Sym2.mem_iff]
          have : (fun v => (if v ∈ A ∧ v ∈ ends e then 1 else 0)) =
                 (fun v => (if v = left e then (if left e ∈ A then 1 else 0) else 0) +
                           (if v = right e then (if right e ∈ A then 1 else 0) else 0)) := by
            ext v
            by_cases hvl : v = left e
            · subst hvl
              have hne : left e ≠ right e := hloop e
              simp [hne, (hmem (left e)).2 (Or.inl rfl)]
            · by_cases hvr : v = right e
              · subst hvr
                simp [hvl, (hmem (right e)).2 (Or.inr rfl)]
              · have : ¬ (v ∈ ends e) := by intro h; rw [hmem] at h; rcases h with rfl | rfl <;> contradiction
                simp [hvl, hvr, this]
          rw [this, sum_add_distrib]
          simp
        simp_rw [hinner]
        rw [sum_comm]
        have hswap : ∀ v ∈ univ, (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) = if v ∈ A then 3 else 0 := by
          intro v hv
          split_ifs with hvA
          · have : (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) =
                   (∑ x ∈ univ, if v ∈ ends x then 1 else 0) := by
              refine sum_congr rfl (fun x hx => by simp [hvA])
            rw [this, ← card_filter, hcubic' v]
          · have : (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) = 0 := by
              have : (fun x => if v ∈ A ∧ v ∈ ends x then 1 else 0) = fun _ => 0 := by
                ext x; simp [hvA]
              rw [this, sum_const_zero]
            exact this
        rw [sum_congr rfl hswap]
        rw [sum_ite]
        simp [mul_comm]
    
  6. $3|S| + 2|E_R| = 3|R| + 2|E_S|$.

    For every edge $e$, the identity $(1_{\mathrm{left}(e) \in S} + 1_{\mathrm{right}(e) \in S}) + 2 \cdot 1_{e \in E_R} = (1_{\mathrm{left}(e) \in R} + 1_{\mathrm{right}(e) \in R}) + 2 \cdot 1_{e \in E_S}$ holds pointwise, as both sides evaluate to 2 if $e$ is induced by $S$ or $R$, and to 1 if $e$ crosses between $S$ and $R$. Summing this over all edges and using the degree sum formula `hsum_deg` on $S$ and $R$ yields $3|S| + 2|E_R| = 3|R| + 2|E_S|$ (`sum_congr`, `sum_add_distrib`, `mul_sum`, `card_filter`).

    lines 128–162

    uses sum_congr, sum_add_distrib, mul_sum, card_filter

      have hdeg : 3 * S.card + 2 * ER.card = 3 * R.card + 2 * ES.card := by
        have hSR : ∀ v, v ∈ S ↔ v ∉ R := by
          intro v; simp [S]
        have hpt : ∀ e : E,
            ((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0)) =
            ((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0)) := by
          intro e
          have h1 := hSR (left e)
          have h2 := hSR (right e)
          by_cases hr1 : left e ∈ R <;> by_cases hr2 : right e ∈ R
          · have hs1 : ¬ left e ∈ S := by intro h; rw [h1] at h; contradiction
            have hs2 : ¬ right e ∈ S := by intro h; rw [h2] at h; contradiction
            simp [hr1, hr2, hs1, hs2]
          · have hs1 : ¬ left e ∈ S := by intro h; rw [h1] at h; contradiction
            have hs2 : right e ∈ S := by rwa [h2]
            simp [hr1, hr2, hs1, hs2]
          · have hs1 : left e ∈ S := by rwa [h1]
            have hs2 : ¬ right e ∈ S := by intro h; rw [h2] at h; contradiction
            simp [hr1, hr2, hs1, hs2]
          · have hs1 : left e ∈ S := by rwa [h1]
            have hs2 : right e ∈ S := by rwa [h2]
            simp [hr1, hr2, hs1, hs2]
        have hsum : (∑ e ∈ univ, (((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0)) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0))) =
                    (∑ e ∈ univ, (((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0)) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0))) :=
          sum_congr rfl (fun e _ => hpt e)
        have hL : (∑ e ∈ univ, (((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0)) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0))) =
                  (∑ e ∈ univ, ((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0))) + 2 * ER.card := by
          rw [sum_add_distrib, ← mul_sum, ← card_filter]
        have hR' : (∑ e ∈ univ, (((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0)) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0))) =
                   (∑ e ∈ univ, ((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0))) + 2 * ES.card := by
          rw [sum_add_distrib, ← mul_sum, ← card_filter]
        have hcomb := hL.symm.trans (hsum.trans hR')
        rw [hsum_deg S, hsum_deg R] at hcomb
        exact hcomb
    
  7. $|V| = |S| + |R|$.

    Because $S$ is defined as the set complement $V \setminus R$, the sizes of $S$ and $R$ sum to the total number of vertices $|V|$ (`card_univ`, `card_sdiff_add_card_eq_card`, `subset_univ`).

    lines 163–167

    uses card_univ, card_sdiff_add_card_eq_card, subset_univ

      have hV : Fintype.card V = S.card + R.card := by
        rw [← card_univ]
        have : S = univ \ R := rfl
        rw [this, card_sdiff_add_card_eq_card (subset_univ R)]
    
  8. $|V| \le 6|M|$. automation

    From $3|S| + 2|E_R| = 3|R| + 2|E_S|$ and $|E_S| \le |S|$, we have $|S| \le 3|S| - 2|E_S| = 3|R| - 2|E_R|$. Substituting $|E_R| \ge |M|$ and $|R| = 2|M|$ yields $|S| \le 3(2|M|) - 2|M| = 4|M|$. Then $|V| = |S| + |R| \le 4|M| + 2|M| = 6|M|$. This linear arithmetic deduction is closed automatically by `omega`.

    lines 168–169

      change Fintype.card V ≤ 6 * M.card
      omega
card_biUnion
The cardinality of a union of pairwise disjoint finite sets is the sum of the cardinalities of the sets.
card_pair
A finite set consisting of two distinct elements has cardinality 2.
Finset.disjoint_left
Two finite sets are disjoint if and only if no element in the first set belongs to the second set.
sum_congr
If two finite index sets are equal and the summands agree at every element, then the two sums are equal.
card_le_card
If a finite set is a subset of another, its cardinality is less than or equal to the cardinality of the superset.
Sym2.mk_isDiag_iff
An unordered pair $s(x, y)$ lies on the diagonal (representing a self-loop) if and only if $x = y$.
op874_missing_color_induced_edges_le_vertices
In a loopless cubic multigraph with a strong 6-color truncation state, any vertex subset $S$ whose incident edges avoid color $a$ induces at most $|S|$ edges.
Set.ncard_coe_finset
The set cardinality (`Set.ncard`) of a coerced finite set equals its `Finset` cardinality.
Sym2.mem_iff
An element $v$ belongs to the unordered pair $s(x, y)$ if and only if $v = x$ or $v = y$.
sum_add_distrib
The sum of the sum of two functions over a finite set equals the sum of the sums of the individual functions.
sum_comm
The order of summation in a finite double sum can be exchanged.
card_filter
The cardinality of a filtered finset equals the sum of the indicator function of the filtering predicate.
sum_ite
A sum of an if-then-else term splits into the sum of the 'then' values over elements satisfying the condition and the sum of the 'else' values over elements satisfying its negation.
mul_sum
A scalar multiplier factors across a finite sum.
card_univ
The cardinality of the universal finset of a finite type equals the type's cardinality (`Fintype.card`).
card_sdiff_add_card_eq_card
For finite sets with $s \subseteq t$, the cardinality of $t \setminus s$ plus the cardinality of $s$ equals the cardinality of $t$.
subset_univ
Any finite subset of a finite type is contained in the universal finset.

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 op874_external_color_class_lower_bound    {V E Ω : Type*} [Fintype V] [Fintype E] [Fintype Ω]    [DecidableEq V] [DecidableEq E] [DecidableEq Ω]    (hΩ : Fintype.card Ω = 6)    (ends : E → Sym2 V) (left right : E → V)    (hends : ∀ e, ends e = s(left e,right e))    (hloop : ∀ e, left e ≠ right e)    (hcubic : ∀ v, Set.ncard {e | v ∈ ends e} = 3)    (c h : V → E → Ω)    (hc : ∀ v e f, v ∈ ends e → v ∈ ends f → c v e = c v f → e = f)    (hcons : ∀ e, c (left e) e = c (right e) e)    (hh : ∀ v e f, v ∈ ends e → v ∈ ends f → h v e = h v f → e = f)    (hch : ∀ v e f, v ∈ ends e → v ∈ ends f → h v e ≠ c v f)    (hs : truncation_local_states_define_strong_coloring ends c h)    (a : Ω) :    Fintype.card V ≤ 6 * (Finset.univ.filter (fun e : E => c (left e) e = a)).card := by  open Finset in  let M := univ.filter (fun e : E => c (left e) e = a)  let R := M.biUnion (fun e => {left e, right e})  let S := univ \ R  let ES := univ.filter (fun e => left e ∈ S ∧ right e ∈ S)  let ER := univ.filter (fun e => left e ∈ R ∧ right e ∈ R)  have hR : R.card = 2 * M.card := by    rw [card_biUnion]    · have : (∑ u ∈ M, ({left u, right u} : Finset V).card) = ∑ u ∈ M, 2 := by        refine sum_congr rfl (fun e he => ?_)        rw [card_pair (hloop e)]      rw [this, sum_const, smul_eq_mul, mul_comm]    · intro e1 he1 e2 he2 hne      dsimp [Function.onFun]      rw [mem_coe, mem_filter] at he1 he2      rw [Finset.disjoint_left]      intro v hv1 hv2      rw [mem_insert, mem_singleton] at hv1 hv2      have h1 : v ∈ ends e1 := by rw [hends]; rcases hv1 with rfl | rfl <;> simp      have h2 : v ∈ ends e2 := by rw [hends]; rcases hv2 with rfl | rfl <;> simp      have hc1 : c v e1 = a := by        rcases hv1 with rfl | rfl        · exact he1.2        · rw [← hcons e1]; exact he1.2      have hc2 : c v e2 = a := by        rcases hv2 with rfl | rfl        · exact he2.2        · rw [← hcons e2]; exact he2.2      have heq : e1 = e2 := hc v e1 e2 h1 h2 (hc1.trans hc2.symm)      exact hne heq  have hMER : M.card ≤ ER.card := by    apply card_le_card    intro e he    rw [mem_filter]    refine ⟨mem_univ e, ?_, ?_⟩    · rw [mem_biUnion]      exact ⟨e, he, by simp⟩    · rw [mem_biUnion]      exact ⟨e, he, by simp⟩  have hES_le : ES.card ≤ S.card := by    have hloop' : ∀ e, ¬ (ends e).IsDiag := by      intro e; rw [hends, Sym2.mk_isDiag_iff]; exact hloop e    have hends' : ∀ e ∈ ES, ∃ u ∈ S, ∃ v ∈ S, ends e = s(u, v) := by      intro e he      rw [mem_filter] at he      exact ⟨left e, he.2.1, right e, he.2.2, hends e⟩    have hmiss : ∀ v ∈ S, ∀ e, v ∈ ends e → c v e ≠ a := by      intro v hv e hve hca      rw [mem_sdiff, mem_biUnion] at hv      apply hv.2      refine ⟨e, ?_, ?_⟩      · rw [mem_filter]        refine ⟨mem_univ e, ?_⟩        rw [hends e, Sym2.mem_iff] at hve        rcases hve with rfl | rfl        · exact hca        · rw [hcons]; exact hca      · rw [hends e, Sym2.mem_iff] at hve        rcases hve with rfl | rfl <;> simp    exact op874_missing_color_induced_edges_le_vertices hΩ ends hloop' hcubic c h hc hh hch hs S ES a hends' hmiss  have hsum_deg : ∀ A : Finset V,      (∑ e ∈ univ, ((if left e ∈ A then 1 else 0) + (if right e ∈ A then 1 else 0))) = 3 * A.card := by    intro A    have hcubic' : ∀ v, (univ.filter (fun e : E => v ∈ ends e)).card = 3 := by      intro v      have hv := hcubic v      have h : {e : E | v ∈ ends e} = (univ.filter (fun e : E => v ∈ ends e) : Set E) := by ext e; simp      rw [h, Set.ncard_coe_finset] at hv      exact hv    have hinner : ∀ e : E, ((if left e ∈ A then 1 else 0) + (if right e ∈ A then 1 else 0)) =        ∑ v ∈ univ, if v ∈ A ∧ v ∈ ends e then 1 else 0 := by      intro e      have hmem : ∀ v, v ∈ ends e ↔ v = left e ∨ v = right e := by        intro v; rw [hends e, Sym2.mem_iff]      have : (fun v => (if v ∈ A ∧ v ∈ ends e then 1 else 0)) =             (fun v => (if v = left e then (if left e ∈ A then 1 else 0) else 0) +                       (if v = right e then (if right e ∈ A then 1 else 0) else 0)) := by        ext v        by_cases hvl : v = left e        · subst hvl          have hne : left e ≠ right e := hloop e          simp [hne, (hmem (left e)).2 (Or.inl rfl)]        · by_cases hvr : v = right e          · subst hvr            simp [hvl, (hmem (right e)).2 (Or.inr rfl)]          · have : ¬ (v ∈ ends e) := by intro h; rw [hmem] at h; rcases h with rfl | rfl <;> contradiction            simp [hvl, hvr, this]      rw [this, sum_add_distrib]      simp    simp_rw [hinner]    rw [sum_comm]    have hswap : ∀ v ∈ univ, (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) = if v ∈ A then 3 else 0 := by      intro v hv      split_ifs with hvA      · have : (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) =               (∑ x ∈ univ, if v ∈ ends x then 1 else 0) := by          refine sum_congr rfl (fun x hx => by simp [hvA])        rw [this, ← card_filter, hcubic' v]      · have : (∑ x ∈ univ, if v ∈ A ∧ v ∈ ends x then 1 else 0) = 0 := by          have : (fun x => if v ∈ A ∧ v ∈ ends x then 1 else 0) = fun _ => 0 := by            ext x; simp [hvA]          rw [this, sum_const_zero]        exact this    rw [sum_congr rfl hswap]    rw [sum_ite]    simp [mul_comm]  have hdeg : 3 * S.card + 2 * ER.card = 3 * R.card + 2 * ES.card := by    have hSR : ∀ v, v ∈ S ↔ v ∉ R := by      intro v; simp [S]    have hpt : ∀ e : E,        ((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0)) =        ((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0)) := by      intro e      have h1 := hSR (left e)      have h2 := hSR (right e)      by_cases hr1 : left e ∈ R <;> by_cases hr2 : right e ∈ R      · have hs1 : ¬ left e ∈ S := by intro h; rw [h1] at h; contradiction        have hs2 : ¬ right e ∈ S := by intro h; rw [h2] at h; contradiction        simp [hr1, hr2, hs1, hs2]      · have hs1 : ¬ left e ∈ S := by intro h; rw [h1] at h; contradiction        have hs2 : right e ∈ S := by rwa [h2]        simp [hr1, hr2, hs1, hs2]      · have hs1 : left e ∈ S := by rwa [h1]        have hs2 : ¬ right e ∈ S := by intro h; rw [h2] at h; contradiction        simp [hr1, hr2, hs1, hs2]      · have hs1 : left e ∈ S := by rwa [h1]        have hs2 : right e ∈ S := by rwa [h2]        simp [hr1, hr2, hs1, hs2]    have hsum : (∑ e ∈ univ, (((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0)) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0))) =                (∑ e ∈ univ, (((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0)) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0))) :=      sum_congr rfl (fun e _ => hpt e)    have hL : (∑ e ∈ univ, (((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0)) + 2 * (if left e ∈ R ∧ right e ∈ R then 1 else 0))) =              (∑ e ∈ univ, ((if left e ∈ S then 1 else 0) + (if right e ∈ S then 1 else 0))) + 2 * ER.card := by      rw [sum_add_distrib, ← mul_sum, ← card_filter]    have hR' : (∑ e ∈ univ, (((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0)) + 2 * (if left e ∈ S ∧ right e ∈ S then 1 else 0))) =               (∑ e ∈ univ, ((if left e ∈ R then 1 else 0) + (if right e ∈ R then 1 else 0))) + 2 * ES.card := by      rw [sum_add_distrib, ← mul_sum, ← card_filter]    have hcomb := hL.symm.trans (hsum.trans hR')    rw [hsum_deg S, hsum_deg R] at hcomb    exact hcomb  have hV : Fintype.card V = S.card + R.card := by    rw [← card_univ]    have : S = univ \ R := rfl    rw [this, card_sdiff_add_card_eq_card (subset_univ R)]  change Fintype.card V ≤ 6 * M.card  omega
See it in the graphDiscuss this resultChallenge it