Lean / innov8ion/erdos64-diam3 / Erdos64Diam3.lean
Lean reader

Erdos64Diam3.lean

1,084 lines15 declarationsno sorryimports Mathlib.Combinatorics.SimpleGraph.Diam Mathlib.Combinatorics.SimpleGraph.Finite Mathlib.Combinatorics.SimpleGraph.Paths
  1. import Mathlib.Combinatorics.SimpleGraph.Diam
  2. import Mathlib.Combinatorics.SimpleGraph.Finite
  3. import Mathlib.Combinatorics.SimpleGraph.Paths
  4. /-!
  5. # Erdős–Gyárfás Conjecture for Graphs with Minimum Degree ≥ 4 and Diameter ≤ 3
  6. Independent audit and Lean 4 formalization of Murat Can Temeller's October 2026 theorem:
  7. every finite simple graph `G` with `G.minDegree ≥ 4` and diameter at most `3`
  8. (`G.ediam ≤ 3`, equivalently `G.Connected ∧ G.diam ≤ 3`) contains a simple cycle
  9. of length `4` or `8`, and therefore satisfies the Erdős–Gyárfás conjecture
  10. (Erdős Problem #64).
  11. ## Proof Overview
  12. Assume `G` has no `4`-cycle and no `8`-cycle. Then:
  13. * **(P1)** Any two distinct vertices have at most one common neighbor.
  14. * **(P2)** Every edge lies in at most one triangle.
  15. The proof splits into two cases:
  16. 1. **Case 1:** Every edge lies in a triangle. Fix `x`; its neighborhood partitions into
  17. triangles `x - y₁ - y₁'` and `x - y₂ - y₂'`. Choosing outer neighbors `z₁` of `y₁`
  18. and `z₂` of `y₂` and taking a walk of length `≤ 3` between `z₁` and `z₂` forces an `8`-cycle
  19. via triangle detours.
  20. 2. **Case 2:** Some edge `u ~ v` lies in no triangle. Let `A = N(u) \ {v}` and `B = N(v) \ {u}`.
  21. * **Step 1 (Bridges):** Common children of `A` and `B` form a star; swapping `u` and `v` if
  22. needed, all bridges attach to a single `b* ∈ B`. Pick `b ∈ B` distinct from `b*` and not
  23. adjacent to `b*`.
  24. * **Step 2 (Funnel):** Either at most one child of `b` is adjacent to a child of `A`, or all
  25. such children reach a unique `a₀ ∈ A`.
  26. * **Step 3 (Short connections):** For any child `x` of `a ∈ A` and child `y` of `b`, a walk of
  27. length `≤ 3` yields an edge `x ~ y`, a common neighbor outside `{u, v} ∪ A ∪ B`, another
  28. child of `a` adjacent to `y`, or another child of `b` adjacent to `x`.
  29. * **Step 4a / 4b:** Split on whether `b` has a partner in `B`; both cases yield a `4`-cycle
  30. or an `8`-cycle.
  31. -/
  32. namespace Erdos64Diam3
  33. open SimpleGraph
  34. section Helpers
  35. variable {V : Type*} {G : SimpleGraph V}
  36. /-- Four pairwise distinct vertices forming a closed walk of length 4 yield a 4-cycle. -/
  37. private lemma exists_cycle_four_of_nodup {v0 v1 v2 v3 : V}
  38. (h01 : G.Adj v0 v1) (h12 : G.Adj v1 v2) (h23 : G.Adj v2 v3) (h30 : G.Adj v3 v0)
  39. (h02 : v0 ≠ v2) (h13 : v1 ≠ v3) :
  40. ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4 := by
  41. have h01' : v0 ≠ v1 := h01.ne
  42. have h12' : v1 ≠ v2 := h12.ne
  43. have h23' : v2 ≠ v3 := h23.ne
  44. have h30' : v3 ≠ v0 := h30.ne
  45. let c : G.Walk v0 v0 :=
  46. Walk.cons h01 (Walk.cons h12 (Walk.cons h23 (Walk.cons h30 Walk.nil)))
  47. refine ⟨v0, c, ?_, rfl⟩
  48. rw [Walk.isCycle_def]
  49. refine ⟨⟨?_⟩, by simp [c], ?_⟩
  50. · simp [c, Walk.edges, h01', h01'.symm, h12', h23', h30', h30'.symm, h02, h02.symm, h13]
  51. · simp [c, Walk.support, h01'.symm, h12', h23', h30', h02.symm, h13]
  52. /-- Eight pairwise distinct vertices forming a closed walk of length 8 yield an 8-cycle. -/
  53. private lemma exists_cycle_eight_of_nodup {v0 v1 v2 v3 v4 v5 v6 v7 : V}
  54. (h01 : G.Adj v0 v1) (h12 : G.Adj v1 v2) (h23 : G.Adj v2 v3) (h34 : G.Adj v3 v4)
  55. (h45 : G.Adj v4 v5) (h56 : G.Adj v5 v6) (h67 : G.Adj v6 v7) (h70 : G.Adj v7 v0)
  56. (hnodup : ([v0, v1, v2, v3, v4, v5, v6, v7] : List V).Nodup) :
  57. ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 8 := by
  58. simp only [List.nodup_cons, List.mem_cons, List.not_mem_nil, or_false, not_or,
  59. List.nodup_nil, and_true, ← ne_eq] at hnodup
  60. rcases hnodup with
  61. ⟨⟨h01', h02, h03, h04, h05, h06, h07⟩,
  62. ⟨h12', h13, h14, h15, h16, h17⟩,
  63. ⟨h23', h24, h25, h26, h27⟩,
  64. ⟨h34', h35, h36, h37⟩,
  65. ⟨h45', h46, h47⟩,
  66. ⟨h56', h57⟩,
  67. h67'⟩
  68. let c : G.Walk v0 v0 :=
  69. Walk.cons h01 (Walk.cons h12 (Walk.cons h23 (Walk.cons h34
  70. (Walk.cons h45 (Walk.cons h56 (Walk.cons h67 (Walk.cons h70 Walk.nil)))))))
  71. refine ⟨v0, c, ?_, rfl⟩
  72. rw [Walk.isCycle_def]
  73. refine ⟨⟨?_⟩, by simp [c], ?_⟩
  74. · simp [c, Walk.edges,
  75. h01', h01'.symm, h02, h02.symm, h03, h03.symm, h04, h04.symm,
  76. h05, h05.symm, h06, h06.symm, h07, h07.symm,
  77. h12', h13, h14, h15, h16, h17,
  78. h23', h24, h25, h26, h27,
  79. h34', h35, h36, h37,
  80. h45', h46, h47, h56', h57, h67']
  81. · simp [c, Walk.support,
  82. h01'.symm, h02.symm, h03.symm, h04.symm, h05.symm, h06.symm, h07.symm,
  83. h12', h13, h14, h15, h16, h17,
  84. h23', h24, h25, h26, h27,
  85. h34', h35, h36, h37,
  86. h45', h46, h47, h56', h57, h67']
  87. /-- **(P1)** If `G` has no 4-cycle, any two distinct vertices have at most one common neighbor. -/
  88. private lemma eq_of_common_neighbors
  89. (hno4 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4)
  90. {x y w1 w2 : V} (hxy : x ≠ y)
  91. (hx1 : G.Adj x w1) (hy1 : G.Adj y w1) (hx2 : G.Adj x w2) (hy2 : G.Adj y w2) :
  92. w1 = w2 := by
  93. by_contra h12
  94. exact hno4 (exists_cycle_four_of_nodup hx1 hy1.symm hy2 hx2.symm hxy h12)
  95. /-- Any two distinct vertices at extended distance ≤ 3 are joined by an edge, a 2-path,
  96. or a simple 3-path. -/
  97. private lemma exists_short_path {x y : V} (hxy : x ≠ y) (hd : G.edist x y ≤ 3) :
  98. G.Adj x y ∨
  99. (∃ w : V, G.Adj x w ∧ G.Adj w y) ∨
  100. (∃ p q : V, G.Adj x p ∧ G.Adj p q ∧ G.Adj q y ∧
  101. p ≠ x ∧ p ≠ y ∧ q ≠ x ∧ q ≠ y ∧ p ≠ q) := by
  102. have hne_top : G.edist x y ≠ ⊤ := ne_top_of_le_ne_top (by simp) hd
  103. obtain ⟨W, hW⟩ := G.exists_walk_of_edist_ne_top hne_top
  104. have hlen : W.length ≤ 3 := by
  105. have : (W.length : ℕ∞) ≤ (3 : ℕ) := by simpa [hW] using hd
  106. exact Nat.cast_le.mp this
  107. cases W with
  108. | nil => exact (hxy rfl).elim
  109. | @cons _ p _ h1 W1 =>
  110. cases W1 with
  111. | nil => exact Or.inl h1
  112. | @cons _ q _ h2 W2 =>
  113. cases W2 with
  114. | nil => exact Or.inr (Or.inl ⟨p, h1, h2⟩)
  115. | @cons _ r _ h3 W3 =>
  116. cases W3 with
  117. | nil =>
  118. by_cases hpy : p = y
  119. · subst hpy; exact Or.inl h1
  120. · by_cases hqx : q = x
  121. · subst hqx; exact Or.inl h3
  122. · exact Or.inr (Or.inr ⟨p, q, h1, h2, h3, h1.ne.symm, hpy, hqx, h3.ne, h2.ne⟩)
  123. | cons _ _ =>
  124. simp only [Walk.length_cons] at hlen
  125. omega
  126. /-- Version-independent cardinality bound for `Finset.sdiff`. -/
  127. private lemma le_card_sdiff_add_card {α : Type*} [DecidableEq α] (s t : Finset α) :
  128. s.card ≤ (s \ t).card + t.card := by
  129. calc s.card ≤ ((s \ t) ∪ t).card := Finset.card_le_card (fun a ha => by
  130. by_cases h : a ∈ t
  131. · exact Finset.mem_union_right _ h
  132. · exact Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨ha, h⟩))
  133. _ ≤ (s \ t).card + t.card := Finset.card_union_le _ _
  134. /-- A `Finset` of cardinality at least 2 contains two distinct elements. -/
  135. private lemma exists_two_of_two_le_card {α : Type*} {s : Finset α} (h : 2 ≤ s.card) :
  136. ∃ a ∈ s, ∃ b ∈ s, a ≠ b :=
  137. Finset.one_lt_card.mp (by omega)
  138. /-- If every two pairs satisfying `R` share a coordinate, then all pairs share a single
  139. fixed first coordinate or a single fixed second coordinate. -/
  140. private lemma star_of_pairwise_share_coord {α : Type*} [Nonempty α] (R : α → α → Prop)
  141. (h : ∀ a1 b1 a2 b2, R a1 b1 → R a2 b2 → a1 = a2 ∨ b1 = b2) :
  142. (∃ a0, ∀ a b, R a b → a = a0) ∨ (∃ b0, ∀ a b, R a b → b = b0) := by
  143. by_cases hex : ∃ a1 b1 a2 b2, R a1 b1 ∧ R a2 b2 ∧ a1 ≠ a2
  144. · obtain ⟨a1, b1, a2, b2, h1, h2, ha12⟩ := hex
  145. have hb12 : b1 = b2 := (h a1 b1 a2 b2 h1 h2).resolve_left ha12
  146. subst hb12
  147. refine Or.inr ⟨b1, fun a b hab => ?_⟩
  148. by_contra hbb
  149. have ha1 : a = a1 := (h a b a1 b1 hab h1).resolve_right hbb
  150. have ha2 : a = a2 := (h a b a2 b1 hab h2).resolve_right hbb
  151. exact ha12 (ha1.symm.trans ha2)
  152. · have hex' : ∀ a1 b1 a2 b2, R a1 b1 → R a2 b2 → a1 = a2 := by
  153. intro a1 b1 a2 b2 h1 h2
  154. by_contra hne
  155. exact hex ⟨a1, b1, a2, b2, h1, h2, hne⟩
  156. by_cases hne : ∃ a0 b0, R a0 b0
  157. · obtain ⟨a0, b0, h0⟩ := hne
  158. exact Or.inl ⟨a0, fun a b hab => hex' a b a0 b0 hab h0⟩
  159. · exact Or.inl ⟨Classical.arbitrary α, fun a b hab => (hne ⟨a, b, hab⟩).elim⟩
  160. end Helpers
  161. section Case1
  162. variable {V : Type*} [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj]
  163. /-- **Case 1:** Every edge lies in a triangle. -/
  164. private lemma case1_all_edges_in_triangle
  165. [Nonempty V]
  166. (hdeg : ∀ v : V, 4 ≤ G.degree v)
  167. (hdiam : ∀ u v : V, G.edist u v ≤ 3)
  168. (hno4 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4)
  169. (hno8 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 8)
  170. (htri : ∀ u v : V, G.Adj u v → ∃ t : V, G.Adj u t ∧ G.Adj v t) :
  171. False := by
  172. let x : V := Classical.arbitrary V
  173. have hx_card : 4 ≤ (G.neighborFinset x).card := by
  174. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg x
  175. obtain ⟨y1, hy1_mem⟩ := Finset.card_pos.mp (by omega : 0 < (G.neighborFinset x).card)
  176. have hxy1 : G.Adj x y1 := (mem_neighborFinset G x y1).mp hy1_mem
  177. obtain ⟨y1', hxy1', hy1y1'⟩ := htri x y1 hxy1
  178. have hcard_rem : 2 ≤ (G.neighborFinset x \ {y1, y1'}).card := by
  179. have h1 := le_card_sdiff_add_card (G.neighborFinset x) {y1, y1'}
  180. have h2 : ({y1, y1'} : Finset V).card ≤ 2 := Finset.card_le_two
  181. omega
  182. obtain ⟨y2, hy2_sdiff⟩ := Finset.card_pos.mp (by omega : 0 < (G.neighborFinset x \ {y1, y1'}).card)
  183. have hxy2 : G.Adj x y2 := (mem_neighborFinset G x y2).mp (Finset.mem_sdiff.mp hy2_sdiff).1
  184. have hy2_ne : y2 ≠ y1 ∧ y2 ≠ y1' := by
  185. simpa using (Finset.mem_sdiff.mp hy2_sdiff).2
  186. obtain ⟨y2', hxy2', hy2y2'⟩ := htri x y2 hxy2
  187. -- Pairwise distinctness of x, y1, y1', y2, y2'
  188. have hxy1_ne : x ≠ y1 := hxy1.ne
  189. have hxy1'_ne : x ≠ y1' := hxy1'.ne
  190. have hxy2_ne : x ≠ y2 := hxy2.ne
  191. have hxy2'_ne : x ≠ y2' := hxy2'.ne
  192. have hy1y1'_ne : y1 ≠ y1' := hy1y1'.ne
  193. have hy2y2'_ne : y2 ≠ y2' := hy2y2'.ne
  194. have hy2'_ne_y1 : y2' ≠ y1 := by
  195. rintro rfl
  196. have := eq_of_common_neighbors hno4 hxy1_ne hxy1' hy1y1' hxy2 hy2y2'.symm
  197. exact hy2_ne.2 this.symm
  198. have hy2'_ne_y1' : y2' ≠ y1' := by
  199. rintro rfl
  200. have := eq_of_common_neighbors hno4 hxy1'_ne hxy1 hy1y1'.symm hxy2 hy2y2'.symm
  201. exact hy2_ne.1 this.symm
  202. -- Helper: any outer neighbor of y ∈ N(x) (with partner y') is non-adjacent to x and unique to y.
  203. have outer_not_adj_x : ∀ {y y' z : V}, G.Adj x y → G.Adj x y' → G.Adj y y' →
  204. G.Adj y z → z ≠ x → z ≠ y' → ¬ G.Adj x z := by
  205. intro y y' z hxy hxy' hyy' hyz hzx hzy' hxz
  206. exact hzy' (eq_of_common_neighbors hno4 hxy.ne hxz hyz hxy' hyy')
  207. have outer_only_nbr_in_Nx : ∀ {y y' z y_other : V}, G.Adj x y → G.Adj x y' → G.Adj y y' →
  208. G.Adj y z → z ≠ x → z ≠ y' → G.Adj x y_other → G.Adj y_other z → y_other = y := by
  209. intro y y' z y_other hxy hxy' hyy' hyz hzx hzy' hxo hoz
  210. exact eq_of_common_neighbors hno4 (Ne.symm hzx) hxo hoz.symm hxy hyz.symm
  211. -- Subcase 1a packaged as a reusable lemma for ANY adjacent outer neighbors (u1 of y1, u2 of y2)
  212. have adj_outer_contra : ∀ {u1 u2 : V},
  213. G.Adj y1 u1 → u1 ≠ x → u1 ≠ y1' →
  214. G.Adj y2 u2 → u2 ≠ x → u2 ≠ y2' →
  215. G.Adj u1 u2 → False := by
  216. intro u1 u2 hy1u1 hu1x hu1y1' hy2u2 hu2x hu2y2' hu1u2
  217. obtain ⟨t, hu1t, hu2t⟩ := htri u1 u2 hu1u2
  218. have hu1_nx : ¬ G.Adj x u1 := outer_not_adj_x hxy1 hxy1' hy1y1' hy1u1 hu1x hu1y1'
  219. have hu2_nx : ¬ G.Adj x u2 := outer_not_adj_x hxy2 hxy2' hy2y2' hy2u2 hu2x hu2y2'
  220. have hu1_not_y2 : ¬ G.Adj y2 u1 := fun h =>
  221. hy2_ne.1 (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1u1 hu1x hu1y1' hxy2 h)
  222. have hu1_not_y1' : ¬ G.Adj y1' u1 := fun h =>
  223. hy1y1'_ne.symm (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1u1 hu1x hu1y1' hxy1' h)
  224. have hu1_not_y2' : ¬ G.Adj y2' u1 := fun h =>
  225. hy2'_ne_y1 (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1u1 hu1x hu1y1' hxy2' h)
  226. have hu2_not_y1 : ¬ G.Adj y1 u2 := fun h =>
  227. hy2_ne.1.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2u2 hu2x hu2y2' hxy1 h)
  228. have hu2_not_y1' : ¬ G.Adj y1' u2 := fun h =>
  229. hy2_ne.2.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2u2 hu2x hu2y2' hxy1' h)
  230. have hu2_not_y2' : ¬ G.Adj y2' u2 := fun h =>
  231. hy2y2'_ne.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2u2 hu2x hu2y2' hxy2' h)
  232. -- Cycle: x - y1' - y1 - u1 - t - u2 - y2 - y2' - x
  233. refine hno8 (exists_cycle_eight_of_nodup hxy1' hy1y1'.symm hy1u1 hu1t hu2t.symm
  234. hy2u2.symm hy2y2' hxy2'.symm ?_)
  235. have ht_x : t ≠ x := fun h => hu1_nx (h ▸ hu1t.symm)
  236. have ht_y1' : t ≠ y1' := fun h => hu1_not_y1' (h ▸ hu1t.symm)
  237. have ht_y1 : t ≠ y1 := fun h => hu2_not_y1 (h ▸ hu2t.symm)
  238. have ht_u1 : t ≠ u1 := hu1t.ne.symm
  239. have ht_u2 : t ≠ u2 := hu2t.ne.symm
  240. have ht_y2 : t ≠ y2 := fun h => hu1_not_y2 (h ▸ hu1t.symm)
  241. have ht_y2' : t ≠ y2' := fun h => hu2_not_y2' (h ▸ hu2t.symm)
  242. have hu1_y2 : u1 ≠ y2 := fun h => hu1_nx (h ▸ hxy2)
  243. have hu1_y2' : u1 ≠ y2' := fun h => hu1_nx (h ▸ hxy2')
  244. have hu2_y1 : u2 ≠ y1 := fun h => hu2_nx (h ▸ hxy1)
  245. have hu2_y1' : u2 ≠ y1' := fun h => hu2_nx (h ▸ hxy1')
  246. simp [hxy1'_ne, hxy1_ne, hu1x.symm, ht_x.symm, hu2x.symm, hxy2_ne, hxy2'_ne,
  247. hy1y1'_ne.symm, hu1y1'.symm, ht_y1'.symm, hu2_y1'.symm, hy2_ne.2.symm, hy2'_ne_y1'.symm,
  248. hy1u1.ne, ht_y1.symm, hu2_y1.symm, hy2_ne.1.symm, hy2'_ne_y1.symm,
  249. ht_u1.symm, hu1u2.ne, hu1_y2, hu1_y2', ht_u2, ht_y2, ht_y2',
  250. hy2u2.ne.symm, hu2y2', hy2y2'_ne]
  251. -- Pick outer neighbor z1 of y1 and outer neighbor z2 of y2
  252. have hz1_card : 2 ≤ (G.neighborFinset y1 \ {x, y1'}).card := by
  253. have h1 := le_card_sdiff_add_card (G.neighborFinset y1) {x, y1'}
  254. have h2 : ({x, y1'} : Finset V).card ≤ 2 := Finset.card_le_two
  255. have h3 : 4 ≤ (G.neighborFinset y1).card := by
  256. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg y1
  257. omega
  258. obtain ⟨z1, hz1_sdiff⟩ := Finset.card_pos.mp (by omega : 0 < (G.neighborFinset y1 \ {x, y1'}).card)
  259. have hy1z1 : G.Adj y1 z1 := (mem_neighborFinset G y1 z1).mp (Finset.mem_sdiff.mp hz1_sdiff).1
  260. have hz1_ne : z1 ≠ x ∧ z1 ≠ y1' := by simpa using (Finset.mem_sdiff.mp hz1_sdiff).2
  261. have hz2_card : 2 ≤ (G.neighborFinset y2 \ {x, y2'}).card := by
  262. have h1 := le_card_sdiff_add_card (G.neighborFinset y2) {x, y2'}
  263. have h2 : ({x, y2'} : Finset V).card ≤ 2 := Finset.card_le_two
  264. have h3 : 4 ≤ (G.neighborFinset y2).card := by
  265. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg y2
  266. omega
  267. obtain ⟨z2, hz2_sdiff⟩ := Finset.card_pos.mp (by omega : 0 < (G.neighborFinset y2 \ {x, y2'}).card)
  268. have hy2z2 : G.Adj y2 z2 := (mem_neighborFinset G y2 z2).mp (Finset.mem_sdiff.mp hz2_sdiff).1
  269. have hz2_ne : z2 ≠ x ∧ z2 ≠ y2' := by simpa using (Finset.mem_sdiff.mp hz2_sdiff).2
  270. have hz1_nx : ¬ G.Adj x z1 := outer_not_adj_x hxy1 hxy1' hy1y1' hy1z1 hz1_ne.1 hz1_ne.2
  271. have hz2_nx : ¬ G.Adj x z2 := outer_not_adj_x hxy2 hxy2' hy2y2' hy2z2 hz2_ne.1 hz2_ne.2
  272. have hz1z2_ne : z1 ≠ z2 := by
  273. rintro rfl
  274. exact hy2_ne.1 (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1z1 hz1_ne.1 hz1_ne.2 hxy2 hy2z2)
  275. have hz1_not_y2 : ¬ G.Adj y2 z1 := fun h =>
  276. hy2_ne.1 (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1z1 hz1_ne.1 hz1_ne.2 hxy2 h)
  277. have hz1_not_y1' : ¬ G.Adj y1' z1 := fun h =>
  278. hy1y1'_ne.symm (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1z1 hz1_ne.1 hz1_ne.2 hxy1' h)
  279. have hz1_not_y2' : ¬ G.Adj y2' z1 := fun h =>
  280. hy2'_ne_y1 (outer_only_nbr_in_Nx hxy1 hxy1' hy1y1' hy1z1 hz1_ne.1 hz1_ne.2 hxy2' h)
  281. have hz2_not_y1 : ¬ G.Adj y1 z2 := fun h =>
  282. hy2_ne.1.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2z2 hz2_ne.1 hz2_ne.2 hxy1 h)
  283. have hz2_not_y1' : ¬ G.Adj y1' z2 := fun h =>
  284. hy2_ne.2.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2z2 hz2_ne.1 hz2_ne.2 hxy1' h)
  285. have hz2_not_y2' : ¬ G.Adj y2' z2 := fun h =>
  286. hy2y2'_ne.symm (outer_only_nbr_in_Nx hxy2 hxy2' hy2y2' hy2z2 hz2_ne.1 hz2_ne.2 hxy2' h)
  287. have hz1_y2 : z1 ≠ y2 := fun h => hz1_nx (h ▸ hxy2)
  288. have hz1_y2' : z1 ≠ y2' := fun h => hz1_nx (h ▸ hxy2')
  289. have hz2_y1 : z2 ≠ y1 := fun h => hz2_nx (h ▸ hxy1)
  290. have hz2_y1' : z2 ≠ y1' := fun h => hz2_nx (h ▸ hxy1')
  291. -- Short path from z1 to z2
  292. rcases exists_short_path hz1z2_ne (hdiam z1 z2) with h1 | ⟨w, hz1w, hwz2⟩ |
  293. ⟨p, q, hz1p, hpq, hqz2, hpz1, hpz2, hqz1, hqz2_ne, hpq_ne⟩
  294. · -- Length 1
  295. exact adj_outer_contra hy1z1 hz1_ne.1 hz1_ne.2 hy2z2 hz2_ne.1 hz2_ne.2 h1
  296. · -- Length 2: x - y1' - y1 - z1 - w - z2 - y2 - y2' - x
  297. refine hno8 (exists_cycle_eight_of_nodup hxy1' hy1y1'.symm hy1z1 hz1w hwz2
  298. hy2z2.symm hy2y2' hxy2'.symm ?_)
  299. have hw_x : w ≠ x := fun h => hz1_nx (h ▸ hz1w.symm)
  300. have hw_y1' : w ≠ y1' := fun h => hz1_not_y1' (h ▸ hz1w.symm)
  301. have hw_y1 : w ≠ y1 := fun h => hz2_not_y1 (h ▸ hwz2)
  302. have hw_z1 : w ≠ z1 := hz1w.ne.symm
  303. have hw_z2 : w ≠ z2 := hwz2.ne
  304. have hw_y2 : w ≠ y2 := fun h => hz1_not_y2 (h ▸ hz1w.symm)
  305. have hw_y2' : w ≠ y2' := fun h => hz2_not_y2' (h ▸ hwz2)
  306. simp [hxy1'_ne, hxy1_ne, hz1_ne.1.symm, hw_x.symm, hz2_ne.1.symm, hxy2_ne, hxy2'_ne,
  307. hy1y1'_ne.symm, hz1_ne.2.symm, hw_y1'.symm, hz2_y1'.symm, hy2_ne.2.symm, hy2'_ne_y1'.symm,
  308. hy1z1.ne, hw_y1.symm, hz2_y1.symm, hy2_ne.1.symm, hy2'_ne_y1.symm,
  309. hw_z1.symm, hz1z2_ne, hz1_y2, hz1_y2', hw_z2, hw_y2, hw_y2',
  310. hy2z2.ne.symm, hz2_ne.2, hy2y2'_ne]
  311. · -- Length 3: z1 - p - q - z2
  312. by_cases hpy1 : p = y1
  313. · -- p = y1: q is an outer neighbor of y1 adjacent to z2
  314. subst hpy1
  315. have hqx : q ≠ x := fun h => hz2_nx (h ▸ hqz2)
  316. have hqy1' : q ≠ y1' := fun h => hz2_not_y1' (h ▸ hqz2)
  317. exact adj_outer_contra hpq hqx hqy1' hy2z2 hz2_ne.1 hz2_ne.2 hqz2
  318. · by_cases hqy2 : q = y2
  319. · -- q = y2: p is an outer neighbor of y2 adjacent to z1
  320. subst hqy2
  321. have hpx : p ≠ x := fun h => hz1_nx (h ▸ hz1p.symm)
  322. have hpy2' : p ≠ y2' := fun h => hz1_not_y2' (h ▸ hz1p.symm)
  323. exact adj_outer_contra hy1z1 hz1_ne.1 hz1_ne.2 hpq.symm hpx hpy2' hz1p
  324. · -- Otherwise: x - y1' - y1 - z1 - p - q - z2 - y2 - x
  325. refine hno8 (exists_cycle_eight_of_nodup hxy1' hy1y1'.symm hy1z1 hz1p hpq hqz2
  326. hy2z2.symm hxy2.symm ?_)
  327. have hp_x : p ≠ x := fun h => hz1_nx (h ▸ hz1p.symm)
  328. have hp_y1' : p ≠ y1' := fun h => hz1_not_y1' (h ▸ hz1p.symm)
  329. have hp_y2 : p ≠ y2 := fun h => hz1_not_y2 (h ▸ hz1p.symm)
  330. have hq_x : q ≠ x := fun h => hz2_nx (h ▸ hqz2)
  331. have hq_y1' : q ≠ y1' := fun h => hz2_not_y1' (h ▸ hqz2)
  332. have hq_y1 : q ≠ y1 := fun h => hz2_not_y1 (h ▸ hqz2)
  333. simp [hxy1'_ne, hxy1_ne, hz1_ne.1.symm, hp_x.symm, hq_x.symm, hz2_ne.1.symm, hxy2_ne,
  334. hy1y1'_ne.symm, hz1_ne.2.symm, hp_y1'.symm, hq_y1'.symm, hz2_y1'.symm, hy2_ne.2.symm,
  335. hy1z1.ne, Ne.symm hpy1, hq_y1.symm, hz2_y1.symm, hy2_ne.1.symm,
  336. hpz1.symm, hqz1.symm, hz1z2_ne, hz1_y2,
  337. hpq_ne, hpz2, hp_y2, hqz2_ne, hqy2, hy2z2.ne.symm]
  338. end Case1
  339. section Case2
  340. variable {V : Type*} [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj]
  341. /-- **Case 2 (oriented):** Given a triangle-free edge `u ~ v` such that all bridges attach to a
  342. single vertex `bstar ∈ B = N(v) \ {u}`, derive a contradiction. -/
  343. private lemma case2_oriented
  344. (hdeg : ∀ v : V, 4 ≤ G.degree v)
  345. (hdiam : ∀ x y : V, G.edist x y ≤ 3)
  346. (hno4 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4)
  347. (hno8 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 8)
  348. {u v : V} (huv : G.Adj u v)
  349. (hnotri : ∀ t : V, ¬ (G.Adj u t ∧ G.Adj v t))
  350. (bstar : V) (hbstar_B : bstar ∈ G.neighborFinset v \ {u})
  351. (hbstar_all : ∀ a ∈ G.neighborFinset u \ {v}, ∀ b ∈ G.neighborFinset v \ {u},
  352. ∀ z : V, z ∈ G.neighborFinset a \ insert u (G.neighborFinset u \ {v}) →
  353. z ∈ G.neighborFinset b \ insert v (G.neighborFinset v \ {u}) →
  354. b = bstar) :
  355. False := by
  356. set A : Finset V := G.neighborFinset u \ {v}
  357. set B : Finset V := G.neighborFinset v \ {u}
  358. have huv_ne : u ≠ v := huv.ne
  359. -- Basic facts about A and B
  360. have hA_card : 3 ≤ A.card := by
  361. have h1 : (G.neighborFinset u).card ≤ A.card + ({v} : Finset V).card :=
  362. le_card_sdiff_add_card (G.neighborFinset u) {v}
  363. have h2 : 4 ≤ (G.neighborFinset u).card := by
  364. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg u
  365. simp only [Finset.card_singleton] at h1
  366. omega
  367. have hB_card : 3 ≤ B.card := by
  368. have h1 : (G.neighborFinset v).card ≤ B.card + ({u} : Finset V).card :=
  369. le_card_sdiff_add_card (G.neighborFinset v) {u}
  370. have h2 : 4 ≤ (G.neighborFinset v).card := by
  371. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg v
  372. simp only [Finset.card_singleton] at h1
  373. omega
  374. have mem_A : ∀ {a}, a ∈ A ↔ G.Adj u a ∧ a ≠ v := by
  375. intro a; simp [A, mem_neighborFinset]
  376. have mem_B : ∀ {b}, b ∈ B ↔ G.Adj v b ∧ b ≠ u := by
  377. intro b; simp [B, mem_neighborFinset]
  378. have u_not_A : u ∉ A := fun h => (mem_A.mp h).1.ne rfl
  379. have v_not_A : v ∉ A := fun h => (mem_A.mp h).2 rfl
  380. have u_not_B : u ∉ B := fun h => (mem_B.mp h).2 rfl
  381. have v_not_B : v ∉ B := fun h => (mem_B.mp h).1.ne rfl
  382. have AB_disj : ∀ {x}, x ∈ A → x ∉ B := fun hxA hxB =>
  383. hnotri _ ⟨(mem_A.mp hxA).1, (mem_B.mp hxB).1⟩
  384. have no_edge_AB : ∀ {a b}, a ∈ A → b ∈ B → ¬ G.Adj a b := by
  385. intro a b ha hb hab
  386. have hau : G.Adj u a := (mem_A.mp ha).1
  387. have hbv : G.Adj v b := (mem_B.mp hb).1
  388. have hub : u ≠ b := fun h => u_not_B (h ▸ hb)
  389. have hva : v ≠ a := fun h => v_not_A (h ▸ ha)
  390. exact hno4 (exists_cycle_four_of_nodup hau hab hbv.symm huv.symm hub hva.symm)
  391. -- Children sets
  392. let ChA : V → Finset V := fun a => G.neighborFinset a \ insert u A
  393. let ChB : V → Finset V := fun b => G.neighborFinset b \ insert v B
  394. have hChA_card : ∀ {a}, a ∈ A → 2 ≤ (ChA a).card := by
  395. intro a ha
  396. have hau : G.Adj u a := (mem_A.mp ha).1
  397. have hpar_le : (G.neighborFinset a ∩ A).card ≤ 1 := by
  398. refine Finset.card_le_one.mpr ?_
  399. intro a1 ha1 a2 ha2
  400. simp only [Finset.mem_inter, mem_neighborFinset] at ha1 ha2
  401. exact eq_of_common_neighbors hno4 hau.ne (mem_A.mp ha1.2).1 ha1.1
  402. (mem_A.mp ha2.2).1 ha2.1
  403. have hsub : G.neighborFinset a ⊆ ChA a ∪ (insert u (G.neighborFinset a ∩ A)) := by
  404. intro z hz
  405. by_cases hzA : z ∈ insert u A
  406. · refine Finset.mem_union_right _ ?_
  407. rcases Finset.mem_insert.mp hzA with rfl | hzA'
  408. · exact Finset.mem_insert_self _ _
  409. · exact Finset.mem_insert_of_mem (Finset.mem_inter.mpr ⟨hz, hzA'⟩)
  410. · exact Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨hz, hzA⟩)
  411. have hdeg_a : 4 ≤ (G.neighborFinset a).card := by
  412. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg a
  413. have hc1 := Finset.card_le_card hsub
  414. have hc2 := Finset.card_union_le (ChA a) (insert u (G.neighborFinset a ∩ A))
  415. have hc3 := Finset.card_insert_le u (G.neighborFinset a ∩ A)
  416. omega
  417. have hChB_card : ∀ {b}, b ∈ B → 2 ≤ (ChB b).card := by
  418. intro b hb
  419. have hvb : G.Adj v b := (mem_B.mp hb).1
  420. have hpar_le : (G.neighborFinset b ∩ B).card ≤ 1 := by
  421. refine Finset.card_le_one.mpr ?_
  422. intro b1 hb1 b2 hb2
  423. simp only [Finset.mem_inter, mem_neighborFinset] at hb1 hb2
  424. exact eq_of_common_neighbors hno4 hvb.ne (mem_B.mp hb1.2).1 hb1.1
  425. (mem_B.mp hb2.2).1 hb2.1
  426. have hsub : G.neighborFinset b ⊆ ChB b ∪ (insert v (G.neighborFinset b ∩ B)) := by
  427. intro z hz
  428. by_cases hzB : z ∈ insert v B
  429. · refine Finset.mem_union_right _ ?_
  430. rcases Finset.mem_insert.mp hzB with rfl | hzB'
  431. · exact Finset.mem_insert_self _ _
  432. · exact Finset.mem_insert_of_mem (Finset.mem_inter.mpr ⟨hz, hzB'⟩)
  433. · exact Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨hz, hzB⟩)
  434. have hdeg_b : 4 ≤ (G.neighborFinset b).card := by
  435. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg b
  436. have hc1 := Finset.card_le_card hsub
  437. have hc2 := Finset.card_union_le (ChB b) (insert v (G.neighborFinset b ∩ B))
  438. have hc3 := Finset.card_insert_le v (G.neighborFinset b ∩ B)
  439. omega
  440. have hChB_card_nopar : ∀ {b}, b ∈ B → (∀ b' ∈ B, ¬ G.Adj b b') → 3 ≤ (ChB b).card := by
  441. intro b hb hnopar
  442. have hsub : G.neighborFinset b ⊆ ChB b ∪ {v} := by
  443. intro z hz
  444. by_cases hzv : z = v
  445. · exact Finset.mem_union_right _ (by simp [hzv])
  446. · refine Finset.mem_union_left _ (Finset.mem_sdiff.mpr ⟨hz, ?_⟩)
  447. intro hz_in
  448. rcases Finset.mem_insert.mp hz_in with rfl | hzB
  449. · exact hzv rfl
  450. · exact hnopar z hzB ((mem_neighborFinset G b z).mp hz)
  451. have hdeg_b : 4 ≤ (G.neighborFinset b).card := by
  452. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg b
  453. have hc1 := Finset.card_le_card hsub
  454. have hc2 := Finset.card_union_le (ChB b) {v}
  455. simp only [Finset.card_singleton] at hc2
  456. omega
  457. -- Basic properties of children
  458. have chA_props : ∀ {a x}, a ∈ A → x ∈ ChA a →
  459. G.Adj a x ∧ x ≠ u ∧ x ≠ v ∧ x ∉ A ∧ x ∉ B ∧ ¬ G.Adj u x ∧ ¬ G.Adj v x := by
  460. intro a x ha hx
  461. have hax : G.Adj a x := (mem_neighborFinset G a x).mp (Finset.mem_sdiff.mp hx).1
  462. have hnot : x ≠ u ∧ x ∉ A := by simpa using (Finset.mem_sdiff.mp hx).2
  463. have hxv : x ≠ v := fun h => hnotri a ⟨(mem_A.mp ha).1, h ▸ hax.symm⟩
  464. have hxB : x ∉ B := fun h => no_edge_AB ha h hax
  465. have hux : ¬ G.Adj u x := fun h => hnot.2 (mem_A.mpr ⟨h, hxv⟩)
  466. have hvx : ¬ G.Adj v x := fun h => hxB (mem_B.mpr ⟨h, hnot.1⟩)
  467. exact ⟨hax, hnot.1, hxv, hnot.2, hxB, hux, hvx⟩
  468. have chB_props : ∀ {b y}, b ∈ B → y ∈ ChB b →
  469. G.Adj b y ∧ y ≠ u ∧ y ≠ v ∧ y ∉ A ∧ y ∉ B ∧ ¬ G.Adj u y ∧ ¬ G.Adj v y := by
  470. intro b y hb hy
  471. have hby : G.Adj b y := (mem_neighborFinset G b y).mp (Finset.mem_sdiff.mp hy).1
  472. have hnot : y ≠ v ∧ y ∉ B := by simpa using (Finset.mem_sdiff.mp hy).2
  473. have hyu : y ≠ u := fun h => hnotri b ⟨h ▸ hby.symm, (mem_B.mp hb).1⟩
  474. have hyA : y ∉ A := fun h => no_edge_AB h hb hby.symm
  475. have huy : ¬ G.Adj u y := fun h => hyA (mem_A.mpr ⟨h, hnot.1⟩)
  476. have hvy : ¬ G.Adj v y := fun h => hnot.2 (mem_B.mpr ⟨h, hyu⟩)
  477. exact ⟨hby, hyu, hnot.1, hyA, hnot.2, huy, hvy⟩
  478. have chA_unique : ∀ {a1 a2 x}, a1 ∈ A → a2 ∈ A → x ∈ ChA a1 → G.Adj a2 x → a1 = a2 := by
  479. intro a1 a2 x ha1 ha2 hx1 ha2x
  480. have hp := chA_props ha1 hx1
  481. exact eq_of_common_neighbors hno4 hp.2.1.symm (mem_A.mp ha1).1 hp.1.symm
  482. (mem_A.mp ha2).1 ha2x.symm
  483. have chB_unique : ∀ {b1 b2 y}, b1 ∈ B → b2 ∈ B → y ∈ ChB b1 → G.Adj b2 y → b1 = b2 := by
  484. intro b1 b2 y hb1 hb2 hy1 hb2y
  485. have hp := chB_props hb1 hy1
  486. exact eq_of_common_neighbors hno4 hp.2.2.1.symm (mem_B.mp hb1).1 hp.1.symm
  487. (mem_B.mp hb2).1 hb2y.symm
  488. -- Step 1 (choice of b ∈ B): pick b ≠ bstar and ¬ G.Adj bstar b
  489. have hbstar_par_le : (G.neighborFinset bstar ∩ B).card ≤ 1 := by
  490. refine Finset.card_le_one.mpr ?_
  491. intro b1 hb1 b2 hb2
  492. simp only [Finset.mem_inter, mem_neighborFinset] at hb1 hb2
  493. exact eq_of_common_neighbors hno4 (mem_B.mp hbstar_B).1.ne (mem_B.mp hb1.2).1 hb1.1
  494. (mem_B.mp hb2.2).1 hb2.1
  495. have hb_rem_pos : 0 < (B \ insert bstar (G.neighborFinset bstar ∩ B)).card := by
  496. have h1 := le_card_sdiff_add_card B (insert bstar (G.neighborFinset bstar ∩ B))
  497. have h2 := Finset.card_insert_le bstar (G.neighborFinset bstar ∩ B)
  498. omega
  499. obtain ⟨b, hb_sdiff⟩ := Finset.card_pos.mp hb_rem_pos
  500. have hb_B : b ∈ B := (Finset.mem_sdiff.mp hb_sdiff).1
  501. have hb_not_bstar : b ≠ bstar := fun h =>
  502. (Finset.mem_sdiff.mp hb_sdiff).2 (by simp [h])
  503. have hb_not_adj_bstar : ¬ G.Adj bstar b := fun h =>
  504. (Finset.mem_sdiff.mp hb_sdiff).2
  505. (Finset.mem_insert_of_mem (Finset.mem_inter.mpr ⟨(mem_neighborFinset G bstar b).mpr h, hb_B⟩))
  506. -- Consequences of choosing b:
  507. -- (a) No child of b is adjacent to any a ∈ A; no child of any a ∈ A is adjacent to b.
  508. have chB_b_not_adj_A : ∀ {y a}, y ∈ ChB b → a ∈ A → ¬ G.Adj a y := by
  509. intro y a hy ha hay
  510. have hp := chB_props hb_B hy
  511. have hy_chA : y ∈ ChA a := Finset.mem_sdiff.mpr
  512. ⟨(mem_neighborFinset G a y).mpr hay, by simp [hp.2.1, hp.2.2.2.1]⟩
  513. exact hb_not_bstar (hbstar_all a ha b hb_B y hy_chA hy)
  514. have chA_not_adj_b : ∀ {a x}, a ∈ A → x ∈ ChA a → ¬ G.Adj b x := by
  515. intro a x ha hx hbx
  516. have hp := chA_props ha hx
  517. have hx_chB : x ∈ ChB b := Finset.mem_sdiff.mpr
  518. ⟨(mem_neighborFinset G b x).mpr hbx, by simp [hp.2.2.1, hp.2.2.2.2.1]⟩
  519. exact hb_not_bstar (hbstar_all a ha b hb_B x hx hx_chB)
  520. have chA_chB_b_disj : ∀ {a x}, a ∈ A → x ∈ ChA a → x ∉ ChB b := fun ha hx hxB =>
  521. chA_not_adj_b ha hx (chB_props hb_B hxB).1
  522. -- (b) No child of any a ∈ A is adjacent to any partner bhat ∈ B of b.
  523. have chA_not_adj_bhat : ∀ {a x bhat}, a ∈ A → x ∈ ChA a → bhat ∈ B → G.Adj b bhat →
  524. ¬ G.Adj bhat x := by
  525. intro a x bhat ha hx hbhat hbbhat hbhatx
  526. have hp := chA_props ha hx
  527. have hx_chB : x ∈ ChB bhat := Finset.mem_sdiff.mpr
  528. ⟨(mem_neighborFinset G bhat x).mpr hbhatx, by simp [hp.2.2.1, hp.2.2.2.2.1]⟩
  529. have hbhat_eq : bhat = bstar := hbstar_all a ha bhat hbhat x hx hx_chB
  530. exact hb_not_adj_bstar (hbhat_eq ▸ hbbhat.symm)
  531. -- Step 2: The funnel
  532. let Reaches : V → V → Prop := fun y a => y ∈ ChB b ∧ a ∈ A ∧ ∃ x ∈ ChA a, G.Adj y x
  533. let Linked : V → Prop := fun y => ∃ a, Reaches y a
  534. have funnel_contradiction : ∀ {y1 y2 a1 a2}, y1 ≠ y2 → a1 ≠ a2 →
  535. Reaches y1 a1 → Reaches y2 a2 → False := by
  536. intro y1 y2 a1 a2 hy12 ha12 ⟨hy1, ha1, x1, hx1, hy1x1⟩ ⟨hy2, ha2, x2, hx2, hy2x2⟩
  537. have hp_y1 := chB_props hb_B hy1
  538. have hp_y2 := chB_props hb_B hy2
  539. have hp_x1 := chA_props ha1 hx1
  540. have hp_x2 := chA_props ha2 hx2
  541. have hx12 : x1 ≠ x2 := fun h => ha12 (chA_unique ha1 ha2 hx1 (h ▸ hp_x2.1))
  542. have hx1y1 : x1 ≠ y1 := fun h => chA_chB_b_disj ha1 hx1 (h ▸ hy1)
  543. have hx1y2 : x1 ≠ y2 := fun h => chA_chB_b_disj ha1 hx1 (h ▸ hy2)
  544. have hx2y1 : x2 ≠ y1 := fun h => chA_chB_b_disj ha2 hx2 (h ▸ hy1)
  545. have hx2y2 : x2 ≠ y2 := fun h => chA_chB_b_disj ha2 hx2 (h ▸ hy2)
  546. have hba1 : b ≠ a1 := fun h => AB_disj ha1 (h ▸ hb_B)
  547. have hba2 : b ≠ a2 := fun h => AB_disj ha2 (h ▸ hb_B)
  548. have hbu : b ≠ u := (mem_B.mp hb_B).2
  549. have ha1u : a1 ≠ u := (mem_A.mp ha1).1.ne.symm
  550. have ha2u : a2 ≠ u := (mem_A.mp ha2).1.ne.symm
  551. have hby1_ne : b ≠ y1 := hp_y1.1.ne
  552. have hby2_ne : b ≠ y2 := hp_y2.1.ne
  553. have hbx1_ne : b ≠ x1 := fun h => hp_x1.2.2.2.2.1 (h ▸ hb_B)
  554. have hbx2_ne : b ≠ x2 := fun h => hp_x2.2.2.2.2.1 (h ▸ hb_B)
  555. have hy1a1_ne : y1 ≠ a1 := fun h => hp_y1.2.2.2.1 (h ▸ ha1)
  556. have hy1a2_ne : y1 ≠ a2 := fun h => hp_y1.2.2.2.1 (h ▸ ha2)
  557. have hy2a1_ne : y2 ≠ a1 := fun h => hp_y2.2.2.2.1 (h ▸ ha1)
  558. have hy2a2_ne : y2 ≠ a2 := fun h => hp_y2.2.2.2.1 (h ▸ ha2)
  559. have hx1a1_ne : x1 ≠ a1 := hp_x1.1.ne.symm
  560. have hx1a2_ne : x1 ≠ a2 := fun h => hp_x1.2.2.2.1 (h ▸ ha2)
  561. have hx2a1_ne : x2 ≠ a1 := fun h => hp_x2.2.2.2.1 (h ▸ ha1)
  562. have hx2a2_ne : x2 ≠ a2 := hp_x2.1.ne.symm
  563. -- Cycle: b - y1 - x1 - a1 - u - a2 - x2 - y2 - b
  564. refine hno8 (exists_cycle_eight_of_nodup hp_y1.1 hy1x1 hp_x1.1.symm
  565. (mem_A.mp ha1).1.symm (mem_A.mp ha2).1 hp_x2.1 hy2x2.symm hp_y2.1.symm ?_)
  566. simp [hby1_ne, hbx1_ne, hba1, hbu, hba2, hbx2_ne, hby2_ne,
  567. hx1y1.symm, hy1a1_ne, hp_y1.2.1, hy1a2_ne, hx2y1.symm, hy12,
  568. hx1a1_ne, hp_x1.2.1, hx1a2_ne, hx12, hx1y2,
  569. ha1u, ha12, hx2a1_ne.symm, hy2a1_ne.symm,
  570. ha2u.symm, hp_x2.2.1.symm, hp_y2.2.1.symm,
  571. hx2a2_ne.symm, hy2a2_ne.symm, hx2y2]
  572. -- Funnel dichotomy: either there is a unique linked child y0, OR there exists a ∈ A reached by no child of b.
  573. have funnel_dichotomy :
  574. (∃ y0 ∈ ChB b, Linked y0 ∧ ∀ y ∈ ChB b, Linked y → y = y0) ∨
  575. (∃ a ∈ A, ∀ y ∈ ChB b, ∀ x ∈ ChA a, ¬ G.Adj y x) := by
  576. by_cases huniq : ∃ y0 ∈ ChB b, Linked y0 ∧ ∀ y ∈ ChB b, Linked y → y = y0
  577. · exact Or.inl huniq
  578. · right
  579. by_cases hex : ∃ y1 ∈ ChB b, Linked y1
  580. · obtain ⟨y1, hy1, a0, hreach1⟩ := hex
  581. have hex2 : ∃ y2 ∈ ChB b, Linked y2 ∧ y2 ≠ y1 := by
  582. by_contra hnone
  583. refine huniq ⟨y1, hy1, ⟨a0, hreach1⟩, fun y hy hly => ?_⟩
  584. by_contra hy_ne
  585. exact hnone ⟨y, hy, hly, hy_ne⟩
  586. obtain ⟨y2, hy2, ⟨a2, hreach2⟩, hy21⟩ := hex2
  587. have ha20 : a2 = a0 := by
  588. by_contra hne
  589. exact funnel_contradiction hy21 hne hreach2 hreach1
  590. rw [ha20] at hreach2
  591. -- Pick a ∈ A \ {a0}
  592. have hrem : 0 < (A \ {a0}).card := by
  593. have h1 := le_card_sdiff_add_card A {a0}
  594. simp only [Finset.card_singleton] at h1
  595. omega
  596. obtain ⟨a, ha_sdiff⟩ := Finset.card_pos.mp hrem
  597. have ha_A : a ∈ A := (Finset.mem_sdiff.mp ha_sdiff).1
  598. have ha_ne : a ≠ a0 := by simpa using (Finset.mem_sdiff.mp ha_sdiff).2
  599. refine ⟨a, ha_A, fun y hy x hx hyx => ?_⟩
  600. by_cases hyy1 : y = y1
  601. · subst hyy1
  602. exact funnel_contradiction hy21.symm ha_ne ⟨hy1, ha_A, x, hx, hyx⟩ hreach2
  603. · exact funnel_contradiction hyy1 ha_ne ⟨hy, ha_A, x, hx, hyx⟩ hreach1
  604. · obtain ⟨a, ha_A⟩ := Finset.card_pos.mp (by omega : 0 < A.card)
  605. exact ⟨a, ha_A, fun y hy x hx hyx => hex ⟨y, hy, ⟨a, hy, ha_A, x, hx, hyx⟩⟩⟩
  606. -- Step 3: Short connections between x ∈ ChA a and y ∈ ChB b
  607. have short_conn : ∀ {a x y}, a ∈ A → x ∈ ChA a → y ∈ ChB b →
  608. G.Adj x y ∨
  609. (∃ w : V, G.Adj x w ∧ G.Adj w y ∧ w ≠ u ∧ w ≠ v ∧ w ∉ A ∧ w ∉ B) ∨
  610. (∃ x' ∈ ChA a, G.Adj x' y) ∨
  611. (∃ y' ∈ ChB b, G.Adj x y') := by
  612. intro a x y ha hx hy
  613. have hpx := chA_props ha hx
  614. have hpy := chB_props hb_B hy
  615. have hxy_ne : x ≠ y := fun h => chA_chB_b_disj ha hx (h ▸ hy)
  616. rcases exists_short_path hxy_ne (hdiam x y) with h1 | ⟨w, hxw, hwy⟩ |
  617. ⟨p, q, hxp, hpq, hqy, hpx_ne, hpy_ne, hqx_ne, hqy_ne, hpq_ne⟩
  618. · exact Or.inl h1
  619. · -- Length 2: w ∉ {u, v} ∪ A ∪ B
  620. refine Or.inr (Or.inl ⟨w, hxw, hwy, ?_, ?_, ?_, ?_⟩)
  621. · rintro rfl; exact hpy.2.2.2.2.2.1 hwy
  622. · rintro rfl; exact hpy.2.2.2.2.2.2 hwy
  623. · intro hwA; exact chB_b_not_adj_A hy hwA hwy
  624. · intro hwB
  625. have hwb : w = b := (chB_unique hb_B hwB hy hwy).symm
  626. exact chA_not_adj_b ha hx (hwb ▸ hxw.symm)
  627. · -- Length 3: x - p - q - y
  628. by_cases hpa : p = a
  629. · rw [hpa] at hpq
  630. have hq_chA : q ∈ ChA a := by
  631. refine Finset.mem_sdiff.mpr ⟨(mem_neighborFinset G a q).mpr hpq, ?_⟩
  632. intro hq_in
  633. rcases Finset.mem_insert.mp hq_in with rfl | hqA
  634. · exact hpy.2.2.2.2.2.1 hqy
  635. · exact chB_b_not_adj_A hy hqA hqy
  636. exact Or.inr (Or.inr (Or.inl ⟨q, hq_chA, hqy⟩))
  637. · by_cases hqb : q = b
  638. · rw [hqb] at hpq
  639. have hp_chB : p ∈ ChB b := by
  640. refine Finset.mem_sdiff.mpr ⟨(mem_neighborFinset G b p).mpr hpq.symm, ?_⟩
  641. intro hp_in
  642. rcases Finset.mem_insert.mp hp_in with rfl | hpB
  643. · exact hpx.2.2.2.2.2.2 hxp.symm
  644. · exact chA_not_adj_bhat ha hx hpB hpq.symm hxp.symm
  645. exact Or.inr (Or.inr (Or.inr ⟨p, hp_chB, hxp⟩))
  646. · -- Otherwise: 8-cycle u - a - x - p - q - y - b - v - u
  647. exfalso
  648. have hau : G.Adj u a := (mem_A.mp ha).1
  649. have hvb : G.Adj v b := (mem_B.mp hb_B).1
  650. have hpu : p ≠ u := fun h => hpx.2.2.2.2.2.1 (h ▸ hxp.symm)
  651. have hpv : p ≠ v := fun h => hpx.2.2.2.2.2.2 (h ▸ hxp.symm)
  652. have hpb : p ≠ b := fun h => chA_not_adj_b ha hx (h ▸ hxp.symm)
  653. have hqu : q ≠ u := fun h => hpy.2.2.2.2.2.1 (h ▸ hqy)
  654. have hqv : q ≠ v := fun h => hpy.2.2.2.2.2.2 (h ▸ hqy)
  655. have hqa : q ≠ a := fun h => chB_b_not_adj_A hy ha (h ▸ hqy)
  656. have hub : u ≠ b := (mem_B.mp hb_B).2.symm
  657. have hva : v ≠ a := (mem_A.mp ha).2.symm
  658. have hab : a ≠ b := fun h => AB_disj ha (h ▸ hb_B)
  659. have hay : a ≠ y := fun h => hpy.2.2.2.1 (h ▸ ha)
  660. have hbx : b ≠ x := fun h => hpx.2.2.2.2.1 (h ▸ hb_B)
  661. refine hno8 (exists_cycle_eight_of_nodup hau hpx.1 hxp hpq hqy hpy.1.symm
  662. hvb.symm huv.symm ?_)
  663. simp [hau.ne, hpx.2.1.symm, hpu.symm, hqu.symm, hpy.2.1.symm, hub, huv_ne,
  664. hpx.1.ne, Ne.symm hpa, hqa.symm, hay, hab, hva.symm,
  665. hpx_ne.symm, hqx_ne.symm, hxy_ne, hbx.symm, hpx.2.2.1,
  666. hpq_ne, hpy_ne, hpb, hpv,
  667. hqy_ne, hqb, hqv,
  668. hpy.1.ne.symm, hpy.2.2.1, hvb.ne.symm]
  669. -- Helper: given y0 ∈ ChB b and a ∈ A, there exists x ∈ ChA a not adjacent to y0.
  670. have exists_chA_not_adj : ∀ {a y0}, a ∈ A → y0 ∈ ChB b → ∃ x ∈ ChA a, ¬ G.Adj y0 x := by
  671. intro a y0 ha hy0
  672. have hpy0 := chB_props hb_B hy0
  673. have hay0 : a ≠ y0 := fun h => hpy0.2.2.2.1 (h ▸ ha)
  674. have hinter_le : (ChA a ∩ G.neighborFinset y0).card ≤ 1 := by
  675. refine Finset.card_le_one.mpr ?_
  676. intro x1 hx1 x2 hx2
  677. simp only [Finset.mem_inter, mem_neighborFinset] at hx1 hx2
  678. exact eq_of_common_neighbors hno4 hay0 (chA_props ha hx1.1).1 hx1.2
  679. (chA_props ha hx2.1).1 hx2.2
  680. have hrem_pos : 0 < (ChA a \ (ChA a ∩ G.neighborFinset y0)).card := by
  681. have h1 := le_card_sdiff_add_card (ChA a) (ChA a ∩ G.neighborFinset y0)
  682. have h2 := hChA_card ha
  683. omega
  684. obtain ⟨x, hx_sdiff⟩ := Finset.card_pos.mp hrem_pos
  685. refine ⟨x, (Finset.mem_sdiff.mp hx_sdiff).1, fun h => ?_⟩
  686. exact (Finset.mem_sdiff.mp hx_sdiff).2
  687. (Finset.mem_inter.mpr ⟨(Finset.mem_sdiff.mp hx_sdiff).1, (mem_neighborFinset G y0 x).mpr h⟩)
  688. -- Step 4: Split on whether b has a partner bhat ∈ B
  689. by_cases hpar : ∃ bhat ∈ B, G.Adj b bhat
  690. · -- Step 4a: b has a partner bhat ∈ B
  691. obtain ⟨bhat, hbhat_B, hbbhat⟩ := hpar
  692. -- Common neighbor w ∉ {u, v} ∪ A ∪ B is impossible
  693. have no_common_outer : ∀ {a x y w}, a ∈ A → x ∈ ChA a → y ∈ ChB b →
  694. G.Adj x w → G.Adj w y → w ≠ u → w ≠ v → w ∉ A → w ∉ B → False := by
  695. intro a x y w ha hx hy hxw hwy hwu hwv hwA hwB
  696. have hpx := chA_props ha hx
  697. have hpy := chB_props hb_B hy
  698. have hau : G.Adj u a := (mem_A.mp ha).1
  699. have hvbhat : G.Adj v bhat := (mem_B.mp hbhat_B).1
  700. have hxy : x ≠ y := fun h => chA_chB_b_disj ha hx (h ▸ hy)
  701. have hxb : x ≠ b := fun h => hpx.2.2.2.2.1 (h ▸ hb_B)
  702. have hxbhat : x ≠ bhat := fun h => hpx.2.2.2.2.1 (h ▸ hbhat_B)
  703. have hwb : w ≠ b := fun h => hwB (h ▸ hb_B)
  704. have hwbhat : w ≠ bhat := fun h => hwB (h ▸ hbhat_B)
  705. have hwa : w ≠ a := fun h => hwA (h ▸ ha)
  706. have hybhat : y ≠ bhat := fun h => hpy.2.2.2.2.1 (h ▸ hbhat_B)
  707. have hya : y ≠ a := fun h => hpy.2.2.2.1 (h ▸ ha)
  708. have hba : b ≠ a := fun h => AB_disj ha (h ▸ hb_B)
  709. have hbhata : bhat ≠ a := fun h => AB_disj ha (h ▸ hbhat_B)
  710. have hbu : b ≠ u := (mem_B.mp hb_B).2
  711. have hbv : b ≠ v := (mem_B.mp hb_B).1.ne.symm
  712. have hbhatu : bhat ≠ u := (mem_B.mp hbhat_B).2
  713. have hva : v ≠ a := (mem_A.mp ha).2.symm
  714. -- Cycle: x - w - y - b - bhat - v - u - a - x
  715. refine hno8 (exists_cycle_eight_of_nodup hxw hwy hpy.1.symm hbbhat hvbhat.symm
  716. huv.symm hau hpx.1 ?_)
  717. simp [hxw.ne, hxy, hxb, hxbhat, hpx.2.2.1, hpx.2.1, hpx.1.ne.symm,
  718. hwy.ne, hwb, hwbhat, hwv, hwu, hwa,
  719. hpy.1.ne.symm, hybhat, hpy.2.2.1, hpy.2.1, hya,
  720. hbbhat.ne, hbv, hbu, hba,
  721. hvbhat.ne.symm, hbhatu, hbhata,
  722. huv_ne.symm, hva, hau.ne]
  723. rcases funnel_dichotomy with ⟨y0, hy0, _, hy0_uniq⟩ | ⟨a, ha, hno_edge⟩
  724. · -- Exactly one linked child y0 of b
  725. obtain ⟨a, ha⟩ := Finset.card_pos.mp (by omega : 0 < A.card)
  726. obtain ⟨x, hx, hny0x⟩ := exists_chA_not_adj ha hy0
  727. have hy_rem_pos : 0 < (ChB b \ {y0}).card := by
  728. have h1 := le_card_sdiff_add_card (ChB b) {y0}
  729. have h2 := hChB_card hb_B
  730. simp only [Finset.card_singleton] at h1
  731. omega
  732. obtain ⟨y, hy_sdiff⟩ := Finset.card_pos.mp hy_rem_pos
  733. have hy : y ∈ ChB b := (Finset.mem_sdiff.mp hy_sdiff).1
  734. have hy_ne : y ≠ y0 := by simpa using (Finset.mem_sdiff.mp hy_sdiff).2
  735. rcases short_conn ha hx hy with h1 | ⟨w, hxw, hwy, hwu, hwv, hwA, hwB⟩ |
  736. ⟨x', hx', hx'y⟩ | ⟨y', hy', hxy'⟩
  737. · exact hy_ne (hy0_uniq y hy ⟨a, hy, ha, x, hx, h1.symm⟩)
  738. · exact no_common_outer ha hx hy hxw hwy hwu hwv hwA hwB
  739. · exact hy_ne (hy0_uniq y hy ⟨a, hy, ha, x', hx', hx'y.symm⟩)
  740. · have hy'eq : y' = y0 := hy0_uniq y' hy' ⟨a, hy', ha, x, hx, hxy'.symm⟩
  741. exact hny0x (hy'eq ▸ hxy'.symm)
  742. · -- Number of linked children ≠ 1: no edge between ChA a and ChB b
  743. obtain ⟨x, hx⟩ := Finset.card_pos.mp (by have := hChA_card ha; omega : 0 < (ChA a).card)
  744. obtain ⟨y, hy⟩ := Finset.card_pos.mp (by have := hChB_card hb_B; omega : 0 < (ChB b).card)
  745. rcases short_conn ha hx hy with h1 | ⟨w, hxw, hwy, hwu, hwv, hwA, hwB⟩ |
  746. ⟨x', hx', hx'y⟩ | ⟨y', hy', hxy'⟩
  747. · exact hno_edge y hy x hx h1.symm
  748. · exact no_common_outer ha hx hy hxw hwy hwu hwv hwA hwB
  749. · exact hno_edge y hy x' hx' hx'y.symm
  750. · exact hno_edge y' hy' x hx hxy'.symm
  751. · -- Step 4b: b has no partner in B, so |ChB b| ≥ 3
  752. have hnopar : ∀ bhat ∈ B, ¬ G.Adj b bhat := fun bhat hbhat h => hpar ⟨bhat, hbhat, h⟩
  753. have hChB_b_3 : 3 ≤ (ChB b).card := hChB_card_nopar hb_B hnopar
  754. rcases funnel_dichotomy with ⟨y0, hy0, _, hy0_uniq⟩ | ⟨a, ha, hno_edge⟩
  755. · -- Subcase 4b(2): exactly one linked child y0 of b
  756. obtain ⟨a1, ha1, a2, ha2, ha12⟩ := exists_two_of_two_le_card (by omega : 2 ≤ A.card)
  757. obtain ⟨x1, hx1, hny0x1⟩ := exists_chA_not_adj ha1 hy0
  758. obtain ⟨x2, hx2, hny0x2⟩ := exists_chA_not_adj ha2 hy0
  759. have hy_rem_2 : 2 ≤ (ChB b \ {y0}).card := by
  760. have h1 := le_card_sdiff_add_card (ChB b) {y0}
  761. simp only [Finset.card_singleton] at h1
  762. omega
  763. obtain ⟨y1, hy1_s, y2, hy2_s, hy12⟩ := exists_two_of_two_le_card hy_rem_2
  764. have hy1 : y1 ∈ ChB b := (Finset.mem_sdiff.mp hy1_s).1
  765. have hy1_ne : y1 ≠ y0 := by simpa using (Finset.mem_sdiff.mp hy1_s).2
  766. have hy2 : y2 ∈ ChB b := (Finset.mem_sdiff.mp hy2_s).1
  767. have hy2_ne : y2 ≠ y0 := by simpa using (Finset.mem_sdiff.mp hy2_s).2
  768. -- For each i ∈ {1, 2} and j ∈ {1, 2}, obtain common outer neighbor w_{ij}
  769. have get_w : ∀ {ai xi yj}, ai ∈ A → xi ∈ ChA ai → ¬ G.Adj y0 xi →
  770. yj ∈ ChB b → yj ≠ y0 →
  771. ∃ w : V, G.Adj xi w ∧ G.Adj w yj ∧ w ≠ u ∧ w ≠ v ∧ w ∉ A ∧ w ∉ B := by
  772. intro ai xi yj hai hxi hny0xi hyj hyj_ne
  773. rcases short_conn hai hxi hyj with h1 | hw | ⟨x', hx', hx'y⟩ | ⟨y', hy', hxy'⟩
  774. · exact (hyj_ne (hy0_uniq yj hyj ⟨ai, hyj, hai, xi, hxi, h1.symm⟩)).elim
  775. · exact hw
  776. · exact (hyj_ne (hy0_uniq yj hyj ⟨ai, hyj, hai, x', hx', hx'y.symm⟩)).elim
  777. · have hy'eq : y' = y0 := hy0_uniq y' hy' ⟨ai, hy', hai, xi, hxi, hxy'.symm⟩
  778. exact (hny0xi (hy'eq ▸ hxy'.symm)).elim
  779. -- Show w_{1j} = w_{2j} for any unlinked yj ∈ ChB b
  780. have hpx1 := chA_props ha1 hx1
  781. have hpx2 := chA_props ha2 hx2
  782. have hx12 : x1 ≠ x2 := fun h => ha12 (chA_unique ha1 ha2 hx1 (h ▸ hpx2.1))
  783. have common_w : ∀ {yj}, yj ∈ ChB b → yj ≠ y0 →
  784. ∃ w : V, G.Adj x1 w ∧ G.Adj x2 w ∧ G.Adj w yj ∧ w ∉ B := by
  785. intro yj hyj hyj_ne
  786. obtain ⟨w1, hx1w1, hw1y, hw1u, _, hw1A, hw1B⟩ := get_w ha1 hx1 hny0x1 hyj hyj_ne
  787. obtain ⟨w2, hx2w2, hw2y, hw2u, _, hw2A, _⟩ := get_w ha2 hx2 hny0x2 hyj hyj_ne
  788. have hw12 : w1 = w2 := by
  789. by_contra hne
  790. have hpy := chB_props hb_B hyj
  791. have hau1 : G.Adj u a1 := (mem_A.mp ha1).1
  792. have hau2 : G.Adj u a2 := (mem_A.mp ha2).1
  793. have hx1y : x1 ≠ yj := fun h => chA_chB_b_disj ha1 hx1 (h ▸ hyj)
  794. have hx2y : x2 ≠ yj := fun h => chA_chB_b_disj ha2 hx2 (h ▸ hyj)
  795. have hw1x2 : w1 ≠ x2 := fun h =>
  796. hyj_ne (hy0_uniq yj hyj ⟨a2, hyj, ha2, x2, hx2, h ▸ hw1y.symm⟩)
  797. have hw2x1 : w2 ≠ x1 := fun h =>
  798. hyj_ne (hy0_uniq yj hyj ⟨a1, hyj, ha1, x1, hx1, h ▸ hw2y.symm⟩)
  799. have hx1a2 : x1 ≠ a2 := fun h => hpx1.2.2.2.1 (h ▸ ha2)
  800. have hx2a1 : x2 ≠ a1 := fun h => hpx2.2.2.2.1 (h ▸ ha1)
  801. have hw1a1 : w1 ≠ a1 := fun h => hw1A (h ▸ ha1)
  802. have hw1a2 : w1 ≠ a2 := fun h => hw1A (h ▸ ha2)
  803. have hw2a1 : w2 ≠ a1 := fun h => hw2A (h ▸ ha1)
  804. have hw2a2 : w2 ≠ a2 := fun h => hw2A (h ▸ ha2)
  805. have hya1 : yj ≠ a1 := fun h => hpy.2.2.2.1 (h ▸ ha1)
  806. have hya2 : yj ≠ a2 := fun h => hpy.2.2.2.1 (h ▸ ha2)
  807. -- Cycle: x1 - w1 - yj - w2 - x2 - a2 - u - a1 - x1
  808. refine hno8 (exists_cycle_eight_of_nodup hx1w1 hw1y hw2y.symm hx2w2.symm
  809. hpx2.1.symm hau2.symm hau1 hpx1.1 ?_)
  810. simp [hx1w1.ne, hx1y, hw2x1.symm, hx12, hx1a2, hpx1.2.1, hpx1.1.ne.symm,
  811. hw1y.ne, hne, hw1x2, hw1a2, hw1u, hw1a1,
  812. hw2y.ne.symm, hx2y.symm, hya2, hpy.2.1, hya1,
  813. hx2w2.ne.symm, hw2a2, hw2u, hw2a1,
  814. hpx2.1.ne.symm, hpx2.2.1, hx2a1,
  815. hau2.ne.symm, ha12.symm, hau1.ne]
  816. subst hw12
  817. exact ⟨w1, hx1w1, hx2w2, hw1y, hw1B⟩
  818. obtain ⟨w1, hx1w1, hx2w1, hw1y1, hw1B⟩ := common_w hy1 hy1_ne
  819. obtain ⟨w2, hx1w2, hx2w2, hw2y2, _⟩ := common_w hy2 hy2_ne
  820. have hw12 : w1 ≠ w2 := by
  821. rintro rfl
  822. have hw1b : w1 ≠ b := fun h => hw1B (h ▸ hb_B)
  823. exact hw1b (eq_of_common_neighbors hno4 hy12 hw1y1.symm hw2y2.symm
  824. (chB_props hb_B hy1).1.symm (chB_props hb_B hy2).1.symm)
  825. exact hw12 (eq_of_common_neighbors hno4 hx12 hx1w1 hx2w1 hx1w2 hx2w2)
  826. · -- Subcase 4b(1): number of linked children ≠ 1, so no edge between ChA a and ChB b
  827. obtain ⟨x1, hx1, x2, hx2, hx12⟩ := exists_two_of_two_le_card (hChA_card ha)
  828. obtain ⟨y1, hy1, y2, hy2, hy12⟩ := exists_two_of_two_le_card (by omega : 2 ≤ (ChB b).card)
  829. have get_w : ∀ {xi yj}, xi ∈ ChA a → yj ∈ ChB b →
  830. ∃ w : V, G.Adj xi w ∧ G.Adj w yj ∧ w ≠ u ∧ w ≠ v ∧ w ∉ A ∧ w ∉ B := by
  831. intro xi yj hxi hyj
  832. rcases short_conn ha hxi hyj with h1 | hw | ⟨x', hx', hx'y⟩ | ⟨y', hy', hxy'⟩
  833. · exact (hno_edge yj hyj xi hxi h1.symm).elim
  834. · exact hw
  835. · exact (hno_edge yj hyj x' hx' hx'y.symm).elim
  836. · exact (hno_edge y' hy' xi hxi hxy'.symm).elim
  837. obtain ⟨w1, hx1w1, hw1y1, _, _, hw1A, hw1B⟩ := get_w hx1 hy1
  838. obtain ⟨w2, hx2w2, hw2y2, _, _, hw2A, hw2B⟩ := get_w hx2 hy2
  839. have hpx1 := chA_props ha hx1
  840. have hpx2 := chA_props ha hx2
  841. have hpy1 := chB_props hb_B hy1
  842. have hpy2 := chB_props hb_B hy2
  843. have hw12 : w1 ≠ w2 := by
  844. rintro rfl
  845. have hw1a : w1 ≠ a := fun h => hw1A (h ▸ ha)
  846. exact hw1a (eq_of_common_neighbors hno4 hx12 hx1w1 hx2w2 hpx1.1.symm hpx2.1.symm)
  847. have hw1x2 : w1 ≠ x2 := fun h => hno_edge y1 hy1 x2 hx2 (h ▸ hw1y1.symm)
  848. have hw1y2 : w1 ≠ y2 := fun h => hno_edge y2 hy2 x1 hx1 (h ▸ hx1w1.symm)
  849. have hw2x1 : w2 ≠ x1 := fun h => hno_edge y2 hy2 x1 hx1 (h ▸ hw2y2.symm)
  850. have hw2y1 : w2 ≠ y1 := fun h => hno_edge y1 hy1 x2 hx2 (h ▸ hx2w2.symm)
  851. have hx1y1 : x1 ≠ y1 := fun h => chA_chB_b_disj ha hx1 (h ▸ hy1)
  852. have hx1y2 : x1 ≠ y2 := fun h => chA_chB_b_disj ha hx1 (h ▸ hy2)
  853. have hx2y1 : x2 ≠ y1 := fun h => chA_chB_b_disj ha hx2 (h ▸ hy1)
  854. have hx2y2 : x2 ≠ y2 := fun h => chA_chB_b_disj ha hx2 (h ▸ hy2)
  855. have hab : a ≠ b := fun h => AB_disj ha (h ▸ hb_B)
  856. have haw1 : a ≠ w1 := fun h => hw1A (h ▸ ha)
  857. have haw2 : a ≠ w2 := fun h => hw2A (h ▸ ha)
  858. have hay1 : a ≠ y1 := fun h => hpy1.2.2.2.1 (h ▸ ha)
  859. have hay2 : a ≠ y2 := fun h => hpy2.2.2.2.1 (h ▸ ha)
  860. have hbx1 : b ≠ x1 := fun h => hpx1.2.2.2.2.1 (h ▸ hb_B)
  861. have hbx2 : b ≠ x2 := fun h => hpx2.2.2.2.2.1 (h ▸ hb_B)
  862. have hbw1 : b ≠ w1 := fun h => hw1B (h ▸ hb_B)
  863. have hbw2 : b ≠ w2 := fun h => hw2B (h ▸ hb_B)
  864. -- Cycle: a - x1 - w1 - y1 - b - y2 - w2 - x2 - a
  865. refine hno8 (exists_cycle_eight_of_nodup hpx1.1 hx1w1 hw1y1 hpy1.1.symm
  866. hpy2.1 hw2y2.symm hx2w2.symm hpx2.1.symm ?_)
  867. simp [hpx1.1.ne, haw1, hay1, hab, hay2, haw2, hpx2.1.ne,
  868. hx1w1.ne, hx1y1, hbx1.symm, hx1y2, hw2x1.symm, hx12,
  869. hw1y1.ne, hbw1.symm, hw1y2, hw12, hw1x2,
  870. hpy1.1.ne.symm, hy12, hw2y1.symm, hx2y1.symm,
  871. hpy2.1.ne, hbw2, hbx2,
  872. hw2y2.ne.symm, hx2y2.symm, hx2w2.ne.symm]
  873. /-- **Case 2:** Some edge `u ~ v` lies in no triangle. -/
  874. private lemma case2_edge_not_in_triangle
  875. (hdeg : ∀ v : V, 4 ≤ G.degree v)
  876. (hdiam : ∀ x y : V, G.edist x y ≤ 3)
  877. (hno4 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4)
  878. (hno8 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 8)
  879. {u v : V} (huv : G.Adj u v)
  880. (hnotri : ∀ t : V, ¬ (G.Adj u t ∧ G.Adj v t)) :
  881. False := by
  882. have : Nonempty V := ⟨u⟩
  883. set A : Finset V := G.neighborFinset u \ {v}
  884. set B : Finset V := G.neighborFinset v \ {u}
  885. let ChA : V → Finset V := fun a => G.neighborFinset a \ insert u A
  886. let ChB : V → Finset V := fun b => G.neighborFinset b \ insert v B
  887. let BridgeLabel : V → V → Prop := fun a b =>
  888. a ∈ A ∧ b ∈ B ∧ ∃ z : V, z ∈ ChA a ∧ z ∈ ChB b
  889. have mem_A : ∀ {a}, a ∈ A ↔ G.Adj u a ∧ a ≠ v := by
  890. intro a; simp [A, mem_neighborFinset]
  891. have mem_B : ∀ {b}, b ∈ B ↔ G.Adj v b ∧ b ≠ u := by
  892. intro b; simp [B, mem_neighborFinset]
  893. have AB_disj : ∀ {x}, x ∈ A → x ∉ B := fun hxA hxB =>
  894. hnotri _ ⟨(mem_A.mp hxA).1, (mem_B.mp hxB).1⟩
  895. have hshare : ∀ a1 b1 a2 b2, BridgeLabel a1 b1 → BridgeLabel a2 b2 → a1 = a2 ∨ b1 = b2 := by
  896. intro a1 b1 a2 b2 ⟨ha1, hb1, z1, hz1A, hz1B⟩ ⟨ha2, hb2, z2, hz2A, hz2B⟩
  897. by_contra h
  898. have ha12 : a1 ≠ a2 := fun h' => h (Or.inl h')
  899. have hb12 : b1 ≠ b2 := fun h' => h (Or.inr h')
  900. have ha1z1 : G.Adj a1 z1 := (mem_neighborFinset G a1 z1).mp (Finset.mem_sdiff.mp hz1A).1
  901. have hb1z1 : G.Adj b1 z1 := (mem_neighborFinset G b1 z1).mp (Finset.mem_sdiff.mp hz1B).1
  902. have ha2z2 : G.Adj a2 z2 := (mem_neighborFinset G a2 z2).mp (Finset.mem_sdiff.mp hz2A).1
  903. have hb2z2 : G.Adj b2 z2 := (mem_neighborFinset G b2 z2).mp (Finset.mem_sdiff.mp hz2B).1
  904. have hz1_notA : z1 ≠ u ∧ z1 ∉ A := by simpa using (Finset.mem_sdiff.mp hz1A).2
  905. have hz1_notB : z1 ≠ v ∧ z1 ∉ B := by simpa using (Finset.mem_sdiff.mp hz1B).2
  906. have hz2_notA : z2 ≠ u ∧ z2 ∉ A := by simpa using (Finset.mem_sdiff.mp hz2A).2
  907. have hz2_notB : z2 ≠ v ∧ z2 ∉ B := by simpa using (Finset.mem_sdiff.mp hz2B).2
  908. have hz12 : z1 ≠ z2 := by
  909. rintro rfl
  910. exact ha12 (eq_of_common_neighbors hno4 hz1_notA.1.symm
  911. (mem_A.mp ha1).1 ha1z1.symm (mem_A.mp ha2).1 ha2z2.symm)
  912. have hau1 : G.Adj u a1 := (mem_A.mp ha1).1
  913. have hau2 : G.Adj u a2 := (mem_A.mp ha2).1
  914. have hvb1 : G.Adj v b1 := (mem_B.mp hb1).1
  915. have hvb2 : G.Adj v b2 := (mem_B.mp hb2).1
  916. -- Cycle: u - a1 - z1 - b1 - v - b2 - z2 - a2 - u
  917. refine hno8 (exists_cycle_eight_of_nodup hau1 ha1z1 hb1z1.symm hvb1.symm
  918. hvb2 hb2z2 ha2z2.symm hau2.symm ?_)
  919. have ha1b1 : a1 ≠ b1 := fun heq => AB_disj ha1 (heq ▸ hb1)
  920. have ha1b2 : a1 ≠ b2 := fun heq => AB_disj ha1 (heq ▸ hb2)
  921. have ha2b1 : a2 ≠ b1 := fun heq => AB_disj ha2 (heq ▸ hb1)
  922. have ha2b2 : a2 ≠ b2 := fun heq => AB_disj ha2 (heq ▸ hb2)
  923. have hz1a2 : z1 ≠ a2 := fun heq => hz1_notA.2 (heq ▸ ha2)
  924. have hz1b2 : z1 ≠ b2 := fun heq => hz1_notB.2 (heq ▸ hb2)
  925. have hz2a1 : z2 ≠ a1 := fun heq => hz2_notA.2 (heq ▸ ha1)
  926. have hz2b1 : z2 ≠ b1 := fun heq => hz2_notB.2 (heq ▸ hb1)
  927. simp [hau1.ne, hz1_notA.1.symm, (mem_B.mp hb1).2.symm, huv.ne, (mem_B.mp hb2).2.symm,
  928. hz2_notA.1.symm, hau2.ne,
  929. ha1z1.ne, ha1b1, (mem_A.mp ha1).2, ha1b2, hz2a1.symm, ha12,
  930. hb1z1.ne.symm, hz1_notB.1, hz1b2, hz12, hz1a2,
  931. hvb1.ne.symm, hb12, hz2b1.symm, ha2b1.symm,
  932. hvb2.ne, hz2_notB.1.symm, (mem_A.mp ha2).2.symm,
  933. hb2z2.ne, ha2b2.symm, ha2z2.ne.symm]
  934. have hA_pos : 0 < A.card := by
  935. have h1 : (G.neighborFinset u).card ≤ A.card + ({v} : Finset V).card :=
  936. le_card_sdiff_add_card (G.neighborFinset u) {v}
  937. have h2 : 4 ≤ (G.neighborFinset u).card := by
  938. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg u
  939. simp only [Finset.card_singleton] at h1
  940. omega
  941. have hB_pos : 0 < B.card := by
  942. have h1 : (G.neighborFinset v).card ≤ B.card + ({u} : Finset V).card :=
  943. le_card_sdiff_add_card (G.neighborFinset v) {u}
  944. have h2 : 4 ≤ (G.neighborFinset v).card := by
  945. simpa [SimpleGraph.card_neighborFinset_eq_degree] using hdeg v
  946. simp only [Finset.card_singleton] at h1
  947. omega
  948. rcases star_of_pairwise_share_coord BridgeLabel hshare with ⟨a0, ha0⟩ | ⟨b0, hb0⟩
  949. · -- All bridges share first coordinate a0: swap u and v
  950. by_cases ha0A : a0 ∈ A
  951. · exact case2_oriented hdeg hdiam hno4 hno8 huv.symm
  952. (fun t ⟨hvt, hut⟩ => hnotri t ⟨hut, hvt⟩) a0 ha0A
  953. (fun b hb a ha z hzB hzA => ha0 a b ⟨ha, hb, z, hzA, hzB⟩)
  954. · -- No bridges at all; pick any astar ∈ A and swap u and v
  955. obtain ⟨astar, hastar⟩ := Finset.card_pos.mp hA_pos
  956. exact case2_oriented hdeg hdiam hno4 hno8 huv.symm
  957. (fun t ⟨hvt, hut⟩ => hnotri t ⟨hut, hvt⟩) astar hastar
  958. (fun b hb a ha z hzB hzA => (ha0A (ha0 a b ⟨ha, hb, z, hzA, hzB⟩ ▸ ha)).elim)
  959. · -- All bridges share second coordinate b0
  960. by_cases hb0B : b0 ∈ B
  961. · exact case2_oriented hdeg hdiam hno4 hno8 huv hnotri b0 hb0B
  962. (fun a ha b hb z hzA hzB => hb0 a b ⟨ha, hb, z, hzA, hzB⟩)
  963. · -- No bridges at all; pick any bstar ∈ B
  964. obtain ⟨bstar, hbstar⟩ := Finset.card_pos.mp hB_pos
  965. exact case2_oriented hdeg hdiam hno4 hno8 huv hnotri bstar hbstar
  966. (fun a ha b hb z hzA hzB => (hb0B (hb0 a b ⟨ha, hb, z, hzA, hzB⟩ ▸ hb)).elim)
  967. end Case2
  968. section MainTheorems
  969. variable {V : Type*} [Fintype V]
  970. /-- **Main Theorem (distance form):** Every finite simple graph with minimum degree at least 4
  971. and all pairwise extended distances at most 3 contains a simple cycle of length 4 or 8. -/
  972. theorem exists_cycle_four_or_eight_of_edist_le_three
  973. (G : SimpleGraph V) [DecidableRel G.Adj]
  974. (hmin : G.minDegree ≥ 4)
  975. (hdiam : ∀ u v : V, G.edist u v ≤ 3) :
  976. ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ (c.length = 4 ∨ c.length = 8) := by
  977. classical
  978. have hne : Nonempty V := by
  979. by_contra h
  980. have : IsEmpty V := not_nonempty_iff.mp h
  981. have h0 : G.minDegree = 0 := by simp [SimpleGraph.minDegree]
  982. omega
  983. have hdeg : ∀ v : V, 4 ≤ G.degree v := fun v => le_trans hmin (G.minDegree_le_degree v)
  984. by_contra hno
  985. have hno4 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 4 := by
  986. rintro ⟨v, c, hc, hlen⟩
  987. exact hno ⟨v, c, hc, Or.inl hlen⟩
  988. have hno8 : ¬ ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ c.length = 8 := by
  989. rintro ⟨v, c, hc, hlen⟩
  990. exact hno ⟨v, c, hc, Or.inr hlen⟩
  991. by_cases htri : ∀ u v : V, G.Adj u v → ∃ t : V, G.Adj u t ∧ G.Adj v t
  992. · exact case1_all_edges_in_triangle hdeg hdiam hno4 hno8 htri
  993. · have hex : ∃ u v : V, G.Adj u v ∧ ∀ t : V, ¬ (G.Adj u t ∧ G.Adj v t) := by
  994. by_contra h
  995. apply htri
  996. intro u v huv
  997. by_contra ht
  998. exact h ⟨u, v, huv, fun t h' => ht ⟨t, h'⟩⟩
  999. obtain ⟨u, v, huv, hnotri⟩ := hex
  1000. exact case2_edge_not_in_triangle hdeg hdiam hno4 hno8 huv hnotri
  1001. /-- **Main Theorem (extended diameter form):** Every finite simple graph with `G.minDegree ≥ 4`
  1002. and `G.ediam ≤ 3` contains a simple cycle of length 4 or 8. -/
  1003. theorem exists_cycle_four_or_eight_of_ediam_le_three
  1004. (G : SimpleGraph V) [DecidableRel G.Adj]
  1005. (hmin : G.minDegree ≥ 4)
  1006. (hediam : G.ediam ≤ 3) :
  1007. ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ (c.length = 4 ∨ c.length = 8) :=
  1008. exists_cycle_four_or_eight_of_edist_le_three G hmin (G.ediam_le_iff.mp hediam)
  1009. /-- **Main Theorem (connected + `diam ≤ 3` form):** Every connected finite simple graph with
  1010. `G.minDegree ≥ 4` and `G.diam ≤ 3` contains a simple cycle of length 4 or 8. -/
  1011. theorem exists_cycle_four_or_eight_of_connected_diam_le_three
  1012. (G : SimpleGraph V) [DecidableRel G.Adj]
  1013. (hmin : G.minDegree ≥ 4)
  1014. (hconn : G.Connected)
  1015. (hdiam : G.diam ≤ 3) :
  1016. ∃ (v : V) (c : G.Walk v v), c.IsCycle ∧ (c.length = 4 ∨ c.length = 8) := by
  1017. have : Nonempty V := hconn.nonempty
  1018. have hne_top : G.ediam ≠ ⊤ := G.connected_iff_ediam_ne_top.mp hconn
  1019. have hediam : G.ediam ≤ 3 := by
  1020. cases h : G.ediam with
  1021. | top => exact (hne_top h).elim
  1022. | coe n =>
  1023. have hn : n ≤ 3 := by simpa [SimpleGraph.diam, h] using hdiam
  1024. exact Nat.cast_le.mpr hn
  1025. exact exists_cycle_four_or_eight_of_ediam_le_three G hmin hediam
  1026. /-- **Erdős–Gyárfás Corollary (`ediam ≤ 3`):** Every finite simple graph with `G.minDegree ≥ 4`
  1027. and `G.ediam ≤ 3` satisfies the conclusion of Erdős Problem #64 (`∃ k ≥ 2`, cycle of length `2^k`). -/
  1028. theorem erdos_64_of_minDegree_ge_four_ediam_le_three
  1029. (G : SimpleGraph V) [DecidableRel G.Adj]
  1030. (hmin : G.minDegree ≥ 4)
  1031. (hediam : G.ediam ≤ 3) :
  1032. ∃ (k : ℕ) (v : V) (c : G.Walk v v), k ≥ 2 ∧ c.IsCycle ∧ c.length = 2 ^ k := by
  1033. obtain ⟨v, c, hc, hlen | hlen⟩ := exists_cycle_four_or_eight_of_ediam_le_three G hmin hediam
  1034. · exact ⟨2, v, c, le_rfl, hc, by simpa using hlen⟩
  1035. · exact ⟨3, v, c, by omega, hc, by simpa using hlen⟩
  1036. /-- **Erdős–Gyárfás Corollary (`Connected ∧ diam ≤ 3`):** Every connected finite simple graph with
  1037. `G.minDegree ≥ 4` and `G.diam ≤ 3` satisfies the conclusion of Erdős Problem #64. -/
  1038. theorem erdos_64_of_minDegree_ge_four_connected_diam_le_three
  1039. (G : SimpleGraph V) [DecidableRel G.Adj]
  1040. (hmin : G.minDegree ≥ 4)
  1041. (hconn : G.Connected)
  1042. (hdiam : G.diam ≤ 3) :
  1043. ∃ (k : ℕ) (v : V) (c : G.Walk v v), k ≥ 2 ∧ c.IsCycle ∧ c.length = 2 ^ k := by
  1044. obtain ⟨v, c, hc, hlen | hlen⟩ :=
  1045. exists_cycle_four_or_eight_of_connected_diam_le_three G hmin hconn hdiam
  1046. · exact ⟨2, v, c, le_rfl, hc, by simpa using hlen⟩
  1047. · exact ⟨3, v, c, by omega, hc, by simpa using hlen⟩
  1048. end MainTheorems
  1049. end Erdos64Diam3