| | @@ -1,5 +1,7 @@ |
| 1 | 1 | import Mathlib.NumberTheory.Chebyshev |
| 2 | 2 | import Mathlib.Analysis.Complex.ExponentialBounds |
| 3 | +import Mathlib.NumberTheory.SumPrimeReciprocals |
| 4 | +import Mathlib.NumberTheory.Primorial |
| 3 | 5 | |
| 4 | 6 | /-! |
| 5 | 7 | # Erdős Problem 5: elementary bounds on the primes |
| | @@ -66,4 +68,102 @@ theorem nth_prime_le : ∃ C : ℝ, ∀ᶠ N : ℕ in atTop, |
| 66 | 68 | linarith |
| 67 | 69 | nlinarith |
| 68 | 70 | |
| 71 | +open Finset in |
| 72 | +theorem exists_primorial_totient_le {ε : ℝ} (hε : 0 < ε) : |
| 73 | + ∃ z : ℕ, ((primorial z).totient : ℝ) ≤ ε * primorial z := by |
| 74 | + have hns := not_summable_one_div_on_primes |
| 75 | + have hnn : ∀ n : ℕ, 0 ≤ Set.indicator {p | p.Prime} (fun n : ℕ ↦ (1 : ℝ) / n) n := fun n => |
| 76 | + Set.indicator_nonneg (fun p _ => by positivity) n |
| 77 | + have ht := (not_summable_iff_tendsto_nat_atTop_of_nonneg hnn).1 hns |
| 78 | + have hev := ht.eventually_ge_atTop (-Real.log ε) |
| 79 | + obtain ⟨z, hz⟩ := hev.exists |
| 80 | + have hsum : ∑ i ∈ range z, Set.indicator {p | p.Prime} (fun n : ℕ ↦ (1 : ℝ) / n) i |
| 81 | + = ∑ p ∈ (range z).filter Nat.Prime, (1 : ℝ) / p := by |
| 82 | + rw [Finset.sum_filter] |
| 83 | + refine Finset.sum_congr rfl fun i _ => ?_ |
| 84 | + by_cases h : i.Prime <;> simp [Set.indicator, h] |
| 85 | + rw [hsum] at hz |
| 86 | + refine ⟨z, ?_⟩ |
| 87 | + have hsub : (range z).filter Nat.Prime ⊆ (primorial z).primeFactors := by |
| 88 | + intro p hp |
| 89 | + rw [mem_filter, mem_range] at hp |
| 90 | + rw [primeFactors_primorial] |
| 91 | + show p ∈ (range (z + 1)).filter Nat.Prime |
| 92 | + rw [mem_filter, mem_range] |
| 93 | + exact ⟨by omega, hp.2⟩ |
| 94 | + have hq := Nat.totient_eq_mul_prod_factors (primorial z) |
| 95 | + have hR : ((primorial z).totient : ℝ) = (primorial z : ℝ) * |
| 96 | + ∏ p ∈ (primorial z).primeFactors, (1 - (p : ℝ)⁻¹) := by |
| 97 | + have := congrArg (fun q : ℚ => (q : ℝ)) hq |
| 98 | + simpa using this |
| 99 | + rw [hR, mul_comm ε] |
| 100 | + refine mul_le_mul_of_nonneg_left ?_ (by positivity) |
| 101 | + have h1 : ∏ p ∈ (primorial z).primeFactors, (1 - (p : ℝ)⁻¹) ≤ |
| 102 | + ∏ p ∈ (primorial z).primeFactors, Real.exp (-(p : ℝ)⁻¹) := by |
| 103 | + refine Finset.prod_le_prod (fun p hp => ?_) (fun p hp => ?_) |
| 104 | + · have := (Nat.prime_of_mem_primeFactors hp).two_le |
| 105 | + have : (2 : ℝ) ≤ p := by exact_mod_cast this |
| 106 | + have : (p : ℝ)⁻¹ ≤ 1 := inv_le_one_of_one_le₀ (by linarith) |
| 107 | + linarith |
| 108 | + · have := Real.add_one_le_exp (-(p : ℝ)⁻¹) |
| 109 | + linarith |
| 110 | + refine h1.trans ?_ |
| 111 | + rw [← Real.exp_sum, Finset.sum_neg_distrib] |
| 112 | + have h2 : ∑ p ∈ (range z).filter Nat.Prime, (1 : ℝ) / p ≤ ∑ p ∈ (primorial z).primeFactors, (p : ℝ)⁻¹ := by |
| 113 | + simp only [one_div] |
| 114 | + exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun p _ _ => by positivity) |
| 115 | + calc Real.exp (-∑ p ∈ (primorial z).primeFactors, (p : ℝ)⁻¹) |
| 116 | + ≤ Real.exp (Real.log ε) := Real.exp_le_exp.2 (by linarith) |
| 117 | + _ = ε := Real.exp_log hε |
| 118 | + |
| 119 | +open Finset in |
| 120 | +theorem exists_shift_few_coprime {P : ℕ} (hP : 0 < P) (S : Finset ℕ) : |
| 121 | + ∃ m₀ < P, ((S.filter fun n => Nat.Coprime (m₀ + n) P).card : ℝ) * P ≤ P.totient * S.card := by |
| 122 | + have hco : ∀ m : ℕ, Nat.Coprime (m % P) P ↔ Nat.Coprime P m := by |
| 123 | + intro m |
| 124 | + simp only [Nat.Coprime] |
| 125 | + rw [← Nat.gcd_rec P m] |
| 126 | + have hcard : ∀ n : ℕ, ((range P).filter fun m₀ => Nat.Coprime (m₀ + n) P).card = P.totient := by |
| 127 | + intro n |
| 128 | + rw [Nat.totient] |
| 129 | + refine Finset.card_nbij (fun m => (m + n) % P) ?_ ?_ ?_ |
| 130 | + · intro m hm |
| 131 | + simp only [mem_filter, mem_range, mem_coe] at hm ⊢ |
| 132 | + refine ⟨Nat.mod_lt _ hP, ?_⟩ |
| 133 | + rw [Nat.coprime_comm, hco]; exact hm.2.symm |
| 134 | + · intro a ha b hb hab |
| 135 | + simp only [mem_coe, mem_filter, mem_range] at ha hb |
| 136 | + have := Nat.ModEq.add_right_cancel' n hab |
| 137 | + exact (Nat.ModEq.eq_of_lt_of_lt this ha.1 hb.1) |
| 138 | + · intro b hb |
| 139 | + simp only [mem_coe, mem_filter, mem_range] at hb |
| 140 | + have key : b + (P - n % P) + n = b + P * (n / P + 1) := by |
| 141 | + have := Nat.div_add_mod n P |
| 142 | + have := Nat.mod_lt n hP |
| 143 | + rw [Nat.mul_add]; omega |
| 144 | + have hmod : ((b + (P - n % P)) % P + n) % P = b := by |
| 145 | + rw [Nat.mod_add_mod, key, Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hb.1] |
| 146 | + refine ⟨(b + (P - n % P)) % P, ?_, hmod⟩ |
| 147 | + simp only [mem_coe, mem_filter, mem_range] |
| 148 | + refine ⟨Nat.mod_lt _ hP, ?_⟩ |
| 149 | + have h3 := hb.2 |
| 150 | + rw [← hmod, Nat.coprime_comm, hco] at h3 |
| 151 | + exact h3.symm |
| 152 | + by_contra hcon |
| 153 | + simp only [not_exists, not_and, not_le] at hcon |
| 154 | + have hsum : ∑ m₀ ∈ range P, (S.filter fun n => Nat.Coprime (m₀ + n) P).card |
| 155 | + = ∑ n ∈ S, ((range P).filter fun m₀ => Nat.Coprime (m₀ + n) P).card := by |
| 156 | + simp only [Finset.card_filter] |
| 157 | + exact Finset.sum_comm |
| 158 | + simp only [hcard, Finset.sum_const, smul_eq_mul] at hsum |
| 159 | + have hne : (range P).Nonempty := ⟨0, by simp [hP]⟩ |
| 160 | + have hlt : ∑ m₀ ∈ range P, (P.totient : ℝ) * S.card < |
| 161 | + ∑ m₀ ∈ range P, ((S.filter fun n => Nat.Coprime (m₀ + n) P).card : ℝ) * P := |
| 162 | + Finset.sum_lt_sum_of_nonempty hne (fun m₀ hm => hcon m₀ (mem_range.1 hm)) |
| 163 | + have hs' : (∑ m₀ ∈ range P, ((S.filter fun n => Nat.Coprime (m₀ + n) P).card : ℝ)) |
| 164 | + = S.card * P.totient := by exact_mod_cast hsum |
| 165 | + rw [← Finset.sum_mul (f := fun m₀ => ((S.filter fun n => Nat.Coprime (m₀ + n) P).card : ℝ)), hs'] at hlt |
| 166 | + simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at hlt |
| 167 | + nlinarith |
| 168 | + |
| 69 | 169 | end ErdosSwarm.Erdos5 |