Lean / Reader
Lean reader

ColourRestrictions.lean

208 lines15 declarationsno sorryimports ProgressionColours Mathlib.Algebra.Order.BigOperators.Group.Finset

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports ProgressionColours, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import ProgressionColours
  2. import Mathlib.Algebra.Order.BigOperators.Group.Finset
  3. namespace ProgressionColours
  4. /-- Every length `k+2` progression in the interval uses a colour outside any given pair. -/
  5. def Valid (N k : ℕ) {α : Type*} (c : ℕ → α) : Prop :=
  6. ∀ a d, 0 < d → a+(k+1)*d < N → ∀ u v, ∃ x ∈ progression a d (k+1), c x ≠ u ∧ c x ≠ v
  7. def Mono {α : Type*} (c : ℕ → α) (P : Finset ℕ) : Prop := ∃ u, ∀ x ∈ P, c x = u
  8. /-- No valid natural-number colouring has a monochromatic length `k+1` progression in `S`. -/
  9. def Universal (N k : ℕ) (S : Finset ℕ) : Prop :=
  10. ∀ (c : ℕ → ℕ), Valid N k c → ∀ a d, 0 < d → progression a d k ⊆ S → ¬ Mono c (progression a d k)
  11. theorem term_mem {a d k j : ℕ} (hj : j≤k) : a+j*d ∈ progression a d k :=
  12. Finset.mem_image.mpr ⟨j, Finset.mem_range.mpr (by omega),rfl⟩
  13. theorem card_progression (a k : ℕ) {d : ℕ} (hd : 0<d) : (progression a d k).card=k+1 := by
  14. have h : Function.Injective (fun j : ℕ => a+j*d) := by
  15. intro i j h; exact Nat.eq_of_mul_eq_mul_right hd (Nat.add_left_cancel h)
  16. simp [progression,Finset.card_image_of_injective _ h]
  17. theorem mono_blocked {α : Type*} {N k a d : ℕ} {c : ℕ → α} (hv : Valid N k c)
  18. (hd : 0<d) (hin : a+k*d<N) (hm : Mono c (progression a d k)) : Blocked N k a d := by
  19. obtain ⟨u,hu⟩ := hm
  20. refine ⟨hd,hin,?_,?_⟩
  21. · by_contra! h
  22. obtain ⟨x,hx,h1,h2⟩ := hv (a-d) d hd (by rw [Nat.add_mul,Nat.one_mul];omega) u (c (a-d))
  23. obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  24. cases j with
  25. | zero => simp at h2
  26. | succ j =>
  27. have hj' : j≤k := by have := Finset.mem_range.mp hj;omega
  28. have he : a-d+(j+1)*d=a+j*d := by rw [Nat.add_mul,Nat.one_mul];omega
  29. exact h1 (he ▸ hu _ (term_mem hj'))
  30. · by_contra! h
  31. obtain ⟨x,hx,h1,h2⟩ := hv a d hd h u (c (a+(k+1)*d))
  32. obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx
  33. by_cases hj' : j≤k
  34. · exact h1 (hu _ (term_mem hj'))
  35. · have he : j=k+1 := by have := Finset.mem_range.mp hj; omega
  36. exact h2 (by rw [he])
  37. /-- When at least three equally spaced terms fit in a progression one term longer, its
  38. common difference must be the same and it must be an end segment. -/
  39. theorem no_larger_progression {N k a d b e : ℕ} (hk : 2≤k) (hb : Blocked N k a d)
  40. (he : 0<e) (hend : b+(k+1)*e<N) : ¬ progression a d k ⊆ progression b e (k+1) := by
  41. intro sub
  42. obtain ⟨hpos,_,hleft,hright⟩ := hb
  43. have hmem (j : ℕ) (hj : j≤k) := sub (term_mem (a:=a) (d:=d) hj)
  44. obtain ⟨i,hi,hi'⟩ := Finset.mem_image.mp (hmem 0 (by omega))
  45. obtain ⟨j,hj,hj'⟩ := Finset.mem_image.mp (hmem 1 (by omega))
  46. obtain ⟨l,hl,hl'⟩ := Finset.mem_image.mp (hmem k le_rfl)
  47. simp only [Nat.zero_mul,Nat.add_zero,Nat.one_mul] at hi' hj'
  48. have hlbound := Finset.mem_range.mp hl
  49. have ij : i<j := by by_contra! h; have := Nat.mul_le_mul_right e h; omega
  50. have delta : d=(j-i)*e := by rw [Nat.sub_mul];omega
  51. have il : l=i+k*(j-i) := by
  52. apply Nat.eq_of_mul_eq_mul_right he
  53. rw [Nat.add_mul,Nat.mul_assoc,←delta];omega
  54. have gap : j-i=1 := by
  55. by_contra! h
  56. have big := Nat.mul_le_mul_left k (by omega : 2≤j-i);omega
  57. have de : d=e := by simpa [gap] using delta
  58. rw [gap,Nat.mul_one] at il
  59. have hi01 : i=0 ∨ i=1 := by omega
  60. rw [de] at hleft hright
  61. rcases hi01 with rfl | rfl <;> simp only [Nat.zero_mul,Nat.one_mul,Nat.add_zero] at hi'
  62. · subst a; omega
  63. · omega
  64. def single_class (P : Finset ℕ) (x : ℕ) : ℕ := if x ∈ P then 0 else x+1
  65. /-- A blocked progression can be made the only colour class of size greater than one. -/
  66. theorem blocked_realizable {N k a d : ℕ} (hk : 2≤k) (hb : Blocked N k a d) :
  67. Valid N k (single_class (progression a d k)) ∧
  68. Mono (single_class (progression a d k)) (progression a d k) := by
  69. let P := progression a d k
  70. refine ⟨?_,0,fun _ h => by simp [single_class,h]⟩
  71. intro b e he hend u v
  72. let Q := progression b e (k+1)
  73. by_contra! h
  74. have covers (x : ℕ) (hx : x∈Q) : single_class P x=u ∨ single_class P x=v := by
  75. by_cases h' : single_class P x=u
  76. · exact Or.inl h'
  77. · exact Or.inr (h x hx h')
  78. have sizeQ := card_progression b (k+1) he
  79. have sizeP := card_progression a k hb.1
  80. change Q.card=_ at sizeQ
  81. change P.card=_ at sizeP
  82. by_cases hit : ∃ x ∈ Q, x∈P
  83. · obtain ⟨x,hx,hp⟩ := hit
  84. have zero := covers x hx
  85. simp only [single_class,if_pos hp] at zero
  86. have sub (w : ℕ) (hw : ∀ y ∈ Q, single_class P y=0 ∨ single_class P y=w) : P⊆Q := by
  87. have sq : Q ⊆ insert (w-1) P := by
  88. intro y hy
  89. by_cases hy' : y∈P
  90. · exact Finset.mem_insert_of_mem hy'
  91. · have hh := hw y hy; simp [single_class,hy'] at hh
  92. exact Finset.mem_insert.mpr (Or.inl (by omega))
  93. have eq := Finset.eq_of_subset_of_card_le sq (by have := Finset.card_insert_le (w-1) P;omega)
  94. rw [eq]; exact Finset.subset_insert ..
  95. apply no_larger_progression hk hb he hend
  96. rcases zero with rfl | rfl
  97. · exact sub v covers
  98. · exact sub u (fun y hy => (covers y hy).symm)
  99. · have small : Q⊆{u-1,v-1} := by
  100. intro y hy
  101. have hp : y∉P := fun hmem => hit ⟨y,hy,hmem⟩
  102. have hh := covers y hy; simp only [single_class,if_neg hp] at hh
  103. simp only [Finset.mem_insert,Finset.mem_singleton];omega
  104. have := Finset.card_le_card small
  105. have := Finset.card_insert_le (u-1) ({v-1} : Finset ℕ)
  106. simp only [Finset.card_singleton] at *;omega
  107. theorem universal_iff {N k : ℕ} (hk : 2≤k) (S : Finset ℕ) (hs : S ⊆ Finset.range N) :
  108. Universal N k S ↔ Hits N k (Finset.range N \ S) := by
  109. constructor
  110. · intro hu a d hb
  111. by_contra! h
  112. have sub : progression a d k ⊆ S := by
  113. intro x hx
  114. obtain ⟨j,hj,hje⟩ := Finset.mem_image.mp hx
  115. have hj' : j≤k := by have := Finset.mem_range.mp hj;omega
  116. have hxN : x ∈ Finset.range N := Finset.mem_range.mpr (by have := Nat.mul_le_mul_right d hj';have := hb.2.1;omega)
  117. by_contra hn
  118. exact h x (Finset.mem_sdiff.mpr ⟨hxN,hn⟩) hx
  119. obtain ⟨hv,hm⟩ := blocked_realizable hk hb
  120. exact hu _ hv a d hb.1 sub hm
  121. · intro hit c hv a d hd sub hm
  122. have hin := Finset.mem_range.mp (hs (sub (term_mem (j:=k) le_rfl)))
  123. obtain ⟨x,hx,hm'⟩ := hit a d (mono_blocked hv hd hin hm)
  124. exact (Finset.mem_sdiff.mp hx).2 (sub hm')
  125. theorem strip_in_range {k q r : ℕ} (hr : r≤k) : strip k q r ⊆ Finset.range ((k+1)*q+r) := by
  126. intro x hx
  127. obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hx
  128. have him := Finset.mem_range.mp hi
  129. have hcount : count k q r ≤ q := max_le (Nat.sub_le ..) (Nat.sub_le ..)
  130. have := Nat.mul_le_mul_right q hr
  131. apply Finset.mem_range.mpr
  132. simp only [Nat.add_mul,Nat.mul_add,Nat.mul_one,Nat.one_mul] at *;omega
  133. /-- The maximum size of a fixed domain on which every valid colouring has no monochromatic
  134. length-`L` progression. The cover and the disjoint progressions witnessing optimality work for
  135. arbitrary interval size. -/
  136. theorem sharp_universal_domain (N L : ℕ) (hL : 3≤L) :
  137. ∃ S ⊆ Finset.range N, Universal N (L-1) S ∧
  138. S.card=N-count (L-1) (N/L) (N%L) ∧
  139. ∀ A ⊆ Finset.range N, Universal N (L-1) A → A.card ≤ S.card := by
  140. let k := L-1
  141. let q := N/L
  142. let r := N%L
  143. have hk : k+1=L := by dsimp [k];omega
  144. have hk2 : 2≤k := by dsimp [k];omega
  145. have hr : r≤k := by have := Nat.mod_lt N (by omega : 0<L); dsimp [r,k];omega
  146. have hn : (k+1)*q+r=N := by rw [hk];exact Nat.div_add_mod N L
  147. let T := strip k q r
  148. have ht : T ⊆ Finset.range N := hn ▸ strip_in_range hr
  149. have hits : Hits N k T := hn ▸ strip_hits hr
  150. let S := Finset.range N \ T
  151. have sub : S ⊆ Finset.range N := Finset.sdiff_subset
  152. have heq : Finset.range N \ S = T := Finset.sdiff_sdiff_eq_self ht
  153. have card : S.card=N-count k q r := by simp [S,Finset.card_sdiff_of_subset ht,T,card_strip]
  154. refine ⟨S,sub,(universal_iff hk2 S sub).2 (heq ▸ hits),card,?_⟩
  155. intro A ha hua
  156. have cover := (universal_iff hk2 A ha).1 hua
  157. have bound := exact_cover_lower hr (Finset.range N \ A) (by rwa [hn])
  158. rw [Finset.card_sdiff_of_subset ha,Finset.card_range] at bound
  159. have := Finset.card_le_card ha
  160. simp only [Finset.card_range] at *;omega
  161. theorem sharp_for_erdos160 (N : ℕ) (hN : 2≤N) :
  162. ∃ S ⊆ Finset.range N, Universal N 2 S ∧ S.card=2*((N+2)/3) ∧
  163. ∀ A ⊆ Finset.range N, Universal N 2 A → A.card ≤ S.card := by
  164. obtain ⟨S,hs,hu,hc,hm⟩ := sharp_universal_domain N 3 (by decide)
  165. refine ⟨S,hs,hu,?_,hm⟩
  166. rw [hc]; simp only [count];omega
  167. /-- Hunter's reduction on a prefix. It suffices that every three-term progression can be
  168. extended to the right in the original interval. -/
  169. theorem prefix_no_mono {α : Type*} {N M a d : ℕ} {c : ℕ → α} (hv : Valid N 2 c)
  170. (hNM : 3*M≤2*N+2) (hd : 0<d) (hin : a+2*d<M) : ¬ Mono c (progression a d 2) := by
  171. intro hm
  172. have hb := mono_blocked hv hd (by omega) hm
  173. have := hb.2.2.2;omega
  174. /-- Any numerical bound for a 3-AP-free subset of the prefix transfers to a lower bound
  175. on the number of colours. -/
  176. theorem transfer_three_free_bound {N M K R : ℕ} (c : ℕ → Fin K) (hv : Valid N 2 c)
  177. (hNM : 3*M≤2*N+2)
  178. (hR : ∀ A ⊆ Finset.range M,
  179. (∀ a d, 0<d → ¬ progression a d 2 ⊆ A) → A.card≤R) : M ≤ R*K := by
  180. classical
  181. have ht : ∀ x ∈ Finset.range M, c x ∈ (Finset.univ : Finset (Fin K)) := by simp
  182. have h := Finset.card_le_mul_card_image_of_maps_to ht R (by
  183. intro col _
  184. apply hR _ (Finset.filter_subset ..)
  185. intro a d hd sub
  186. have H (j : ℕ) (hj : j≤2) := Finset.mem_filter.mp (sub (term_mem (a:=a) (d:=d) hj))
  187. apply prefix_no_mono hv hNM hd (Finset.mem_range.mp (H 2 (by decide)).1)
  188. exact ⟨col,fun x hx => (Finset.mem_filter.mp (sub hx)).2⟩)
  189. simpa using h
  190. end ProgressionColours