import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Combinatorics.SimpleGraph.Acyclic 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.Order.Lattice.Nat import Mathlib.Data.Set.Card import Mathlib.Tactic /-! # Total Coloring Conjecture for `k`-Degenerate Graphs (`Δ ≥ 3k`) & Galvin's Theorem This file establishes a new linear-in-`k` threshold for the **Total Coloring Conjecture** (Behzad 1965, Vizing 1968) on `k`-degenerate simple graphs: > **Main Theorem (`total_coloring_conjecture_of_isDegenerate_ge_three_mul`):** > Every `k`-degenerate finite simple graph `G` with `Δ(G) ≥ 3k` satisfies > `χ''(G) ≤ Δ(G) + 2`. This reduces the 19-year-old threshold `Δ(G) ≥ 4k + 3` of Isobe–Zhou–Nishizeki (*Combinatorica* 27(2), 2007) for the Total Coloring Conjecture on `k`-degenerate graphs by `k + 3` for every `k ≥ 1` (cutting the linear slope from `4k` to `3k`). In particular, for **4-degenerate graphs** it establishes `χ''(G) ≤ Δ(G) + 2` for all `Δ(G) ≥ 12` (closing `Δ ∈ {12, 13, 14, 15, 16, 17, 18}` below Isobe–Zhou–Nishizeki's `Δ ≥ 19`), and for **5-degenerate graphs** it establishes `χ''(G) ≤ Δ(G) + 2` for all `Δ(G) ≥ 15` (vs. `Δ ≥ 23`). The proof introduces a new **Bipartite Degree-Reduction Decomposition Lemma** (`exists_bipartite_subgraph_degree_split`): every `k`-degenerate graph with `Δ(G) ≥ 3k - 1` contains a bipartite spanning subgraph `F ≤ G` with `Δ(F) ≤ k` and `Δ(G \ F) ≤ Δ(G) - k`. Combining this with a complete, self-contained formalization of **Galvin's Theorem (1995)** (`galvin_bipartite_list_edge_coloring`, proved via König's Edge Coloring Theorem, Gale–Shapley stable matchings, and the Bondy–Boppana–Siegel Kernel Lemma) on `F`, and **Vizing's Degeneracy Class-1 Theorem** (`class_one_of_degenerate`) on `G \ F`, yields a `(Δ + 2)`-total coloring. All total coloring definitions (`SimpleGraph.IsTotalColoring`, `SimpleGraph.TotalColorable`, `SimpleGraph.totalChromaticNumber`) match `FormalConjecturesForMathlib/Combinatorics/SimpleGraph/TotalColouring.lean` and `FormalConjectures/Wikipedia/TotalColoringConjecture.lean` verbatim. -/ /-! ## Section 1: Verbatim Total Coloring Definitions -/ namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) /-- A function `c` on the vertices and edges of `G` (an element of `V ⊕ G.edgeSet`) is a **total colouring** if adjacent vertices, incident (distinct) edges, and each vertex together with its incident edges receive different colours. (Verbatim from `FormalConjecturesForMathlib/Combinatorics/SimpleGraph/TotalColouring.lean`.) -/ def IsTotalColoring {ι : Type*} (c : V ⊕ G.edgeSet → ι) : Prop := (∀ u v, G.Adj u v → c (Sum.inl u) ≠ c (Sum.inl v)) ∧ (∀ e f : G.edgeSet, e ≠ f → (∃ v, v ∈ (e : Sym2 V) ∧ v ∈ (f : Sym2 V)) → c (Sum.inr e) ≠ c (Sum.inr f)) ∧ (∀ (v : V) (e : G.edgeSet), v ∈ (e : Sym2 V) → c (Sum.inl v) ≠ c (Sum.inr e)) /-- `G` is **totally `n`-colourable** if it has a total colouring with `n` colours. (Verbatim from `FormalConjecturesForMathlib/Combinatorics/SimpleGraph/TotalColouring.lean`.) -/ def TotalColorable (n : ℕ) : Prop := ∃ c : V ⊕ G.edgeSet → Fin n, G.IsTotalColoring c /-- The **total chromatic number** `χ''(G)`: the least number of colours in a total colouring. (Verbatim from `FormalConjecturesForMathlib/Combinatorics/SimpleGraph/TotalColouring.lean`.) -/ noncomputable def totalChromaticNumber : ℕ := sInf {n | G.TotalColorable n} end SimpleGraph namespace DegenerateTotalColoring open SimpleGraph Finset open scoped Classical /-! ## Section 2: Degeneracy API & Vertex Coloring -/ /-- A finite simple graph `G` is **`k`-degenerate** if every nonempty vertex subset `S` contains a vertex with at most `k` neighbors inside `S`. -/ def IsDegenerate {V : Type*} (G : SimpleGraph V) (k : ℕ) : Prop := ∀ S : Finset V, S.Nonempty → ∃ v ∈ S, (S.filter (fun w ↦ G.Adj v w)).card ≤ k lemma IsDegenerate.of_le {V : Type*} {G H : SimpleGraph V} {k : ℕ} (hG : IsDegenerate G k) (hHG : H ≤ G) : IsDegenerate H k := by intro S hS obtain ⟨v, hvS, hvdeg⟩ := hG S hS refine ⟨v, hvS, le_trans (Finset.card_le_card (fun w hw ↦ ?_)) hvdeg⟩ rw [Finset.mem_filter] at hw ⊢ exact ⟨hw.1, hHG hw.2⟩ lemma IsDegenerate.mono {V : Type*} {G : SimpleGraph V} {k₁ k₂ : ℕ} (hG : IsDegenerate G k₁) (hle : k₁ ≤ k₂) : IsDegenerate G k₂ := by intro S hS obtain ⟨v, hvS, hvdeg⟩ := hG S hS exact ⟨v, hvS, le_trans hvdeg hle⟩ /-- **Degeneracy Ordering Lemma:** Every `k`-degenerate finite simple graph admits an injective vertex ranking `π : V → ℕ` into `{0, …, |V|-1}` such that every vertex `u` has at most `k` neighbors of smaller rank. -/ lemma exists_degeneracy_ordering_lt {V : Type*} [Fintype V] {G : SimpleGraph V} {k : ℕ} (hG : IsDegenerate G k) : ∃ π : V → ℕ, (∀ u, π u < Fintype.card V) ∧ Function.Injective π ∧ ∀ u : V, (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u)).card ≤ k := by suffices h : ∀ n (S : Finset V), S.card = n → ∃ π : V → ℕ, (∀ x ∈ S, π x < n) ∧ (∀ x ∈ S, ∀ y ∈ S, π x = π y → x = y) ∧ (∀ u ∈ S, (S.filter (fun v ↦ G.Adj u v ∧ π v < π u)).card ≤ k) by obtain ⟨π, hlt, hinj, hdeg⟩ := h (Fintype.card V) Finset.univ Finset.card_univ exact ⟨π, fun u ↦ hlt u (Finset.mem_univ u), fun x y hxy ↦ hinj x (Finset.mem_univ x) y (Finset.mem_univ y) hxy, fun u ↦ hdeg u (Finset.mem_univ u)⟩ intro n induction n with | zero => intro S hS have hE : S = ∅ := Finset.card_eq_zero.mp hS subst hE exact ⟨fun _ ↦ 0, by simp, by simp, by simp⟩ | succ n ih => intro S hS have hne : S.Nonempty := Finset.card_pos.mp (by omega) obtain ⟨v₀, hv₀S, hv₀deg⟩ := hG S hne let S' := S.erase v₀ have hS'card : S'.card = n := by rw [Finset.card_erase_of_mem hv₀S]; omega obtain ⟨π', hlt', hinj', hdeg'⟩ := ih S' hS'card let π : V → ℕ := fun x ↦ if x = v₀ then n else π' x refine ⟨π, ?_, ?_, ?_⟩ · intro x hx dsimp [π] by_cases hx0 : x = v₀ · rw [if_pos hx0]; omega · rw [if_neg hx0] have := hlt' x (Finset.mem_erase.mpr ⟨hx0, hx⟩) omega · intro x hx y hy hEq dsimp [π] at hEq by_cases hx0 : x = v₀ <;> by_cases hy0 : y = v₀ · exact hx0.trans hy0.symm · rw [if_pos hx0, if_neg hy0] at hEq have := hlt' y (Finset.mem_erase.mpr ⟨hy0, hy⟩); omega · rw [if_neg hx0, if_pos hy0] at hEq have := hlt' x (Finset.mem_erase.mpr ⟨hx0, hx⟩); omega · rw [if_neg hx0, if_neg hy0] at hEq exact hinj' x (Finset.mem_erase.mpr ⟨hx0, hx⟩) y (Finset.mem_erase.mpr ⟨hy0, hy⟩) hEq · intro u hu by_cases hu0 : u = v₀ · subst hu0 refine le_trans (Finset.card_le_card (fun w hw ↦ ?_)) hv₀deg rw [Finset.mem_filter] at hw ⊢ exact ⟨hw.1, hw.2.1⟩ · have huS' : u ∈ S' := Finset.mem_erase.mpr ⟨hu0, hu⟩ have hsub : S.filter (fun v ↦ G.Adj u v ∧ π v < π u) ⊆ S'.filter (fun v ↦ G.Adj u v ∧ π' v < π' u) := by intro w hw rw [Finset.mem_filter] at hw ⊢ rcases hw with ⟨hwS, huw, hlt⟩ have hw0 : w ≠ v₀ := by intro hweq; subst hweq dsimp [π] at hlt rw [if_pos rfl, if_neg hu0] at hlt have := hlt' u huS'; omega dsimp [π] at hlt rw [if_neg hw0, if_neg hu0] at hlt exact ⟨Finset.mem_erase.mpr ⟨hw0, hwS⟩, huw, hlt⟩ exact le_trans (Finset.card_le_card hsub) (hdeg' u huS') /-- **Forward Degeneracy Ordering:** Reversing `exists_degeneracy_ordering_lt` gives a bijection `π : V → ℕ` onto `{0, …, |V|-1}` where every vertex `u` has at most `k` *forward* neighbors `v` with `π u < π v`. -/ lemma exists_forward_degeneracy_ordering {V : Type*} [Fintype V] {G : SimpleGraph V} {k : ℕ} (hG : IsDegenerate G k) : ∃ π : V → ℕ, (∀ u, π u < Fintype.card V) ∧ Function.Injective π ∧ ∀ u : V, (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π u < π v)).card ≤ k := by obtain ⟨π₀, hlt₀, hinj₀, hdeg₀⟩ := exists_degeneracy_ordering_lt hG let N := Fintype.card V let π : V → ℕ := fun u ↦ N - 1 - π₀ u refine ⟨π, ?_, ?_, ?_⟩ · intro u; have := hlt₀ u; dsimp [π]; omega · intro u v huv have hu := hlt₀ u; have hv := hlt₀ v dsimp [π] at huv exact hinj₀ (by omega) · intro u refine le_trans (Finset.card_le_card (fun v hv ↦ ?_)) (hdeg₀ u) rw [Finset.mem_filter] at hv ⊢ have hu := hlt₀ u; have hv' := hlt₀ v dsimp [π] at hv exact ⟨Finset.mem_univ v, hv.2.1, by omega⟩ /-- Every `k`-degenerate finite simple graph admits a proper `(k + 1)`-vertex coloring. -/ theorem exists_vertex_coloring_of_isDegenerate {V : Type*} [Fintype V] {G : SimpleGraph V} {k : ℕ} (hG : IsDegenerate G k) : ∃ c : V → Fin (k + 1), ∀ u v, G.Adj u v → c u ≠ c v := by suffices h : ∀ n (S : Finset V), S.card = n → ∃ c : V → Fin (k + 1), ∀ u ∈ S, ∀ v ∈ S, G.Adj u v → c u ≠ c v by obtain ⟨c, hc⟩ := h (Fintype.card V) Finset.univ Finset.card_univ exact ⟨c, fun u v huv ↦ hc u (Finset.mem_univ u) v (Finset.mem_univ v) huv⟩ intro n induction n with | zero => intro S hS have hE : S = ∅ := Finset.card_eq_zero.mp hS subst hE exact ⟨fun _ ↦ ⟨0, by omega⟩, by simp⟩ | succ n ih => intro S hS have hne : S.Nonempty := Finset.card_pos.mp (by omega) obtain ⟨v₀, hv₀S, hv₀deg⟩ := hG S hne let S' := S.erase v₀ have hS'card : S'.card = n := by rw [Finset.card_erase_of_mem hv₀S]; omega obtain ⟨c', hc'⟩ := ih S' hS'card let nb := S.filter (fun w ↦ G.Adj v₀ w) let used : Finset (Fin (k + 1)) := nb.image c' have hused_le : used.card ≤ k := le_trans Finset.card_image_le hv₀deg have hfree : (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 ⟨col₀, hcol₀⟩ := hfree rw [Finset.mem_sdiff] at hcol₀ let c : V → Fin (k + 1) := fun x ↦ if x = v₀ then col₀ else c' x refine ⟨c, fun u hu v hv huv ↦ ?_⟩ dsimp [c] by_cases hu0 : u = v₀ <;> by_cases hv0 : v = v₀ · exact absurd (hu0.trans hv0.symm ▸ huv) (G.loopless.irrefl u) · rw [if_pos hu0, if_neg hv0] intro hEq apply hcol₀.2 rw [Finset.mem_image] exact ⟨v, Finset.mem_filter.mpr ⟨hv, hu0 ▸ huv⟩, hEq.symm⟩ · rw [if_neg hu0, if_pos hv0] intro hEq apply hcol₀.2 rw [Finset.mem_image] exact ⟨u, Finset.mem_filter.mpr ⟨hu, (hv0 ▸ huv).symm⟩, hEq⟩ · rw [if_neg hu0, if_neg hv0] exact hc' u (Finset.mem_erase.mpr ⟨hu0, hu⟩) v (Finset.mem_erase.mpr ⟨hv0, hv⟩) huv /-- Every finite acyclic graph (forest) is `1`-degenerate. -/ lemma isDegenerate_of_isAcyclic {V : Type*} [Fintype V] {G : SimpleGraph V} (hacyc : G.IsAcyclic) : IsDegenerate G 1 := by intro S hS obtain ⟨v₀, hv₀S⟩ := hS let GS : SimpleGraph S := G.induce (S : Set V) let C : Finset S := Finset.univ.filter (fun x : S ↦ GS.Reachable ⟨v₀, hv₀S⟩ x) have hv₀C : ⟨v₀, hv₀S⟩ ∈ C := Finset.mem_filter.mpr ⟨Finset.mem_univ _, SimpleGraph.Reachable.refl _⟩ let T : SimpleGraph C := GS.induce (C : Set S) have hlift : ∀ {a b : S} (w : GS.Walk a b) (ha : a ∈ C), ∃ hb : b ∈ C, T.Reachable ⟨a, ha⟩ ⟨b, hb⟩ := by intro a b w induction w with | nil => intro ha; exact ⟨ha, SimpleGraph.Reachable.refl _⟩ | @cons x y z hxy w' ih => intro hx have hy : y ∈ C := Finset.mem_filter.mpr ⟨Finset.mem_univ y, (Finset.mem_filter.mp hx).2.trans hxy.reachable⟩ obtain ⟨hz, hrz⟩ := ih hy exact ⟨hz, (show T.Adj ⟨x, hx⟩ ⟨y, hy⟩ from hxy).reachable.trans hrz⟩ have hT_conn : T.Connected := by have : Nonempty C := ⟨⟨⟨v₀, hv₀S⟩, hv₀C⟩⟩ refine SimpleGraph.Connected.mk (fun a b ↦ ?_) have hto : ∀ x : C, T.Reachable ⟨⟨v₀, hv₀S⟩, hv₀C⟩ x := by intro ⟨x, hxC⟩ obtain ⟨w⟩ := (Finset.mem_filter.mp hxC).2 obtain ⟨_, hr⟩ := hlift w hv₀C exact hr exact (hto a).symm.trans (hto b) have hT_acyc : T.IsAcyclic := by let f : T ↪g G := { toFun := fun x ↦ x.1.1 inj' := fun x y h ↦ Subtype.ext (Subtype.ext h) map_rel_iff' := Iff.rfl } intro x p hp exact hacyc (p.map f.toHom) (hp.map f.injective) have hT_tree : T.IsTree := ⟨hT_conn, hT_acyc⟩ have hedge : T.edgeFinset.card + 1 = Fintype.card C := hT_tree.card_edgeFinset have hsum : ∑ x : C, T.degree x = 2 * T.edgeFinset.card := T.sum_degrees_eq_twice_card_edges have hex : ∃ x : C, T.degree x ≤ 1 := by by_contra hall push Not at hall have hge : ∑ _x : C, 2 ≤ ∑ x : C, T.degree x := Finset.sum_le_sum (fun x _ ↦ by have := hall x; omega) simp only [Finset.sum_const, Finset.card_univ, smul_eq_mul] at hge omega obtain ⟨x, hx_deg⟩ := hex refine ⟨x.1.1, x.1.2, ?_⟩ have hle : (S.filter (fun w ↦ G.Adj x.1.1 w)).card ≤ (T.neighborFinset x).card := by have hpick : ∀ w ∈ S.filter (fun w ↦ G.Adj x.1.1 w), ∃ y ∈ T.neighborFinset x, y.1.1 = w := by intro w hw rw [Finset.mem_filter] at hw have hwC : ⟨w, hw.1⟩ ∈ C := Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp x.2).2.trans (show GS.Adj x.1 ⟨w, hw.1⟩ from hw.2).reachable⟩ exact ⟨⟨⟨w, hw.1⟩, hwC⟩, (SimpleGraph.mem_neighborFinset _ _ _).mpr hw.2, rfl⟩ choose g hgmem hgeq using hpick calc (S.filter (fun w ↦ G.Adj x.1.1 w)).card = ((S.filter (fun w ↦ G.Adj x.1.1 w)).attach.image (fun w ↦ g w.1 w.2)).card := by rw [Finset.card_image_of_injective] · simp · intro ⟨w₁, h₁⟩ ⟨w₂, h₂⟩ hEq dsimp at hEq have e1 := hgeq w₁ h₁; have e2 := hgeq w₂ h₂ rw [hEq] at e1 exact Subtype.ext (e1.symm.trans e2) _ ≤ (T.neighborFinset x).card := Finset.card_le_card (by intro y hy; rw [Finset.mem_image] at hy obtain ⟨w, _, rfl⟩ := hy; exact hgmem w.1 w.2) rw [SimpleGraph.card_neighborFinset_eq_degree] at hle omega /-! ## Section 3: Vizing's Theorem, Vizing's Adjacency Lemma & Class-1 Thresholds -/ section VizingEngine /-- 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 /-- 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 /-- 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 /-- **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 /-- **Vizing's Degeneracy Class-1 Theorem (Vizing 1965):** Every `d`-degenerate finite simple graph `H` with `Δ(H) ≤ r` and `2 * d ≤ r` is `r`-edge-colorable (Class 1). Proved directly from `vizing_adjacency_lemma`. -/ theorem class_one_of_degenerate {V : Type*} [Fintype V] (H : SimpleGraph V) (d r : ℕ) (hdeg_en : IsDegenerate H d) (hr : 2 * d ≤ r) (hdeg : ∀ v, H.degree v ≤ r) : IsEdgeColorable H r := by by_contra hnotcol have hex_bad : ∃ m : ℕ, ∃ H₀ : SimpleGraph V, H₀ ≤ H ∧ ¬IsEdgeColorable H₀ r ∧ 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 ≤ r := fun v ↦ le_trans (SimpleGraph.degree_le_of_le hH₀le) (hdeg v) have hH₀degen : IsDegenerate H₀ d := hdeg_en.of_le hH₀le have hcrit : ∀ x y, H₀.Adj x y → IsEdgeColorable (H₀.deleteEdges {s(x, y)}) r := 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⟩ 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) obtain ⟨e, he⟩ := Finset.card_pos.mp hH₀_pos induction e using Sym2.ind with | _ a b => have hab : H₀.Adj a b := SimpleGraph.mem_edgeFinset.mp he by_cases hd0 : d = 0 · subst hd0 obtain ⟨v, hv, hv0⟩ := hH₀degen {a, b} ⟨a, Finset.mem_insert_self a {b}⟩ rw [Finset.mem_insert, Finset.mem_singleton] at hv rcases hv with hva | hvb · have hmem : b ∈ ({a, b} : Finset V).filter (fun w ↦ H₀.Adj v w) := Finset.mem_filter.mpr ⟨Finset.mem_insert_of_mem (Finset.mem_singleton_self b), hva ▸ hab⟩ have hpos := Finset.card_pos.mpr ⟨b, hmem⟩ omega · have hmem : a ∈ ({a, b} : Finset V).filter (fun w ↦ H₀.Adj v w) := Finset.mem_filter.mpr ⟨Finset.mem_insert_self a {b}, hvb ▸ hab.symm⟩ have hpos := Finset.card_pos.mpr ⟨a, hmem⟩ omega · have hd1 : 1 ≤ d := by omega have hval_ab := vizing_adjacency_lemma H₀ r hH₀deg hH₀not a b hab (hcrit a b hab) have hdb := hH₀deg b have hpos_r : 0 < (Finset.univ.filter (fun x : V ↦ H₀.Adj a x ∧ x ≠ b ∧ H₀.degree x = r)).card := by omega obtain ⟨z, hz⟩ := Finset.card_pos.mp hpos_r have hdz : H₀.degree z = r := (Finset.mem_filter.mp hz).2.2.2 let B : Finset V := Finset.univ.filter (fun v ↦ d + 1 ≤ H₀.degree v) have hBne : B.Nonempty := ⟨z, Finset.mem_filter.mpr ⟨Finset.mem_univ z, by omega⟩⟩ obtain ⟨v, hvB, hv_inB⟩ := hH₀degen B hBne have hdv : d + 1 ≤ H₀.degree v := (Finset.mem_filter.mp hvB).2 have hv_nb_card : d + 1 ≤ (H₀.neighborFinset v).card := by rw [SimpleGraph.card_neighborFinset_eq_degree]; exact hdv have hsub_eq : (H₀.neighborFinset v ∩ B).card ≤ d := by refine le_trans (Finset.card_le_card (fun x hx ↦ ?_)) hv_inB rw [Finset.mem_inter, SimpleGraph.mem_neighborFinset] at hx exact Finset.mem_filter.mpr ⟨hx.2, hx.1⟩ have hex_out : ∃ w ∈ H₀.neighborFinset v, w ∉ B := by by_contra hall push Not at hall have hsub : H₀.neighborFinset v ⊆ H₀.neighborFinset v ∩ B := fun w hw ↦ Finset.mem_inter.mpr ⟨hw, hall w hw⟩ have := Finset.card_le_card hsub omega obtain ⟨w, hvw_mem, hw_notB⟩ := hex_out have hvw : H₀.Adj v w := (SimpleGraph.mem_neighborFinset _ _ _).mp hvw_mem have hdw : H₀.degree w ≤ d := by by_contra hgt; push Not at hgt exact hw_notB (Finset.mem_filter.mpr ⟨Finset.mem_univ w, by omega⟩) have hval_vw := vizing_adjacency_lemma H₀ r hH₀deg hH₀not v w hvw (hcrit v w hvw) have hle_B : (Finset.univ.filter (fun x : V ↦ H₀.Adj v x ∧ x ≠ w ∧ H₀.degree x = r)).card ≤ (B.filter (fun x ↦ H₀.Adj v x)).card := by refine Finset.card_le_card (fun x hx ↦ ?_) rw [Finset.mem_filter] at hx ⊢ refine ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ x, by omega⟩, hx.2.1⟩ omega end VizingEngine /-! ## Section 4: König's Bipartite Edge Coloring Theorem -/ section KonigEngine /-- **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 end KonigEngine /-! ## Section 5: Galvin's Theorem (1995) via Kernel Lemma & Gale–Shapley Stable Matchings -/ section GalvinEngine /-- **Bondy–Boppana–Siegel Kernel Lemma:** If every subset `S` of a finite digraph `(U, D)` has a kernel `K ⊆ S` (independent and absorbing), and every vertex `u` has a list `L u` of size strictly larger than its out-degree in `D`, then `U` admits a proper list coloring from `L`. -/ theorem exists_list_coloring_of_kernel_perfect {U α : Type*} [Fintype U] (D : U → U → Prop) (hker : ∀ S : Finset U, ∃ K : Finset U, K ⊆ S ∧ (∀ u ∈ K, ∀ v ∈ K, ¬D u v) ∧ (∀ u ∈ S, u ∉ K → ∃ v ∈ K, D u v)) (L : U → Finset α) (hL : ∀ u : U, (Finset.univ.filter (fun v ↦ D u v)).card < (L u).card) : ∃ c : U → α, (∀ u, c u ∈ L u) ∧ (∀ u v, D u v → c u ≠ c v) := by suffices hopt : ∀ m (A : Finset U) (L : U → Finset α), A.card ≤ m → (∀ u ∈ A, (A.filter (fun v ↦ D u v)).card < (L u).card) → ∃ c : U → Option α, (∀ u ∈ A, ∃ a ∈ L u, c u = some a) ∧ (∀ u ∈ A, ∀ v ∈ A, D u v → c u ≠ c v) by obtain ⟨copt, hmem, hprop⟩ := hopt (Fintype.card U) Finset.univ L (by simp) (fun u _ ↦ hL u) have hpick : ∀ u : U, ∃ a ∈ L u, copt u = some a := fun u ↦ hmem u (Finset.mem_univ u) choose c hcL hceq using hpick refine ⟨c, hcL, fun u v huv hEq ↦ ?_⟩ apply hprop u (Finset.mem_univ u) v (Finset.mem_univ v) huv rw [hceq u, hceq v, hEq] intro m induction m with | zero => intro A L hcard _ have hE : A = ∅ := Finset.card_eq_zero.mp (Nat.le_zero.mp hcard) subst hE exact ⟨fun _ ↦ none, by simp, by simp⟩ | succ m ih => intro A L hcard hLA by_cases hA : A = ∅ · subst hA; exact ⟨fun _ ↦ none, by simp, by simp⟩ · obtain ⟨u₀, hu₀⟩ := Finset.nonempty_iff_ne_empty.mpr hA have hLu₀ : 0 < (L u₀).card := lt_of_le_of_lt (Nat.zero_le _) (hLA u₀ hu₀) obtain ⟨a₀, ha₀⟩ := Finset.card_pos.mp hLu₀ let S : Finset U := A.filter (fun u ↦ a₀ ∈ L u) have hu₀S : u₀ ∈ S := Finset.mem_filter.mpr ⟨hu₀, ha₀⟩ obtain ⟨K, hKS, hKind, hKdom⟩ := hker S have hKA : K ⊆ A := hKS.trans (Finset.filter_subset _ A) have hKne : K.Nonempty := by by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp subst hemp obtain ⟨v, hv, _⟩ := hKdom u₀ hu₀S (by simp) exact Finset.notMem_empty v hv let A' : Finset U := A \ K have hA'card : A'.card ≤ m := by rw [Finset.card_sdiff_of_subset hKA] have hKpos : 0 < K.card := Finset.card_pos.mpr hKne omega let L' : U → Finset α := fun u ↦ (L u).erase a₀ have hLA' : ∀ u ∈ A', (A'.filter (fun v ↦ D u v)).card < (L' u).card := by intro u huA' rw [Finset.mem_sdiff] at huA' rcases huA' with ⟨huA, huK⟩ by_cases ha : a₀ ∈ L u · have huS : u ∈ S := Finset.mem_filter.mpr ⟨huA, ha⟩ obtain ⟨v, hvK, huv⟩ := hKdom u huS huK have hvA : v ∈ A := hKA hvK have hvmem : v ∈ A.filter (fun w ↦ D u w) := Finset.mem_filter.mpr ⟨hvA, huv⟩ have hsub : A'.filter (fun w ↦ D u w) ⊆ (A.filter (fun w ↦ D u w)).erase v := by intro w hw rw [Finset.mem_filter, Finset.mem_sdiff] at hw rw [Finset.mem_erase, Finset.mem_filter] exact ⟨fun hEq ↦ hw.1.2 (hEq ▸ hvK), hw.1.1, hw.2⟩ have hc1 : (A'.filter (fun w ↦ D u w)).card ≤ (A.filter (fun w ↦ D u w)).card - 1 := by have := Finset.card_le_card hsub rwa [Finset.card_erase_of_mem hvmem] at this have hc2 : (L' u).card = (L u).card - 1 := Finset.card_erase_of_mem ha have hpos : 1 ≤ (A.filter (fun w ↦ D u w)).card := Finset.card_pos.mpr ⟨v, hvmem⟩ have hlt := hLA u huA omega · have hLeq : L' u = L u := Finset.erase_eq_of_notMem ha have hsub : A'.filter (fun w ↦ D u w) ⊆ A.filter (fun w ↦ D u w) := by intro w hw rw [Finset.mem_filter, Finset.mem_sdiff] at hw exact Finset.mem_filter.mpr ⟨hw.1.1, hw.2⟩ rw [hLeq] exact lt_of_le_of_lt (Finset.card_le_card hsub) (hLA u huA) obtain ⟨c', hc'mem, hc'prop⟩ := ih A' L' hA'card hLA' let c : U → Option α := fun u ↦ if u ∈ K then some a₀ else c' u refine ⟨c, ?_, ?_⟩ · intro u huA dsimp [c] by_cases huK : u ∈ K · rw [if_pos huK] exact ⟨a₀, (Finset.mem_filter.mp (hKS huK)).2, rfl⟩ · rw [if_neg huK] obtain ⟨a, haL', hca⟩ := hc'mem u (Finset.mem_sdiff.mpr ⟨huA, huK⟩) exact ⟨a, Finset.mem_of_mem_erase haL', hca⟩ · intro u huA v hvA huv dsimp [c] by_cases huK : u ∈ K <;> by_cases hvK : v ∈ K · exact absurd huv (hKind u huK v hvK) · rw [if_pos huK, if_neg hvK] obtain ⟨a, haL', hca⟩ := hc'mem v (Finset.mem_sdiff.mpr ⟨hvA, hvK⟩) rw [hca] intro hEq exact (Finset.mem_erase.mp haL').1 (Option.some.inj hEq).symm · rw [if_neg huK, if_pos hvK] obtain ⟨a, haL', hca⟩ := hc'mem u (Finset.mem_sdiff.mpr ⟨huA, huK⟩) rw [hca] intro hEq exact (Finset.mem_erase.mp haL').1 (Option.some.inj hEq) · rw [if_neg huK, if_neg hvK] exact hc'prop u (Finset.mem_sdiff.mpr ⟨huA, huK⟩) v (Finset.mem_sdiff.mpr ⟨hvA, hvK⟩) huv /-- **Gale–Shapley Kernel Existence for Galvin's Orientation:** Given an oriented bipartite edge set `U = {p : V × V // E p.1 p.2}` and a proper `d`-edge coloring `colVal : U → Fin d`, every subset `S : Finset U` has a kernel in Galvin's digraph `D e f ↔ (e.1.1 = f.1.1 ∧ colVal e < colVal f) ∨ (e.1.2 = f.1.2 ∧ colVal f < colVal e)`. -/ theorem exists_kernel_galvin_orientation {V : Type*} [Fintype V] {d : ℕ} {E : V → V → Prop} (colVal : {p : V × V // E p.1 p.2} → Fin d) (hpropL : ∀ e f : {p : V × V // E p.1 p.2}, e.1.1 = f.1.1 → colVal e = colVal f → e = f) (hpropR : ∀ e f : {p : V × V // E p.1 p.2}, e.1.2 = f.1.2 → colVal e = colVal f → e = f) (S : Finset {p : V × V // E p.1 p.2}) : let D := fun e f : {p : V × V // E p.1 p.2} ↦ (e.1.1 = f.1.1 ∧ colVal e < colVal f) ∨ (e.1.2 = f.1.2 ∧ colVal f < colVal e) ∃ K : Finset {p : V × V // E p.1 p.2}, K ⊆ S ∧ (∀ u ∈ K, ∀ v ∈ K, ¬D u v) ∧ (∀ u ∈ S, u ∉ K → ∃ v ∈ K, D u v) := by intro D let U := {p : V × V // E p.1 p.2} let proposals : Finset U → Finset U := fun R ↦ R.filter (fun e ↦ ∀ e' ∈ R, e'.1.1 = e.1.1 → colVal e' ≤ colVal e) have hprop_sub : ∀ R : Finset U, proposals R ⊆ R := fun R ↦ Finset.filter_subset _ R have hprop_left_uniq : ∀ (R : Finset U) (e f : U), e ∈ proposals R → f ∈ proposals R → e.1.1 = f.1.1 → e = f := by intro R e f he hf h1 rw [Finset.mem_filter] at he hf have hle1 : colVal f ≤ colVal e := he.2 f hf.1 h1.symm have hle2 : colVal e ≤ colVal f := hf.2 e he.1 h1 exact hpropL e f h1 (le_antisymm hle2 hle1) have hprop_ex : ∀ (R : Finset U) (e : U), e ∈ R → ∃ f ∈ proposals R, f.1.1 = e.1.1 ∧ colVal e ≤ colVal f := by intro R e heR let slice := R.filter (fun e' ↦ e'.1.1 = e.1.1) have hne : slice.Nonempty := ⟨e, Finset.mem_filter.mpr ⟨heR, rfl⟩⟩ obtain ⟨f, hfslice, hfmax⟩ := Finset.exists_max_image slice (fun x ↦ (colVal x).val) hne rw [Finset.mem_filter] at hfslice refine ⟨f, Finset.mem_filter.mpr ⟨hfslice.1, fun e' he'R h1 ↦ ?_⟩, hfslice.2, ?_⟩ · have he's : e' ∈ slice := Finset.mem_filter.mpr ⟨he'R, h1.trans hfslice.2⟩ exact hfmax e' he's · exact hfmax e (Finset.mem_filter.mpr ⟨heR, rfl⟩) suffices hgs : ∀ m (R : Finset U), R.card ≤ m → R ⊆ S → (∀ e ∈ S, e ∉ R → ∃ f ∈ proposals R, f.1.2 = e.1.2 ∧ colVal f < colVal e) → ∃ K : Finset U, K ⊆ S ∧ (∀ u ∈ K, ∀ v ∈ K, ¬D u v) ∧ (∀ u ∈ S, u ∉ K → ∃ v ∈ K, D u v) by exact hgs S.card S le_rfl Subset.rfl (fun e he hne ↦ absurd he hne) intro m induction m with | zero => intro R hcard hRS hinv have hRe : R = ∅ := Finset.card_eq_zero.mp (Nat.le_zero.mp hcard) subst hRe have hSe : S = ∅ := by ext e simp only [Finset.notMem_empty, iff_false] intro heS obtain ⟨f, hf, _⟩ := hinv e heS (by simp) exact Finset.notMem_empty f (hprop_sub ∅ hf) subst hSe exact ⟨∅, Subset.rfl, by simp, by simp⟩ | succ m ih => intro R hcard hRS hinv by_cases hmatch : ∀ e ∈ proposals R, ∀ f ∈ proposals R, e.1.2 = f.1.2 → e = f · refine ⟨proposals R, (hprop_sub R).trans hRS, ?_, ?_⟩ · intro u hu v hv huv rcases huv with ⟨h1, hlt⟩ | ⟨h2, hlt⟩ · have hEq := hprop_left_uniq R u v hu hv h1 subst hEq; exact lt_irrefl _ hlt · have hEq := hmatch u hu v hv h2 subst hEq; exact lt_irrefl _ hlt · intro u huS huK by_cases huR : u ∈ R · obtain ⟨v, hvK, h1, hle⟩ := hprop_ex R u huR have hne : u ≠ v := fun hEq ↦ huK (hEq ▸ hvK) have hcolne : colVal u ≠ colVal v := fun hc ↦ hne (hpropL u v h1.symm hc) have hlt : colVal u < colVal v := lt_of_le_of_ne hle hcolne exact ⟨v, hvK, Or.inl ⟨h1.symm, hlt⟩⟩ · obtain ⟨v, hvK, h2, hlt⟩ := hinv u huS huR exact ⟨v, hvK, Or.inr ⟨h2.symm, hlt⟩⟩ · push Not at hmatch obtain ⟨e₁, he₁, e₂, he₂, h12, hne12⟩ := hmatch have hcolne : colVal e₁ ≠ colVal e₂ := fun hc ↦ hne12 (hpropR e₁ e₂ h12 hc) -- Orient so `a` has strictly smaller `colVal` than `b` (and `b` gets rejected). have hex_ab : ∃ a ∈ proposals R, ∃ b ∈ proposals R, a.1.2 = b.1.2 ∧ colVal a < colVal b := by rcases lt_or_gt_of_ne hcolne with hlt | hgt · exact ⟨e₁, he₁, e₂, he₂, h12, hlt⟩ · exact ⟨e₂, he₂, e₁, he₁, h12.symm, hgt⟩ obtain ⟨a, ha, b, hb, hab2, hablt⟩ := hex_ab have hne_ab : a ≠ b := fun hEq ↦ lt_irrefl _ (hEq ▸ hablt) let R' : Finset U := R.erase b have hbR : b ∈ R := hprop_sub R hb have hR'card : R'.card ≤ m := by rw [Finset.card_erase_of_mem hbR] have hpos : 0 < R.card := Finset.card_pos.mpr ⟨b, hbR⟩ omega have hR'sub : R' ⊆ R := Finset.erase_subset b R have hkeep : ∀ g ∈ proposals R, g ≠ b → g ∈ proposals R' := by intro g hg hgb rw [Finset.mem_filter] at hg ⊢ refine ⟨Finset.mem_erase.mpr ⟨hgb, hg.1⟩, fun e' he'R' h1 ↦ hg.2 e' (hR'sub he'R') h1⟩ have ha' : a ∈ proposals R' := hkeep a ha hne_ab apply ih R' hR'card (hR'sub.trans hRS) intro e heS heR' by_cases heb : e = b · subst heb exact ⟨a, ha', hab2, hablt⟩ · have heR : e ∉ R := fun h ↦ heR' (Finset.mem_erase.mpr ⟨heb, h⟩) obtain ⟨f, hf, hf2, hflt⟩ := hinv e heS heR by_cases hfb : f = b · subst hfb exact ⟨a, ha', hab2.trans hf2, lt_trans hablt hflt⟩ · exact ⟨f, hkeep f hf hfb, hf2, hflt⟩ /-- **Galvin's Theorem (1995) for Finite Bipartite Simple Graphs:** Every finite bipartite simple graph `B` (bipartitioned by `side : V → Bool`) with `Δ(B) ≤ d` admits a proper list edge coloring for any edge list assignment `L : Sym2 V → Finset α` with `d ≤ (L s(u, v)).card` for all edges `u ~ v` of `B`. -/ theorem galvin_bipartite_list_edge_coloring {V α : Type*} [Fintype V] (B : SimpleGraph V) (side : V → Bool) (hbip : ∀ u v, B.Adj u v → side u ≠ side v) (d : ℕ) (hdeg : ∀ v, B.degree v ≤ d) (L : Sym2 V → Finset α) (hL : ∀ u v, B.Adj u v → d ≤ (L s(u, v)).card) : ∃ col : Sym2 V → Option α, (∀ u v a, col s(u, v) = some a → B.Adj u v ∧ a ∈ L s(u, v)) ∧ (∀ u v, B.Adj u v → (col s(u, v)).isSome) ∧ (∀ u v₁ v₂ a, col s(u, v₁) = some a → col s(u, v₂) = some a → v₁ = v₂) := by let E : V → V → Prop := fun u v ↦ B.Adj u v ∧ side u = false ∧ side v = true have hEL : ∀ u, (Finset.univ.filter (fun v ↦ E u v)).card ≤ d := by intro u have hsub : Finset.univ.filter (fun v ↦ E u v) ⊆ B.neighborFinset u := by intro v hv rw [Finset.mem_filter] at hv exact (SimpleGraph.mem_neighborFinset B u v).mpr hv.2.1 calc (Finset.univ.filter (fun v ↦ E u v)).card ≤ (B.neighborFinset u).card := Finset.card_le_card hsub _ = B.degree u := SimpleGraph.card_neighborFinset_eq_degree B u _ ≤ d := hdeg u have hER : ∀ v, (Finset.univ.filter (fun u ↦ E u v)).card ≤ d := by intro v have hsub : Finset.univ.filter (fun u ↦ E u v) ⊆ B.neighborFinset v := by intro u hu rw [Finset.mem_filter] at hu exact (SimpleGraph.mem_neighborFinset B v u).mpr hu.2.1.symm calc (Finset.univ.filter (fun u ↦ E u v)).card ≤ (B.neighborFinset v).card := Finset.card_le_card hsub _ = B.degree v := SimpleGraph.card_neighborFinset_eq_degree B v _ ≤ d := hdeg v obtain ⟨φ, hsupp, hpropLφ, hpropRφ⟩ := konig_bipartite_edge_coloring d E (fun u ↦ by convert hEL u) (fun v ↦ by convert hER v) let U := {p : V × V // E p.1 p.2} let colVal : U → Fin d := fun e ↦ (φ e.1.1 e.1.2).get ((hsupp e.1.1 e.1.2).mpr e.2) have hφ_eq : ∀ e : U, φ e.1.1 e.1.2 = some (colVal e) := fun e ↦ (Option.some_get _).symm have hpropL : ∀ e f : U, e.1.1 = f.1.1 → colVal e = colVal f → e = f := by intro e f h1 hc have h2 : e.1.2 = f.1.2 := by have he := hφ_eq e have hf := hφ_eq f rw [← h1, ← hc] at hf exact hpropLφ e.1.1 e.1.2 f.1.2 (colVal e) he hf exact Subtype.ext (Prod.ext h1 h2) have hpropR : ∀ e f : U, e.1.2 = f.1.2 → colVal e = colVal f → e = f := by intro e f h2 hc have h1 : e.1.1 = f.1.1 := by have he := hφ_eq e have hf := hφ_eq f rw [← h2, ← hc] at hf exact hpropRφ e.1.1 f.1.1 e.1.2 (colVal e) he hf exact Subtype.ext (Prod.ext h1 h2) let D : U → U → Prop := fun e f ↦ (e.1.1 = f.1.1 ∧ colVal e < colVal f) ∨ (e.1.2 = f.1.2 ∧ colVal f < colVal e) have hker : ∀ S : Finset U, ∃ K : Finset U, K ⊆ S ∧ (∀ u ∈ K, ∀ v ∈ K, ¬D u v) ∧ (∀ u ∈ S, u ∉ K → ∃ v ∈ K, D u v) := fun S ↦ exists_kernel_galvin_orientation colVal hpropL hpropR S let LU : U → Finset α := fun e ↦ L s(e.1.1, e.1.2) have hLU : ∀ e : U, (Finset.univ.filter (fun f : U ↦ D e f)).card < (LU e).card := by intro e have hd_le : d ≤ (LU e).card := hL e.1.1 e.1.2 e.2.1 let F₁ : Finset U := Finset.univ.filter (fun f : U ↦ e.1.1 = f.1.1 ∧ colVal e < colVal f) let F₂ : Finset U := Finset.univ.filter (fun f : U ↦ e.1.2 = f.1.2 ∧ colVal f < colVal e) have hsubU : Finset.univ.filter (fun f : U ↦ D e f) ⊆ F₁ ∪ F₂ := by intro f hf rw [Finset.mem_filter] at hf rw [Finset.mem_union, Finset.mem_filter, Finset.mem_filter] rcases hf.2 with h1 | h2 · exact Or.inl ⟨Finset.mem_univ f, h1⟩ · exact Or.inr ⟨Finset.mem_univ f, h2⟩ have hF₁ : F₁.card ≤ d - 1 - (colVal e).val := by have hinj : Set.InjOn colVal (F₁ : Set U) := by intro x hx y hy hEq rw [Finset.mem_coe, Finset.mem_filter] at hx hy exact hpropL x y (hx.2.1.symm.trans hy.2.1) hEq have himg_sub : F₁.image colVal ⊆ Finset.univ.filter (fun c : Fin d ↦ colVal e < c) := by intro c hc rw [Finset.mem_image] at hc obtain ⟨f, hf, rfl⟩ := hc exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hf).2.2⟩ have hcard_gt : (Finset.univ.filter (fun c : Fin d ↦ colVal e < c)).card ≤ d - 1 - (colVal e).val := by have himg2 : (Finset.univ.filter (fun c : Fin d ↦ colVal e < c)).image Fin.val ⊆ Finset.Ioo (colVal e).val d := by intro n hn rw [Finset.mem_image] at hn obtain ⟨c, hc, rfl⟩ := hn rw [Finset.mem_filter] at hc exact Finset.mem_Ioo.mpr ⟨hc.2, c.isLt⟩ calc (Finset.univ.filter (fun c : Fin d ↦ colVal e < c)).card = ((Finset.univ.filter (fun c : Fin d ↦ colVal e < c)).image Fin.val).card := (Finset.card_image_of_injective _ Fin.val_injective).symm _ ≤ (Finset.Ioo (colVal e).val d).card := Finset.card_le_card himg2 _ = d - 1 - (colVal e).val := by rw [Nat.card_Ioo]; omega calc F₁.card = (F₁.image colVal).card := (Finset.card_image_of_injOn hinj).symm _ ≤ (Finset.univ.filter (fun c : Fin d ↦ colVal e < c)).card := Finset.card_le_card himg_sub _ ≤ d - 1 - (colVal e).val := hcard_gt have hF₂ : F₂.card ≤ (colVal e).val := by have hinj : Set.InjOn colVal (F₂ : Set U) := by intro x hx y hy hEq rw [Finset.mem_coe, Finset.mem_filter] at hx hy exact hpropR x y (hx.2.1.symm.trans hy.2.1) hEq have himg_sub : F₂.image colVal ⊆ Finset.univ.filter (fun c : Fin d ↦ c < colVal e) := by intro c hc rw [Finset.mem_image] at hc obtain ⟨f, hf, rfl⟩ := hc exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hf).2.2⟩ have hcard_lt : (Finset.univ.filter (fun c : Fin d ↦ c < colVal e)).card ≤ (colVal e).val := by have himg2 : (Finset.univ.filter (fun c : Fin d ↦ c < colVal e)).image Fin.val ⊆ Finset.range (colVal e).val := by intro n hn rw [Finset.mem_image] at hn obtain ⟨c, hc, rfl⟩ := hn rw [Finset.mem_filter] at hc exact Finset.mem_range.mpr hc.2 calc (Finset.univ.filter (fun c : Fin d ↦ c < colVal e)).card = ((Finset.univ.filter (fun c : Fin d ↦ c < colVal e)).image Fin.val).card := (Finset.card_image_of_injective _ Fin.val_injective).symm _ ≤ (Finset.range (colVal e).val).card := Finset.card_le_card himg2 _ = (colVal e).val := Finset.card_range _ calc F₂.card = (F₂.image colVal).card := (Finset.card_image_of_injOn hinj).symm _ ≤ (Finset.univ.filter (fun c : Fin d ↦ c < colVal e)).card := Finset.card_le_card himg_sub _ ≤ (colVal e).val := hcard_lt have hlt_d : (colVal e).val < d := (colVal e).isLt have hcard_D : (Finset.univ.filter (fun f : U ↦ D e f)).card ≤ F₁.card + F₂.card := le_trans (Finset.card_le_card hsubU) (Finset.card_union_le F₁ F₂) omega obtain ⟨cU, hcU_mem, hcU_prop⟩ := exists_list_coloring_of_kernel_perfect D hker LU (fun e ↦ by convert hLU e) -- Injectivity of `U → Sym2 V`: ordered pair `(x, y)` with `side x = false, side y = true` is unique. have hsym_inj : ∀ p q : U, s(p.1.1, p.1.2) = s(q.1.1, q.1.2) → p = q := by intro p q hEq rw [Sym2.eq_iff] at hEq rcases hEq with ⟨h1, h2⟩ | ⟨h1, h2⟩ · exact Subtype.ext (Prod.ext h1 h2) · exfalso have hp := p.2.2.1 have hq := q.2.2.2 rw [h1] at hp exact Bool.false_ne_true (hp.symm.trans hq) let col : Sym2 V → Option α := fun e ↦ if h : ∃ p : U, s(p.1.1, p.1.2) = e then some (cU h.choose) else none have hcol_at : ∀ p : U, col s(p.1.1, p.1.2) = some (cU p) := by intro p have hex : ∃ q : U, s(q.1.1, q.1.2) = s(p.1.1, p.1.2) := ⟨p, rfl⟩ dsimp [col] rw [dif_pos hex] congr 1 exact congrArg cU (hsym_inj hex.choose p hex.choose_spec) have hcol_some : ∀ u v a, col s(u, v) = some a → ∃ p : U, s(p.1.1, p.1.2) = s(u, v) ∧ cU p = a := by intro u v a h dsimp [col] at h by_cases hex : ∃ p : U, s(p.1.1, p.1.2) = s(u, v) · rw [dif_pos hex] at h exact ⟨hex.choose, hex.choose_spec, Option.some.inj h⟩ · rw [dif_neg hex] at h; exact absurd h (by simp) refine ⟨col, ?_, ?_, ?_⟩ · intro u v a h obtain ⟨p, hpEq, rfl⟩ := hcol_some u v a h refine ⟨?_, ?_⟩ · rw [Sym2.eq_iff] at hpEq rcases hpEq with ⟨h1, h2⟩ | ⟨h1, h2⟩ · rw [← h1, ← h2]; exact p.2.1 · rw [← h1, ← h2]; exact p.2.1.symm · rw [← hpEq]; exact hcU_mem p · intro u v huv have hne : side u ≠ side v := hbip u v huv cases hsu : side u <;> cases hsv : side v · exact absurd (hsu.trans hsv.symm) hne · let p : U := ⟨(u, v), huv, hsu, hsv⟩ rw [hcol_at p]; rfl · let p : U := ⟨(v, u), huv.symm, hsv, hsu⟩ rw [Sym2.eq_swap, hcol_at p]; rfl · exact absurd (hsu.trans hsv.symm) hne · intro u v₁ v₂ a h1 h2 obtain ⟨p₁, hp₁Eq, hp₁c⟩ := hcol_some u v₁ a h1 obtain ⟨p₂, hp₂Eq, hp₂c⟩ := hcol_some u v₂ a h2 by_contra hne_v have hne_p : p₁ ≠ p₂ := by intro hEq subst hEq have hsym : s(u, v₁) = s(u, v₂) := hp₁Eq.symm.trans hp₂Eq rw [Sym2.eq_iff] at hsym rcases hsym with ⟨_, h⟩ | ⟨h1', h2'⟩ · exact hne_v h · exact hne_v (h2'.trans h1') have hshare : p₁.1.1 = p₂.1.1 ∨ p₁.1.2 = p₂.1.2 := by have hu1 : u ∈ s(p₁.1.1, p₁.1.2) := by rw [hp₁Eq]; exact Sym2.mem_mk_left u v₁ have hu2 : u ∈ s(p₂.1.1, p₂.1.2) := by rw [hp₂Eq]; exact Sym2.mem_mk_left u v₂ rw [Sym2.mem_iff] at hu1 hu2 rcases hu1 with rfl | rfl <;> rcases hu2 with h | h · exact Or.inl h · exfalso have hp1 := p₁.2.2.1; have hp2 := p₂.2.2.2 rw [h] at hp1 exact Bool.false_ne_true (hp1.symm.trans hp2) · exfalso have hp1 := p₁.2.2.2; have hp2 := p₂.2.2.1 rw [h] at hp1 exact Bool.false_ne_true (hp2.symm.trans hp1) · exact Or.inr h have hD : D p₁ p₂ ∨ D p₂ p₁ := by rcases hshare with hL_eq | hR_eq · have hne_c : colVal p₁ ≠ colVal p₂ := fun hc ↦ hne_p (hpropL p₁ p₂ hL_eq hc) rcases lt_or_gt_of_ne hne_c with hlt | hgt · exact Or.inl (Or.inl ⟨hL_eq, hlt⟩) · exact Or.inr (Or.inl ⟨hL_eq.symm, hgt⟩) · have hne_c : colVal p₁ ≠ colVal p₂ := fun hc ↦ hne_p (hpropR p₁ p₂ hR_eq hc) rcases lt_or_gt_of_ne hne_c with hlt | hgt · exact Or.inr (Or.inr ⟨hR_eq.symm, hlt⟩) · exact Or.inl (Or.inr ⟨hR_eq, hgt⟩) rcases hD with h12 | h21 · exact hcU_prop p₁ p₂ h12 (hp₁c.trans hp₂c.symm) · exact hcU_prop p₂ p₁ h21 (hp₂c.trans hp₁c.symm) end GalvinEngine /-! ## Section 6: Bipartite Degree-Reduction Decomposition for `k`-Degenerate Graphs -/ section BipartiteDecomposition /-- **Forward Greedy Bipartition Lemma:** Given any injective vertex ranking `π : V → ℕ` into `{0, …, |V| - 1}`, there exists a `2`-coloring `side : V → Bool` such that every vertex `u` has at least half of its *backward* neighbors (`π v < π u`) on the opposite side. -/ lemma exists_forward_greedy_bipartition {V : Type*} [Fintype V] (G : SimpleGraph V) (π : V → ℕ) (hπ_lt : ∀ u, π u < Fintype.card V) (hπ_inj : Function.Injective π) : ∃ side : V → Bool, ∀ u : V, (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u)).card ≤ 2 * (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u ∧ side v ≠ side u)).card := by suffices h : ∀ m : ℕ, ∃ side : V → Bool, ∀ u : V, π u < m → (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u)).card ≤ 2 * (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u ∧ side v ≠ side u)).card by obtain ⟨side, hside⟩ := h (Fintype.card V) exact ⟨side, fun u ↦ hside u (hπ_lt u)⟩ intro m induction m with | zero => exact ⟨fun _ ↦ false, fun _ hu ↦ by omega⟩ | succ m ih => obtain ⟨side, hside⟩ := ih by_cases hex : ∃ u₀ : V, π u₀ = m · obtain ⟨u₀, hu₀⟩ := hex let back := Finset.univ.filter (fun v ↦ G.Adj u₀ v ∧ π v < m) let bF := back.filter (fun v ↦ side v = false) let bT := back.filter (fun v ↦ side v = true) have hpart : bF.card + bT.card = back.card := by have h1 := Finset.card_filter_add_card_filter_not (s := back) (p := fun v ↦ side v = false) have heq : back.filter (fun v ↦ ¬side v = false) = bT := by ext v; simp [bT] rwa [heq] at h1 let s₀ : Bool := decide (bT.card ≤ bF.card) let side' : V → Bool := fun x ↦ if x = u₀ then s₀ else side x refine ⟨side', fun u hu ↦ ?_⟩ by_cases hu_eq : u = u₀ · subst hu_eq have hback_eq : Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u) = back := by ext v; simp [back, hu₀] rw [hback_eq] have hopp_eq : Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u ∧ side' v ≠ side' u) = if bT.card ≤ bF.card then bF else bT := by split_ifs with hle · ext v simp only [Finset.mem_filter, Finset.mem_univ, true_and, back, bF, side', s₀, decide_eq_true hle] constructor · rintro ⟨hadj, hlt, hne⟩ have hvu : v ≠ u := fun hEq ↦ by subst hEq; omega rw [if_neg hvu, if_pos trivial] at hne refine ⟨⟨hadj, by omega⟩, ?_⟩ cases hv : side v <;> simp_all · rintro ⟨⟨hadj, hlt⟩, hvF⟩ have hvu : v ≠ u := fun hEq ↦ by subst hEq; omega refine ⟨hadj, by omega, ?_⟩ rw [if_neg hvu, if_pos trivial, hvF]; decide · ext v simp only [Finset.mem_filter, Finset.mem_univ, true_and, back, bT, side', s₀, decide_eq_false hle] constructor · rintro ⟨hadj, hlt, hne⟩ have hvu : v ≠ u := fun hEq ↦ by subst hEq; omega rw [if_neg hvu, if_pos trivial] at hne refine ⟨⟨hadj, by omega⟩, ?_⟩ cases hv : side v <;> simp_all · rintro ⟨⟨hadj, hlt⟩, hvT⟩ have hvu : v ≠ u := fun hEq ↦ by subst hEq; omega refine ⟨hadj, by omega, ?_⟩ rw [if_neg hvu, if_pos trivial, hvT]; decide rw [hopp_eq] split_ifs with hle <;> omega · have hult : π u < m := by have hne : π u ≠ m := fun hEq ↦ hu_eq (hπ_inj (hEq.trans hu₀.symm)) omega have hsame : Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u ∧ side' v ≠ side' u) = Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u ∧ side v ≠ side u) := by ext v simp only [Finset.mem_filter, Finset.mem_univ, true_and, side'] constructor <;> rintro ⟨hadj, hlt, hne⟩ · have hvu : v ≠ u₀ := fun hEq ↦ by subst hEq; omega rw [if_neg hvu, if_neg hu_eq] at hne exact ⟨hadj, hlt, hne⟩ · have hvu : v ≠ u₀ := fun hEq ↦ by subst hEq; omega refine ⟨hadj, hlt, ?_⟩ rw [if_neg hvu, if_neg hu_eq]; exact hne rw [hsame] exact hside u hult · refine ⟨side, fun u hu ↦ hside u ?_⟩ have hne : π u ≠ m := fun hEq ↦ hex ⟨u, hEq⟩ omega /-- **Bipartite Degree-Reduction Decomposition Theorem (New Structural Lemma):** Every `k`-degenerate finite simple graph `G` with `Δ(G) ≤ Δ` and `3 * k - 1 ≤ Δ` contains a **bipartite** spanning subgraph `F ≤ G` (with bipartition `side : V → Bool`) such that: 1. `Δ(F) ≤ k`, and 2. `Δ(G \ F) ≤ Δ - k`. -/ theorem exists_bipartite_subgraph_degree_split {V : Type*} [Fintype V] (G : SimpleGraph V) {k Δ : ℕ} (hdeg_en : IsDegenerate G k) (hΔ : ∀ v, G.degree v ≤ Δ) (hge : 3 * k - 1 ≤ Δ) : ∃ (F : SimpleGraph V) (side : V → Bool), F ≤ G ∧ (∀ u v, F.Adj u v → side u ≠ side v) ∧ (∀ v, F.degree v ≤ k) ∧ (∀ v, (G \ F).degree v ≤ Δ - k) := by by_cases hk0 : k = 0 · subst hk0 refine ⟨⊥, fun _ ↦ false, bot_le, fun _ _ h ↦ h.elim, fun v ↦ by simp, fun v ↦ ?_⟩ have hle : (G \ ⊥) ≤ G := sdiff_le have hfin : (G \ ⊥).degree v ≤ Δ := le_trans (SimpleGraph.degree_le_of_le hle) (hΔ v) simpa using (by convert hfin) have hkpos : 1 ≤ k := by omega obtain ⟨π, hπ_lt, hπ_inj, hπ_fwd⟩ := exists_forward_degeneracy_ordering hdeg_en obtain ⟨side, hside_back⟩ := exists_forward_greedy_bipartition G π hπ_lt hπ_inj let N := Fintype.card V -- For any vertex `u`, `deg(u) = back_deg(u) + fwd_deg(u)`. have hdeg_split : ∀ u : V, G.degree u = (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u)).card + (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π u < π v)).card := by intro u rw [← SimpleGraph.card_neighborFinset_eq_degree] have hdisj : Disjoint (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u)) (Finset.univ.filter (fun v ↦ G.Adj u v ∧ π u < π v)) := by rw [Finset.disjoint_left] intro v hv1 hv2 rw [Finset.mem_filter] at hv1 hv2; omega have hunion : G.neighborFinset u = Finset.univ.filter (fun v ↦ G.Adj u v ∧ π v < π u) ∪ Finset.univ.filter (fun v ↦ G.Adj u v ∧ π u < π v) := by ext v simp only [SimpleGraph.mem_neighborFinset, Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] constructor · intro huv have hne : π v ≠ π u := fun hEq ↦ G.ne_of_adj huv (hπ_inj hEq).symm rcases lt_or_gt_of_ne hne with hlt | hgt · exact Or.inl ⟨huv, hlt⟩ · exact Or.inr ⟨huv, hgt⟩ · rintro (⟨huv, _⟩ | ⟨huv, _⟩) <;> exact huv rw [hunion, Finset.card_union_of_disjoint hdisj] -- Backward induction on `t = 0, …, N`, processing vertices `u` with `N - t ≤ π u`. suffices hind : ∀ t : ℕ, t ≤ N → ∃ F : SimpleGraph V, F ≤ G ∧ (∀ u v, F.Adj u v → side u ≠ side v) ∧ (∀ u v, F.Adj u v → N - t ≤ max (π u) (π v)) ∧ (∀ u, N - t ≤ π u → F.degree u ≤ k ∧ G.degree u ≤ Δ - k + F.degree u) by obtain ⟨F, hFG, hFbip, _, hFdeg⟩ := hind N le_rfl refine ⟨F, side, hFG, hFbip, fun v ↦ (hFdeg v (by omega)).1, fun v ↦ ?_⟩ have hadd : (G \ F).degree v + F.degree v = G.degree v := by rw [← SimpleGraph.card_neighborFinset_eq_degree, ← SimpleGraph.card_neighborFinset_eq_degree, ← SimpleGraph.card_neighborFinset_eq_degree] have hdisj : Disjoint ((G \ F).neighborFinset v) (F.neighborFinset v) := by rw [Finset.disjoint_left] intro w hw1 hw2 rw [SimpleGraph.mem_neighborFinset] at hw1 hw2 exact hw1.2 hw2 have hunion : (G \ F).neighborFinset v ∪ F.neighborFinset v = G.neighborFinset v := by ext w simp only [Finset.mem_union, SimpleGraph.mem_neighborFinset, SimpleGraph.sdiff_adj] exact ⟨fun h ↦ h.elim And.left (fun hw ↦ hFG hw), fun hw ↦ if hF : F.Adj v w then Or.inr hF else Or.inl ⟨hw, hF⟩⟩ rw [← Finset.card_union_of_disjoint hdisj, hunion] have hle := (hFdeg v (by omega)).2 omega intro t induction t with | zero => intro _ refine ⟨⊥, bot_le, fun _ _ h ↦ h.elim, fun _ _ h ↦ h.elim, fun u hu ↦ ?_⟩ have := hπ_lt u omega | succ t iht => intro htN obtain ⟨F, hFG, hFbip, hFmax, hFproc⟩ := iht (by omega) let target := N - (t + 1) by_cases hex : ∃ u₀ : V, π u₀ = target · obtain ⟨u₀, hu₀⟩ := hex -- Currently, all `F`-neighbors of `u₀` are forward neighbors (`π u₀ < π v`), so `F.degree u₀ ≤ k`. have hFu₀_le_k : F.degree u₀ ≤ k := by rw [← SimpleGraph.card_neighborFinset_eq_degree] have hsub : F.neighborFinset u₀ ⊆ Finset.univ.filter (fun v ↦ G.Adj u₀ v ∧ π u₀ < π v) := by intro v hv rw [SimpleGraph.mem_neighborFinset] at hv have hmx := hFmax u₀ v hv have hlt : π u₀ < π v := by omega exact Finset.mem_filter.mpr ⟨Finset.mem_univ v, hFG hv, hlt⟩ exact le_trans (Finset.card_le_card hsub) (hπ_fwd u₀) let need := G.degree u₀ - (Δ - k) have hneed_le_k : need ≤ k := by have := hΔ u₀; omega by_cases hsat : need ≤ F.degree u₀ · refine ⟨F, hFG, hFbip, fun u v huv ↦ le_trans (by omega) (hFmax u v huv), fun u hu ↦ ?_⟩ by_cases hu_eq : u = u₀ · subst hu_eq; exact ⟨hFu₀_le_k, by omega⟩ · have hge_old : N - t ≤ π u := by have hne : π u ≠ target := fun hEq ↦ hu_eq (hπ_inj (hEq.trans hu₀.symm)) omega exact hFproc u hge_old · let deficit := need - F.degree u₀ let cands := Finset.univ.filter (fun v ↦ G.Adj u₀ v ∧ π v < π u₀ ∧ side v ≠ side u₀) have hdef_le : deficit ≤ cands.card := by have hsb := hside_back u₀ have hds := hdeg_split u₀ have hfwd := hπ_fwd u₀ have hdu := hΔ u₀ dsimp only [cands, need, deficit] at * omega obtain ⟨S, hScands, hScard⟩ := Finset.exists_subset_card_eq hdef_le let F' : SimpleGraph V := { Adj := fun x y ↦ F.Adj x y ∨ (x = u₀ ∧ y ∈ S) ∨ (y = u₀ ∧ x ∈ S) symm := ⟨fun _ _ h ↦ by rcases h with h | h | h <;> [exact Or.inl h.symm; exact Or.inr (Or.inr h); exact Or.inr (Or.inl h)]⟩ loopless := ⟨fun x h ↦ by rcases h with h | ⟨rfl, hxS⟩ | ⟨rfl, hxS⟩ · exact F.loopless.irrefl x h · have := (Finset.mem_filter.mp (hScands hxS)).2.2.1; omega · have := (Finset.mem_filter.mp (hScands hxS)).2.2.1; omega⟩ } have hF'G : F' ≤ G := by intro x y hxy rcases hxy with h | ⟨rfl, hyS⟩ | ⟨rfl, hxS⟩ · exact hFG h · exact (Finset.mem_filter.mp (hScands hyS)).2.1 · exact (Finset.mem_filter.mp (hScands hxS)).2.1.symm have hF'bip : ∀ x y, F'.Adj x y → side x ≠ side y := by intro x y hxy rcases hxy with h | ⟨rfl, hyS⟩ | ⟨rfl, hxS⟩ · exact hFbip x y h · exact (Finset.mem_filter.mp (hScands hyS)).2.2.2.symm · exact (Finset.mem_filter.mp (hScands hxS)).2.2.2 have hF'max : ∀ x y, F'.Adj x y → target ≤ max (π x) (π y) := by intro x y hxy rcases hxy with h | ⟨rfl, _⟩ | ⟨rfl, _⟩ · have := hFmax x y h; omega · rw [hu₀]; exact le_max_left _ _ · rw [hu₀]; exact le_max_right _ _ have hF'u₀_deg : F'.degree u₀ = F.degree u₀ + deficit := by rw [← SimpleGraph.card_neighborFinset_eq_degree, ← SimpleGraph.card_neighborFinset_eq_degree] have hdisj : Disjoint (F.neighborFinset u₀) S := by rw [Finset.disjoint_left] intro v hvF hvS rw [SimpleGraph.mem_neighborFinset] at hvF have hmx := hFmax u₀ v hvF have hlt := (Finset.mem_filter.mp (hScands hvS)).2.2.1 omega have hunion : F'.neighborFinset u₀ = F.neighborFinset u₀ ∪ S := by ext v simp only [SimpleGraph.mem_neighborFinset, Finset.mem_union, F'] constructor · rintro (hF | ⟨_, hvS⟩ | ⟨rfl, hvS⟩) · exact Or.inl hF · exact Or.inr hvS · exfalso; have := (Finset.mem_filter.mp (hScands hvS)).2.2.1; omega · rintro (hF | hvS) · exact Or.inl hF · exact Or.inr (Or.inl ⟨trivial, hvS⟩) rw [hunion, Finset.card_union_of_disjoint hdisj, hScard] refine ⟨F', hF'G, hF'bip, hF'max, fun u hu ↦ ?_⟩ by_cases hu_eq : u = u₀ · subst hu_eq have hfin : F'.degree u ≤ k ∧ G.degree u ≤ Δ - k + F'.degree u := by rw [hF'u₀_deg]; omega convert hfin · have hge_old : N - t ≤ π u := by have hne : π u ≠ target := fun hEq ↦ hu_eq (hπ_inj (hEq.trans hu₀.symm)) omega have hdeg_same : F'.degree u = F.degree u := by rw [← SimpleGraph.card_neighborFinset_eq_degree, ← SimpleGraph.card_neighborFinset_eq_degree] congr 1 ext v simp only [SimpleGraph.mem_neighborFinset, F'] constructor · rintro (hF | ⟨rfl, _⟩ | ⟨rfl, huS⟩) · exact hF · exact absurd rfl hu_eq · exfalso; have := (Finset.mem_filter.mp (hScands huS)).2.2.1; omega · exact Or.inl have hfin : F'.degree u ≤ k ∧ G.degree u ≤ Δ - k + F'.degree u := by rw [hdeg_same]; exact hFproc u hge_old convert hfin · refine ⟨F, hFG, hFbip, fun u v huv ↦ le_trans (by omega) (hFmax u v huv), fun u hu ↦ ?_⟩ have hne : π u ≠ target := fun hEq ↦ hex ⟨u, hEq⟩ exact hFproc u (by omega) end BipartiteDecomposition /-! ## Section 7: Main Total Coloring Theorems (Matching `TotalColoringConjecture.lean` Verbatim) -/ section MainTheorems /-- Helper: Build a `SimpleGraph.IsTotalColoring` from a proper vertex coloring `vcol : V → Fin N` and a proper edge coloring `ecol : Sym2 V → Option (Fin N)` that avoids endpoint vertex colors. -/ lemma totalColorable_of_vertex_edge_coloring {V : Type*} (G : SimpleGraph V) (N : ℕ) (vcol : V → Fin N) (hv_prop : ∀ u v, G.Adj u v → vcol u ≠ vcol v) (ecol : Sym2 V → Option (Fin N)) (he_tot : ∀ u v, G.Adj u v → (ecol s(u, v)).isSome) (he_prop : ∀ u v₁ v₂ c, ecol s(u, v₁) = some c → ecol s(u, v₂) = some c → v₁ = v₂) (hve : ∀ u v c, ecol s(u, v) = some c → c ≠ vcol u) : G.TotalColorable N := by have he_isSome : ∀ e : G.edgeSet, (ecol e.1).isSome := by intro ⟨e, he⟩ induction e using Sym2.ind with | _ u v => exact he_tot u v he let c : V ⊕ G.edgeSet → Fin N := fun x ↦ match x with | Sum.inl v => vcol v | Sum.inr e => (ecol e.1).get (he_isSome e) refine ⟨c, hv_prop, ?_, ?_⟩ · intro e f hef ⟨v, hve_mem, hvf_mem⟩ hEq rcases e with ⟨e, he⟩ rcases f with ⟨f, hf⟩ induction e using Sym2.ind with | _ u₁ w₁ => induction f using Sym2.ind with | _ u₂ w₂ => dsimp [c] at hEq let col0 : Fin N := (ecol s(u₁, w₁)).get (he_isSome ⟨s(u₁, w₁), he⟩) have he1 : ecol s(u₁, w₁) = some col0 := (Option.some_get _).symm have hf1 : ecol s(u₂, w₂) = some col0 := by change ecol s(u₂, w₂) = some ((ecol s(u₁, w₁)).get (he_isSome ⟨s(u₁, w₁), he⟩)) rw [hEq]; exact (Option.some_get _).symm rw [Sym2.mem_iff] at hve_mem hvf_mem rcases hve_mem with rfl | rfl <;> rcases hvf_mem with rfl | rfl · have := he_prop v w₁ w₂ col0 he1 hf1 exact hef (Subtype.ext (show s(v, w₁) = s(v, w₂) by rw [this])) · rw [Sym2.eq_swap] at hf1 have := he_prop v w₁ u₂ col0 he1 hf1 exact hef (Subtype.ext (show s(v, w₁) = s(u₂, v) by rw [this, Sym2.eq_swap])) · rw [Sym2.eq_swap] at he1 have := he_prop v u₁ w₂ col0 he1 hf1 exact hef (Subtype.ext (show s(u₁, v) = s(v, w₂) by rw [this, Sym2.eq_swap])) · rw [Sym2.eq_swap] at he1 hf1 have := he_prop v u₁ u₂ col0 he1 hf1 exact hef (Subtype.ext (show s(u₁, v) = s(u₂, v) by rw [this])) · intro v ⟨e, he⟩ hve_mem hEq induction e using Sym2.ind with | _ u w => dsimp [c] at hEq have he1 : ecol s(u, w) = some (vcol v) := by rw [hEq]; exact (Option.some_get _).symm rw [Sym2.mem_iff] at hve_mem rcases hve_mem with rfl | rfl · exact hve v w (vcol v) he1 rfl · rw [Sym2.eq_swap] at he1 exact hve v u (vcol v) he1 rfl /-- **Main Parametric Theorem (Total Coloring for `k`-Degenerate Graphs with `Δ ≥ 3k`):** Every `k`-degenerate finite simple graph `G` with maximum degree at most `Δ` and `3 * k ≤ Δ` is totally `(Δ + 2)`-colorable. -/ theorem totalColorable_of_isDegenerate_ge_three_mul {V : Type*} [Fintype V] (G : SimpleGraph V) {k Δ : ℕ} (hdeg_en : IsDegenerate G k) (hΔ : ∀ v, G.degree v ≤ Δ) (hge : 3 * k ≤ Δ) : G.TotalColorable (Δ + 2) := by -- Step 1: Proper `(k + 1)`-vertex coloring of `G`, embedded into `{0, …, k} ⊆ Fin (Δ + 2)`. obtain ⟨vcol0, hvcol0⟩ := exists_vertex_coloring_of_isDegenerate hdeg_en let vcol : V → Fin (Δ + 2) := fun v ↦ ⟨(vcol0 v).val, by have := (vcol0 v).isLt; omega⟩ have hv_prop : ∀ u v, G.Adj u v → vcol u ≠ vcol v := by intro u v huv hEq have hval : (vcol u).val = (vcol v).val := congrArg Fin.val hEq exact hvcol0 u v huv (Fin.ext hval) -- Step 2: Bipartite degree-reduction decomposition `G = F ∪ (G \ F)` with `Δ(F) ≤ k`, `Δ(G \ F) ≤ Δ - k`. obtain ⟨F, side, hFG, hFbip, hFdeg, hGFdeg⟩ := exists_bipartite_subgraph_degree_split G hdeg_en hΔ (by omega) -- Step 3: List edge coloring of `F` via Galvin's Theorem using colors in `{0, …, k + 1}` -- avoiding the endpoint vertex colors `vcol0 u` and `vcol0 v`. let L : Sym2 V → Finset (Fin (k + 2)) := fun e ↦ Finset.univ.filter (fun c : Fin (k + 2) ↦ ∀ x ∈ e, c.val ≠ (vcol0 x).val) have hLcard : ∀ u v, F.Adj u v → k ≤ (L s(u, v)).card := by intro u v huv let cu : Fin (k + 2) := ⟨(vcol0 u).val, by have := (vcol0 u).isLt; omega⟩ let cv : Fin (k + 2) := ⟨(vcol0 v).val, by have := (vcol0 v).isLt; omega⟩ have hL_eq : L s(u, v) = (Finset.univ : Finset (Fin (k + 2))) \ {cu, cv} := by ext c simp only [L, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton, Sym2.mem_iff] constructor · intro h rintro (rfl | rfl) · exact h u (Or.inl rfl) rfl · exact h v (Or.inr rfl) rfl · intro h x hx hval rcases hx with rfl | rfl · exact h (Or.inl (Fin.ext hval)) · exact h (Or.inr (Fin.ext hval)) rw [hL_eq, Finset.card_sdiff_of_subset (Finset.subset_univ _)] have hpair : ({cu, cv} : Finset (Fin (k + 2))).card ≤ 2 := Finset.card_le_two simp only [Finset.card_univ, Fintype.card_fin] omega obtain ⟨colF, hcolF_supp, hcolF_tot, hcolF_prop⟩ := galvin_bipartite_list_edge_coloring F side hFbip k hFdeg L hLcard -- Step 4: Class-1 `(Δ - k)`-edge coloring of `G \ F` via Vizing's Degeneracy Theorem (`2k ≤ Δ - k`). have hGF_degen : IsDegenerate (G \ F) k := hdeg_en.of_le sdiff_le obtain ⟨P, hPtot⟩ := class_one_of_degenerate (G \ F) k (Δ - k) hGF_degen (by omega) (fun v ↦ by convert hGFdeg v) -- Step 5: Combine `colF` (in `{0, …, k + 1}`) and shifted `P.col` (in `{k + 2, …, Δ + 1}`). let liftF : Fin (k + 2) → Fin (Δ + 2) := fun c ↦ ⟨c.val, by have := c.isLt; omega⟩ let liftR : Fin (Δ - k) → Fin (Δ + 2) := fun c ↦ ⟨k + 2 + c.val, by have := c.isLt; omega⟩ let ecol : Sym2 V → Option (Fin (Δ + 2)) := fun e ↦ match colF e with | some c => some (liftF c) | none => (P.col e).map liftR refine totalColorable_of_vertex_edge_coloring G (Δ + 2) vcol hv_prop ecol ?_ ?_ ?_ · intro u v huv dsimp [ecol] by_cases hFuv : F.Adj u v · have h1 := hcolF_tot u v hFuv cases h : colF s(u, v) with | none => simp [h] at h1 | some c => simp · cases h : colF s(u, v) with | some c => simp | none => have hGFuv : (G \ F).Adj u v := ⟨huv, hFuv⟩ have h2 := hPtot u v hGFuv cases hp : P.col s(u, v) with | none => simp [hp] at h2 | some c => simp · intro u v₁ v₂ c h1 h2 dsimp [ecol] at h1 h2 cases hf1 : colF s(u, v₁) with | some c₁ => rw [hf1] at h1 have hc1 : liftF c₁ = c := Option.some.inj h1 cases hf2 : colF s(u, v₂) with | some c₂ => rw [hf2] at h2 have hc2 : liftF c₂ = c := Option.some.inj h2 have heqc : c₁ = c₂ := Fin.ext (by have := congrArg Fin.val (hc1.trans hc2.symm) simpa [liftF] using this) exact hcolF_prop u v₁ v₂ c₁ hf1 (heqc ▸ hf2) | none => rw [hf2] at h2 cases hp2 : P.col s(u, v₂) with | none => simp [hp2] at h2 | some r₂ => rw [hp2] at h2 have hc2 : liftR r₂ = c := Option.some.inj (by simpa using h2) have hval := congrArg Fin.val (hc1.trans hc2.symm) dsimp [liftF, liftR] at hval have := c₁.isLt; omega | none => rw [hf1] at h1 cases hp1 : P.col s(u, v₁) with | none => simp [hp1] at h1 | some r₁ => rw [hp1] at h1 have hc1 : liftR r₁ = c := Option.some.inj (by simpa using h1) cases hf2 : colF s(u, v₂) with | some c₂ => rw [hf2] at h2 have hc2 : liftF c₂ = c := Option.some.inj h2 have hval := congrArg Fin.val (hc1.trans hc2.symm) dsimp [liftF, liftR] at hval have := c₂.isLt; omega | none => rw [hf2] at h2 cases hp2 : P.col s(u, v₂) with | none => simp [hp2] at h2 | some r₂ => rw [hp2] at h2 have hc2 : liftR r₂ = c := Option.some.inj (by simpa using h2) have heqr : r₁ = r₂ := Fin.ext (by have := congrArg Fin.val (hc1.trans hc2.symm) dsimp [liftR] at this; omega) exact P.proper u v₁ v₂ r₁ hp1 (heqr ▸ hp2) · intro u v c h dsimp [ecol] at h cases hf : colF s(u, v) with | some c₁ => rw [hf] at h have hc : liftF c₁ = c := Option.some.inj h have hmem := (hcolF_supp u v c₁ hf).2 rw [Finset.mem_filter] at hmem intro hEq have hval := congrArg Fin.val (hc.trans hEq) exact hmem.2 u (Sym2.mem_mk_left u v) hval | none => rw [hf] at h cases hp : P.col s(u, v) with | none => simp [hp] at h | some r₁ => rw [hp] at h have hc : liftR r₁ = c := Option.some.inj (by simpa using h) intro hEq have hval := congrArg Fin.val (hc.trans hEq) dsimp [liftR, vcol] at hval have := (vcol0 u).isLt; omega /-- **MAIN THEOREM (Total Coloring Conjecture for `k`-Degenerate Graphs, `Δ ≥ 3k`):** Every `k`-degenerate finite simple graph `G` with `3 * k ≤ G.maxDegree` satisfies the Total Coloring Conjecture `G.totalChromaticNumber ≤ G.maxDegree + 2` (verbatim signature of `FormalConjectures/Wikipedia/TotalColoringConjecture.lean`). Strictly improves the 19-year-old threshold `Δ ≥ 4k + 3` of Isobe–Zhou–Nishizeki (*Combinatorica* 27(2), 2007) by `k + 3` for every `k ≥ 1`. -/ theorem total_coloring_conjecture_of_isDegenerate_ge_three_mul {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] {k : ℕ} (hdeg : IsDegenerate G k) (hge : 3 * k ≤ G.maxDegree) : G.totalChromaticNumber ≤ G.maxDegree + 2 := Nat.sInf_le (totalColorable_of_isDegenerate_ge_three_mul G hdeg (fun v ↦ by convert G.degree_le_maxDegree v) hge) /-- **Corollary 1 (4-Degenerate TCC Frontier, `Δ ≥ 12`):** Every `4`-degenerate finite simple graph `G` with `Δ(G) ≥ 12` satisfies `χ''(G) ≤ Δ(G) + 2`, closing the 7 values `Δ ∈ {12, 13, 14, 15, 16, 17, 18}` below Isobe–Zhou–Nishizeki's `Δ ≥ 19`. -/ theorem total_coloring_conjecture_four_degenerate {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hdeg : IsDegenerate G 4) (hge : 12 ≤ G.maxDegree) : G.totalChromaticNumber ≤ G.maxDegree + 2 := total_coloring_conjecture_of_isDegenerate_ge_three_mul G hdeg hge /-- **Corollary 2 (5-Degenerate TCC Frontier, `Δ ≥ 15`):** Every `5`-degenerate finite simple graph `G` with `Δ(G) ≥ 15` satisfies `χ''(G) ≤ Δ(G) + 2`, closing the 8 values `Δ ∈ {15, 16, 17, 18, 19, 20, 21, 22}` below Isobe–Zhou–Nishizeki's `Δ ≥ 23`. -/ theorem total_coloring_conjecture_five_degenerate {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hdeg : IsDegenerate G 5) (hge : 15 ≤ G.maxDegree) : G.totalChromaticNumber ≤ G.maxDegree + 2 := total_coloring_conjecture_of_isDegenerate_ge_three_mul G hdeg hge /-- The subgraph formed by two color classes `c0, c1` of a partial edge coloring `P`. -/ def twoColorGraph {V : Type*} {G : SimpleGraph V} {Δ : ℕ} (P : PartialEdgeColoring G Δ) (c0 c1 : Fin Δ) : SimpleGraph V where Adj u v := P.col s(u, v) = some c0 ∨ P.col s(u, v) = some c1 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 G.loopless.irrefl v (P.supported v v _ h)⟩ /-- **Helper Lemma (Union of Two Matchings is Bipartite):** In any partial edge coloring `P` of `G`, the subgraph `twoColorGraph P c0 c1` formed by two color classes `c0, c1` has maximum degree at most `2` and is bipartite (every closed walk has even length). -/ lemma isBipartite_union_two_matchings {V : Type*} [Fintype V] {G : SimpleGraph V} {Δ : ℕ} (P : PartialEdgeColoring G Δ) (c0 c1 : Fin Δ) : (∀ v, (twoColorGraph P c0 c1).degree v ≤ 2) ∧ ∃ side : V → Bool, ∀ u v, (twoColorGraph P c0 c1).Adj u v → side u ≠ side v := by let F := twoColorGraph P c0 c1 have hFdeg : ∀ v, F.degree v ≤ 2 := by intro v rw [← SimpleGraph.card_neighborFinset_eq_degree] let S0 := Finset.univ.filter (fun w ↦ P.col s(v, w) = some c0) let S1 := Finset.univ.filter (fun w ↦ P.col s(v, w) = some c1) have hsub : F.neighborFinset v ⊆ S0 ∪ S1 := by intro 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⟩ have hS0 : S0.card ≤ 1 := Finset.card_le_one.mpr fun a ha b hb ↦ P.proper v a b c0 (Finset.mem_filter.mp ha).2 (Finset.mem_filter.mp hb).2 have hS1 : S1.card ≤ 1 := Finset.card_le_one.mpr fun a ha b hb ↦ P.proper v a b c1 (Finset.mem_filter.mp ha).2 (Finset.mem_filter.mp hb).2 exact le_trans (Finset.card_le_card hsub) (le_trans (Finset.card_union_le S0 S1) (by omega)) refine ⟨hFdeg, ?_⟩ have hF_even : ∀ (v : V) (w : F.Walk v v), Even w.length := by intro v w by_contra hodd rw [Nat.not_even_iff_odd] at hodd have hex_odd : ∃ m : ℕ, Odd m ∧ ∃ u : V, ∃ p : F.Walk u u, p.length = m := ⟨w.length, hodd, v, w, rfl⟩ let m₀ := Nat.find hex_odd obtain ⟨hm₀_odd, u₀, p₀, hp₀_len⟩ := Nat.find_spec hex_odd have hm₀_ge3 : 3 ≤ m₀ := by rcases hm₀_odd with ⟨r, hr⟩ by_cases hr0 : r = 0 · subst hr0 have hp1 : p₀.length = 1 := by omega cases p₀ with | nil => simp at hp1 | cons h q => simp only [SimpleGraph.Walk.length_cons] at hp1 have hq0 : q.length = 0 := by omega have hEq := SimpleGraph.Walk.eq_of_length_eq_zero hq0 subst hEq exact absurd h (F.loopless.irrefl _) · omega have hbuild : ∀ (a b : ℕ), a ≤ b → b ≤ m₀ → ∃ q : F.Walk (p₀.getVert a) (p₀.getVert b), q.length = b - a := by intro a b hab hbm induction b with | zero => have ha0 : a = 0 := by omega subst ha0; exact ⟨SimpleGraph.Walk.nil, rfl⟩ | succ b ihb => by_cases hab' : a = b + 1 · subst hab'; exact ⟨SimpleGraph.Walk.nil, by simp⟩ · obtain ⟨q, hqlen⟩ := ihb (by omega) (by omega) have hadj : F.Adj (p₀.getVert b) (p₀.getVert (b + 1)) := p₀.adj_getVert_succ (by omega) exact ⟨q.concat hadj, by simp [hqlen]; omega⟩ have hstep_ne : ∀ i (hi : i + 1 < m₀), P.col s(p₀.getVert i, p₀.getVert (i + 1)) ≠ P.col s(p₀.getVert (i + 1), p₀.getVert (i + 2)) := by intro i hi hEq have h1 : F.Adj (p₀.getVert i) (p₀.getVert (i + 1)) := p₀.adj_getVert_succ (by omega) have hv_eq : p₀.getVert i = p₀.getVert (i + 2) := by rcases h1 with h10 | h11 · rw [h10] at hEq exact P.proper (p₀.getVert (i + 1)) _ _ c0 (by rwa [Sym2.eq_swap]) hEq.symm · rw [h11] at hEq exact P.proper (p₀.getVert (i + 1)) _ _ c1 (by rwa [Sym2.eq_swap]) hEq.symm obtain ⟨w1, hw1⟩ := hbuild 0 i (Nat.zero_le i) (by omega) obtain ⟨w2, hw2⟩ := hbuild (i + 2) m₀ (by omega) le_rfl have h0 : p₀.getVert 0 = u₀ := p₀.getVert_zero have hm : p₀.getVert m₀ = u₀ := by dsimp only [m₀]; rw [← hp₀_len]; exact p₀.getVert_length let wshort : F.Walk u₀ u₀ := (w1.copy h0 hv_eq).append (w2.copy rfl hm) have hlen_s : wshort.length = m₀ - 2 := by simp only [wshort, SimpleGraph.Walk.length_append, SimpleGraph.Walk.length_copy, hw1, hw2] omega have hodd_s : Odd (m₀ - 2) := by rcases hm₀_odd with ⟨r, hr⟩; exact ⟨r - 1, by omega⟩ exact Nat.find_min hex_odd (show m₀ - 2 < m₀ by omega) ⟨hodd_s, u₀, wshort, hlen_s⟩ have hwrap_ne : P.col s(p₀.getVert (m₀ - 1), p₀.getVert m₀) ≠ P.col s(p₀.getVert 0, p₀.getVert 1) := by intro hEq have hlast : F.Adj (p₀.getVert (m₀ - 1)) (p₀.getVert m₀) := by have := p₀.adj_getVert_succ (show m₀ - 1 < p₀.length by omega) rwa [show m₀ - 1 + 1 = m₀ by omega] at this have h0 : p₀.getVert 0 = u₀ := p₀.getVert_zero have hm : p₀.getVert m₀ = u₀ := by dsimp only [m₀]; rw [← hp₀_len]; exact p₀.getVert_length have hv_eq : p₀.getVert (m₀ - 1) = p₀.getVert 1 := by rw [h0, hm] at hEq rw [hm] at hlast rcases hlast with h10 | h11 · rw [h10] at hEq exact P.proper u₀ _ _ c0 (by rwa [Sym2.eq_swap]) hEq.symm · rw [h11] at hEq exact P.proper u₀ _ _ c1 (by rwa [Sym2.eq_swap]) hEq.symm obtain ⟨wmid, hwmid⟩ := hbuild 1 (m₀ - 1) (by omega) (by omega) let wshort : F.Walk (p₀.getVert 1) (p₀.getVert 1) := wmid.copy rfl hv_eq have hlen_s : wshort.length = m₀ - 2 := by simp only [wshort, SimpleGraph.Walk.length_copy, hwmid]; omega have hodd_s : Odd (m₀ - 2) := by rcases hm₀_odd with ⟨r, hr⟩; exact ⟨r - 1, by omega⟩ exact Nat.find_min hex_odd (show m₀ - 2 < m₀ by omega) ⟨hodd_s, _, wshort, hlen_s⟩ have h0adj : F.Adj (p₀.getVert 0) (p₀.getVert 1) := p₀.adj_getVert_succ (by omega) have halt : ∀ i (hi : i < m₀), (Even i → P.col s(p₀.getVert i, p₀.getVert (i + 1)) = P.col s(p₀.getVert 0, p₀.getVert 1)) ∧ (Odd i → P.col s(p₀.getVert i, p₀.getVert (i + 1)) ≠ P.col s(p₀.getVert 0, p₀.getVert 1)) := by intro i induction i with | zero => intro _; exact ⟨fun _ ↦ rfl, fun h ↦ by simp at h⟩ | succ i ihi => intro hi obtain ⟨hev, hod⟩ := ihi (by omega) have hne := hstep_ne i hi have hadj_i : F.Adj (p₀.getVert i) (p₀.getVert (i + 1)) := p₀.adj_getVert_succ (by omega) have hadj_s : F.Adj (p₀.getVert (i + 1)) (p₀.getVert (i + 2)) := p₀.adj_getVert_succ (by omega) constructor · intro hev_s have hodd_i : Odd i := by rcases hev_s with ⟨r, hr⟩; exact ⟨r - 1, by omega⟩ have hni := hod hodd_i rcases h0adj with h00 | h01 <;> rcases hadj_i with hi0 | hi1 <;> rcases hadj_s with hs0 | hs1 all_goals simp_all · intro hodd_s have hev_i : Even i := by rcases hodd_s with ⟨r, hr⟩; exact ⟨r, by omega⟩ have hei := hev hev_i rw [hei] at hne exact hne.symm have hlast_even : Even (m₀ - 1) := by rcases hm₀_odd with ⟨r, hr⟩; exact ⟨r, by omega⟩ have hlast_eq := (halt (m₀ - 1) (by omega)).1 hlast_even rw [show m₀ - 1 + 1 = m₀ by omega] at hlast_eq exact hwrap_ne hlast_eq let rep : V → V := fun v ↦ (F.connectedComponentMk v).exists_rep.choose have hrep_eq : ∀ u v, F.Adj u v → rep u = rep v := by intro u v huv have hcc : F.connectedComponentMk u = F.connectedComponentMk v := SimpleGraph.ConnectedComponent.eq.mpr huv.reachable simp only [rep, hcc] have hrep_reach : ∀ v, F.Reachable (rep v) v := fun v ↦ SimpleGraph.ConnectedComponent.exact ((F.connectedComponentMk v).exists_rep.choose_spec) let side : V → Bool := fun v ↦ decide (Even (hrep_reach v).some.length) refine ⟨side, fun u v huv hEq ↦ ?_⟩ have hr := hrep_eq u v huv let wu : F.Walk (rep u) u := (hrep_reach u).some let wv : F.Walk (rep v) v := (hrep_reach v).some let wclosed : F.Walk (rep u) (rep u) := (wu.concat huv).append (wv.reverse.copy rfl hr.symm) have hev := hF_even (rep u) wclosed simp only [wclosed, SimpleGraph.Walk.length_append, SimpleGraph.Walk.length_concat, SimpleGraph.Walk.length_copy, SimpleGraph.Walk.length_reverse] at hev dsimp [side] at hEq have hiff : Even wu.length ↔ Even wv.length := by simpa only [decide_eq_decide] using hEq by_cases hu : Even wu.length · have hv : Even wv.length := hiff.mp hu rcases hu with ⟨a, ha⟩; rcases hv with ⟨b, hb⟩; rcases hev with ⟨c, hc⟩; omega · have hv : ¬Even wv.length := fun hv' ↦ hu (hiff.mpr hv') rw [Nat.not_even_iff_odd] at hu hv rcases hu with ⟨a, ha⟩; rcases hv with ⟨b, hb⟩; rcases hev with ⟨c, hc⟩; omega /-- **Theorem (4-Colorable Class-1 Graphs Satisfy TCC via Galvin's Theorem):** Every finite simple graph `G` that is properly `4`-vertex-colorable and Class 1 (`IsEdgeColorable G Δ`) with `2 ≤ Δ` satisfies `G.TotalColorable (Δ + 2)`. -/ theorem totalColorable_of_four_colorable_class_one {V : Type*} [Fintype V] (G : SimpleGraph V) {Δ : ℕ} (hvcol : ∃ c : V → Fin 4, ∀ u v, G.Adj u v → c u ≠ c v) (hecol : IsEdgeColorable G Δ) (hΔ2 : 2 ≤ Δ) : G.TotalColorable (Δ + 2) := by obtain ⟨cV, hcV⟩ := hvcol obtain ⟨P, hPtot⟩ := hecol let vmap : Fin 4 → Fin (Δ + 2) := fun i ↦ match i.val with | 0 => ⟨0, by omega⟩ | 1 => ⟨1, by omega⟩ | 2 => ⟨Δ, by omega⟩ | _ => ⟨Δ + 1, by omega⟩ have hvmap_inj : Function.Injective vmap := by rintro ⟨a, ha⟩ ⟨b, hb⟩ hEq have hval : (vmap ⟨a, ha⟩).val = (vmap ⟨b, hb⟩).val := congrArg Fin.val hEq apply Fin.ext dsimp [vmap] at hval interval_cases a <;> interval_cases b <;> simp at hval <;> omega let vcol : V → Fin (Δ + 2) := fun v ↦ vmap (cV v) have hv_prop : ∀ u v, G.Adj u v → vcol u ≠ vcol v := fun u v huv hEq ↦ hcV u v huv (hvmap_inj hEq) let c0 : Fin Δ := ⟨0, by omega⟩ let c1 : Fin Δ := ⟨1, by omega⟩ let F := twoColorGraph P c0 c1 obtain ⟨hFdeg, side, hFbip⟩ := isBipartite_union_two_matchings P c0 c1 -- List edge color `F` with lists `{0, 1, Δ, Δ + 1} \ {vcol u, vcol v}` of size `2` via Galvin! let palette : Finset (Fin (Δ + 2)) := (Finset.univ : Finset (Fin 4)).image vmap have hpal_card : palette.card = 4 := by rw [Finset.card_image_of_injective _ hvmap_inj]; simp have hvcol_in_pal : ∀ v, vcol v ∈ palette := fun v ↦ Finset.mem_image.mpr ⟨cV v, Finset.mem_univ _, rfl⟩ let L : Sym2 V → Finset (Fin (Δ + 2)) := fun e ↦ palette.filter (fun c ↦ ∀ x ∈ e, c ≠ vcol x) have hLcard : ∀ u v, F.Adj u v → 2 ≤ (L s(u, v)).card := by intro u v huv have hL_eq : L s(u, v) = palette \ {vcol u, vcol v} := by ext c simp only [L, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_insert, Finset.mem_singleton, Sym2.mem_iff] constructor · rintro ⟨hcp, h⟩ refine ⟨hcp, ?_⟩ rintro (rfl | rfl) · exact h u (Or.inl rfl) rfl · exact h v (Or.inr rfl) rfl · rintro ⟨hcp, h⟩ refine ⟨hcp, fun x hx hEq ↦ ?_⟩ rcases hx with rfl | rfl · exact h (Or.inl hEq) · exact h (Or.inr hEq) have hsub : ({vcol u, vcol v} : Finset (Fin (Δ + 2))) ⊆ palette := by intro c hc rw [Finset.mem_insert, Finset.mem_singleton] at hc rcases hc with rfl | rfl <;> exact hvcol_in_pal _ rw [hL_eq, Finset.card_sdiff_of_subset hsub, hpal_card] have hpair : ({vcol u, vcol v} : Finset (Fin (Δ + 2))).card ≤ 2 := Finset.card_le_two omega obtain ⟨colF, hcolF_supp, hcolF_tot, hcolF_prop⟩ := galvin_bipartite_list_edge_coloring F side hFbip 2 hFdeg L hLcard -- Combine `colF` (on `F`, values in `palette = {0, 1, Δ, Δ+1}`) and `P.col` (on `G \ F`, values in `{2, …, Δ-1}`)! let liftP : Fin Δ → Fin (Δ + 2) := fun c ↦ ⟨c.val, by have := c.isLt; omega⟩ let ecol : Sym2 V → Option (Fin (Δ + 2)) := fun e ↦ match colF e with | some c => some c | none => (P.col e).map liftP have hpal_val : ∀ c ∈ palette, c.val = 0 ∨ c.val = 1 ∨ c.val = Δ ∨ c.val = Δ + 1 := by intro c hc obtain ⟨⟨i, hi⟩, _, rfl⟩ := Finset.mem_image.mp hc interval_cases i <;> simp [vmap] refine totalColorable_of_vertex_edge_coloring G (Δ + 2) vcol hv_prop ecol ?_ ?_ ?_ · intro u v huv dsimp [ecol] cases hf : colF s(u, v) with | some c => simp | none => have h2 := hPtot u v huv cases hp : P.col s(u, v) with | none => simp [hp] at h2 | some c => simp · intro u v₁ v₂ c h1 h2 dsimp [ecol] at h1 h2 cases hf1 : colF s(u, v₁) with | some c₁ => rw [hf1] at h1 have hc1 : c₁ = c := Option.some.inj h1 have hpal1 := hpal_val c₁ (Finset.mem_filter.mp (hcolF_supp u v₁ c₁ hf1).2).1 cases hf2 : colF s(u, v₂) with | some c₂ => rw [hf2] at h2 have hc2 : c₂ = c := Option.some.inj h2 exact hcolF_prop u v₁ v₂ c₁ hf1 (hc1.trans hc2.symm ▸ hf2) | none => rw [hf2] at h2 cases hp2 : P.col s(u, v₂) with | none => simp [hp2] at h2 | some r₂ => rw [hp2] at h2 have hc2 : liftP r₂ = c := Option.some.inj (by simpa using h2) have hnotF2 : ¬F.Adj u v₂ := fun hF ↦ by have := hcolF_tot u v₂ hF; simp [hf2] at this have hr2_ne0 : r₂ ≠ c0 := fun hEq ↦ hnotF2 (Or.inl (hEq ▸ hp2)) have hr2_ne1 : r₂ ≠ c1 := fun hEq ↦ hnotF2 (Or.inr (hEq ▸ hp2)) have hval : c₁.val = r₂.val := congrArg Fin.val (hc1.trans hc2.symm) have hlt := r₂.isLt have h0 : r₂.val ≠ 0 := fun h ↦ hr2_ne0 (Fin.ext h) have h1' : r₂.val ≠ 1 := fun h ↦ hr2_ne1 (Fin.ext h) omega | none => rw [hf1] at h1 cases hp1 : P.col s(u, v₁) with | none => simp [hp1] at h1 | some r₁ => rw [hp1] at h1 have hc1 : liftP r₁ = c := Option.some.inj (by simpa using h1) have hnotF1 : ¬F.Adj u v₁ := fun hF ↦ by have := hcolF_tot u v₁ hF; simp [hf1] at this have hr1_ne0 : r₁ ≠ c0 := fun hEq ↦ hnotF1 (Or.inl (hEq ▸ hp1)) have hr1_ne1 : r₁ ≠ c1 := fun hEq ↦ hnotF1 (Or.inr (hEq ▸ hp1)) cases hf2 : colF s(u, v₂) with | some c₂ => rw [hf2] at h2 have hc2 : c₂ = c := Option.some.inj h2 have hpal2 := hpal_val c₂ (Finset.mem_filter.mp (hcolF_supp u v₂ c₂ hf2).2).1 have hval : r₁.val = c₂.val := congrArg Fin.val (hc1.trans hc2.symm) have hlt := r₁.isLt have h0 : r₁.val ≠ 0 := fun h ↦ hr1_ne0 (Fin.ext h) have h1' : r₁.val ≠ 1 := fun h ↦ hr1_ne1 (Fin.ext h) omega | none => rw [hf2] at h2 cases hp2 : P.col s(u, v₂) with | none => simp [hp2] at h2 | some r₂ => rw [hp2] at h2 have hc2 : liftP r₂ = c := Option.some.inj (by simpa using h2) have heqr : r₁ = r₂ := Fin.ext (by have := congrArg Fin.val (hc1.trans hc2.symm) simpa [liftP] using this) exact P.proper u v₁ v₂ r₁ hp1 (heqr ▸ hp2) · intro u v c h dsimp [ecol] at h cases hf : colF s(u, v) with | some c₁ => rw [hf] at h have hc : c₁ = c := Option.some.inj h have hmem := (hcolF_supp u v c₁ hf).2 rw [Finset.mem_filter] at hmem exact hc ▸ hmem.2 u (Sym2.mem_mk_left u v) | none => rw [hf] at h cases hp : P.col s(u, v) with | none => simp [hp] at h | some r₁ => rw [hp] at h have hc : liftP r₁ = c := Option.some.inj (by simpa using h) have hnotF : ¬F.Adj u v := fun hF ↦ by have := hcolF_tot u v hF; simp [hf] at this have hr1_ne0 : r₁ ≠ c0 := fun hEq ↦ hnotF (Or.inl (hEq ▸ hp)) have hr1_ne1 : r₁ ≠ c1 := fun hEq ↦ hnotF (Or.inr (hEq ▸ hp)) have hpal := hpal_val (vcol u) (hvcol_in_pal u) intro hEq have hval := congrArg Fin.val (hc.trans hEq) dsimp [liftP] at hval have hlt := r₁.isLt have h0 : r₁.val ≠ 0 := fun h ↦ hr1_ne0 (Fin.ext h) have h1' : r₁.val ≠ 1 := fun h ↦ hr1_ne1 (Fin.ext h) omega /-- **Corollary 3 (3-Degenerate TCC for `Δ ≥ 6`):** Every `3`-degenerate finite simple graph with `Δ(G) ≥ 6` satisfies `χ''(G) ≤ Δ(G) + 2`. -/ theorem total_coloring_conjecture_three_degenerate_ge_six {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hdeg : IsDegenerate G 3) (hge : 6 ≤ G.maxDegree) : G.totalChromaticNumber ≤ G.maxDegree + 2 := Nat.sInf_le (totalColorable_of_four_colorable_class_one G (exists_vertex_coloring_of_isDegenerate hdeg) (class_one_of_degenerate G 3 G.maxDegree hdeg (by omega) (fun v ↦ by convert G.degree_le_maxDegree v)) (by omega)) /-- **Corollary 4 (2-Degenerate TCC for `Δ ≥ 4`):** Every `2`-degenerate finite simple graph with `Δ(G) ≥ 4` satisfies `χ''(G) ≤ Δ(G) + 2`. -/ theorem total_coloring_conjecture_two_degenerate_ge_four {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hdeg : IsDegenerate G 2) (hge : 4 ≤ G.maxDegree) : G.totalChromaticNumber ≤ G.maxDegree + 2 := Nat.sInf_le (totalColorable_of_four_colorable_class_one G (exists_vertex_coloring_of_isDegenerate (hdeg.mono (by omega))) (class_one_of_degenerate G 2 G.maxDegree hdeg (by omega) (fun v ↦ by convert G.degree_le_maxDegree v)) (by omega)) /-- **Theorem (Every Bipartite Graph Satisfies TCC for ALL `Δ`):** Every finite bipartite simple graph `G` satisfies `G.totalChromaticNumber ≤ G.maxDegree + 2`. -/ theorem total_coloring_conjecture_of_bipartite {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (side : V → Bool) (hbip : ∀ u v, G.Adj u v → side u ≠ side v) : G.totalChromaticNumber ≤ G.maxDegree + 2 := by let Δ := G.maxDegree let vcol : V → Fin (Δ + 2) := fun v ↦ if side v then ⟨1, by omega⟩ else ⟨0, by omega⟩ have hv_prop : ∀ u v, G.Adj u v → vcol u ≠ vcol v := by intro u v huv have hne := hbip u v huv dsimp [vcol] cases hsu : side u <;> cases hsv : side v <;> simp_all let L : Sym2 V → Finset (Fin (Δ + 2)) := fun _ ↦ Finset.univ.filter (fun c : Fin (Δ + 2) ↦ 2 ≤ c.val) have hLcard : ∀ u v, G.Adj u v → Δ ≤ (L s(u, v)).card := by intro u v _ let f : Fin Δ → Fin (Δ + 2) := fun i ↦ ⟨i.val + 2, by have := i.isLt; omega⟩ have hsub : (Finset.univ : Finset (Fin Δ)).image f ⊆ L s(u, v) := by intro c hc rw [Finset.mem_image] at hc obtain ⟨i, _, rfl⟩ := hc exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, by dsimp [f]; omega⟩ have hinj : Function.Injective f := by intro a b hEq have hval := congrArg Fin.val hEq dsimp [f] at hval exact Fin.ext (by omega) calc Δ = (Finset.univ : Finset (Fin Δ)).card := by simp _ = ((Finset.univ : Finset (Fin Δ)).image f).card := (Finset.card_image_of_injective _ hinj).symm _ ≤ (L s(u, v)).card := Finset.card_le_card hsub obtain ⟨colE, hcolE_supp, hcolE_tot, hcolE_prop⟩ := galvin_bipartite_list_edge_coloring G side hbip Δ (fun v ↦ by convert G.degree_le_maxDegree v) L hLcard apply Nat.sInf_le refine totalColorable_of_vertex_edge_coloring G (Δ + 2) vcol hv_prop colE hcolE_tot hcolE_prop ?_ intro u v c h hEq have hc2 : 2 ≤ c.val := (Finset.mem_filter.mp (hcolE_supp u v c h).2).2 have hval : c.val = (vcol u).val := congrArg Fin.val hEq have hvu : (vcol u).val ≤ 1 := by dsimp [vcol] cases side u <;> simp omega /-- **Corollary 5 (Every 1-Degenerate Graph / Forest Satisfies TCC for ALL `Δ`):** -/ theorem total_coloring_conjecture_one_degenerate {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hdeg : IsDegenerate G 1) : G.totalChromaticNumber ≤ G.maxDegree + 2 := by obtain ⟨c2, hc2⟩ := exists_vertex_coloring_of_isDegenerate hdeg let side : V → Bool := fun v ↦ decide ((c2 v).val = 1) refine total_coloring_conjecture_of_bipartite G side (fun u v huv hEq ↦ ?_) dsimp [side] at hEq have hu := (c2 u).isLt; have hv := (c2 v).isLt apply hc2 u v huv apply Fin.ext by_cases h1 : (c2 u).val = 1 <;> by_cases h2 : (c2 v).val = 1 · omega · simp [h1, h2] at hEq · simp [h1, h2] at hEq · omega /-- **Corollary 6 (Every Finite Acyclic Graph / Forest Satisfies TCC for ALL `Δ`):** -/ theorem total_coloring_conjecture_of_isAcyclic {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] (hacyc : G.IsAcyclic) : G.totalChromaticNumber ≤ G.maxDegree + 2 := total_coloring_conjecture_one_degenerate G (isDegenerate_of_isAcyclic hacyc) /-- **Universal Bound for ALL `k`-Degenerate Graphs (No `Δ` Lower Bound):** Every `k`-degenerate finite simple graph `G` satisfies `χ''(G) ≤ Δ(G) + k + 2` unconditionally (via `(k + 1)`-vertex coloring + Vizing `(Δ + 1)`-edge coloring), and whenever `3k ≤ Δ(G)`, the sharp TCC bound `χ''(G) ≤ Δ(G) + 2` holds. -/ theorem total_coloring_universal_degenerate_bound {V : Type} [Fintype V] [DecidableEq V] (G : SimpleGraph V) [DecidableRel G.Adj] {k : ℕ} (hdeg : IsDegenerate G k) : G.totalChromaticNumber ≤ G.maxDegree + k + 2 := by let Δ := G.maxDegree obtain ⟨vcol0, hvcol0⟩ := exists_vertex_coloring_of_isDegenerate hdeg obtain ⟨P, hPtot⟩ := vizing_theorem G Δ (fun v ↦ by convert G.degree_le_maxDegree v) let vcol : V → Fin (Δ + k + 2) := fun v ↦ ⟨(vcol0 v).val, by have := (vcol0 v).isLt; omega⟩ have hv_prop : ∀ u v, G.Adj u v → vcol u ≠ vcol v := by intro u v huv hEq have hval : (vcol u).val = (vcol v).val := congrArg Fin.val hEq exact hvcol0 u v huv (Fin.ext hval) let liftE : Fin (Δ + 1) → Fin (Δ + k + 2) := fun c ↦ ⟨k + 1 + c.val, by have := c.isLt; omega⟩ let ecol : Sym2 V → Option (Fin (Δ + k + 2)) := fun e ↦ (P.col e).map liftE apply Nat.sInf_le refine totalColorable_of_vertex_edge_coloring G (Δ + k + 2) vcol hv_prop ecol ?_ ?_ ?_ · intro u v huv dsimp [ecol] have h := hPtot u v huv cases hp : P.col s(u, v) with | none => simp [hp] at h | some c => simp · intro u v₁ v₂ c h1 h2 dsimp [ecol] at h1 h2 cases hp1 : P.col s(u, v₁) with | none => simp [hp1] at h1 | some c₁ => cases hp2 : P.col s(u, v₂) with | none => simp [hp2] at h2 | some c₂ => rw [hp1] at h1; rw [hp2] at h2 have heq1 : liftE c₁ = c := Option.some.inj (by simpa using h1) have heq2 : liftE c₂ = c := Option.some.inj (by simpa using h2) have hcc : c₁ = c₂ := Fin.ext (by have := congrArg Fin.val (heq1.trans heq2.symm) dsimp [liftE] at this; omega) exact P.proper u v₁ v₂ c₁ hp1 (hcc ▸ hp2) · intro u v c h hEq dsimp [ecol] at h cases hp : P.col s(u, v) with | none => simp [hp] at h | some c₁ => rw [hp] at h have heq1 : liftE c₁ = c := Option.some.inj (by simpa using h) have hval := congrArg Fin.val (heq1.trans hEq) dsimp [liftE, vcol] at hval have := (vcol0 u).isLt; omega end MainTheorems end DegenerateTotalColoring /-! ## Axiom Audit -/ #print axioms DegenerateTotalColoring.vizing_theorem #print axioms DegenerateTotalColoring.vizing_adjacency_lemma #print axioms DegenerateTotalColoring.class_one_of_degenerate #print axioms DegenerateTotalColoring.konig_bipartite_edge_coloring #print axioms DegenerateTotalColoring.exists_list_coloring_of_kernel_perfect #print axioms DegenerateTotalColoring.exists_kernel_galvin_orientation #print axioms DegenerateTotalColoring.galvin_bipartite_list_edge_coloring #print axioms DegenerateTotalColoring.exists_forward_greedy_bipartition #print axioms DegenerateTotalColoring.exists_bipartite_subgraph_degree_split #print axioms DegenerateTotalColoring.totalColorable_of_isDegenerate_ge_three_mul #print axioms DegenerateTotalColoring.total_coloring_conjecture_of_isDegenerate_ge_three_mul #print axioms DegenerateTotalColoring.total_coloring_conjecture_four_degenerate #print axioms DegenerateTotalColoring.total_coloring_conjecture_five_degenerate #print axioms DegenerateTotalColoring.totalColorable_of_four_colorable_class_one #print axioms DegenerateTotalColoring.total_coloring_conjecture_three_degenerate_ge_six #print axioms DegenerateTotalColoring.total_coloring_conjecture_two_degenerate_ge_four #print axioms DegenerateTotalColoring.total_coloring_conjecture_of_bipartite #print axioms DegenerateTotalColoring.total_coloring_conjecture_one_degenerate #print axioms DegenerateTotalColoring.total_coloring_conjecture_of_isAcyclic #print axioms DegenerateTotalColoring.total_coloring_universal_degenerate_bound