Lean / Reader
Lean reader

Erdos311Residues.lean

216 lines22 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. open Finset
  3. namespace Erdos311Residues
  4. /-- The actual set of distinct harmonic subset sums in the problem. -/
  5. noncomputable def subsetSums (N : ℕ) : Finset ℚ :=
  6. ((Icc 1 N).powerset).image (fun A : Finset ℕ => ∑ j ∈ A, (j : ℚ)⁻¹)
  7. def commonDen (N : ℕ) := (Icc 1 N).lcm id
  8. /-- Exactly the independent full prime-power tests used in the paper. -/
  9. def locallyAdmissible (N u : ℕ) : Prop :=
  10. ∀ p ∈ Icc 1 N, p.Prime → ∃ A ⊆ (Icc 1 N).filter (p ∣ ·),
  11. Nat.ModEq (p^(commonDen N).factorization p) u (∑ j ∈ A, commonDen N / j)
  12. /-- The full large-N statement, with the real inequalities written using rational coordinates. -/
  13. def centralMembership : Prop :=
  14. ∀ ε : ℚ, 0 < ε → ∃ N₀ : ℕ, ∀ N ≥ N₀, ∀ u : ℕ,
  15. let x := (u : ℚ) / commonDen N
  16. let H := ∑ j ∈ Icc 1 N, (j : ℚ)⁻¹
  17. ε ≤ x → x ≤ H-ε → (x ∈ subsetSums N ↔ locallyAdmissible N u)
  18. /-- The nonzero digit test on denominators carrying the full p-power. -/
  19. def firstDigits (N u : ℕ) : Prop := ∀ p ∈ Icc 1 N, p.Prime →
  20. ∃ A ⊆ (Icc 1 N).filter (p^(commonDen N).factorization p ∣ ·),
  21. Nat.ModEq p u (∑ j ∈ A, commonDen N / j)
  22. def representedModuloOne (N u : ℕ) : Prop := ∃ A ⊆ Icc 1 N,
  23. Nat.ModEq (commonDen N) u (∑ j ∈ A, commonDen N / j)
  24. def fractionalPartTheorem : Prop := ∀ N u : ℕ,
  25. representedModuloOne N u ↔ firstDigits N u
  26. noncomputable def localCount (N : ℕ) : ℕ := ∏ p ∈ (Icc 1 N).filter Nat.Prime,
  27. ((((Icc 1 N).filter (p ∣ ·)).powerset).image (fun A : Finset ℕ =>
  28. (∑ j ∈ A, commonDen N/j) % p^(commonDen N).factorization p)).card
  29. def countAsymptotic : Prop := Filter.Tendsto (fun N : ℕ =>
  30. ((subsetSums N).card : ℝ) / localCount N - ∑ j ∈ Icc 1 N, (j : ℝ)⁻¹)
  31. Filter.atTop (nhds 0)
  32. /-- A projected sum is unchanged when terms invisible in that projection are removed. -/
  33. theorem filter_sum {ι : Type*} [DecidableEq ι] {R : Type*} [AddCommMonoid R]
  34. (A B : Finset ι) (f : ι → R) (h : ∀ j ∈ A, j ∉ B → f j = 0) :
  35. ∑ j ∈ A, f j = ∑ j ∈ A ∩ B, f j := by
  36. symm
  37. apply Finset.sum_subset Finset.inter_subset_left
  38. intro j hj hj'
  39. exact h j hj (fun hB => hj' (Finset.mem_inter.mpr ⟨hj,hB⟩))
  40. /-- The nonzero common denominator and its divisibility by each allowed index. -/
  41. theorem commonDen_ne_zero (N : ℕ) : commonDen N ≠ 0 := by
  42. apply Finset.lcm_ne_zero_iff.mpr
  43. intro j hj
  44. have := (Finset.mem_Icc.mp hj).1
  45. simpa only [id_eq] using (show j ≠ 0 by omega)
  46. theorem weight_sum_eq (N : ℕ) (A : Finset ℕ) (hA : A ⊆ Icc 1 N) :
  47. ((∑ j ∈ A, commonDen N/j : ℕ) : ℚ) = (commonDen N : ℚ) * ∑ j ∈ A, (j : ℚ)⁻¹ := by
  48. rw [Nat.cast_sum, Finset.mul_sum]
  49. apply Finset.sum_congr rfl
  50. intro d hd
  51. have hdvd : d ∣ commonDen N := Finset.dvd_lcm (f := id) (hA hd)
  52. rw [Nat.cast_div hdvd (by have := (Finset.mem_Icc.mp (hA hd)).1; exact_mod_cast (show d ≠ 0 by omega)), div_eq_mul_inv]
  53. theorem necessary (N u : ℕ) (h : (u : ℚ)/commonDen N ∈ subsetSums N) : locallyAdmissible N u := by
  54. obtain ⟨A,hA,hval⟩ := Finset.mem_image.mp h
  55. have hsub := Finset.mem_powerset.mp hA
  56. have hu : u = ∑ j ∈ A, commonDen N/j := by
  57. have hl : (commonDen N : ℚ) ≠ 0 := by exact_mod_cast commonDen_ne_zero N
  58. have hw := weight_sum_eq N A hsub
  59. change (∑ j ∈ A, (j : ℚ)⁻¹) = (u : ℚ) / commonDen N at hval
  60. rw [hval] at hw
  61. field_simp [hl] at hw
  62. exact_mod_cast hw.symm
  63. intro p _ hp
  64. let B := (Icc 1 N).filter (p ∣ ·)
  65. refine ⟨A ∩ B, Finset.inter_subset_right, ?_⟩
  66. apply (ZMod.natCast_eq_natCast_iff ..).mp
  67. rw [hu, Nat.cast_sum, Nat.cast_sum]
  68. apply filter_sum
  69. intro j hj hjB
  70. apply (ZMod.natCast_eq_zero_iff ..).mpr
  71. have hprime : ¬ p ∣ j := fun hd => hjB (Finset.mem_filter.mpr ⟨hsub hj,hd⟩)
  72. have hdvd : j ∣ commonDen N := Finset.dvd_lcm (f := id) (hsub hj)
  73. apply ((hp.coprime_iff_not_dvd.mpr hprime).pow_left _).dvd_of_dvd_mul_right
  74. simpa only [Nat.div_mul_cancel hdvd] using Nat.ordProj_dvd (commonDen N) p
  75. #print axioms necessary
  76. /-- At every finite order, realization modulo one passes each top-digit test. -/
  77. theorem top_digits_necessary (N u : ℕ) (h : representedModuloOne N u) : firstDigits N u := by
  78. obtain ⟨A,hA,hcongr⟩ := h
  79. intro p hpN hp
  80. let q := p^(commonDen N).factorization p
  81. let B := (Icc 1 N).filter (q ∣ ·)
  82. refine ⟨A ∩ B, Finset.inter_subset_right, ?_⟩
  83. have hpL : p ∣ commonDen N := Finset.dvd_lcm (f := id) hpN
  84. apply (hcongr.of_dvd hpL).trans
  85. apply (ZMod.natCast_eq_natCast_iff ..).mp
  86. rw [Nat.cast_sum,Nat.cast_sum]
  87. apply filter_sum
  88. intro j hj hn
  89. apply (ZMod.natCast_eq_zero_iff ..).mpr
  90. by_contra hneg
  91. have hdvd : j ∣ commonDen N := Finset.dvd_lcm (f := id) (hA hj)
  92. have hq : q ∣ (commonDen N/j)*j := by simpa [Nat.div_mul_cancel hdvd] using Nat.ordProj_dvd (commonDen N) p
  93. have hc := (hp.coprime_iff_not_dvd.mpr hneg).pow_left ((commonDen N).factorization p)
  94. exact hn (Finset.mem_filter.mpr ⟨hA hj,hc.dvd_of_dvd_mul_left hq⟩)
  95. #print axioms top_digits_necessary
  96. /-- Local witnesses from disjoint blocks glue simultaneously under arbitrary additive projections. -/
  97. theorem glue {ι κ G : Type*} [DecidableEq ι] [DecidableEq κ] [AddCommMonoid G]
  98. (I : Finset κ) (block take : κ → Finset ι) (w : ι → G) (target : G)
  99. (R : κ → Type*) [∀ i, AddCommMonoid (R i)] (project : ∀ i, G →+ R i)
  100. (disj : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → Disjoint (block i) (block j))
  101. (within : ∀ i ∈ I, take i ⊆ block i)
  102. (invisible : ∀ i ∈ I, ∀ j, j ∉ block i → project i (w j) = 0)
  103. (realizes : ∀ i ∈ I, project i (∑ j ∈ take i, w j) = project i target) :
  104. ∀ i ∈ I, project i (∑ j ∈ I.biUnion take, w j) = project i target := by
  105. intro i hi
  106. have hinter : I.biUnion take ∩ block i = take i := by
  107. ext x; constructor
  108. · intro h
  109. obtain ⟨hU,hB⟩ := Finset.mem_inter.mp h
  110. obtain ⟨j,hj,hx⟩ := Finset.mem_biUnion.mp hU
  111. by_cases he : j=i
  112. · simpa [he] using hx
  113. · exact False.elim ((Finset.disjoint_left.mp (disj j hj i hi he)) (within j hj hx) hB)
  114. · intro h
  115. exact Finset.mem_inter.mpr ⟨Finset.mem_biUnion.mpr ⟨i,hi,h⟩,within i hi h⟩
  116. rw [map_sum, filter_sum _ (block i) _ (fun j _ hn => invisible i hi j hn), hinter,
  117. ← map_sum, realizes i hi]
  118. /-- Once a bounded smooth remainder can be represented, three disjoint sets give the whole sum. -/
  119. theorem assemble (N : ℕ) (u : ℚ) (T F B : Finset ℕ)
  120. (hTF : Disjoint T F) (hUB : Disjoint (T ∪ F) B) (hdom : (T ∪ F) ∪ B ⊆ Icc 1 N)
  121. (hrem : ∑ j ∈ B, (j : ℚ)⁻¹ = u - (∑ j ∈ T, (j : ℚ)⁻¹) - ∑ j ∈ F, (j : ℚ)⁻¹) :
  122. u ∈ subsetSums N := by
  123. apply Finset.mem_image.mpr
  124. refine ⟨(T ∪ F) ∪ B, Finset.mem_powerset.mpr hdom, ?_⟩
  125. rw [Finset.sum_union hUB, Finset.sum_union hTF, hrem]
  126. ring
  127. /-- The arithmetic grid with denominator D, expressed without a choice of reduced numerator. -/
  128. def onGrid (D : ℕ) (x : ℚ) : Prop := ∃ a : ℤ, x * D = a
  129. theorem grid_sub {D : ℕ} {x y : ℚ} (hx : onGrid D x) (hy : onGrid D y) :
  130. onGrid D (x-y) := by
  131. obtain ⟨a,ha⟩ := hx
  132. obtain ⟨b,hb⟩ := hy
  133. exact ⟨a-b, by rw [sub_mul,ha,hb]; norm_cast⟩
  134. theorem grid_sum {ι : Type*} (D : ℕ) (S : Finset ι) (w : ι → ℚ)
  135. (h : ∀ j ∈ S, onGrid D (w j)) : onGrid D (∑ j ∈ S,w j) := by
  136. classical
  137. induction S using Finset.induction_on with
  138. | empty => exact ⟨0,by simp⟩
  139. | @insert j S hj ih =>
  140. obtain ⟨a,ha⟩ := h j (by simp)
  141. obtain ⟨b,hb⟩ := ih (fun i hi => h i (by simp [hi]))
  142. exact ⟨a+b,by rw [Finset.sum_insert hj, add_mul, ha,hb]; norm_cast⟩
  143. /-- Select a subset of small increments to put the remaining rational in the target interval. -/
  144. theorem subset_hit {ι : Type*} (S : Finset ι) (w : ι → ℚ) (lo hi z : ℚ)
  145. (start : lo ≤ z) (mass : z-hi ≤ ∑ j ∈ S, w j)
  146. (step : ∀ j ∈ S, w j ≤ hi-lo) :
  147. ∃ F ⊆ S, lo ≤ z-(∑ j ∈ F, w j) ∧ z-(∑ j ∈ F,w j) ≤ hi := by
  148. classical
  149. induction S using Finset.induction_on generalizing z with
  150. | empty => exact ⟨∅,Finset.Subset.rfl,by simpa using start,by simpa using (sub_nonpos.mp (by simpa using mass) : z ≤ hi)⟩
  151. | @insert j S hj ih =>
  152. by_cases hz : z ≤ hi
  153. · exact ⟨∅,Finset.empty_subset _,by simpa using start,by simpa using hz⟩
  154. have hw := step j (by simp)
  155. obtain ⟨F,hF,hlo,hhi⟩ := ih (z-w j) (by linarith)
  156. (by rw [Finset.sum_insert hj] at mass; linarith) (fun d hd => step d (by simp [hd]))
  157. have hjF : j ∉ F := fun h => hj (hF h)
  158. exact ⟨insert j F,Finset.insert_subset_insert _ hF,
  159. by rw [Finset.sum_insert hjF]; linarith,by rw [Finset.sum_insert hjF]; linarith⟩
  160. abbrev harmonic (A : Finset ℕ) : ℚ := ∑ j ∈ A, (j : ℚ)⁻¹
  161. /-- Finite central lifting. The hypotheses expose precisely the rough congruence, the small
  162. denominators and the separate scaled smooth-completion input. -/
  163. theorem central_lift (N m D : ℕ) (hm : 0 < m) (x : ℚ) (T F C : Finset ℕ)
  164. (hdom : (T ∪ F) ∪ C ⊆ Icc 1 N) (hTF : Disjoint T F) (hTC : Disjoint (T ∪ F) C)
  165. (hgrid : onGrid (m*D) (x-harmonic T))
  166. (hFgrid : ∀ j ∈ F, onGrid (m*D) (j : ℚ)⁻¹)
  167. (hlo : (1/3 : ℚ) / m ≤ x-harmonic T)
  168. (hmass : x-harmonic T-1/(m : ℚ) ≤ harmonic F)
  169. (hstep : ∀ j ∈ F, (j : ℚ)⁻¹ ≤ 1/(m : ℚ)-(1/3 : ℚ)/m)
  170. (complete : ∀ v : ℚ, onGrid D v → 1/3 ≤ v → v ≤ 1 →
  171. ∃ B ⊆ C, harmonic B = v/m) : x ∈ subsetSums N := by
  172. have hm' : (0 : ℚ) < m := by exact_mod_cast hm
  173. obtain ⟨F',hF',hlo',hhi'⟩ := subset_hit F (fun j : ℕ => (j : ℚ)⁻¹) _ _ _ hlo hmass hstep
  174. let rest := x-harmonic T-harmonic F'
  175. have hg := grid_sub hgrid (grid_sum (m*D) F' _ (fun j hj => hFgrid j (hF' hj)))
  176. obtain ⟨a,ha⟩ := hg
  177. change rest * ↑(m*D) = a at ha
  178. have hg' : onGrid D (rest*m) := ⟨a,by simpa [Nat.cast_mul,mul_assoc] using ha⟩
  179. obtain ⟨B,hB,hvalue⟩ := complete (rest*m) hg' ((div_le_iff₀ hm').mp hlo') ((le_div_iff₀ hm').mp hhi')
  180. have hUF : T ∪ F' ⊆ T ∪ F := Finset.union_subset_union_right hF'
  181. refine assemble N x T F' B (hTF.mono_right hF') (hTC.mono hUF hB) ?_ ?_
  182. · exact (Finset.union_subset_union hUF hB).trans hdom
  183. · change harmonic B = rest
  184. rw [hvalue, mul_div_cancel_right₀ _ (ne_of_gt hm')]
  185. #print axioms subset_hit
  186. #print axioms central_lift
  187. #print axioms glue
  188. #print axioms assemble
  189. end Erdos311Residues