Lean / Reader
Lean reader

Erdos311Lower.lean

112 lines13 declarationsno sorryimports Erdos311Residues

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

  1. import Erdos311Residues
  2. open Finset
  3. namespace Erdos311Lower
  4. def scale : ℕ := 337293588832926264639465766794841407432394382785157234228847021917234018060677390066992000
  5. def pivots : List ℕ := [199,197,193,191,181,179,173,167,163,157,151,149,139,137,131,127]
  6. def modulus : ℕ := 246754462477588902008901238171675219
  7. def gap : ℕ := 1507565388862991484001615748834
  8. /-- The projections of all subset sums of a list, without constructing its powerset. -/
  9. def residues (L q : ℕ) : List ℕ → List ℕ
  10. | [] => [0]
  11. | n :: ns => let old := residues L q ns
  12. old ++ old.map (fun a => (a + L/n) % q)
  13. theorem residue_mem (L q : ℕ) (ns : List ℕ) (A : Finset ℕ) (h : A ⊆ ns.toFinset) :
  14. (∑ j ∈ A, L/j)%q ∈ residues L q ns := by
  15. induction ns generalizing A with
  16. | nil => have ha : A=∅ := Finset.subset_empty.mp (by simpa using h)
  17. simp [ha,residues]
  18. | cons n ns ih =>
  19. by_cases hn : n ∈ A
  20. · have hrest : A.erase n ⊆ ns.toFinset := by
  21. intro j hj
  22. obtain ⟨hne,hjA⟩ := Finset.mem_erase.mp hj
  23. simpa [hne] using h hjA
  24. have hm := ih (A.erase n) hrest
  25. apply List.mem_append.mpr (Or.inr (List.mem_map.mpr ⟨_,hm,?_⟩))
  26. rw [Nat.mod_add_mod, Finset.sum_erase_add _ _ hn]
  27. · have hrest : A ⊆ ns.toFinset := by
  28. intro j hj
  29. have hne : j ≠ n := fun he => hn (he ▸ hj)
  30. simpa [hne] using h hj
  31. exact List.mem_append.mpr (Or.inl (ih A hrest))
  32. set_option maxHeartbeats 0
  33. set_option maxRecDepth 200000
  34. theorem scale_eq : Erdos311Residues.commonDen 200 = scale := by decide +kernel
  35. theorem invisible : ∀ j ∈ Finset.Icc 1 200, j ∉ pivots.toFinset → modulus ∣ scale/j := by decide +kernel
  36. theorem computed : (residues scale modulus pivots).all (fun r => decide (r=0 ∨ gap ≤ r ∧ r+gap ≤ modulus)) = true := by decide +kernel
  37. theorem residue_bound (A : Finset ℕ) (hA : A ⊆ Finset.Icc 1 200) :
  38. let r := (∑ j ∈ A, scale/j) % modulus
  39. r=0 ∨ gap ≤ r ∧ r+gap ≤ modulus := by
  40. let B := pivots.toFinset
  41. have he : (∑ j ∈ A, scale/j) % modulus = (∑ j ∈ A ∩ B,scale/j) % modulus := by
  42. apply (ZMod.natCast_eq_natCast_iff' ..).mp
  43. rw [Nat.cast_sum,Nat.cast_sum]
  44. exact Erdos311Residues.filter_sum A B _ (fun j hj hB => (ZMod.natCast_eq_zero_iff ..).mpr (invisible j (hA hj) hB))
  45. dsimp only
  46. rw [he]
  47. exact of_decide_eq_true (List.all_eq_true.mp computed _ (residue_mem scale modulus pivots _ Finset.inter_subset_right))
  48. /-- A gap on both sides of zero in the residue circle yields a gap about a multiple of q. -/
  49. theorem dist_bound {q b u L : ℕ} (hL : q ∣ L) (hb : b ≤ q)
  50. (hne : u ≠ L) (h : u%q=0 ∨ b ≤ u%q ∧ u%q+b ≤ q) :
  51. b ≤ u-L ∨ b ≤ L-u := by
  52. have hzero := Nat.mod_eq_zero_of_dvd hL
  53. by_cases hu : L ≤ u
  54. · left
  55. have he : (u-L)%q = u%q := by
  56. calc (u-L)%q = (L+(u-L))%q := by rw [Nat.add_mod,hzero,Nat.zero_add,Nat.mod_mod]
  57. _ = u%q := by rw [Nat.add_sub_of_le hu]
  58. rcases h with hr | hr
  59. · have hd : q ∣ u-L := Nat.dvd_of_mod_eq_zero (he.trans hr)
  60. exact hb.trans (Nat.le_of_dvd (by omega) hd)
  61. · exact hr.1.trans (he ▸ Nat.mod_le _ _)
  62. · right
  63. have he : (u%q+(L-u))%q=0 := by rw [Nat.mod_add_mod,Nat.add_sub_of_le (by omega : u≤L),hzero]
  64. have hp : q ≤ u%q+(L-u) := Nat.le_of_dvd (by omega) (Nat.dvd_of_mod_eq_zero he)
  65. omega
  66. theorem rational_dist {a L u : ℕ} {z : ℚ} (ha : 0 < a) (hL : (0 : ℚ) < L)
  67. (he : (u : ℚ) = (L : ℚ)*z) (h : a ≤ u-L ∨ a ≤ L-u) :
  68. (a : ℚ)/L ≤ |z-1| := by
  69. apply (div_le_iff₀ hL).mpr
  70. rw [← abs_of_pos hL, ← abs_mul, sub_mul, mul_comm z, ← he, one_mul]
  71. rcases h with h | h
  72. · have hs : L ≤ u := by omega
  73. have hh : (a : ℚ) ≤ (u : ℚ)-L := by
  74. exact_mod_cast (show (a : ℤ) ≤ (u : ℤ)-L by omega)
  75. exact hh.trans (le_abs_self _)
  76. · have hs : u ≤ L := by omega
  77. have hh : (a : ℚ) ≤ (L : ℚ)-u := by
  78. exact_mod_cast (show (a : ℤ) ≤ (L : ℤ)-u by omega)
  79. rw [abs_sub_comm]
  80. exact hh.trans (le_abs_self _)
  81. theorem lower_200 (A : Finset ℕ) (hA : A ⊆ Icc 1 200) (hne : (∑ j ∈ A, (j : ℚ)⁻¹) ≠ 1) :
  82. (gap : ℚ)/scale ≤ |(∑ j ∈ A, (j : ℚ)⁻¹)-1| := by
  83. let u := ∑ j ∈ A, scale/j
  84. let z := ∑ j ∈ A, (j : ℚ)⁻¹
  85. have he : (u : ℚ) = (scale : ℚ)*z := by simpa [u,z,scale_eq] using Erdos311Residues.weight_sum_eq 200 A hA
  86. have hpos : (0 : ℚ) < scale := by norm_num [scale]
  87. have huv : u ≠ scale := by
  88. intro hu
  89. rw [hu] at he
  90. apply hne
  91. change z=1
  92. nlinarith
  93. exact rational_dist (by decide +kernel : 0 < gap) hpos he
  94. (dist_bound (q:=modulus) (by decide +kernel : modulus ∣ scale)
  95. (by decide +kernel : gap ≤ modulus) huv (residue_bound A hA))
  96. #print axioms computed
  97. #print axioms lower_200
  98. end Erdos311Lower