| | @@ -0,0 +1,186 @@ |
| 1 | +import ErdosSwarm.Erdos5Run |
| 2 | + |
| 3 | +/-! |
| 4 | +# Erdős Problem 5: the asymptotic count for the sieve |
| 5 | + |
| 6 | +Step 4 of the plan: `exists_composite_run` (a simplified Erdős–Rankin construction). |
| 7 | +-/ |
| 8 | + |
| 9 | +open Real Filter |
| 10 | + |
| 11 | +namespace ErdosSwarm.Erdos5 |
| 12 | + |
| 13 | +/-- Polylogarithms are eventually below any multiple of `x / log x`. -/ |
| 14 | +theorem eventually_pow_log_mul_log_le (K : ℝ) (hK : 0 < K) (z : ℕ) : |
| 15 | + ∀ᶠ x : ℕ in atTop, (K * Real.log x) ^ z * Real.log x ≤ (1 / 4) * x := by |
| 16 | + have h := (isLittleO_pow_log_id_atTop (n := z + 1)).bound |
| 17 | + (show (0 : ℝ) < 1 / (4 * K ^ z) by positivity) |
| 18 | + have h' : ∀ᶠ x : ℕ in atTop, ‖Real.log (x : ℝ) ^ (z + 1)‖ ≤ 1 / (4 * K ^ z) * ‖(x : ℝ)‖ := |
| 19 | + tendsto_natCast_atTop_atTop.eventually h |
| 20 | + filter_upwards [h', eventually_ge_atTop 1] with x hx hx1 |
| 21 | + have hx0 : (0 : ℝ) ≤ x := by positivity |
| 22 | + have hl : 0 ≤ Real.log (x : ℝ) := Real.log_nonneg (by exact_mod_cast hx1) |
| 23 | + rw [Real.norm_of_nonneg (by positivity), Real.norm_of_nonneg hx0] at hx |
| 24 | + have hKz : 0 < K ^ z := by positivity |
| 25 | + calc (K * Real.log x) ^ z * Real.log x = K ^ z * Real.log (x : ℝ) ^ (z + 1) := by ring |
| 26 | + _ ≤ K ^ z * (1 / (4 * K ^ z) * x) := by gcongr |
| 27 | + _ = (1 / 4) * x := by field_simp |
| 28 | + |
| 29 | +theorem eventually_sqrt_mul_log_le (u : ℕ) (hu : 1 ≤ u) : |
| 30 | + ∀ᶠ x : ℕ in atTop, Real.sqrt ((u : ℝ) * x) * Real.log x ≤ (1 / 4) * x := by |
| 31 | + have hu' : (1 : ℝ) ≤ u := by exact_mod_cast hu |
| 32 | + have h := (isLittleO_log_rpow_atTop (r := (1 / 2 : ℝ)) (by norm_num)).bound |
| 33 | + (show (0 : ℝ) < 1 / (4 * u) by positivity) |
| 34 | + have h' : ∀ᶠ x : ℕ in atTop, ‖Real.log (x : ℝ)‖ ≤ 1 / (4 * u) * ‖(x : ℝ) ^ (1 / 2 : ℝ)‖ := |
| 35 | + tendsto_natCast_atTop_atTop.eventually h |
| 36 | + filter_upwards [h', eventually_ge_atTop 1] with x hx hx1 |
| 37 | + have hx0 : (0 : ℝ) ≤ x := by positivity |
| 38 | + have hl : 0 ≤ Real.log (x : ℝ) := Real.log_nonneg (by exact_mod_cast hx1) |
| 39 | + rw [Real.norm_of_nonneg hl, Real.norm_of_nonneg (by positivity), ← Real.sqrt_eq_rpow] at hx |
| 40 | + have hs : Real.sqrt ((u : ℝ) * x) ≤ u * Real.sqrt x := by |
| 41 | + rw [Real.sqrt_mul (by positivity)] |
| 42 | + have : Real.sqrt (u : ℝ) ≤ u := by |
| 43 | + rw [Real.sqrt_le_left (by positivity)]; nlinarith |
| 44 | + exact mul_le_mul_of_nonneg_right this (Real.sqrt_nonneg _) |
| 45 | + have hsx : Real.sqrt (x : ℝ) * Real.sqrt x = x := Real.mul_self_sqrt hx0 |
| 46 | + calc Real.sqrt ((u : ℝ) * x) * Real.log x ≤ (u * Real.sqrt x) * (1 / (4 * u) * Real.sqrt x) := by |
| 47 | + gcongr |
| 48 | + _ = (1 / 4) * (Real.sqrt x * Real.sqrt x) := by field_simp |
| 49 | + _ = (1 / 4) * x := by rw [hsx] |
| 50 | + |
| 51 | + |
| 52 | +set_option maxHeartbeats 800000 in |
| 53 | +open Classical in |
| 54 | +theorem exists_composite_run_pos (u : ℕ) (hu : 1 ≤ u) : ∀ᶠ x : ℕ in atTop, |
| 55 | + ∃ m : ℕ, x < m ∧ Real.log m ≤ 2 * x ∧ ∀ i ∈ Finset.Icc 1 (u * x), ¬ (m + i).Prime := by |
| 56 | + have hu' : (1 : ℝ) ≤ u := by exact_mod_cast hu |
| 57 | + set δ : ℝ := 1 / (100 * ((u : ℝ) + 1) ^ 2) with hδdef |
| 58 | + have hδ : 0 < δ := by positivity |
| 59 | + obtain ⟨z, hz⟩ := exists_primorial_totient_le hδ |
| 60 | + have hδ1 : δ * (u + 1) ^ 2 = 1 / 100 := by rw [hδdef]; field_simp |
| 61 | + have hδu : δ * u ≤ 1 / 100 := by nlinarith |
| 62 | + have hδuu : δ * u * u ≤ 1 / 100 := by nlinarith |
| 63 | + have hδ0 : δ ≤ 1 / 100 := by nlinarith |
| 64 | + have hlu : 0 ≤ Real.log u := Real.log_nonneg hu' |
| 65 | + set K : ℝ := 2 * Real.log u + 3 with hKdef |
| 66 | + have hK : 0 < K := by positivity |
| 67 | + have hlog : ∀ᶠ y : ℝ in atTop, Real.log y ≤ (1 / 10) * y := by |
| 68 | + have := isLittleO_log_id_atTop.bound (c := 1 / 10) (by positivity) |
| 69 | + filter_upwards [this, eventually_ge_atTop 1] with y hy hy1 |
| 70 | + simpa [abs_of_nonneg (Real.log_nonneg hy1), abs_of_nonneg (by linarith : (0:ℝ) ≤ y)] using hy |
| 71 | + have hlogN : ∀ᶠ x : ℕ in atTop, Real.log ((x : ℝ) + 2) ≤ (1 / 10) * ((x : ℝ) + 2) := by |
| 72 | + have ht : Tendsto (fun x : ℕ => (x : ℝ) + 2) atTop atTop := |
| 73 | + tendsto_atTop_add_const_right _ 2 tendsto_natCast_atTop_atTop |
| 74 | + exact ht.eventually hlog |
| 75 | + filter_upwards [eventually_pow_log_mul_log_le K hK z, eventually_sqrt_mul_log_le u hu, |
| 76 | + eventually_card_primes_Ioc, hlogN, eventually_ge_atTop (4 * z + 4)] with x h1 h2 h3 h4 h5 |
| 77 | + have hx3 : (3 : ℝ) ≤ x := by exact_mod_cast (by omega : 3 ≤ x) |
| 78 | + have hx0 : (0 : ℝ) < x := by linarith |
| 79 | + have hl1 : 1 ≤ Real.log x := by |
| 80 | + rw [Real.le_log_iff_exp_le hx0] |
| 81 | + have := Real.exp_one_lt_d9 |
| 82 | + linarith |
| 83 | + set ℓ := Real.log x with hℓ |
| 84 | + have hℓ0 : 0 < ℓ := by linarith |
| 85 | + have hl2 := Real.log_two_gt_d9 |
| 86 | + have hl2' := Real.log_two_lt_d9 |
| 87 | + -- the candidate count |
| 88 | + set C := (Finset.Icc 1 (u * x)).filter |
| 89 | + (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z ∨ x / 4 < p) with hC |
| 90 | + set S := (Finset.Ioc (x / 4) x).filter Nat.Prime with hS |
| 91 | + have hCc := card_candidates_le z 4 u x (by norm_num) |
| 92 | + have hux : (1 : ℝ) < (u : ℝ) * x := by nlinarith |
| 93 | + -- bound on `Nat.log` |
| 94 | + have hA : ((Nat.log 2 (u * x) + 1 : ℕ) : ℝ) ≤ K * ℓ := by |
| 95 | + have h := Real.natLog_le_logb (u * x) 2 |
| 96 | + rw [Real.logb, Nat.cast_mul, Real.log_mul (by positivity) (by positivity)] at h |
| 97 | + have hh : (Real.log u + ℓ) / Real.log 2 ≤ 2 * (Real.log u + ℓ) := by |
| 98 | + rw [div_le_iff₀ (by linarith)] |
| 99 | + nlinarith |
| 100 | + push_cast |
| 101 | + nlinarith |
| 102 | + have hApow : ((Nat.log 2 (u * x) + 1 : ℕ) : ℝ) ^ z ≤ (K * ℓ) ^ z := |
| 103 | + pow_le_pow_left₀ (by positivity) hA z |
| 104 | + -- bound on `π` |
| 105 | + have hpi : (Nat.primeCounting (u * x) : ℝ) ≤ 2 * Real.log 4 * (u * x) / ℓ + Real.sqrt (u * x) := by |
| 106 | + have h := Chebyshev.pi_le_log4_mul_div hux |
| 107 | + have e : ⌊(u : ℝ) * x⌋₊ = u * x := by rw [← Nat.cast_mul, Nat.floor_natCast] |
| 108 | + rw [e] at h |
| 109 | + have hy : 0 ≤ (u : ℝ) * x := by positivity |
| 110 | + have hls : Real.log (Real.sqrt ((u : ℝ) * x)) = (Real.log u + ℓ) / 2 := by |
| 111 | + rw [Real.log_sqrt hy, Real.log_mul (by positivity) (by positivity)] |
| 112 | + have hl4 : 0 ≤ Real.log 4 := Real.log_nonneg (by norm_num) |
| 113 | + have hd : Real.log 4 * ((u : ℝ) * x) / Real.log (Real.sqrt ((u : ℝ) * x)) |
| 114 | + ≤ 2 * Real.log 4 * ((u : ℝ) * x) / ℓ := by |
| 115 | + rw [hls, div_le_div_iff₀ (by linarith) hℓ0] |
| 116 | + have := mul_nonneg (mul_nonneg hl4 hy) hlu |
| 117 | + nlinarith |
| 118 | + linarith |
| 119 | + have hl4v : Real.log 4 < 1.3862943616 := by |
| 120 | + rw [show (4 : ℝ) = 2 ^ 2 by norm_num, Real.log_pow]; push_cast; linarith |
| 121 | + have hπℓ : ℓ * (Nat.primeCounting (u * x) : ℝ) ≤ 2 * Real.log 4 * (u * x) + Real.sqrt (u * x) * ℓ := by |
| 122 | + calc ℓ * (Nat.primeCounting (u * x) : ℝ) |
| 123 | + ≤ ℓ * (2 * Real.log 4 * (u * x) / ℓ + Real.sqrt (u * x)) := |
| 124 | + mul_le_mul_of_nonneg_left hpi hℓ0.le |
| 125 | + _ = 2 * Real.log 4 * (u * x) + Real.sqrt (u * x) * ℓ := by field_simp |
| 126 | + have hCr : (C.card : ℝ) ≤ ((Nat.log 2 (u * x) + 1 : ℕ) : ℝ) ^ z + 4 * u * (Nat.primeCounting (u * x) : ℝ) := by |
| 127 | + have := hCc |
| 128 | + have h' : (C.card : ℝ) ≤ (((Nat.log 2 (u * x) + 1) ^ z + u * 4 * Nat.primeCounting (u * x) : ℕ) : ℝ) := by |
| 129 | + exact_mod_cast this |
| 130 | + push_cast at h' ⊢ |
| 131 | + linarith |
| 132 | + have hπ0 : (0 : ℝ) ≤ (Nat.primeCounting (u * x) : ℝ) := by positivity |
| 133 | + have hs0 : 0 ≤ Real.sqrt ((u : ℝ) * x) := Real.sqrt_nonneg _ |
| 134 | + have hmain : δ * C.card ≤ S.card := by |
| 135 | + refine le_trans ?_ h3 |
| 136 | + rw [le_div_iff₀ (by positivity)] |
| 137 | + have e1 : δ * (C.card : ℝ) * (4 * ℓ) ≤ 4 * δ * (((Nat.log 2 (u * x) + 1 : ℕ) : ℝ) ^ z * ℓ) |
| 138 | + + 16 * δ * u * (ℓ * Nat.primeCounting (u * x)) := by |
| 139 | + have := mul_le_mul_of_nonneg_left hCr (by positivity : 0 ≤ δ * (4 * ℓ)) |
| 140 | + calc δ * (C.card : ℝ) * (4 * ℓ) = δ * (4 * ℓ) * C.card := by ring |
| 141 | + _ ≤ _ := this |
| 142 | + _ = _ := by ring |
| 143 | + have e2 : 4 * δ * (((Nat.log 2 (u * x) + 1 : ℕ) : ℝ) ^ z * ℓ) ≤ 4 * δ * ((1 / 4) * x) := by |
| 144 | + exact mul_le_mul_of_nonneg_left ((mul_le_mul_of_nonneg_right hApow hℓ0.le).trans h1) |
| 145 | + (by positivity) |
| 146 | + have e3 : 16 * δ * u * (ℓ * Nat.primeCounting (u * x)) ≤ |
| 147 | + 16 * δ * u * (2 * Real.log 4 * (u * x) + Real.sqrt (u * x) * ℓ) := by |
| 148 | + gcongr |
| 149 | + have e4 : 16 * δ * u * (2 * Real.log 4 * (u * x) + Real.sqrt (u * x) * ℓ) |
| 150 | + = 32 * Real.log 4 * (δ * u * u) * x + 16 * (δ * u) * (Real.sqrt (u * x) * ℓ) := by ring |
| 151 | + have e5 : 32 * Real.log 4 * (δ * u * u) * x ≤ 32 * 1.3862943616 * (1 / 100) * x := by |
| 152 | + gcongr |
| 153 | + have e6 : 16 * (δ * u) * (Real.sqrt (u * x) * ℓ) ≤ 16 * (1 / 100) * ((1 / 4) * x) := by |
| 154 | + gcongr |
| 155 | + nlinarith |
| 156 | + have hcount : ((primorial z).totient : ℝ) * (C.card : ℝ) ≤ (primorial z : ℝ) * S.card := by |
| 157 | + have hP : (0 : ℝ) < primorial z := by exact_mod_cast primorial_pos z |
| 158 | + calc ((primorial z).totient : ℝ) * C.card ≤ (δ * primorial z) * C.card := |
| 159 | + mul_le_mul_of_nonneg_right hz (by positivity) |
| 160 | + _ = primorial z * (δ * C.card) := by ring |
| 161 | + _ ≤ primorial z * S.card := mul_le_mul_of_nonneg_left hmain hP.le |
| 162 | + have hzx : z ≤ x / 4 := by omega |
| 163 | + obtain ⟨m, hxm, hmlt, hmrun⟩ := exists_run_of_count x z u hzx (by omega) hcount |
| 164 | + refine ⟨m, hxm, ?_, hmrun⟩ |
| 165 | + have hm0 : (0 : ℝ) < m := by exact_mod_cast (by omega : 0 < m) |
| 166 | + have hmle : (m : ℝ) ≤ ((x : ℝ) + 2) * 4 ^ x := by |
| 167 | + have h1 : (m : ℝ) ≤ (((x + 2) * primorial x : ℕ) : ℝ) := by exact_mod_cast hmlt.le |
| 168 | + have h2 : (primorial x : ℝ) ≤ 4 ^ x := by exact_mod_cast primorial_le_four_pow x |
| 169 | + push_cast at h1 |
| 170 | + calc (m : ℝ) ≤ ((x : ℝ) + 2) * primorial x := h1 |
| 171 | + _ ≤ ((x : ℝ) + 2) * 4 ^ x := by gcongr |
| 172 | + calc Real.log m ≤ Real.log (((x : ℝ) + 2) * 4 ^ x) := Real.log_le_log hm0 hmle |
| 173 | + _ = Real.log ((x : ℝ) + 2) + x * Real.log 4 := by |
| 174 | + rw [Real.log_mul (by positivity) (by positivity), Real.log_pow] |
| 175 | + _ ≤ 2 * x := by nlinarith |
| 176 | + |
| 177 | +/-- Runs of `u * x` composites above some `m ∈ (x, 4^x·(x+2))`: Westzynthius–Erdős–Rankin sieve. -/ |
| 178 | +theorem exists_composite_run (u : ℕ) : ∀ᶠ x : ℕ in atTop, |
| 179 | + ∃ m : ℕ, x < m ∧ Real.log m ≤ 2 * x ∧ ∀ i ∈ Finset.Icc 1 (u * x), ¬ (m + i).Prime := by |
| 180 | + filter_upwards [exists_composite_run_pos (u + 1) (by omega)] with x hx |
| 181 | + obtain ⟨m, h1, h2, h3⟩ := hx |
| 182 | + refine ⟨m, h1, h2, fun i hi => h3 i ?_⟩ |
| 183 | + rw [Finset.mem_Icc] at hi ⊢ |
| 184 | + exact ⟨hi.1, hi.2.trans (Nat.mul_le_mul_right _ (by omega))⟩ |
| 185 | + |
| 186 | +end ErdosSwarm.Erdos5 |