This journal is in preparation. Submissions are open as a pilot and the editorial board is being formed. Articles marked Demonstration show the format only.
Journal of Machine-Verified MathematicsPeer-reviewed mathematics with machine-checked proofs, for the age of AI

E424/Defs.lean

All files · 344 lines · source at the verified commit

1module
2
3public import E424.ToolDefs
4public import E424.Input.Main
5public import E424.Input.Words
6
7@[expose] public section
8
9/-!
10# Erdős 424, natural density 2/3: definitions and basic API
11
12Outline: `docs/proof-outline.md`, including the corrections at its end.
13
14Conventions.
15* A window `W : Win` is a pair of real endpoints `lo < hi` and stands for the integers of `(lo, hi]`.
16 All averages are log-weighted and normalised by `W.len = log (hi / lo)`, so the normaliser is
17 invariant under dilation and additive under concatenation.
18* `ind p` is the real 0/1 indicator of a proposition.
19* Constants: `θ = 1/100`, `C0 = 200`. `K2 = (log lo)^C2` with `C2 = 200000`.
20-/
21
22set_option linter.style.header false
23open Finset
24
25namespace E424
26
27/- ## The sets -/
28
29/-- Hofstadter's set. -/
30def A : Set ℕ := Inp.genSet
31
32/-- `U = {n ≥ 1 : n ≢ 1 mod 3}`. -/
33def U : Set ℕ := {n | 1 ≤ n ∧ n % 3 ≠ 1}
34
35/-- `B = U \ A`. -/
36def B : Set ℕ := U \ A
37
38open Classical in
39/-- Real indicator of a proposition. -/
40noncomputable def ind (p : Prop) : ℝ := if p then 1 else 0
41
42/-- `f = 1_B`. -/
43noncomputable def f (n : ℕ) : ℝ := ind (n ∈ B)
44
45/-- `F z = f (3 z)`. -/
46noncomputable def F (n : ℕ) : ℝ := f (3 * n)
47
48/-- Bridge to the inductive form of membership. -/
49theorem mem_A_iff (n : ℕ) : n ∈ A ↔ Inp.Gen n := Inp.mem_iff n
50
51theorem mul_sub_one_mem_A {a b : ℕ} (ha : a ∈ A) (hb : b ∈ A) (hab : a ≠ b) : a * b - 1 ∈ A := by
52 rw [mem_A_iff] at *; exact .mul_sub_one ha hb hab
53
54theorem ind_true {p : Prop} (h : p) : ind p = 1 := if_pos h
55theorem ind_false {p : Prop} (h : ¬ p) : ind p = 0 := if_neg h
56theorem ind_nonneg (p : Prop) : 0 ≤ ind p := by unfold ind; split_ifs <;> norm_num
57theorem ind_le_one (p : Prop) : ind p ≤ 1 := by unfold ind; split_ifs <;> norm_num
58theorem ind_mono {p q : Prop} (h : p → q) : ind p ≤ ind q := by
59 by_cases hp : p
60 · rw [ind_true hp, ind_true (h hp)]
61 · rw [ind_false hp]; exact ind_nonneg q
62theorem ind_or_le (p q : Prop) : ind (p ∨ q) ≤ ind p + ind q := by
63 by_cases hp : p
64 · rw [ind_true (Or.inl hp), ind_true hp]; linarith [ind_nonneg q]
65 · rw [ind_false hp, zero_add]; exact ind_mono fun h => h.resolve_left hp
66theorem ind_congr {p q : Prop} (h : p ↔ q) : ind p = ind q := by rw [propext h]
67theorem f_nonneg (n : ℕ) : 0 ≤ f n := ind_nonneg _
68theorem f_le_one (n : ℕ) : f n ≤ 1 := ind_le_one _
69theorem F_nonneg (n : ℕ) : 0 ≤ F n := ind_nonneg _
70theorem F_le_one (n : ℕ) : F n ≤ 1 := ind_le_one _
71theorem f_eq_zero_or_one (n : ℕ) : f n = 0 ∨ f n = 1 := by
72 by_cases h : n ∈ B
73 · exact Or.inr (ind_true h)
74 · exact Or.inl (ind_false h)
75
76/- ## Windows -/
77
78/-- A window: real endpoints, standing for the integers of `(lo, hi]`. -/
79structure Win where
80 lo : ℝ
81 hi : ℝ
82
83namespace Win
84
85/-- Logarithmic length. -/
86noncomputable def len (W : Win) : ℝ := Real.log (W.hi / W.lo)
87
88/-- The integers of `(lo, hi]` (for `0 ≤ lo`). -/
89noncomputable def pts (W : Win) : Finset ℕ := Ioc ⌊W.lo⌋₊ ⌊W.hi⌋₊
90
91/-- `∑_{lo < n ≤ hi} g n / n`. -/
92noncomputable def sum (W : Win) (g : ℕ → ℝ) : ℝ := ∑ n ∈ W.pts, g n / n
93
94/-- The log-weighted average `E_W g`. -/
95noncomputable def E (W : Win) (g : ℕ → ℝ) : ℝ := W.sum g / W.len
96
97/-- `μ_W`. -/
98noncomputable def mu (W : Win) (S : Set ℕ) : ℝ := W.E fun n => ind (n ∈ S)
99
100/-- `W / c`. -/
101noncomputable def div (W : Win) (c : ℝ) : Win := ⟨W.lo / c, W.hi / c⟩
102
103/-- `D_W h = μ_W {n : F (n + h) ≠ F n}`. -/
104noncomputable def D (W : Win) (h : ℕ) : ℝ := W.E fun n => ind (F (n + h) ≠ F n)
105
106/-- The size of all boundary effects: `edge W = (log lo)^(-1/3)`. -/
107noncomputable def edge (W : Win) : ℝ := Real.log W.lo ^ (-(1/3) : ℝ)
108
109/-- The class `𝓦(N)` of windows of ratio `η` (with `lo ≥ 3` built in). -/
110structure Adm (η N : ℝ) (W : Win) : Prop where
111 three_le : 3 ≤ W.lo
112 lo_lt : W.lo < W.hi
113 le_lo : N ≤ W.lo
114 le_len : η * Real.log W.lo ≤ W.len
115 len_le : W.len ≤ 8 * η * Real.log W.lo
116
117variable {W : Win} {g g' : ℕ → ℝ}
118
119theorem mem_pts (h0 : 0 ≤ W.lo) (h : 0 ≤ W.hi) {n : ℕ} :
120 n ∈ W.pts ↔ W.lo < n ∧ (n : ℝ) ≤ W.hi := by
121 rw [pts, mem_Ioc, Nat.le_floor_iff h, Nat.floor_lt h0]
122
123theorem lo_lt_of_mem_pts {n : ℕ} (h0 : 0 ≤ W.lo) (hn : n ∈ W.pts) : W.lo < n :=
124 (Nat.floor_lt h0).mp (mem_Ioc.mp hn).1
125
126theorem sum_add : W.sum (fun n => g n + g' n) = W.sum g + W.sum g' := by
127 simp only [sum, add_div, sum_add_distrib]
128
129theorem sum_sub : W.sum (fun n => g n - g' n) = W.sum g - W.sum g' := by
130 simp only [sum, sub_div, sum_sub_distrib]
131
132theorem sum_const_mul (c : ℝ) : W.sum (fun n => c * g n) = c * W.sum g := by
133 simp only [sum, mul_div_assoc, mul_sum]
134
135theorem sum_finset_sum {ι : Type*} (s : Finset ι) (G : ι → ℕ → ℝ) :
136 W.sum (fun n => ∑ i ∈ s, G i n) = ∑ i ∈ s, W.sum (G i) := by
137 simp only [sum, sum_div]; exact Finset.sum_comm
138
139theorem sum_mono (h : ∀ n ∈ W.pts, g n ≤ g' n) : W.sum g ≤ W.sum g' :=
140 sum_le_sum fun n hn => div_le_div_of_nonneg_right (h n hn) (Nat.cast_nonneg n)
141
142theorem sum_nonneg (h : ∀ n ∈ W.pts, 0 ≤ g n) : 0 ≤ W.sum g :=
143 Finset.sum_nonneg fun n hn => div_nonneg (h n hn) (Nat.cast_nonneg n)
144
145theorem sum_congr (h : ∀ n ∈ W.pts, g n = g' n) : W.sum g = W.sum g' :=
146 Finset.sum_congr rfl fun n hn => by rw [h n hn]
147
148theorem abs_sum_le : |W.sum g| ≤ W.sum fun n => |g n| := by
149 unfold sum
150 refine (abs_sum_le_sum_abs _ _).trans (le_of_eq (Finset.sum_congr rfl fun n _ => ?_))
151 rw [abs_div, Nat.abs_cast]
152
153theorem sum_concat {a b c : ℝ} (hab : a ≤ b) (hbc : b ≤ c) :
154 (Win.mk a b).sum g + (Win.mk b c).sum g = (Win.mk a c).sum g := by
155 simp only [sum, pts]
156 rw [← sum_union (Ioc_disjoint_Ioc_of_le le_rfl)]
157 rw [Ioc_union_Ioc_eq_Ioc (Nat.floor_mono hab) (Nat.floor_mono hbc)]
158
159theorem len_concat {a b c : ℝ} (ha : 0 < a) (hab : a ≤ b) (hbc : b ≤ c) :
160 (Win.mk a b).len + (Win.mk b c).len = (Win.mk a c).len := by
161 have hb := ha.trans_le hab
162 have hc := hb.trans_le hbc
163 simp only [len]
164 rw [Real.log_div hb.ne' ha.ne', Real.log_div hc.ne' hb.ne', Real.log_div hc.ne' ha.ne']; ring
165
166theorem len_div {c : ℝ} (hc : c ≠ 0) : (W.div c).len = W.len := by
167 simp only [len, div]; rw [div_div_div_cancel_right₀ hc]
168
169theorem E_add : W.E (fun n => g n + g' n) = W.E g + W.E g' := by
170 simp only [E, sum_add, add_div]
171
172theorem E_sub : W.E (fun n => g n - g' n) = W.E g - W.E g' := by
173 simp only [E, sum_sub, sub_div]
174
175theorem E_const_mul (c : ℝ) : W.E (fun n => c * g n) = c * W.E g := by
176 simp only [E, sum_const_mul, mul_div_assoc]
177
178theorem E_mono (hL : 0 ≤ W.len) (h : ∀ n ∈ W.pts, g n ≤ g' n) : W.E g ≤ W.E g' :=
179 div_le_div_of_nonneg_right (sum_mono h) hL
180
181theorem E_nonneg (hL : 0 ≤ W.len) (h : ∀ n ∈ W.pts, 0 ≤ g n) : 0 ≤ W.E g :=
182 div_nonneg (sum_nonneg h) hL
183
184theorem sum_eq_E_mul (hL : 0 < W.len) : W.sum g = W.E g * W.len := by
185 unfold E; rw [div_mul_cancel₀ _ hL.ne']
186
187namespace Adm
188
189variable {η N : ℝ} (h : Adm η N W)
190
191include h
192theorem lo_pos : 0 < W.lo := by linarith [h.three_le]
193
194theorem one_lt_log : 1 < Real.log W.lo := by
195 rw [Real.lt_log_iff_exp_lt h.lo_pos]
196 linarith [h.three_le, Real.exp_one_lt_d9]
197
198theorem len_pos (hη : 0 < η) : 0 < W.len := by
199 have := h.one_lt_log
200 have := h.le_len
201 nlinarith
202
203theorem mono {N' : ℝ} (hN : N' ≤ N) : Adm η N' W :=
204 ⟨h.three_le, h.lo_lt, hN.trans h.le_lo, h.le_len, h.len_le⟩
205
206theorem hi_pos : 0 < W.hi := h.lo_pos.trans h.lo_lt
207
208omit h in
209/-- Dilating a window of ratio at most `tη` stays in the class as long as `log (lo / c)` keeps at least
210the proportion `t / 8` of `log lo`. -/
211theorem div {t c : ℝ} (hη : 0 ≤ η) (h : Adm η N W) (ht : W.len ≤ t * η * Real.log W.lo) {N' : ℝ}
212 (hc : 1 ≤ c) (h3 : 3 ≤ W.lo / c) (hN : N' ≤ W.lo / c)
213 (hlog : t / 8 * Real.log W.lo ≤ Real.log (W.lo / c)) : Adm η N' (W.div c) := by
214 have hc0 : 0 < c := by linarith
215 have hlo := h.lo_pos
216 refine ⟨h3, div_lt_div_of_pos_right h.lo_lt hc0, hN, ?_, ?_⟩
217 · rw [len_div hc0.ne']
218 refine le_trans ?_ h.le_len
219 refine mul_le_mul_of_nonneg_left ?_ hη
220 exact Real.log_le_log (by change 0 < W.lo / c; positivity) (div_le_self hlo.le hc)
221 · rw [len_div hc0.ne']
222 refine ht.trans ?_
223 change _ ≤ 8 * η * Real.log (W.lo / c)
224 nlinarith
225
226end Adm
227end Win
228
229/- ## Divisor families -/
230
231/-- `m_S = ∑ 1/s`. -/
232noncomputable def ms (S : Finset ℕ) : ℝ := ∑ s ∈ S, 1 / (s : ℝ)
233
234/-- `r_S n = #{s ∈ S : s ∣ n}`, as a real number. -/
235noncomputable def rc (S : Finset ℕ) (n : ℕ) : ℝ := ((S.filter (· ∣ n)).card : ℝ)
236
237/-- A θ-family at `z` (`C0 = 200`). -/
238def IsFam (z : ℝ) (S : Finset ℕ) : Prop := ∀ s ∈ S, z < s ∧ (s : ℝ) ≤ z ^ 200 ∧ Rough z s
239
240/-- `T` is a union of `J` θ-families ("blocks") at `z_0, z_1 ≥ z_0^200, ...`.
241A single family is the case `J = 1`. -/
242def IsBlocks (J : ℕ) (T : Finset ℕ) : Prop :=
243 ∃ (z : ℕ → ℝ) (S : ℕ → Finset ℕ), (∀ j < J, 3 ≤ z j ∧ IsFam (z j) (S j)) ∧
244 (∀ j, j + 1 < J → z j ^ 200 ≤ z (j + 1)) ∧ T = (range J).biUnion S
245
246/-- The macroscopic family of Lemma 10: `S ⊂ A ∩ [Y, Y^{1+τ}]`, `s ≡ ρ mod 54`, `Y^{1/100}`-rough,
247of mass at least `c τ`. -/
248structure MacroFam (c τ Y : ℝ) (ρ : ℕ) (S : Finset ℕ) : Prop where
249 mem : ∀ s ∈ S, s ∈ A ∧ s % 54 = ρ ∧ Y ≤ s ∧ (s : ℝ) ≤ Y ^ (1 + τ) ∧ Rough (Y ^ (1 / 100 : ℝ)) s
250 mass : c * τ ≤ ms S
251
252/-- The block of Lemma 11 at `z`. -/
253structure BlockFam (c z : ℝ) (ρ : ℕ) (S : Finset ℕ) : Prop where
254 fam : IsFam z S
255 mem : ∀ s ∈ S, s ∈ A ∧ s % 54 = ρ ∧ z ^ 100 ≤ s
256 mass : c ≤ ms S
257
258theorem ms_nonneg (S : Finset ℕ) : 0 ≤ ms S := Finset.sum_nonneg fun _ _ => by positivity
259theorem rc_nonneg (S : Finset ℕ) (n : ℕ) : 0 ≤ rc S n := Nat.cast_nonneg _
260
261theorem rc_eq_sum (S : Finset ℕ) (n : ℕ) : rc S n = ∑ s ∈ S, if s ∣ n then (1 : ℝ) else 0 := by
262 rw [rc, Finset.sum_ite, Finset.sum_const, Finset.sum_const_zero, add_zero, nsmul_eq_mul, mul_one]
263
264theorem rc_eq_sum' (S : Finset ℕ) (n : ℕ) : rc S n = ∑ s ∈ S with s ∣ n, (1 : ℝ) := by
265 rw [rc, Finset.sum_const, nsmul_eq_mul, mul_one]
266
267/- ## The exceptional sets of section 5 -/
268
269/-- `E_s = {y ∈ U : f y ≠ f (s y - 1)}`. -/
270def Es (s : ℕ) : Set ℕ := {y | y ∈ U ∧ f y ≠ f (s * y - 1)}
271def G1 : Set ℕ := {w | w ∈ U ∧ F w ≠ f w}
272def G2 : Set ℕ := {z | F (2 * z) ≠ F z}
273def G3 : Set ℕ := {z | F (3 * z) ≠ F z}
274
275/-- `#{s ∈ S : s ∣ n, F n ≠ F (n / s)}`. -/
276noncomputable def badCount (S : Finset ℕ) (n : ℕ) : ℝ :=
277 ∑ s ∈ S with s ∣ n, ind (F n ≠ F (n / s))
278
279/-- `∑_{s ∣ n} |F n - F (n / s)|`; equal to `badCount` since `F` is 0/1 valued. -/
280theorem badCount_eq (S : Finset ℕ) (n : ℕ) :
281 badCount S n = ∑ s ∈ S with s ∣ n, |F n - F (n / s)| := by
282 refine Finset.sum_congr rfl fun s _ => ?_
283 rcases f_eq_zero_or_one (3 * n) with h | h <;>
284 rcases f_eq_zero_or_one (3 * (n / s)) with h' | h' <;>
285 simp [F, h, h', ind]
286
287/- ## Dirichlet polynomials (sections 7, 8) -/
288
289/-- Smooth dyadic partition of unity on the log scale: supported in `[1,4]`, values in `[0,1]`,
290`∑_k gw (x / 2^k) = 1` for `x > 0`. -/
291noncomputable def gw (x : ℝ) : ℝ :=
292 if 0 < x then Real.smoothTransition (Real.logb 2 x) - Real.smoothTransition (Real.logb 2 x - 1)
293 else 0
294
295/-- `F_N(t) = ∑ gw(n/N) F(n) n^{-1-it}`, any real `N > 0`. -/
296noncomputable def Fp (N t : ℝ) : ℂ :=
297 ∑ n ∈ Icc 1 ⌊4 * N⌋₊, ((gw (n / N) * F n / n : ℝ) : ℂ) * nit n t
298
299/-- `Err_N^S(t) = F_N(t) - m_S^{-1} ∑_{s ∈ S} s^{-1-it} F_{N/s}(t)`. -/
300noncomputable def Err (S : Finset ℕ) (N t : ℝ) : ℂ :=
301 Fp N t - ((ms S)⁻¹ : ℝ) * ∑ s ∈ S, ((1 / s : ℝ) : ℂ) * nit s t * Fp (N / s) t
302
303/-- `𝒩(W)`: the exponents `k` with `[N/4, 16 N] ⊂ [lo, hi]`, `N = 2^k`. -/
304noncomputable def Win.dy (W : Win) : Finset ℕ :=
305 (range (⌈W.hi⌉₊ + 1)).filter fun k => 4 * W.lo ≤ 2 ^ k ∧ 16 * 2 ^ k ≤ W.hi
306
307/-- `C2 = 200000`. -/
308def C2 : ℕ := 200000
309
310/-- `K2 = (log lo)^C2`. -/
311noncomputable def K2 (lo : ℝ) : ℝ := Real.log lo ^ C2
312
313/-- `H1 = K2^C0`. -/
314noncomputable def H1 (lo : ℝ) : ℝ := K2 lo ^ 200
315
316/-- `ξ = K2^{ϖ/2} = (log lo)^100` (`ϖ = 1/1000`). -/
317noncomputable def xi (lo : ℝ) : ℝ := Real.log lo ^ 100
318
319/-- The cell polynomial `P_v(t)`, the sum over `s ∈ S` with `⌊ξ log s⌋ = v`. -/
320noncomputable def Pv (lo : ℝ) (S : Finset ℕ) (v : ℕ) (t : ℝ) : ℂ :=
321 ∑ s ∈ S with ⌊xi lo * Real.log (s : ℕ)⌋₊ = v, ((1 / s : ℝ) : ℂ) * nit s t
322
323/-- `𝒰`: some cell polynomial exceeds `K2^{-ϖ} = (log lo)^{-200}`. -/
324def Ubad (lo : ℝ) (S : Finset ℕ) : Set ℝ := {t | ∃ v, (Real.log lo ^ 200)⁻¹ < ‖Pv lo S v t‖}
325
326/-- `Band_N = {N^0.58 ≤ |t| ≤ N / H1}`. -/
327def Band (lo N : ℝ) : Set ℝ := {t | N ^ (0.58 : ℝ) ≤ |t| ∧ |t| ≤ N / H1 lo}
328
329/-- `|t| ≤ N / H1`. -/
330def Low (lo N : ℝ) : Set ℝ := Set.Icc (-(N / H1 lo)) (N / H1 lo)
331
332/-- `F̄(x) = ∑_n F(n)/n ψ_Q(x - log n)`; for `Q ≥ 1` all nonzero terms have `n ≤ e^{x+1}`. -/
333noncomputable def Fb (Q x : ℝ) : ℝ :=
334 ∑ n ∈ Icc 1 ⌊Real.exp (x + 1)⌋₊, F n / n * tri Q (x - Real.log n)
335
336/-- `Q = lo^0.59`. -/
337noncomputable def Qs (lo : ℝ) : ℝ := lo ^ (0.59 : ℝ)
338
339/-- `∫_{log lo + 3}^{log hi - 3} |F(⌊e^x⌋) - F̄(x)|² dx`, the quantity of Proposition G. -/
340noncomputable def L2err (W : Win) : ℝ :=
341 ∫ x in (Real.log W.lo + 3)..(Real.log W.hi - 3), (F ⌊Real.exp x⌋₊ - Fb (Qs W.lo) x) ^ 2
342
343end E424
344