| | @@ -195,4 +195,156 @@ theorem exists_shift_few_coprime {P : ℕ} (hP : 0 < P) (S : Finset ℕ) : |
| 195 | 195 | simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at hlt |
| 196 | 196 | nlinarith |
| 197 | 197 | |
| 198 | +open Classical in |
| 199 | +theorem card_smooth_le (z L : ℕ) : |
| 200 | + ((Finset.Icc 1 L).filter (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z)).card |
| 201 | + ≤ (Nat.log 2 L + 1) ^ z := by |
| 202 | + classical |
| 203 | + set S := (Finset.Icc 1 L).filter (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z) |
| 204 | + let T : Finset (ℕ → ℕ) := (Fintype.piFinset (fun _ : Finset.Icc 2 z => Finset.range (Nat.log 2 L + 1))).image |
| 205 | + (fun g => fun p => if h : p ∈ Finset.Icc 2 z then g ⟨p, h⟩ else 0) |
| 206 | + have hmem : ∀ n ∈ S, (fun p : ℕ => if p ∈ Finset.Icc 2 z then n.factorization p else 0) ∈ T := by |
| 207 | + intro n hn |
| 208 | + simp only [S, Finset.mem_filter, Finset.mem_Icc] at hn |
| 209 | + refine Finset.mem_image.2 ⟨fun p => n.factorization p.1, ?_, ?_⟩ |
| 210 | + · simp only [Fintype.mem_piFinset, Finset.mem_range, Nat.lt_succ_iff] |
| 211 | + intro p |
| 212 | + have hp2 : 2 ≤ p.1 := (Finset.mem_Icc.1 p.2).1 |
| 213 | + exact Nat.le_log_of_pow_le (by norm_num) |
| 214 | + (le_trans (Nat.pow_le_pow_left hp2 _) (le_trans (Nat.ordProj_le _ (by omega)) hn.1.2)) |
| 215 | + · funext p |
| 216 | + by_cases h : p ∈ Finset.Icc 2 z <;> simp [h] |
| 217 | + have hfact0 : ∀ n ∈ S, ∀ p, p ∉ Finset.Icc 2 z → n.factorization p = 0 := by |
| 218 | + intro n hn p hp |
| 219 | + simp only [S, Finset.mem_filter, Finset.mem_Icc] at hn |
| 220 | + by_contra h |
| 221 | + have hpp : p.Prime := Nat.prime_of_mem_primeFactors (Finsupp.mem_support_iff.2 h) |
| 222 | + have := hn.2 p hpp (Nat.dvd_of_mem_primeFactors (Finsupp.mem_support_iff.2 h)) |
| 223 | + exact hp (Finset.mem_Icc.2 ⟨hpp.two_le, this⟩) |
| 224 | + have hinj : Set.InjOn (fun n : ℕ => fun p : ℕ => if p ∈ Finset.Icc 2 z then n.factorization p else 0) S := by |
| 225 | + intro a ha b hb hab |
| 226 | + have ha' := ha; have hb' := hb |
| 227 | + simp only [S, Finset.coe_filter, Finset.mem_Icc, Set.mem_ofPred_eq] at ha' hb' |
| 228 | + apply Nat.eq_of_factorization_eq (by omega) (by omega) |
| 229 | + intro p |
| 230 | + by_cases hp : p ∈ Finset.Icc 2 z |
| 231 | + · have := congrFun hab p |
| 232 | + simpa [hp] using this |
| 233 | + · rw [hfact0 a ha p hp, hfact0 b hb p hp] |
| 234 | + calc S.card ≤ T.card := Finset.card_le_card_of_injOn _ (fun n hn => hmem n hn) hinj |
| 235 | + _ ≤ (Fintype.piFinset (fun _ : Finset.Icc 2 z => Finset.range (Nat.log 2 L + 1))).card := |
| 236 | + Finset.card_image_le |
| 237 | + _ = (Nat.log 2 L + 1) ^ (z + 1 - 2) := by |
| 238 | + simp [Fintype.card_piFinset] |
| 239 | + _ ≤ (Nat.log 2 L + 1) ^ z := Nat.pow_le_pow_right (by omega) (by omega) |
| 240 | + |
| 241 | + |
| 242 | +open Classical in |
| 243 | +theorem card_candidates_le (z K u x : ℕ) (hK : 1 ≤ K) : |
| 244 | + ((Finset.Icc 1 (u * x)).filter |
| 245 | + (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z ∨ x / K < p)).card |
| 246 | + ≤ (Nat.log 2 (u * x) + 1) ^ z + u * K * Nat.primeCounting (u * x) := by |
| 247 | + set L := u * x with hL |
| 248 | + set R : Finset ℕ := (Finset.range (L + 1)).filter Nat.Prime with hR |
| 249 | + have hRc : R.card = Nat.primeCounting L := by |
| 250 | + rw [hR, ← Nat.count_eq_card_filter_range]; rfl |
| 251 | + have hsub : ((Finset.Icc 1 L).filter |
| 252 | + (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z ∨ x / K < p)) ⊆ |
| 253 | + ((Finset.Icc 1 L).filter (fun n => ∀ p, p.Prime → p ∣ n → p ≤ z)) ∪ |
| 254 | + R.biUnion (fun q => (Finset.Icc 1 (u * K)).image (fun k => q * k)) := by |
| 255 | + intro n hn |
| 256 | + simp only [Finset.mem_filter, Finset.mem_Icc] at hn |
| 257 | + by_cases hs : ∀ p, p.Prime → p ∣ n → p ≤ z |
| 258 | + · exact Finset.mem_union_left _ (by simp only [Finset.mem_filter, Finset.mem_Icc]; exact ⟨hn.1, hs⟩) |
| 259 | + · push Not at hs |
| 260 | + obtain ⟨p, hp, hpn, hpz⟩ := hs |
| 261 | + have hxp : x / K < p := (hn.2 p hp hpn).resolve_left (by omega) |
| 262 | + obtain ⟨k, hk⟩ := hpn |
| 263 | + have hp0 : 0 < p := hp.pos |
| 264 | + have hk1 : 1 ≤ k := by |
| 265 | + rcases Nat.eq_zero_or_pos k with h | h |
| 266 | + · subst h; simp at hk; omega |
| 267 | + · exact h |
| 268 | + have hpL : p ≤ L := by |
| 269 | + have : p ≤ n := Nat.le_of_dvd (by omega) ⟨k, hk⟩ |
| 270 | + omega |
| 271 | + have h1 : x < K * p := by |
| 272 | + have := Nat.lt_mul_div_succ x (show 0 < K by omega) |
| 273 | + calc x < K * (x / K + 1) := this |
| 274 | + _ ≤ K * p := Nat.mul_le_mul_left _ hxp |
| 275 | + have h2 : k ≤ u * K := by |
| 276 | + have h3 : k * p ≤ u * K * p := by |
| 277 | + calc k * p = n := by rw [hk]; ring |
| 278 | + _ ≤ u * x := hn.1.2 |
| 279 | + _ ≤ u * (K * p) := Nat.mul_le_mul_left _ h1.le |
| 280 | + _ = u * K * p := by ring |
| 281 | + exact Nat.le_of_mul_le_mul_right h3 hp0 |
| 282 | + refine Finset.mem_union_right _ (Finset.mem_biUnion.2 ⟨p, ?_, ?_⟩) |
| 283 | + · simp [hR, hp, hpL] |
| 284 | + · exact Finset.mem_image.2 ⟨k, Finset.mem_Icc.2 ⟨hk1, h2⟩, hk.symm⟩ |
| 285 | + calc _ ≤ _ := Finset.card_le_card hsub |
| 286 | + _ ≤ _ := Finset.card_union_le _ _ |
| 287 | + _ ≤ _ := by |
| 288 | + gcongr |
| 289 | + · exact card_smooth_le z L |
| 290 | + · calc _ ≤ ∑ q ∈ R, ((Finset.Icc 1 (u * K)).image (fun k => q * k)).card := |
| 291 | + Finset.card_biUnion_le |
| 292 | + _ ≤ ∑ q ∈ R, (u * K) := Finset.sum_le_sum fun q _ => by |
| 293 | + refine Finset.card_image_le.trans ?_; simp |
| 294 | + _ = u * K * Nat.primeCounting L := by |
| 295 | + rw [Finset.sum_const, hRc, smul_eq_mul, mul_comm] |
| 296 | + |
| 297 | + |
| 298 | +open Classical in |
| 299 | +theorem eventually_card_primes_Ioc : ∀ᶠ x : ℕ in Filter.atTop, |
| 300 | + (x : ℝ) / (4 * Real.log x) ≤ ((Finset.Ioc (x / 4) x).filter Nat.Prime).card := by |
| 301 | + -- error terms are eventually small |
| 302 | + have hlog : ∀ᶠ y : ℝ in atTop, Real.log y ≤ (1 / 100) * y ^ (1 / 2 : ℝ) := by |
| 303 | + have := (isLittleO_log_rpow_atTop (r := (1 / 2 : ℝ)) (by norm_num)).bound |
| 304 | + (show (0 : ℝ) < 1 / 100 by norm_num) |
| 305 | + filter_upwards [this, eventually_gt_atTop (1 : ℝ)] with y hy hy1 |
| 306 | + have hy0 : 0 < y := by linarith |
| 307 | + simpa [Real.norm_eq_abs, abs_of_pos (Real.log_pos hy1), abs_of_pos (Real.rpow_pos_of_pos hy0 _)] using hy |
| 308 | + have hlogN : ∀ᶠ x : ℕ in atTop, Real.log x ≤ (1 / 100) * (x : ℝ) ^ (1 / 2 : ℝ) := |
| 309 | + tendsto_natCast_atTop_atTop.eventually hlog |
| 310 | + filter_upwards [hlogN, eventually_ge_atTop 4] with x hx hx4 |
| 311 | + have hxr : (4 : ℝ) ≤ x := by exact_mod_cast hx4 |
| 312 | + have hx0 : (0 : ℝ) < x := by linarith |
| 313 | + have hlogpos : 0 < Real.log x := Real.log_pos (by linarith) |
| 314 | + set c := ((Finset.Ioc (x / 4) x).filter Nat.Prime).card with hc |
| 315 | + have hsq : (x : ℝ) ^ (1 / 2 : ℝ) = √x := by rw [Real.sqrt_eq_rpow] |
| 316 | + rw [hsq] at hx |
| 317 | + have hsqx : √(x : ℝ) * √(x : ℝ) = x := Real.mul_self_sqrt hx0.le |
| 318 | + have hsq1 : 1 ≤ √(x : ℝ) := by rw [Real.one_le_sqrt]; linarith |
| 319 | + -- theta difference |
| 320 | + have hdiff : Chebyshev.theta (x : ℝ) - Chebyshev.theta ((x / 4 : ℕ) : ℝ) ≤ c * Real.log x := by |
| 321 | + have hsplit : Chebyshev.theta (x : ℝ) = Chebyshev.theta ((x / 4 : ℕ) : ℝ) + |
| 322 | + ∑ p ∈ (Finset.Ioc (x / 4) x).filter Nat.Prime, Real.log p := by |
| 323 | + simp only [Chebyshev.theta, Nat.floor_natCast, Finset.sum_filter] |
| 324 | + rw [Finset.sum_Ioc_consecutive _ (Nat.zero_le _) (Nat.div_le_self _ _)] |
| 325 | + rw [hsplit, add_sub_cancel_left] |
| 326 | + calc _ ≤ ∑ p ∈ (Finset.Ioc (x / 4) x).filter Nat.Prime, Real.log x := |
| 327 | + Finset.sum_le_sum fun p hp => by |
| 328 | + simp only [Finset.mem_filter, Finset.mem_Ioc] at hp |
| 329 | + exact Real.log_le_log (by exact_mod_cast hp.2.pos) (by exact_mod_cast hp.1.2) |
| 330 | + _ = c * Real.log x := by simp [hc] |
| 331 | + have hlow := Chebyshev.theta_ge x |
| 332 | + have hup : Chebyshev.theta ((x / 4 : ℕ) : ℝ) ≤ Real.log 4 * ((x : ℝ) / 4) := |
| 333 | + (Chebyshev.theta_le_log4_mul_x (by positivity)).trans |
| 334 | + (mul_le_mul_of_nonneg_left (Nat.cast_div_le) (Real.log_nonneg (by norm_num))) |
| 335 | + have hl4 : Real.log 4 = 2 * Real.log 2 := by |
| 336 | + rw [show (4 : ℝ) = 2 ^ 2 by norm_num, Real.log_pow]; norm_num |
| 337 | + have hl1 : Real.log ((x : ℝ) + 1) ≤ 3 * Real.log x := by |
| 338 | + have h2 : (4 : ℝ) * x ≤ (x : ℝ) ^ 2 := by nlinarith |
| 339 | + have h3 : (x : ℝ) + 1 ≤ (x : ℝ) ^ 3 := by nlinarith [mul_le_mul_of_nonneg_left h2 hx0.le] |
| 340 | + calc Real.log ((x : ℝ) + 1) ≤ Real.log ((x : ℝ) ^ 3) := Real.log_le_log (by positivity) h3 |
| 341 | + _ = 3 * Real.log x := by rw [Real.log_pow]; norm_num |
| 342 | + have hl2 := Real.log_two_gt_d9 |
| 343 | + have hs1 : Real.log x * √(x : ℝ) ≤ x / 100 := by nlinarith |
| 344 | + have hs2 : Real.log x ≤ x / 100 := by |
| 345 | + have : √(x : ℝ) ≤ x := by nlinarith |
| 346 | + nlinarith |
| 347 | + rw [div_le_iff₀ (by positivity)] |
| 348 | + nlinarith |
| 349 | + |
| 198 | 350 | end ErdosSwarm.Erdos5 |