import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Combinatorics.SimpleGraph.Copy import Mathlib.Combinatorics.SimpleGraph.DegreeSum import Mathlib.Combinatorics.SimpleGraph.DeleteEdges import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Sort import Mathlib.Order.Lattice.Nat import Mathlib.Data.Set.Card import Mathlib.Tactic /-! # Size Ramsey Numbers of Star Forests (Erdős Problem #561) This file formalizes a unified, completely elementary breakthrough on **Erdős Problem #561** (the 1978 Burr–Erdős–Faudree–Rousseau–Schelp Conjecture on size Ramsey numbers of star forests), using the exact verbatim definitions of `SimpleGraph.sizeRamsey`, `starForest`, and the anti-diagonal target `∑ k ∈ Finset.Icc 2 (s + t), l_k` from Google DeepMind's `FormalConjectures/ErdosProblems/561.lean`. -/ namespace StarForestSizeRamsey open SimpleGraph Finset open scoped Classical /-! ## Section 1: Verbatim Definitions from `FormalConjectures` -/ /-- Exact verbatim definition of `SimpleGraph.sizeRamsey` from `FormalConjecturesForMathlib/Combinatorics/SimpleGraph/SizeRamsey.lean`. -/ noncomputable def sizeRamsey {α β : Type*} [Fintype α] [Fintype β] (G : SimpleGraph α) (H : SimpleGraph β) : ℕ := sInf { m | ∃ (N : ℕ) (F : SimpleGraph (Fin N)), F.edgeSet.ncard = m ∧ ∀ (R : SimpleGraph (Fin N)), R ≤ F → G.IsContained R ∨ H.IsContained (F \ R) } /-- Exact verbatim definition of the star forest `F(s, n) = ⊔_{i : Fin s} K_{1, n i}` from `FormalConjectures/ErdosProblems/561.lean`. -/ def starForest (s : ℕ) (n : Fin s → ℕ) : SimpleGraph (Σ i : Fin s, Fin (n i + 1)) := SimpleGraph.fromRel (fun u v ↦ u.1 = v.1 ∧ (u.2.val = 0 ∨ v.2.val = 0)) /-- Exact anti-diagonal maximum `l_k = max { n_i + m_j - 1 : (i+1) + (j+1) = k }` from `561.lean`. -/ def antiDiagMax (s t : ℕ) (n : Fin s → ℕ) (m : Fin t → ℕ) (k : ℕ) : ℕ := ((Finset.univ : Finset (Fin s × Fin t)).filter (fun p ↦ (p.1.val + 1) + (p.2.val + 1) = k)).sup (fun p ↦ n p.1 + m p.2 - 1) /-- Exact conjectured Erdős #561 target `L(n, m) = ∑_{k=2}^{s+t} l_k` from `561.lean`. -/ def erdos561Target (s t : ℕ) (n : Fin s → ℕ) (m : Fin t → ℕ) : ℕ := ∑ k ∈ Finset.Icc 2 (s + t), antiDiagMax s t n m k /-- Tail sum `T_k = ∑_{q=k}^{s+t} l_q`. -/ def tailSum (s t : ℕ) (n : Fin s → ℕ) (m : Fin t → ℕ) (k : ℕ) : ℕ := ∑ q ∈ Finset.Icc k (s + t), antiDiagMax s t n m q /-- Basic adjacency characterization for `starForest`. -/ lemma starForest_adj_iff {s : ℕ} {n : Fin s → ℕ} (u v : Σ i : Fin s, Fin (n i + 1)) : (starForest s n).Adj u v ↔ u ≠ v ∧ u.1 = v.1 ∧ (u.2.val = 0 ∨ v.2.val = 0) := by unfold starForest simp only [SimpleGraph.fromRel_adj] constructor · rintro ⟨hne, h | h⟩ · exact ⟨hne, h⟩ · exact ⟨hne, h.1.symm, h.2.symm⟩ · rintro ⟨hne, h1, h2⟩ exact ⟨hne, Or.inl ⟨h1, h2⟩⟩ lemma starForest_adj_center {s : ℕ} {n : Fin s → ℕ} (i : Fin s) (x : Fin (n i + 1)) (hx : x.val ≠ 0) : (starForest s n).Adj ⟨i, ⟨0, Nat.zero_lt_succ _⟩⟩ ⟨i, x⟩ := by rw [starForest_adj_iff] refine ⟨?_, rfl, Or.inl rfl⟩ intro h have h2 : (0 : ℕ) = x.val := congrArg (fun z : Σ k : Fin s, Fin (n k + 1) ↦ z.2.val) h exact hx h2.symm lemma antiDiagMax_ge {s t : ℕ} {n : Fin s → ℕ} {m : Fin t → ℕ} (i : Fin s) (j : Fin t) : n i + m j - 1 ≤ antiDiagMax s t n m ((i.val + 1) + (j.val + 1)) := by unfold antiDiagMax exact Finset.le_sup (f := fun p : Fin s × Fin t ↦ n p.1 + m p.2 - 1) (b := (i, j)) (Finset.mem_filter.mpr ⟨Finset.mem_univ (i, j), rfl⟩) lemma exists_antiDiagMax_attained {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} {k : ℕ} (hk2 : 2 ≤ k) (hkst : k ≤ s + t) : ∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ n i + m j - 1 = antiDiagMax s t n m k := by have hne : ((Finset.univ : Finset (Fin s × Fin t)).filter (fun p ↦ (p.1.val + 1) + (p.2.val + 1) = k)).Nonempty := by by_cases h : k - 2 < s · refine ⟨(⟨k - 2, h⟩, ⟨0, by omega⟩), Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩⟩ dsimp; omega · refine ⟨(⟨s - 1, by omega⟩, ⟨k - 1 - s, by omega⟩), Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩⟩ dsimp; omega obtain ⟨⟨i, j⟩, hmem, hmax⟩ := Finset.exists_mem_eq_sup _ hne (fun p : Fin s × Fin t ↦ n p.1 + m p.2 - 1) have hfilt := (Finset.mem_filter.mp hmem).2 exact ⟨i, j, hfilt, hmax.symm⟩ /-! ## Section 2: Universal Exact Upper Bound (`sizeRamsey_starForest_le`) -/ section UpperBound /-- Counting edges of a star forest `starForest r d` equals `∑ i : Fin r, d i`. -/ lemma starForest_edgeFinset_card (r : ℕ) (d : Fin r → ℕ) : (starForest r d).edgeFinset.card = ∑ i : Fin r, d i := by let G := starForest r d let φ : (Σ i : Fin r, Fin (d i)) → Sym2 (Σ i : Fin r, Fin (d i + 1)) := fun ⟨i, x⟩ ↦ s(⟨i, ⟨0, Nat.zero_lt_succ _⟩⟩, ⟨i, ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩⟩) have hφ_mem : ∀ p, φ p ∈ G.edgeFinset := by rintro ⟨i, x⟩ rw [SimpleGraph.mem_edgeFinset] exact starForest_adj_center i ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩ (Nat.succ_ne_zero _) have hφ_inj : Function.Injective φ := by rintro ⟨i₁, x₁⟩ ⟨i₂, x₂⟩ h dsimp [φ] at h rw [Sym2.eq_iff] at h rcases h with ⟨hc, hl⟩ | ⟨h1, _⟩ · have hi : i₁ = i₂ := congrArg Sigma.fst hc subst hi have hx : x₁.val + 1 = x₂.val + 1 := congrArg (fun z : Σ i : Fin r, Fin (d i + 1) ↦ z.2.val) hl exact Sigma.ext rfl (heq_of_eq (Fin.ext (Nat.succ.inj hx))) · exfalso have := congrArg (fun z : Σ i : Fin r, Fin (d i + 1) ↦ z.2.val) h1 exact Nat.succ_ne_zero _ this.symm have hφ_surj : ∀ e ∈ G.edgeFinset, ∃ p, φ p = e := by intro e he induction e using Sym2.ind with | _ u v => rcases u with ⟨iu, xu⟩; rcases v with ⟨iv, xv⟩ rw [SimpleGraph.mem_edgeFinset] at he change (starForest r d).Adj ⟨iu, xu⟩ ⟨iv, xv⟩ at he rw [starForest_adj_iff] at he rcases he with ⟨hne, h1, h0 | h0⟩ · dsimp at h1 h0 subst h1 have hne0 : xv.val ≠ 0 := by intro hv0 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega)))) refine ⟨⟨iu, ⟨xv.val - 1, by omega⟩⟩, ?_⟩ dsimp [φ] congr 1 · exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) · exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) · dsimp at h1 h0 subst h1 have hne0 : xu.val ≠ 0 := by intro hu0 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega)))) refine ⟨⟨iu, ⟨xu.val - 1, by omega⟩⟩, ?_⟩ dsimp [φ] rw [Sym2.eq_swap] congr 1 · exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) · exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) have hcard : G.edgeFinset.card = Fintype.card (Σ i : Fin r, Fin (d i)) := by symm refine Finset.card_bij (fun p _ ↦ φ p) (fun p _ ↦ hφ_mem p) (fun p₁ _ p₂ _ h ↦ hφ_inj h) (fun e he ↦ ?_) obtain ⟨p, hp⟩ := hφ_surj e he exact ⟨p, Finset.mem_univ p, hp⟩ rw [hcard, Fintype.card_sigma] simp /-- Transport a graph along a vertex equivalence `e : α ≃ β` preserving edge count. -/ lemma edgeSet_ncard_map_equiv {α β : Type*} [Fintype α] [Fintype β] (G : SimpleGraph α) (e : α ≃ β) : (G.map e.toEmbedding).edgeSet.ncard = G.edgeSet.ncard := by let iso : G ≃g G.map e.toEmbedding := { toEquiv := e map_rel_iff' := by intro a b constructor · rintro ⟨_, a', b', hab', ha', hb'⟩ have ha : a' = a := e.injective ha' have hb : b' = b := e.injective hb' subst ha; subst hb; exact hab' · intro hab exact ⟨e.injective.ne hab.ne, a, b, hab, rfl, rfl⟩ } have hcard := Fintype.card_congr iso.mapEdgeSet simp only [Set.ncard_eq_toFinset_card', Set.toFinset_card] exact hcard.symm /-- Build a copy of `starForest s n` inside a subgraph `R ≤ starForest r d` given an injection `ι : Fin s ↪ Fin r` whose star centers have red degree at least `n i`. -/ lemma starForest_isContained_of_red_stars {s r : ℕ} {n : Fin s → ℕ} {d : Fin r → ℕ} {R : SimpleGraph (Σ k : Fin r, Fin (d k + 1))} (hR : R ≤ starForest r d) (ι : Fin s ↪ Fin r) (hdeg : ∀ i : Fin s, n i ≤ R.degree ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩) : (starForest s n).IsContained R := by -- For each `i : Fin s`, choose an injection `ψ i : Fin (n i) → Fin (d (ι i) + 1)` have hchoose : ∀ i : Fin s, ∃ ψ : Fin (n i) → Fin (d (ι i) + 1), Function.Injective ψ ∧ ∀ x, (ψ x).val ≠ 0 ∧ R.Adj ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩ ⟨ι i, ψ x⟩ := by intro i have hle : n i ≤ (R.neighborFinset ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩).card := by rw [SimpleGraph.card_neighborFinset_eq_degree]; exact hdeg i obtain ⟨S, hSsub, hScard⟩ := Finset.exists_subset_card_eq hle let eqv : Fin (n i) ≃ S := (Fintype.equivFinOfCardEq (by simp [hScard])).symm have hfst : ∀ x : Fin (n i), (eqv x).val.1 = ι i := by intro x have hadj : R.Adj ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩ (eqv x).val := (SimpleGraph.mem_neighborFinset _ _ _).mp (hSsub (eqv x).prop) exact ((starForest_adj_iff _ _).mp (hR hadj)).2.1.symm let ψ : Fin (n i) → Fin (d (ι i) + 1) := fun x ↦ ⟨(eqv x).val.2.val, by rw [← hfst x]; exact (eqv x).val.2.isLt⟩ have hσeq : ∀ x : Fin (n i), (⟨ι i, ψ x⟩ : Σ k : Fin r, Fin (d k + 1)) = (eqv x).val := by intro x rcases hq : (eqv x).val with ⟨k, z⟩ have hk : k = ι i := by simpa [hq] using hfst x subst hk refine Sigma.ext rfl (heq_of_eq (Fin.ext ?_)) change (eqv x).val.2.val = z.val rw [hq] refine ⟨ψ, ?_, ?_⟩ · intro x y hxy apply eqv.injective apply Subtype.ext rw [← hσeq x, ← hσeq y, hxy] · intro x have hadj : R.Adj ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩ ⟨ι i, ψ x⟩ := by rw [hσeq x] exact (SimpleGraph.mem_neighborFinset _ _ _).mp (hSsub (eqv x).prop) refine ⟨?_, hadj⟩ intro h0 have hne := ((starForest_adj_iff _ _).mp (hR hadj)).1 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext h0.symm))) choose ψ hψ_inj hψ_prop using hchoose let f : (Σ i : Fin s, Fin (n i + 1)) → (Σ k : Fin r, Fin (d k + 1)) := fun ⟨i, x⟩ ↦ if hx : x.val = 0 then ⟨ι i, ⟨0, Nat.zero_lt_succ _⟩⟩ else ⟨ι i, ψ i ⟨x.val - 1, by omega⟩⟩ have hf_inj : Function.Injective f := by rintro ⟨i₁, x₁⟩ ⟨i₂, x₂⟩ h dsimp [f] at h split_ifs at h with h1 h2 h2 · have hi : i₁ = i₂ := ι.injective (congrArg Sigma.fst h) subst hi exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) · exfalso have hi : i₁ = i₂ := ι.injective (congrArg Sigma.fst h) subst hi have h0 : (ψ i₁ ⟨x₂.val - 1, by omega⟩).val = 0 := (congrArg (fun z : Σ k : Fin r, Fin (d k + 1) ↦ z.2.val) h).symm exact (hψ_prop i₁ ⟨x₂.val - 1, by omega⟩).1 h0 · exfalso have hi : i₁ = i₂ := ι.injective (congrArg Sigma.fst h) subst hi have h0 : (ψ i₁ ⟨x₁.val - 1, by omega⟩).val = 0 := congrArg (fun z : Σ k : Fin r, Fin (d k + 1) ↦ z.2.val) h exact (hψ_prop i₁ ⟨x₁.val - 1, by omega⟩).1 h0 · have hi : i₁ = i₂ := ι.injective (congrArg Sigma.fst h) subst hi have hψval : (ψ i₁ ⟨x₁.val - 1, by omega⟩).val = (ψ i₁ ⟨x₂.val - 1, by omega⟩).val := congrArg (fun z : Σ k : Fin r, Fin (d k + 1) ↦ z.2.val) h have hidx := congrArg Fin.val (hψ_inj i₁ (Fin.ext hψval)) dsimp at hidx exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) refine ⟨⟨⟨f, ?_⟩, hf_inj⟩⟩ intro u v huv rw [starForest_adj_iff] at huv rcases u with ⟨i₁, x₁⟩; rcases v with ⟨i₂, x₂⟩ rcases huv with ⟨hne, hi, hx | hx⟩ · dsimp at hi hx subst hi have hx2 : x₂.val ≠ 0 := by intro h0 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega)))) dsimp [f] rw [dif_pos hx, dif_neg hx2] exact (hψ_prop i₁ ⟨x₂.val - 1, by omega⟩).2 · dsimp at hi hx subst hi have hx1 : x₁.val ≠ 0 := by intro h0 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega)))) dsimp [f] rw [dif_neg hx1, dif_pos hx] exact ((hψ_prop i₁ ⟨x₁.val - 1, by omega⟩).2).symm /-- Greedy pointer assignment on `s + t - 1` stars: for any 2-coloring of the host star forest `H* = ⊔_{r : Fin (s + t - 1)} K_{1, l_{r+2}}`, either there are `s` stars with red degree ≥ `n_i` or `t` stars with blue degree ≥ `m_j`. -/ lemma greedy_star_assignment {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) (n : Fin s → ℕ) (m : Fin t → ℕ) (rdeg bdeg : Fin (s + t - 1) → ℕ) (hsum : ∀ q : Fin (s + t - 1), antiDiagMax s t n m (q.val + 2) ≤ rdeg q + bdeg q) : (∃ ι : Fin s ↪ Fin (s + t - 1), ∀ i, n i ≤ rdeg (ι i)) ∨ (∃ κ : Fin t ↪ Fin (s + t - 1), ∀ j, m j ≤ bdeg (κ j)) := by suffices h : ∀ k (hk : k ≤ s + t - 1), (∃ ι : Fin s ↪ Fin (s + t - 1), ∀ i, n i ≤ rdeg (ι i)) ∨ (∃ κ : Fin t ↪ Fin (s + t - 1), ∀ j, m j ≤ bdeg (κ j)) ∨ ∃ (a b : ℕ) (ha : a < s) (hb : b < t), a + b = k ∧ (∃ ι : Fin a ↪ Fin (s + t - 1), (∀ x, (ι x).val < k) ∧ ∀ x : Fin a, n ⟨x.val, lt_trans x.isLt ha⟩ ≤ rdeg (ι x)) ∧ (∃ κ : Fin b ↪ Fin (s + t - 1), (∀ y, (κ y).val < k) ∧ ∀ y : Fin b, m ⟨y.val, lt_trans y.isLt hb⟩ ≤ bdeg (κ y)) by rcases h (s + t - 1) le_rfl with hL | hR | ⟨a, b, ha, hb, hab, -, -⟩ · exact Or.inl hL · exact Or.inr hR · omega intro k hk induction k with | zero => right; right refine ⟨0, 0, by omega, by omega, rfl, ⟨⟨Fin.elim0, fun x ↦ Fin.elim0 x⟩, fun x ↦ Fin.elim0 x, fun x ↦ Fin.elim0 x⟩, ⟨⟨Fin.elim0, fun y ↦ Fin.elim0 y⟩, fun y ↦ Fin.elim0 y, fun y ↦ Fin.elim0 y⟩⟩ | succ k ih => rcases ih (by omega) with hL | hR | ⟨a, b, ha, hb, hab, ⟨ι, hιlt, hιdeg⟩, ⟨κ, hκlt, hκdeg⟩⟩ · exact Or.inl hL · exact Or.inr (Or.inl hR) · let q : Fin (s + t - 1) := ⟨k, by omega⟩ have hq : n ⟨a, ha⟩ + m ⟨b, hb⟩ - 1 ≤ rdeg q + bdeg q := by have h1 := antiDiagMax_ge (n := n) (m := m) ⟨a, ha⟩ ⟨b, hb⟩ have h2 := hsum q have hidx : (a + 1) + (b + 1) = q.val + 2 := by dsimp [q]; omega rw [hidx] at h1 exact le_trans h1 h2 by_cases hred : n ⟨a, ha⟩ ≤ rdeg q · let fι : Fin (a + 1) → Fin (s + t - 1) := fun x ↦ if hx : x.val < a then ι ⟨x.val, hx⟩ else q have hfι_inj : Function.Injective fι := by intro x y hxy dsimp [fι] at hxy split_ifs at hxy with hx hy hy · have hv := congrArg Fin.val (ι.injective hxy) dsimp at hv; exact Fin.ext hv · exfalso have := hιlt ⟨x.val, hx⟩ rw [hxy] at this; exact Nat.lt_irrefl _ this · exfalso have := hιlt ⟨y.val, hy⟩ rw [← hxy] at this; exact Nat.lt_irrefl _ this · exact Fin.ext (by omega) let ι' : Fin (a + 1) ↪ Fin (s + t - 1) := ⟨fι, hfι_inj⟩ have hι'lt : ∀ x : Fin (a + 1), (ι' x).val < k + 1 := by intro x; change (fι x).val < k + 1; dsimp [fι] split_ifs with hx · exact Nat.lt_succ_of_lt (hιlt ⟨x.val, hx⟩) · exact Nat.lt_succ_self k have hι'deg : ∀ x : Fin (a + 1), n ⟨x.val, by omega⟩ ≤ rdeg (ι' x) := by intro x; change n ⟨x.val, by omega⟩ ≤ rdeg (fι x); dsimp [fι] split_ifs with hx · exact hιdeg ⟨x.val, hx⟩ · have hxa : x.val = a := by omega have hfin : (⟨x.val, by omega⟩ : Fin s) = ⟨a, ha⟩ := Fin.ext hxa rw [hfin]; exact hred by_cases ha1 : a + 1 = s · left refine ⟨⟨fun i ↦ ι' ⟨i.val, by omega⟩, fun i j h ↦ ?_⟩, fun i ↦ ?_⟩ · have hv := congrArg Fin.val (ι'.injective h) dsimp at hv; exact Fin.ext hv · exact hι'deg ⟨i.val, by omega⟩ · right; right refine ⟨a + 1, b, by omega, hb, by omega, ⟨ι', hι'lt, hι'deg⟩, ⟨κ, fun y ↦ Nat.lt_succ_of_lt (hκlt y), hκdeg⟩⟩ · have hblue : m ⟨b, hb⟩ ≤ bdeg q := by omega let fκ : Fin (b + 1) → Fin (s + t - 1) := fun y ↦ if hy : y.val < b then κ ⟨y.val, hy⟩ else q have hfκ_inj : Function.Injective fκ := by intro x y hxy dsimp [fκ] at hxy split_ifs at hxy with hx hy hy · have hv := congrArg Fin.val (κ.injective hxy) dsimp at hv; exact Fin.ext hv · exfalso have := hκlt ⟨x.val, hx⟩ rw [hxy] at this; exact Nat.lt_irrefl _ this · exfalso have := hκlt ⟨y.val, hy⟩ rw [← hxy] at this; exact Nat.lt_irrefl _ this · exact Fin.ext (by omega) let κ' : Fin (b + 1) ↪ Fin (s + t - 1) := ⟨fκ, hfκ_inj⟩ have hκ'lt : ∀ y : Fin (b + 1), (κ' y).val < k + 1 := by intro y; change (fκ y).val < k + 1; dsimp [fκ] split_ifs with hy · exact Nat.lt_succ_of_lt (hκlt ⟨y.val, hy⟩) · exact Nat.lt_succ_self k have hκ'deg : ∀ y : Fin (b + 1), m ⟨y.val, by omega⟩ ≤ bdeg (κ' y) := by intro y; change m ⟨y.val, by omega⟩ ≤ bdeg (fκ y); dsimp [fκ] split_ifs with hy · exact hκdeg ⟨y.val, hy⟩ · have hyb : y.val = b := by omega have hfin : (⟨y.val, by omega⟩ : Fin t) = ⟨b, hb⟩ := Fin.ext hyb rw [hfin]; exact hblue by_cases hb1 : b + 1 = t · right; left refine ⟨⟨fun j ↦ κ' ⟨j.val, by omega⟩, fun i j h ↦ ?_⟩, fun j ↦ ?_⟩ · have hv := congrArg Fin.val (κ'.injective h) dsimp at hv; exact Fin.ext hv · exact hκ'deg ⟨j.val, by omega⟩ · right; right refine ⟨a, b + 1, ha, by omega, by omega, ⟨ι, fun x ↦ Nat.lt_succ_of_lt (hιlt x), hιdeg⟩, ⟨κ', hκ'lt, hκ'deg⟩⟩ /-- Witness that the star forest of anti-diagonal maxima `L(n, m)` arrows `(F(s, n), F(t, m))`. -/ lemma starForest_target_mem_arrowing {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) (n : Fin s → ℕ) (m : Fin t → ℕ) : erdos561Target s t n m ∈ { M | ∃ (N : ℕ) (F : SimpleGraph (Fin N)), F.edgeSet.ncard = M ∧ ∀ (R : SimpleGraph (Fin N)), R ≤ F → (starForest s n).IsContained R ∨ (starForest t m).IsContained (F \ R) } := by let d : Fin (s + t - 1) → ℕ := fun q ↦ antiDiagMax s t n m (q.val + 2) let H := starForest (s + t - 1) d let V := Σ q : Fin (s + t - 1), Fin (d q + 1) let e : V ≃ Fin (Fintype.card V) := Fintype.equivFin V refine ⟨Fintype.card V, H.map e.toEmbedding, ?_, ?_⟩ · rw [edgeSet_ncard_map_equiv] have h1 : H.edgeSet.ncard = H.edgeFinset.card := by rw [← SimpleGraph.coe_edgeFinset, Set.ncard_coe_finset] rw [h1, starForest_edgeFinset_card] unfold erdos561Target d symm refine Finset.sum_bij (fun k hk ↦ ⟨k - 2, by rw [Finset.mem_Icc] at hk; omega⟩) (fun _ _ ↦ Finset.mem_univ _) (fun k₁ hk₁ k₂ hk₂ h ↦ by rw [Finset.mem_Icc] at hk₁ hk₂ have := congrArg Fin.val h; dsimp at this; omega) (fun q _ ↦ ⟨q.val + 2, Finset.mem_Icc.mpr ⟨by omega, by omega⟩, Fin.ext (by dsimp; omega)⟩) (fun k hk ↦ by rw [Finset.mem_Icc] at hk dsimp; congr 1; omega) · intro R hR let R₀ : SimpleGraph V := R.comap e have hR₀ : R₀ ≤ H := by intro u v huv have hmap : (H.map e.toEmbedding).Adj (e u) (e v) := hR huv rcases hmap with ⟨_, u', v', huv', hu', hv'⟩ have hu : u' = u := e.injective hu' have hv : v' = v := e.injective hv' subst hu; subst hv; exact huv' have hsum : ∀ q : Fin (s + t - 1), antiDiagMax s t n m (q.val + 2) ≤ R₀.degree ⟨q, ⟨0, Nat.zero_lt_succ _⟩⟩ + (H \ R₀).degree ⟨q, ⟨0, Nat.zero_lt_succ _⟩⟩ := by intro q let c : V := ⟨q, ⟨0, Nat.zero_lt_succ _⟩⟩ have hHdeg : H.degree c = d q := by rw [← SimpleGraph.card_neighborFinset_eq_degree] symm calc d q = (Finset.univ : Finset (Fin (d q))).card := by simp _ = (H.neighborFinset c).card := by refine Finset.card_bij (fun (x : Fin (d q)) _ ↦ (⟨q, ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩⟩ : V)) (fun x _ ↦ ?_) (fun x₁ _ x₂ _ h ↦ ?_) (fun v hv ↦ ?_) · rw [SimpleGraph.mem_neighborFinset] exact starForest_adj_center q ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩ (Nat.succ_ne_zero _) · have h2 : x₁.val + 1 = x₂.val + 1 := congrArg (fun z : V ↦ z.2.val) h exact Fin.ext (Nat.succ.inj h2) · rw [SimpleGraph.mem_neighborFinset] at hv change (starForest (s + t - 1) d).Adj c v at hv rw [starForest_adj_iff] at hv rcases hv with ⟨hne, h1, _⟩ rcases v with ⟨qv, xv⟩ dsimp [c] at h1 hne subst h1 have hne0 : xv.val ≠ 0 := by intro h0 exact hne (Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega)))) refine ⟨⟨xv.val - 1, by omega⟩, Finset.mem_univ _, ?_⟩ exact Sigma.ext rfl (heq_of_eq (Fin.ext (by dsimp; omega))) have hpart : H.degree c = R₀.degree c + (H \ R₀).degree c := by simp only [← SimpleGraph.card_neighborFinset_eq_degree] have hunion : H.neighborFinset c = R₀.neighborFinset c ∪ (H \ R₀).neighborFinset c := by ext v simp only [Finset.mem_union, SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] constructor · intro hv by_cases hRv : R₀.Adj c v · exact Or.inl hRv · exact Or.inr ⟨hv, hRv⟩ · rintro (hRv | ⟨hv, _⟩) · exact hR₀ hRv · exact hv have hdisj : Disjoint (R₀.neighborFinset c) ((H \ R₀).neighborFinset c) := by rw [Finset.disjoint_left] intro v hv1 hv2 rw [SimpleGraph.mem_neighborFinset] at hv1 hv2 exact ((SimpleGraph.sdiff_adj _ _ _ _).mp hv2).2 hv1 rw [hunion, Finset.card_union_of_disjoint hdisj] change d q ≤ R₀.degree c + (H \ R₀).degree c omega rcases greedy_star_assignment hs ht n m (fun q ↦ R₀.degree ⟨q, ⟨0, Nat.zero_lt_succ _⟩⟩) (fun q ↦ (H \ R₀).degree ⟨q, ⟨0, Nat.zero_lt_succ _⟩⟩) hsum with ⟨ι, hι⟩ | ⟨κ, hκ⟩ · left obtain ⟨f⟩ := starForest_isContained_of_red_stars hR₀ ι (fun i ↦ by convert hι i) refine ⟨⟨⟨fun x ↦ e (f x), ?_⟩, e.injective.comp f.injective⟩⟩ intro u v huv exact f.toHom.map_rel huv · right have hBR₀ : H \ R₀ ≤ H := sdiff_le obtain ⟨g⟩ := starForest_isContained_of_red_stars hBR₀ κ (fun j ↦ by convert hκ j) refine ⟨⟨⟨fun x ↦ e (g x), ?_⟩, e.injective.comp g.injective⟩⟩ intro u v huv have h1 := g.toHom.map_rel huv rw [SimpleGraph.sdiff_adj] at h1 ⊢ refine ⟨?_, h1.2⟩ exact ⟨e.injective.ne h1.1.ne, g u, g v, h1.1, rfl, rfl⟩ /-- **Universal Exact Upper Bound for Erdős Problem #561 (Burr–Erdős–Faudree–Rousseau–Schelp):** For ALL `s, t ≥ 1` and ALL star-size sequences `n : Fin s → ℕ`, `m : Fin t → ℕ`, `sizeRamsey (starForest s n) (starForest t m) ≤ erdos561Target s t n m`. -/ theorem sizeRamsey_starForest_le {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) (n : Fin s → ℕ) (m : Fin t → ℕ) : sizeRamsey (starForest s n) (starForest t m) ≤ erdos561Target s t n m := Nat.sInf_le (starForest_target_mem_arrowing hs ht n m) end UpperBound /-! ## Section 3: Greedy Peeling Master Reduction -/ section PeelingReduction /-- Restrict a graph `G` to edges with both endpoints outside a deleted vertex set `P`. Keeping the ambient vertex type `V` eliminates subtype coercions throughout induction. -/ def restrictOutside {V : Type*} (G : SimpleGraph V) (P : Finset V) : SimpleGraph V where Adj u v := u ∉ P ∧ v ∉ P ∧ G.Adj u v symm := ⟨fun _ _ h ↦ ⟨h.2.1, h.1, h.2.2.symm⟩⟩ loopless := ⟨fun _ h ↦ G.loopless.irrefl _ h.2.2⟩ lemma restrictOutside_le {V : Type*} (G : SimpleGraph V) (P : Finset V) : restrictOutside G P ≤ G := fun _ _ h ↦ h.2.2 @[simp] lemma restrictOutside_empty {V : Type*} (G : SimpleGraph V) : restrictOutside G ∅ = G := by ext u v; simp [restrictOutside] lemma restrictOutside_insert_edge_card {V : Type*} [Fintype V] (G : SimpleGraph V) (P : Finset V) (v : V) : (restrictOutside G (insert v P)).edgeFinset.card + (restrictOutside G P).degree v = (restrictOutside G P).edgeFinset.card := by let H := restrictOutside G P let H' := restrictOutside G (insert v P) have hsub : H'.edgeFinset ⊆ H.edgeFinset := by intro e he induction e using Sym2.ind with | _ x y => rw [SimpleGraph.mem_edgeFinset] at he ⊢ exact ⟨fun hx ↦ he.1 (Finset.mem_insert_of_mem hx), fun hy ↦ he.2.1 (Finset.mem_insert_of_mem hy), he.2.2⟩ have hdiff : (H.edgeFinset \ H'.edgeFinset).card = H.degree v := by rw [← SimpleGraph.card_neighborFinset_eq_degree] symm refine Finset.card_bij (fun w _ ↦ s(v, w)) (fun w hw ↦ ?_) (fun w₁ _ w₂ _ h ↦ ?_) (fun e he ↦ ?_) · rw [SimpleGraph.mem_neighborFinset] at hw rw [Finset.mem_sdiff, SimpleGraph.mem_edgeFinset, SimpleGraph.mem_edgeFinset] exact ⟨hw, fun h' ↦ h'.1 (Finset.mem_insert_self v P)⟩ · rw [Sym2.eq_iff] at h rcases h with ⟨_, h⟩ | ⟨h1, h2⟩ · exact h · exact h2.trans h1 · induction e using Sym2.ind with | _ x y => rw [Finset.mem_sdiff, SimpleGraph.mem_edgeFinset, SimpleGraph.mem_edgeFinset] at he rcases he with ⟨hxy, hnot⟩ have hxy' : x = v ∨ y = v := by by_contra hneither push Not at hneither apply hnot refine ⟨?_, ?_, hxy.2.2⟩ · rw [Finset.mem_insert]; push Not; exact ⟨hneither.1, hxy.1⟩ · rw [Finset.mem_insert]; push Not; exact ⟨hneither.2, hxy.2.1⟩ rcases hxy' with rfl | rfl · exact ⟨y, (SimpleGraph.mem_neighborFinset _ _ _).mpr hxy, rfl⟩ · exact ⟨x, (SimpleGraph.mem_neighborFinset _ _ _).mpr hxy.symm, Sym2.eq_swap⟩ rw [← hdiff, add_comm] exact Finset.card_sdiff_add_card_eq_card hsub /-- **Greedy Peeling Lemma:** Given a finite graph `G` and positive thresholds `b : ℕ → ℕ` on `range M`, if `e(G) < ∑ r < M, b r`, then greedy max-degree vertex deletion halts at some step `r < M` with a deleted set `P` of cardinality `r` such that `H := restrictOutside G P` satisfies `Δ(H) < b r` and `e(H) < ∑ q ∈ Ico r M, b q`. -/ lemma greedy_peeling_exists {V : Type*} [Fintype V] (G : SimpleGraph V) (M : ℕ) (b : ℕ → ℕ) (hb_pos : ∀ r < M, 1 ≤ b r) (hcard : G.edgeFinset.card < ∑ r ∈ Finset.range M, b r) : ∃ (r : ℕ) (_ : r < M) (P : Finset V), P.card = r ∧ (∀ v : V, (restrictOutside G P).degree v < b r) ∧ (restrictOutside G P).edgeFinset.card < ∑ q ∈ Finset.Ico r M, b q := by suffices h : ∀ k (hk : k ≤ M), (∃ (r : ℕ) (_ : r < k) (P : Finset V), P.card = r ∧ (∀ v : V, (restrictOutside G P).degree v < b r) ∧ (restrictOutside G P).edgeFinset.card < ∑ q ∈ Finset.Ico r M, b q) ∨ (∃ P : Finset V, P.card = k ∧ (restrictOutside G P).edgeFinset.card + ∑ q ∈ Finset.range k, b q ≤ G.edgeFinset.card) by rcases h M le_rfl with ⟨r, hr, P, hP, hdeg, hedge⟩ | ⟨P, _, hle⟩ · exact ⟨r, hr, P, hP, hdeg, hedge⟩ · omega intro k hk induction k with | zero => right refine ⟨∅, Finset.card_empty, ?_⟩ rw [restrictOutside_empty]; simp | succ k ih => rcases ih (by omega) with ⟨r, hr, P, hP, hdeg, hedge⟩ | ⟨P, hP, hle⟩ · left exact ⟨r, Nat.lt_succ_of_lt hr, P, hP, hdeg, hedge⟩ · by_cases hstop : ∀ v : V, (restrictOutside G P).degree v < b k · left refine ⟨k, Nat.lt_succ_self k, P, hP, hstop, ?_⟩ have hsplit : ∑ q ∈ Finset.range M, b q = ∑ q ∈ Finset.range k, b q + ∑ q ∈ Finset.Ico k M, b q := by rw [← Finset.sum_union] · congr 1; ext q; simp only [Finset.mem_range, Finset.mem_union, Finset.mem_Ico]; omega · rw [Finset.disjoint_left]; intro q h1 h2 rw [Finset.mem_range] at h1; rw [Finset.mem_Ico] at h2; omega omega · push Not at hstop obtain ⟨v, hv⟩ := hstop have hbk_pos : 1 ≤ b k := hb_pos k (by omega) have hvP : v ∉ P := by intro hmem have hdeg0 : (restrictOutside G P).degree v = 0 := by rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false] intro hadj exact hadj.1 hmem omega right refine ⟨insert v P, by rw [Finset.card_insert_of_notMem hvP, hP], ?_⟩ have hins := restrictOutside_insert_edge_card G P v rw [Finset.sum_range_succ] omega /-- A graph `H` admits an `(a, b)`-edge-decomposition if it has a subgraph `R ≤ H` with `Δ(R) ≤ a` and `Δ(H \ R) ≤ b`. -/ def HasDecomp {V : Type*} [Fintype V] (H : SimpleGraph V) (a b : ℕ) : Prop := ∃ R : SimpleGraph V, R ≤ H ∧ (∀ v : V, R.degree v ≤ a) ∧ (∀ v : V, (H \ R).degree v ≤ b) /-- **Master Peeling-to-Coloring Reduction:** Given `G : SimpleGraph V`, antitone positive star-size sequences `n, m`, indices `i : Fin s`, `j : Fin t`, and a peeled set `P : Finset V` of size `i.val + j.val`: if `restrictOutside G P` admits an `(n i - 1, m j - 1)`-edge-decomposition, then `G` admits a 2-coloring `R ≤ G` containing NEITHER a red `starForest s n` NOR a blue `starForest t m`. -/ lemma not_arrows_of_peeling_decomp {V : Type*} [Fintype V] {s t : ℕ} {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) (G : SimpleGraph V) (i : Fin s) (j : Fin t) (P : Finset V) (hPcard : P.card = i.val + j.val) (hdecomp : HasDecomp (restrictOutside G P) (n i - 1) (m j - 1)) : ∃ R : SimpleGraph V, R ≤ G ∧ ¬(starForest s n).IsContained R ∧ ¬(starForest t m).IsContained (G \ R) := by obtain ⟨A, hAP, hAcard⟩ := Finset.exists_subset_card_eq (show i.val ≤ P.card by omega) let B : Finset V := P \ A have hBcard : B.card = j.val := by rw [Finset.card_sdiff_of_subset hAP]; omega have hAB_union : A ∪ B = P := Finset.union_sdiff_of_subset hAP obtain ⟨RW, hRWle, hRWdeg, hBWdeg⟩ := hdecomp let R : SimpleGraph V := { Adj := fun u v ↦ G.Adj u v ∧ (u ∈ A ∨ v ∈ A ∨ (u ∉ P ∧ v ∉ P ∧ RW.Adj u v)) symm := ⟨fun u v h ↦ by refine ⟨h.1.symm, ?_⟩ rcases h.2 with hu | hv | ⟨huP, hvP, hRW⟩ · exact Or.inr (Or.inl hu) · exact Or.inl hv · exact Or.inr (Or.inr ⟨hvP, huP, hRW.symm⟩)⟩ loopless := ⟨fun v h ↦ G.loopless.irrefl v h.1⟩ } have hRle : R ≤ G := fun _ _ h ↦ h.1 refine ⟨R, hRle, ?_, ?_⟩ · rintro ⟨f⟩ let S : Fin (i.val + 1) → Finset V := fun p ↦ Finset.univ.image (fun x : Fin (n ⟨p.val, by omega⟩ + 1) ↦ f ⟨⟨p.val, by omega⟩, x⟩) have hexists : ∃ p : Fin (i.val + 1), Disjoint (S p) A := by by_contra hall push Not at hall have hpick : ∀ p : Fin (i.val + 1), ∃ v ∈ A, v ∈ S p := by intro p have hnd := hall p rw [Finset.not_disjoint_iff] at hnd obtain ⟨v, hvS, hvA⟩ := hnd exact ⟨v, hvA, hvS⟩ choose g hgA hgS using hpick have hginj : Function.Injective g := by intro p₁ p₂ hEq have h1 := hgS p₁ have h2 := hgS p₂ rw [hEq] at h1 rw [Finset.mem_image] at h1 h2 obtain ⟨x₁, _, hx₁⟩ := h1 obtain ⟨x₂, _, hx₂⟩ := h2 have hf := f.injective (hx₁.trans hx₂.symm) have hp := congrArg (fun z : Σ k : Fin s, Fin (n k + 1) ↦ z.1.val) hf exact Fin.ext hp have hcard_le : (Finset.univ : Finset (Fin (i.val + 1))).card ≤ A.card := by calc (Finset.univ : Finset (Fin (i.val + 1))).card = (Finset.univ.image g).card := (Finset.card_image_of_injective _ hginj).symm _ ≤ A.card := Finset.card_le_card (by intro v hv; rw [Finset.mem_image] at hv; obtain ⟨p, _, rfl⟩ := hv; exact hgA p) simp [hAcard] at hcard_le obtain ⟨p, hdisj⟩ := hexists let pi : Fin s := ⟨p.val, by omega⟩ let c : V := f ⟨pi, ⟨0, Nat.zero_lt_succ _⟩⟩ have hcA : c ∉ A := by intro hc exact Finset.disjoint_left.mp hdisj (Finset.mem_image.mpr ⟨⟨0, Nat.zero_lt_succ _⟩, Finset.mem_univ _, rfl⟩) hc have hleaves : n pi ≤ RW.degree c := by rw [← SimpleGraph.card_neighborFinset_eq_degree] let φ : Fin (n pi) → V := fun x ↦ f ⟨pi, ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩⟩ have hφ_inj : Function.Injective φ := by intro x₁ x₂ h have hf := f.injective h have hx := congrArg (fun z : Σ k : Fin s, Fin (n k + 1) ↦ z.2.val) hf exact Fin.ext (Nat.succ.inj hx) calc n pi = (Finset.univ : Finset (Fin (n pi))).card := by simp _ = (Finset.univ.image φ).card := (Finset.card_image_of_injective _ hφ_inj).symm _ ≤ (RW.neighborFinset c).card := Finset.card_le_card (by intro w hw rw [Finset.mem_image] at hw obtain ⟨x, _, rfl⟩ := hw rw [SimpleGraph.mem_neighborFinset] have hadj_R : R.Adj c (φ x) := f.toHom.map_rel (starForest_adj_center pi ⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩ (Nat.succ_ne_zero _)) have hwA : φ x ∉ A := by intro hmem exact Finset.disjoint_left.mp hdisj (Finset.mem_image.mpr ⟨⟨x.val + 1, Nat.succ_lt_succ x.isLt⟩, Finset.mem_univ _, rfl⟩) hmem rcases hadj_R.2 with h1 | h2 | ⟨_, _, hRW⟩ · exact absurd h1 hcA · exact absurd h2 hwA · exact hRW) have hni : n i ≤ n pi := hn_anti (show pi ≤ i by exact Fin.mk_le_mk.mpr (by omega)) have hdeg := hRWdeg c have hpos := hn_pos i omega · rintro ⟨g⟩ let T : Fin (j.val + 1) → Finset V := fun q ↦ Finset.univ.image (fun y : Fin (m ⟨q.val, by omega⟩ + 1) ↦ g ⟨⟨q.val, by omega⟩, y⟩) have hexists : ∃ q : Fin (j.val + 1), Disjoint (T q) B := by by_contra hall push Not at hall have hpick : ∀ q : Fin (j.val + 1), ∃ v ∈ B, v ∈ T q := by intro q have hnd := hall q rw [Finset.not_disjoint_iff] at hnd obtain ⟨v, hvT, hvB⟩ := hnd exact ⟨v, hvB, hvT⟩ choose h hhB hhT using hpick have hhinj : Function.Injective h := by intro q₁ q₂ hEq have h1 := hhT q₁ have h2 := hhT q₂ rw [hEq] at h1 rw [Finset.mem_image] at h1 h2 obtain ⟨y₁, _, hy₁⟩ := h1 obtain ⟨y₂, _, hy₂⟩ := h2 have hg := g.injective (hy₁.trans hy₂.symm) have hq := congrArg (fun z : Σ k : Fin t, Fin (m k + 1) ↦ z.1.val) hg exact Fin.ext hq have hcard_le : (Finset.univ : Finset (Fin (j.val + 1))).card ≤ B.card := by calc (Finset.univ : Finset (Fin (j.val + 1))).card = (Finset.univ.image h).card := (Finset.card_image_of_injective _ hhinj).symm _ ≤ B.card := Finset.card_le_card (by intro v hv; rw [Finset.mem_image] at hv; obtain ⟨q, _, rfl⟩ := hv; exact hhB q) simp [hBcard] at hcard_le obtain ⟨q, hdisj⟩ := hexists let qj : Fin t := ⟨q.val, by omega⟩ let c : V := g ⟨qj, ⟨0, Nat.zero_lt_succ _⟩⟩ have hcB : c ∉ B := by intro hc exact Finset.disjoint_left.mp hdisj (Finset.mem_image.mpr ⟨⟨0, Nat.zero_lt_succ _⟩, Finset.mem_univ _, rfl⟩) hc have hleaves : m qj ≤ (restrictOutside G P \ RW).degree c := by rw [← SimpleGraph.card_neighborFinset_eq_degree] let φ : Fin (m qj) → V := fun y ↦ g ⟨qj, ⟨y.val + 1, Nat.succ_lt_succ y.isLt⟩⟩ have hφ_inj : Function.Injective φ := by intro y₁ y₂ h have hg := g.injective h have hy := congrArg (fun z : Σ k : Fin t, Fin (m k + 1) ↦ z.2.val) hg exact Fin.ext (Nat.succ.inj hy) calc m qj = (Finset.univ : Finset (Fin (m qj))).card := by simp _ = (Finset.univ.image φ).card := (Finset.card_image_of_injective _ hφ_inj).symm _ ≤ ((restrictOutside G P \ RW).neighborFinset c).card := Finset.card_le_card (by intro w hw rw [Finset.mem_image] at hw obtain ⟨y, _, rfl⟩ := hw rw [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] have hadj_B : (G \ R).Adj c (φ y) := g.toHom.map_rel (starForest_adj_center qj ⟨y.val + 1, Nat.succ_lt_succ y.isLt⟩ (Nat.succ_ne_zero _)) rw [SimpleGraph.sdiff_adj] at hadj_B have hwB : φ y ∉ B := by intro hmem exact Finset.disjoint_left.mp hdisj (Finset.mem_image.mpr ⟨⟨y.val + 1, Nat.succ_lt_succ y.isLt⟩, Finset.mem_univ _, rfl⟩) hmem have hcA : c ∉ A := fun hcA ↦ hadj_B.2 ⟨hadj_B.1, Or.inl hcA⟩ have hwA : φ y ∉ A := fun hwA ↦ hadj_B.2 ⟨hadj_B.1, Or.inr (Or.inl hwA)⟩ have hcP : c ∉ P := by rw [← hAB_union, Finset.mem_union]; rintro (h | h) <;> contradiction have hwP : φ y ∉ P := by rw [← hAB_union, Finset.mem_union]; rintro (h | h) <;> contradiction refine ⟨⟨hcP, hwP, hadj_B.1⟩, ?_⟩ intro hRW exact hadj_B.2 ⟨hadj_B.1, Or.inr (Or.inr ⟨hcP, hwP, hRW⟩)⟩) have hmj : m j ≤ m qj := hm_anti (show qj ≤ j by exact Fin.mk_le_mk.mpr (by omega)) have hdeg := hBWdeg c have hpos := hm_pos j omega end PeelingReduction /-! ## Section 4: Elementary Edge-Decomposition Engines (Zero Lovász) -/ section DecompEngines /-! ### Engine 1: Unit-Star Trivial Decompositions -/ lemma hasDecomp_zero_left {V : Type*} [Fintype V] (H : SimpleGraph V) (b : ℕ) (hdeg : ∀ v, H.degree v ≤ b) : HasDecomp H 0 b := by refine ⟨⊥, bot_le, fun v ↦ by simp, fun v ↦ ?_⟩ have hle : ((H \ ⊥).neighborFinset v).card ≤ (H.neighborFinset v).card := by refine Finset.card_le_card (fun w hw ↦ ?_) rw [SimpleGraph.mem_neighborFinset] at hw ⊢ exact ((SimpleGraph.sdiff_adj _ _ _ _).mp hw).1 have h1 : (H \ ⊥).degree v = ((H \ ⊥).neighborFinset v).card := by rw [SimpleGraph.card_neighborFinset_eq_degree] have h2 : H.degree v = (H.neighborFinset v).card := by rw [SimpleGraph.card_neighborFinset_eq_degree] have h3 : (H \ ⊥).degree v ≤ b := by have := hdeg v; omega convert h3 lemma hasDecomp_zero_right {V : Type*} [Fintype V] (H : SimpleGraph V) (a : ℕ) (hdeg : ∀ v, H.degree v ≤ a) : HasDecomp H a 0 := by refine ⟨H, le_rfl, hdeg, fun v ↦ ?_⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] have hempty : (H \ H).neighborFinset v = ∅ := by ext w simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false] intro hw have := (SimpleGraph.sdiff_adj _ _ _ _).mp hw exact this.2 this.1 rw [hempty, Finset.card_empty] /-! ### Trail Machinery (Shared by Even–Even & Diagonal Eulerian Engines) -/ /-- A directed trail in `G` is a list of directed arcs `(u, v)` whose edges lie in `G`, consecutive arcs chain (`(u, v)` followed by `(v, w)`), and no undirected edge `s(u, v)` repeats. -/ def IsArcTrail {V : Type*} (G : SimpleGraph V) : List (V × V) → Prop | [] => True | (u, v) :: rest => G.Adj u v ∧ (∀ p, rest.head? = some p → v = p.1) ∧ (∀ p ∈ rest, s(u, v) ≠ s(p.1, p.2)) ∧ IsArcTrail G rest /-- Undirected edge list of a directed arc list. -/ def arcEdges {V : Type*} (L : List (V × V)) : List (Sym2 V) := L.map (fun p ↦ s(p.1, p.2)) /-- Count of occurrences of `v` as start of an arc in `L`. -/ noncomputable def arcOutDeg {V : Type*} (L : List (V × V)) (v : V) : ℕ := (L.filter (fun p ↦ p.1 = v)).length /-- Count of occurrences of `v` as end of an arc in `L`. -/ noncomputable def arcInDeg {V : Type*} (L : List (V × V)) (v : V) : ℕ := (L.filter (fun p ↦ p.2 = v)).length lemma isArcTrail_nodup_edges {V : Type*} {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) : (arcEdges L).Nodup := by induction L with | nil => simp [arcEdges] | cons p rest ih => rcases p with ⟨u, v⟩ rcases h with ⟨_, _, hne, hrest⟩ simp only [arcEdges, List.map_cons, List.nodup_cons] refine ⟨?_, ih hrest⟩ intro hmem rw [List.mem_map] at hmem obtain ⟨q, hq, heq⟩ := hmem exact hne q hq heq.symm lemma isArcTrail_subset_edges {V : Type*} {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) : ∀ e ∈ arcEdges L, e ∈ G.edgeSet := by induction L with | nil => simp [arcEdges] | cons p rest ih => rcases p with ⟨u, v⟩ rcases h with ⟨hadj, _, _, hrest⟩ intro e he simp only [arcEdges, List.map_cons, List.mem_cons] at he rcases he with rfl | hmem · exact hadj · exact ih hrest e hmem lemma isArcTrail_length_le {V : Type*} [Fintype V] {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) : L.length ≤ G.edgeFinset.card := by have hnodup := isArcTrail_nodup_edges h have hsub : (arcEdges L).toFinset ⊆ G.edgeFinset := by intro e he rw [List.mem_toFinset] at he rw [SimpleGraph.mem_edgeFinset] exact isArcTrail_subset_edges h e he calc L.length = (arcEdges L).length := by simp [arcEdges] _ = (arcEdges L).toFinset.card := (List.toFinset_card_of_nodup hnodup).symm _ ≤ G.edgeFinset.card := Finset.card_le_card hsub /-- For any non-empty chained arc list from `s` to `t`, `arcOutDeg L v` and `arcInDeg L v` match everywhere except at `s` and `t`. -/ lemma arcOutDeg_inDeg_eq {V : Type*} {G : SimpleGraph V} : ∀ (L : List (V × V)), IsArcTrail G L → ∀ (s t : V), (∀ p, L.head? = some p → p.1 = s) → (∀ p, L.getLast? = some p → p.2 = t) → L ≠ [] → ∀ v : V, arcOutDeg L v + (if v = t then 1 else 0) = arcInDeg L v + (if v = s then 1 else 0) := by intro L induction L with | nil => intro _ _ _ _ _ hne; exact absurd rfl hne | cons p rest ih => rcases p with ⟨u, w⟩ intro htrail s t hhead hlast _ v have hus : u = s := hhead (u, w) rfl subst hus rcases htrail with ⟨_, hchain, _, hrest⟩ cases rest with | nil => have hwt : w = t := hlast (u, w) rfl subst hwt simp only [arcOutDeg, arcInDeg, List.filter_cons, List.filter_nil] by_cases h1 : u = v <;> by_cases h2 : w = v <;> simp [h1, h2, eq_comm] | cons q tail => have hchain' : w = q.1 := hchain q rfl have hlast' : ∀ r, (q :: tail).getLast? = some r → r.2 = t := by intro r hr apply hlast r simpa using hr have hih := ih hrest w t (by intro r hr; simp at hr; subst hr; exact hchain'.symm) hlast' (List.cons_ne_nil _ _) v simp only [arcOutDeg, arcInDeg, List.filter_cons] at hih ⊢ by_cases hu : u = v <;> by_cases hw : w = v <;> simp [hu, hw, eq_comm] at hih ⊢ <;> omega /-- Number of edges of `L` incident to `v` equals `arcOutDeg L v + arcInDeg L v`. -/ lemma count_incident_arcEdges {V : Type*} [Fintype V] {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) (v : V) : ((arcEdges L).toFinset.filter (fun e ↦ v ∈ e)).card = arcOutDeg L v + arcInDeg L v := by induction L with | nil => simp [arcEdges, arcOutDeg, arcInDeg] | cons p rest ih => rcases p with ⟨x, y⟩ rcases h with ⟨hadj, _, hne, hrest⟩ have hxy : x ≠ y := hadj.ne have hnotmem : s(x, y) ∉ (arcEdges rest).toFinset := by rw [List.mem_toFinset, arcEdges, List.mem_map] rintro ⟨q, hq, heq⟩ exact hne q hq heq.symm have hih := ih hrest have hcons : (arcEdges ((x, y) :: rest)).toFinset = insert s(x, y) (arcEdges rest).toFinset := by simp [arcEdges] rw [hcons] simp only [arcOutDeg, arcInDeg, List.filter_cons] at hih ⊢ by_cases hv : v ∈ s(x, y) · rw [Finset.filter_insert, if_pos hv, Finset.card_insert_of_notMem (by intro hmem; exact hnotmem (Finset.mem_filter.mp hmem).1), hih] rw [Sym2.mem_iff] at hv rcases hv with rfl | rfl · have hne' : y ≠ v := hxy.symm simp [hne', eq_comm]; omega · have hne' : x ≠ v := hxy simp [hne', eq_comm]; omega · rw [Finset.filter_insert, if_neg hv, hih] rw [Sym2.mem_iff] at hv push Not at hv have h1 : x ≠ v := hv.1.symm have h2 : y ≠ v := hv.2.symm simp [h1, h2] /-- Delete the edges of an arc list `L` from `G`. -/ def deleteArcs {V : Type*} (G : SimpleGraph V) (L : List (V × V)) : SimpleGraph V where Adj u v := G.Adj u v ∧ s(u, v) ∉ arcEdges L symm := ⟨fun _ _ h ↦ ⟨h.1.symm, by rw [Sym2.eq_swap]; exact h.2⟩⟩ loopless := ⟨fun v h ↦ G.loopless.irrefl v h.1⟩ lemma deleteArcs_degree {V : Type*} [Fintype V] {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) (v : V) : (deleteArcs G L).degree v + (arcOutDeg L v + arcInDeg L v) = G.degree v := by rw [← count_incident_arcEdges h v] simp only [← SimpleGraph.card_neighborFinset_eq_degree] have hsub : (deleteArcs G L).neighborFinset v ⊆ G.neighborFinset v := by intro w hw rw [SimpleGraph.mem_neighborFinset] at hw ⊢ exact hw.1 have hdiff : (G.neighborFinset v \ (deleteArcs G L).neighborFinset v).card = ((arcEdges L).toFinset.filter (fun e ↦ v ∈ e)).card := by refine Finset.card_bij (fun w _ ↦ s(v, w)) (fun w hw ↦ ?_) (fun w₁ _ w₂ _ hEq ↦ ?_) (fun e he ↦ ?_) · rw [Finset.mem_sdiff, SimpleGraph.mem_neighborFinset, SimpleGraph.mem_neighborFinset] at hw rw [Finset.mem_filter, List.mem_toFinset] refine ⟨?_, Sym2.mem_mk_left v w⟩ by_contra hnot exact hw.2 ⟨hw.1, hnot⟩ · rw [Sym2.eq_iff] at hEq rcases hEq with ⟨_, h⟩ | ⟨h1, h2⟩ · exact h · exact h2.trans h1 · rw [Finset.mem_filter, List.mem_toFinset] at he rcases he with ⟨heL, hve⟩ have heG : e ∈ G.edgeSet := isArcTrail_subset_edges h e heL induction e using Sym2.ind with | _ x y => rw [Sym2.mem_iff] at hve rcases hve with rfl | rfl · refine ⟨y, ?_, rfl⟩ rw [Finset.mem_sdiff, SimpleGraph.mem_neighborFinset, SimpleGraph.mem_neighborFinset] exact ⟨heG, fun hdel ↦ hdel.2 heL⟩ · refine ⟨x, ?_, Sym2.eq_swap⟩ rw [Finset.mem_sdiff, SimpleGraph.mem_neighborFinset, SimpleGraph.mem_neighborFinset] exact ⟨heG.symm, fun hdel ↦ hdel.2 (by rwa [Sym2.eq_swap])⟩ rw [← hdiff, add_comm] exact Finset.card_sdiff_add_card_eq_card hsub lemma deleteArcs_edgeFinset_card {V : Type*} [Fintype V] {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) : (deleteArcs G L).edgeFinset.card + L.length = G.edgeFinset.card := by have hnodup := isArcTrail_nodup_edges h have hsub : (arcEdges L).toFinset ⊆ G.edgeFinset := by intro e he rw [List.mem_toFinset] at he rw [SimpleGraph.mem_edgeFinset] exact isArcTrail_subset_edges h e he have hEq : (deleteArcs G L).edgeFinset = G.edgeFinset \ (arcEdges L).toFinset := by ext e induction e using Sym2.ind with | _ u v => simp only [Finset.mem_sdiff, SimpleGraph.mem_edgeFinset, List.mem_toFinset] rfl have hcardL : (arcEdges L).toFinset.card = L.length := by rw [List.toFinset_card_of_nodup hnodup]; simp [arcEdges] rw [hEq, ← hcardL] exact Finset.card_sdiff_add_card_eq_card hsub /-- In a graph where every vertex has even degree, any non-isolated vertex `v₀` has a nonempty closed arc trail starting and ending at `v₀`. -/ lemma exists_nonempty_closed_trail {V : Type*} [Fintype V] (G : SimpleGraph V) (heven : ∀ v, Even (G.degree v)) (v₀ : V) (hpos : 0 < G.degree v₀) : ∃ L : List (V × V), L ≠ [] ∧ IsArcTrail G L ∧ (∀ p, L.head? = some p → p.1 = v₀) ∧ (∀ p, L.getLast? = some p → p.2 = v₀) := by have hstart : ∃ L : List (V × V), L ≠ [] ∧ IsArcTrail G L ∧ (∀ p, L.head? = some p → p.1 = v₀) := by rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_pos] at hpos obtain ⟨w, hw⟩ := hpos rw [SimpleGraph.mem_neighborFinset] at hw refine ⟨[(v₀, w)], List.cons_ne_nil _ _, ⟨hw, by simp, by simp, trivial⟩, ?_⟩ intro p hp; simp at hp; rw [← hp] suffices hstep : ∀ k (L : List (V × V)), G.edgeFinset.card - L.length ≤ k → L ≠ [] → IsArcTrail G L → (∀ p, L.head? = some p → p.1 = v₀) → ∃ L' : List (V × V), L' ≠ [] ∧ IsArcTrail G L' ∧ (∀ p, L'.head? = some p → p.1 = v₀) ∧ (∀ p, L'.getLast? = some p → p.2 = v₀) by obtain ⟨L, hne, htr, hhd⟩ := hstart exact hstep G.edgeFinset.card L (Nat.sub_le _ _) hne htr hhd intro k induction k with | zero => intro L hk hne htr hhd obtain ⟨p_last, hlast⟩ := Option.isSome_iff_exists.mp (List.getLast?_isSome.mpr hne) by_cases hret : p_last.2 = v₀ · refine ⟨L, hne, htr, hhd, fun p hp ↦ ?_⟩ rw [hlast] at hp; exact (Option.some.inj hp ▸ hret) · exfalso have hbal := arcOutDeg_inDeg_eq L htr v₀ p_last.2 hhd (fun p hp ↦ by rw [hlast] at hp; exact congrArg Prod.snd (Option.some.inj hp).symm) hne p_last.2 simp only [if_true, if_neg hret] at hbal have hdeg := deleteArcs_degree htr p_last.2 have hrem_pos : 0 < (deleteArcs G L).degree p_last.2 := by rcases heven p_last.2 with ⟨m, hm⟩ omega have hed := deleteArcs_edgeFinset_card htr have hlen := isArcTrail_length_le htr have hzero : (deleteArcs G L).edgeFinset.card = 0 := by omega rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_pos] at hrem_pos obtain ⟨w, hw⟩ := hrem_pos rw [SimpleGraph.mem_neighborFinset] at hw have hmem : s(p_last.2, w) ∈ (deleteArcs G L).edgeFinset := SimpleGraph.mem_edgeFinset.mpr hw exact Finset.card_ne_zero.mpr ⟨_, hmem⟩ hzero | succ k ih => intro L hk hne htr hhd obtain ⟨p_last, hlast⟩ := Option.isSome_iff_exists.mp (List.getLast?_isSome.mpr hne) by_cases hret : p_last.2 = v₀ · refine ⟨L, hne, htr, hhd, fun p hp ↦ ?_⟩ rw [hlast] at hp; exact (Option.some.inj hp ▸ hret) · have hbal := arcOutDeg_inDeg_eq L htr v₀ p_last.2 hhd (fun p hp ↦ by rw [hlast] at hp; exact congrArg Prod.snd (Option.some.inj hp).symm) hne p_last.2 simp only [if_true, if_neg hret] at hbal have hdeg := deleteArcs_degree htr p_last.2 have hrem_pos : 0 < (deleteArcs G L).degree p_last.2 := by rcases heven p_last.2 with ⟨m, hm⟩ omega rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_pos] at hrem_pos obtain ⟨w, hw⟩ := hrem_pos rw [SimpleGraph.mem_neighborFinset] at hw have hadj : G.Adj p_last.2 w := hw.1 have hnotmem : s(p_last.2, w) ∉ arcEdges L := hw.2 let L' := L ++ [(p_last.2, w)] have htr' : IsArcTrail G L' := by clear ih hk hbal hdeg hw hret hhd induction L with | nil => exact absurd rfl hne | cons a rest ihr => rcases a with ⟨x, y⟩ rcases htr with ⟨hxy, hch, hne_e, hrest⟩ cases rest with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hlast subst hlast refine ⟨hxy, ?_, ?_, ⟨hadj, by simp, by simp, trivial⟩⟩ · intro p hp; simp at hp; rw [← hp] · intro p hp simp at hp subst hp intro heq apply hnotmem simp [arcEdges, heq] | cons b tail => have hlast' : (b :: tail).getLast? = some p_last := by simpa using hlast have hnotmem' : s(p_last.2, w) ∉ arcEdges (b :: tail) := fun hm ↦ hnotmem (by simp [arcEdges] at hm ⊢; exact Or.inr hm) have hih := ihr (List.cons_ne_nil _ _) hrest hlast' hnotmem' refine ⟨hxy, ?_, ?_, hih⟩ · intro p hp; simp at hp; exact hch p (by simp [hp]) · intro p hp rcases List.mem_append.mp hp with hp | hp · exact hne_e p hp · rw [List.mem_singleton] at hp; subst hp intro heq; apply hnotmem; simp [arcEdges, heq] have hhd' : ∀ p, L'.head? = some p → p.1 = v₀ := by intro p hp apply hhd p cases L with | nil => exact absurd rfl hne | cons a rest => simpa [L'] using hp have hlen' : L'.length = L.length + 1 := by simp [L'] have hle_tot := isArcTrail_length_le htr' exact ih L' (by omega) (by simp [L']) htr' hhd' /-! ### Engine 2: Even–Even Decomposition (Balanced Orientation + König Bipartite Edge Coloring) -/ /-- Every even-degree finite simple graph admits a balanced orientation (`outDeg = inDeg`). -/ lemma exists_balanced_orientation {V : Type*} [Fintype V] (G : SimpleGraph V) (heven : ∀ v, Even (G.degree v)) : ∃ dir : V → V → Prop, (∀ u v, G.Adj u v ↔ dir u v ∨ dir v u) ∧ (∀ u v, ¬(dir u v ∧ dir v u)) ∧ (∀ v, (Finset.univ.filter (fun w ↦ dir v w)).card = (Finset.univ.filter (fun w ↦ dir w v)).card) := by suffices h : ∀ m (G : SimpleGraph V), G.edgeFinset.card ≤ m → (∀ v, Even (G.degree v)) → ∃ dir : V → V → Prop, (∀ u v, G.Adj u v ↔ dir u v ∨ dir v u) ∧ (∀ u v, ¬(dir u v ∧ dir v u)) ∧ (∀ v, (Finset.univ.filter (fun w ↦ dir v w)).card = (Finset.univ.filter (fun w ↦ dir w v)).card) by exact h G.edgeFinset.card G le_rfl heven intro m induction m with | zero => intro G hm _ refine ⟨fun _ _ ↦ False, ?_, by simp, by simp⟩ intro u v simp only [or_self, iff_false] intro hadj have hmem : s(u, v) ∈ G.edgeFinset := SimpleGraph.mem_edgeFinset.mpr hadj exact Nat.not_lt_zero _ (lt_of_lt_of_le (Finset.card_pos.mpr ⟨_, hmem⟩) hm) | succ m ih => intro G hm hev by_cases hempty : G.edgeFinset.card = 0 · exact ih G (by omega) hev · obtain ⟨e, he⟩ := Finset.card_pos.mp (Nat.pos_of_ne_zero hempty) induction e using Sym2.ind with | _ v₀ w₀ => rw [SimpleGraph.mem_edgeFinset] at he have hv₀_pos : 0 < G.degree v₀ := by rw [← SimpleGraph.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨w₀, (SimpleGraph.mem_neighborFinset _ _ _).mpr he⟩ obtain ⟨L, hLne, hLtr, hLhd, hLlast⟩ := exists_nonempty_closed_trail G hev v₀ hv₀_pos let G' := deleteArcs G L have hG'_card : G'.edgeFinset.card ≤ m := by have hed : G'.edgeFinset.card + L.length = G.edgeFinset.card := deleteArcs_edgeFinset_card hLtr have hpos : 0 < L.length := List.length_pos_iff.mpr hLne omega have hG'_even : ∀ v, Even (G'.degree v) := by intro v have hbal := arcOutDeg_inDeg_eq L hLtr v₀ v₀ hLhd hLlast hLne v have hdeg : G'.degree v + (arcOutDeg L v + arcInDeg L v) = G.degree v := deleteArcs_degree hLtr v rcases hev v with ⟨k, hk⟩ refine ⟨k - arcOutDeg L v, ?_⟩ omega obtain ⟨dir', hdir'_adj, hdir'_anti, hdir'_bal⟩ := ih G' hG'_card hG'_even let dir : V → V → Prop := fun u v ↦ dir' u v ∨ (u, v) ∈ L have hL_disj : ∀ u v, (u, v) ∈ L → ¬dir' u v ∧ ¬dir' v u := by intro u v huv have heL : s(u, v) ∈ arcEdges L := List.mem_map.mpr ⟨(u, v), huv, rfl⟩ have hnotG' : ¬G'.Adj u v := fun h ↦ h.2 heL rw [hdir'_adj] at hnotG' push Not at hnotG' exact hnotG' have hL_anti : ∀ u v, ¬((u, v) ∈ L ∧ (v, u) ∈ L) := by intro u v ⟨h1, h2⟩ have huv_ne : u ≠ v := by have heG := isArcTrail_subset_edges hLtr s(u, v) (List.mem_map.mpr ⟨(u, v), h1, rfl⟩) exact SimpleGraph.Adj.ne heG clear ih hm hev hG'_card hG'_even dir' hdir'_adj hdir'_anti hdir'_bal dir hL_disj G' hLne hLhd hLlast induction L with | nil => exact absurd h1 List.not_mem_nil | cons p rest ihr => rcases p with ⟨x, y⟩ rcases hLtr with ⟨_, _, hne_e, hrest⟩ simp only [List.mem_cons] at h1 h2 rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · have := h1.trans h2.symm exact huv_ne (congrArg Prod.fst this) · rcases Prod.mk.inj h1 with ⟨rfl, rfl⟩ exact hne_e (v, u) h2 Sym2.eq_swap · rcases Prod.mk.inj h2 with ⟨rfl, rfl⟩ exact hne_e (u, v) h1 Sym2.eq_swap · exact ihr hrest h1 h2 refine ⟨dir, ?_, ?_, ?_⟩ · intro u v constructor · intro huv by_cases heL : s(u, v) ∈ arcEdges L · rw [arcEdges, List.mem_map] at heL obtain ⟨⟨x, y⟩, hxyL, hsym⟩ := heL rw [Sym2.eq_iff] at hsym rcases hsym with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact Or.inl (Or.inr hxyL) · exact Or.inr (Or.inr hxyL) · have hG' : G'.Adj u v := ⟨huv, heL⟩ rw [hdir'_adj] at hG' rcases hG' with h1 | h2 · exact Or.inl (Or.inl h1) · exact Or.inr (Or.inl h2) · rintro ((h | h) | (h | h)) · exact ((hdir'_adj u v).mpr (Or.inl h)).1 · exact isArcTrail_subset_edges hLtr s(u, v) (List.mem_map.mpr ⟨(u, v), h, rfl⟩) · exact ((hdir'_adj u v).mpr (Or.inr h)).1 · exact (isArcTrail_subset_edges hLtr s(v, u) (List.mem_map.mpr ⟨(v, u), h, rfl⟩)).symm · intro u v ⟨h1, h2⟩ rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 · exact hdir'_anti u v ⟨h1, h2⟩ · exact (hL_disj v u h2).2 h1 · exact (hL_disj u v h1).2 h2 · exact hL_anti u v ⟨h1, h2⟩ · intro v have hL_nodup : L.Nodup := List.Nodup.of_map _ (isArcTrail_nodup_edges hLtr) have hout_L : (Finset.univ.filter (fun w ↦ (v, w) ∈ L)).card = arcOutDeg L v := by have hnodup_f : (L.filter (fun p ↦ p.1 = v)).Nodup := hL_nodup.filter _ unfold arcOutDeg rw [← List.toFinset_card_of_nodup hnodup_f] refine Finset.card_bij (fun w _ ↦ (v, w)) (fun w hw ↦ by rw [Finset.mem_filter] at hw rw [List.mem_toFinset, List.mem_filter] exact ⟨hw.2, by simp⟩) (fun w₁ _ w₂ _ h ↦ congrArg Prod.snd h) (fun p hp ↦ by rw [List.mem_toFinset, List.mem_filter] at hp rcases p with ⟨x, y⟩ simp only [decide_eq_true_eq] at hp rcases hp with ⟨hmem, rfl⟩ exact ⟨y, Finset.mem_filter.mpr ⟨Finset.mem_univ y, hmem⟩, rfl⟩) have hin_L : (Finset.univ.filter (fun w ↦ (w, v) ∈ L)).card = arcInDeg L v := by have hnodup_f : (L.filter (fun p ↦ p.2 = v)).Nodup := hL_nodup.filter _ unfold arcInDeg rw [← List.toFinset_card_of_nodup hnodup_f] refine Finset.card_bij (fun w _ ↦ (w, v)) (fun w hw ↦ by rw [Finset.mem_filter] at hw rw [List.mem_toFinset, List.mem_filter] exact ⟨hw.2, by simp⟩) (fun w₁ _ w₂ _ h ↦ congrArg Prod.fst h) (fun p hp ↦ by rw [List.mem_toFinset, List.mem_filter] at hp rcases p with ⟨x, y⟩ simp only [decide_eq_true_eq] at hp rcases hp with ⟨hmem, rfl⟩ exact ⟨x, Finset.mem_filter.mpr ⟨Finset.mem_univ x, hmem⟩, rfl⟩) have hout_split : (Finset.univ.filter (fun w ↦ dir v w)).card = (Finset.univ.filter (fun w ↦ dir' v w)).card + (Finset.univ.filter (fun w ↦ (v, w) ∈ L)).card := by rw [← Finset.card_union_of_disjoint] · congr 1; ext w; simp [dir] · rw [Finset.disjoint_left]; intro w h1 h2 rw [Finset.mem_filter] at h1 h2 exact (hL_disj v w h2.2).1 h1.2 have hin_split : (Finset.univ.filter (fun w ↦ dir w v)).card = (Finset.univ.filter (fun w ↦ dir' w v)).card + (Finset.univ.filter (fun w ↦ (w, v) ∈ L)).card := by rw [← Finset.card_union_of_disjoint] · congr 1; ext w; simp [dir] · rw [Finset.disjoint_left]; intro w h1 h2 rw [Finset.mem_filter] at h1 h2 exact (hL_disj w v h2.2).1 h1.2 have hbal_L := arcOutDeg_inDeg_eq L hLtr v₀ v₀ hLhd hLlast hLne v have h1 : (Finset.univ.filter (fun w ↦ dir v w)).card = (Finset.univ.filter (fun w ↦ dir' v w)).card + arcOutDeg L v := by rw [← hout_L]; convert hout_split have h2 : (Finset.univ.filter (fun w ↦ dir w v)).card = (Finset.univ.filter (fun w ↦ dir' w v)).card + arcInDeg L v := by rw [← hin_L]; convert hin_split have h3 := hdir'_bal v have heq : (Finset.univ.filter (fun w ↦ dir v w)).card = (Finset.univ.filter (fun w ↦ dir w v)).card := by omega convert heq /-- Any graph `H` with `Δ(H) ≤ 2k` admits an orientation with `outDeg ≤ k` and `inDeg ≤ k` at every vertex (by adding one dummy vertex `none : Option V` connected to odd-degree vertices). -/ lemma exists_half_orientation {V : Type*} [Fintype V] (H : SimpleGraph V) (k : ℕ) (hdeg : ∀ v, H.degree v ≤ 2 * k) : ∃ dir : V → V → Prop, (∀ u v, H.Adj u v ↔ dir u v ∨ dir v u) ∧ (∀ u v, ¬(dir u v ∧ dir v u)) ∧ (∀ v, (Finset.univ.filter (fun w ↦ dir v w)).card ≤ k) ∧ (∀ v, (Finset.univ.filter (fun w ↦ dir w v)).card ≤ k) := by let H' : SimpleGraph (Option V) := { Adj := fun a b ↦ match a, b with | some u, some v => H.Adj u v | none, some v => Odd (H.degree v) | some u, none => Odd (H.degree u) | none, none => False symm := ⟨fun a b h ↦ by cases a with | none => cases b with | none => exact h | some v => exact h | some u => cases b with | none => exact h | some v => exact h.symm⟩ loopless := ⟨fun a h ↦ by cases a with | none => exact h | some u => exact H.loopless.irrefl u h⟩ } have hdeg_some : ∀ v : V, H'.degree (some v) = H.degree v + (if Odd (H.degree v) then 1 else 0) := by intro v let S₁ : Finset (Option V) := (H.neighborFinset v).map ⟨Option.some, Option.some_injective V⟩ by_cases hodd : Odd (H.degree v) · rw [if_pos hodd] simp only [← SimpleGraph.card_neighborFinset_eq_degree] have heq : H'.neighborFinset (some v) = insert none S₁ := by ext a cases a with | none => simp only [SimpleGraph.mem_neighborFinset, Finset.mem_insert, true_or, iff_true] exact hodd | some w => simp only [SimpleGraph.mem_neighborFinset, Finset.mem_insert, reduceCtorEq, false_or, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, Option.some.injEq, exists_eq_right] rfl have hnotmem : none ∉ S₁ := by simp [S₁] rw [heq, Finset.card_insert_of_notMem hnotmem, Finset.card_map] · rw [if_neg hodd, add_zero] simp only [← SimpleGraph.card_neighborFinset_eq_degree] have heq : H'.neighborFinset (some v) = S₁ := by ext a cases a with | none => simp only [SimpleGraph.mem_neighborFinset, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, reduceCtorEq, and_false, exists_false, iff_false] exact hodd | some w => simp only [SimpleGraph.mem_neighborFinset, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, Option.some.injEq, exists_eq_right] rfl rw [heq, Finset.card_map] have hdeg_none : Even (H'.degree none) := by have hsum := H.sum_degrees_eq_twice_card_edges have hcard : H'.degree none = (Finset.univ.filter (fun v : V ↦ Odd (H.degree v))).card := by rw [← SimpleGraph.card_neighborFinset_eq_degree] refine Finset.card_bij (fun a ha ↦ match a with | some v => v | none => False.elim (by rw [SimpleGraph.mem_neighborFinset] at ha; exact ha)) (fun a ha ↦ by cases a with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha; exact ha | some v => rw [SimpleGraph.mem_neighborFinset] at ha exact Finset.mem_filter.mpr ⟨Finset.mem_univ v, ha⟩) (fun a₁ ha₁ a₂ ha₂ h ↦ by cases a₁ with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha₁; exact ha₁ | some v₁ => cases a₂ with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha₂; exact ha₂ | some v₂ => exact congrArg Option.some h) (fun v hv ↦ by rw [Finset.mem_filter] at hv exact ⟨some v, (SimpleGraph.mem_neighborFinset _ _ _).mpr hv.2, rfl⟩) rw [hcard] have hmod : (∑ v : V, H.degree v) % 2 = 0 := by rw [hsum]; omega have hparity : (Finset.univ.filter (fun v : V ↦ Odd (H.degree v))).card % 2 = (∑ v : V, H.degree v) % 2 := by have h1 : ∀ v : V, H.degree v % 2 = if Odd (H.degree v) then 1 else 0 := by intro v by_cases ho : Odd (H.degree v) · rw [if_pos ho]; exact Nat.odd_iff.mp ho · rw [if_neg ho]; exact Nat.even_iff.mp (Nat.not_odd_iff_even.mp ho) have h2 : (∑ v : V, H.degree v) % 2 = (∑ v : V, H.degree v % 2) % 2 := by rw [Finset.sum_nat_mod] rw [h2] simp only [h1, Finset.sum_boole, Nat.cast_id] rw [Nat.even_iff, hparity, hmod] have hH'_even : ∀ a : Option V, Even (H'.degree a) := by intro a cases a with | none => exact hdeg_none | some v => rw [hdeg_some v] by_cases ho : Odd (H.degree v) · rw [if_pos ho]; rcases ho with ⟨m, hm⟩; exact ⟨m + 1, by omega⟩ · rw [if_neg ho, add_zero]; exact Nat.not_odd_iff_even.mp ho obtain ⟨dir', hdir'_adj, hdir'_anti, hdir'_bal⟩ := exists_balanced_orientation H' hH'_even let dir : V → V → Prop := fun u v ↦ dir' (some u) (some v) refine ⟨dir, fun u v ↦ hdir'_adj (some u) (some v), fun u v ↦ hdir'_anti (some u) (some v), ?_, ?_⟩ · intro v have hle : (Finset.univ.filter (fun w : V ↦ dir v w)).card ≤ (Finset.univ.filter (fun b : Option V ↦ dir' (some v) b)).card := by calc (Finset.univ.filter (fun w : V ↦ dir v w)).card = ((Finset.univ.filter (fun w : V ↦ dir v w)).map ⟨Option.some, Option.some_injective V⟩).card := (Finset.card_map _).symm _ ≤ (Finset.univ.filter (fun b : Option V ↦ dir' (some v) b)).card := Finset.card_le_card (by intro b hb rw [Finset.mem_map] at hb obtain ⟨w, hw, rfl⟩ := hb exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hw).2⟩) have hsum : (Finset.univ.filter (fun b : Option V ↦ dir' (some v) b)).card + (Finset.univ.filter (fun b : Option V ↦ dir' b (some v))).card = H'.degree (some v) := by rw [← SimpleGraph.card_neighborFinset_eq_degree, ← Finset.card_union_of_disjoint] · congr 1; ext b simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, SimpleGraph.mem_neighborFinset] exact (hdir'_adj (some v) b).symm · rw [Finset.disjoint_left]; intro b h1 h2 rw [Finset.mem_filter] at h1 h2 exact hdir'_anti (some v) b ⟨h1.2, h2.2⟩ have hbal := hdir'_bal (some v) have hdv := hdeg v have hds := hdeg_some v by_cases ho : Odd (H.degree v) · rw [if_pos ho] at hds; rcases ho with ⟨m, hm⟩; omega · rw [if_neg ho, add_zero] at hds; omega · intro v have hle : (Finset.univ.filter (fun w : V ↦ dir w v)).card ≤ (Finset.univ.filter (fun b : Option V ↦ dir' b (some v))).card := by calc (Finset.univ.filter (fun w : V ↦ dir w v)).card = ((Finset.univ.filter (fun w : V ↦ dir w v)).map ⟨Option.some, Option.some_injective V⟩).card := (Finset.card_map _).symm _ ≤ (Finset.univ.filter (fun b : Option V ↦ dir' b (some v))).card := Finset.card_le_card (by intro b hb rw [Finset.mem_map] at hb obtain ⟨w, hw, rfl⟩ := hb exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hw).2⟩) have hsum : (Finset.univ.filter (fun b : Option V ↦ dir' (some v) b)).card + (Finset.univ.filter (fun b : Option V ↦ dir' b (some v))).card = H'.degree (some v) := by rw [← SimpleGraph.card_neighborFinset_eq_degree, ← Finset.card_union_of_disjoint] · congr 1; ext b simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, SimpleGraph.mem_neighborFinset] exact (hdir'_adj (some v) b).symm · rw [Finset.disjoint_left]; intro b h1 h2 rw [Finset.mem_filter] at h1 h2 exact hdir'_anti (some v) b ⟨h1.2, h2.2⟩ have hbal := hdir'_bal (some v) have hdv := hdeg v have hds := hdeg_some v by_cases ho : Odd (H.degree v) · rw [if_pos ho] at hds; rcases ho with ⟨m, hm⟩; omega · rw [if_neg ho, add_zero] at hds; omega /-- Helper: swap two colors `c₁, c₂` in an `Option (Fin k)`. -/ def swapOpt {k : ℕ} (c₁ c₂ : Fin k) (o : Option (Fin k)) : Option (Fin k) := if o = some c₁ then some c₂ else if o = some c₂ then some c₁ else o lemma swapOpt_invol {k : ℕ} (c₁ c₂ : Fin k) (o : Option (Fin k)) : swapOpt c₁ c₂ (swapOpt c₁ c₂ o) = o := by unfold swapOpt by_cases h1 : o = some c₁ · subst h1; by_cases heq : c₁ = c₂ <;> simp [heq] · by_cases h2 : o = some c₂ · subst h2; simp [h1] · simp [h1, h2] lemma swapOpt_inj {k : ℕ} (c₁ c₂ : Fin k) {o₁ o₂ : Option (Fin k)} (h : swapOpt c₁ c₂ o₁ = swapOpt c₁ c₂ o₂) : o₁ = o₂ := by have := congrArg (swapOpt c₁ c₂) h rwa [swapOpt_invol, swapOpt_invol] at this lemma swapOpt_isSome {k : ℕ} (c₁ c₂ : Fin k) (o : Option (Fin k)) : (swapOpt c₁ c₂ o).isSome = o.isSome := by unfold swapOpt split_ifs with h1 h2 · simp [h1] · simp [h2] · rfl lemma swapOpt_eq_of_ne {k : ℕ} (c₁ c₂ : Fin k) {o : Option (Fin k)} (h1 : o ≠ some c₁) (h2 : o ≠ some c₂) : swapOpt c₁ c₂ o = o := by simp [swapOpt, h1, h2] lemma swapOpt_eq_some_iff {k : ℕ} (c₁ c₂ c : Fin k) (o : Option (Fin k)) : swapOpt c₁ c₂ o = some c ↔ o = swapOpt c₁ c₂ (some c) := by constructor · intro h; rw [← h, swapOpt_invol] · intro h; rw [h, swapOpt_invol] lemma swapOpt_some_ne_none {k : ℕ} (c₁ c₂ c : Fin k) : swapOpt c₁ c₂ (some c) ≠ none := by unfold swapOpt split_ifs <;> simp /-- **König's Bipartite Edge Coloring Theorem** (completely elementary, via Kempe-chain swap on bipartite relations `E : V → V → Prop` with max left/right degree ≤ `k`). -/ theorem konig_bipartite_edge_coloring {V : Type*} [Fintype V] (k : ℕ) (E : V → V → Prop) (hL : ∀ u, (Finset.univ.filter (fun v ↦ E u v)).card ≤ k) (hR : ∀ v, (Finset.univ.filter (fun u ↦ E u v)).card ≤ k) : ∃ col : V → V → Option (Fin k), (∀ u v, (col u v).isSome ↔ E u v) ∧ (∀ u v₁ v₂ c, col u v₁ = some c → col u v₂ = some c → v₁ = v₂) ∧ (∀ u₁ u₂ v c, col u₁ v = some c → col u₂ v = some c → u₁ = u₂) := by suffices h : ∀ m (E : V → V → Prop), (Finset.univ.filter (fun p : V × V ↦ E p.1 p.2)).card ≤ m → (∀ u, (Finset.univ.filter (fun v ↦ E u v)).card ≤ k) → (∀ v, (Finset.univ.filter (fun u ↦ E u v)).card ≤ k) → ∃ col : V → V → Option (Fin k), (∀ u v, (col u v).isSome ↔ E u v) ∧ (∀ u v₁ v₂ c, col u v₁ = some c → col u v₂ = some c → v₁ = v₂) ∧ (∀ u₁ u₂ v c, col u₁ v = some c → col u₂ v = some c → u₁ = u₂) by exact h _ E le_rfl hL hR intro m induction m with | zero => intro E hm _ _ refine ⟨fun _ _ ↦ none, ?_, by simp, by simp⟩ intro u v constructor · intro h; simp at h · intro huv have hmem : (u, v) ∈ Finset.univ.filter (fun p : V × V ↦ E p.1 p.2) := Finset.mem_filter.mpr ⟨Finset.mem_univ _, huv⟩ exact absurd (lt_of_lt_of_le (Finset.card_pos.mpr ⟨_, hmem⟩) hm) (Nat.not_lt_zero _) | succ m ih => intro E hm hL hR by_cases hempty : (Finset.univ.filter (fun p : V × V ↦ E p.1 p.2)).card = 0 · exact ih E (by omega) hL hR · obtain ⟨⟨u₀, v₀⟩, huv₀⟩ := Finset.card_pos.mp (Nat.pos_of_ne_zero hempty) have hE₀ : E u₀ v₀ := (Finset.mem_filter.mp huv₀).2 let E' : V → V → Prop := fun u v ↦ E u v ∧ ¬(u = u₀ ∧ v = v₀) have hcard' : (Finset.univ.filter (fun p : V × V ↦ E' p.1 p.2)).card ≤ m := by have hss : Finset.univ.filter (fun p : V × V ↦ E' p.1 p.2) = (Finset.univ.filter (fun p : V × V ↦ E p.1 p.2)).erase (u₀, v₀) := by ext ⟨u, v⟩; simp [E', and_comm] have hce := Finset.card_erase_of_mem huv₀ rw [hss, hce]; omega have hL' : ∀ u, (Finset.univ.filter (fun v ↦ E' u v)).card ≤ k := fun u ↦ le_trans (Finset.card_le_card (fun v hv ↦ Finset.mem_filter.mpr ⟨Finset.mem_univ v, (Finset.mem_filter.mp hv).2.1⟩)) (hL u) have hR' : ∀ v, (Finset.univ.filter (fun u ↦ E' u v)).card ≤ k := fun v ↦ le_trans (Finset.card_le_card (fun u hu ↦ Finset.mem_filter.mpr ⟨Finset.mem_univ u, (Finset.mem_filter.mp hu).2.1⟩)) (hR v) obtain ⟨col, hsupp, hpropL, hpropR⟩ := ih E' (by convert hcard') (by convert hL') (by convert hR') have hmissL : ∃ c₁ : Fin k, ∀ v, col u₀ v ≠ some c₁ := by have hlt : (Finset.univ.filter (fun v ↦ E' u₀ v)).card < k := by have hss : Finset.univ.filter (fun v ↦ E' u₀ v) = (Finset.univ.filter (fun v ↦ E u₀ v)).erase v₀ := by ext v; simp [E', and_comm] have hmem0 : v₀ ∈ Finset.univ.filter (fun v ↦ E u₀ v) := Finset.mem_filter.mpr ⟨Finset.mem_univ v₀, hE₀⟩ have hce := Finset.card_erase_of_mem hmem0 have hpos : 0 < (Finset.univ.filter (fun v ↦ E u₀ v)).card := Finset.card_pos.mpr ⟨v₀, hmem0⟩ have := hL u₀; rw [hss, hce]; omega let used : Finset (Fin k) := Finset.univ.filter (fun c ↦ ∃ v, col u₀ v = some c) have hused_le : used.card ≤ (Finset.univ.filter (fun v ↦ E' u₀ v)).card := by have hpick : ∀ c ∈ used, ∃ v ∈ Finset.univ.filter (fun v ↦ E' u₀ v), col u₀ v = some c := by intro c hc obtain ⟨v, hv⟩ := (Finset.mem_filter.mp hc).2 refine ⟨v, Finset.mem_filter.mpr ⟨Finset.mem_univ v, ?_⟩, hv⟩ exact (hsupp u₀ v).mp (by simp [hv]) choose f hfmem hfcol using hpick calc used.card = (used.attach.image (fun c ↦ f c.1 c.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ heq dsimp at heq have h1 := hfcol c₁ h₁ have h2 := hfcol c₂ h₂ rw [heq] at h1 exact Subtype.ext (Option.some.inj (h1.symm.trans h2)) _ ≤ (Finset.univ.filter (fun v ↦ E' u₀ v)).card := Finset.card_le_card (by intro v hv; rw [Finset.mem_image] at hv obtain ⟨c, _, rfl⟩ := hv; exact hfmem c.1 c.2) have hne : (Finset.univ \ used).Nonempty := by rw [← Finset.card_pos, Finset.card_sdiff_of_subset (Finset.subset_univ used)] simp only [Finset.card_univ, Fintype.card_fin]; omega obtain ⟨c₁, hc₁⟩ := hne rw [Finset.mem_sdiff, Finset.mem_filter] at hc₁ refine ⟨c₁, fun v hv ↦ hc₁.2 ⟨Finset.mem_univ c₁, v, hv⟩⟩ have hmissR : ∃ c₂ : Fin k, ∀ u, col u v₀ ≠ some c₂ := by have hlt : (Finset.univ.filter (fun u ↦ E' u v₀)).card < k := by have hss : Finset.univ.filter (fun u ↦ E' u v₀) = (Finset.univ.filter (fun u ↦ E u v₀)).erase u₀ := by ext u; simp [E', and_comm] have hmem0 : u₀ ∈ Finset.univ.filter (fun u ↦ E u v₀) := Finset.mem_filter.mpr ⟨Finset.mem_univ u₀, hE₀⟩ have hce := Finset.card_erase_of_mem hmem0 have hpos : 0 < (Finset.univ.filter (fun u ↦ E u v₀)).card := Finset.card_pos.mpr ⟨u₀, hmem0⟩ have := hR v₀; rw [hss, hce]; omega let used : Finset (Fin k) := Finset.univ.filter (fun c ↦ ∃ u, col u v₀ = some c) have hused_le : used.card ≤ (Finset.univ.filter (fun u ↦ E' u v₀)).card := by have hpick : ∀ c ∈ used, ∃ u ∈ Finset.univ.filter (fun u ↦ E' u v₀), col u v₀ = some c := by intro c hc obtain ⟨u, hu⟩ := (Finset.mem_filter.mp hc).2 refine ⟨u, Finset.mem_filter.mpr ⟨Finset.mem_univ u, ?_⟩, hu⟩ exact (hsupp u v₀).mp (by simp [hu]) choose f hfmem hfcol using hpick calc used.card = (used.attach.image (fun c ↦ f c.1 c.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ heq dsimp at heq have h1 := hfcol c₁ h₁ have h2 := hfcol c₂ h₂ rw [heq] at h1 exact Subtype.ext (Option.some.inj (h1.symm.trans h2)) _ ≤ (Finset.univ.filter (fun u ↦ E' u v₀)).card := Finset.card_le_card (by intro u hu; rw [Finset.mem_image] at hu obtain ⟨c, _, rfl⟩ := hu; exact hfmem c.1 c.2) have hne : (Finset.univ \ used).Nonempty := by rw [← Finset.card_pos, Finset.card_sdiff_of_subset (Finset.subset_univ used)] simp only [Finset.card_univ, Fintype.card_fin]; omega obtain ⟨c₂, hc₂⟩ := hne rw [Finset.mem_sdiff, Finset.mem_filter] at hc₂ refine ⟨c₂, fun u hu ↦ hc₂.2 ⟨Finset.mem_univ c₂, u, hu⟩⟩ obtain ⟨c₁, hc₁⟩ := hmissL obtain ⟨c₂, hc₂⟩ := hmissR let K : SimpleGraph (V ⊕ V) := { Adj := fun a b ↦ match a, b with | Sum.inl u, Sum.inr v => col u v = some c₁ ∨ col u v = some c₂ | Sum.inr v, Sum.inl u => col u v = some c₁ ∨ col u v = some c₂ | _, _ => False symm := ⟨fun a b h ↦ by cases a <;> cases b <;> exact h⟩ loopless := ⟨fun a h ↦ by cases a <;> exact h⟩ } have hnotreach : ¬K.Reachable (Sum.inr v₀) (Sum.inl u₀) := by rintro ⟨w⟩ have hp := w.toPath suffices hlen : ∀ n {b : V ⊕ V} (p : K.Walk (Sum.inr v₀) b), p.length = n → p.IsPath → match b with | Sum.inl u => ∃ v, col u v = some c₁ ∧ p.getVert (n - 1) = Sum.inr v | Sum.inr v => p.length = 0 ∨ ∃ u, col u v = some c₂ ∧ p.getVert (n - 1) = Sum.inl u by obtain ⟨v, hv, _⟩ := hlen hp.1.length hp.1 rfl hp.2 exact hc₁ v hv intro n induction n with | zero => intro b p hlen _ cases p with | nil => exact Or.inl rfl | cons _ _ => simp at hlen | succ n ihn => intro b p hlen hp have hrev_len : p.reverse.length = n + 1 := by simp [hlen] cases hrev : p.reverse with | nil => simp [hrev] at hrev_len | cons hlast q => rename_i prev have hp_eq : p = q.reverse.concat hlast.symm := by have := congrArg SimpleGraph.Walk.reverse hrev simp only [SimpleGraph.Walk.reverse_reverse, SimpleGraph.Walk.reverse_cons] at this exact this have hq_len : q.reverse.length = n := by have := congrArg SimpleGraph.Walk.length hp_eq simp only [SimpleGraph.Walk.length_concat] at this omega have hq_path : q.reverse.IsPath := by rw [hp_eq] at hp exact hp.of_append_left have hlast_ne : b ∉ q.reverse.support := by rw [hp_eq] at hp have hnd := hp.support_nodup rw [SimpleGraph.Walk.support_concat, List.nodup_append] at hnd intro hmem exact hnd.2.2 b hmem b (List.mem_singleton_self b) rfl have hget : p.getVert n = prev := by rw [hp_eq, SimpleGraph.Walk.concat_eq_append, SimpleGraph.Walk.getVert_append] rw [hq_len]; simp have hih := ihn q.reverse hq_len hq_path cases b with | inl u => cases prev with | inl u' => exact absurd hlast (by simp [K]) | inr v => dsimp [K] at hlast rcases hlast with h1 | h2 · exact ⟨v, h1, by simpa using hget⟩ · rcases hih with hlen0 | ⟨u', hu', hprev⟩ · have hvv0 : Sum.inr v₀ = Sum.inr v := SimpleGraph.Walk.eq_of_length_eq_zero hlen0 have hv0 : v = v₀ := (Sum.inr.inj hvv0).symm subst hv0 exact absurd h2 (hc₂ u) · have huu' : u = u' := hpropR u u' v c₂ h2 hu' subst huu' exfalso apply hlast_ne rw [← hprev] exact SimpleGraph.Walk.getVert_mem_support _ _ | inr v => cases prev with | inr v' => exact absurd hlast (by simp [K]) | inl u => dsimp [K] at hlast rcases hlast with h1 | h2 · obtain ⟨v', hv', hprev⟩ := hih have hvv' : v = v' := hpropL u v v' c₁ h1 hv' subst hvv' exfalso apply hlast_ne rw [← hprev] exact SimpleGraph.Walk.getVert_mem_support _ _ · exact Or.inr ⟨u, h2, by simpa using hget⟩ let swapCol : V → V → Option (Fin k) := fun u v ↦ if u = u₀ ∧ v = v₀ then some c₁ else if K.Reachable (Sum.inr v₀) (Sum.inl u) then swapOpt c₁ c₂ (col u v) else col u v have hreach_iff : ∀ u v, (col u v = some c₁ ∨ col u v = some c₂) → (K.Reachable (Sum.inr v₀) (Sum.inl u) ↔ K.Reachable (Sum.inr v₀) (Sum.inr v)) := by intro u v huv have hadj : K.Adj (Sum.inl u) (Sum.inr v) := huv exact ⟨fun h ↦ h.trans hadj.reachable, fun h ↦ h.trans hadj.symm.reachable⟩ refine ⟨swapCol, ?_, ?_, ?_⟩ · intro u v dsimp [swapCol] by_cases huv : u = u₀ ∧ v = v₀ · rcases huv with ⟨rfl, rfl⟩; simp [hE₀] · rw [if_neg huv] by_cases hr : K.Reachable (Sum.inr v₀) (Sum.inl u) · rw [if_pos hr, swapOpt_isSome, hsupp u v] exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, huv⟩⟩ · rw [if_neg hr, hsupp u v] exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, huv⟩⟩ · intro u v₁ v₂ c h1 h2 dsimp [swapCol] at h1 h2 by_cases heq1 : u = u₀ ∧ v₁ = v₀ <;> by_cases heq2 : u = u₀ ∧ v₂ = v₀ · exact heq1.2.trans heq2.2.symm · rcases heq1 with ⟨rfl, rfl⟩ rw [if_pos ⟨rfl, rfl⟩] at h1 have hc : c = c₁ := (Option.some.inj h1).symm; subst hc rw [if_neg heq2, if_neg hnotreach] at h2 exact absurd h2 (hc₁ v₂) · rcases heq2 with ⟨rfl, rfl⟩ rw [if_pos ⟨rfl, rfl⟩] at h2 have hc : c = c₁ := (Option.some.inj h2).symm; subst hc rw [if_neg heq1, if_neg hnotreach] at h1 exact absurd h1 (hc₁ v₁) · rw [if_neg heq1] at h1; rw [if_neg heq2] at h2 by_cases hru : K.Reachable (Sum.inr v₀) (Sum.inl u) · rw [if_pos hru] at h1 h2 rw [swapOpt_eq_some_iff] at h1 h2 cases hs : swapOpt c₁ c₂ (some c) with | none => exact absurd hs (swapOpt_some_ne_none c₁ c₂ c) | some c' => rw [hs] at h1 h2; exact hpropL u v₁ v₂ c' h1 h2 · rw [if_neg hru] at h1 h2 exact hpropL u v₁ v₂ c h1 h2 · intro u₁ u₂ v c h1 h2 dsimp [swapCol] at h1 h2 by_cases heq1 : u₁ = u₀ ∧ v = v₀ <;> by_cases heq2 : u₂ = u₀ ∧ v = v₀ · exact heq1.1.trans heq2.1.symm · rcases heq1 with ⟨rfl, rfl⟩ rw [if_pos ⟨rfl, rfl⟩] at h1 have hc : c = c₁ := (Option.some.inj h1).symm rw [hc] at h2 rw [if_neg heq2] at h2 by_cases hru : K.Reachable (Sum.inr v) (Sum.inl u₂) · rw [if_pos hru, swapOpt_eq_some_iff] at h2 have hso : swapOpt c₁ c₂ (some c₁) = some c₂ := by simp [swapOpt] rw [hso] at h2 exact absurd h2 (hc₂ u₂) · rw [if_neg hru] at h2 exact absurd ((hreach_iff u₂ v (Or.inl h2)).mpr (SimpleGraph.Reachable.refl _)) hru · rcases heq2 with ⟨rfl, rfl⟩ rw [if_pos ⟨rfl, rfl⟩] at h2 have hc : c = c₁ := (Option.some.inj h2).symm rw [hc] at h1 rw [if_neg heq1] at h1 by_cases hru : K.Reachable (Sum.inr v) (Sum.inl u₁) · rw [if_pos hru, swapOpt_eq_some_iff] at h1 have hso : swapOpt c₁ c₂ (some c₁) = some c₂ := by simp [swapOpt] rw [hso] at h1 exact absurd h1 (hc₂ u₁) · rw [if_neg hru] at h1 exact absurd ((hreach_iff u₁ v (Or.inl h1)).mpr (SimpleGraph.Reachable.refl _)) hru · rw [if_neg heq1] at h1; rw [if_neg heq2] at h2 -- Uniformly reduce both `h1, h2` using `K.Reachable (inr v₀) (inr v)`! have hred : ∀ u, (if K.Reachable (Sum.inr v₀) (Sum.inl u) then swapOpt c₁ c₂ (col u v) else col u v) = (if K.Reachable (Sum.inr v₀) (Sum.inr v) then swapOpt c₁ c₂ (col u v) else col u v) := by intro u by_cases h12 : col u v = some c₁ ∨ col u v = some c₂ · rw [hreach_iff u v h12] · push Not at h12 rw [swapOpt_eq_of_ne c₁ c₂ h12.1 h12.2] split_ifs <;> rfl rw [hred u₁] at h1; rw [hred u₂] at h2 by_cases hrv : K.Reachable (Sum.inr v₀) (Sum.inr v) · rw [if_pos hrv, swapOpt_eq_some_iff] at h1 h2 cases hs : swapOpt c₁ c₂ (some c) with | none => exact absurd hs (swapOpt_some_ne_none c₁ c₂ c) | some c' => rw [hs] at h1 h2; exact hpropR u₁ u₂ v c' h1 h2 · rw [if_neg hrv] at h1 h2 exact hpropR u₁ u₂ v c h1 h2 /-- **Engine 2 (Even–Even Decomposition):** For EVERY finite simple graph `H` and `p, q : ℕ`, if `Δ(H) ≤ 2p + 2q`, then `H` admits a `(2p, 2q)`-edge-decomposition (`HasDecomp H (2 * p) (2 * q)`). -/ theorem hasDecomp_even_even {V : Type*} [Fintype V] (H : SimpleGraph V) (p q : ℕ) (hdeg : ∀ v, H.degree v ≤ 2 * p + 2 * q) : HasDecomp H (2 * p) (2 * q) := by have hdeg' : ∀ v, H.degree v ≤ 2 * (p + q) := fun v ↦ by have := hdeg v; omega obtain ⟨dir, hdir_adj, hdir_anti, hdir_out, hdir_in⟩ := exists_half_orientation H (p + q) hdeg' obtain ⟨col, hsupp, hpropL, hpropR⟩ := konig_bipartite_edge_coloring (p + q) dir hdir_out hdir_in let isRedDir : V → V → Prop := fun u v ↦ ∃ c : Fin (p + q), col u v = some c ∧ c.val < p let R : SimpleGraph V := { Adj := fun u v ↦ isRedDir u v ∨ isRedDir v u symm := ⟨fun _ _ h ↦ h.symm⟩ loopless := ⟨fun v h ↦ by rcases h with ⟨c, hc, _⟩ | ⟨c, hc, _⟩ · have hd : dir v v := (hsupp v v).mp (by simp [hc]) exact H.loopless.irrefl v ((hdir_adj v v).mpr (Or.inl hd)) · have hd : dir v v := (hsupp v v).mp (by simp [hc]) exact H.loopless.irrefl v ((hdir_adj v v).mpr (Or.inl hd))⟩ } have hRle : R ≤ H := by intro u v h rcases h with ⟨c, hc, _⟩ | ⟨c, hc, _⟩ · exact (hdir_adj u v).mpr (Or.inl ((hsupp u v).mp (by simp [hc]))) · exact (hdir_adj u v).mpr (Or.inr ((hsupp v u).mp (by simp [hc]))) refine ⟨R, hRle, ?_, ?_⟩ · intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] have hle_union : (R.neighborFinset v).card ≤ (Finset.univ.filter (fun w ↦ isRedDir v w) ∪ Finset.univ.filter (fun w ↦ isRedDir w v)).card := by refine Finset.card_le_card (fun w hw ↦ ?_) rw [SimpleGraph.mem_neighborFinset] at hw rw [Finset.mem_union, Finset.mem_filter, Finset.mem_filter] rcases hw with h1 | h2 · exact Or.inl ⟨Finset.mem_univ w, h1⟩ · exact Or.inr ⟨Finset.mem_univ w, h2⟩ have hout : (Finset.univ.filter (fun w ↦ isRedDir v w)).card ≤ p := by let S := Finset.univ.filter (fun w ↦ isRedDir v w) have hpick : ∀ w ∈ S, ∃ c : Fin p, col v w = some ⟨c.val, by omega⟩ := by intro w hw obtain ⟨c, hc, hlt⟩ := (Finset.mem_filter.mp hw).2 exact ⟨⟨c.val, hlt⟩, by simpa using hc⟩ choose f hf using hpick calc S.card = (S.attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ hEq dsimp at hEq have h1 := hf w₁ hw₁; have h2 := hf w₂ hw₂ rw [hEq] at h1 exact Subtype.ext (hpropL v w₁ w₂ _ h1 h2) _ ≤ (Finset.univ : Finset (Fin p)).card := Finset.card_le_univ _ _ = p := by simp have hin : (Finset.univ.filter (fun w ↦ isRedDir w v)).card ≤ p := by let S := Finset.univ.filter (fun w ↦ isRedDir w v) have hpick : ∀ w ∈ S, ∃ c : Fin p, col w v = some ⟨c.val, by omega⟩ := by intro w hw obtain ⟨c, hc, hlt⟩ := (Finset.mem_filter.mp hw).2 exact ⟨⟨c.val, hlt⟩, by simpa using hc⟩ choose f hf using hpick calc S.card = (S.attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ hEq dsimp at hEq have h1 := hf w₁ hw₁; have h2 := hf w₂ hw₂ rw [hEq] at h1 exact Subtype.ext (hpropR w₁ w₂ v _ h1 h2) _ ≤ (Finset.univ : Finset (Fin p)).card := Finset.card_le_univ _ _ = p := by simp have hunion := Finset.card_union_le (Finset.univ.filter (fun w ↦ isRedDir v w)) (Finset.univ.filter (fun w ↦ isRedDir w v)) have hfinal : (R.neighborFinset v).card ≤ 2 * p := by omega convert hfinal · intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] let isBlueDir : V → V → Prop := fun u w ↦ ∃ c : Fin (p + q), col u w = some c ∧ p ≤ c.val have hle_union : ((H \ R).neighborFinset v).card ≤ (Finset.univ.filter (fun w ↦ isBlueDir v w) ∪ Finset.univ.filter (fun w ↦ isBlueDir w v)).card := by refine Finset.card_le_card (fun w hw ↦ ?_) rw [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] at hw rcases hw with ⟨hH, hnotR⟩ rw [Finset.mem_union, Finset.mem_filter, Finset.mem_filter] rcases (hdir_adj v w).mp hH with hvw | hwv · obtain ⟨c, hc⟩ := Option.isSome_iff_exists.mp ((hsupp v w).mpr hvw) refine Or.inl ⟨Finset.mem_univ w, c, hc, ?_⟩ by_contra hlt; push Not at hlt exact hnotR (Or.inl ⟨c, hc, hlt⟩) · obtain ⟨c, hc⟩ := Option.isSome_iff_exists.mp ((hsupp w v).mpr hwv) refine Or.inr ⟨Finset.mem_univ w, c, hc, ?_⟩ by_contra hlt; push Not at hlt exact hnotR (Or.inr ⟨c, hc, hlt⟩) have hout : (Finset.univ.filter (fun w ↦ isBlueDir v w)).card ≤ q := by let S := Finset.univ.filter (fun w ↦ isBlueDir v w) have hpick : ∀ w ∈ S, ∃ c : Fin q, col v w = some ⟨p + c.val, by omega⟩ := by intro w hw obtain ⟨c, hc, hge⟩ := (Finset.mem_filter.mp hw).2 refine ⟨⟨c.val - p, by omega⟩, ?_⟩ have hfin : (⟨p + (c.val - p), by omega⟩ : Fin (p + q)) = c := Fin.ext (by dsimp; omega) rw [hfin]; exact hc choose f hf using hpick calc S.card = (S.attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ hEq dsimp at hEq have h1 := hf w₁ hw₁; have h2 := hf w₂ hw₂ rw [hEq] at h1 exact Subtype.ext (hpropL v w₁ w₂ _ h1 h2) _ ≤ (Finset.univ : Finset (Fin q)).card := Finset.card_le_univ _ _ = q := by simp have hin : (Finset.univ.filter (fun w ↦ isBlueDir w v)).card ≤ q := by let S := Finset.univ.filter (fun w ↦ isBlueDir w v) have hpick : ∀ w ∈ S, ∃ c : Fin q, col w v = some ⟨p + c.val, by omega⟩ := by intro w hw obtain ⟨c, hc, hge⟩ := (Finset.mem_filter.mp hw).2 refine ⟨⟨c.val - p, by omega⟩, ?_⟩ have hfin : (⟨p + (c.val - p), by omega⟩ : Fin (p + q)) = c := Fin.ext (by dsimp; omega) rw [hfin]; exact hc choose f hf using hpick calc S.card = (S.attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ hEq dsimp at hEq have h1 := hf w₁ hw₁; have h2 := hf w₂ hw₂ rw [hEq] at h1 exact Subtype.ext (hpropR w₁ w₂ v _ h1 h2) _ ≤ (Finset.univ : Finset (Fin q)).card := Finset.card_le_univ _ _ = q := by simp have hunion := Finset.card_union_le (Finset.univ.filter (fun w ↦ isBlueDir v w)) (Finset.univ.filter (fun w ↦ isBlueDir w v)) have hfinal : ((H \ R).neighborFinset v).card ≤ 2 * q := by omega convert hfinal /-! ### Engine 3: Exact Diagonal Eulerian Decomposition (`HasDecomp H m m` for `e(H) < m(2m+1)`) -/ /-- Append two edge-disjoint arc trails `L₁, L₂` when the end of `L₁` matches the start of `L₂`. -/ lemma isArcTrail_append {V : Type*} {G : SimpleGraph V} {L₁ L₂ : List (V × V)} (h₁ : IsArcTrail G L₁) (h₂ : IsArcTrail G L₂) (hlink : ∀ p q, L₁.getLast? = some p → L₂.head? = some q → p.2 = q.1) (hdisj : ∀ p ∈ L₁, ∀ q ∈ L₂, s(p.1, p.2) ≠ s(q.1, q.2)) : IsArcTrail G (L₁ ++ L₂) := by induction L₁ with | nil => simpa using h₂ | cons a rest ih => rcases a with ⟨x, y⟩ rcases h₁ with ⟨hxy, hch, hne, hrest⟩ refine ⟨hxy, ?_, ?_, ?_⟩ · intro p hp cases rest with | nil => exact hlink (x, y) p rfl (by simpa using hp) | cons b tail => exact hch p (by simpa using hp) · intro p hp rcases List.mem_append.mp hp with hp | hp · exact hne p hp · exact hdisj (x, y) (List.mem_cons_self ..) p hp · refine ih hrest ?_ (fun p hp q hq ↦ hdisj p (List.mem_cons_of_mem _ hp) q hq) intro p q hlast hhd apply hlink p q _ hhd cases rest with | nil => simp at hlast | cons b tail => simpa using hlast /-- Hierholzer's Eulerian Circuit Theorem on a connected component: If every vertex of `G` has even degree, then for any base vertex `v₀` there exists a closed arc trail `L` starting and ending at `v₀` that covers every edge of `G` reachable from `v₀`. -/ lemma exists_eulerian_circuit_component {V : Type*} [Fintype V] (G : SimpleGraph V) (heven : ∀ v, Even (G.degree v)) (v₀ : V) : ∃ L : List (V × V), IsArcTrail G L ∧ (∀ p, L.head? = some p → p.1 = v₀) ∧ (∀ p, L.getLast? = some p → p.2 = v₀) ∧ (∀ x y, G.Adj x y → G.Reachable v₀ x → s(x, y) ∈ arcEdges L) := by suffices h : ∀ k (L : List (V × V)), G.edgeFinset.card - L.length ≤ k → IsArcTrail G L → (∀ p, L.head? = some p → p.1 = v₀) → (∀ p, L.getLast? = some p → p.2 = v₀) → ∃ L' : List (V × V), IsArcTrail G L' ∧ (∀ p, L'.head? = some p → p.1 = v₀) ∧ (∀ p, L'.getLast? = some p → p.2 = v₀) ∧ (∀ x y, G.Adj x y → G.Reachable v₀ x → s(x, y) ∈ arcEdges L') by exact h G.edgeFinset.card [] (Nat.sub_le _ _) trivial (by simp) (by simp) intro k induction k with | zero => intro L hk htr hhd hlast refine ⟨L, htr, hhd, hlast, ?_⟩ intro x y hxy _ by_contra hnot have hmem : s(x, y) ∈ (deleteArcs G L).edgeFinset := SimpleGraph.mem_edgeFinset.mpr ⟨hxy, hnot⟩ have hed := deleteArcs_edgeFinset_card htr have hpos : 0 < (deleteArcs G L).edgeFinset.card := Finset.card_pos.mpr ⟨_, hmem⟩ omega | succ k ih => intro L hk htr hhd hlast by_cases hcov : ∀ x y, G.Adj x y → G.Reachable v₀ x → s(x, y) ∈ arcEdges L · exact ⟨L, htr, hhd, hlast, hcov⟩ · push Not at hcov obtain ⟨x, y, hxy, hreach, hnotmem⟩ := hcov let G' := deleteArcs G L have hG'_even : ∀ v, Even (G'.degree v) := by intro v by_cases hLnil : L = [] · subst hLnil have heq : G'.degree v = G.degree v := by simp only [← SimpleGraph.card_neighborFinset_eq_degree] congr 1; ext w simp only [SimpleGraph.mem_neighborFinset] simp [G', deleteArcs, arcEdges] rw [heq]; exact heven v · have hbal := arcOutDeg_inDeg_eq L htr v₀ v₀ hhd hlast hLnil v have hdeg : G'.degree v + (arcOutDeg L v + arcInDeg L v) = G.degree v := deleteArcs_degree htr v rcases heven v with ⟨r, hr⟩ refine ⟨r - arcOutDeg L v, ?_⟩; omega let onL : V → Prop := fun u ↦ u = v₀ ∨ ∃ w, (u, w) ∈ L have honL_edge : ∀ a b, s(a, b) ∈ arcEdges L → onL a ∧ onL b := by intro a b hab rw [arcEdges, List.mem_map] at hab obtain ⟨⟨p1, p2⟩, hpL, hsym⟩ := hab have hLne : L ≠ [] := List.ne_nil_of_mem hpL have hboth : ∀ z, (∃ w, (z, w) ∈ L) ∨ (∃ w, (w, z) ∈ L) → onL z := by intro z hz rcases hz with ⟨w, hw⟩ | ⟨w, hw⟩ · exact Or.inr ⟨w, hw⟩ · have hin_pos : 0 < arcInDeg L z := by unfold arcInDeg exact List.length_pos_iff.mpr (List.ne_nil_of_mem (List.mem_filter.mpr ⟨hw, by simp⟩)) have hbal := arcOutDeg_inDeg_eq L htr v₀ v₀ hhd hlast hLne z have hout_pos : 0 < arcOutDeg L z := by omega unfold arcOutDeg at hout_pos obtain ⟨⟨q1, q2⟩, hq⟩ := List.exists_mem_of_ne_nil _ (List.length_pos_iff.mp hout_pos) rw [List.mem_filter] at hq have hq1 : q1 = z := of_decide_eq_true hq.2 exact Or.inr ⟨q2, hq1 ▸ hq.1⟩ rw [Sym2.eq_iff] at hsym rcases hsym with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact ⟨hboth _ (Or.inl ⟨_, hpL⟩), hboth _ (Or.inr ⟨_, hpL⟩)⟩ · exact ⟨hboth _ (Or.inr ⟨_, hpL⟩), hboth _ (Or.inl ⟨_, hpL⟩)⟩ have hex_u : ∃ u, onL u ∧ 0 < G'.degree u := by obtain ⟨w⟩ := hreach suffices hwalk : ∀ {a b : V} (p : G.Walk a b), onL a → (∃ z, G'.Adj b z) → ∃ u, onL u ∧ 0 < G'.degree u by exact hwalk w (Or.inl rfl) ⟨y, hxy, hnotmem⟩ intro a b p induction p with | nil => rename_i a₀ intro ha ⟨z, hz⟩ refine ⟨a₀, ha, ?_⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨z, (SimpleGraph.mem_neighborFinset _ _ _).mpr hz⟩ | cons hab rest ihw => rename_i a' b' c' intro ha hbz by_cases heL : s(a', b') ∈ arcEdges L · exact ihw (honL_edge a' b' heL).2 hbz · refine ⟨a', ha, ?_⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨b', (SimpleGraph.mem_neighborFinset _ _ _).mpr ⟨hab, heL⟩⟩ obtain ⟨u, hu_on, hu_pos⟩ := hex_u obtain ⟨C, hCne, hCtr_G', hChd, hClast⟩ := exists_nonempty_closed_trail G' hG'_even u hu_pos have hCtr : IsArcTrail G C := by clear ih hk htr hhd hlast hG'_even hu_on hu_pos hChd hClast hCne x y hxy hreach hnotmem induction C with | nil => trivial | cons p rest ihc => rcases p with ⟨a, b⟩ rcases hCtr_G' with ⟨h1, h2, h3, h4⟩ exact ⟨h1.1, h2, h3, ihc h4⟩ have hdisj_LC : ∀ p ∈ L, ∀ q ∈ C, s(p.1, p.2) ≠ s(q.1, q.2) := by intro p hp q hq heq have hqG' : G'.Adj q.1 q.2 := isArcTrail_subset_edges hCtr_G' s(q.1, q.2) (List.mem_map.mpr ⟨q, hq, rfl⟩) exact hqG'.2 (by rw [← heq]; exact List.mem_map.mpr ⟨p, hp, rfl⟩) by_cases hLnil : L = [] · subst hLnil have hu0 : u = v₀ := by rcases hu_on with rfl | ⟨w, hw⟩; rfl; simp at hw subst hu0 have hlenC : 0 < C.length := List.length_pos_iff.mpr hCne have hleC := isArcTrail_length_le hCtr exact ih C (by simp at hk ⊢; omega) hCtr hChd hClast · by_cases huv0 : u = v₀ · subst huv0 let L' := C ++ L have htr' : IsArcTrail G L' := isArcTrail_append hCtr htr (fun p q hp hq ↦ (hClast p hp).trans (hhd q hq).symm) (fun q hq p hp ↦ (hdisj_LC p hp q hq).symm) have hhd' : ∀ p, L'.head? = some p → p.1 = u := by intro p hp cases C with | nil => exact absurd rfl hCne | cons a rest => exact hChd p (by simpa [L'] using hp) have hlast' : ∀ p, L'.getLast? = some p → p.2 = u := by intro p hp apply hlast p rwa [List.getLast?_append_of_ne_nil _ hLnil] at hp have hlenC : 0 < C.length := List.length_pos_iff.mpr hCne have hlen' : L'.length = C.length + L.length := List.length_append exact ih L' (by omega) htr' hhd' hlast' · rcases hu_on with h0 | ⟨w, hwL⟩ · exact absurd h0 huv0 · obtain ⟨L₁, L₂, hLsplit⟩ := List.append_of_mem hwL let L' := L₁ ++ C ++ ((u, w) :: L₂) have htr_parts : IsArcTrail G L₁ ∧ IsArcTrail G ((u, w) :: L₂) ∧ (∀ p q, L₁.getLast? = some p → ((u, w) :: L₂).head? = some q → p.2 = q.1) ∧ (∀ p ∈ L₁, ∀ q ∈ (u, w) :: L₂, s(p.1, p.2) ≠ s(q.1, q.2)) := by rw [hLsplit] at htr clear ih hk hhd hlast hLsplit hLnil hG'_even hCne hCtr_G' hCtr hChd hClast hdisj_LC x y hxy hreach hnotmem huv0 hwL induction L₁ with | nil => exact ⟨trivial, htr, by simp, by simp⟩ | cons a rest ihs => rcases a with ⟨a1, a2⟩ rcases htr with ⟨ha, hch, hne, hrest⟩ obtain ⟨hr1, hr2, hlink, hdj⟩ := ihs hrest refine ⟨⟨ha, ?_, ?_, hr1⟩, hr2, ?_, ?_⟩ · intro p hp exact hch p (by cases rest <;> simp at hp ⊢; exact hp) · intro p hp exact hne p (List.mem_append_left _ hp) · intro p q hlp hq cases rest with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hlp subst hlp exact hch q (by simpa using hq) | cons b tail => exact hlink p q (by simpa using hlp) hq · intro p hp q hq rcases List.mem_cons.mp hp with rfl | hp · exact hne q (List.mem_append_right _ hq) · exact hdj p hp q hq obtain ⟨htr1, htr2, hlink12, hdisj12⟩ := htr_parts have htr1C : IsArcTrail G (L₁ ++ C) := isArcTrail_append htr1 hCtr (fun p q hp hq ↦ (hlink12 p (u, w) hp rfl).trans (hChd q hq).symm) (fun p hp q hq ↦ hdisj_LC p (by rw [hLsplit]; exact List.mem_append_left _ hp) q hq) have htr' : IsArcTrail G L' := isArcTrail_append htr1C htr2 (fun p q hp hq ↦ by rw [List.getLast?_append_of_ne_nil _ hCne] at hp simp only [List.head?_cons, Option.some.injEq] at hq rw [← hq]; exact hClast p hp) (fun p hp q hq ↦ by rcases List.mem_append.mp hp with hp | hp · exact hdisj12 p hp q hq · exact (hdisj_LC q (by rw [hLsplit]; exact List.mem_append_right _ hq) p hp).symm) have hhd' : ∀ p, L'.head? = some p → p.1 = v₀ := by intro p hp cases L₁ with | nil => simp only [List.nil_append] at hLsplit have hhd_uw : (u, w).1 = v₀ := hhd (u, w) (by rw [hLsplit]; rfl) exact absurd hhd_uw huv0 | cons a rest => apply hhd p rw [hLsplit] simpa [L'] using hp have hlast' : ∀ p, L'.getLast? = some p → p.2 = v₀ := by intro p hp apply hlast p rw [hLsplit, List.getLast?_append_of_ne_nil _ (List.cons_ne_nil _ _)] dsimp [L'] at hp rwa [List.getLast?_append_of_ne_nil _ (List.cons_ne_nil _ _)] at hp have hlenC : 0 < C.length := List.length_pos_iff.mpr hCne have hlenL : L.length = L₁.length + ((u, w) :: L₂).length := by rw [hLsplit, List.length_append] have hlen' : L'.length = L.length + C.length := by dsimp [L']; rw [List.length_append, List.length_append, hlenL]; omega exact ih L' (by omega) htr' hhd' hlast' /-- Split a list of directed arcs into alternating parity sublists. -/ def splitAlt {V : Type*} : Bool → List (V × V) → List (V × V) × List (V × V) | _, [] => ([], []) | true, p :: rest => let rb := splitAlt false rest; (p :: rb.1, rb.2) | false, p :: rest => let rb := splitAlt true rest; (rb.1, p :: rb.2) /-- Count of arcs in a list incident to `v`. -/ noncomputable def arcIncDeg {V : Type*} (L : List (V × V)) (v : V) : ℕ := arcOutDeg L v + arcInDeg L v lemma splitAlt_mem_iff {V : Type*} (b : Bool) (L : List (V × V)) (p : V × V) : p ∈ L ↔ p ∈ (splitAlt b L).1 ∨ p ∈ (splitAlt b L).2 := by induction L generalizing b with | nil => simp [splitAlt] | cons a rest ih => cases b with | true => have h := ih false simp only [splitAlt, List.mem_cons] tauto | false => have h := ih true simp only [splitAlt, List.mem_cons] tauto lemma splitAlt_nodup {V : Type*} (b : Bool) (L : List (V × V)) (hnd : L.Nodup) : (splitAlt b L).1.Nodup ∧ (splitAlt b L).2.Nodup := by induction L generalizing b with | nil => simp [splitAlt] | cons a rest ih => rw [List.nodup_cons] at hnd obtain ⟨h1, h2⟩ := ih (!b) hnd.2 cases b with | true => exact ⟨List.nodup_cons.mpr ⟨fun hm ↦ hnd.1 ((splitAlt_mem_iff false rest a).mpr (Or.inl hm)), h1⟩, h2⟩ | false => exact ⟨h1, List.nodup_cons.mpr ⟨fun hm ↦ hnd.1 ((splitAlt_mem_iff true rest a).mpr (Or.inr hm)), h2⟩⟩ lemma splitAlt_disjoint_edges {V : Type*} {G : SimpleGraph V} {L : List (V × V)} (h : IsArcTrail G L) (b : Bool) : ∀ p ∈ (splitAlt b L).1, ∀ q ∈ (splitAlt b L).2, s(p.1, p.2) ≠ s(q.1, q.2) := by induction L generalizing b with | nil => simp [splitAlt] | cons a rest ih => rcases a with ⟨x, y⟩ rcases h with ⟨_, _, hne, hrest⟩ cases b with | true => intro p hp q hq simp only [splitAlt, List.mem_cons] at hp rcases hp with rfl | hp · exact hne q ((splitAlt_mem_iff false rest q).mpr (Or.inr hq)) · exact ih hrest false p hp q hq | false => intro p hp q hq simp only [splitAlt, List.mem_cons] at hq rcases hq with rfl | hq · exact (hne p ((splitAlt_mem_iff true rest p).mpr (Or.inl hp))).symm · exact ih hrest true p hp q hq lemma splitAlt_arcIncDeg_add {V : Type*} (b : Bool) (L : List (V × V)) (v : V) : arcIncDeg (splitAlt b L).1 v + arcIncDeg (splitAlt b L).2 v = arcIncDeg L v := by induction L generalizing b with | nil => simp [splitAlt, arcIncDeg, arcOutDeg, arcInDeg] | cons a rest ih => cases b with | true => have := ih false simp only [splitAlt, arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons] at this ⊢ by_cases h1 : a.1 = v <;> by_cases h2 : a.2 = v <;> simp [h1, h2] at this ⊢ <;> omega | false => have := ih true simp only [splitAlt, arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons] at this ⊢ by_cases h1 : a.1 = v <;> by_cases h2 : a.2 = v <;> simp [h1, h2] at this ⊢ <;> omega lemma splitAlt_balance {V : Type*} {G : SimpleGraph V} : ∀ (L : List (V × V)) (b : Bool), IsArcTrail G L → ∀ (s t : V), (∀ p, L.head? = some p → p.1 = s) → (∀ p, L.getLast? = some p → p.2 = t) → L ≠ [] → ∀ v : V, (arcIncDeg (splitAlt b L).1 v : ℤ) - (arcIncDeg (splitAlt b L).2 v : ℤ) = (if b then (1 : ℤ) else -1) * (if v = s then 1 else 0) + (if (b ^^ (L.length % 2 = 0)) then (1 : ℤ) else -1) * (if v = t then 1 else 0) := by intro L induction L with | nil => intro _ _ _ _ _ _ hne; exact absurd rfl hne | cons a rest ih => rcases a with ⟨x, y⟩ intro b htr s t hhd hlast _ v have hxs : x = s := hhd (x, y) rfl subst hxs rcases htr with ⟨_, hch, _, hrest⟩ cases rest with | nil => have hyt : y = t := hlast (x, y) rfl subst hyt cases b <;> · simp only [splitAlt, arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons, List.filter_nil, List.length_nil, List.length_cons] by_cases hx : v = x <;> by_cases hy : v = y · subst hx; subst hy; simp · subst hx; simp [hy, Ne.symm hy] · subst hy; simp [hx, Ne.symm hx] · simp [hx, hy, Ne.symm hx, Ne.symm hy] | cons q tail => have hyq : y = q.1 := hch q rfl have hih := ih (!b) hrest y t (fun r hr ↦ by simp at hr; subst hr; exact hyq.symm) (fun r hr ↦ hlast r (by simpa using hr)) (List.cons_ne_nil _ _) v have hpar : (b ^^ (((x, y) :: q :: tail).length % 2 = 0)) = ((!b) ^^ ((q :: tail).length % 2 = 0)) := by simp only [List.length_cons] cases b <;> · by_cases h0 : (tail.length + 1) % 2 = 0 · have h1 : ¬(tail.length + 1 + 1) % 2 = 0 := by omega simp [h0, h1] · have h1 : (tail.length + 1 + 1) % 2 = 0 := by omega simp [h0, h1] rw [hpar] cases b with | true => simp only [Bool.not_true, Bool.false_eq_true, ↓reduceIte] at hih simp only [splitAlt, arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons, ↓reduceIte] at hih ⊢ by_cases hx : v = x <;> by_cases hy : v = y · subst hx; subst hy; simp at hih ⊢; omega · subst hx; simp [hy, Ne.symm hy] at hih ⊢; omega · subst hy; simp [hx, Ne.symm hx] at hih ⊢; omega · simp [hx, hy, Ne.symm hx, Ne.symm hy] at hih ⊢; omega | false => simp only [Bool.not_false, ↓reduceIte] at hih simp only [splitAlt, arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons, Bool.false_eq_true, ↓reduceIte] at hih ⊢ by_cases hx : v = x <;> by_cases hy : v = y · subst hx; subst hy; simp at hih ⊢; omega · subst hx; simp [hy, Ne.symm hy] at hih ⊢; omega · subst hy; simp [hx, Ne.symm hx] at hih ⊢; omega · simp [hx, hy, Ne.symm hx, Ne.symm hy] at hih ⊢; omega /-- Subgraph formed by the edges of an arc sublist `S`. -/ def arcListGraph {V : Type*} {G : SimpleGraph V} {L : List (V × V)} (htr : IsArcTrail G L) (S : List (V × V)) (hsub : ∀ p ∈ S, p ∈ L) : SimpleGraph V where Adj u v := s(u, v) ∈ arcEdges S symm := ⟨fun _ _ h ↦ by rwa [Sym2.eq_swap]⟩ loopless := ⟨fun v h ↦ by rw [arcEdges, List.mem_map] at h obtain ⟨p, hpS, heq⟩ := h have hadj : G.Adj p.1 p.2 := isArcTrail_subset_edges htr s(p.1, p.2) (List.mem_map.mpr ⟨p, hsub p hpS, rfl⟩) rw [Sym2.eq_iff] at heq rcases heq with ⟨h1, h2⟩ | ⟨h1, h2⟩ · exact hadj.ne (h1.trans h2.symm) · exact hadj.ne (h1.trans h2.symm)⟩ lemma arcListGraph_le {V : Type*} {G : SimpleGraph V} {L : List (V × V)} (htr : IsArcTrail G L) (S : List (V × V)) (hsub : ∀ p ∈ S, p ∈ L) : arcListGraph htr S hsub ≤ G := by intro u v huv rw [arcListGraph] at huv change s(u, v) ∈ arcEdges S at huv rw [arcEdges, List.mem_map] at huv obtain ⟨p, hpS, heq⟩ := huv have hadj : G.Adj p.1 p.2 := isArcTrail_subset_edges htr s(p.1, p.2) (List.mem_map.mpr ⟨p, hsub p hpS, rfl⟩) rw [Sym2.eq_iff] at heq rcases heq with ⟨h1, h2⟩ | ⟨h1, h2⟩ · rw [← h1, ← h2]; exact hadj · rw [← h1, ← h2]; exact hadj.symm lemma arcListGraph_degree {V : Type*} [Fintype V] {G : SimpleGraph V} {L : List (V × V)} (htr : IsArcTrail G L) (S : List (V × V)) (hsub : ∀ p ∈ S, p ∈ L) (hSnd : S.Nodup) (v : V) : (arcListGraph htr S hsub).degree v = arcIncDeg S v := by have hS_edges_nodup : (arcEdges S).Nodup := by have hinj : ∀ p ∈ S, ∀ q ∈ S, s(p.1, p.2) = s(q.1, q.2) → p = q := by intro p hp q hq heq have hpL := hsub p hp; have hqL := hsub q hq clear hp hq hsub hSnd induction L with | nil => exact absurd hpL List.not_mem_nil | cons a rest ihl => rcases a with ⟨a1, a2⟩ rcases htr with ⟨_, _, hne, hrest⟩ simp only [List.mem_cons] at hpL hqL rcases hpL with rfl | hpL <;> rcases hqL with rfl | hqL · rfl · exact absurd heq (hne q hqL) · exact absurd heq.symm (hne p hpL) · exact ihl hrest hpL hqL unfold arcEdges exact hSnd.map_on hinj have hcard_inc : ((arcEdges S).toFinset.filter (fun e ↦ v ∈ e)).card = arcIncDeg S v := by have hno_loop : ∀ p ∈ S, p.1 ≠ p.2 := by intro p hpS exact (isArcTrail_subset_edges htr s(p.1, p.2) (List.mem_map.mpr ⟨p, hsub p hpS, rfl⟩)).ne clear hsub htr induction S with | nil => simp [arcEdges, arcIncDeg, arcOutDeg, arcInDeg] | cons a rest ihs => rcases a with ⟨x, y⟩ simp only [List.nodup_cons] at hSnd simp only [arcEdges, List.map_cons, List.nodup_cons] at hS_edges_nodup have hxy : x ≠ y := hno_loop (x, y) (List.mem_cons_self ..) have hih := ihs hSnd.2 hS_edges_nodup.2 (fun p hp ↦ hno_loop p (List.mem_cons_of_mem _ hp)) have hcons : (arcEdges ((x, y) :: rest)).toFinset = insert s(x, y) (arcEdges rest).toFinset := by simp [arcEdges] have hnotmem : s(x, y) ∉ (arcEdges rest).toFinset := by rw [List.mem_toFinset]; exact hS_edges_nodup.1 rw [hcons] simp only [arcIncDeg, arcOutDeg, arcInDeg, List.filter_cons] at hih ⊢ by_cases hv : v ∈ s(x, y) · rw [Finset.filter_insert, if_pos hv, Finset.card_insert_of_notMem (fun hm ↦ hnotmem (Finset.mem_filter.mp hm).1), hih] rw [Sym2.mem_iff] at hv rcases hv with rfl | rfl · have hne' : y ≠ v := hxy.symm simp [hne', eq_comm]; omega · have hne' : x ≠ v := hxy simp [hne', eq_comm]; omega · rw [Finset.filter_insert, if_neg hv, hih] rw [Sym2.mem_iff] at hv push Not at hv have h1 : x ≠ v := hv.1.symm; have h2 : y ≠ v := hv.2.symm simp [h1, h2] rw [← SimpleGraph.card_neighborFinset_eq_degree, ← hcard_inc] refine Finset.card_bij (fun w _ ↦ s(v, w)) (fun w hw ↦ by rw [SimpleGraph.mem_neighborFinset] at hw exact Finset.mem_filter.mpr ⟨List.mem_toFinset.mpr hw, Sym2.mem_mk_left v w⟩) (fun w₁ _ w₂ _ hEq ↦ by rw [Sym2.eq_iff] at hEq rcases hEq with ⟨_, h⟩ | ⟨h1, h2⟩ · exact h · exact h2.trans h1) (fun e he ↦ by rw [Finset.mem_filter, List.mem_toFinset] at he rcases he with ⟨heS, hve⟩ induction e using Sym2.ind with | _ x y => rw [Sym2.mem_iff] at hve rcases hve with rfl | rfl · exact ⟨y, (SimpleGraph.mem_neighborFinset _ _ _).mpr heS, rfl⟩ · refine ⟨x, (SimpleGraph.mem_neighborFinset _ _ _).mpr ?_, Sym2.eq_swap⟩ change s(v, x) ∈ arcEdges S rwa [Sym2.eq_swap]) /-- Helper 3A: Diagonal `(m, m)`-decomposition of a single even-degree component with `< m(2m+1)` edges. -/ lemma hasDecomp_diag_even_component {V : Type*} [Fintype V] (HC : SimpleGraph V) (m : ℕ) (x₀ : V) (hpos : 0 < HC.edgeFinset.card) (hconn : ∀ a b, HC.Adj a b → HC.Reachable x₀ a) (heven : ∀ v, Even (HC.degree v)) (hdeg : ∀ v, HC.degree v ≤ 2 * m) (hedge : HC.edgeFinset.card < m * (2 * m + 1)) : HasDecomp HC m m := by have hstart_v0 : ∃ v₀, HC.Reachable x₀ v₀ ∧ (Odd HC.edgeFinset.card → HC.degree v₀ + 2 ≤ 2 * m) := by by_cases hodd_e : Odd HC.edgeFinset.card · by_contra hall_reg push Not at hall_reg have hreg : ∀ v, HC.Reachable x₀ v → HC.degree v = 2 * m := by intro v hr have hlt : 2 * m < HC.degree v + 2 := (hall_reg v hr).2 have hle := hdeg v rcases heven v with ⟨r, hr2⟩ omega let comp : Finset V := Finset.univ.filter (fun v ↦ HC.Reachable x₀ v) have hcomp_card : 2 * m + 1 ≤ comp.card := by have hsub : insert x₀ (HC.neighborFinset x₀) ⊆ comp := by intro v hv rw [Finset.mem_insert, SimpleGraph.mem_neighborFinset] at hv rw [Finset.mem_filter] refine ⟨Finset.mem_univ v, ?_⟩ rcases hv with rfl | hadj · exact SimpleGraph.Reachable.refl _ · exact hadj.reachable have hnot : x₀ ∉ HC.neighborFinset x₀ := by rw [SimpleGraph.mem_neighborFinset]; exact HC.loopless.irrefl x₀ calc 2 * m + 1 = HC.degree x₀ + 1 := by rw [hreg x₀ (SimpleGraph.Reachable.refl _)] _ = (HC.neighborFinset x₀).card + 1 := by rw [SimpleGraph.card_neighborFinset_eq_degree] _ = (insert x₀ (HC.neighborFinset x₀)).card := (Finset.card_insert_of_notMem hnot).symm _ ≤ comp.card := Finset.card_le_card hsub have hsum := HC.sum_degrees_eq_twice_card_edges have hsum_comp : ∑ v : V, HC.degree v = ∑ v ∈ comp, (2 * m) := by rw [← Finset.sum_subset (Finset.subset_univ comp)] · exact Finset.sum_congr rfl (fun v hv ↦ hreg v (Finset.mem_filter.mp hv).2) · intro v _ hv rw [Finset.mem_filter] at hv have hnr : ¬HC.Reachable x₀ v := fun hr ↦ hv ⟨Finset.mem_univ v, hr⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w; simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false] exact fun hadj ↦ hnr (hconn v w hadj) rw [hsum_comp, Finset.sum_const, smul_eq_mul] at hsum have hmul : 2 * (m * (2 * m + 1)) ≤ comp.card * (2 * m) := by nlinarith omega · exact ⟨x₀, SimpleGraph.Reachable.refl _, fun ho ↦ absurd ho hodd_e⟩ obtain ⟨v₀, hv₀_reach, hv₀_deg⟩ := hstart_v0 obtain ⟨L, hLtr, hLhd, hLlast, hLcov⟩ := exists_eulerian_circuit_component HC heven v₀ have hLcov_all : ∀ a b, HC.Adj a b → s(a, b) ∈ arcEdges L := fun a b hab ↦ hLcov a b hab (hv₀_reach.symm.trans (hconn a b hab)) have hLlen : L.length = HC.edgeFinset.card := by have hed := deleteArcs_edgeFinset_card hLtr have hzero : (deleteArcs HC L).edgeFinset.card = 0 := by rw [Finset.card_eq_zero] ext e' induction e' using Sym2.ind with | _ a b => simp only [SimpleGraph.mem_edgeFinset, Finset.notMem_empty, iff_false] intro hdel; exact hdel.2 (hLcov_all a b hdel.1) omega have hLne : L ≠ [] := by intro hnil; rw [hnil, List.length_nil] at hLlen; omega have hLnd : L.Nodup := List.Nodup.of_map _ (isArcTrail_nodup_edges hLtr) let L1 := (splitAlt true L).1 let L2 := (splitAlt true L).2 have hL1_sub : ∀ p ∈ L1, p ∈ L := fun p hp ↦ (splitAlt_mem_iff true L p).mpr (Or.inl hp) have hL2_sub : ∀ p ∈ L2, p ∈ L := fun p hp ↦ (splitAlt_mem_iff true L p).mpr (Or.inr hp) have hL12_nd := splitAlt_nodup true L hLnd let RC := arcListGraph hLtr L1 hL1_sub let BC := arcListGraph hLtr L2 hL2_sub have hR1_le : RC ≤ HC := arcListGraph_le hLtr L1 hL1_sub have hR2_le : BC ≤ HC := arcListGraph_le hLtr L2 hL2_sub have hdiff_eq : ∀ a b, (HC \ RC).Adj a b ↔ BC.Adj a b := by intro a b simp only [SimpleGraph.sdiff_adj] constructor · rintro ⟨hab, hnot1⟩ have heL := hLcov_all a b hab rw [arcEdges, List.mem_map] at heL obtain ⟨p, hpL, hsym⟩ := heL rcases (splitAlt_mem_iff true L p).mp hpL with hp1 | hp2 · exact absurd (List.mem_map.mpr ⟨p, hp1, hsym⟩) hnot1 · exact List.mem_map.mpr ⟨p, hp2, hsym⟩ · intro h2 refine ⟨hR2_le h2, ?_⟩ intro h1 change s(a, b) ∈ arcEdges L1 at h1 change s(a, b) ∈ arcEdges L2 at h2 rw [arcEdges, List.mem_map] at h1 h2 obtain ⟨p, hp1, hs1⟩ := h1 obtain ⟨q, hq2, hs2⟩ := h2 exact splitAlt_disjoint_edges hLtr true p hp1 q hq2 (hs1.trans hs2.symm) have htot : ∀ v, arcIncDeg L1 v + arcIncDeg L2 v = HC.degree v := by intro v rw [splitAlt_arcIncDeg_add true L v] have hd := deleteArcs_degree hLtr v have h0 : (deleteArcs HC L).degree v = 0 := by rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w; simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false] intro hdel; exact hdel.2 (hLcov_all v w hdel.1) unfold arcIncDeg; omega refine ⟨RC, hR1_le, ?_, ?_⟩ · intro v rw [arcListGraph_degree hLtr L1 hL1_sub hL12_nd.1 v] have hbal := splitAlt_balance L true hLtr v₀ v₀ hLhd hLlast hLne v change (arcIncDeg L1 v : ℤ) - (arcIncDeg L2 v : ℤ) = _ at hbal have hdv := hdeg v have ht := htot v by_cases hvv0 : v = v₀ · subst hvv0 by_cases hev_len : L.length % 2 = 0 · simp [hev_len] at hbal omega · have hodd_e : Odd HC.edgeFinset.card := by rw [← hLlen]; exact Nat.odd_iff.mpr (by omega) have hv0le := hv₀_deg hodd_e simp [hev_len] at hbal omega · simp only [if_neg hvv0] at hbal; omega · intro v have hdeg2 : (HC \ RC).degree v = arcIncDeg L2 v := by rw [← arcListGraph_degree hLtr L2 hL2_sub hL12_nd.2 v] simp only [← SimpleGraph.card_neighborFinset_eq_degree] congr 1; ext w simp only [SimpleGraph.mem_neighborFinset] exact hdiff_eq v w rw [hdeg2] have hbal := splitAlt_balance L true hLtr v₀ v₀ hLhd hLlast hLne v change (arcIncDeg L1 v : ℤ) - (arcIncDeg L2 v : ℤ) = _ at hbal have hdv := hdeg v have ht := htot v by_cases hvv0 : v = v₀ · subst hvv0 by_cases hev_len : L.length % 2 = 0 · simp [hev_len] at hbal omega · simp [hev_len] at hbal omega · simp only [if_neg hvv0] at hbal; omega /-- Helper 3B: Diagonal `(m, m)`-decomposition of a single component containing an odd-degree vertex. -/ lemma hasDecomp_diag_odd_component {V : Type*} [Fintype V] (HC : SimpleGraph V) (m : ℕ) (x₀ u_odd : V) (hpos : 0 < HC.edgeFinset.card) (hconn : ∀ a b, HC.Adj a b → HC.Reachable x₀ a) (hu_odd : Odd (HC.degree u_odd)) (hdeg : ∀ v, HC.degree v ≤ 2 * m) : HasDecomp HC m m := by have hu_reach : HC.Reachable x₀ u_odd := by have hpos_u : 0 < HC.degree u_odd := by rcases hu_odd with ⟨r, hr⟩; omega rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_pos] at hpos_u obtain ⟨w, hw⟩ := hpos_u exact hconn u_odd w ((SimpleGraph.mem_neighborFinset _ _ _).mp hw) let HC' : SimpleGraph (Option V) := { Adj := fun a b ↦ match a, b with | some u, some v => HC.Adj u v | none, some v => Odd (HC.degree v) | some u, none => Odd (HC.degree u) | none, none => False symm := ⟨fun a b h ↦ by cases a with | none => cases b with | none => exact h | some v => exact h | some u => cases b with | none => exact h | some v => exact h.symm⟩ loopless := ⟨fun a h ↦ by cases a with | none => exact h | some u => exact HC.loopless.irrefl u h⟩ } have hdeg_some : ∀ v : V, HC'.degree (some v) = HC.degree v + (if Odd (HC.degree v) then 1 else 0) := by intro v let S₁ : Finset (Option V) := (HC.neighborFinset v).map ⟨Option.some, Option.some_injective V⟩ by_cases ho : Odd (HC.degree v) · rw [if_pos ho]; simp only [← SimpleGraph.card_neighborFinset_eq_degree] have heq : HC'.neighborFinset (some v) = insert none S₁ := by ext a; cases a with | none => simp only [SimpleGraph.mem_neighborFinset, Finset.mem_insert, true_or, iff_true]; exact ho | some w => simp only [SimpleGraph.mem_neighborFinset, Finset.mem_insert, reduceCtorEq, false_or, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, Option.some.injEq, exists_eq_right]; rfl rw [heq, Finset.card_insert_of_notMem (by simp [S₁]), Finset.card_map] · rw [if_neg ho, add_zero]; simp only [← SimpleGraph.card_neighborFinset_eq_degree] have heq : HC'.neighborFinset (some v) = S₁ := by ext a; cases a with | none => simp only [SimpleGraph.mem_neighborFinset, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, reduceCtorEq, and_false, exists_false, iff_false]; exact ho | some w => simp only [SimpleGraph.mem_neighborFinset, S₁, Finset.mem_map, Function.Embedding.coeFn_mk, Option.some.injEq, exists_eq_right]; rfl rw [heq, Finset.card_map] have hHC'_even : ∀ a : Option V, Even (HC'.degree a) := by intro a cases a with | none => have hsum := HC.sum_degrees_eq_twice_card_edges have hcard : HC'.degree none = (Finset.univ.filter (fun v : V ↦ Odd (HC.degree v))).card := by rw [← SimpleGraph.card_neighborFinset_eq_degree] refine Finset.card_bij (fun a ha ↦ match a with | some v => v | none => False.elim (by rw [SimpleGraph.mem_neighborFinset] at ha; exact ha)) (fun a ha ↦ by cases a with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha; exact ha | some v => rw [SimpleGraph.mem_neighborFinset] at ha; exact Finset.mem_filter.mpr ⟨Finset.mem_univ v, ha⟩) (fun a₁ ha₁ a₂ ha₂ h ↦ by cases a₁ with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha₁; exact ha₁ | some v₁ => cases a₂ with | none => exfalso; rw [SimpleGraph.mem_neighborFinset] at ha₂; exact ha₂ | some v₂ => exact congrArg Option.some h) (fun v hv ↦ ⟨some v, (SimpleGraph.mem_neighborFinset _ _ _).mpr (Finset.mem_filter.mp hv).2, rfl⟩) rw [hcard, Nat.even_iff] have hmod : (∑ v : V, HC.degree v) % 2 = 0 := by rw [hsum]; omega have h1 : ∀ v : V, HC.degree v % 2 = if Odd (HC.degree v) then 1 else 0 := by intro v; by_cases ho : Odd (HC.degree v) · rw [if_pos ho]; exact Nat.odd_iff.mp ho · rw [if_neg ho]; exact Nat.even_iff.mp (Nat.not_odd_iff_even.mp ho) have h2 : (∑ v : V, HC.degree v) % 2 = (∑ v : V, HC.degree v % 2) % 2 := by rw [Finset.sum_nat_mod] rw [← hmod, h2]; simp only [h1, Finset.sum_boole, Nat.cast_id] | some v => rw [hdeg_some v]; by_cases ho : Odd (HC.degree v) · rw [if_pos ho]; rcases ho with ⟨r, hr⟩; exact ⟨r + 1, by omega⟩ · rw [if_neg ho, add_zero]; exact Nat.not_odd_iff_even.mp ho obtain ⟨L, hLtr, hLhd, hLlast, hLcov⟩ := exists_eulerian_circuit_component HC' hHC'_even none have hLcov_HC : ∀ a b, HC.Adj a b → s(some a, some b) ∈ arcEdges L := by intro a b hab apply hLcov (some a) (some b) hab have h1 : HC'.Reachable none (some u_odd) := SimpleGraph.Adj.reachable hu_odd have htoHC' : ∀ {u w : V}, HC.Reachable u w → HC'.Reachable (some u) (some w) := by intro u w huw obtain ⟨p⟩ := huw induction p with | nil => exact SimpleGraph.Reachable.refl _ | cons hstep _ ihp => have hstep' : HC'.Adj (some _) (some _) := hstep exact hstep'.reachable.trans ihp exact h1.trans (htoHC' (hu_reach.symm.trans (hconn a b hab))) have hLne : L ≠ [] := by intro hnil obtain ⟨e, he⟩ := Finset.card_pos.mp hpos induction e using Sym2.ind with | _ a b => have hm := hLcov_HC a b (SimpleGraph.mem_edgeFinset.mp he) rw [hnil] at hm; simp [arcEdges] at hm have hLnd : L.Nodup := List.Nodup.of_map _ (isArcTrail_nodup_edges hLtr) let L1 := (splitAlt true L).1 let L2 := (splitAlt true L).2 have hL1_sub : ∀ p ∈ L1, p ∈ L := fun p hp ↦ (splitAlt_mem_iff true L p).mpr (Or.inl hp) have hL2_sub : ∀ p ∈ L2, p ∈ L := fun p hp ↦ (splitAlt_mem_iff true L p).mpr (Or.inr hp) have hL12_nd := splitAlt_nodup true L hLnd have hR1_le := arcListGraph_le hLtr L1 hL1_sub have hR2_le := arcListGraph_le hLtr L2 hL2_sub let RC : SimpleGraph V := { Adj := fun u v ↦ s(some u, some v) ∈ arcEdges L1 symm := ⟨fun _ _ h ↦ by rwa [Sym2.eq_swap]⟩ loopless := ⟨fun v h ↦ HC.loopless.irrefl v (hR1_le h)⟩ } have hRC_le : RC ≤ HC := fun u v h ↦ hR1_le h have hinc_le : ∀ v, arcIncDeg L1 (some v) ≤ m ∧ arcIncDeg L2 (some v) ≤ m := by intro v have hbal := splitAlt_balance L true hLtr none none hLhd hLlast hLne (some v) change (arcIncDeg L1 (some v) : ℤ) - (arcIncDeg L2 (some v) : ℤ) = _ at hbal have hne_none : (some v : Option V) ≠ none := Option.some_ne_none v simp only [if_neg hne_none] at hbal have hsum_inc : arcIncDeg L1 (some v) + arcIncDeg L2 (some v) ≤ HC'.degree (some v) := by rw [splitAlt_arcIncDeg_add true L (some v)] have := deleteArcs_degree hLtr (some v) unfold arcIncDeg; omega have hdv : HC'.degree (some v) ≤ 2 * m := by rw [hdeg_some v]; have hle := hdeg v by_cases ho : Odd (HC.degree v) · rw [if_pos ho]; rcases ho with ⟨r, hr⟩; omega · rw [if_neg ho, add_zero]; omega omega refine ⟨RC, hRC_le, ?_, ?_⟩ · intro v have hle1 : (RC.neighborFinset v).card ≤ arcIncDeg L1 (some v) := by rw [← arcListGraph_degree hLtr L1 hL1_sub hL12_nd.1 (some v)] rw [← SimpleGraph.card_neighborFinset_eq_degree] have hsub : (RC.neighborFinset v).map ⟨Option.some, Option.some_injective V⟩ ⊆ (arcListGraph hLtr L1 hL1_sub).neighborFinset (some v) := by intro a ha rw [Finset.mem_map] at ha; obtain ⟨w, hw, rfl⟩ := ha rw [SimpleGraph.mem_neighborFinset] at hw ⊢; exact hw have hcard_le := Finset.card_le_card hsub rw [Finset.card_map] at hcard_le exact hcard_le rw [← SimpleGraph.card_neighborFinset_eq_degree] have hfin : (RC.neighborFinset v).card ≤ m := le_trans hle1 (hinc_le v).1 convert hfin · intro v have hle2 : ((HC \ RC).neighborFinset v).card ≤ arcIncDeg L2 (some v) := by rw [← arcListGraph_degree hLtr L2 hL2_sub hL12_nd.2 (some v)] rw [← SimpleGraph.card_neighborFinset_eq_degree] have hsub : ((HC \ RC).neighborFinset v).map ⟨Option.some, Option.some_injective V⟩ ⊆ (arcListGraph hLtr L2 hL2_sub).neighborFinset (some v) := by intro a ha rw [Finset.mem_map] at ha; obtain ⟨w, hw, rfl⟩ := ha rw [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] at hw rw [SimpleGraph.mem_neighborFinset] have heL := hLcov_HC v w hw.1 rw [arcEdges, List.mem_map] at heL obtain ⟨p, hpL, hsym⟩ := heL rcases (splitAlt_mem_iff true L p).mp hpL with hp1 | hp2 · exact absurd (List.mem_map.mpr ⟨p, hp1, hsym⟩) hw.2 · exact List.mem_map.mpr ⟨p, hp2, hsym⟩ have hcard_le := Finset.card_le_card hsub rw [Finset.card_map] at hcard_le exact hcard_le rw [← SimpleGraph.card_neighborFinset_eq_degree] have hfin : ((HC \ RC).neighborFinset v).card ≤ m := le_trans hle2 (hinc_le v).2 convert hfin /-- **Engine 3 (Exact Diagonal Eulerian Decomposition):** For EVERY `m : ℕ` (even OR odd!) and EVERY finite simple graph `H` with `Δ(H) ≤ 2m` and `e(H) < m * (2 * m + 1)`, `H` admits an `(m, m)`-edge-decomposition (`HasDecomp H m m`). -/ theorem hasDecomp_diag_of_lt_edges {V : Type*} [Fintype V] (H : SimpleGraph V) (m : ℕ) (hdeg : ∀ v, H.degree v ≤ 2 * m) (hedge : H.edgeFinset.card < m * (2 * m + 1)) : HasDecomp H m m := by suffices h : ∀ k (H : SimpleGraph V), H.edgeFinset.card ≤ k → (∀ v, H.degree v ≤ 2 * m) → H.edgeFinset.card < m * (2 * m + 1) → HasDecomp H m m by exact h H.edgeFinset.card H le_rfl hdeg hedge intro k induction k with | zero => intro H hk _ _ refine ⟨⊥, bot_le, fun _ ↦ by simp, fun v ↦ ?_⟩ have h0 : H.degree v = 0 := by rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false] intro hw have hmem : s(v, w) ∈ H.edgeFinset := SimpleGraph.mem_edgeFinset.mpr hw exact Nat.not_lt_zero _ (lt_of_lt_of_le (Finset.card_pos.mpr ⟨_, hmem⟩) hk) have hle : ((H \ ⊥).neighborFinset v).card ≤ (H.neighborFinset v).card := Finset.card_le_card (fun w hw ↦ (SimpleGraph.mem_neighborFinset _ _ _).mpr ((SimpleGraph.sdiff_adj _ _ _ _).mp ((SimpleGraph.mem_neighborFinset _ _ _).mp hw)).1) have h1 : (H \ ⊥).degree v = ((H \ ⊥).neighborFinset v).card := by rw [SimpleGraph.card_neighborFinset_eq_degree] have h2 : H.degree v = (H.neighborFinset v).card := by rw [SimpleGraph.card_neighborFinset_eq_degree] have hfin : (H \ ⊥).degree v ≤ m := by omega convert hfin | succ k ih => intro H hk hdeg hedge by_cases hempty : H.edgeFinset.card = 0 · exact ih H (by omega) hdeg hedge · obtain ⟨e, he⟩ := Finset.card_pos.mp (Nat.pos_of_ne_zero hempty) induction e using Sym2.ind with | _ x₀ y₀ => rw [SimpleGraph.mem_edgeFinset] at he let HC : SimpleGraph V := { Adj := fun u v ↦ H.Adj u v ∧ H.Reachable x₀ u symm := ⟨fun u v h ↦ ⟨h.1.symm, h.2.trans h.1.reachable⟩⟩ loopless := ⟨fun v h ↦ H.loopless.irrefl v h.1⟩ } let Hrest : SimpleGraph V := { Adj := fun u v ↦ H.Adj u v ∧ ¬H.Reachable x₀ u symm := ⟨fun u v h ↦ ⟨h.1.symm, fun hr ↦ h.2 (hr.trans h.1.symm.reachable)⟩⟩ loopless := ⟨fun v h ↦ H.loopless.irrefl v h.1⟩ } have hHC_deg : ∀ v, HC.degree v = if H.Reachable x₀ v then H.degree v else 0 := by intro v by_cases hr : H.Reachable x₀ v · rw [if_pos hr]; simp only [← SimpleGraph.card_neighborFinset_eq_degree] congr 1; ext w; simp only [SimpleGraph.mem_neighborFinset, HC] exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, hr⟩⟩ · rw [if_neg hr, ← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w; simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false, HC] exact fun h ↦ hr h.2 have hHrest_deg : ∀ v, Hrest.degree v = if H.Reachable x₀ v then 0 else H.degree v := by intro v by_cases hr : H.Reachable x₀ v · rw [if_pos hr, ← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_eq_zero] ext w; simp only [SimpleGraph.mem_neighborFinset, Finset.notMem_empty, iff_false, Hrest] exact fun h ↦ h.2 hr · rw [if_neg hr]; simp only [← SimpleGraph.card_neighborFinset_eq_degree] congr 1; ext w; simp only [SimpleGraph.mem_neighborFinset, Hrest] exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, hr⟩⟩ have hH_edges_split : HC.edgeFinset.card + Hrest.edgeFinset.card = H.edgeFinset.card := by rw [← Finset.card_union_of_disjoint] · congr 1; ext e' induction e' using Sym2.ind with | _ a b => simp only [Finset.mem_union, SimpleGraph.mem_edgeFinset] change (H.Adj a b ∧ H.Reachable x₀ a) ∨ (H.Adj a b ∧ ¬H.Reachable x₀ a) ↔ H.Adj a b tauto · rw [Finset.disjoint_left]; intro e' h1 h2 induction e' using Sym2.ind with | _ a b => rw [SimpleGraph.mem_edgeFinset] at h1 h2 exact h2.2 h1.2 have hHC_pos : 0 < HC.edgeFinset.card := Finset.card_pos.mpr ⟨s(x₀, y₀), SimpleGraph.mem_edgeFinset.mpr ⟨he, SimpleGraph.Reachable.refl _⟩⟩ have hHrest_deg_le : ∀ v, Hrest.degree v ≤ 2 * m := by intro v; rw [hHrest_deg v]; split_ifs; exact Nat.zero_le _; exact hdeg v have hHC_deg_le : ∀ v, HC.degree v ≤ 2 * m := by intro v; rw [hHC_deg v]; split_ifs; exact hdeg v; exact Nat.zero_le _ have hHrest_le : Hrest.edgeFinset.card ≤ k := by omega have hHrest_lt : Hrest.edgeFinset.card < m * (2 * m + 1) := by omega have hHC_lt : HC.edgeFinset.card < m * (2 * m + 1) := by omega obtain ⟨Rrest, hRrest_le, hRrest_r, hRrest_b⟩ := ih Hrest (by convert hHrest_le) (by convert hHrest_deg_le) (by convert hHrest_lt) have hHC_conn : ∀ a b, HC.Adj a b → HC.Reachable x₀ a := by intro a b hab obtain ⟨p⟩ := hab.2 have htoHC : ∀ {u w : V} (q : H.Walk u w), H.Reachable x₀ u → HC.Reachable u w := by intro u w q induction q with | nil => intro _; exact SimpleGraph.Reachable.refl _ | cons hstep _ ihp => intro hxu have hadjHC : HC.Adj _ _ := ⟨hstep, hxu⟩ exact hadjHC.reachable.trans (ihp (hxu.trans hstep.reachable)) exact htoHC p (SimpleGraph.Reachable.refl _) have hHC_decomp : HasDecomp HC m m := by by_cases hall_even : ∀ v, Even (HC.degree v) · exact hasDecomp_diag_even_component HC m x₀ (by convert hHC_pos) hHC_conn (by convert hall_even) (by convert hHC_deg_le) (by convert hHC_lt) · push Not at hall_even obtain ⟨u_odd, hu_odd⟩ := hall_even exact hasDecomp_diag_odd_component HC m x₀ u_odd (by convert hHC_pos) hHC_conn (by convert Nat.not_even_iff_odd.mp hu_odd) (by convert hHC_deg_le) obtain ⟨RC, hRC_le, hRC_r, hRC_b⟩ := hHC_decomp let R : SimpleGraph V := RC ⊔ Rrest have hRle : R ≤ H := fun u v huv ↦ huv.elim (fun h1 ↦ (hRC_le h1).1) (fun h2 ↦ (hRrest_le h2).1) refine ⟨R, hRle, ?_, ?_⟩ · intro v by_cases hr : H.Reachable x₀ v · have heq : (R.neighborFinset v).card = (RC.neighborFinset v).card := by congr 1; ext w; simp only [SimpleGraph.mem_neighborFinset, R, SimpleGraph.sup_adj] exact ⟨fun h ↦ h.elim id (fun h2 ↦ absurd hr (hRrest_le h2).2), Or.inl⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] have h1 : (RC.neighborFinset v).card ≤ m := by rw [SimpleGraph.card_neighborFinset_eq_degree]; exact hRC_r v exact le_trans (by convert heq.le) h1 · have heq : (R.neighborFinset v).card = (Rrest.neighborFinset v).card := by congr 1; ext w; simp only [SimpleGraph.mem_neighborFinset, R, SimpleGraph.sup_adj] exact ⟨fun h ↦ h.elim (fun h1 ↦ absurd (hRC_le h1).2 hr) id, Or.inr⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] have h1 : (Rrest.neighborFinset v).card ≤ m := by rw [SimpleGraph.card_neighborFinset_eq_degree]; exact hRrest_r v exact le_trans (by convert heq.le) h1 · intro v by_cases hr : H.Reachable x₀ v · have heq : ((H \ R).neighborFinset v).card = ((HC \ RC).neighborFinset v).card := by congr 1; ext w simp only [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj, R, SimpleGraph.sup_adj, HC] exact ⟨fun ⟨hH, hnot⟩ ↦ ⟨⟨hH, hr⟩, fun hRC ↦ hnot (Or.inl hRC)⟩, fun ⟨⟨hH, _⟩, hnot⟩ ↦ ⟨hH, fun hsup ↦ hsup.elim hnot (fun h2 ↦ absurd hr (hRrest_le h2).2)⟩⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] have h1 : ((HC \ RC).neighborFinset v).card ≤ m := by rw [SimpleGraph.card_neighborFinset_eq_degree]; convert hRC_b v exact le_trans (by convert heq.le) h1 · have heq : ((H \ R).neighborFinset v).card = ((Hrest \ Rrest).neighborFinset v).card := by congr 1; ext w simp only [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj, R, SimpleGraph.sup_adj, Hrest] exact ⟨fun ⟨hH, hnot⟩ ↦ ⟨⟨hH, hr⟩, fun hRr ↦ hnot (Or.inr hRr)⟩, fun ⟨⟨hH, _⟩, hnot⟩ ↦ ⟨hH, fun hsup ↦ hsup.elim (fun h1 ↦ absurd (hRC_le h1).2 hr) hnot⟩⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] have h1 : ((Hrest \ Rrest).neighborFinset v).card ≤ m := by rw [SimpleGraph.card_neighborFinset_eq_degree]; convert hRrest_b v exact le_trans (by convert heq.le) h1 /-! ### Engine 4: Vizing's Theorem, Vizing's Adjacency Lemma, and Class-1 Edge Threshold -/ /-- A partial proper `k`-edge-coloring of a simple graph `H`. -/ structure PartialEdgeColoring {V : Type*} (H : SimpleGraph V) (k : ℕ) where col : Sym2 V → Option (Fin k) supported : ∀ u v c, col s(u, v) = some c → H.Adj u v proper : ∀ u v₁ v₂ c, col s(u, v₁) = some c → col s(u, v₂) = some c → v₁ = v₂ /-- A partial edge coloring is total if every edge of `H` is colored. -/ def PartialEdgeColoring.IsTotal {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) : Prop := ∀ u v, H.Adj u v → (P.col s(u, v)).isSome /-- A graph `H` is `k`-edge-colorable if it admits a total proper `k`-edge-coloring. -/ def IsEdgeColorable {V : Type*} (H : SimpleGraph V) (k : ℕ) : Prop := ∃ P : PartialEdgeColoring H k, P.IsTotal /-- Color `c` is missing at vertex `v` in partial edge coloring `P`. -/ def IsMissing {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (c : Fin k) : Prop := ∀ w, P.col s(v, w) ≠ some c /-- Number of missing colors at `v` when `v` has at most `deg` colored incident edges. -/ lemma card_missing_ge {V : Type*} [Fintype V] {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) : k ≤ (Finset.univ.filter (fun c : Fin k ↦ IsMissing P v c)).card + (Finset.univ.filter (fun w : V ↦ (P.col s(v, w)).isSome)).card := by let used : Finset (Fin k) := Finset.univ.filter (fun c ↦ ∃ w, P.col s(v, w) = some c) have hpart : (Finset.univ.filter (fun c : Fin k ↦ IsMissing P v c)).card + used.card = k := by have h1 := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin k))) (p := fun c ↦ IsMissing P v c) have heq : (Finset.univ.filter (fun c : Fin k ↦ ¬IsMissing P v c)) = used := by ext c; simp [used, IsMissing] rw [heq] at h1 simpa using h1 have hused_le : used.card ≤ (Finset.univ.filter (fun w : V ↦ (P.col s(v, w)).isSome)).card := by have hpick : ∀ c ∈ used, ∃ w ∈ Finset.univ.filter (fun w : V ↦ (P.col s(v, w)).isSome), P.col s(v, w) = some c := by intro c hc obtain ⟨w, hw⟩ := (Finset.mem_filter.mp hc).2 exact ⟨w, Finset.mem_filter.mpr ⟨Finset.mem_univ w, by simp [hw]⟩, hw⟩ choose f hfmem hfcol using hpick calc used.card = (used.attach.image (fun c ↦ f c.1 c.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ heq dsimp at heq have e1 := hfcol c₁ h₁; have e2 := hfcol c₂ h₂ rw [heq] at e1 exact Subtype.ext (Option.some.inj (e1.symm.trans e2)) _ ≤ (Finset.univ.filter (fun w : V ↦ (P.col s(v, w)).isSome)).card := Finset.card_le_card (by intro w hw; rw [Finset.mem_image] at hw obtain ⟨c, _, rfl⟩ := hw; exact hfmem c.1 c.2) omega /-- From a total `(a + b)`-edge-coloring of `H`, extract an `(a, b)`-edge-decomposition `HasDecomp H a b`. -/ lemma hasDecomp_of_isEdgeColorable {V : Type*} [Fintype V] {H : SimpleGraph V} {a b : ℕ} (hcol : IsEdgeColorable H (a + b)) : HasDecomp H a b := by obtain ⟨P, htot⟩ := hcol let R : SimpleGraph V := { Adj := fun u v ↦ ∃ c : Fin (a + b), P.col s(u, v) = some c ∧ c.val < a symm := ⟨fun _ _ ⟨c, hc, hlt⟩ ↦ ⟨c, by rwa [Sym2.eq_swap], hlt⟩⟩ loopless := ⟨fun v ⟨c, hc, _⟩ ↦ H.loopless.irrefl v (P.supported v v c hc)⟩ } have hRle : R ≤ H := fun u v ⟨c, hc, _⟩ ↦ P.supported u v c hc refine ⟨R, hRle, ?_, ?_⟩ · intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] have hpick : ∀ w ∈ R.neighborFinset v, ∃ c : Fin a, P.col s(v, w) = some ⟨c.val, by omega⟩ := by intro w hw rw [SimpleGraph.mem_neighborFinset] at hw obtain ⟨c, hc, hlt⟩ := hw exact ⟨⟨c.val, hlt⟩, by simpa using hc⟩ choose f hf using hpick have hcard : (R.neighborFinset v).card ≤ a := by calc (R.neighborFinset v).card = ((R.neighborFinset v).attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ heq dsimp at heq have e1 := hf w₁ hw₁; have e2 := hf w₂ hw₂ rw [heq] at e1 exact Subtype.ext (P.proper v w₁ w₂ _ e1 e2) _ ≤ (Finset.univ : Finset (Fin a)).card := Finset.card_le_univ _ _ = a := by simp convert hcard · intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] have hpick : ∀ w ∈ (H \ R).neighborFinset v, ∃ c : Fin b, P.col s(v, w) = some ⟨a + c.val, by omega⟩ := by intro w hw rw [SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] at hw obtain ⟨c, hc⟩ := Option.isSome_iff_exists.mp (htot v w hw.1) have hge : a ≤ c.val := by by_contra hlt; push Not at hlt exact hw.2 ⟨c, hc, hlt⟩ refine ⟨⟨c.val - a, by omega⟩, ?_⟩ have hfin : (⟨a + (c.val - a), by omega⟩ : Fin (a + b)) = c := Fin.ext (by dsimp; omega) rw [hfin]; exact hc choose f hf using hpick have hcard : ((H \ R).neighborFinset v).card ≤ b := by calc ((H \ R).neighborFinset v).card = (((H \ R).neighborFinset v).attach.image (fun w ↦ f w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ heq dsimp at heq have e1 := hf w₁ hw₁; have e2 := hf w₂ hw₂ rw [heq] at e1 exact Subtype.ext (P.proper v w₁ w₂ _ e1 e2) _ ≤ (Finset.univ : Finset (Fin b)).card := Finset.card_le_univ _ _ = b := by simp convert hcard /-- The `(α, β)`-Kempe subgraph of a partial edge coloring `P`. -/ def kempeGraph {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (α β : Fin k) : SimpleGraph V where Adj u v := P.col s(u, v) = some α ∨ P.col s(u, v) = some β symm := ⟨fun _ _ h ↦ by rcases h with h | h <;> [exact Or.inl (by rwa [Sym2.eq_swap]); exact Or.inr (by rwa [Sym2.eq_swap])]⟩ loopless := ⟨fun v h ↦ by rcases h with h | h · exact H.loopless.irrefl v (P.supported v v α h) · exact H.loopless.irrefl v (P.supported v v β h)⟩ lemma kempeGraph_degree_le_two {V : Type*} [Fintype V] {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (α β : Fin k) (v : V) : (kempeGraph P α β).degree v ≤ 2 := by rw [← SimpleGraph.card_neighborFinset_eq_degree] have hle : ((kempeGraph P α β).neighborFinset v).card ≤ (Finset.univ.filter (fun w ↦ P.col s(v, w) = some α)).card + (Finset.univ.filter (fun w ↦ P.col s(v, w) = some β)).card := by calc ((kempeGraph P α β).neighborFinset v).card ≤ (Finset.univ.filter (fun w ↦ P.col s(v, w) = some α) ∪ Finset.univ.filter (fun w ↦ P.col s(v, w) = some β)).card := by refine Finset.card_le_card (fun w hw ↦ ?_) rw [SimpleGraph.mem_neighborFinset] at hw rw [Finset.mem_union, Finset.mem_filter, Finset.mem_filter] rcases hw with h | h · exact Or.inl ⟨Finset.mem_univ w, h⟩ · exact Or.inr ⟨Finset.mem_univ w, h⟩ _ ≤ _ := Finset.card_union_le _ _ have hcard1 : ∀ γ : Fin k, (Finset.univ.filter (fun w ↦ P.col s(v, w) = some γ)).card ≤ 1 := by intro γ rw [Finset.card_le_one] intro w₁ hw₁ w₂ hw₂ exact P.proper v w₁ w₂ γ (Finset.mem_filter.mp hw₁).2 (Finset.mem_filter.mp hw₂).2 have h1 := hcard1 α; have h2 := hcard1 β have hfin : ((kempeGraph P α β).neighborFinset v).card ≤ 2 := by omega convert hfin lemma kempeGraph_degree_le_one_of_missing {V : Type*} [Fintype V] {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (α β : Fin k) (v : V) (hmiss : IsMissing P v α ∨ IsMissing P v β) : (kempeGraph P α β).degree v ≤ 1 := by rw [← SimpleGraph.card_neighborFinset_eq_degree] have hfin : ((kempeGraph P α β).neighborFinset v).card ≤ 1 := by rw [Finset.card_le_one] intro w₁ hw₁ w₂ hw₂ rw [SimpleGraph.mem_neighborFinset] at hw₁ hw₂ rcases hmiss with hm | hm · rcases hw₁ with h1 | h1 · exact absurd h1 (hm w₁) · rcases hw₂ with h2 | h2 · exact absurd h2 (hm w₂) · exact P.proper v w₁ w₂ β h1 h2 · rcases hw₁ with h1 | h1 · rcases hw₂ with h2 | h2 · exact P.proper v w₁ w₂ α h1 h2 · exact absurd h2 (hm w₂) · exact absurd h1 (hm w₁) convert hfin /-- In any graph `K` with `Δ(K) ≤ 2`, two simple paths starting at a vertex `a` of degree `≤ 1` must agree at every vertex index `i ≤ min p.length q.length`! -/ lemma unique_path_from_deg_le_one {V : Type*} [Fintype V] (K : SimpleGraph V) (hdeg2 : ∀ v, K.degree v ≤ 2) {a b₁ b₂ : V} (p : K.Walk a b₁) (q : K.Walk a b₂) (hp : p.IsPath) (hq : q.IsPath) (ha : K.degree a ≤ 1) : ∀ i, i ≤ p.length → i ≤ q.length → p.getVert i = q.getVert i := by intro i induction i using Nat.strong_induction_on with | h i ih => intro hip hiq cases i with | zero => simp | succ j => cases j with | zero => have hp1 : K.Adj a (p.getVert 1) := by simpa using p.adj_getVert_succ (show 0 < p.length by omega) have hq1 : K.Adj a (q.getVert 1) := by simpa using q.adj_getVert_succ (show 0 < q.length by omega) rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_le_one] at ha exact ha _ ((SimpleGraph.mem_neighborFinset _ _ _).mpr hp1) _ ((SimpleGraph.mem_neighborFinset _ _ _).mpr hq1) | succ j => have hprev0 : p.getVert j = q.getVert j := ih j (by omega) (by omega) (by omega) have hprev1 : p.getVert (j + 1) = q.getVert (j + 1) := ih (j + 1) (by omega) (by omega) (by omega) set x := p.getVert (j + 1) have hp_prev : K.Adj x (p.getVert j) := (p.adj_getVert_succ (show j < p.length by omega)).symm have hp_next : K.Adj x (p.getVert (j + 2)) := p.adj_getVert_succ (show j + 1 < p.length by omega) have hq_next : K.Adj x (q.getVert (j + 2)) := by have h := q.adj_getVert_succ (show j + 1 < q.length by omega) rwa [← hprev1] at h have hp_ne : p.getVert (j + 2) ≠ p.getVert j := by intro heq have := hp.getVert_injOn (show j + 2 ∈ {t | t ≤ p.length} by dsimp; omega) (show j ∈ {t | t ≤ p.length} by dsimp; omega) heq omega have hq_ne : q.getVert (j + 2) ≠ p.getVert j := by intro heq rw [hprev0] at heq have := hq.getVert_injOn (show j + 2 ∈ {t | t ≤ q.length} by dsimp; omega) (show j ∈ {t | t ≤ q.length} by dsimp; omega) heq omega have her_card : ((K.neighborFinset x).erase (p.getVert j)).card ≤ 1 := by rw [Finset.card_erase_of_mem ((SimpleGraph.mem_neighborFinset _ _ _).mpr hp_prev), SimpleGraph.card_neighborFinset_eq_degree] have := hdeg2 x; omega rw [Finset.card_le_one] at her_card exact her_card _ (Finset.mem_erase.mpr ⟨hp_ne, (SimpleGraph.mem_neighborFinset _ _ _).mpr hp_next⟩) _ (Finset.mem_erase.mpr ⟨hq_ne, (SimpleGraph.mem_neighborFinset _ _ _).mpr hq_next⟩) /-- **Kempe Endpoint Lemma:** In any graph `K` with `Δ(K) ≤ 2`, three pairwise distinct vertices `a, b, c` each of degree `≤ 1` cannot all lie in the same connected component! -/ lemma kempe_at_most_two_deg_le_one {V : Type*} [Fintype V] (K : SimpleGraph V) (hdeg2 : ∀ v, K.degree v ≤ 2) {a b c : V} (hab : a ≠ b) (hac : a ≠ c) (hbc : b ≠ c) (ha : K.degree a ≤ 1) (hb : K.degree b ≤ 1) (hc : K.degree c ≤ 1) : ¬(K.Reachable a b ∧ K.Reachable a c) := by rintro ⟨⟨wb⟩, ⟨wc⟩⟩ have pb := wb.toPath have pc := wc.toPath -- WLOG `pb.1.length ≤ pc.1.length` have haux : ∀ {x y : V} (px : K.Walk a x) (py : K.Walk a y), px.IsPath → py.IsPath → a ≠ x → x ≠ y → K.degree x ≤ 1 → px.length ≤ py.length → False := by intro x y px py hpx hpy hax hxy hx hle have hpx_pos : 0 < px.length := by by_contra h0 have hlen0 : px.length = 0 := by omega exact hax (SimpleGraph.Walk.eq_of_length_eq_zero hlen0) have heq_x : px.getVert px.length = py.getVert px.length := unique_path_from_deg_le_one K hdeg2 px py hpx hpy ha px.length le_rfl hle rw [SimpleGraph.Walk.getVert_length] at heq_x have hlt : px.length < py.length := by by_contra hge have hlen_eq : px.length = py.length := by omega rw [hlen_eq, SimpleGraph.Walk.getVert_length] at heq_x exact hxy heq_x -- Then `x = py.getVert px.length` has TWO distinct neighbors on `py`: -- `py.getVert (px.length - 1)` and `py.getVert (px.length + 1)`! have hadj1 : K.Adj (py.getVert (px.length - 1)) x := by have h1 := py.adj_getVert_succ (show px.length - 1 < py.length by omega) have hidx : px.length - 1 + 1 = px.length := by omega rw [hidx, ← heq_x] at h1 exact h1 have hadj2 : K.Adj x (py.getVert (px.length + 1)) := by have h2 := py.adj_getVert_succ hlt rwa [← heq_x] at h2 rw [← SimpleGraph.card_neighborFinset_eq_degree, Finset.card_le_one] at hx have hsame : py.getVert (px.length - 1) = py.getVert (px.length + 1) := hx _ ((SimpleGraph.mem_neighborFinset _ _ _).mpr hadj1.symm) _ ((SimpleGraph.mem_neighborFinset _ _ _).mpr hadj2) have hinj := hpy.getVert_injOn have hmem1 : px.length - 1 ∈ {i | i ≤ py.length} := by dsimp; omega have hmem2 : px.length + 1 ∈ {i | i ≤ py.length} := by dsimp; omega have := hinj hmem1 hmem2 hsame omega by_cases hle : pb.1.length ≤ pc.1.length · exact haux pb.1 pc.1 pb.2 pc.2 hab hbc hb hle · exact haux pc.1 pb.1 pc.2 pb.2 hac hbc.symm hc (by omega) /-- Swap colors `α` and `β` on the `(α, β)`-Kempe component of vertex `v`. -/ noncomputable def kempeSwap {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) : PartialEdgeColoring H k where col e := if ∃ x ∈ e, (kempeGraph P α β).Reachable v x then swapOpt α β (P.col e) else P.col e supported := by intro u w c hc by_cases hr : ∃ x ∈ s(u, w), (kempeGraph P α β).Reachable v x · rw [if_pos hr] at hc rw [swapOpt_eq_some_iff] at hc cases hs : swapOpt α β (some c) with | none => exact absurd hs (swapOpt_some_ne_none α β c) | some c' => rw [hs] at hc; exact P.supported u w c' hc · rw [if_neg hr] at hc; exact P.supported u w c hc proper := by intro u w₁ w₂ c h1 h2 -- Note: if `P.col s(u, w) ∈ {some α, some β}`, then `(∃ x ∈ s(u, w), Reachable v x) ↔ Reachable v u`! have hred : ∀ w, (if ∃ x ∈ s(u, w), (kempeGraph P α β).Reachable v x then swapOpt α β (P.col s(u, w)) else P.col s(u, w)) = (if (kempeGraph P α β).Reachable v u then swapOpt α β (P.col s(u, w)) else P.col s(u, w)) := by intro w by_cases hab : P.col s(u, w) = some α ∨ P.col s(u, w) = some β · have hadj : (kempeGraph P α β).Adj u w := hab have hiff : (∃ x ∈ s(u, w), (kempeGraph P α β).Reachable v x) ↔ (kempeGraph P α β).Reachable v u := by constructor · rintro ⟨x, hx, hrx⟩ rw [Sym2.mem_iff] at hx rcases hx with rfl | rfl · exact hrx · exact hrx.trans hadj.symm.reachable · intro hru; exact ⟨u, Sym2.mem_mk_left u w, hru⟩ rw [hiff] · push Not at hab rw [swapOpt_eq_of_ne α β hab.1 hab.2] split_ifs <;> rfl rw [hred w₁] at h1; rw [hred w₂] at h2 by_cases hru : (kempeGraph P α β).Reachable v u · rw [if_pos hru, swapOpt_eq_some_iff] at h1 h2 cases hs : swapOpt α β (some c) with | none => exact absurd hs (swapOpt_some_ne_none α β c) | some c' => rw [hs] at h1 h2; exact P.proper u w₁ w₂ c' h1 h2 · rw [if_neg hru] at h1 h2 exact P.proper u w₁ w₂ c h1 h2 lemma kempeSwap_isSome {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) (e : Sym2 V) : ((kempeSwap P v α β).col e).isSome = (P.col e).isSome := by dsimp [kempeSwap] split_ifs · exact swapOpt_isSome α β _ · rfl lemma kempeSwap_eq_of_not_reachable {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) {u w : V} (hnot : ¬(kempeGraph P α β).Reachable v u) : (kempeSwap P v α β).col s(u, w) = P.col s(u, w) := by dsimp [kempeSwap] by_cases hab : P.col s(u, w) = some α ∨ P.col s(u, w) = some β · have hadj : (kempeGraph P α β).Adj u w := hab have hno : ¬∃ x ∈ s(u, w), (kempeGraph P α β).Reachable v x := by rintro ⟨x, hx, hrx⟩ rw [Sym2.mem_iff] at hx rcases hx with rfl | rfl · exact hnot hrx · exact hnot (hrx.trans hadj.symm.reachable) rw [if_neg hno] · push Not at hab rw [swapOpt_eq_of_ne α β hab.1 hab.2] split_ifs <;> rfl lemma kempeSwap_missing_swap {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) (u : V) (hreach : (kempeGraph P α β).Reachable v u) (hmiss : IsMissing P u β) : IsMissing (kempeSwap P v α β) u α := by intro w hw dsimp [kempeSwap] at hw rw [if_pos ⟨u, Sym2.mem_mk_left u w, hreach⟩, swapOpt_eq_some_iff] at hw have hso : swapOpt α β (some α) = some β := by simp [swapOpt] rw [hso] at hw exact hmiss w hw lemma kempeSwap_missing_preserved_of_not_reachable {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) (u : V) (γ : Fin k) (hnot : ¬(kempeGraph P α β).Reachable v u) (hmiss : IsMissing P u γ) : IsMissing (kempeSwap P v α β) u γ := by intro w hw rw [kempeSwap_eq_of_not_reachable P v α β hnot] at hw exact hmiss w hw lemma kempeSwap_missing_preserved_of_ne {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (v : V) (α β : Fin k) (u : V) (γ : Fin k) (h1 : γ ≠ α) (h2 : γ ≠ β) (hmiss : IsMissing P u γ) : IsMissing (kempeSwap P v α β) u γ := by intro w hw dsimp [kempeSwap] at hw by_cases hr : ∃ x ∈ s(u, w), (kempeGraph P α β).Reachable v x · rw [if_pos hr, swapOpt_eq_some_iff] at hw have hso : swapOpt α β (some γ) = some γ := swapOpt_eq_of_ne α β (by simp [h1]) (by simp [h2]) rw [hso] at hw exact hmiss w hw · rw [if_neg hr] at hw; exact hmiss w hw /-- A Vizing fan at center `u` is a nonempty nodup list `F = [w₀, w₁, ..., w_r]` of neighbors of `u` such that `s(u, w₀)` is uncolored, and for each step `wᵢ → wᵢ₊₁` in `F`, `s(u, wᵢ₊₁)` has a color that is missing at `wᵢ`. -/ def IsVizingFan {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (u : V) (F : List V) : Prop := F ≠ [] ∧ F.Nodup ∧ (∀ w ∈ F, H.Adj u w) ∧ (∀ w₀, F.head? = some w₀ → P.col s(u, w₀) = none) ∧ (∀ i (hi : i + 1 < F.length), ∃ c : Fin k, P.col s(u, F[i + 1]) = some c ∧ IsMissing P F[i] c) /-- If `F = [w₀, ..., w_r]` is a Vizing fan at `u` in `P`, and some color `γ` is missing at BOTH `u` and the last vertex `w_r`, then shifting colors along `F` and coloring `s(u, w_r)` with `γ` produces a valid `PartialEdgeColoring H k` that colors `s(u, w₀)` in addition to all previously colored edges! -/ lemma shiftFan_extend {V : Type*} {H : SimpleGraph V} {k : ℕ} (P : PartialEdgeColoring H k) (u : V) (F : List V) (hF : IsVizingFan P u F) (w₀ w_last : V) (hhd : F.head? = some w₀) (hlast : F.getLast? = some w_last) (γ : Fin k) (hmiss_u : IsMissing P u γ) (hmiss_last : IsMissing P w_last γ) : ∃ P' : PartialEdgeColoring H k, (P'.col s(u, w₀)).isSome ∧ (∀ e, (P.col e).isSome → (P'.col e).isSome) := by -- Induct on `F.length`! -- Base case `F = [w₀]` (`w_last = w₀`): simply color `s(u, w₀)` with `γ`! -- Inductive step `F = w₀ :: w₁ :: rest`: first shift/recolor `s(u, w₀) := P.col s(u, w₁)` and -- uncolor `s(u, w₁)` to get a valid partial coloring `P₁` where `w₁ :: rest` is a shorter Vizing fan! -- Wait: EVEN CLEANER! Induct on `n = F.length` generalizing `P, F, w₀`! suffices h : ∀ n (P : PartialEdgeColoring H k) (F : List V) (w₀ : V), F.length = n → IsVizingFan P u F → F.head? = some w₀ → F.getLast? = some w_last → IsMissing P u γ → IsMissing P w_last γ → ∃ P' : PartialEdgeColoring H k, (P'.col s(u, w₀)).isSome ∧ (∀ e, (P.col e).isSome → (P'.col e).isSome) by exact h F.length P F w₀ rfl hF hhd hlast hmiss_u hmiss_last intro n induction n with | zero => intro P F w₀ hlen hF _ _ _ _ exact absurd (List.eq_nil_of_length_eq_zero hlen) hF.1 | succ n ih => intro P F w₀ hlen hF hhd hlast hmu hml cases F with | nil => exact absurd rfl hF.1 | cons a rest => simp only [List.head?_cons, Option.some.injEq] at hhd subst hhd cases rest with | nil => simp only [List.getLast?_singleton, Option.some.injEq] at hlast subst hlast have hadj : H.Adj u a := hF.2.2.1 a (List.mem_cons_self ..) let P' : PartialEdgeColoring H k := { col := fun e ↦ if e = s(u, a) then some γ else P.col e supported := by intro x y c hc by_cases he : s(x, y) = s(u, a) · rw [Sym2.eq_iff] at he rcases he with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact hadj · exact hadj.symm · rw [if_neg he] at hc; exact P.supported x y c hc proper := by intro x y₁ y₂ c h1 h2 by_cases he1 : s(x, y₁) = s(u, a) <;> by_cases he2 : s(x, y₂) = s(u, a) · have h := he1.trans he2.symm rw [Sym2.eq_iff] at h rcases h with ⟨_, h⟩ | ⟨h1', h2'⟩ · exact h · exact h2'.trans h1' · rw [if_pos he1] at h1; rw [if_neg he2] at h2 have hc : c = γ := (Option.some.inj h1).symm; subst hc rw [Sym2.eq_iff] at he1 rcases he1 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact absurd h2 (hmu y₂) · exact absurd h2 (hml y₂) · rw [if_neg he1] at h1; rw [if_pos he2] at h2 have hc : c = γ := (Option.some.inj h2).symm; subst hc rw [Sym2.eq_iff] at he2 rcases he2 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact absurd h1 (hmu y₁) · exact absurd h1 (hml y₁) · rw [if_neg he1] at h1; rw [if_neg he2] at h2 exact P.proper x y₁ y₂ c h1 h2 } refine ⟨P', by simp [P'], ?_⟩ intro e he dsimp [P'] by_cases h0 : e = s(u, a) · rw [if_pos h0]; simp · rw [if_neg h0]; exact he | cons b tail => -- Shift edge `(u, b)`'s color `c₁` onto `(u, a)`, uncoloring `(u, b)`! obtain ⟨c₁, hc₁_eq, hc₁_miss⟩ := hF.2.2.2.2 0 (by simp) dsimp at hc₁_eq hc₁_miss have hnd : (a :: b :: tail).Nodup := hF.2.1 have hab_ne : a ≠ b := by rw [List.nodup_cons] at hnd; intro h; exact hnd.1 (h ▸ List.mem_cons_self ..) have hsua_ne_sub : s(u, a) ≠ s(u, b) := by intro h; rw [Sym2.eq_iff] at h rcases h with ⟨_, h⟩ | ⟨h1, h2⟩ · exact hab_ne h · exact hab_ne (h2.trans h1) have hadj_a : H.Adj u a := hF.2.2.1 a (List.mem_cons_self ..) have hcol_a_none : P.col s(u, a) = none := hF.2.2.2.1 a rfl let P₁ : PartialEdgeColoring H k := { col := fun e ↦ if e = s(u, a) then some c₁ else if e = s(u, b) then none else P.col e supported := by intro x y c hc by_cases h1 : s(x, y) = s(u, a) · rw [Sym2.eq_iff] at h1 rcases h1 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · exact hadj_a · exact hadj_a.symm · rw [if_neg h1] at hc by_cases h2 : s(x, y) = s(u, b) · rw [if_pos h2] at hc; simp at hc · rw [if_neg h2] at hc; exact P.supported x y c hc proper := by intro x y₁ y₂ c h1 h2 by_cases ha1 : s(x, y₁) = s(u, a) <;> by_cases ha2 : s(x, y₂) = s(u, a) · have h := ha1.trans ha2.symm rw [Sym2.eq_iff] at h rcases h with ⟨_, h⟩ | ⟨h1', h2'⟩ · exact h · exact h2'.trans h1' · rw [if_pos ha1] at h1; rw [if_neg ha2] at h2 have hceq : c = c₁ := (Option.some.inj h1).symm; subst hceq by_cases hb2 : s(x, y₂) = s(u, b) · rw [if_pos hb2] at h2; simp at h2 · rw [if_neg hb2] at h2 rw [Sym2.eq_iff] at ha1 rcases ha1 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · have hy2b : y₂ = b := P.proper x y₂ b c h2 hc₁_eq exact absurd (hy2b ▸ rfl) hb2 · exact absurd h2 (hc₁_miss y₂) · rw [if_neg ha1] at h1; rw [if_pos ha2] at h2 have hceq : c = c₁ := (Option.some.inj h2).symm; subst hceq by_cases hb1 : s(x, y₁) = s(u, b) · rw [if_pos hb1] at h1; simp at h1 · rw [if_neg hb1] at h1 rw [Sym2.eq_iff] at ha2 rcases ha2 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · have hy1b : y₁ = b := P.proper x y₁ b c h1 hc₁_eq exact absurd (hy1b ▸ rfl) hb1 · exact absurd h1 (hc₁_miss y₁) · rw [if_neg ha1] at h1; rw [if_neg ha2] at h2 by_cases hb1 : s(x, y₁) = s(u, b) · rw [if_pos hb1] at h1; simp at h1 · rw [if_neg hb1] at h1 by_cases hb2 : s(x, y₂) = s(u, b) · rw [if_pos hb2] at h2; simp at h2 · rw [if_neg hb2] at h2; exact P.proper x y₁ y₂ c h1 h2 } -- Check `b :: tail` is a Vizing fan for `P₁`! have ha_not_in : a ∉ (b :: tail) := (List.nodup_cons.mp hnd).1 have hnot_sua : ∀ w ∈ (b :: tail), s(u, w) ≠ s(u, a) := by intro w hw heq rw [Sym2.eq_iff] at heq rcases heq with ⟨_, rfl⟩ | ⟨h1, _⟩ · exact ha_not_in hw · exact hadj_a.ne h1 have hF₁ : IsVizingFan P₁ u (b :: tail) := by refine ⟨List.cons_ne_nil _ _, (List.nodup_cons.mp hnd).2, fun w hw ↦ hF.2.2.1 w (List.mem_cons_of_mem _ hw), ?_, ?_⟩ · intro w₀' hw₀' simp only [List.head?_cons, Option.some.injEq] at hw₀'; subst hw₀' dsimp [P₁]; rw [if_neg hsua_ne_sub.symm, if_pos rfl] · intro i hi obtain ⟨c, hceq, hcmiss⟩ := hF.2.2.2.2 (i + 1) (by simp at hi ⊢; omega) dsimp at hceq hcmiss refine ⟨c, ?_, ?_⟩ · dsimp [P₁] have hti_mem : tail[i]'(by simp at hi; omega) ∈ b :: tail := List.mem_cons_of_mem b (List.getElem_mem ..) have hne1 : s(u, tail[i]'(by simp at hi; omega)) ≠ s(u, a) := hnot_sua _ hti_mem have hne2 : s(u, tail[i]'(by simp at hi; omega)) ≠ s(u, b) := by intro heq have hb_not_in : b ∉ tail := (List.nodup_cons.mp (List.nodup_cons.mp hnd).2).1 rw [Sym2.eq_iff] at heq rcases heq with ⟨_, h⟩ | ⟨h1, _⟩ · exact hb_not_in (h ▸ List.getElem_mem ..) · exact (hF.2.2.1 b (List.mem_cons_of_mem a (List.mem_cons_self ..))).ne h1 rw [if_neg hne1, if_neg hne2] exact hceq · intro w hw dsimp [P₁] at hw by_cases h1 : s((b :: tail)[i], w) = s(u, a) · rw [if_pos h1] at hw rw [Sym2.eq_iff] at h1 rcases h1 with ⟨h1', _⟩ | ⟨h1', _⟩ · exact (hF.2.2.1 _ (List.mem_cons_of_mem _ (List.getElem_mem ..))).ne h1'.symm · exact ha_not_in (h1' ▸ List.getElem_mem ..) · rw [if_neg h1] at hw by_cases h2 : s((b :: tail)[i], w) = s(u, b) · rw [if_pos h2] at hw; simp at hw · rw [if_neg h2] at hw; exact hcmiss w hw have hlast₁ : (b :: tail).getLast? = some w_last := by simpa using hlast have hmu₁ : IsMissing P₁ u γ := by intro w hw dsimp [P₁] at hw by_cases h1 : s(u, w) = s(u, a) · rw [if_pos h1] at hw have hcc : c₁ = γ := Option.some.inj hw exact hmu b (hcc ▸ hc₁_eq) · rw [if_neg h1] at hw by_cases h2 : s(u, w) = s(u, b) · rw [if_pos h2] at hw; simp at hw · rw [if_neg h2] at hw; exact hmu w hw have hml₁ : IsMissing P₁ w_last γ := by intro w hw dsimp [P₁] at hw by_cases h1 : s(w_last, w) = s(u, a) · rw [Sym2.eq_iff] at h1 have hwlast_mem : w_last ∈ (b :: tail) := List.mem_of_getLast? hlast₁ rcases h1 with ⟨h1', _⟩ | ⟨h1', _⟩ · exact (hF.2.2.1 w_last (List.mem_cons_of_mem _ hwlast_mem)).ne h1'.symm · exact ha_not_in (h1' ▸ hwlast_mem) · rw [if_neg h1] at hw by_cases h2 : s(w_last, w) = s(u, b) · rw [if_pos h2] at hw; simp at hw · rw [if_neg h2] at hw; exact hml w hw obtain ⟨P', hP'b, hP'supp⟩ := ih P₁ (b :: tail) b (by simp at hlen; omega) hF₁ rfl hlast₁ hmu₁ hml₁ refine ⟨P', hP'supp s(u, a) (by simp [P₁]), ?_⟩ intro e he by_cases hb : e = s(u, b) · rw [hb]; exact hP'b · apply hP'supp e dsimp [P₁] by_cases ha : e = s(u, a) · rw [if_pos ha]; simp · rw [if_neg ha, if_neg hb]; exact he /-- **Master Vizing Multifan Lemma (Ehrenfeucht–Faber–Kierstead / Vizing 1965):** Suppose `H` is NOT `k`-edge-colorable, `P` is a partial `k`-edge-coloring of `H` missing ONLY the single edge `s(u, w₀)`, and `α` is missing at `u`. Let `X` be the set of endpoints of Vizing fans at `u` starting at `w₀`. Then: 1. `w₀ ∈ X` and every `x ∈ X` is a neighbor of `u`; 2. No `x ∈ X` misses `α`; 3. Every color `γ` missing at some `x ∈ X` appears on `s(u, y)` for some `y ∈ X \ {w₀}`; 4. The missing color sets at distinct vertices `x, y ∈ X` are pairwise disjoint! -/ lemma vizing_multifan_disjoint_missing {V : Type*} [Fintype V] {H : SimpleGraph V} {k : ℕ} (hnotcol : ¬IsEdgeColorable H k) (u w₀ : V) (huw₀ : H.Adj u w₀) (P : PartialEdgeColoring H k) (hP_none : P.col s(u, w₀) = none) (hP_rest : ∀ x y, H.Adj x y → s(x, y) ≠ s(u, w₀) → (P.col s(x, y)).isSome) (α : Fin k) (hα : IsMissing P u α) : let X : Finset V := Finset.univ.filter (fun x ↦ ∃ F : List V, IsVizingFan P u F ∧ F.head? = some w₀ ∧ F.getLast? = some x) w₀ ∈ X ∧ (∀ x ∈ X, H.Adj u x) ∧ (∀ x ∈ X, ¬IsMissing P x α) ∧ (∀ x ∈ X, ∀ γ : Fin k, IsMissing P x γ → ∃ y ∈ X, y ≠ w₀ ∧ P.col s(u, y) = some γ) ∧ (∀ x ∈ X, ∀ y ∈ X, ∀ γ : Fin k, IsMissing P x γ → IsMissing P y γ → x = y) := by intro X have hExtendContrad : ∀ (Q : PartialEdgeColoring H k) (F : List V) (x : V) (γ : Fin k), (∀ e, (P.col e).isSome → (Q.col e).isSome) → IsVizingFan Q u F → F.head? = some w₀ → F.getLast? = some x → IsMissing Q u γ → IsMissing Q x γ → False := by intro Q F x γ hQsupp hFQ hhd hlast hmu hmx obtain ⟨Q', hQ'0, hQ'supp⟩ := shiftFan_extend Q u F hFQ w₀ x hhd hlast γ hmu hmx apply hnotcol refine ⟨Q', fun a b hab ↦ ?_⟩ by_cases h0 : s(a, b) = s(u, w₀) · rw [h0]; exact hQ'0 · exact hQ'supp _ (hQsupp _ (hP_rest a b hab h0)) have hw₀_mem : w₀ ∈ X := by rw [Finset.mem_filter] refine ⟨Finset.mem_univ w₀, [w₀], ⟨List.cons_ne_nil _ _, List.nodup_singleton w₀, fun w hw ↦ by rw [List.mem_singleton] at hw; exact hw ▸ huw₀, fun w hw ↦ by simp at hw; exact hw ▸ hP_none, fun i hi ↦ by simp at hi⟩, rfl, rfl⟩ have hX_adj : ∀ x ∈ X, H.Adj u x := by intro x hx obtain ⟨F, hF, _, hlast⟩ := (Finset.mem_filter.mp hx).2 exact hF.2.2.1 x (List.mem_of_getLast? hlast) have hX_not_α : ∀ x ∈ X, ¬IsMissing P x α := by intro x hx hmx obtain ⟨F, hF, hhd, hlast⟩ := (Finset.mem_filter.mp hx).2 exact hExtendContrad P F x α (fun _ h ↦ h) hF hhd hlast hα hmx have hX_appear : ∀ x ∈ X, ∀ γ : Fin k, IsMissing P x γ → ∃ y ∈ X, y ≠ w₀ ∧ P.col s(u, y) = some γ := by intro x hx γ hmx obtain ⟨F, hF, hhd, hlast⟩ := (Finset.mem_filter.mp hx).2 -- `γ` cannot be missing at `u`! have hnot_u : ¬IsMissing P u γ := fun hmu ↦ hExtendContrad P F x γ (fun _ h ↦ h) hF hhd hlast hmu hmx unfold IsMissing at hnot_u push Not at hnot_u obtain ⟨y, hy⟩ := hnot_u have hy_ne : y ≠ w₀ := by intro heq; subst heq; rw [hP_none] at hy; simp at hy refine ⟨y, ?_, hy_ne, hy⟩ rw [Finset.mem_filter] refine ⟨Finset.mem_univ y, ?_⟩ by_cases hyF : y ∈ F · -- Take the prefix of `F` up to `y`! obtain ⟨F₁, F₂, hFsplit⟩ := List.append_of_mem hyF let F' := F₁ ++ [y] have hF'ne : F' ≠ [] := by simp [F'] have hF'nd : F'.Nodup := by have hnd := hF.2.1 rw [hFsplit] at hnd have hnd1 := (List.nodup_append.mp hnd).1 have hdisj := (List.nodup_append.mp hnd).2.2 rw [List.nodup_append] refine ⟨hnd1, List.nodup_singleton y, fun a ha b hb ↦ ?_⟩ rw [List.mem_singleton] at hb; rw [hb] exact hdisj a ha y (List.mem_cons_self ..) have hF'hd : F'.head? = some w₀ := by cases F₁ with | nil => simp only [List.nil_append] at hFsplit rw [hFsplit] at hhd; simp at hhd; exact absurd hhd hy_ne | cons a rest => rw [hFsplit] at hhd; simpa [F'] using hhd have hF'last : F'.getLast? = some y := by simp [F'] have hF'sub : ∀ i (hi : i < F'.length), F'[i] = F[i]'(by rw [hFsplit, List.length_append, List.length_cons]; dsimp [F'] at hi; simp at hi; omega) := by intro i hi have hF_eq : F = F' ++ F₂ := by rw [hFsplit]; simp [F'] have h1 : F'[i] = (F' ++ F₂)[i]'(by rw [List.length_append]; omega) := (List.getElem_append_left hi).symm simpa [hF_eq] using h1 refine ⟨F', ⟨hF'ne, hF'nd, fun w hw ↦ hF.2.2.1 w (by rw [hFsplit]; rcases List.mem_append.mp hw with hw | hw · exact List.mem_append_left _ hw · rw [List.mem_singleton] at hw; subst hw; exact List.mem_append_right _ (List.mem_cons_self ..)), fun w hw ↦ by rw [hF'hd] at hw; simp at hw; exact hw ▸ hP_none, fun i hi ↦ by have hiF : i + 1 < F.length := by rw [hFsplit, List.length_append, List.length_cons]; dsimp [F'] at hi; simp at hi; omega obtain ⟨c, hc1, hc2⟩ := hF.2.2.2.2 i hiF rw [hF'sub (i + 1) hi, hF'sub i (by omega)] exact ⟨c, hc1, hc2⟩⟩, hF'hd, hF'last⟩ · -- Append `y` to `F`! let F' := F ++ [y] have hF'nd : F'.Nodup := by rw [List.nodup_append] exact ⟨hF.2.1, List.nodup_singleton y, fun a ha b hb ↦ by rw [List.mem_singleton] at hb; subst hb; intro heq; exact hyF (heq ▸ ha)⟩ have hF'hd : F'.head? = some w₀ := by cases F with | nil => exact absurd rfl hF.1 | cons a rest => simpa [F'] using hhd refine ⟨F', ⟨by simp [F'], hF'nd, fun w hw ↦ by rcases List.mem_append.mp hw with hw | hw · exact hF.2.2.1 w hw · rw [List.mem_singleton] at hw; rw [hw]; exact P.supported u y γ hy, fun w hw ↦ by rw [hF'hd] at hw; simp at hw; exact hw ▸ hP_none, fun i hi ↦ by dsimp [F'] at hi; rw [List.length_append, List.length_singleton] at hi by_cases hilt : i + 1 < F.length · obtain ⟨c, hc1, hc2⟩ := hF.2.2.2.2 i hilt dsimp [F'] rw [List.getElem_append_left hilt, List.getElem_append_left (by omega)] exact ⟨c, hc1, hc2⟩ · have hieq : i + 1 = F.length := by omega have hFi : F[i]'(by omega) = x := by have hgl : F.getLast? = F[F.length - 1]? := List.getLast?_eq_getElem? rw [hlast] at hgl have hlen_pos : 0 < F.length := List.length_pos_iff.mpr hF.1 rw [List.getElem?_eq_getElem (by omega)] at hgl have hidx : F.length - 1 = i := by omega simp only [hidx] at hgl; exact (Option.some.inj hgl).symm refine ⟨γ, ?_, ?_⟩ · dsimp [F'] rw [List.getElem_append_right (by omega)] have h0 : i + 1 - F.length = 0 := by omega simp [h0, hy] · dsimp [F'] rw [List.getElem_append_left (by omega), hFi] exact hmx⟩, hF'hd, by simp [F']⟩ -- Finally: disjoint missing colors across `X`! have hX_disj : ∀ x ∈ X, ∀ y ∈ X, ∀ γ : Fin k, IsMissing P x γ → IsMissing P y γ → x = y := by intro x hx y hy γ hmx hmy by_contra hxy -- In the `(α, γ)`-Kempe graph `K`, `u, x, y` are 3 distinct vertices each of degree ≤ 1! let K := kempeGraph P α γ have hux : u ≠ x := (hX_adj x hx).ne have huy : u ≠ y := (hX_adj y hy).ne have hdu : K.degree u ≤ 1 := kempeGraph_degree_le_one_of_missing P α γ u (Or.inl hα) have hdx : K.degree x ≤ 1 := kempeGraph_degree_le_one_of_missing P α γ x (Or.inr hmx) have hdy : K.degree y ≤ 1 := kempeGraph_degree_le_one_of_missing P α γ y (Or.inr hmy) have hnotboth := kempe_at_most_two_deg_le_one K (kempeGraph_degree_le_two P α γ) hux huy hxy hdu hdx hdy -- Hence there exists SOME `z ∈ X` with `IsMissing P z γ ∧ ¬K.Reachable u z`! have hex_bad : ∃ n : ℕ, ∃ (z : V) (F : List V), F.length = n ∧ IsVizingFan P u F ∧ F.head? = some w₀ ∧ F.getLast? = some z ∧ IsMissing P z γ ∧ ¬K.Reachable u z := by by_cases hrx : K.Reachable u x · have hry : ¬K.Reachable u y := fun h ↦ hnotboth ⟨hrx, h⟩ obtain ⟨F, hF, hhd, hlast⟩ := (Finset.mem_filter.mp hy).2 exact ⟨F.length, y, F, rfl, hF, hhd, hlast, hmy, hry⟩ · obtain ⟨F, hF, hhd, hlast⟩ := (Finset.mem_filter.mp hx).2 exact ⟨F.length, x, F, rfl, hF, hhd, hlast, hmx, hrx⟩ -- Take a MINIMAL-length fan `F` for such a vertex `z`! let n_min := Nat.find hex_bad obtain ⟨z, F, hFlen, hF, hhd, hlast, hmz, hnotrz⟩ := Nat.find_spec hex_bad have hmin : ∀ (z' : V) (F' : List V), F'.length < n_min → IsVizingFan P u F' → F'.head? = some w₀ → F'.getLast? = some z' → IsMissing P z' γ → ¬K.Reachable u z' → False := by intro z' F' hlt hF' hhd' hlast' hmz' hnr' exact Nat.find_min hex_bad hlt ⟨z', F', rfl, hF', hhd', hlast', hmz', hnr'⟩ -- Perform Kempe swap `(α, γ)` on the `K`-component of `z`! let Q := kempeSwap P z α γ have hQsupp : ∀ e, (P.col e).isSome → (Q.col e).isSome := fun e he ↦ by rw [kempeSwap_isSome]; exact he have hnotzu : ¬K.Reachable z u := fun h ↦ hnotrz h.symm have hQ_u_eq : ∀ w, Q.col s(u, w) = P.col s(u, w) := fun w ↦ kempeSwap_eq_of_not_reachable P z α γ hnotzu have hQ_mu : IsMissing Q u α := kempeSwap_missing_preserved_of_not_reachable P z α γ u α hnotzu hα have hQ_mz : IsMissing Q z α := kempeSwap_missing_swap P z α γ z (SimpleGraph.Reachable.refl _) hmz -- Verify `F` is STILL a Vizing fan for `Q`! have hFQ : IsVizingFan Q u F := by refine ⟨hF.1, hF.2.1, hF.2.2.1, fun w hw ↦ by rw [hQ_u_eq]; exact hF.2.2.2.1 w hw, ?_⟩ intro i hi obtain ⟨c, hceq, hcmiss⟩ := hF.2.2.2.2 i hi refine ⟨c, by rw [hQ_u_eq]; exact hceq, ?_⟩ have hc_ne_α : c ≠ α := fun h ↦ hα F[i + 1] (h ▸ hceq) by_cases hc_eq_γ : c = γ · subst hc_eq_γ -- Show `¬K.Reachable z F[i]` by minimality of `F`! have hnotr_i : ¬K.Reachable z F[i] := by intro hrz_i have hnotru_i : ¬K.Reachable u F[i] := fun hru_i ↦ hnotrz (hru_i.trans hrz_i.symm) -- The prefix `F.take (i + 1)` is a strictly shorter Vizing fan ending at `F[i]`! let F' := F.take (i + 1) have hF'len : F'.length = i + 1 := List.length_take_of_le (by omega) have hF'ne : F' ≠ [] := by intro h; rw [h] at hF'len; simp at hF'len have hF'nd : F'.Nodup := hF.2.1.sublist (List.take_sublist _ _) have hF'hd : F'.head? = some w₀ := by cases F with | nil => exact absurd rfl hF.1 | cons a rest => simpa [F'] using hhd have hF'last : F'.getLast? = some F[i] := by rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega)] simp [F', hF'len] have hF'fan : IsVizingFan P u F' := by refine ⟨hF'ne, hF'nd, fun w hw ↦ hF.2.2.1 w (List.mem_of_mem_take hw), fun w hw ↦ by rw [hF'hd] at hw; simp at hw; exact hw ▸ hP_none, fun j hj ↦ by have hjF : j + 1 < F.length := by omega obtain ⟨c', hc'1, hc'2⟩ := hF.2.2.2.2 j hjF refine ⟨c', ?_, ?_⟩ · simpa [F'] using hc'1 · simpa [F'] using hc'2⟩ exact hmin F[i] F' (by omega) hF'fan hF'hd hF'last hcmiss hnotru_i exact kempeSwap_missing_preserved_of_not_reachable P z α c F[i] c hnotr_i hcmiss · exact kempeSwap_missing_preserved_of_ne P z α γ F[i] c hc_ne_α hc_eq_γ hcmiss exact hExtendContrad Q F z α hQsupp hFQ hhd hlast hQ_mu hQ_mz exact ⟨hw₀_mem, hX_adj, hX_not_α, hX_appear, hX_disj⟩ /-- **Vizing's Theorem (1964):** Every finite simple graph `H` with `Δ(H) ≤ d` is `(d + 1)`-edge-colorable! (Proved in 20 lines from `vizing_multifan_disjoint_missing`.) -/ theorem vizing_theorem {V : Type*} [Fintype V] (H : SimpleGraph V) (d : ℕ) (hdeg : ∀ v, H.degree v ≤ d) : IsEdgeColorable H (d + 1) := by suffices h : ∀ m (H : SimpleGraph V), H.edgeFinset.card ≤ m → (∀ v, H.degree v ≤ d) → IsEdgeColorable H (d + 1) by exact h H.edgeFinset.card H le_rfl hdeg intro m induction m with | zero => intro H hm _ refine ⟨⟨fun _ ↦ none, by simp, by simp⟩, fun u v huv ↦ ?_⟩ exact absurd (lt_of_lt_of_le (Finset.card_pos.mpr ⟨_, SimpleGraph.mem_edgeFinset.mpr (show s(u, v) ∈ H.edgeSet from huv)⟩) hm) (Nat.not_lt_zero _) | succ m ih => intro H hm hdeg by_cases hempty : H.edgeFinset.card = 0 · exact ih H (by omega) hdeg · obtain ⟨e, he⟩ := Finset.card_pos.mp (Nat.pos_of_ne_zero hempty) induction e using Sym2.ind with | _ u w₀ => have he_adj : H.Adj u w₀ := SimpleGraph.mem_edgeFinset.mp he let H' : SimpleGraph V := H.deleteEdges {s(u, w₀)} have hH'_le : H' ≤ H := SimpleGraph.deleteEdges_le _ have hH'_card : H'.edgeFinset.card ≤ m := by have hss : H'.edgeFinset = H.edgeFinset.erase s(u, w₀) := by ext e' simp only [SimpleGraph.mem_edgeFinset, Finset.mem_erase, H', SimpleGraph.edgeSet_deleteEdges, Set.mem_sdiff, Set.mem_singleton_iff] tauto rw [hss, Finset.card_erase_of_mem he] omega have hH'_deg : ∀ v, H'.degree v ≤ d := fun v ↦ le_trans (SimpleGraph.degree_le_of_le hH'_le) (hdeg v) obtain ⟨P', hP'tot⟩ := ih H' (by convert hH'_card) (by intro v; convert hH'_deg v) -- Lift `P'` to a partial coloring `P` of `H` missing only `s(u, w₀)` let P : PartialEdgeColoring H (d + 1) := { col := fun e' ↦ if e' = s(u, w₀) then none else P'.col e' supported := by intro x y c hc by_cases h0 : s(x, y) = s(u, w₀) · rw [if_pos h0] at hc; simp at hc · rw [if_neg h0] at hc; exact hH'_le (P'.supported x y c hc) proper := by intro x y₁ y₂ c h1 h2 by_cases h01 : s(x, y₁) = s(u, w₀) · rw [if_pos h01] at h1; simp at h1 · rw [if_neg h01] at h1 by_cases h02 : s(x, y₂) = s(u, w₀) · rw [if_pos h02] at h2; simp at h2 · rw [if_neg h02] at h2; exact P'.proper x y₁ y₂ c h1 h2 } by_contra hnotcol -- `u` has at most `d - 1` colored edges in `P`, so `u` misses some color `α`! have hcolored_le : ∀ v, (Finset.univ.filter (fun w ↦ (P.col s(v, w)).isSome)).card ≤ H'.degree v := by intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] refine Finset.card_le_card (fun w hw ↦ ?_) rw [Finset.mem_filter] at hw rw [SimpleGraph.mem_neighborFinset] obtain ⟨c, hc⟩ := Option.isSome_iff_exists.mp hw.2 dsimp [P] at hc by_cases h0 : s(v, w) = s(u, w₀) · rw [if_pos h0] at hc; simp at hc · rw [if_neg h0] at hc; exact P'.supported v w c hc have hmiss_u_card : 1 ≤ (Finset.univ.filter (fun c : Fin (d + 1) ↦ IsMissing P u c)).card := by have hc := card_missing_ge P u have hl := hcolored_le u have hd := hH'_deg u omega obtain ⟨α, hα⟩ := Finset.card_pos.mp (by omega : 0 < (Finset.univ.filter (fun c : Fin (d + 1) ↦ IsMissing P u c)).card) have hα_miss : IsMissing P u α := (Finset.mem_filter.mp hα).2 have hP_rest : ∀ x y, H.Adj x y → s(x, y) ≠ s(u, w₀) → (P.col s(x, y)).isSome := by intro x y hxy hne dsimp [P]; rw [if_neg hne] exact hP'tot x y (SimpleGraph.deleteEdges_adj.mpr ⟨hxy, by simpa using hne⟩) obtain ⟨hw₀X, _, _, hX_app, hX_disj⟩ := vizing_multifan_disjoint_missing hnotcol u w₀ he_adj P (by simp [P]) hP_rest α hα_miss set X := Finset.univ.filter (fun x ↦ ∃ F : List V, IsVizingFan P u F ∧ F.head? = some w₀ ∧ F.getLast? = some x) -- Every `x ∈ X` has `≥ 1` missing color, and `w₀` has `≥ 2` missing colors! have hmiss_x : ∀ x ∈ X, 1 ≤ (Finset.univ.filter (fun c : Fin (d + 1) ↦ IsMissing P x c)).card := by intro x _ have hc := card_missing_ge P x; have hl := hcolored_le x; have hd := hH'_deg x; omega have hmiss_w₀ : 2 ≤ (Finset.univ.filter (fun c : Fin (d + 1) ↦ IsMissing P w₀ c)).card := by have hc := card_missing_ge P w₀; have hl := hcolored_le w₀ have hdeg_w₀ : H'.degree w₀ + 1 = H.degree w₀ := by simp only [← SimpleGraph.card_neighborFinset_eq_degree] have hss : H'.neighborFinset w₀ = (H.neighborFinset w₀).erase u := by ext z; simp only [SimpleGraph.mem_neighborFinset, Finset.mem_erase, H', SimpleGraph.deleteEdges_adj, Set.mem_singleton_iff] constructor · rintro ⟨hz, hne⟩ exact ⟨fun hzu ↦ hne (hzu ▸ Sym2.eq_swap), hz⟩ · rintro ⟨hne, hz⟩ refine ⟨hz, fun heq ↦ ?_⟩ rw [Sym2.eq_iff] at heq rcases heq with ⟨h1, _⟩ | ⟨_, h2⟩ · exact he_adj.ne h1.symm · exact hne h2 have hu_mem : u ∈ H.neighborFinset w₀ := (SimpleGraph.mem_neighborFinset H w₀ u).mpr he_adj.symm rw [hss, Finset.card_erase_of_mem hu_mem] have hpos : 0 < (H.neighborFinset w₀).card := Finset.card_pos.mpr ⟨u, hu_mem⟩ omega have hd := hdeg w₀; omega -- Total missing colors across `X` is `≥ |X| + 1`, but each maps injectively into `X \ {w₀}` (size `|X| - 1`)! let M : V → Finset (Fin (d + 1)) := fun x ↦ Finset.univ.filter (fun c ↦ IsMissing P x c) have hsum_ge : X.card + 1 ≤ ∑ x ∈ X, (M x).card := by rw [← Finset.add_sum_erase _ _ hw₀X] have h1 : (X.erase w₀).card ≤ ∑ x ∈ X.erase w₀, (M x).card := by calc (X.erase w₀).card = ∑ _x ∈ X.erase w₀, 1 := by simp _ ≤ ∑ x ∈ X.erase w₀, (M x).card := Finset.sum_le_sum (fun x hx ↦ hmiss_x x (Finset.mem_of_mem_erase hx)) have h2 := Finset.card_erase_of_mem hw₀X have h3 : 1 ≤ X.card := Finset.card_pos.mpr ⟨w₀, hw₀X⟩ change 2 ≤ (M w₀).card at hmiss_w₀ omega have hdisj_M : Set.PairwiseDisjoint (X : Set V) M := by intro x hx y hy hxy show Disjoint (M x) (M y) rw [Finset.disjoint_left] intro c hcx hcy exact hxy (hX_disj x hx y hy c (Finset.mem_filter.mp hcx).2 (Finset.mem_filter.mp hcy).2) have hbiU_card : (X.biUnion M).card = ∑ x ∈ X, (M x).card := Finset.card_biUnion hdisj_M have hbiU_le : (X.biUnion M).card ≤ (X.erase w₀).card := by have hpick : ∀ c ∈ X.biUnion M, ∃ y ∈ X.erase w₀, P.col s(u, y) = some c := by intro c hc rw [Finset.mem_biUnion] at hc obtain ⟨x, hxX, hcx⟩ := hc obtain ⟨y, hyX, hyne, hyc⟩ := hX_app x hxX c (Finset.mem_filter.mp hcx).2 exact ⟨y, Finset.mem_erase.mpr ⟨hyne, hyX⟩, hyc⟩ choose f hfmem hfcol using hpick calc (X.biUnion M).card = ((X.biUnion M).attach.image (fun c ↦ f c.1 c.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ heq dsimp at heq have e1 := hfcol c₁ h₁; have e2 := hfcol c₂ h₂ rw [heq] at e1 exact Subtype.ext (Option.some.inj (e1.symm.trans e2)) _ ≤ (X.erase w₀).card := Finset.card_le_card (by intro y hy; rw [Finset.mem_image] at hy obtain ⟨c, _, rfl⟩ := hy; exact hfmem c.1 c.2) have hcard_er := Finset.card_erase_of_mem hw₀X omega /-- Corollary of Vizing's Theorem: if `Δ(H) ≤ a + b - 1` (with `1 ≤ a + b`), then `HasDecomp H a b`. -/ lemma hasDecomp_vizing {V : Type*} [Fintype V] (H : SimpleGraph V) (a b : ℕ) (hab : 1 ≤ a + b) (hdeg : ∀ v, H.degree v ≤ a + b - 1) : HasDecomp H a b := by have hcol := vizing_theorem H (a + b - 1) hdeg have hEq : a + b - 1 + 1 = a + b := by omega rw [hEq] at hcol exact hasDecomp_of_isEdgeColorable hcol /-- **Vizing's Adjacency Lemma (1965):** If `H` has `Δ(H) ≤ d`, `H` is NOT `d`-edge-colorable, `H.Adj u w₀`, and `H - s(u, w₀)` IS `d`-edge-colorable, then `u` has at least `d - H.degree w₀ + 1` neighbors `x ≠ w₀` of degree `d`. -/ theorem vizing_adjacency_lemma {V : Type*} [Fintype V] (H : SimpleGraph V) (d : ℕ) (hdeg : ∀ v, H.degree v ≤ d) (hnotcol : ¬IsEdgeColorable H d) (u w₀ : V) (huw₀ : H.Adj u w₀) (hcrit : IsEdgeColorable (H.deleteEdges {s(u, w₀)}) d) : d - H.degree w₀ + 1 ≤ (Finset.univ.filter (fun x : V ↦ H.Adj u x ∧ x ≠ w₀ ∧ H.degree x = d)).card := by let H' := H.deleteEdges {s(u, w₀)} have hH'_le : H' ≤ H := SimpleGraph.deleteEdges_le _ obtain ⟨P', hP'tot⟩ := hcrit let P : PartialEdgeColoring H d := { col := fun e' ↦ if e' = s(u, w₀) then none else P'.col e' supported := by intro x y c hc by_cases h0 : s(x, y) = s(u, w₀) · rw [if_pos h0] at hc; simp at hc · rw [if_neg h0] at hc; exact hH'_le (P'.supported x y c hc) proper := by intro x y₁ y₂ c h1 h2 by_cases h01 : s(x, y₁) = s(u, w₀) · rw [if_pos h01] at h1; simp at h1 · rw [if_neg h01] at h1 by_cases h02 : s(x, y₂) = s(u, w₀) · rw [if_pos h02] at h2; simp at h2 · rw [if_neg h02] at h2; exact P'.proper x y₁ y₂ c h1 h2 } have hcolored_le : ∀ v, (Finset.univ.filter (fun w ↦ (P.col s(v, w)).isSome)).card ≤ H'.degree v := by intro v; rw [← SimpleGraph.card_neighborFinset_eq_degree] refine Finset.card_le_card (fun w hw ↦ ?_) rw [Finset.mem_filter] at hw; rw [SimpleGraph.mem_neighborFinset] obtain ⟨c, hc⟩ := Option.isSome_iff_exists.mp hw.2 dsimp [P] at hc by_cases h0 : s(v, w) = s(u, w₀) · rw [if_pos h0] at hc; simp at hc · rw [if_neg h0] at hc; exact P'.supported v w c hc have hdeg_del : ∀ e a b, e = s(a, b) → H.Adj a b → (H.deleteEdges {e}).degree a + 1 = H.degree a := by intro e a b he hab simp only [← SimpleGraph.card_neighborFinset_eq_degree] have hss : (H.deleteEdges {e}).neighborFinset a = (H.neighborFinset a).erase b := by ext z; simp only [SimpleGraph.mem_neighborFinset, Finset.mem_erase, SimpleGraph.deleteEdges_adj, Set.mem_singleton_iff, he] constructor · rintro ⟨hz, hne⟩; exact ⟨fun hzb ↦ hne (hzb ▸ rfl), hz⟩ · rintro ⟨hne, hz⟩ refine ⟨hz, fun heq ↦ ?_⟩ rw [Sym2.eq_iff] at heq rcases heq with ⟨_, h2⟩ | ⟨h1, _⟩ · exact hne h2 · exact hab.ne h1 have hb_mem : b ∈ H.neighborFinset a := (SimpleGraph.mem_neighborFinset H a b).mpr hab rw [hss, Finset.card_erase_of_mem hb_mem] have hpos : 0 < (H.neighborFinset a).card := Finset.card_pos.mpr ⟨b, hb_mem⟩ omega have hH'_u : H'.degree u + 1 = H.degree u := hdeg_del s(u, w₀) u w₀ rfl huw₀ have hH'_w₀ : H'.degree w₀ + 1 = H.degree w₀ := hdeg_del s(u, w₀) w₀ u Sym2.eq_swap huw₀.symm have hmiss_u_pos : 0 < (Finset.univ.filter (fun c : Fin d ↦ IsMissing P u c)).card := by have := card_missing_ge P u; have := hcolored_le u; have := hdeg u; omega obtain ⟨α, hα⟩ := Finset.card_pos.mp hmiss_u_pos have hP_rest : ∀ x y, H.Adj x y → s(x, y) ≠ s(u, w₀) → (P.col s(x, y)).isSome := fun x y hxy hne ↦ by dsimp [P]; rw [if_neg hne] exact hP'tot x y (SimpleGraph.deleteEdges_adj.mpr ⟨hxy, by simpa using hne⟩) obtain ⟨hw₀X, hX_adj, _, hX_app, hX_disj⟩ := vizing_multifan_disjoint_missing hnotcol u w₀ huw₀ P (by simp [P]) hP_rest α (Finset.mem_filter.mp hα).2 set X := Finset.univ.filter (fun x ↦ ∃ F : List V, IsVizingFan P u F ∧ F.head? = some w₀ ∧ F.getLast? = some x) let M : V → Finset (Fin d) := fun x ↦ Finset.univ.filter (fun c ↦ IsMissing P x c) let X' := X.erase w₀ let X_lt := X'.filter (fun x ↦ H.degree x < d) let X_eq := X'.filter (fun x ↦ H.degree x = d) have hX'_split : X_lt.card + X_eq.card = X'.card := by rw [← Finset.card_union_of_disjoint] · congr 1; ext x; simp only [X_lt, X_eq, Finset.mem_union, Finset.mem_filter] constructor · rintro (⟨h, _⟩ | ⟨h, _⟩) <;> exact h · intro hx; have := hdeg x; by_cases hlt : H.degree x < d · exact Or.inl ⟨hx, hlt⟩ · exact Or.inr ⟨hx, by omega⟩ · rw [Finset.disjoint_left]; intro x h1 h2 have a1 := (Finset.mem_filter.mp h1).2; have a2 := (Finset.mem_filter.mp h2).2; omega have hmiss_w₀ : d - H.degree w₀ + 1 ≤ (M w₀).card := by dsimp only [M] have := card_missing_ge P w₀; have := hcolored_le w₀; have := hdeg w₀; omega have hmiss_lt : ∀ x ∈ X_lt, 1 ≤ (M x).card := by intro x hx dsimp only [M] have hlt := (Finset.mem_filter.mp hx).2 have := card_missing_ge P x; have := hcolored_le x have hle := SimpleGraph.degree_le_of_le (v := x) hH'_le omega have hdisj_M : Set.PairwiseDisjoint (X : Set V) M := by intro x hx y hy hxy show Disjoint (M x) (M y) rw [Finset.disjoint_left] intro c hcx hcy exact hxy (hX_disj x hx y hy c (Finset.mem_filter.mp hcx).2 (Finset.mem_filter.mp hcy).2) have hbiU_le : (X.biUnion M).card ≤ X'.card := by have hpick : ∀ c ∈ X.biUnion M, ∃ y ∈ X', P.col s(u, y) = some c := by intro c hc rw [Finset.mem_biUnion] at hc; obtain ⟨x, hxX, hcx⟩ := hc obtain ⟨y, hyX, hyne, hyc⟩ := hX_app x hxX c (Finset.mem_filter.mp hcx).2 exact ⟨y, Finset.mem_erase.mpr ⟨hyne, hyX⟩, hyc⟩ choose f hfmem hfcol using hpick calc (X.biUnion M).card = ((X.biUnion M).attach.image (fun c ↦ f c.1 c.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ heq dsimp at heq have e1 := hfcol c₁ h₁; have e2 := hfcol c₂ h₂ rw [heq] at e1 exact Subtype.ext (Option.some.inj (e1.symm.trans e2)) _ ≤ X'.card := Finset.card_le_card (by intro y hy; rw [Finset.mem_image] at hy obtain ⟨c, _, rfl⟩ := hy; exact hfmem c.1 c.2) have hsum_ge : (d - H.degree w₀ + 1) + X_lt.card ≤ (X.biUnion M).card := by rw [Finset.card_biUnion hdisj_M, ← Finset.add_sum_erase _ _ hw₀X] have hlt_sub : X_lt ⊆ X' := Finset.filter_subset _ _ have h1 : X_lt.card ≤ ∑ x ∈ X', (M x).card := by calc X_lt.card = ∑ _x ∈ X_lt, 1 := by simp _ ≤ ∑ x ∈ X_lt, (M x).card := Finset.sum_le_sum hmiss_lt _ ≤ ∑ x ∈ X', (M x).card := Finset.sum_le_sum_of_subset hlt_sub change X_lt.card ≤ ∑ x ∈ X.erase w₀, (M x).card at h1 omega have hXeq_sub : X_eq ⊆ Finset.univ.filter (fun x : V ↦ H.Adj u x ∧ x ≠ w₀ ∧ H.degree x = d) := by intro x hx rw [Finset.mem_filter] at hx ⊢ rcases hx with ⟨hx', hdx⟩ rw [Finset.mem_erase] at hx' exact ⟨Finset.mem_univ x, hX_adj x hx'.2, hx'.1, hdx⟩ have hle_target := Finset.card_le_card hXeq_sub omega /-- **Class-1 Edge-Count Threshold Theorem (via Vizing's Adjacency Lemma):** For every `d ≥ 2` and every finite simple graph `H` with `Δ(H) ≤ d` and `8 * H.edgeFinset.card < 3 * d ^ 2 + 6 * d - 1`, `H` is `d`-edge-colorable (Class 1)! -/ theorem class_one_of_lt_edges {V : Type*} [Fintype V] (H : SimpleGraph V) (d : ℕ) (hd2 : 2 ≤ d) (hdeg : ∀ v, H.degree v ≤ d) (hedge : 8 * H.edgeFinset.card < 3 * d ^ 2 + 6 * d - 1) : IsEdgeColorable H d := by by_contra hnotcol -- Pick a minimum-edge subgraph `H₀ ≤ H` that is NOT `d`-edge-colorable! have hex_bad : ∃ m : ℕ, ∃ H₀ : SimpleGraph V, H₀ ≤ H ∧ ¬IsEdgeColorable H₀ d ∧ H₀.edgeFinset.card = m := ⟨H.edgeFinset.card, H, le_rfl, hnotcol, rfl⟩ let m₀ := Nat.find hex_bad obtain ⟨H₀, hH₀le, hH₀not, hH₀card⟩ := Nat.find_spec hex_bad have hH₀deg : ∀ v, H₀.degree v ≤ d := fun v ↦ le_trans (SimpleGraph.degree_le_of_le hH₀le) (hdeg v) have hH₀edge_le : H₀.edgeFinset.card ≤ H.edgeFinset.card := Finset.card_le_card (fun e he ↦ by induction e using Sym2.ind with | _ x y => exact SimpleGraph.mem_edgeFinset.mpr (hH₀le (SimpleGraph.mem_edgeFinset.mp he))) -- Every edge of `H₀` is critical! have hcrit : ∀ x y, H₀.Adj x y → IsEdgeColorable (H₀.deleteEdges {s(x, y)}) d := by intro x y hxy by_contra hbad have hlt : (H₀.deleteEdges {s(x, y)}).edgeFinset.card < m₀ := by have hss : (H₀.deleteEdges {s(x, y)}).edgeFinset = H₀.edgeFinset.erase s(x, y) := by ext e' simp only [SimpleGraph.mem_edgeFinset, Finset.mem_erase, SimpleGraph.edgeSet_deleteEdges, Set.mem_sdiff, Set.mem_singleton_iff] tauto have hmem : s(x, y) ∈ H₀.edgeFinset := SimpleGraph.mem_edgeFinset.mpr (show s(x, y) ∈ H₀.edgeSet from hxy) rw [hss, Finset.card_erase_of_mem hmem] have hpos : 0 < H₀.edgeFinset.card := Finset.card_pos.mpr ⟨_, hmem⟩ omega exact Nat.find_min hex_bad (by convert hlt) ⟨H₀.deleteEdges {s(x, y)}, le_trans (SimpleGraph.deleteEdges_le _) hH₀le, hbad, rfl⟩ -- `H₀` has at least one edge (else empty graph is `d`-edge-colorable!) have hH₀_pos : 0 < H₀.edgeFinset.card := by by_contra h0 have hz : H₀.edgeFinset.card = 0 := by omega apply hH₀not refine ⟨⟨fun _ ↦ none, by simp, by simp⟩, fun a b hab ↦ ?_⟩ exact absurd (Finset.card_pos.mpr ⟨_, SimpleGraph.mem_edgeFinset.mpr (show s(a, b) ∈ H₀.edgeSet from hab)⟩) (by omega) -- Every non-isolated vertex of `H₀` has degree ≥ 2 (by Vizing's Adjacency Lemma or direct coloring!) have hmin_deg_ge2 : ∀ v, 0 < H₀.degree v → 2 ≤ H₀.degree v := by intro v hv by_contra hlt2 have hv1 : H₀.degree v = 1 := by omega rw [← SimpleGraph.card_neighborFinset_eq_degree] at hv obtain ⟨u, hu⟩ := Finset.card_pos.mp hv have huv : H₀.Adj v u := (SimpleGraph.mem_neighborFinset _ _ _).mp hu have hval := vizing_adjacency_lemma H₀ d hH₀deg hH₀not u v huv.symm (hcrit u v huv.symm) -- Wait: `hval` gives `d - 1 + 1 = d` neighbors of `u` BESIDES `v`! So `H₀.degree u ≥ d + 1 > d`, contradiction! have hle_u : (Finset.univ.filter (fun x : V ↦ H₀.Adj u x ∧ x ≠ v ∧ H₀.degree x = d)).card ≤ ((H₀.neighborFinset u).erase v).card := by refine Finset.card_le_card (fun x hx ↦ ?_) rw [Finset.mem_filter] at hx exact Finset.mem_erase.mpr ⟨hx.2.2.1, (SimpleGraph.mem_neighborFinset _ _ _).mpr hx.2.1⟩ have her := Finset.card_erase_of_mem ((SimpleGraph.mem_neighborFinset _ _ _).mpr huv.symm) have hdu := hH₀deg u have hdu_eq : (H₀.neighborFinset u).card = H₀.degree u := SimpleGraph.card_neighborFinset_eq_degree H₀ u omega -- Pick a non-isolated vertex `w₀` minimizing `H₀.degree w₀`! let active : Finset V := Finset.univ.filter (fun v ↦ 0 < H₀.degree v) have hactive_ne : active.Nonempty := by obtain ⟨e, he⟩ := Finset.card_pos.mp hH₀_pos induction e using Sym2.ind with | _ a b => refine ⟨a, Finset.mem_filter.mpr ⟨Finset.mem_univ a, ?_⟩⟩ rw [← SimpleGraph.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨b, (SimpleGraph.mem_neighborFinset _ _ _).mpr (SimpleGraph.mem_edgeFinset.mp he)⟩ obtain ⟨w₀, hw₀_act, hw₀_min⟩ := Finset.exists_min_image active (fun v ↦ H₀.degree v) hactive_ne let δ := H₀.degree w₀ have hδ_ge2 : 2 ≤ δ := hmin_deg_ge2 w₀ (Finset.mem_filter.mp hw₀_act).2 have hδ_le_d : δ ≤ d := hH₀deg w₀ -- Show `w₀` has a neighbor `u` with `H₀.degree u = d`! have hex_u : ∃ u, H₀.Adj w₀ u ∧ H₀.degree u = d := by have hpos_w : 0 < (H₀.neighborFinset w₀).card := by rw [SimpleGraph.card_neighborFinset_eq_degree]; exact (Finset.mem_filter.mp hw₀_act).2 obtain ⟨u₁, hu₁⟩ := Finset.card_pos.mp hpos_w have hwu₁ : H₀.Adj w₀ u₁ := (SimpleGraph.mem_neighborFinset _ _ _).mp hu₁ by_cases hdu₁ : H₀.degree u₁ = d · exact ⟨u₁, hwu₁, hdu₁⟩ · have hval := vizing_adjacency_lemma H₀ d hH₀deg hH₀not w₀ u₁ hwu₁ (hcrit w₀ u₁ hwu₁) have hdu₁_lt : H₀.degree u₁ < d := lt_of_le_of_ne (hH₀deg u₁) hdu₁ have hpos_f : 0 < (Finset.univ.filter (fun x : V ↦ H₀.Adj w₀ x ∧ x ≠ u₁ ∧ H₀.degree x = d)).card := by omega obtain ⟨u, hu⟩ := Finset.card_pos.mp hpos_f have hf := (Finset.mem_filter.mp hu).2 exact ⟨u, hf.1, hf.2.2⟩ obtain ⟨u, hwu, hdu⟩ := hex_u -- Apply Vizing's Adjacency Lemma to edge `(u, w₀)`: `u` has ≥ `d - δ + 1` neighbors of degree `d`! have hval_u := vizing_adjacency_lemma H₀ d hH₀deg hH₀not u w₀ hwu.symm (hcrit u w₀ hwu.symm) let D : Finset V := Finset.univ.filter (fun v ↦ H₀.degree v = d) have hD_card : d - δ + 2 ≤ D.card := by let S := Finset.univ.filter (fun x : V ↦ H₀.Adj u x ∧ x ≠ w₀ ∧ H₀.degree x = d) have hsub : insert u S ⊆ D := by intro x hx rw [Finset.mem_insert] at hx; rw [Finset.mem_filter] rcases hx with rfl | hx · exact ⟨Finset.mem_univ x, hdu⟩ · exact ⟨Finset.mem_univ x, (Finset.mem_filter.mp hx).2.2.2⟩ have hunot : u ∉ S := fun h ↦ H₀.loopless.irrefl u (Finset.mem_filter.mp h).2.1 have hc := Finset.card_le_card hsub rw [Finset.card_insert_of_notMem hunot] at hc change d - δ + 1 ≤ S.card at hval_u omega have hD_sub : D ⊆ active := fun v hv ↦ Finset.mem_filter.mpr ⟨Finset.mem_univ v, by rw [(Finset.mem_filter.mp hv).2]; omega⟩ have hactive_card : d + 1 ≤ active.card := by have hsub : insert u (H₀.neighborFinset u) ⊆ active := by intro x hx rw [Finset.mem_insert, SimpleGraph.mem_neighborFinset] at hx rw [Finset.mem_filter]; refine ⟨Finset.mem_univ x, ?_⟩ rcases hx with rfl | hux · omega · rw [← SimpleGraph.card_neighborFinset_eq_degree] exact Finset.card_pos.mpr ⟨u, (SimpleGraph.mem_neighborFinset _ _ _).mpr hux.symm⟩ have hunot : u ∉ H₀.neighborFinset u := by rw [SimpleGraph.mem_neighborFinset]; exact H₀.loopless.irrefl u calc d + 1 = H₀.degree u + 1 := by rw [hdu] _ = (H₀.neighborFinset u).card + 1 := by rw [SimpleGraph.card_neighborFinset_eq_degree] _ = (insert u (H₀.neighborFinset u)).card := (Finset.card_insert_of_notMem hunot).symm _ ≤ active.card := Finset.card_le_card hsub -- Handshaking lower bound on `2 * e(H₀)`! have hsum := H₀.sum_degrees_eq_twice_card_edges have hsum_lb : D.card * d + (active.card - D.card) * δ ≤ 2 * H₀.edgeFinset.card := by rw [← hsum] have h1 : ∑ v ∈ active, H₀.degree v ≤ ∑ v : V, H₀.degree v := Finset.sum_le_sum_of_subset (Finset.subset_univ active) have h2 : ∑ v ∈ active, H₀.degree v = ∑ v ∈ D, H₀.degree v + ∑ v ∈ active \ D, H₀.degree v := by rw [← Finset.sum_union Finset.disjoint_sdiff, Finset.union_sdiff_of_subset hD_sub] have h3 : ∑ v ∈ D, H₀.degree v = D.card * d := by rw [Finset.sum_congr rfl (fun v hv ↦ (Finset.mem_filter.mp hv).2), Finset.sum_const, smul_eq_mul] have h4 : (active \ D).card * δ ≤ ∑ v ∈ active \ D, H₀.degree v := by calc (active \ D).card * δ = ∑ _v ∈ active \ D, δ := by simp _ ≤ ∑ v ∈ active \ D, H₀.degree v := Finset.sum_le_sum (fun v hv ↦ hw₀_min v (Finset.mem_sdiff.mp hv).1) rw [Finset.card_sdiff_of_subset hD_sub] at h4 omega -- Since `D.card ≥ d - δ + 2`, `active.card ≥ d + 1`, and `δ ≤ d`, -- `D.card * d + (active.card - D.card) * δ ≥ (d - δ + 2) * d + (δ - 1) * δ`! have hquad : (d - δ + 2) * d + (δ - 1) * δ ≤ 2 * H₀.edgeFinset.card := by have hD_le_act : D.card ≤ active.card := Finset.card_le_card hD_sub have hcast : ((d : ℤ) - δ + 2) * d + ((δ : ℤ) - 1) * δ ≤ (D.card : ℤ) * d + ((active.card : ℤ) - D.card) * δ := by have hA : (d : ℤ) + 1 ≤ active.card := by exact_mod_cast hactive_card have hD : (d : ℤ) - δ + 2 ≤ D.card := by omega have hdd : (δ : ℤ) ≤ d := by exact_mod_cast hδ_le_d nlinarith have hcast2 : (D.card : ℤ) * d + ((active.card : ℤ) - D.card) * δ ≤ 2 * (H₀.edgeFinset.card : ℤ) := by have h1 : ((active.card - D.card : ℕ) : ℤ) = (active.card : ℤ) - D.card := Nat.cast_sub hD_le_act rw [← h1] exact_mod_cast hsum_lb have hsub1 : ((d - δ + 2 : ℕ) : ℤ) = (d : ℤ) - δ + 2 := by omega have hsub2 : ((δ - 1 : ℕ) : ℤ) = (δ : ℤ) - 1 := by omega have hfinal_z : ((d - δ + 2 : ℕ) : ℤ) * d + ((δ - 1 : ℕ) : ℤ) * δ ≤ 2 * (H₀.edgeFinset.card : ℤ) := by rw [hsub1, hsub2]; linarith exact_mod_cast hfinal_z -- Complete the square: `4 * ((d - δ + 2) * d + (δ - 1) * δ) = (2δ - d - 1)^2 + 3d^2 + 6d - 1`! have hsq : 3 * d ^ 2 + 6 * d - 1 ≤ 8 * H₀.edgeFinset.card := by have hz : (3 * (d : ℤ) ^ 2 + 6 * d - 1) ≤ 8 * (H₀.edgeFinset.card : ℤ) := by have hq : ((d : ℤ) - δ + 2) * d + ((δ : ℤ) - 1) * δ ≤ 2 * (H₀.edgeFinset.card : ℤ) := by have hsub1 : ((d - δ + 2 : ℕ) : ℤ) = (d : ℤ) - δ + 2 := by omega have hsub2 : ((δ - 1 : ℕ) : ℤ) = (δ : ℤ) - 1 := by omega rw [← hsub1, ← hsub2]; exact_mod_cast hquad nlinarith [sq_nonneg (2 * (δ : ℤ) - d - 1)] have hpow : ((d ^ 2 : ℕ) : ℤ) = (d : ℤ) ^ 2 := by push_cast; rfl have hpos : 1 ≤ 3 * d ^ 2 + 6 * d := by nlinarith omega omega /-- Corollary of Vizing's Adjacency Lemma: if `Δ(H) ≤ a + b`, `2 ≤ a + b`, and `8 * e(H) < 3 * (a + b)^2 + 6 * (a + b) - 1`, then `HasDecomp H a b` (ZERO parity restrictions!). -/ lemma hasDecomp_vizing_small_edges {V : Type*} [Fintype V] (H : SimpleGraph V) (a b : ℕ) (hab : 2 ≤ a + b) (hdeg : ∀ v, H.degree v ≤ a + b) (hedge : 8 * H.edgeFinset.card < 3 * (a + b) ^ 2 + 6 * (a + b) - 1) : HasDecomp H a b := hasDecomp_of_isEdgeColorable (class_one_of_lt_edges H (a + b) hab hdeg hedge) end DecompEngines /-! ## Section 5: Headline Erdős Problem #561 Theorems, New Infinite Families & Universal Lower Bound -/ section MainTheorems lemma le_sizeRamsey_starForest_of_forall_lt {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} {B : ℕ} (h : ∀ (N : ℕ) (F : SimpleGraph (Fin N)), F.edgeFinset.card < B → ∃ R : SimpleGraph (Fin N), R ≤ F ∧ ¬(starForest s n).IsContained R ∧ ¬(starForest t m).IsContained (F \ R)) : B ≤ sizeRamsey (starForest s n) (starForest t m) := by unfold sizeRamsey apply le_csInf ⟨erdos561Target s t n m, starForest_target_mem_arrowing hs ht n m⟩ rintro M ⟨N, F, hM, hArr⟩ by_contra hlt push Not at hlt have hcard : F.edgeFinset.card = M := by rw [← SimpleGraph.coe_edgeFinset, Set.ncard_coe_finset] at hM exact hM obtain ⟨R, hRle, hnotG, hnotH⟩ := h N F (by omega) rcases hArr R hRle with hG | hH · exact hnotG hG · exact hnotH hH lemma antiDiagMax_pos {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) {k : ℕ} (hk2 : 2 ≤ k) (hkst : k ≤ s + t) : 1 ≤ antiDiagMax s t n m k := by obtain ⟨i, j, _, hmax⟩ := exists_antiDiagMax_attained hs ht (n := n) (m := m) hk2 hkst have h1 := hn_pos i; have h2 := hm_pos j; omega lemma sum_range_antiDiagMax {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) (n : Fin s → ℕ) (m : Fin t → ℕ) : ∑ r ∈ Finset.range (s + t - 1), antiDiagMax s t n m (r + 2) = erdos561Target s t n m := by unfold erdos561Target refine Finset.sum_bij (fun r _ ↦ r + 2) (fun r hr ↦ by rw [Finset.mem_range] at hr; rw [Finset.mem_Icc]; omega) (fun _ _ _ _ h ↦ by omega) (fun k hk ↦ ⟨k - 2, Finset.mem_range.mpr (by rw [Finset.mem_Icc] at hk; omega), by rw [Finset.mem_Icc] at hk; omega⟩) (fun _ _ ↦ rfl) lemma sum_Ico_antiDiagMax {s t : ℕ} (n : Fin s → ℕ) (m : Fin t → ℕ) {r : ℕ} (hr : r < s + t - 1) : ∑ q ∈ Finset.Ico r (s + t - 1), antiDiagMax s t n m (q + 2) = tailSum s t n m (r + 2) := by unfold tailSum refine Finset.sum_bij (fun q _ ↦ q + 2) (fun q hq ↦ by rw [Finset.mem_Ico] at hq; rw [Finset.mem_Icc]; omega) (fun _ _ _ _ h ↦ by omega) (fun k hk ↦ ⟨k - 2, Finset.mem_Ico.mpr (by rw [Finset.mem_Icc] at hk; omega), by rw [Finset.mem_Icc] at hk; omega⟩) (fun _ _ ↦ rfl) /-- Unified 5-regime admissibility condition for anti-diagonal `k ∈ [2, s + t]`: some maximizer `(i, j)` of `l_k = n_i + m_j - 1` falls into ANY of: 1. Unit star on left (`n_i = 1`), 2. Unit star on right (`m_j = 1`), 3. Odd–odd stars (`Odd (n_i) ∧ Odd (m_j)` — NO edge-count bound required!), 4. Equal stars with diagonal Eulerian tail bound (`n_i = m_j ∧ T_k ≤ (n_i - 1) * (2 * n_i - 1)`), 5. Arbitrary parities and unequal stars with Vizing Adjacency Lemma tail bound (`2 ≤ l_k - 1 ∧ 8 * T_k ≤ 3 * (l_k - 1)^2 + 6 * (l_k - 1) - 1`). -/ def AdmissibleAntiDiag (s t : ℕ) (n : Fin s → ℕ) (m : Fin t → ℕ) (k : ℕ) : Prop := ∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ n i + m j - 1 = antiDiagMax s t n m k ∧ (n i = 1 ∨ m j = 1 ∨ (Odd (n i) ∧ Odd (m j)) ∨ (n i = m j ∧ tailSum s t n m k ≤ (n i - 1) * (2 * n i - 1)) ∨ (2 ≤ antiDiagMax s t n m k - 1 ∧ 8 * tailSum s t n m k ≤ 3 * (antiDiagMax s t n m k - 1) ^ 2 + 6 * (antiDiagMax s t n m k - 1) - 1)) lemma hasDecomp_of_admissibleAntiDiag {V : Type*} [Fintype V] {s t : ℕ} {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) {k : ℕ} (hadm : AdmissibleAntiDiag s t n m k) (H : SimpleGraph V) (hdeg : ∀ v, H.degree v < antiDiagMax s t n m k) (hedge : H.edgeFinset.card < tailSum s t n m k) : ∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ HasDecomp H (n i - 1) (m j - 1) := by obtain ⟨i, j, hij, hmax, hcond⟩ := hadm refine ⟨i, j, hij, ?_⟩ have hni := hn_pos i; have hmj := hm_pos j have hdeg_le : ∀ v, H.degree v ≤ (n i - 1) + (m j - 1) := fun v ↦ by have := hdeg v; omega rcases hcond with h1 | h2 | ⟨⟨p, hp⟩, ⟨q, hq⟩⟩ | ⟨heq, htail⟩ | ⟨hd2, htail⟩ · -- Branch 1: `n i = 1` have h0 : n i - 1 = 0 := by omega rw [h0] exact hasDecomp_zero_left H (m j - 1) (fun v ↦ by have := hdeg_le v; omega) · -- Branch 2: `m j = 1` have h0 : m j - 1 = 0 := by omega rw [h0] exact hasDecomp_zero_right H (n i - 1) (fun v ↦ by have := hdeg_le v; omega) · -- Branch 3: `Odd (n i) ∧ Odd (m j)` have hni_eq : n i - 1 = 2 * p := by omega have hmj_eq : m j - 1 = 2 * q := by omega rw [hni_eq, hmj_eq] exact hasDecomp_even_even H p q (fun v ↦ by have := hdeg_le v; omega) · -- Branch 4: `n i = m j` with diagonal Eulerian bound have hmeq : m j - 1 = n i - 1 := by omega rw [hmeq] refine hasDecomp_diag_of_lt_edges H (n i - 1) (fun v ↦ by have := hdeg_le v; omega) ?_ have h2 : 2 * (n i - 1) + 1 = 2 * n i - 1 := by omega rw [h2]; exact lt_of_lt_of_le hedge htail · -- Branch 5: Vizing's Adjacency Lemma Class-1 threshold have hsum_eq : (n i - 1) + (m j - 1) = antiDiagMax s t n m k - 1 := by omega refine hasDecomp_vizing_small_edges H (n i - 1) (m j - 1) (by omega) hdeg_le ?_ rw [hsum_eq]; omega /-- **Automatic Exactness of the Final Anti-Diagonal `k = s + t`:** For EVERY `s, t ≥ 1` and EVERY positive `n, m` (with ZERO parity or size restrictions!), the final anti-diagonal `k = s + t` is ALWAYS admissible! -/ lemma admissibleAntiDiag_last {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) : AdmissibleAntiDiag s t n m (s + t) := by let i : Fin s := ⟨s - 1, by omega⟩ let j : Fin t := ⟨t - 1, by omega⟩ have hij : (i.val + 1) + (j.val + 1) = s + t := by dsimp [i, j]; omega have hmax : n i + m j - 1 = antiDiagMax s t n m (s + t) := by apply le_antisymm · rw [← hij]; exact antiDiagMax_ge i j · obtain ⟨i', j', hij', hmax'⟩ := exists_antiDiagMax_attained hs ht (n := n) (m := m) (k := s + t) (by omega) le_rfl have hi_eq : i' = i := Fin.ext (by dsimp [i]; omega) have hj_eq : j' = j := Fin.ext (by dsimp [j]; omega) subst hi_eq; subst hj_eq; omega have htail_eq : tailSum s t n m (s + t) = antiDiagMax s t n m (s + t) := by unfold tailSum; simp refine ⟨i, j, hij, hmax, ?_⟩ have hni := hn_pos i; have hmj := hm_pos j by_cases h1 : n i = 1 · exact Or.inl h1 · by_cases h2 : m j = 1 · exact Or.inr (Or.inl h2) · let d := antiDiagMax s t n m (s + t) - 1 have hd_eq : d = (n i - 1) + (m j - 1) := by omega have hd_ge2 : 2 ≤ d := by omega by_cases hd2 : d = 2 · -- Only possible case: `n i = 2` and `m j = 2`! Diagonal Eulerian engine handles `3 ≤ 1 * 3`! have hni2 : n i = 2 := by omega have hmj2 : m j = 2 := by omega refine Or.inr (Or.inr (Or.inr (Or.inl ⟨by omega, ?_⟩))) rw [htail_eq, ← hmax, hni2, hmj2] · -- `d ≥ 3`: Vizing's Adjacency Lemma gives `8 * (d + 1) ≤ 3 * d^2 + 6 * d - 1`! refine Or.inr (Or.inr (Or.inr (Or.inr ⟨hd_ge2, ?_⟩))) rw [htail_eq] change 8 * antiDiagMax s t n m (s + t) ≤ 3 * d ^ 2 + 6 * d - 1 have hl : antiDiagMax s t n m (s + t) = d + 1 := by omega rw [hl] have hd3 : 3 ≤ d := by omega have hmul : 3 * d ^ 2 ≥ 9 * d := by nlinarith omega /-- **Headline Theorem 1 (`erdos_561_unified_exact`):** For ALL `s, t ≥ 1` and ALL antitone positive star-size sequences `n : Fin s → ℕ`, `m : Fin t → ℕ`, if every anti-diagonal `k ∈ [2, s + t]` satisfies `AdmissibleAntiDiag s t n m k`, then the exact Erdős Problem #561 formula holds: `sizeRamsey (starForest s n) (starForest t m) = ∑ k ∈ Finset.Icc 2 (s + t), l_k`. -/ theorem erdos_561_unified_exact {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) (hadm : ∀ k ∈ Finset.Icc 2 (s + t), AdmissibleAntiDiag s t n m k) : sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by apply le_antisymm (sizeRamsey_starForest_le hs ht n m) apply le_sizeRamsey_starForest_of_forall_lt hs ht intro N F hFcard let b : ℕ → ℕ := fun r ↦ antiDiagMax s t n m (r + 2) have hb_pos : ∀ r < s + t - 1, 1 ≤ b r := fun r hr ↦ antiDiagMax_pos hs ht hn_pos hm_pos (by omega) (by omega) have hsum_b : ∑ r ∈ Finset.range (s + t - 1), b r = erdos561Target s t n m := sum_range_antiDiagMax hs ht n m obtain ⟨r, hr, P, hPcard, hdeg, hedge⟩ := greedy_peeling_exists F (s + t - 1) b hb_pos (by omega) have htail_eq : ∑ q ∈ Finset.Ico r (s + t - 1), b q = tailSum s t n m (r + 2) := sum_Ico_antiDiagMax n m hr rw [htail_eq] at hedge have hk_mem : r + 2 ∈ Finset.Icc 2 (s + t) := Finset.mem_Icc.mpr ⟨by omega, by omega⟩ obtain ⟨i, j, hij, hdecomp⟩ := hasDecomp_of_admissibleAntiDiag hn_pos hm_pos (hadm (r + 2) hk_mem) (restrictOutside F P) hdeg hedge exact not_arrows_of_peeling_decomp hn_anti hm_anti hn_pos hm_pos F i j P (by omega) hdecomp /-- **Corollary 1 (`erdos_561_all_odd`):** Recovers Davoodi–Javadi–Kamranian–Raeisi (*Ars Math. Contemp.* 2025): when all star sizes `n_i` and `m_j` are odd, Erdős Problem #561 holds exactly with zero gap/size restrictions. -/ theorem erdos_561_all_odd {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_odd : ∀ i, Odd (n i)) (hm_odd : ∀ j, Odd (m j)) : sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by have hn_pos : ∀ i, 1 ≤ n i := fun i ↦ by rcases hn_odd i with ⟨p, hp⟩; omega have hm_pos : ∀ j, 1 ≤ m j := fun j ↦ by rcases hm_odd j with ⟨q, hq⟩; omega refine erdos_561_unified_exact hs ht hn_anti hm_anti hn_pos hm_pos (fun k hk ↦ ?_) rw [Finset.mem_Icc] at hk obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained hs ht hk.1 hk.2 exact ⟨i, j, hij, hmax, Or.inr (Or.inr (Or.inl ⟨hn_odd i, hm_odd j⟩))⟩ /-- **Corollary 2 (`erdos_561_unit_matching_left`):** For every `s, t ≥ 1` and every antitone positive `m : Fin t → ℕ`, the size Ramsey number of the matching `s K_2` (`n ≡ 1`) versus `F(t, m)` equals `erdos561Target s t n m`. -/ theorem erdos_561_unit_matching_left {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_one : ∀ i, n i = 1) (hm_anti : Antitone m) (hm_pos : ∀ j, 1 ≤ m j) : sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by have hn_anti : Antitone n := fun i₁ i₂ _ ↦ by rw [hn_one i₁, hn_one i₂] have hn_pos : ∀ i, 1 ≤ n i := fun i ↦ by rw [hn_one i] refine erdos_561_unified_exact hs ht hn_anti hm_anti hn_pos hm_pos (fun k hk ↦ ?_) rw [Finset.mem_Icc] at hk obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained hs ht hk.1 hk.2 exact ⟨i, j, hij, hmax, Or.inl (hn_one i)⟩ /-- **Corollary 3 (`erdos_561_odd_prefix_even_tail`):** For ANY `s, t ≥ 2` and antitone positive `n, m`: if every non-tail anti-diagonal `k ∈ [2, s + t - 2]` is attained by an odd–odd pair `(n_i, m_j)` and `6 ≤ l_{s+t-1}`, then Erdős Problem #561 holds EXACTLY (regardless of the parities or equality of the tail stars!). -/ theorem erdos_561_odd_prefix_even_tail {s t : ℕ} (hs : 2 ≤ s) (ht : 2 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) (hpref : ∀ k ∈ Finset.Icc 2 (s + t - 2), ∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ n i + m j - 1 = antiDiagMax s t n m k ∧ Odd (n i) ∧ Odd (m j)) (hpen : 6 ≤ antiDiagMax s t n m (s + t - 1)) : sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by refine erdos_561_unified_exact (by omega) (by omega) hn_anti hm_anti hn_pos hm_pos (fun k hk ↦ ?_) rw [Finset.mem_Icc] at hk by_cases hlast : k = s + t · subst hlast; exact admissibleAntiDiag_last (by omega) (by omega) hn_pos hm_pos · by_cases hpen_k : k = s + t - 1 · subst hpen_k obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained (by omega) (by omega) (n := n) (m := m) (k := s + t - 1) (by omega) (by omega) -- Antitonicity gives `l_{s+t} ≤ l_{s+t-1}`! have hl_le : antiDiagMax s t n m (s + t) ≤ antiDiagMax s t n m (s + t - 1) := by obtain ⟨il, jl, hiljl, hmaxl⟩ := exists_antiDiagMax_attained (by omega) (by omega) (n := n) (m := m) (k := s + t) (by omega) le_rfl have hil_eq : il.val = s - 1 := by omega have hjl_eq : jl.val = t - 1 := by omega let il' : Fin s := ⟨s - 2, by omega⟩ have hle_n : n il ≤ n il' := hn_anti (Fin.mk_le_mk.mpr (by omega)) have hge := antiDiagMax_ge (n := n) (m := m) il' jl have hidx : (il'.val + 1) + (jl.val + 1) = s + t - 1 := by dsimp [il']; omega rw [hidx] at hge omega have htail_pen : tailSum s t n m (s + t - 1) = antiDiagMax s t n m (s + t - 1) + antiDiagMax s t n m (s + t) := by unfold tailSum have hset : Finset.Icc (s + t - 1) (s + t) = {s + t - 1, s + t} := by ext q; simp only [Finset.mem_Icc, Finset.mem_insert, Finset.mem_singleton]; omega rw [hset, Finset.sum_pair (by omega)] refine ⟨i, j, hij, hmax, Or.inr (Or.inr (Or.inr (Or.inr ⟨by omega, ?_⟩)))⟩ let d := antiDiagMax s t n m (s + t - 1) - 1 change 8 * tailSum s t n m (s + t - 1) ≤ 3 * d ^ 2 + 6 * d - 1 have hd5 : 5 ≤ d := by omega have hTle : tailSum s t n m (s + t - 1) ≤ 2 * (d + 1) := by omega have hquad : 16 * (d + 1) + 1 ≤ 3 * d ^ 2 + 6 * d := by nlinarith omega · obtain ⟨i, j, hij, hmax, hoi, hoj⟩ := hpref k (Finset.mem_Icc.mpr ⟨hk.1, by omega⟩) exact ⟨i, j, hij, hmax, Or.inr (Or.inr (Or.inl ⟨hoi, hoj⟩))⟩ /-- **Corollary 4 (`erdos_561_explicit_new_family` — Brand-New 5-Parameter Infinite Family):** For ALL `s ≥ 3`, `t ≥ 3`, ALL `p ≥ 3`, and ALL `1 ≤ a ≤ 2p + 1`, `1 ≤ b ≤ 2p + 1` (in particular EVEN tail stars `a = 2r`, `b = 2r'`, or mixed parity!), the non-uniform mixed-parity star forests with `s - 1` odd stars of size `2p + 1` plus one tail star of size `a`, versus `t - 1` odd stars of size `2p + 1` plus one tail star of size `b`, satisfy Erdős Problem #561 EXACTLY! This 5-parameter infinite family is strictly outside BEFRS (1978, `s = 1` / uniform), Győri–Schelp (2002, large-gap), Davoodi–Javadi–Kamranian–Raeisi (2025, all-odd), Fu–Luo–Ni (2026, uniform), and Chunlin You (Oct 2026, `s = 2`). -/ theorem erdos_561_explicit_new_family {s t p a b : ℕ} (hs : 3 ≤ s) (ht : 3 ≤ t) (hp : 3 ≤ p) (ha1 : 1 ≤ a) (ha2 : a ≤ 2 * p + 1) (hb1 : 1 ≤ b) (hb2 : b ≤ 2 * p + 1) : let n : Fin s → ℕ := fun i ↦ if i.val + 1 < s then 2 * p + 1 else a let m : Fin t → ℕ := fun j ↦ if j.val + 1 < t then 2 * p + 1 else b sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by intro n m have hn_anti : Antitone n := by intro i₁ i₂ hle dsimp [n] split_ifs <;> omega have hm_anti : Antitone m := by intro j₁ j₂ hle dsimp [m] split_ifs <;> omega have hn_pos : ∀ i, 1 ≤ n i := fun i ↦ by dsimp [n]; split_ifs <;> omega have hm_pos : ∀ j, 1 ≤ m j := fun j ↦ by dsimp [m]; split_ifs <;> omega have hmax_le : ∀ (i : Fin s) (j : Fin t), n i + m j - 1 ≤ 4 * p + 1 := fun i j ↦ by dsimp [n, m]; split_ifs <;> omega refine erdos_561_odd_prefix_even_tail (by omega) (by omega) hn_anti hm_anti hn_pos hm_pos ?_ ?_ · intro k hk rw [Finset.mem_Icc] at hk -- Pick `(i, j)` with `i.val + 1 < s`, `j.val + 1 < t`, and `(i.val + 1) + (j.val + 1) = k`! have hex : ∃ (i : Fin s) (j : Fin t), i.val + 1 < s ∧ j.val + 1 < t ∧ (i.val + 1) + (j.val + 1) = k := by by_cases hks : k ≤ s · exact ⟨⟨k - 2, by omega⟩, ⟨0, by omega⟩, by dsimp; omega, by dsimp; omega, by dsimp; omega⟩ · exact ⟨⟨s - 2, by omega⟩, ⟨k - s, by omega⟩, by dsimp; omega, by dsimp; omega, by dsimp; omega⟩ obtain ⟨i, j, hi, hj, hij⟩ := hex have hni : n i = 2 * p + 1 := by dsimp [n]; rw [if_pos hi] have hmj : m j = 2 * p + 1 := by dsimp [m]; rw [if_pos hj] have hmax : n i + m j - 1 = antiDiagMax s t n m k := by apply le_antisymm · rw [← hij]; exact antiDiagMax_ge i j · obtain ⟨i', j', _, hmax'⟩ := exists_antiDiagMax_attained (by omega) (by omega) (n := n) (m := m) (k := k) (by omega) (by omega) have := hmax_le i' j' omega exact ⟨i, j, hij, hmax, ⟨p, hni⟩, ⟨p, hmj⟩⟩ · -- At `k = s + t - 1`, pair `i = ⟨s - 2, _⟩` (`n i = 2p + 1`) and `j = ⟨t - 1, _⟩` (`m j = b ≥ 1`) gives `≥ 2p + 1 ≥ 7 ≥ 6`! let i : Fin s := ⟨s - 2, by omega⟩ let j : Fin t := ⟨t - 1, by omega⟩ have hge := antiDiagMax_ge (n := n) (m := m) i j have hidx : (i.val + 1) + (j.val + 1) = s + t - 1 := by dsimp [i, j]; omega rw [hidx] at hge have hni : n i = 2 * p + 1 := by dsimp [n, i]; rw [if_pos (by omega)] have hmj : 1 ≤ m j := hm_pos j omega /-- **Corollary 5 (`erdos_561_dense_gap_family`):** For ALL `s, t ≥ 1` and ALL antitone positive `n, m` (arbitrary parities!), if every non-final anti-diagonal `k ∈ [2, s + t - 1]` without a unit-star or odd–odd maximizer satisfies `2 ≤ l_k - 1` and `8 * T_k ≤ 3 * (l_k - 1)^2 + 6 * (l_k - 1) - 1`, then Erdős Problem #561 holds EXACTLY! -/ theorem erdos_561_dense_gap_family {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) (hgap : ∀ k ∈ Finset.Icc 2 (s + t - 1), (∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ n i + m j - 1 = antiDiagMax s t n m k ∧ (n i = 1 ∨ m j = 1 ∨ (Odd (n i) ∧ Odd (m j)))) ∨ (2 ≤ antiDiagMax s t n m k - 1 ∧ 8 * tailSum s t n m k ≤ 3 * (antiDiagMax s t n m k - 1) ^ 2 + 6 * (antiDiagMax s t n m k - 1) - 1)) : sizeRamsey (starForest s n) (starForest t m) = erdos561Target s t n m := by refine erdos_561_unified_exact hs ht hn_anti hm_anti hn_pos hm_pos (fun k hk ↦ ?_) rw [Finset.mem_Icc] at hk by_cases hlast : k = s + t · subst hlast; exact admissibleAntiDiag_last hs ht hn_pos hm_pos · rcases hgap k (Finset.mem_Icc.mpr ⟨hk.1, by omega⟩) with ⟨i, j, hij, hmax, hc⟩ | hval · rcases hc with h1 | h2 | h3 · exact ⟨i, j, hij, hmax, Or.inl h1⟩ · exact ⟨i, j, hij, hmax, Or.inr (Or.inl h2)⟩ · exact ⟨i, j, hij, hmax, Or.inr (Or.inr (Or.inl h3))⟩ · obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained hs ht hk.1 hk.2 exact ⟨i, j, hij, hmax, Or.inr (Or.inr (Or.inr (Or.inr hval)))⟩ /-- Non-final anti-diagonals `k ∈ [2, s + t - 1]` that lack both a unit-star maximizer and an odd–odd maximizer. -/ noncomputable def nonDecompAntiDiags (s t : ℕ) (n : Fin s → ℕ) (m : Fin t → ℕ) : Finset ℕ := (Finset.Icc 2 (s + t - 1)).filter (fun k ↦ ¬∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = k ∧ n i + m j - 1 = antiDiagMax s t n m k ∧ (n i = 1 ∨ m j = 1 ∨ (Odd (n i) ∧ Odd (m j)))) /-- **Headline Theorem 2 (`erdos_561_universal_lower_bound`):** For **ALL** `s, t ≥ 1` and **ALL** antitone positive star-size sequences `n, m` (with ZERO restrictions on `s, t`, parities, or gaps!), the size Ramsey number satisfies `erdos561Target s t n m - (nonDecompAntiDiags s t n m).card ≤ sizeRamsey (starForest s n) (starForest t m)`. In particular, the final anti-diagonal `k = s + t` NEVER incurs even a 1-edge loss, and every unit-star or odd–odd anti-diagonal NEVER incurs any loss! -/ theorem erdos_561_universal_lower_bound {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) : erdos561Target s t n m - (nonDecompAntiDiags s t n m).card ≤ sizeRamsey (starForest s n) (starForest t m) := by apply le_sizeRamsey_starForest_of_forall_lt hs ht intro N F hFcard let B := nonDecompAntiDiags s t n m let b : ℕ → ℕ := fun r ↦ antiDiagMax s t n m (r + 2) - if r + 2 ∈ B then 1 else 0 have hb_pos : ∀ r < s + t - 1, 1 ≤ b r := by intro r hr dsimp [b] by_cases hmem : r + 2 ∈ B · rw [if_pos hmem] obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained hs ht (n := n) (m := m) (k := r + 2) (by omega) (by omega) have hnot := (Finset.mem_filter.mp hmem).2 have hni2 : 2 ≤ n i := by by_contra hlt; have h1 : n i = 1 := by have := hn_pos i; omega exact hnot ⟨i, j, hij, hmax, Or.inl h1⟩ have hmj2 : 2 ≤ m j := by by_contra hlt; have h1 : m j = 1 := by have := hm_pos j; omega exact hnot ⟨i, j, hij, hmax, Or.inr (Or.inl h1)⟩ omega · rw [if_neg hmem, Nat.sub_zero] exact antiDiagMax_pos hs ht hn_pos hm_pos (by omega) (by omega) have hsum_b : ∑ r ∈ Finset.range (s + t - 1), b r = erdos561Target s t n m - B.card := by have hadd : ∑ r ∈ Finset.range (s + t - 1), b r + ∑ r ∈ Finset.range (s + t - 1), (if r + 2 ∈ B then 1 else 0) = ∑ r ∈ Finset.range (s + t - 1), antiDiagMax s t n m (r + 2) := by rw [← Finset.sum_add_distrib] refine Finset.sum_congr rfl (fun r hr ↦ ?_) rw [Finset.mem_range] at hr have hpos := antiDiagMax_pos hs ht hn_pos hm_pos (k := r + 2) (by omega) (by omega) dsimp [b]; split_ifs <;> omega have hBcard : ∑ r ∈ Finset.range (s + t - 1), (if r + 2 ∈ B then 1 else 0) = B.card := by rw [← Finset.card_filter] refine Finset.card_bij (fun r _ ↦ r + 2) (fun r hr ↦ (Finset.mem_filter.mp hr).2) (fun _ _ _ _ h ↦ by omega) (fun k hk ↦ ?_) have hkIcc : k ∈ Finset.Icc 2 (s + t - 1) := (Finset.mem_filter.mp hk).1 rw [Finset.mem_Icc] at hkIcc exact ⟨k - 2, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (by omega), by have hk2 : k - 2 + 2 = k := by omega rwa [hk2]⟩, by omega⟩ rw [hBcard, sum_range_antiDiagMax hs ht n m] at hadd omega change F.edgeFinset.card < erdos561Target s t n m - B.card at hFcard obtain ⟨r, hr, P, hPcard, hdeg, hedge⟩ := greedy_peeling_exists F (s + t - 1) b hb_pos (by omega) by_cases hlast : r + 2 = s + t · -- Final anti-diagonal `k = s + t`: automatic exactness with zero loss! have hnotB : r + 2 ∉ B := by intro hmem have h1 := (Finset.mem_filter.mp hmem).1 rw [Finset.mem_Icc] at h1; omega have hbr_eq : b r = antiDiagMax s t n m (s + t) := by dsimp [b]; rw [if_neg hnotB, Nat.sub_zero, hlast] have hIco_eq : Finset.Ico r (s + t - 1) = {r} := by ext q; simp only [Finset.mem_Ico, Finset.mem_singleton]; omega rw [hIco_eq, Finset.sum_singleton, hbr_eq] at hedge have htail_last : tailSum s t n m (s + t) = antiDiagMax s t n m (s + t) := by unfold tailSum; simp have hdeg' : ∀ v, (restrictOutside F P).degree v < antiDiagMax s t n m (s + t) := by intro v; rw [← hbr_eq]; exact hdeg v obtain ⟨i, j, hij, hdecomp⟩ := hasDecomp_of_admissibleAntiDiag hn_pos hm_pos (admissibleAntiDiag_last hs ht hn_pos hm_pos) (restrictOutside F P) hdeg' (by omega) exact not_arrows_of_peeling_decomp hn_anti hm_anti hn_pos hm_pos F i j P (by omega) hdecomp · by_cases hmem : r + 2 ∈ B · -- Non-decomposable anti-diagonal: `Δ(H) < l_k - 1`, so Vizing's Theorem gives exact decomposition! obtain ⟨i, j, hij, hmax⟩ := exists_antiDiagMax_attained hs ht (n := n) (m := m) (k := r + 2) (by omega) (by omega) have hnot := (Finset.mem_filter.mp hmem).2 have hni2 : 2 ≤ n i := by by_contra hlt; have h1 : n i = 1 := by have := hn_pos i; omega exact hnot ⟨i, j, hij, hmax, Or.inl h1⟩ have hmj2 : 2 ≤ m j := by by_contra hlt; have h1 : m j = 1 := by have := hm_pos j; omega exact hnot ⟨i, j, hij, hmax, Or.inr (Or.inl h1)⟩ have hdeg_v : ∀ v, (restrictOutside F P).degree v ≤ (n i - 1) + (m j - 1) - 1 := by intro v have hv := hdeg v dsimp [b] at hv; rw [if_pos hmem] at hv omega have hdecomp : HasDecomp (restrictOutside F P) (n i - 1) (m j - 1) := hasDecomp_vizing (restrictOutside F P) (n i - 1) (m j - 1) (by omega) hdeg_v exact not_arrows_of_peeling_decomp hn_anti hm_anti hn_pos hm_pos F i j P (by omega) hdecomp · -- Unit-star or odd–odd anti-diagonal: Engines 1–2 give exact decomposition with NO edge bound! have hex : ∃ (i : Fin s) (j : Fin t), (i.val + 1) + (j.val + 1) = r + 2 ∧ n i + m j - 1 = antiDiagMax s t n m (r + 2) ∧ (n i = 1 ∨ m j = 1 ∨ (Odd (n i) ∧ Odd (m j))) := by by_contra hno exact hmem (Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨by omega, by omega⟩, hno⟩) obtain ⟨i, j, hij, hmax, hc⟩ := hex have hni := hn_pos i; have hmj := hm_pos j have hdeg_le : ∀ v, (restrictOutside F P).degree v ≤ (n i - 1) + (m j - 1) := by intro v have hv := hdeg v dsimp [b] at hv; rw [if_neg hmem, Nat.sub_zero] at hv omega have hdecomp : HasDecomp (restrictOutside F P) (n i - 1) (m j - 1) := by rcases hc with h1 | h2 | ⟨⟨p, hp⟩, ⟨q, hq⟩⟩ · have h0 : n i - 1 = 0 := by omega rw [h0] exact hasDecomp_zero_left _ (m j - 1) (fun v ↦ by have := hdeg_le v; omega) · have h0 : m j - 1 = 0 := by omega rw [h0] exact hasDecomp_zero_right _ (n i - 1) (fun v ↦ by have := hdeg_le v; omega) · have hni_eq : n i - 1 = 2 * p := by omega have hmj_eq : m j - 1 = 2 * q := by omega rw [hni_eq, hmj_eq] exact hasDecomp_even_even _ p q (fun v ↦ by have := hdeg_le v; omega) exact not_arrows_of_peeling_decomp hn_anti hm_anti hn_pos hm_pos F i j P (by omega) hdecomp /-- **Corollary 6 (`erdos_561_universal_gap_bound`):** For EVERY pair of antitone positive star forests `F(s, n)` and `F(t, m)` (`s, t ≥ 1`), the conjectured Erdős Problem #561 formula is sandwiched within at most `s + t - 2` edges: `L(n, m) - (s + t - 2) ≤ sizeRamsey (starForest s n) (starForest t m) ≤ L(n, m)`. -/ theorem erdos_561_universal_gap_bound {s t : ℕ} (hs : 1 ≤ s) (ht : 1 ≤ t) {n : Fin s → ℕ} {m : Fin t → ℕ} (hn_anti : Antitone n) (hm_anti : Antitone m) (hn_pos : ∀ i, 1 ≤ n i) (hm_pos : ∀ j, 1 ≤ m j) : erdos561Target s t n m - (s + t - 2) ≤ sizeRamsey (starForest s n) (starForest t m) ∧ sizeRamsey (starForest s n) (starForest t m) ≤ erdos561Target s t n m := by refine ⟨?_, sizeRamsey_starForest_le hs ht n m⟩ have hle : (nonDecompAntiDiags s t n m).card ≤ s + t - 2 := by calc (nonDecompAntiDiags s t n m).card ≤ (Finset.Icc 2 (s + t - 1)).card := Finset.card_le_card (Finset.filter_subset _ _) _ = s + t - 2 := by rw [Nat.card_Icc]; omega have hlb := erdos_561_universal_lower_bound hs ht hn_anti hm_anti hn_pos hm_pos omega end MainTheorems end StarForestSizeRamsey /-! ## Section 6: Axiom Audit -/ #print axioms StarForestSizeRamsey.sizeRamsey_starForest_le #print axioms StarForestSizeRamsey.konig_bipartite_edge_coloring #print axioms StarForestSizeRamsey.hasDecomp_even_even #print axioms StarForestSizeRamsey.exists_eulerian_circuit_component #print axioms StarForestSizeRamsey.hasDecomp_diag_of_lt_edges #print axioms StarForestSizeRamsey.vizing_theorem #print axioms StarForestSizeRamsey.vizing_adjacency_lemma #print axioms StarForestSizeRamsey.class_one_of_lt_edges #print axioms StarForestSizeRamsey.erdos_561_unified_exact #print axioms StarForestSizeRamsey.erdos_561_all_odd #print axioms StarForestSizeRamsey.erdos_561_unit_matching_left #print axioms StarForestSizeRamsey.erdos_561_odd_prefix_even_tail #print axioms StarForestSizeRamsey.erdos_561_explicit_new_family #print axioms StarForestSizeRamsey.erdos_561_dense_gap_family #print axioms StarForestSizeRamsey.erdos_561_universal_lower_bound #print axioms StarForestSizeRamsey.erdos_561_universal_gap_bound