Lean / Reader
Lean readerSparsePalette.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Growth, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import Growthimport Mathlib.Data.Nat.Factorial.Basicimport Mathlib.Logic.Equiv.Fin.Basicnamespace ProgressionColoursprivate theorem index_divides {a d b e i I j J L : ℕ} (hj : j<J) (hJ : J≤L)(cop : d.Coprime L.factorial) (h1 : b+j*e=a+i*d) (h2 : b+J*e=a+I*d) : d ∣ e := byhave dd : d ∣ (J-j)*e := byhave H := Nat.dvd_sub (Nat.dvd_mul_left d I) (Nat.dvd_mul_left d i)have heq : J*e-j*e= I*d-i*d := by omegarwa [Nat.sub_mul,heq]exact (cop.coprime_dvd_right (Nat.dvd_factorial (by omega : 0<J-j) (by omega : J-j≤L))).dvd_of_dvd_mul_left dd/-- If the blocked step is coprime to every possible index gap in a longer progression,each longer progression intersects the blocked progression in at most one point. -/theorem coprime_intersection {N k a d b e : ℕ} (hb : Blocked N k a d)(cop : d.Coprime (k+1).factorial) (he : 0<e) (hend : b+(k+1)*e<N){x y : ℕ} (xp : x∈progression a d k) (yp : y∈progression a d k)(xq : x∈progression b e (k+1)) (yq : y∈progression b e (k+1)) : x=y := byobtain ⟨i,_,hi⟩ := Finset.mem_image.mp xpobtain ⟨I,_,hI⟩ := Finset.mem_image.mp ypobtain ⟨j,hj,hje⟩ := Finset.mem_image.mp xqobtain ⟨J,hJ,hJe⟩ := Finset.mem_image.mp yqhave jbound := Finset.mem_range.mp hj;have Jbound := Finset.mem_range.mp hJby_contra hnhave hne : j≠J := by intro hh;subst J;omegahave div : d ∣ e := byrcases Nat.lt_or_gt_of_ne hne with hh | hh· exact index_divides hh (by omega) cop (hje.trans hi.symm) (hJe.trans hI.symm)· exact index_divides hh (by omega) cop (hJe.trans hI.symm) (hje.trans hi.symm)have hde := Nat.le_of_dvd he divhave hm := Nat.mul_le_mul_left (k+1) hdeobtain ⟨s,rfl⟩ := divhave eq : b%d=a := byhave h := congrArg (· % d) (hje.trans hi.symm)change (b+j*(d*s))%d=(a+i*d)%d at hrw [show j*(d*s)=(j*s)*d by ring,Nat.add_mul_mod_self_right,Nat.add_mul_mod_self_right,Nat.mod_eq_of_lt hb.2.2.1] at hexact hhave hab := Nat.mod_le b dhave := hb.2.2.2;omega/-- Change all positions in `P` to a single fresh colour. -/def mark {α : Type*} (P : Finset ℕ) (c : ℕ → α) (x : ℕ) : Option α :=if x∈P then none else some (c x)theorem fresh_valid {N k : ℕ} {α : Type*} {c : ℕ → α} (hv : Valid N k c) (P : Finset ℕ)(hP : ∀ b e, 0<e → b+(k+1)*e<N → ∀ x∈P, ∀ y∈P,x∈progression b e (k+1) → y∈progression b e (k+1) → x=y) : Valid N k (mark P c) := byintro b e he hi u vlet Q := progression b e (k+1)have off (col : α) : ∃ x∈Q, x∉P ∧ c x≠col := byby_cases hit : ∃ y∈Q, y∈P· obtain ⟨y,hy,hp⟩ := hitobtain ⟨x,hx,hn1,hn2⟩ := hv b e he hi col (c y)exact ⟨x,hx,fun hxP => hn2 (congrArg c (hP b e he hi x hxP y hp hx hy)),hn1⟩· obtain ⟨x,hx,hn,_⟩ := hv b e he hi col colexact ⟨x,hx,fun hp => hit ⟨x,hx,hp⟩,hn⟩cases u with| none =>cases v with| none => obtain ⟨x,hx,hp,_⟩ := off (c 0);exact ⟨x,hx,by simp [mark,hp],by simp [mark,hp]⟩| some v => obtain ⟨x,hx,hp,hn⟩ := off v;exact ⟨x,hx,by simp [mark,hp],by simp [mark,hp,hn]⟩| some u =>cases v with| none => obtain ⟨x,hx,hp,hn⟩ := off u;exact ⟨x,hx,by simp [mark,hp,hn],by simp [mark,hp]⟩| some v =>obtain ⟨x,hx,hu,hv'⟩ := hv b e he hi u vby_cases hp : x∈P <;> exact ⟨x,hx,by simp [mark,hp,hu],by simp [mark,hp,hv']⟩theorem bounded_palette_coprime {N k a d K : ℕ} (hb : Blocked N k a d)(cop : d.Coprime (k+1).factorial) (c : ℕ → Fin K) (hv : Valid N k c) :∃ c' : ℕ → Fin (K+1), Valid N k c' ∧ Mono c' (progression a d k) := bylet P := progression a d klet f := mark P chave h := fresh_valid hv P (fun _ _ he hh _ xp _ yp xq yq => coprime_intersection hb cop he hh xp yp xq yq)let equiv := (finSuccEquiv K).symmrefine ⟨fun x => equiv (f x),?_,equiv none,fun x hx => by simp [f,mark,hx,P]⟩intro b e he hh u vobtain ⟨x,hx,hn1,hn2⟩ := h b e he hh (equiv.symm u) (equiv.symm v)exact ⟨x,hx,fun hx => hn1 (equiv.eq_symm_apply.mpr hx),fun hx => hn2 (equiv.eq_symm_apply.mpr hx)⟩end ProgressionColours