Lean / Reader
Lean reader

SparsePalette.lean

84 lines5 declarationsno sorryimports Growth Mathlib.Data.Nat.Factorial.Basic Mathlib.Logic.Equiv.Fin.Basic

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.

  1. import Growth
  2. import Mathlib.Data.Nat.Factorial.Basic
  3. import Mathlib.Logic.Equiv.Fin.Basic
  4. namespace ProgressionColours
  5. private theorem index_divides {a d b e i I j J L : ℕ} (hj : j<J) (hJ : J≤L)
  6. (cop : d.Coprime L.factorial) (h1 : b+j*e=a+i*d) (h2 : b+J*e=a+I*d) : d ∣ e := by
  7. have dd : d ∣ (J-j)*e := by
  8. have H := Nat.dvd_sub (Nat.dvd_mul_left d I) (Nat.dvd_mul_left d i)
  9. have heq : J*e-j*e= I*d-i*d := by omega
  10. rwa [Nat.sub_mul,heq]
  11. exact (cop.coprime_dvd_right (Nat.dvd_factorial (by omega : 0<J-j) (by omega : J-j≤L))).dvd_of_dvd_mul_left dd
  12. /-- If the blocked step is coprime to every possible index gap in a longer progression,
  13. each longer progression intersects the blocked progression in at most one point. -/
  14. theorem coprime_intersection {N k a d b e : ℕ} (hb : Blocked N k a d)
  15. (cop : d.Coprime (k+1).factorial) (he : 0<e) (hend : b+(k+1)*e<N)
  16. {x y : ℕ} (xp : x∈progression a d k) (yp : y∈progression a d k)
  17. (xq : x∈progression b e (k+1)) (yq : y∈progression b e (k+1)) : x=y := by
  18. obtain ⟨i,_,hi⟩ := Finset.mem_image.mp xp
  19. obtain ⟨I,_,hI⟩ := Finset.mem_image.mp yp
  20. obtain ⟨j,hj,hje⟩ := Finset.mem_image.mp xq
  21. obtain ⟨J,hJ,hJe⟩ := Finset.mem_image.mp yq
  22. have jbound := Finset.mem_range.mp hj;have Jbound := Finset.mem_range.mp hJ
  23. by_contra hn
  24. have hne : j≠J := by intro hh;subst J;omega
  25. have div : d ∣ e := by
  26. rcases Nat.lt_or_gt_of_ne hne with hh | hh
  27. · exact index_divides hh (by omega) cop (hje.trans hi.symm) (hJe.trans hI.symm)
  28. · exact index_divides hh (by omega) cop (hJe.trans hI.symm) (hje.trans hi.symm)
  29. have hde := Nat.le_of_dvd he div
  30. have hm := Nat.mul_le_mul_left (k+1) hde
  31. obtain ⟨s,rfl⟩ := div
  32. have eq : b%d=a := by
  33. have h := congrArg (· % d) (hje.trans hi.symm)
  34. change (b+j*(d*s))%d=(a+i*d)%d at h
  35. rw [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 h
  36. exact h
  37. have hab := Nat.mod_le b d
  38. have := hb.2.2.2;omega
  39. /-- Change all positions in `P` to a single fresh colour. -/
  40. def mark {α : Type*} (P : Finset ℕ) (c : ℕ → α) (x : ℕ) : Option α :=
  41. if x∈P then none else some (c x)
  42. theorem fresh_valid {N k : ℕ} {α : Type*} {c : ℕ → α} (hv : Valid N k c) (P : Finset ℕ)
  43. (hP : ∀ b e, 0<e → b+(k+1)*e<N → ∀ x∈P, ∀ y∈P,
  44. x∈progression b e (k+1) → y∈progression b e (k+1) → x=y) : Valid N k (mark P c) := by
  45. intro b e he hi u v
  46. let Q := progression b e (k+1)
  47. have off (col : α) : ∃ x∈Q, x∉P ∧ c x≠col := by
  48. by_cases hit : ∃ y∈Q, y∈P
  49. · obtain ⟨y,hy,hp⟩ := hit
  50. obtain ⟨x,hx,hn1,hn2⟩ := hv b e he hi col (c y)
  51. exact ⟨x,hx,fun hxP => hn2 (congrArg c (hP b e he hi x hxP y hp hx hy)),hn1⟩
  52. · obtain ⟨x,hx,hn,_⟩ := hv b e he hi col col
  53. exact ⟨x,hx,fun hp => hit ⟨x,hx,hp⟩,hn⟩
  54. cases u with
  55. | none =>
  56. cases v with
  57. | none => obtain ⟨x,hx,hp,_⟩ := off (c 0);exact ⟨x,hx,by simp [mark,hp],by simp [mark,hp]⟩
  58. | some v => obtain ⟨x,hx,hp,hn⟩ := off v;exact ⟨x,hx,by simp [mark,hp],by simp [mark,hp,hn]⟩
  59. | some u =>
  60. cases v with
  61. | none => obtain ⟨x,hx,hp,hn⟩ := off u;exact ⟨x,hx,by simp [mark,hp,hn],by simp [mark,hp]⟩
  62. | some v =>
  63. obtain ⟨x,hx,hu,hv'⟩ := hv b e he hi u v
  64. by_cases hp : x∈P <;> exact ⟨x,hx,by simp [mark,hp,hu],by simp [mark,hp,hv']⟩
  65. theorem bounded_palette_coprime {N k a d K : ℕ} (hb : Blocked N k a d)
  66. (cop : d.Coprime (k+1).factorial) (c : ℕ → Fin K) (hv : Valid N k c) :
  67. ∃ c' : ℕ → Fin (K+1), Valid N k c' ∧ Mono c' (progression a d k) := by
  68. let P := progression a d k
  69. let f := mark P c
  70. have h := fresh_valid hv P (fun _ _ he hh _ xp _ yp xq yq => coprime_intersection hb cop he hh xp yp xq yq)
  71. let equiv := (finSuccEquiv K).symm
  72. refine ⟨fun x => equiv (f x),?_,equiv none,fun x hx => by simp [f,mark,hx,P]⟩
  73. intro b e he hh u v
  74. obtain ⟨x,hx,hn1,hn2⟩ := h b e he hh (equiv.symm u) (equiv.symm v)
  75. exact ⟨x,hx,fun hx => hn1 (equiv.eq_symm_apply.mpr hx),fun hx => hn2 (equiv.eq_symm_apply.mpr hx)⟩
  76. end ProgressionColours