Lean / Reader
Lean readerPaletteDomains.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports SparsePalette, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import SparsePalettenamespace ProgressionColoursdef SafeFor (α : Type*) (N k : ℕ) (S : Finset ℕ) : Prop :=∀ c : ℕ → α, Valid N k c → ∀ a d, 0<d → progression a d k ⊆ S → ¬ Mono c (progression a d k)theorem safe_of_hits {α : Type*} {N k : ℕ} (S : Finset ℕ) (hs : S⊆Finset.range N)(hit : Hits N k (Finset.range N \ S)) : SafeFor α N k S := byintro c hv a d hd sub hmhave hin := Finset.mem_range.mp (hs (sub (term_mem (j:=k) le_rfl)))obtain ⟨x,hx,hp⟩ := hit a d (mono_blocked hv hd hin hm)exact (Finset.mem_sdiff.mp hx).2 (sub hp)/-- A proof that every blocked progression is attainable proves sharpness for a fixed palette. -/theorem safe_iff_hits_of_attainable {α : Type*} {N k : ℕ} (S : Finset ℕ) (hs : S⊆Finset.range N)(att : ∀ a d, Blocked N k a d → ∃ c : ℕ → α, Valid N k c ∧ Mono c (progression a d k)) :SafeFor α N k S ↔ Hits N k (Finset.range N \ S) := byrefine ⟨?_,safe_of_hits S hs⟩intro safe a d hbobtain ⟨c,hc,hm⟩ := att a d hbby_contra! happly safe c hc a d hb.1 _ hmintro x hxobtain ⟨j,hj,hje⟩ := Finset.mem_image.mp hxhave hj' : j≤k := by have := Finset.mem_range.mp hj;omegahave hn : x ∈ Finset.range N := Finset.mem_range.mpr (by have := Nat.mul_le_mul_right d hj';have := hb.2.1;omega)by_contra hn';exact h x (Finset.mem_sdiff.mpr ⟨hn,hn'⟩) hx/-- When `N=3q` and `q` is coprime to six, a single additional colour already makes`2q` the sharp universal-domain size. -/theorem sharp_with_one_extra {q K : ℕ} (hq : 0<q) (hc : q.Coprime 6)(c : ℕ → Fin K) (hv : Valid (3*q) 2 c) :∃ S ⊆ Finset.range (3*q), SafeFor (Fin (K+1)) (3*q) 2 S ∧ S.card=2*q ∧∀ A ⊆ Finset.range (3*q), SafeFor (Fin (K+1)) (3*q) 2 A → A.card ≤ S.card := byobtain ⟨S,hs,hu,hcard,_⟩ := sharp_for_erdos160 (3*q) (by omega)refine ⟨S,hs,safe_of_hits S hs ((universal_iff (by decide) S hs).1 hu),by omega,?_⟩intro A hA safelet T := Finset.range (3*q) \ Ahave elem (i : Fin q) : ∃ x ∈ T, x ∈ progression i.val q 2 := byhave hb : Blocked (3*q) 2 i.val q := ⟨hq,by omega,i.isLt,by omega⟩obtain ⟨c',hv',hm⟩ := bounded_palette_coprime hb (by simpa using hc) c hvby_contra! nhapply safe c' hv' i.val q hq _ hmintro x hxinobtain ⟨j,hj,he⟩ := Finset.mem_image.mp hxinhave jj : j≤2 := by have := Finset.mem_range.mp hj;omegahave hlim := Nat.mul_le_mul_right q jjby_contra hnexact nh x (Finset.mem_sdiff.mpr ⟨Finset.mem_range.mpr (by omega),hn⟩) hxinchoose f hf hg using elemlet g : Fin q → ↥T := fun i => ⟨f i,hf i⟩have residue (i : Fin q) : f i%q=i.val := byobtain ⟨j,_,hj⟩ := Finset.mem_image.mp (hg i)rw [←hj,Nat.add_mul_mod_self_right,Nat.mod_eq_of_lt i.isLt]have inj : Function.Injective g := byintro i j hh;have he : f i=f j := congrArg Subtype.val hhexact Fin.ext ((residue i).symm.trans ((congrArg (· % q) he).trans (residue j)))have card : q≤(Finset.range (3*q) \ A).card := by simpa [T] using Fintype.card_le_of_injective g injrw [Finset.card_sdiff_of_subset hA,Finset.card_range] at cardhave := Finset.card_le_card hAsimp only [Finset.card_range] at *;omegaend ProgressionColours