/-
Copyright 2025 The Formal Conjectures Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
module
public import FormalConjecturesUtil
/-!
# Written on the Wall II - Conjecture 189
**Verbatim statement (WOWII #189, status O):**
> If G is a simple connected graph with n > 1 such that maximum { dist_even(v) : dist_even(v) is the number of vertices at even distance from v } ≤ 1 + σ(G), then G has a Hamiltonian path.
**Source:** http://cms.uhd.edu/faculty/delavinae/research/wowII/all.html#conj189
*Reference:*
[E. DeLaVina, Written on the Wall II, Conjectures of Graffiti.pc](http://cms.dt.uh.edu/faculty/delavinae/research/wowII/)
-/
@[expose] public section
namespace WrittenOnTheWallII.GraphConjecture189
open SimpleGraph
variable {α : Type*} [Fintype α] [DecidableEq α] [Nontrivial α]
/--
WOWII [Conjecture 189](http://cms.uhd.edu/faculty/delavinae/research/wowII/all.html#conj189)
(status O):
For a simple connected graph `G`, if `max_v distEven(v) ≤ 1 + σ(G)`,
then `G` has a Hamiltonian path.
Here `distEven(v)` is the number of vertices at even distance from `v`, and
`σ(G)` is the **second-smallest degree** of `G`'s degree sequence (per
WOWII defEntry 65).
-/
@[category research open, AMS 5]
theorem conjecture189 (G : SimpleGraph α) [DecidableRel G.Adj] (h : G.Connected)
(hσ : (Finset.univ.image (distEven G)).max' (by simp) ≤ 1 + secondSmallestDegree G) :
∃ a b : α, ∃ p : G.Walk a b, p.IsHamiltonian := by
sorry
-- Sanity checks
/-- The second-smallest degree is nonneg. -/
@[category test, AMS 5]
example (G : SimpleGraph (Fin 3)) [DecidableRel G.Adj] :
0 ≤ secondSmallestDegree G := Nat.zero_le _
/-- `distEven G v` is positive for any vertex `v`. -/
@[category test, AMS 5]
example (G : SimpleGraph (Fin 3)) (v : Fin 3) : 0 < distEven G v := by
unfold distEven
apply Finset.card_pos.mpr
exact ⟨v, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ⟨0, by simp [SimpleGraph.dist_self]⟩⟩⟩
set_option linter.unusedSectionVars false
set_option linter.unusedVariables false
section RootDev
variable {β : Type*} [Fintype β] [DecidableEq β]
theorem exists_walk_of_isChain (G : SimpleGraph β) :
∀ (l : List β) (a : β), (a :: l).IsChain G.Adj →
∃ b : β, ∃ p : G.Walk a b, p.support = a :: l
| [], a, _ => ⟨a, Walk.nil, rfl⟩
| (c :: l), a, h => by
rw [List.isChain_cons_cons] at h
obtain ⟨b, p, hp⟩ := exists_walk_of_isChain G l c h.2
exact ⟨b, Walk.cons h.1 p, by simp [hp]⟩
/-- A connected graph has an edge leaving any nonempty proper set given as a list. -/
theorem exists_adj_out (G : SimpleGraph β) (h : G.Connected) (l : List β) (hne : l ≠ [])
(hlt : l.length < Fintype.card β) (hnd : l.Nodup) :
∃ y ∈ l, ∃ x, x ∉ l ∧ G.Adj y x := by
obtain ⟨a, ha⟩ := List.exists_mem_of_ne_nil l hne
have : ∃ x, x ∉ l := by
by_contra hcon
push Not at hcon
have h1 : l.toFinset = Finset.univ := Finset.eq_univ_iff_forall.mpr (by simpa using hcon)
have h2 := List.toFinset_card_of_nodup hnd
rw [h1, Finset.card_univ] at h2
omega
obtain ⟨x, hx⟩ := this
obtain ⟨p⟩ := h.preconnected a x
obtain ⟨d, -, hd1, hd2⟩ := p.exists_boundary_dart {v | v ∈ l} ha hx
exact ⟨d.fst, hd1, d.snd, hd2, d.adj⟩
/-- Rotating a cyclic chain at a vertex `y` and appending an outside neighbour `x` of `y`. -/
theorem extend_cycle (G : SimpleGraph β) (cyc : List β) (hc : cyc.IsChain G.Adj) (hnd : cyc.Nodup)
(hclose : ∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a)
(y : β) (hy : y ∈ cyc) (x : β) (hx : x ∉ cyc) (hyx : G.Adj y x) :
∃ l' : List β, l' ≠ [] ∧ l'.IsChain G.Adj ∧ l'.Nodup ∧ l'.length = cyc.length + 1 := by
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hy
set p := cyc.take (j + 1) with hp
set q := cyc.drop (j + 1) with hq
have hpq : p ++ q = cyc := List.take_append_drop _ _
have hplast : p.getLast? = some (cyc[j]'hj) := by
rw [hp, List.getLast?_take]; simp [hj]
have hpchain : p.IsChain G.Adj := hc.take _
have hqchain : q.IsChain G.Adj := hc.drop _
refine ⟨q ++ (p ++ [x]), by simp, ?_, ?_, ?_⟩
· have hpx : (p ++ [x]).IsChain G.Adj := by
apply hpchain.append (List.isChain_singleton x)
intro u hu v hv
rw [hplast] at hu
simp only [Option.mem_def, Option.some.injEq] at hu
simp only [List.head?_cons, Option.mem_def, Option.some.injEq] at hv
subst hu; subst hv; exact hyx
apply hqchain.append hpx
intro u hu v hv
-- u is the last element of q (= last of cyc), v the head of p (= head of cyc)
have hu' : u ∈ cyc.getLast? := by
rw [← hpq, List.getLast?_append]
simp only [Option.mem_def] at hu ⊢
rw [hu]; rfl
have hv' : v ∈ cyc.head? := by
rw [← hpq]
have hpne : p ≠ [] := by
rw [hp]; exact List.ne_nil_of_length_pos (by simp; omega)
rw [List.head?_append_of_ne_nil _ hpne]
rw [List.head?_append_of_ne_nil _ hpne] at hv
exact hv
exact hclose v hv' u hu'
· have hperm : (q ++ (p ++ [x])).Perm (cyc ++ [x]) := by
rw [← hpq, ← List.append_assoc]
exact List.perm_append_comm.append_right _
rw [hperm.nodup_iff, List.nodup_append]
refine ⟨hnd, List.nodup_singleton x, ?_⟩
intro a ha b hb
simp only [List.mem_singleton] at hb
subst hb
exact fun hab => hx (hab ▸ ha)
· rw [← hpq]
simp only [List.length_append, List.length_singleton]
omega
/-- Ore's crossing step: a path whose end-vertices have all their neighbours on the path and
large degree sum can be closed into a cycle on the same vertex set. -/
theorem cycle_of_path (G : SimpleGraph β) [DecidableRel G.Adj] (l : List β)
(hc : l.IsChain G.Adj) (hnd : l.Nodup) (hlen : 2 ≤ l.length)
(hA : ∀ x, G.Adj (l[0]'(by omega)) x → x ∈ l)
(hZ : ∀ x, G.Adj (l[l.length - 1]'(by omega)) x → x ∈ l)
(hsum : l.length ≤ G.degree (l[0]'(by omega)) + G.degree (l[l.length - 1]'(by omega))) :
∃ cyc : List β, cyc.Perm l ∧ cyc.IsChain G.Adj ∧
∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a := by
set k := l.length with hk
set a := l[0]'(by omega) with ha
set z := l[k - 1]'(by omega) with hz
let f : ℕ → β := fun i => l.getD (i + 1) a
let g : ℕ → β := fun i => l.getD i a
set A := (Finset.range (k - 1)).filter (fun i => G.Adj a (f i)) with hAdef
set B := (Finset.range (k - 1)).filter (fun i => G.Adj z (g i)) with hBdef
have hdegA : G.degree a ≤ A.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := A.image f) ?_) Finset.card_image_le
intro x hx
rw [SimpleGraph.mem_neighborFinset] at hx
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem (hA x hx)
have hj0 : j ≠ 0 := by
rintro rfl
exact G.ne_of_adj hx (by simp [ha])
refine Finset.mem_image.mpr ⟨j - 1, ?_, ?_⟩
· simp only [hAdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [f, List.getD_eq_getElem?_getD]
rw [show j - 1 + 1 = j by omega, List.getElem?_eq_getElem hj]
simpa using hx
· simp only [f, List.getD_eq_getElem?_getD]
rw [show j - 1 + 1 = j by omega, List.getElem?_eq_getElem hj]
simp
have hdegB : G.degree z ≤ B.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := B.image g) ?_) Finset.card_image_le
intro x hx
rw [SimpleGraph.mem_neighborFinset] at hx
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem (hZ x hx)
have hjk : j ≠ k - 1 := by
rintro rfl
exact G.ne_of_adj hx (by simp [hz])
refine Finset.mem_image.mpr ⟨j, ?_, ?_⟩
· simp only [hBdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hj]
simpa using hx
· simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hj]
simp
-- pigeonhole: A and B intersect
obtain ⟨i, hiA, hiB⟩ : ∃ i, i ∈ A ∧ i ∈ B := by
by_contra hcon
push Not at hcon
have hdisj : Disjoint A B := Finset.disjoint_left.mpr hcon
have h1 : (A ∪ B).card ≤ k - 1 := by
have : A ∪ B ⊆ Finset.range (k - 1) := by
intro x hx
rcases Finset.mem_union.mp hx with hx | hx
· exact (Finset.mem_filter.mp hx).1
· exact (Finset.mem_filter.mp hx).1
simpa using Finset.card_le_card this
rw [Finset.card_union_of_disjoint hdisj] at h1
omega
simp only [hAdef, hBdef, Finset.mem_filter, Finset.mem_range] at hiA hiB
obtain ⟨hik, hai⟩ := hiA
obtain ⟨-, hzi⟩ := hiB
have hi1 : i + 1 < k := by omega
have hfi : f i = l[i + 1] := by
simp only [f, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi1, Option.getD_some]
have hgi : g i = l[i] := by
simp only [g, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem (by omega : i < k),
Option.getD_some]
rw [hfi] at hai
rw [hgi] at hzi
refine ⟨l.take (i + 1) ++ (l.drop (i + 1)).reverse, ?_, ?_, ?_⟩
· calc (l.take (i + 1) ++ (l.drop (i + 1)).reverse).Perm (l.take (i + 1) ++ l.drop (i + 1)) :=
(List.reverse_perm _).append_left _
_ = l := List.take_append_drop _ _
· apply (hc.take (i + 1)).append
· exact List.isChain_reverse.mpr ((hc.drop (i + 1)).imp fun _ _ h => h.symm)
· intro u hu v hv
rw [List.getLast?_take] at hu
simp only [show ¬ (i + 1 = 0) by omega, if_false, Nat.add_sub_cancel,
List.getElem?_eq_getElem (by omega : i < k), Option.some_or, Option.mem_def,
Option.some.injEq] at hu
rw [List.head?_reverse, List.getLast?_drop] at hv
simp only [show ¬ (k ≤ i + 1) by omega, if_false, ← hk, Option.mem_def] at hv
rw [List.getLast?_eq_getElem?, ← hk, List.getElem?_eq_getElem (by omega : k - 1 < k)] at hv
simp only [Option.some.injEq] at hv
subst hu; subst hv
exact hzi.symm
· intro u hu v hv
rw [List.head?_append, List.head?_take] at hu
simp only [show ¬ (i + 1 = 0) by omega, if_false, List.head?_eq_getElem?,
List.getElem?_eq_getElem (by omega : 0 < k), Option.some_or, Option.mem_def,
Option.some.injEq] at hu
rw [List.getLast?_append, List.getLast?_reverse, List.head?_drop,
List.getElem?_eq_getElem hi1] at hv
simp only [Option.some_or, Option.mem_def, Option.some.injEq] at hv
subst hu; subst hv
exact hai.symm
/-- Under Ore's condition, every path that misses a vertex can be made one vertex longer. -/
theorem ore_step (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected)
(hore : ∀ u v : β, u ≠ v → ¬ G.Adj u v → Fintype.card β - 1 ≤ G.degree u + G.degree v)
(l : List β) (hne : l ≠ []) (hc : l.IsChain G.Adj) (hnd : l.Nodup)
(hlt : l.length < Fintype.card β) :
∃ l' : List β, l' ≠ [] ∧ l'.IsChain G.Adj ∧ l'.Nodup ∧ l'.length = l.length + 1 := by
have hpos : 0 < l.length := List.length_pos_of_ne_nil hne
by_cases h1 : ∃ x, x ∉ l ∧ G.Adj (l[0]'hpos) x
· obtain ⟨x, hx, hadj⟩ := h1
obtain ⟨b, t, rfl⟩ := List.exists_cons_of_ne_nil hne
refine ⟨x :: b :: t, by simp, List.isChain_cons_cons.mpr ⟨hadj.symm, hc⟩,
List.nodup_cons.mpr ⟨hx, hnd⟩, by simp⟩
by_cases h2 : ∃ x, x ∉ l ∧ G.Adj (l[l.length - 1]'(by omega)) x
· obtain ⟨x, hx, hadj⟩ := h2
refine ⟨l ++ [x], by simp, ?_, ?_, by simp⟩
· apply hc.append (List.isChain_singleton x)
intro u hu v hv
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : l.length - 1 < l.length),
Option.mem_def, Option.some.injEq] at hu
simp only [List.head?_cons, Option.mem_def, Option.some.injEq] at hv
subst hu; subst hv; exact hadj
· rw [List.nodup_append]
refine ⟨hnd, List.nodup_singleton x, ?_⟩
intro a ha b hb
simp only [List.mem_singleton] at hb
subst hb
exact fun hab => hx (hab ▸ ha)
push Not at h1 h2
have hA : ∀ x, G.Adj (l[0]'hpos) x → x ∈ l := fun x hx => by
by_contra hn; exact h1 x hn hx
have hZ : ∀ x, G.Adj (l[l.length - 1]'(by omega)) x → x ∈ l := fun x hx => by
by_contra hn; exact h2 x hn hx
obtain ⟨y, hy, x, hx, hyx⟩ := exists_adj_out G h l hne hlt hnd
have hlen : 2 ≤ l.length := by
by_contra hcon
have h1' : l.length = 1 := by omega
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hy
have : j = 0 := by omega
subst this
exact hx (hA x hyx)
obtain ⟨cyc, hperm, hcc, hclose⟩ : ∃ cyc : List β, cyc.Perm l ∧ cyc.IsChain G.Adj ∧
∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a := by
by_cases hadj : G.Adj (l[0]'hpos) (l[l.length - 1]'(by omega))
· refine ⟨l, List.Perm.refl l, hc, ?_⟩
intro a ha z hz
rw [List.head?_eq_getElem?, List.getElem?_eq_getElem hpos, Option.mem_def,
Option.some.injEq] at ha
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : l.length - 1 < l.length),
Option.mem_def, Option.some.injEq] at hz
subst ha; subst hz; exact hadj.symm
· have hne' : l[0]'hpos ≠ l[l.length - 1]'(by omega) := by
intro heq
have := (List.Nodup.getElem_inj_iff hnd).mp heq
omega
have := hore _ _ hne' hadj
exact cycle_of_path G l hc hnd hlen hA hZ (by omega)
obtain ⟨l', hne', hc', hnd', hlen'⟩ :=
extend_cycle G cyc hcc (hperm.nodup_iff.mpr hnd) hclose y (hperm.mem_iff.mpr hy) x
(fun hm => hx (hperm.mem_iff.mp hm)) hyx
exact ⟨l', hne', hc', hnd', by rw [hlen', hperm.length_eq]⟩
/-- **Ore's theorem**, Hamiltonian-path version. -/
theorem ore_hamiltonian_path [Nontrivial β] (G : SimpleGraph β) [DecidableRel G.Adj]
(h : G.Connected)
(hore : ∀ u v : β, u ≠ v → ¬ G.Adj u v → Fintype.card β - 1 ≤ G.degree u + G.degree v) :
∃ a b : β, ∃ p : G.Walk a b, p.IsHamiltonian := by
have hall : ∀ k, 1 ≤ k → k ≤ Fintype.card β →
∃ l : List β, l ≠ [] ∧ l.IsChain G.Adj ∧ l.Nodup ∧ l.length = k := by
intro k
induction k with
| zero => intro h0; omega
| succ k ih =>
intro _ hk
rcases Nat.eq_zero_or_pos k with rfl | hpos
· obtain ⟨v⟩ := (inferInstance : Nonempty β)
exact ⟨[v], by simp, List.isChain_singleton v, List.nodup_singleton v, rfl⟩
· obtain ⟨l, hne, hc, hnd, hl⟩ := ih hpos (by omega)
obtain ⟨l', hne', hc', hnd', hl'⟩ := ore_step G h hore l hne hc hnd (by omega)
exact ⟨l', hne', hc', hnd', by omega⟩
obtain ⟨l, hne, hc, hnd, hl⟩ := hall (Fintype.card β) Fintype.card_pos le_rfl
obtain ⟨a, t, rfl⟩ := List.exists_cons_of_ne_nil hne
obtain ⟨b, p, hp⟩ := exists_walk_of_isChain G t a hc
refine ⟨a, b, p, ?_⟩
have hpath : p.IsPath := (Walk.isPath_def p).mpr (hp ▸ hnd)
apply hpath.isHamiltonian_of_mem
intro w
rw [hp]
have huniv : (a :: t).toFinset = Finset.univ :=
Finset.eq_univ_of_card _ (by rw [List.toFinset_card_of_nodup hnd, hl])
have : w ∈ (a :: t).toFinset := huniv ▸ Finset.mem_univ w
exact List.mem_toFinset.mp this
/-- Reversing the tail after position `i` when `q[i]` is adjacent to the last vertex. -/
theorem rot_end (G : SimpleGraph β) (q : List β) (hc : q.IsChain G.Adj) (i : ℕ)
(hi : i + 1 < q.length) (hadj : G.Adj (q[i]'(by omega)) (q[q.length - 1]'(by omega))) :
(q.take (i + 1) ++ (q.drop (i + 1)).reverse).IsChain G.Adj ∧
(q.take (i + 1) ++ (q.drop (i + 1)).reverse).Perm q ∧
(q.take (i + 1) ++ (q.drop (i + 1)).reverse).head? = q.head? ∧
(q.take (i + 1) ++ (q.drop (i + 1)).reverse).getLast? = some (q[i + 1]'hi) := by
set k := q.length with hk
refine ⟨?_, ?_, ?_, ?_⟩
· apply (hc.take (i + 1)).append
· exact List.isChain_reverse.mpr ((hc.drop (i + 1)).imp fun _ _ h => h.symm)
· intro u hu v hv
rw [List.getLast?_take] at hu
simp only [show ¬ (i + 1 = 0) by omega, if_false, Nat.add_sub_cancel,
List.getElem?_eq_getElem (by omega : i < k), Option.some_or, Option.mem_def,
Option.some.injEq] at hu
rw [List.head?_reverse, List.getLast?_drop] at hv
simp only [show ¬ (k ≤ i + 1) by omega, if_false, ← hk, Option.mem_def] at hv
rw [List.getLast?_eq_getElem?, ← hk, List.getElem?_eq_getElem (by omega : k - 1 < k)] at hv
simp only [Option.some.injEq] at hv
subst hu; subst hv
exact hadj
· calc (q.take (i + 1) ++ (q.drop (i + 1)).reverse).Perm (q.take (i + 1) ++ q.drop (i + 1)) :=
(List.reverse_perm _).append_left _
_ = q := List.take_append_drop _ _
· have hne : q.take (i + 1) ≠ [] := by
exact List.ne_nil_of_length_pos (by simp only [List.length_take]; omega)
rw [List.head?_append_of_ne_nil _ hne, List.head?_take]; simp
· rw [List.getLast?_append, List.getLast?_reverse, List.head?_drop,
List.getElem?_eq_getElem hi]
simp
/-- Reversing the head part up to position `i` when the first vertex is adjacent to `q[i+1]`. -/
theorem rot_start (G : SimpleGraph β) (q : List β) (hc : q.IsChain G.Adj) (i : ℕ)
(hi : i + 1 < q.length) (hadj : G.Adj (q[0]'(by omega)) (q[i + 1]'hi)) :
((q.take (i + 1)).reverse ++ q.drop (i + 1)).IsChain G.Adj ∧
((q.take (i + 1)).reverse ++ q.drop (i + 1)).Perm q ∧
((q.take (i + 1)).reverse ++ q.drop (i + 1)).head? = some (q[i]'(by omega)) := by
refine ⟨?_, ?_, ?_⟩
· apply (List.isChain_reverse.mpr ((hc.take (i + 1)).imp fun _ _ h => h.symm)).append
(hc.drop (i + 1))
intro u hu v hv
rw [List.getLast?_reverse, List.head?_take] at hu
simp only [show ¬ (i + 1 = 0) by omega, if_false, List.head?_eq_getElem?,
List.getElem?_eq_getElem (by omega : 0 < q.length), Option.mem_def,
Option.some.injEq] at hu
rw [List.head?_drop, List.getElem?_eq_getElem hi, Option.mem_def, Option.some.injEq] at hv
subst hu; subst hv
exact hadj
· calc ((q.take (i + 1)).reverse ++ q.drop (i + 1)).Perm (q.take (i + 1) ++ q.drop (i + 1)) :=
(List.reverse_perm _).append_right _
_ = q := List.take_append_drop _ _
· have hne : (q.take (i + 1)).reverse ≠ [] := by
exact List.ne_nil_of_length_pos (by simp only [List.length_reverse, List.length_take]; omega)
rw [List.head?_append_of_ne_nil _ hne, List.head?_reverse, List.getLast?_take]
simp [List.getElem?_eq_getElem (by omega : i < q.length)]
/-- A cyclic chain can be rotated to start at any of its vertices. -/
theorem rotate_to (G : SimpleGraph β) (cyc : List β) (hc : cyc.IsChain G.Adj)
(hclose : ∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a) (x : β) (hx : x ∈ cyc) :
∃ l : List β, l.head? = some x ∧ l.IsChain G.Adj ∧ l.Perm cyc := by
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hx
refine ⟨cyc.drop j ++ cyc.take j, ?_, ?_, ?_⟩
· have hne : cyc.drop j ≠ [] := by simp; omega
rw [List.head?_append_of_ne_nil _ hne, List.head?_drop, List.getElem?_eq_getElem hj]
· apply (hc.drop j).append (hc.take j)
intro u hu v hv
rw [List.getLast?_drop] at hu
simp only [show ¬ (cyc.length ≤ j) by omega, if_false] at hu
rw [List.head?_take] at hv
split_ifs at hv with h0
· simp at hv
· exact hclose v hv u hu
· calc (cyc.drop j ++ cyc.take j).Perm (cyc.take j ++ cyc.drop j) := List.perm_append_comm
_ = cyc := List.take_append_drop _ _
theorem mem_of_nodup_card (q : List β) (hnd : q.Nodup) (hlen : q.length = Fintype.card β) (y : β) :
y ∈ q := by
by_contra hy
have := (List.nodup_cons.mpr ⟨hy, hnd⟩).length_le_card
simp at this; omega
/-- If no Hamiltonian list starts at `x`, then both ends of every Hamiltonian list are adjacent
to `x` (under an Ore-type condition for pairs avoiding `x`). -/
theorem ends_adj_root (G : SimpleGraph β) [DecidableRel G.Adj] (x : β)
(hT : ∀ u v : β, u ≠ x → v ≠ x → u ≠ v → ¬ G.Adj u v →
Fintype.card β - 1 ≤ G.degree u + G.degree v)
(hno : ¬ ∃ l : List β, l.head? = some x ∧ l.IsChain G.Adj ∧ l.Nodup ∧
l.length = Fintype.card β)
(q : List β) (hc : q.IsChain G.Adj) (hnd : q.Nodup) (hlen : q.length = Fintype.card β)
(h2 : 2 ≤ q.length) :
G.Adj (q[0]'(by omega)) x ∧ G.Adj (q[q.length - 1]'(by omega)) x := by
set k := q.length with hk
have hmem := mem_of_nodup_card q hnd hlen
have hrot : ∀ r : List β, r.Perm q → r.IsChain G.Adj → r.head? = some x → False :=
fun r hp hrc hrh => hno ⟨r, hrh, hrc, hp.nodup_iff.mpr hnd, by rw [hp.length_eq]; omega⟩
have hcyc : ∀ cyc : List β, cyc.Perm q → cyc.IsChain G.Adj →
(∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a) → False := by
intro cyc hp hcc hcl
obtain ⟨r, hrh, hrc, hrp⟩ := rotate_to G cyc hcc hcl x (hp.mem_iff.mpr (hmem x))
exact hrot r (hrp.trans hp) hrc hrh
have hrev : ∀ r : List β, r.Perm q → r.IsChain G.Adj → r.getLast? = some x → False := by
intro r hp hrc hrl
refine hrot r.reverse ((List.reverse_perm r).trans hp)
(List.isChain_reverse.mpr (hrc.imp fun _ _ h => h.symm)) ?_
rw [List.head?_reverse, hrl]
obtain ⟨j, hj, hxj⟩ := List.getElem_of_mem (hmem x)
have hj0 : j ≠ 0 := by
rintro rfl
refine hrot q (List.Perm.refl q) hc ?_
rw [List.head?_eq_getElem?, List.getElem?_eq_getElem hj, hxj]
have hjk : j ≠ k - 1 := by
rintro rfl
refine hrev q (List.Perm.refl q) hc ?_
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem hj, hxj]
set u := q[0]'(by omega) with hu
set v := q[k - 1]'(by omega) with hv
have hux : u ≠ x := by
rw [← hxj, hu]; intro h; exact hj0 ((List.Nodup.getElem_inj_iff hnd).mp h).symm
have hvx : v ≠ x := by
rw [← hxj, hv]; intro h; exact hjk ((List.Nodup.getElem_inj_iff hnd).mp h).symm
have huv : u ≠ v := by
rw [hu, hv]; intro h; have := (List.Nodup.getElem_inj_iff hnd).mp h; omega
have hnadj : ¬ G.Adj u v := by
intro hadj
refine hcyc q (List.Perm.refl q) hc ?_
intro a ha z hz
rw [List.head?_eq_getElem?, List.getElem?_eq_getElem (by omega : 0 < k), Option.mem_def,
Option.some.injEq] at ha
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : k - 1 < k),
Option.mem_def, Option.some.injEq] at hz
subst ha; subst hz; exact hadj.symm
have hsum := hT u v hux hvx huv hnadj
let f : ℕ → β := fun i => q.getD (i + 1) x
let g : ℕ → β := fun i => q.getD i x
set A := (Finset.range (k - 1)).filter (fun i => G.Adj u (f i)) with hAdef
set B := (Finset.range (k - 1)).filter (fun i => G.Adj v (g i)) with hBdef
have hdegA : G.degree u ≤ A.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := A.image f) ?_) Finset.card_image_le
intro y hy
rw [SimpleGraph.mem_neighborFinset] at hy
obtain ⟨i, hi, rfl⟩ := List.getElem_of_mem (hmem y)
have hi0 : i ≠ 0 := by
rintro rfl
exact G.ne_of_adj hy rfl
refine Finset.mem_image.mpr ⟨i - 1, ?_, ?_⟩
· simp only [hAdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [f, List.getD_eq_getElem?_getD]
rw [show i - 1 + 1 = i by omega, List.getElem?_eq_getElem hi]
simpa using hy
· simp only [f, List.getD_eq_getElem?_getD]
rw [show i - 1 + 1 = i by omega, List.getElem?_eq_getElem hi]
simp
have hdegB : G.degree v ≤ B.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := B.image g) ?_) Finset.card_image_le
intro y hy
rw [SimpleGraph.mem_neighborFinset] at hy
obtain ⟨i, hi, rfl⟩ := List.getElem_of_mem (hmem y)
have hik : i ≠ k - 1 := by
rintro rfl
exact G.ne_of_adj hy rfl
refine Finset.mem_image.mpr ⟨i, ?_, ?_⟩
· simp only [hBdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hi]
simpa using hy
· simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hi]
simp
have hf : ∀ i (hi : i + 1 < k), f i = q[i + 1] := fun i hi => by
simp only [f, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi, Option.getD_some]
have hg : ∀ i (hi : i < k), g i = q[i] := fun i hi => by
simp only [g, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi, Option.getD_some]
-- no crossing, otherwise a Hamiltonian cycle
have hdisj : ∀ i, i ∈ A → i ∈ B → False := by
intro i hiA hiB
simp only [hAdef, hBdef, Finset.mem_filter, Finset.mem_range] at hiA hiB
have hi1 : i + 1 < k := by omega
have hai : G.Adj u q[i + 1] := hf i hi1 ▸ hiA.2
have hzi : G.Adj v q[i] := hg i (by omega) ▸ hiB.2
obtain ⟨hrc, hrp, hrh, hrl⟩ := rot_end G q hc i hi1 hzi.symm
refine hcyc _ hrp hrc ?_
intro a ha z hz
rw [hrh, List.head?_eq_getElem?, List.getElem?_eq_getElem (by omega : 0 < k),
Option.mem_def, Option.some.injEq] at ha
rw [hrl, Option.mem_def, Option.some.injEq] at hz
subst ha; subst hz; exact hai.symm
have hcover : ∀ i, i < k - 1 → i ∈ A ∨ i ∈ B := by
have hd : Disjoint A B := Finset.disjoint_left.mpr (fun {i} hiA hiB => hdisj i hiA hiB)
have hsub : A ∪ B ⊆ Finset.range (k - 1) := by
intro i hi
rcases Finset.mem_union.mp hi with hi | hi
· exact (Finset.mem_filter.mp hi).1
· exact (Finset.mem_filter.mp hi).1
have heq : A ∪ B = Finset.range (k - 1) := by
apply Finset.eq_of_subset_of_card_le hsub
rw [Finset.card_union_of_disjoint hd, Finset.card_range]
omega
intro i hi
have : i ∈ A ∪ B := by rw [heq]; exact Finset.mem_range.mpr hi
exact Finset.mem_union.mp this
refine ⟨?_, ?_⟩
· rcases hcover (j - 1) (by omega) with h | h
· simp only [hAdef, Finset.mem_filter] at h
have := hf (j - 1) (by omega) ▸ h.2
simpa [show j - 1 + 1 = j by omega, hxj] using this
· exfalso
simp only [hBdef, Finset.mem_filter] at h
have hzi : G.Adj v q[j - 1] := hg (j - 1) (by omega) ▸ h.2
obtain ⟨hrc, hrp, -, hrl⟩ := rot_end G q hc (j - 1) (by omega) hzi.symm
refine hrev _ hrp hrc ?_
rw [hrl]; simp [show j - 1 + 1 = j by omega, hxj]
· rcases hcover j (by omega) with h | h
· exfalso
simp only [hAdef, Finset.mem_filter] at h
have hai : G.Adj u q[j + 1] := hf j (by omega) ▸ h.2
obtain ⟨hrc, hrp, hrh⟩ := rot_start G q hc j (by omega) hai
exact hrot _ hrp hrc (by rw [hrh, hxj])
· simp only [hBdef, Finset.mem_filter] at h
have := hg j (by omega) ▸ h.2
simpa [hxj] using this
/-- From a Hamiltonian list to one starting at `x`, when `deg x ≤ s ≤ deg y` for `y ≠ x`. -/
theorem rooted_of_ham (G : SimpleGraph β) [DecidableRel G.Adj] (x : β) (s : ℕ)
(hdeg : ∀ y, y ≠ x → s ≤ G.degree y) (hdx : G.degree x ≤ s)
(hT : ∀ u v : β, u ≠ x → v ≠ x → u ≠ v → ¬ G.Adj u v →
Fintype.card β - 1 ≤ G.degree u + G.degree v)
(q : List β) (hc : q.IsChain G.Adj) (hnd : q.Nodup) (hlen : q.length = Fintype.card β)
(h2 : 2 ≤ q.length) :
∃ l : List β, l.head? = some x ∧ l.IsChain G.Adj ∧ l.Nodup ∧
l.length = Fintype.card β := by
by_contra hno
set k := q.length with hk
have hmem := mem_of_nodup_card q hnd hlen
obtain ⟨hu, hv⟩ := ends_adj_root G x hT hno q hc hnd hlen h2
set u := q[0]'(by omega) with hudef
set v := q[k - 1]'(by omega) with hvdef
have hvx : v ≠ x := G.ne_of_adj hv
let f : ℕ → β := fun i => q.getD (i + 1) x
let g : ℕ → β := fun i => q.getD i x
set B := (Finset.range (k - 1)).filter (fun i => G.Adj v (g i)) with hBdef
have hdegB : G.degree v ≤ B.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := B.image g) ?_) Finset.card_image_le
intro y hy
rw [SimpleGraph.mem_neighborFinset] at hy
obtain ⟨i, hi, rfl⟩ := List.getElem_of_mem (hmem y)
have hik : i ≠ k - 1 := by
rintro rfl
exact G.ne_of_adj hy rfl
refine Finset.mem_image.mpr ⟨i, ?_, ?_⟩
· simp only [hBdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hi]
simpa using hy
· simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hi]
simp
have hf : ∀ i (hi : i + 1 < k), f i = q[i + 1] := fun i hi => by
simp only [f, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi, Option.getD_some]
have hg : ∀ i (hi : i < k), g i = q[i] := fun i hi => by
simp only [g, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi, Option.getD_some]
-- every `f i` with `i ∈ B` is a neighbour of `x`
have hfB : ∀ i ∈ B, G.Adj (f i) x := by
intro i hi
simp only [hBdef, Finset.mem_filter, Finset.mem_range] at hi
have hi1 : i + 1 < k := by omega
have hzi : G.Adj v q[i] := hg i (by omega) ▸ hi.2
obtain ⟨hrc, hrp, -, hrl⟩ := rot_end G q hc i hi1 hzi.symm
set r := q.take (i + 1) ++ (q.drop (i + 1)).reverse with hr
have hrlen : r.length = k := hrp.length_eq
have := (ends_adj_root G x hT hno r hrc (hrp.nodup_iff.mpr hnd) (by omega) (by omega)).2
have hlast : r[r.length - 1]'(by omega) = q[i + 1] := by
have h1 := hrl
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega)] at h1
exact Option.some.inj h1
rw [hf i hi1, ← hlast]; exact this
have hsub : insert u (B.image f) ⊆ G.neighborFinset x := by
intro y hy
rw [SimpleGraph.mem_neighborFinset]
rcases Finset.mem_insert.mp hy with rfl | hy
· exact hu.symm
· obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hy
exact (hfB i hi).symm
have hnotin : u ∉ B.image f := by
intro hy
obtain ⟨i, hi, hfi⟩ := Finset.mem_image.mp hy
simp only [hBdef, Finset.mem_filter, Finset.mem_range] at hi
rw [hf i (by omega), hudef] at hfi
have := (List.Nodup.getElem_inj_iff hnd).mp hfi
omega
have hinj : Set.InjOn f B := by
intro i hi i' hi' heq
simp only [hBdef, Finset.coe_filter, Finset.mem_range, Set.mem_setOf_eq] at hi hi'
rw [hf i (by omega), hf i' (by omega)] at heq
have := (List.Nodup.getElem_inj_iff hnd).mp heq
omega
have hcard := Finset.card_le_card hsub
rw [Finset.card_insert_of_notMem hnotin, Finset.card_image_of_injOn hinj,
G.card_neighborFinset_eq_degree] at hcard
have := hdeg v hvx
omega
/-- Under Ore's condition, every path that misses a vertex can be made one vertex longer. -/
theorem ore_step_gen (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected)
(l : List β) (hne : l ≠ []) (hc : l.IsChain G.Adj) (hnd : l.Nodup)
(hlt : l.length < Fintype.card β)
(hk : ∀ h0 : 0 < l.length, ¬ G.Adj (l[0]'h0) (l[l.length - 1]'(by omega)) →
l[0]'h0 ≠ l[l.length - 1]'(by omega) →
l.length ≤ G.degree (l[0]'h0) + G.degree (l[l.length - 1]'(by omega))) :
∃ l' : List β, l' ≠ [] ∧ l'.IsChain G.Adj ∧ l'.Nodup ∧ l'.length = l.length + 1 := by
have hpos : 0 < l.length := List.length_pos_of_ne_nil hne
by_cases h1 : ∃ x, x ∉ l ∧ G.Adj (l[0]'hpos) x
· obtain ⟨x, hx, hadj⟩ := h1
obtain ⟨b, t, rfl⟩ := List.exists_cons_of_ne_nil hne
refine ⟨x :: b :: t, by simp, List.isChain_cons_cons.mpr ⟨hadj.symm, hc⟩,
List.nodup_cons.mpr ⟨hx, hnd⟩, by simp⟩
by_cases h2 : ∃ x, x ∉ l ∧ G.Adj (l[l.length - 1]'(by omega)) x
· obtain ⟨x, hx, hadj⟩ := h2
refine ⟨l ++ [x], by simp, ?_, ?_, by simp⟩
· apply hc.append (List.isChain_singleton x)
intro u hu v hv
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : l.length - 1 < l.length),
Option.mem_def, Option.some.injEq] at hu
simp only [List.head?_cons, Option.mem_def, Option.some.injEq] at hv
subst hu; subst hv; exact hadj
· rw [List.nodup_append]
refine ⟨hnd, List.nodup_singleton x, ?_⟩
intro a ha b hb
simp only [List.mem_singleton] at hb
subst hb
exact fun hab => hx (hab ▸ ha)
push Not at h1 h2
have hA : ∀ x, G.Adj (l[0]'hpos) x → x ∈ l := fun x hx => by
by_contra hn; exact h1 x hn hx
have hZ : ∀ x, G.Adj (l[l.length - 1]'(by omega)) x → x ∈ l := fun x hx => by
by_contra hn; exact h2 x hn hx
obtain ⟨y, hy, x, hx, hyx⟩ := exists_adj_out G h l hne hlt hnd
have hlen : 2 ≤ l.length := by
by_contra hcon
have h1' : l.length = 1 := by omega
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hy
have : j = 0 := by omega
subst this
exact hx (hA x hyx)
obtain ⟨cyc, hperm, hcc, hclose⟩ : ∃ cyc : List β, cyc.Perm l ∧ cyc.IsChain G.Adj ∧
∀ a ∈ cyc.head?, ∀ z ∈ cyc.getLast?, G.Adj z a := by
by_cases hadj : G.Adj (l[0]'hpos) (l[l.length - 1]'(by omega))
· refine ⟨l, List.Perm.refl l, hc, ?_⟩
intro a ha z hz
rw [List.head?_eq_getElem?, List.getElem?_eq_getElem hpos, Option.mem_def,
Option.some.injEq] at ha
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : l.length - 1 < l.length),
Option.mem_def, Option.some.injEq] at hz
subst ha; subst hz; exact hadj.symm
· have hne' : l[0]'hpos ≠ l[l.length - 1]'(by omega) := by
intro heq
have := (List.Nodup.getElem_inj_iff hnd).mp heq
omega
exact cycle_of_path G l hc hnd hlen hA hZ (hk hpos hadj hne')
obtain ⟨l', hne', hc', hnd', hlen'⟩ :=
extend_cycle G cyc hcc (hperm.nodup_iff.mpr hnd) hclose y (hperm.mem_iff.mpr hy) x
(fun hm => hx (hperm.mem_iff.mp hm)) hyx
exact ⟨l', hne', hc', hnd', by rw [hlen', hperm.length_eq]⟩
/-- Absorbing an outside vertex `y` at the far end of a path whose far end is closed. -/
theorem path_absorb (G : SimpleGraph β) [DecidableRel G.Adj] (l : List β)
(hc : l.IsChain G.Adj) (hnd : l.Nodup) (hlen : 2 ≤ l.length) (y : β) (hy : y ∉ l)
(hZ : ∀ v, G.Adj (l[l.length - 1]'(by omega)) v → v ∈ l) (hY : ∀ v, G.Adj y v → v ∈ l)
(hy0 : ¬ G.Adj y (l[0]'(by omega))) (hyz : ¬ G.Adj y (l[l.length - 1]'(by omega)))
(hsum : l.length ≤ G.degree (l[l.length - 1]'(by omega)) + G.degree y) :
∃ l' : List β, l'.head? = l.head? ∧ l'.IsChain G.Adj ∧ l'.Nodup ∧
l'.length = l.length + 1 := by
set k := l.length with hk
set z := l[k - 1]'(by omega) with hz
let f : ℕ → β := fun i => l.getD (i + 1) y
let g : ℕ → β := fun i => l.getD i y
set A := (Finset.range (k - 1)).filter (fun i => G.Adj z (g i)) with hAdef
set B := (Finset.range (k - 1)).filter (fun i => G.Adj y (f i)) with hBdef
have hdegA : G.degree z ≤ A.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := A.image g) ?_) Finset.card_image_le
intro x hx
rw [SimpleGraph.mem_neighborFinset] at hx
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem (hZ x hx)
have hjk : j ≠ k - 1 := by
rintro rfl
exact G.ne_of_adj hx (by simp [hz])
refine Finset.mem_image.mpr ⟨j, ?_, ?_⟩
· simp only [hAdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hj]
simpa using hx
· simp only [g, List.getD_eq_getElem?_getD]
rw [List.getElem?_eq_getElem hj]
simp
have hdegB : G.degree y ≤ B.card := by
rw [← G.card_neighborFinset_eq_degree]
refine le_trans (Finset.card_le_card (t := B.image f) ?_) Finset.card_image_le
intro x hx
rw [SimpleGraph.mem_neighborFinset] at hx
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem (hY x hx)
have hj0 : j ≠ 0 := by
rintro rfl
exact hy0 hx
have hjk : j ≠ k - 1 := by
rintro rfl
exact hyz hx
refine Finset.mem_image.mpr ⟨j - 1, ?_, ?_⟩
· simp only [hBdef, Finset.mem_filter, Finset.mem_range]
refine ⟨by omega, ?_⟩
simp only [f, List.getD_eq_getElem?_getD]
rw [show j - 1 + 1 = j by omega, List.getElem?_eq_getElem hj]
simpa using hx
· simp only [f, List.getD_eq_getElem?_getD]
rw [show j - 1 + 1 = j by omega, List.getElem?_eq_getElem hj]
simp
obtain ⟨i, hiA, hiB⟩ : ∃ i, i ∈ A ∧ i ∈ B := by
by_contra hcon
push Not at hcon
have hdisj : Disjoint A B := Finset.disjoint_left.mpr hcon
have h1 : (A ∪ B).card ≤ k - 1 := by
have : A ∪ B ⊆ Finset.range (k - 1) := by
intro x hx
rcases Finset.mem_union.mp hx with hx | hx
· exact (Finset.mem_filter.mp hx).1
· exact (Finset.mem_filter.mp hx).1
simpa using Finset.card_le_card this
rw [Finset.card_union_of_disjoint hdisj] at h1
omega
simp only [hAdef, hBdef, Finset.mem_filter, Finset.mem_range] at hiA hiB
have hi1 : i + 1 < k := by omega
have hzi : G.Adj z l[i] := by
have := hiA.2
simp only [g, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem (by omega : i < k),
Option.getD_some] at this
exact this
have hyi : G.Adj y l[i + 1] := by
have := hiB.2
simp only [f, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem hi1,
Option.getD_some] at this
exact this
obtain ⟨hrc, hrp, hrh, hrl⟩ := rot_end G l hc i hi1 hzi.symm
set r := l.take (i + 1) ++ (l.drop (i + 1)).reverse with hr
have hrne : r ≠ [] := List.ne_nil_of_length_pos (by rw [hrp.length_eq]; omega)
refine ⟨r ++ [y], ?_, ?_, ?_, ?_⟩
· rw [List.head?_append_of_ne_nil _ hrne, hrh]
· apply hrc.append (List.isChain_singleton y)
intro a ha b hb
rw [hrl, Option.mem_def, Option.some.injEq] at ha
simp only [List.head?_cons, Option.mem_def, Option.some.injEq] at hb
subst ha; subst hb; exact hyi.symm
· rw [List.nodup_append]
refine ⟨hrp.nodup_iff.mpr hnd, List.nodup_singleton y, ?_⟩
intro a ha b hb
simp only [List.mem_singleton] at hb
subst hb
exact fun hab => hy (hrp.mem_iff.mp (hab ▸ ha))
· simp [hrp.length_eq, hk]
theorem last_step_head (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected) (x : β) (s : ℕ)
(hdeg : ∀ y, y ≠ x → s ≤ G.degree y) (hm : Fintype.card β ≤ 2 * s + 1)
(l : List β) (hne : l ≠ []) (hc : l.IsChain G.Adj) (hnd : l.Nodup)
(hlen : l.length + 1 = Fintype.card β)
(hx : l[0]'(List.length_pos_of_ne_nil hne) = x) :
∃ l' : List β, l'.IsChain G.Adj ∧ l'.Nodup ∧ l'.length = Fintype.card β := by
have hpos : 0 < l.length := List.length_pos_of_ne_nil hne
by_cases h1 : ∃ v, v ∉ l ∧ G.Adj (l[0]'hpos) v
· obtain ⟨v, hv, hadj⟩ := h1
obtain ⟨b, t, rfl⟩ := List.exists_cons_of_ne_nil hne
refine ⟨v :: b :: t, List.isChain_cons_cons.mpr ⟨hadj.symm, hc⟩,
List.nodup_cons.mpr ⟨hv, hnd⟩, by simp at hlen ⊢; omega⟩
by_cases h2 : ∃ v, v ∉ l ∧ G.Adj (l[l.length - 1]'(by omega)) v
· obtain ⟨v, hv, hadj⟩ := h2
refine ⟨l ++ [v], ?_, ?_, by simp; omega⟩
· apply hc.append (List.isChain_singleton v)
intro u hu w hw
rw [List.getLast?_eq_getElem?, List.getElem?_eq_getElem (by omega : l.length - 1 < l.length),
Option.mem_def, Option.some.injEq] at hu
simp only [List.head?_cons, Option.mem_def, Option.some.injEq] at hw
subst hu; subst hw; exact hadj
· rw [List.nodup_append]
refine ⟨hnd, List.nodup_singleton v, ?_⟩
intro a ha b hb
simp only [List.mem_singleton] at hb
subst hb
exact fun hab => hv (hab ▸ ha)
push Not at h1 h2
have hA : ∀ v, G.Adj (l[0]'hpos) v → v ∈ l := fun v hv => by
by_contra hn; exact h1 v hn hv
have hZ : ∀ v, G.Adj (l[l.length - 1]'(by omega)) v → v ∈ l := fun v hv => by
by_contra hn; exact h2 v hn hv
obtain ⟨y', hy', y, hy, hyy⟩ := exists_adj_out G h l hne (by omega) hnd
have hlen2 : 2 ≤ l.length := by
by_contra hcon
have h1' : l.length = 1 := by omega
obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hy'
have : j = 0 := by omega
subst this
exact hy (hA y hyy)
have hall : ∀ v, v ≠ y → v ∈ l := by
intro v hvy
by_contra hv
have hnd2 : (v :: y :: l).Nodup := by
refine List.nodup_cons.mpr ⟨?_, List.nodup_cons.mpr ⟨hy, hnd⟩⟩
simp only [List.mem_cons, not_or]; exact ⟨hvy, hv⟩
have := hnd2.length_le_card
simp at this; omega
have hY : ∀ v, G.Adj y v → v ∈ l := fun v hv => hall v (G.ne_of_adj hv).symm
have hy0 : ¬ G.Adj y (l[0]'hpos) := fun hadj => hy (hA y hadj.symm)
have hyz : ¬ G.Adj y (l[l.length - 1]'(by omega)) := fun hadj => hy (hZ y hadj.symm)
have hzx : l[l.length - 1]'(by omega) ≠ x := by
rw [← hx]; intro heq
have := (List.Nodup.getElem_inj_iff hnd).mp heq
omega
have hyx : y ≠ x := by
rintro rfl; exact hy (hx ▸ List.getElem_mem hpos)
have e1 := hdeg _ hzx
have e2 := hdeg _ hyx
obtain ⟨l', -, hc', hnd', hlen'⟩ :=
path_absorb G l hc hnd hlen2 y hy hZ hY hy0 hyz (by omega)
exact ⟨l', hc', hnd', by omega⟩
theorem last_step (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected) (x : β) (s : ℕ)
(hdeg : ∀ y, y ≠ x → s ≤ G.degree y) (hm : Fintype.card β ≤ 2 * s + 1)
(l : List β) (hne : l ≠ []) (hc : l.IsChain G.Adj) (hnd : l.Nodup)
(hlen : l.length + 1 = Fintype.card β) :
∃ l' : List β, l'.IsChain G.Adj ∧ l'.Nodup ∧ l'.length = Fintype.card β := by
have hpos : 0 < l.length := List.length_pos_of_ne_nil hne
by_cases hx0 : l[0]'hpos = x
· exact last_step_head G h x s hdeg hm l hne hc hnd hlen hx0
by_cases hxz : l[l.length - 1]'(by omega) = x
· have hne' : l.reverse ≠ [] := by simpa using hne
refine last_step_head G h x s hdeg hm l.reverse hne'
(List.isChain_reverse.mpr (hc.imp fun _ _ h => h.symm)) (List.nodup_reverse.mpr hnd)
(by simpa using hlen) ?_
rw [← hxz, List.getElem_reverse]
congr 1
obtain ⟨l', -, hc', hnd', hlen'⟩ := ore_step_gen G h l hne hc hnd (by omega)
(fun h0 _ _ => by have := hdeg _ hx0; have := hdeg _ hxz; omega)
exact ⟨l', hc', hnd', by omega⟩
theorem ham_exists (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected) (x : β) (s : ℕ)
(hdeg : ∀ y, y ≠ x → s ≤ G.degree y) (hx1 : s ≤ G.degree x + 1)
(hm : Fintype.card β ≤ 2 * s + 1) (h2 : 2 ≤ Fintype.card β) :
∃ q : List β, q.IsChain G.Adj ∧ q.Nodup ∧ q.length = Fintype.card β := by
have hall : ∀ k, 1 ≤ k → k + 1 ≤ Fintype.card β →
∃ l : List β, l ≠ [] ∧ l.IsChain G.Adj ∧ l.Nodup ∧ l.length = k := by
intro k
induction k with
| zero => intro h0; omega
| succ k ih =>
intro _ hk
rcases Nat.eq_zero_or_pos k with rfl | hpos
· exact ⟨[x], by simp, List.isChain_singleton x, List.nodup_singleton x, rfl⟩
· obtain ⟨l, hne, hc, hnd, hl⟩ := ih hpos (by omega)
obtain ⟨l', hne', hc', hnd', hl'⟩ := ore_step_gen G h l hne hc hnd (by omega)
(fun h0 _ hne2 => by
have e1 : s ≤ G.degree (l[0]'h0) + 1 := by
by_cases hh : l[0]'h0 = x
· rw [hh]; exact hx1
· have := hdeg _ hh; omega
have e2 : s ≤ G.degree (l[l.length - 1]'(by omega)) + 1 := by
by_cases hh : l[l.length - 1]'(by omega) = x
· rw [hh]; exact hx1
· have := hdeg _ hh; omega
have e3 : s ≤ G.degree (l[0]'h0) ∨ s ≤ G.degree (l[l.length - 1]'(by omega)) := by
by_cases hh : l[0]'h0 = x
· right; exact hdeg _ (fun h' => hne2 (hh.trans h'.symm))
· left; exact hdeg _ hh
omega)
exact ⟨l', hne', hc', hnd', by omega⟩
obtain ⟨l, hne, hc, hnd, hl⟩ := hall (Fintype.card β - 1) (by omega) (by omega)
exact last_step G h x s hdeg hm l hne hc hnd (by omega)
/-- **Rooted traceability.** If every vertex other than `x` has degree at least `s`,
`s - 1 ≤ deg x ≤ s` and there are at most `2s + 1` vertices, then a Hamiltonian path starts at
`x`. -/
theorem rooted_ham (G : SimpleGraph β) [DecidableRel G.Adj] (h : G.Connected) (x : β) (s : ℕ)
(hdeg : ∀ y, y ≠ x → s ≤ G.degree y) (hx1 : s ≤ G.degree x + 1) (hdx : G.degree x ≤ s)
(hm : Fintype.card β ≤ 2 * s + 1) :
∃ l : List β, l.head? = some x ∧ l.IsChain G.Adj ∧ l.Nodup ∧
l.length = Fintype.card β := by
by_cases h2 : 2 ≤ Fintype.card β
· obtain ⟨q, hc, hnd, hlen⟩ := ham_exists G h x s hdeg hx1 hm h2
exact rooted_of_ham G x s hdeg hdx
(fun u v hu hv _ _ => by have := hdeg u hu; have := hdeg v hv; omega)
q hc hnd hlen (by omega)
· have h1 : Fintype.card β = 1 := by
have := Fintype.card_pos_iff.mpr ⟨x⟩; omega
exact ⟨[x], rfl, List.isChain_singleton x, List.nodup_singleton x, by simp [h1]⟩
end RootDev
theorem secondSmallestDegree_le_degree_or (G : SimpleGraph α) [DecidableRel G.Adj] (u v : α)
(huv : u ≠ v) : secondSmallestDegree G ≤ G.degree u ∨ secondSmallestDegree G ≤ G.degree v := by
classical
by_contra hcon
push Not at hcon
obtain ⟨hu, hv⟩ := hcon
have hsorted : (degreeSequence G).Pairwise (· ≤ ·) := Multiset.pairwise_sort _ _
have hperm : (degreeSequence G : Multiset ℕ) = Finset.univ.val.map fun w => G.degree w :=
Multiset.sort_eq _ _
have hlen : 2 ≤ (degreeSequence G).length := by
have := congrArg Multiset.card hperm
simp only [Multiset.coe_card, Multiset.card_map, Finset.card_val] at this
rw [this, Finset.card_univ]
exact Fintype.one_lt_card_iff_nontrivial.mpr inferInstance
obtain ⟨a, b, t, hl⟩ : ∃ a b t, degreeSequence G = a :: b :: t := by
match hds : degreeSequence G, hlen with
| a :: b :: t, _ => exact ⟨a, b, t, rfl⟩
have hb : secondSmallestDegree G = b := by
simp [secondSmallestDegree, hl]
rw [hb] at hu hv
rw [hl] at hsorted
have hbt : ∀ x ∈ t, b ≤ x := by
intro x hx
exact (List.pairwise_cons.mp (List.pairwise_cons.mp hsorted).2).1 x hx
-- count the degrees below `b`
have hcount : ((Finset.univ.val.map fun w => G.degree w).filter (· < b)).card ≤ 1 := by
rw [← hperm, hl]
simp only [Multiset.filter_coe, Multiset.coe_card]
have : (b :: t).filter (fun x => decide (x < b)) = [] := by
rw [List.filter_eq_nil_iff]
intro x hx
simp only [decide_eq_true_eq, not_lt]
rcases List.mem_cons.mp hx with rfl | hx
· exact le_rfl
· exact hbt x hx
rw [List.filter_cons]
split_ifs <;> simp [this]
have hge : 2 ≤ ((Finset.univ.val.map fun w => G.degree w).filter (· < b)).card := by
rw [Multiset.filter_map, Multiset.card_map]
have hsub : ({u, v} : Finset α) ⊆ Finset.univ.filter (fun w => G.degree w < b) := by
intro x hx
simp only [Finset.mem_insert, Finset.mem_singleton] at hx
rcases hx with rfl | rfl <;> simp [hu, hv]
have := Finset.card_le_card hsub
rw [Finset.card_pair huv] at this
exact this
omega
theorem card_dist_two_le_secondSmallestDegree (G : SimpleGraph α) [DecidableRel G.Adj]
(hσ : (Finset.univ.image (distEven G)).max' (Finset.univ_nonempty.image _) ≤
1 + secondSmallestDegree G) (v : α) :
(Finset.univ.filter fun w => G.dist v w = 2).card ≤ secondSmallestDegree G := by
classical
have hmem : distEven G v ∈ Finset.univ.image (distEven G) :=
Finset.mem_image_of_mem _ (Finset.mem_univ v)
have h1 := (Finset.le_max' _ _ hmem).trans hσ
have hsub : insert v (Finset.univ.filter fun w => G.dist v w = 2) ⊆
Finset.univ.filter fun w => Even (G.dist v w) := by
intro w hw
simp only [Finset.mem_insert, Finset.mem_filter, Finset.mem_univ, true_and] at hw ⊢
rcases hw with rfl | hw
· rw [SimpleGraph.dist_self]; exact ⟨0, rfl⟩
· rw [hw]; exact ⟨1, rfl⟩
have hnot : v ∉ Finset.univ.filter fun w => G.dist v w = 2 := by
simp [SimpleGraph.dist_self]
have h2 := Finset.card_le_card hsub
rw [Finset.card_insert_of_notMem hnot] at h2
unfold distEven at h1
omega
theorem pendant_dist (G : SimpleGraph α) (h : G.Connected) (w x : α) (hwx : G.Adj w x)
(huniq : ∀ v, G.Adj w v → v = x) (y : α) (hy : y ≠ w) :
G.dist w y = G.dist x y + 1 := by
apply le_antisymm
· have := h.dist_triangle (u := w) (v := x) (w := y)
rw [dist_eq_one_iff_adj.mpr hwx] at this; omega
· obtain ⟨p, hp⟩ := h.exists_walk_length_eq_dist w y
cases p with
| nil => exact absurd rfl hy
| cons hadj q =>
have := huniq _ hadj; subst this
have := SimpleGraph.dist_le q
simp only [Walk.length_cons] at hp; omega
/-- Intermediate lemma (nosorry): Diameter ≥ 3 case with a pendant vertex (about 40% of the hypothesis graphs of diameter ≥ 3 on 8 vertices). The Hamiltonian path must start at the pendant vertex. -/
theorem conjecture189_of_three_le_dist_of_degree_one (G : SimpleGraph α) [DecidableRel G.Adj] (h : G.Connected) (hσ : (Finset.univ.image (distEven G)).max' (Finset.univ_nonempty.image _) ≤ 1 + secondSmallestDegree G) (hd : ∃ u w : α, 3 ≤ G.dist u w) (hδ : ∃ w : α, G.degree w = 1) : ∃ a b : α, ∃ p : G.Walk a b, p.IsHamiltonian := by
classical
obtain ⟨w, hw⟩ := hδ
obtain ⟨x, hwx, huniq⟩ := degree_eq_one_iff_existsUnique_adj.mp hw
set σ := secondSmallestDegree G with hσdef
have hxw : x ≠ w := (G.ne_of_adj hwx).symm
have hF1 : ∀ y, y ≠ w → σ ≤ G.degree y := by
intro y hy
rcases secondSmallestDegree_le_degree_or G w y (Ne.symm hy) with h1 | h1
· rw [hw] at h1
obtain ⟨p⟩ := h.preconnected y w
cases p with
| nil => exact absurd rfl hy
| cons hadj _ =>
have := (G.degree_pos_iff_exists_adj y).mpr ⟨_, hadj⟩
omega
· exact h1
have hdist := pendant_dist G h w x hwx (fun v hv => huniq v hv)
have hF3 : G.degree x ≤ σ + 1 := by
have hc2 := card_dist_two_le_secondSmallestDegree G hσ w
have hsub : (G.neighborFinset x).erase w ⊆ Finset.univ.filter fun y => G.dist w y = 2 := by
intro y hy
rw [Finset.mem_erase, mem_neighborFinset] at hy
simp only [Finset.mem_filter, Finset.mem_univ, true_and]
rw [hdist y hy.1, dist_eq_one_iff_adj.mpr hy.2]
have := Finset.card_le_card hsub
rw [Finset.card_erase_of_mem (by rw [mem_neighborFinset]; exact hwx.symm),
card_neighborFinset_eq_degree] at this
omega
have hn : Fintype.card α ≤ 2 * σ + 2 := by
have hmem : ∀ v, distEven G v ≤ 1 + σ := fun v =>
(Finset.le_max' _ _ (Finset.mem_image_of_mem _ (Finset.mem_univ v))).trans hσ
have hunion : (Finset.univ : Finset α) ⊆ (Finset.univ.filter fun y => Even (G.dist w y)) ∪
(Finset.univ.filter fun y => Even (G.dist x y)) := by
intro y _
simp only [Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and]
by_cases hy : y = w
· left; rw [hy, SimpleGraph.dist_self]; exact ⟨0, rfl⟩
· rw [hdist y hy]
rcases Nat.even_or_odd (G.dist x y) with he | ho
· right; exact he
· left; exact ho.add_one
have := (Finset.card_le_card hunion).trans (Finset.card_union_le _ _)
rw [Finset.card_univ] at this
have h1 := hmem w
have h2 := hmem x
unfold distEven at h1 h2
omega
set s : Set α := {w}ᶜ with hs
have hHc : (G.induce s).Connected := h.induce_compl_singleton_of_degree_eq_one hw
have hxs : x ∈ s := by simp [hs, hxw]
let x' : s := ⟨x, hxs⟩
have hdegH : ∀ y' : s, y' ≠ x' → σ ≤ (G.induce s).degree y' := by
intro y' hy'
have hyx : y'.1 ≠ x := fun h' => hy' (Subtype.ext h')
have hyw : y'.1 ≠ w := by
have h3 : y'.1 ∈ ({w}ᶜ : Set α) := y'.2
exact Set.mem_compl_singleton_iff.mp h3
have hsub : G.neighborSet y' ⊆ s := by
intro v hv
simp only [hs, Set.mem_compl_iff, Set.mem_singleton_iff]
rintro rfl
exact hyx (huniq _ (G.adj_symm hv))
rw [degree_induce_of_neighborSet_subset hsub]
exact hF1 _ hyw
have hdegx : (G.induce s).degree x' + 1 = G.degree x := by
rw [← card_neighborFinset_eq_degree, ← card_neighborFinset_eq_degree,
← Finset.card_map (Function.Embedding.subtype _), map_neighborFinset_induce]
have : G.neighborFinset x ∩ s.toFinset = (G.neighborFinset x).erase w := by
ext v; simp [hs, and_comm]
rw [this, Finset.card_erase_of_mem (by rw [mem_neighborFinset]; exact hwx.symm)]
have : 0 < (G.neighborFinset x).card := Finset.card_pos.mpr ⟨w, by simpa using hwx.symm⟩
omega
have hcard : Fintype.card s + 1 = Fintype.card α := by
have e : Fintype.card s = (Finset.univ.erase w).card := by
apply Fintype.card_of_subtype; intro v; simp [hs]
rw [e, Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ]
have := Fintype.card_pos (α := α)
omega
have hF4 := hF1 x hxw
obtain ⟨l, hhead, hc, hnd, hlen⟩ :=
rooted_ham (G.induce s) hHc x' σ hdegH (by omega) (by omega) (by omega)
obtain ⟨t, rfl⟩ : ∃ t, l = x' :: t := by
cases l with
| nil => simp at hhead
| cons a t => simp only [List.head?_cons, Option.some.injEq] at hhead; exact ⟨t, by rw [hhead]⟩
have h1 : ((x' :: t).map Subtype.val).IsChain G.Adj :=
(List.isChain_map Subtype.val).mpr (hc.imp fun _ _ hab => hab)
have hLc : (w :: x :: t.map Subtype.val).IsChain G.Adj :=
List.isChain_cons_cons.mpr ⟨hwx, h1⟩
have hLnd : (w :: x :: t.map Subtype.val).Nodup := by
have h2 : ((x' :: t).map Subtype.val).Nodup := hnd.map Subtype.val_injective
refine List.nodup_cons.mpr ⟨?_, h2⟩
intro hmem
have : w ∈ (x' :: t).map Subtype.val := hmem
obtain ⟨a, -, ha⟩ := List.mem_map.mp this
have := a.2
simp [hs, ha] at this
have hLlen : (w :: x :: t.map Subtype.val).length = Fintype.card α := by
simp only [List.length_cons, List.length_map] at hlen ⊢
omega
obtain ⟨b, p, hp⟩ := exists_walk_of_isChain G (x :: t.map Subtype.val) w hLc
refine ⟨w, b, p, ?_⟩
have hpath : p.IsPath := (Walk.isPath_def p).mpr (hp ▸ hLnd)
apply hpath.isHamiltonian_of_mem
intro v
rw [hp]
have huniv : (w :: x :: t.map Subtype.val).toFinset = Finset.univ :=
Finset.eq_univ_of_card _ (by rw [List.toFinset_card_of_nodup hLnd, hLlen])
have : v ∈ (w :: x :: t.map Subtype.val).toFinset := huniv ▸ Finset.mem_univ v
exact List.mem_toFinset.mp this
end WrittenOnTheWallII.GraphConjecture189