Lean / Reader
Lean readerTriangularStatement.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports TriangularCertificate, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import TriangularCertificatenamespace TriangularRamsey/-- The intrinsic patch has rows of lengths nine, eight, …, one. -/abbrev T9 := {p : Point // p.1 + p.2 < 9}/-- Brouwer, Joe, Noble and Noble, Question 2. -/theorem no_proper_three_coloring (color : T9 → Fin 3) :∃ p q r : T9, equilateral p.val q.val r.val ∧ color p = color q ∧ color p = color r := bylet f (p : Point) := if h : p.1 + p.2 < 9 then color ⟨p,h⟩ else 0obtain ⟨p,q,r,⟨hp,hq,hr,he⟩,hpq,hpr⟩ := nine_row_triangle funfold grid at hp hq hrexact ⟨⟨p,hp⟩,⟨q,hq⟩,⟨r,hr⟩,he,by simpa [f,hp,hq,grid] using hpq,by simpa [f,hp,hr,grid] using hpr⟩/-- Four color classes, written in the coordinate encoding `9*x+y`. -/private def classes : Fin 4 → List ℕ| 0 => [1,2,6,11,20,21,31,36,48,55,56,63,72]| 1 => [0,3,5,12,14,24,32,37,38,39,54,64]| 2 => [4,7,16,18,19,23,40,45,46,47]| 3 => [8,9,10,13,15,22,27,28,29,30]private def encode (p : Point) := 9*p.1+p.2private theorem decode_encode (p : T9) : decode (encode p.val) = p.val := byobtain ⟨⟨x,y⟩,h⟩ := pchange x+y<9 at happly Prod.ext <;> simp [encode,decode] <;> omegaprivate theorem covered (p : T9) : ∃ c : Fin 4, encode p.val ∈ classes c := byhave h : ∀ x y : Fin 9, x.val+y.val<9 → ∃ c : Fin 4, 9*x.val+y.val ∈ classes c := bydecide +kernelobtain ⟨⟨x,y⟩,hp⟩ := pchange x+y<9 at hpexact h ⟨x,by omega⟩ ⟨y,by omega⟩ hpprivate instance (p q r : Point) : Decidable (equilateral p q r) := byunfold equilateral; infer_instanceprivate theorem independent (c : Fin 4) (x y z : ℕ)(hx : x ∈ classes c) (hy : y ∈ classes c) (hz : z ∈ classes c) :¬equilateral (decode x) (decode y) (decode z) := byhave h : ∀ d : Fin 4, (classes d).all (fun i => (classes d).all (fun j =>(classes d).all (fun k => decide (¬equilateral (decode i) (decode j) (decode k))))) = true := bydecide +kernelsimpa using List.all_eq_true.mp (List.all_eq_true.mp (List.all_eq_true.mp (h c) x hx) y hy) z hz/-- A matching four-coloring certifies the exact chromatic number. -/theorem proper_four_coloring : ∃ color : T9 → Fin 4, ∀ p q r : T9,equilateral p.val q.val r.val → ¬(color p = color q ∧ color p = color r) := byclassicallet color (p : T9) := Classical.choose (covered p)have hc (p : T9) : encode p.val ∈ classes (color p) := Classical.choose_spec (covered p)refine ⟨color,?_⟩rintro p q r he ⟨hpq,hpr⟩apply independent (color p) (encode p.val) (encode q.val) (encode r.val) (hc p)(hpq ▸ hc q) (hpr ▸ hc r)simpa only [decode_encode] using he#print axioms no_proper_three_coloring#print axioms proper_four_coloringend TriangularRamsey