Lean / Reader
Lean reader

PaletteDomains.lean

65 lines4 declarationsno sorryimports SparsePalette

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.

  1. import SparsePalette
  2. namespace ProgressionColours
  3. def SafeFor (α : Type*) (N k : ℕ) (S : Finset ℕ) : Prop :=
  4. ∀ c : ℕ → α, Valid N k c → ∀ a d, 0<d → progression a d k ⊆ S → ¬ Mono c (progression a d k)
  5. theorem safe_of_hits {α : Type*} {N k : ℕ} (S : Finset ℕ) (hs : S⊆Finset.range N)
  6. (hit : Hits N k (Finset.range N \ S)) : SafeFor α N k S := by
  7. intro c hv a d hd sub hm
  8. have hin := Finset.mem_range.mp (hs (sub (term_mem (j:=k) le_rfl)))
  9. obtain ⟨x,hx,hp⟩ := hit a d (mono_blocked hv hd hin hm)
  10. exact (Finset.mem_sdiff.mp hx).2 (sub hp)
  11. /-- A proof that every blocked progression is attainable proves sharpness for a fixed palette. -/
  12. theorem safe_iff_hits_of_attainable {α : Type*} {N k : ℕ} (S : Finset ℕ) (hs : S⊆Finset.range N)
  13. (att : ∀ a d, Blocked N k a d → ∃ c : ℕ → α, Valid N k c ∧ Mono c (progression a d k)) :
  14. SafeFor α N k S ↔ Hits N k (Finset.range N \ S) := by
  15. refine ⟨?_,safe_of_hits S hs⟩
  16. intro safe a d hb
  17. obtain ⟨c,hc,hm⟩ := att a d hb
  18. by_contra! h
  19. apply safe c hc a d hb.1 _ hm
  20. intro x hx
  21. obtain ⟨j,hj,hje⟩ := Finset.mem_image.mp hx
  22. have hj' : j≤k := by have := Finset.mem_range.mp hj;omega
  23. have hn : x ∈ Finset.range N := Finset.mem_range.mpr (by have := Nat.mul_le_mul_right d hj';have := hb.2.1;omega)
  24. by_contra hn';exact h x (Finset.mem_sdiff.mpr ⟨hn,hn'⟩) hx
  25. /-- When `N=3q` and `q` is coprime to six, a single additional colour already makes
  26. `2q` the sharp universal-domain size. -/
  27. theorem sharp_with_one_extra {q K : ℕ} (hq : 0<q) (hc : q.Coprime 6)
  28. (c : ℕ → Fin K) (hv : Valid (3*q) 2 c) :
  29. ∃ S ⊆ Finset.range (3*q), SafeFor (Fin (K+1)) (3*q) 2 S ∧ S.card=2*q ∧
  30. ∀ A ⊆ Finset.range (3*q), SafeFor (Fin (K+1)) (3*q) 2 A → A.card ≤ S.card := by
  31. obtain ⟨S,hs,hu,hcard,_⟩ := sharp_for_erdos160 (3*q) (by omega)
  32. refine ⟨S,hs,safe_of_hits S hs ((universal_iff (by decide) S hs).1 hu),by omega,?_⟩
  33. intro A hA safe
  34. let T := Finset.range (3*q) \ A
  35. have elem (i : Fin q) : ∃ x ∈ T, x ∈ progression i.val q 2 := by
  36. have hb : Blocked (3*q) 2 i.val q := ⟨hq,by omega,i.isLt,by omega⟩
  37. obtain ⟨c',hv',hm⟩ := bounded_palette_coprime hb (by simpa using hc) c hv
  38. by_contra! nh
  39. apply safe c' hv' i.val q hq _ hm
  40. intro x hxin
  41. obtain ⟨j,hj,he⟩ := Finset.mem_image.mp hxin
  42. have jj : j≤2 := by have := Finset.mem_range.mp hj;omega
  43. have hlim := Nat.mul_le_mul_right q jj
  44. by_contra hn
  45. exact nh x (Finset.mem_sdiff.mpr ⟨Finset.mem_range.mpr (by omega),hn⟩) hxin
  46. choose f hf hg using elem
  47. let g : Fin q → ↥T := fun i => ⟨f i,hf i⟩
  48. have residue (i : Fin q) : f i%q=i.val := by
  49. obtain ⟨j,_,hj⟩ := Finset.mem_image.mp (hg i)
  50. rw [←hj,Nat.add_mul_mod_self_right,Nat.mod_eq_of_lt i.isLt]
  51. have inj : Function.Injective g := by
  52. intro i j hh;have he : f i=f j := congrArg Subtype.val hh
  53. exact Fin.ext ((residue i).symm.trans ((congrArg (· % q) he).trans (residue j)))
  54. have card : q≤(Finset.range (3*q) \ A).card := by simpa [T] using Fintype.card_le_of_injective g inj
  55. rw [Finset.card_sdiff_of_subset hA,Finset.card_range] at card
  56. have := Finset.card_le_card hA
  57. simp only [Finset.card_range] at *;omega
  58. end ProgressionColours