goldbach-spectral-bridge
Li and Liu's GRH + S ⇒ Goldbach in Lean, checked against the paper by Comparator: clean it up together, and settle S
| 1 | module |
| 2 | |
| 3 | public import ConditionalGoldbach.Definitions.Operators |
| 4 | public import ConditionalGoldbach.Proofs.Elementary |
| 5 | public import Mathlib.Analysis.Asymptotics.SpecificAsymptotics |
| 6 | |
| 7 | /-! Natural density on the positive even integers and the norm of the full residual operator. -/ |
| 8 | @[expose] public section |
| 9 | |
| 10 | set_option autoImplicit false |
| 11 | noncomputable section |
| 12 | open Filter Finset |
| 13 | open scoped Topology BigOperators |
| 14 | |
| 15 | namespace ConditionalGoldbach |
| 16 | namespace ResidualAverage |
| 17 | |
| 18 | attribute [local instance] Classical.propDecidable |
| 19 | |
| 20 | /-- Index zero is the first positive even integer. -/ |
| 21 | def evenAt (j : ℕ) : ℕ := 2 * (j + 1) |
| 22 | |
| 23 | /-- The mean of the first `M` entries, with the usual real division convention at zero. -/ |
| 24 | def prefixMean (u : ℕ → ℝ) (M : ℕ) : ℝ := (∑ j ∈ range M, u j) / M |
| 25 | |
| 26 | /-- The indices in this block correspond to the positive integers `X < k ≤ 2*X`. -/ |
| 27 | def blockMean (u : ℕ → ℝ) (X : ℕ) : ℝ := prefixMean (fun j => u (X + j)) X |
| 28 | |
| 29 | /-- The real indicator of a set of indices. -/ |
| 30 | def hit (G : Set ℕ) (j : ℕ) : ℝ := if j ∈ G then 1 else 0 |
| 31 | |
| 32 | /-- The relative frequency of a set of indices in a finite prefix. -/ |
| 33 | def frequency (G : Set ℕ) (M : ℕ) : ℝ := |
| 34 | prefixMean (hit G) M |
| 35 | |
| 36 | theorem frequency_eq_card (G : Set ℕ) (M : ℕ) : |
| 37 | frequency G M = (((range M).filter (· ∈ G)).card : ℝ) / M := by |
| 38 | simp only [frequency, prefixMean, hit, sum_boole] |
| 39 | |
| 40 | /-- One set of positive even integers has relative natural density one, and along it the |
| 41 | nonnegative ratio is eventually below each positive threshold. -/ |
| 42 | def DensityOneLimit (r : ℕ → ℝ) : Prop := |
| 43 | ∃ E : Set ℕ, (∀ N ∈ E, 0 < N ∧ Even N) ∧ |
| 44 | Tendsto (frequency {j | evenAt j ∈ E}) atTop (𝓝 1) ∧ |
| 45 | ∀ ε : ℝ, 0 < ε → ∃ n : ℕ, ∀ N ∈ E, n ≤ N → r N < ε |
| 46 | |
| 47 | private lemma prefixMean_nonneg {u : ℕ → ℝ} (hu : ∀ j, 0 ≤ u j) (M : ℕ) : |
| 48 | 0 ≤ prefixMean u M := div_nonneg (sum_nonneg fun j _ => hu j) (Nat.cast_nonneg _) |
| 49 | |
| 50 | private lemma prefixMean_mono {u v : ℕ → ℝ} (h : ∀ j, u j ≤ v j) (M : ℕ) : |
| 51 | prefixMean u M ≤ prefixMean v M := |
| 52 | div_le_div_of_nonneg_right (sum_le_sum fun j _ => h j) (Nat.cast_nonneg _) |
| 53 | |
| 54 | private lemma frequency_compl {G : Set ℕ} {M : ℕ} (hM : 0 < M) : |
| 55 | frequency Gᶜ M = 1 - frequency G M := by |
| 56 | have he (j : ℕ) : hit Gᶜ j = 1 - hit G j := by |
| 57 | by_cases hj : j ∈ G <;> simp [hit, hj] |
| 58 | simp only [frequency, prefixMean, he, sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, |
| 59 | mul_one, sub_div, div_self (show (M : ℝ) ≠ 0 by positivity)] |
| 60 | |
| 61 | private lemma frequency_compl_tendsto (G : Set ℕ) {l : ℝ} |
| 62 | (h : Tendsto (frequency G) atTop (𝓝 l)) : |
| 63 | Tendsto (frequency Gᶜ) atTop (𝓝 (1 - l)) := by |
| 64 | apply (tendsto_const_nhds.sub h).congr' |
| 65 | filter_upwards [eventually_ge_atTop 1] with M hM |
| 66 | exact (frequency_compl (G := G) hM).symm |
| 67 | |
| 68 | /-- Choose an index if some later prefix makes its entry at most the moving threshold. |
| 69 | Every omitted index in a prefix is then larger than that prefix's own threshold. -/ |
| 70 | private lemma extract_indices (u : ℕ → ℝ) (hu : ∀ j, 0 ≤ u j) |
| 71 | (h : Tendsto (prefixMean u) atTop (𝓝 0)) : |
| 72 | ∃ G : Set ℕ, Tendsto (frequency G) atTop (𝓝 1) ∧ |
| 73 | ∀ ε : ℝ, 0 < ε → ∃ n : ℕ, ∀ j ∈ G, n ≤ j → u j < ε := by |
| 74 | let g (M : ℕ) := Real.sqrt (prefixMean u M) + 1 / ((M : ℝ) + 1) |
| 75 | have hg : Tendsto g atTop (𝓝 0) := by |
| 76 | simpa [g] using h.sqrt.add (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) |
| 77 | have hgpos (M : ℕ) : 0 < g M := by dsimp [g]; positivity |
| 78 | let G : Set ℕ := {j | ∃ M ≥ j, u j ≤ g M} |
| 79 | have hbad : Tendsto (frequency Gᶜ) atTop (𝓝 0) := by |
| 80 | apply squeeze_zero (fun M => prefixMean_nonneg (u := hit Gᶜ) |
| 81 | (fun j => by unfold hit; split_ifs <;> norm_num) M) _ hg |
| 82 | intro M |
| 83 | have hcount : ∑ j ∈ range M, hit Gᶜ j * g M ≤ ∑ j ∈ range M, u j := by |
| 84 | apply sum_le_sum |
| 85 | intro j hj |
| 86 | by_cases hjG : j ∈ Gᶜ |
| 87 | · simpa only [hit, ite_eq_left hjG, one_mul] using |
| 88 | (le_of_not_ge (fun hju => hjG ⟨M, (mem_range.mp hj).le, hju⟩) : g M ≤ u j) |
| 89 | · simpa only [hit, ite_eq_right hjG, zero_mul] using hu j |
| 90 | have hprod : frequency Gᶜ M * g M ≤ prefixMean u M := by |
| 91 | unfold frequency prefixMean |
| 92 | rw [div_mul_eq_mul_div, sum_mul] |
| 93 | exact div_le_div_of_nonneg_right hcount (Nat.cast_nonneg _) |
| 94 | have hs : prefixMean u M ≤ (g M) ^ 2 := by |
| 95 | rw [← Real.sq_sqrt (prefixMean_nonneg hu M)] |
| 96 | apply (sq_le_sq₀ (Real.sqrt_nonneg _) (hgpos M).le).mpr |
| 97 | dsimp [g] |
| 98 | exact le_add_of_nonneg_right (by positivity) |
| 99 | exact le_of_mul_le_mul_right (hprod.trans (by simpa only [pow_two] using hs)) (hgpos M) |
| 100 | refine ⟨G, by simpa using frequency_compl_tendsto Gᶜ hbad, ?_⟩ |
| 101 | intro ε hε |
| 102 | obtain ⟨n, hn⟩ := eventually_atTop.mp (hg.eventually_lt_const hε) |
| 103 | exact ⟨n, fun j ⟨M, hjM, hju⟩ hj => hju.trans_lt (hn M (hj.trans hjM))⟩ |
| 104 | |
| 105 | /-- Vanishing clipped square mean is equivalent to convergence to zero on one density-one |
| 106 | set of positive even integers. The entries may be unbounded on its complement. -/ |
| 107 | theorem clippedMean_iff {r : ℕ → ℝ} (hr : ∀ N, 0 ≤ r N) : |
| 108 | Tendsto (prefixMean fun j => min 1 (r (evenAt j) ^ 2)) atTop (𝓝 0) ↔ DensityOneLimit r := by |
| 109 | let u (j : ℕ) := min 1 (r (evenAt j) ^ 2) |
| 110 | have hu (j : ℕ) : 0 ≤ u j := le_min zero_le_one (sq_nonneg _) |
| 111 | constructor |
| 112 | · intro h |
| 113 | obtain ⟨G, hG, hsmall⟩ := extract_indices u hu h |
| 114 | let E := evenAt '' G |
| 115 | have hmem (j : ℕ) : evenAt j ∈ E ↔ j ∈ G := by |
| 116 | constructor |
| 117 | · rintro ⟨i, hi, he⟩ |
| 118 | have hij : i = j := by unfold evenAt at he; omega |
| 119 | simpa only [← hij] using hi |
| 120 | · exact fun hj => ⟨j, hj, rfl⟩ |
| 121 | refine ⟨E, ?_, ?_, ?_⟩ |
| 122 | · rintro N ⟨j, _, rfl⟩ |
| 123 | exact ⟨by unfold evenAt; omega, even_two_mul _⟩ |
| 124 | · have he : {j | evenAt j ∈ E} = G := Set.ext hmem |
| 125 | rwa [he] |
| 126 | · intro ε hε |
| 127 | obtain ⟨n, hn⟩ := hsmall (min 1 (ε ^ 2)) (lt_min zero_lt_one (sq_pos_of_pos hε)) |
| 128 | refine ⟨evenAt n, ?_⟩ |
| 129 | rintro _ ⟨j, hj, rfl⟩ hnj |
| 130 | have hjn : n ≤ j := by unfold evenAt at hnj; omega |
| 131 | by_contra! he |
| 132 | exact (hn j hj hjn).not_ge (min_le_min_left 1 ((sq_le_sq₀ hε.le (hr _)).2 he)) |
| 133 | · rintro ⟨E, _, hd, hE⟩ |
| 134 | let G : Set ℕ := {j | evenAt j ∈ E} |
| 135 | let v (j : ℕ) := if j ∈ G then r (evenAt j) else 0 |
| 136 | have hv : Tendsto v atTop (𝓝 0) := by |
| 137 | apply Metric.tendsto_atTop.mpr |
| 138 | intro ε hε |
| 139 | obtain ⟨n, hn⟩ := hE ε hε |
| 140 | refine ⟨n, fun j hj => ?_⟩ |
| 141 | by_cases hjG : j ∈ G |
| 142 | · simpa [v, hjG, Real.dist_eq, abs_of_nonneg (hr _)] using |
| 143 | hn (evenAt j) hjG (by unfold evenAt; omega) |
| 144 | · simpa [v, hjG] using hε |
| 145 | have hv2 : Tendsto (prefixMean fun j => v j ^ 2) atTop (𝓝 0) := by |
| 146 | change Tendsto (fun M : ℕ => (∑ j ∈ range M, v j ^ 2) / M) atTop (𝓝 0) |
| 147 | simpa [div_eq_inv_mul] using (hv.pow 2).cesaro |
| 148 | have hb : Tendsto (frequency Gᶜ) atTop (𝓝 0) := by |
| 149 | simpa using frequency_compl_tendsto G hd |
| 150 | apply squeeze_zero (prefixMean_nonneg hu) _ (by simpa using hv2.add hb) |
| 151 | intro M |
| 152 | calc |
| 153 | prefixMean u M ≤ prefixMean (fun j => v j ^ 2 + hit Gᶜ j) M := by |
| 154 | apply prefixMean_mono |
| 155 | intro j |
| 156 | by_cases hj : j ∈ G |
| 157 | · simp [v, u, hit, hj] |
| 158 | · simp [v, u, hit, hj] |
| 159 | _ = _ := by simp [prefixMean, frequency, sum_add_distrib, add_div] |
| 160 | |
| 161 | /-- The untruncated dyadic block means also suffice. -/ |
| 162 | theorem prefixMean_of_blockMean {u : ℕ → ℝ} (hu : ∀ j, 0 ≤ u j) |
| 163 | (h : Tendsto (blockMean u) atTop (𝓝 0)) : Tendsto (prefixMean u) atTop (𝓝 0) := by |
| 164 | let S (m : ℕ) := ∑ j ∈ range m, u j |
| 165 | have hmono {m n : ℕ} (hmn : m ≤ n) : S m ≤ S n := |
| 166 | sum_le_sum_of_subset_of_nonneg (range_mono hmn) (fun j _ _ => hu j) |
| 167 | apply Metric.tendsto_atTop.mpr |
| 168 | intro ε hε |
| 169 | let δ := ε / 4 |
| 170 | have hδ : 0 < δ := by dsimp [δ]; positivity |
| 171 | obtain ⟨K, hK⟩ := eventually_atTop.mp (h.eventually_lt_const hδ) |
| 172 | let B := 2 * K + 4 |
| 173 | have hbound (m : ℕ) : S m ≤ S B + 2 * δ * m := by |
| 174 | induction m using Nat.strong_induction_on with |
| 175 | | h m ih => |
| 176 | by_cases hbase : m ≤ B |
| 177 | · exact (hmono hbase).trans (le_add_of_nonneg_right (by positivity)) |
| 178 | · let x := (m + 1) / 2 |
| 179 | have hx : K ≤ x ∧ 0 < x ∧ x < m ∧ m ≤ x + x ∧ 3 * x ≤ 2 * m := by |
| 180 | dsimp [x, B] at *; omega |
| 181 | have hblock := hK x hx.1 |
| 182 | have hsum : ∑ j ∈ range x, u (x + j) ≤ δ * x := |
| 183 | (div_le_iff₀ (Nat.cast_pos.mpr hx.2.1)).mp hblock.le |
| 184 | have hsplit : S (x + x) = S x + ∑ j ∈ range x, u (x + j) := sum_range_add u x x |
| 185 | have hscale : (3 : ℝ) * x ≤ 2 * m := by exact_mod_cast hx.2.2.2.2 |
| 186 | calc |
| 187 | S m ≤ S (x + x) := hmono hx.2.2.2.1 |
| 188 | _ ≤ (S B + 2 * δ * x) + δ * x := by rw [hsplit]; exact add_le_add (ih x hx.2.2.1) hsum |
| 189 | _ ≤ _ := by nlinarith only [mul_le_mul_of_nonneg_left hscale hδ.le] |
| 190 | obtain ⟨n, hn⟩ := eventually_atTop.mp |
| 191 | ((tendsto_const_div_atTop_nhds_zero_nat (S B)).eventually_lt_const hδ) |
| 192 | refine ⟨max n 1, fun m hm => ?_⟩ |
| 193 | have hmpos : (0 : ℝ) < m := Nat.cast_pos.mpr (le_trans (le_max_right _ _) hm) |
| 194 | have hratio : prefixMean u m ≤ S B / m + 2 * δ := by |
| 195 | apply (div_le_iff₀ hmpos).mpr |
| 196 | calc |
| 197 | S m ≤ S B + 2 * δ * m := hbound m |
| 198 | _ = _ := by field_simp |
| 199 | have hfirst := hn m (le_trans (le_max_left _ _) hm) |
| 200 | rw [Real.dist_eq, sub_zero, abs_of_nonneg (prefixMean_nonneg hu m)] |
| 201 | dsimp [δ] at hfirst hratio |
| 202 | linarith |
| 203 | |
| 204 | /-- For nonnegative entries the full prefixes and all the blocks `X < k ≤ 2*X` |
| 205 | have zero mean in the limit simultaneously. -/ |
| 206 | theorem prefixMean_iff_blockMean {u : ℕ → ℝ} (hu : ∀ j, 0 ≤ u j) : |
| 207 | Tendsto (prefixMean u) atTop (𝓝 0) ↔ Tendsto (blockMean u) atTop (𝓝 0) := by |
| 208 | refine ⟨fun h => ?_, prefixMean_of_blockMean hu⟩ |
| 209 | have h2 : Tendsto (fun X : ℕ => X + X) atTop atTop := |
| 210 | tendsto_atTop.mpr fun K => (eventually_ge_atTop K).mono fun X hX => by omega |
| 211 | have ht : Tendsto (fun X : ℕ => 2 * prefixMean u (X + X)) atTop (𝓝 0) := by |
| 212 | simpa using (h.comp h2).const_mul 2 |
| 213 | apply squeeze_zero (fun X => prefixMean_nonneg (fun j => hu (X+j)) X) _ ht |
| 214 | intro X |
| 215 | have he : 2 * prefixMean u (X+X) = prefixMean u X + blockMean u X := by |
| 216 | unfold blockMean prefixMean |
| 217 | rw [sum_range_add, Nat.cast_add] |
| 218 | by_cases hx : X = 0 |
| 219 | · simp [hx] |
| 220 | · have hx' : (X : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hx |
| 221 | have hxx : (X : ℝ) + X ≠ 0 := by positivity |
| 222 | field_simp |
| 223 | ring |
| 224 | rw [he] |
| 225 | exact le_add_of_nonneg_left (prefixMean_nonneg hu X) |
| 226 | |
| 227 | /-- The project's actual norm ratio on its standard strip, extended by zero over the |
| 228 | finite prefix where the strip parameters are unavailable. -/ |
| 229 | def residualRatio (N : ℕ) : ℝ := |
| 230 | if h : Real.exp 10 < (N : ℝ) then |
| 231 | letI : NeZero N := ⟨by have := (large_parameters h).1; omega⟩ |
| 232 | ‖residualOperator (large_parameters h).2.2 N‖ / singularSeries N |
| 233 | else 0 |
| 234 | |
| 235 | theorem residualRatio_nonneg (N : ℕ) : 0 ≤ residualRatio N := by |
| 236 | unfold residualRatio |
| 237 | split_ifs |
| 238 | · exact div_nonneg (norm_nonneg _) (singularSeries_pos N).le |
| 239 | · exact le_rfl |
| 240 | |
| 241 | /-- The clipped mean criterion for the full residual operator. -/ |
| 242 | theorem residual_clippedMean_iff : |
| 243 | Tendsto (prefixMean fun j => min 1 (residualRatio (evenAt j) ^ 2)) atTop (𝓝 0) ↔ |
| 244 | DensityOneLimit residualRatio := clippedMean_iff residualRatio_nonneg |
| 245 | |
| 246 | /-- A mean square estimate at all prefixes gives one density-one set for the residual. -/ |
| 247 | theorem residual_of_meanSquare |
| 248 | (h : Tendsto (prefixMean fun j => residualRatio (evenAt j) ^ 2) atTop (𝓝 0)) : |
| 249 | DensityOneLimit residualRatio := |
| 250 | residual_clippedMean_iff.mp (squeeze_zero |
| 251 | (prefixMean_nonneg fun _ => le_min zero_le_one (sq_nonneg _)) |
| 252 | (prefixMean_mono fun _ => min_le_right _ _) h) |
| 253 | |
| 254 | /-- A mean square estimate for `X < k ≤ 2*X` gives the same density-one conclusion. -/ |
| 255 | theorem residual_of_blockMeanSquare |
| 256 | (h : Tendsto (blockMean fun j => residualRatio (evenAt j) ^ 2) atTop (𝓝 0)) : |
| 257 | DensityOneLimit residualRatio := |
| 258 | residual_of_meanSquare (prefixMean_of_blockMean (fun _ => sq_nonneg _) h) |
| 259 | |
| 260 | end ResidualAverage |
| 261 | end ConditionalGoldbach |
