Lean / Reader
Lean readerDetour.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports RingObstruction, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import RingObstructionopen SimpleGraph SimpleGraph.Walknamespace TerminalCyclesuniverse u/-- The two designated vertices have degree exactly two. In the absenceof a power-of-two cycle, they admit a path strictly longer than twice theirdistance. Reachability avoids mathlib's junk distance for unrelated vertices. -/def two_defect_detour : Prop :=∀ (T : Type u) [Finite T] (K : SimpleGraph T) (s t : T), s ≠ t → valence K s = 2 →valence K t = 2 → (∀ v, v ≠ s → v ≠ t → 3 ≤ valence K v) →¬ hasPowerCycle K → K.Reachable s t → ∃ p : K.Walk s t, p.IsPath ∧ 2*K.dist s t < p.lengthprivate theorem detour_of_erdos (conjecture : erdos64Statement.{u}) : two_defect_detour.{u} := byintro T _ K s t ne ds dt others absent reachclassicallet d := K.dist s thave positive : 1 ≤ d := byhave nz : K.dist s t ≠ 0 := fun h => ((dist_eq_zero_iff_eq_or_not_reachable.mp h).elim ne (fun q => q reach))change 1 ≤ K.dist s tomegaby_contra nolet X : PathBlock.{u} (d+1) (2*d+1) (Nat.card T) := {Vertex := T, finite := inferInstance, graph := K, start := s, finish := t,rootDegree := ds.ge, side := ⟨ne.symm,dt.ge,others,absent⟩, order := rfl,window := byintro p hphave lower : d ≤ p.length := SimpleGraph.dist_le phave upper : ¬ 2*d < p.length := fun h => no ⟨p,hp,h⟩omega }exact X.narrow_window_refutes_erdos64 positive (by omega) (by omega) conjectureprivate abbrev Tri : Type u := ULift.{u} (Fin 3)private abbrev triangle : SimpleGraph Tri.{u} := ⊤private abbrev t0 : Tri.{u} := ⟨0⟩private abbrev t1 : Tri.{u} := ⟨1⟩private abbrev t2 : Tri.{u} := ⟨2⟩private theorem tri_degree (v : Tri.{u}) : valence triangle v = 2 := byrw [valence_eq_degree]; simp [Tri,Fintype.card_ulift]private theorem triangle_absent : ¬ hasPowerCycle triangle.{u} := byrintro ⟨k,v,p,hk,hp,len⟩cases p with| nil => exact hp.ne_nil rfl| cons h q =>have simple := ((cons_isCycle_iff _ _).mp hp).1have upper := simple.length_lthave n : Fintype.card Tri.{u} = 3 := by simp [Tri]have pow := Nat.pow_le_pow_right (by decide : 0 < 2) hksimp only [length_cons] at lenomegaprivate theorem erdos_of_detour (detour : two_defect_detour.{u}) : erdos64Statement.{u} := byintro T G _ _ highclassicalrcases isEmpty_or_nonempty T with empty | nonempty· simp at high· let b := nonempty.someby_contra nolet K := wedge triangle G t0 blet s : WedgeVertex Tri b := Sum.inl t1let t : WedgeVertex Tri b := Sum.inl t2have ne : s ≠ t := fun e => (by decide : t1.{u} ≠ t2) (Sum.inl.inj e)have ds : valence K s = 2 := (wedge_left_exact triangle G t0 b t1 (by decide)).trans (tri_degree _)have dt : valence K t = 2 := (wedge_left_exact triangle G t0 b t2 (by decide)).trans (tri_degree _)have orig (x : T) : 3 ≤ valence G x := by rw [valence_eq_degree]; exact high.trans (G.minDegree_le_degree x)have rest (v : WedgeVertex Tri b) (vs : v ≠ s) (vt : v ≠ t) : 3 ≤ valence K v := bycases v with| inl z =>have e1 : z ≠ t1 := fun e => vs (congrArg Sum.inl e)have e2 : z ≠ t2 := fun e => vt (congrArg Sum.inl e)have z0 : z=t0 := byrcases z with ⟨i⟩have a : i ≠ (1 : Fin 3) := fun h => e1 (congrArg ULift.up h)have b' : i ≠ (2 : Fin 3) := fun h => e2 (congrArg ULift.up h)exact congrArg ULift.up (show i=0 by omega)subst zhave bound := wedge_root_degree triangle G t0 bhave dg := orig bexact dg.trans ((Nat.le_add_left _ _).trans bound)| inr z => exact (orig z.val).trans (wedge_right_degree triangle G t0 b z)have noK : ¬ hasPowerCycle K := fun h => (wedge_cycle_from_side triangle G t0 b h).elim triangle_absent nohave edge : K.Adj s t := (by decide : t1.{u} ≠ t2)have d : K.dist s t=1 := dist_eq_one_iff_adj.mpr edgeobtain ⟨p,hp,long⟩ := detour _ K s t ne ds dt rest noK edge.reachableobtain ⟨q,hq,size⟩ := wedge_left_path triangle G t0 b p hphave short := hq.length_lthave n : Fintype.card Tri.{u}=3 := by simp [Tri]omega/-- A reformulation of the full Erdős–Gyárfás conjecture in terms of pathlengths in graphs with exactly two degree-two vertices. -/theorem erdos64_iff_two_defect_detour : erdos64Statement.{u} ↔ two_defect_detour.{u} :=⟨detour_of_erdos,erdos_of_detour⟩end TerminalCycles