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/Rigidity/Core.lean

All files · 1238 lines · source at the verified commit

1module
2
3public import E424.Rigidity.Setup
4
5@[expose] public section
6
7/-!
8# Section 5: Lemmas 18-24 (all proved, from section 4)
9-/
10
11set_option linter.style.header false
12open Finset
13
14namespace E424
15
16/-- Summand of the defect of `(s, n)`: nonnegative on windows with `lo ≥ s²`. -/
17theorem defect_nonneg {s n : ℕ} (hs : s ∈ A) (hs3 : s % 3 = 2) (hn : 1 ≤ n) (hsn : s ∣ n)
18 (hne : s * s ≠ n) : 0 ≤ f (n / s) - f (n - 1) := by
19 obtain ⟨y, rfl⟩ := hsn
20 have hs1 : 0 < s := by omega
21 have hy1 : 1 ≤ y := Nat.pos_of_mul_pos_left hn
22 rw [Nat.mul_div_cancel_left y hs1]
23 by_cases hyU : y ∈ U
24 · linarith [L4 hs hyU (fun h => hne (by rw [← h]))]
25 · rw [f_eq_zero_of_not_U hyU, f_eq_zero_of_not_U fun h => hyU ((mem_U_iff_of_mod hs3 hy1).mp h)]
26 simp
27
28/-- For large `lo`, `s² < lo` for all `s ≤ exp √(log lo)`. -/
29theorem exp_sq_lt : ∃ N0 : ℝ, ∀ lo ≥ N0, Real.exp (Real.sqrt (Real.log lo)) ^ 2 < lo := by
30 refine ⟨Real.exp 9, fun lo hlo => ?_⟩
31 have h0 : 0 < lo := (Real.exp_pos 9).trans_le hlo
32 have hl : 9 ≤ Real.log lo := by rwa [Real.le_log_iff_exp_le h0]
33 rw [← Real.exp_nat_mul]
34 conv_rhs => rw [← Real.exp_log h0]
35 rw [Real.exp_lt_exp]
36 have h1 := Real.sq_sqrt (show 0 ≤ Real.log lo by linarith)
37 have h2 : 3 ≤ Real.sqrt (Real.log lo) := by
38 rw [Real.le_sqrt (by norm_num) (by linarith)]; linarith
39 push_cast
40 nlinarith
41
42/-- **Lemma 18**, class by class: `|δ_a - (b(r) - b(ρr-1))| ≤ x + 2 edge`, `a = ρ r`. -/
43theorem L18_aux (K η : ℝ) (hη : 0 < η) : ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
44 ∀ ρ : ℕ, ρ = 53 ∨ ρ = 23 → ∀ r < 54,
45 |W.E (fun n => ∑ s ∈ T ρ with s ∣ n, ind (n % 54 = ρ * r % 54) * (f (n / s) - f (n - 1))) -
46 ms (T ρ) * (bcl W r - bcl W ((ρ * r + 53) % 54))| ≤ ms (T ρ) * (x + 2 * W.edge) := by
47 obtain ⟨N1, hfam⟩ := E_family_le η hη
48 refine ⟨max N1 (4 / η), fun W J T x hS ρ hρ r hr => ?_⟩
49 have hL := hS.adm.len_pos hη
50 have hR := hS.rig ρ hρ
51 have hsm := small_le_edge hη (hS.adm.mono (le_max_right _ _)) le_rfl
52 set M := ms (T ρ) with hM
53 have hJ0 : (0 : ℝ) < J := by have := hS.three_le; positivity
54 have hM0 : 0 < M := by
55 rcases (ms_nonneg (T ρ)).lt_or_eq with h | h
56 · exact h
57 · exfalso; have := hR.le_ms; rw [← h] at this; linarith
58 set a := ρ * r % 54 with ha
59 -- first part
60 have h1 := hfam W (hS.adm.mono (le_max_left _ _)) (T ρ)
61 (fun s hs => ⟨by have := (hR.mem s hs).2.1; omega, (hR.mem s hs).2.2⟩)
62 (fun y => ind (y % 54 = r) * f y) (fun y => mul_nonneg (ind_nonneg _) (f_nonneg _))
63 (fun y => mul_le_one₀ (ind_le_one _) (f_nonneg _) (f_le_one _))
64 -- second part
65 have h2 : |W.E (fun n => ind (n % 54 = a) * f (n - 1) * (M - rc (T ρ) n))| ≤ x * M := by
66 have := hS.bound ρ hρ a (Nat.mod_lt _ (by norm_num))
67 unfold Dl at this
68 rwa [div_le_iff₀ hM0] at this
69 have h3 := E_shift_le hη hS.adm 1 (fun n => ind (n % 54 = a) * f (n - 1)) 1 (fun n => by
70 rw [abs_of_nonneg (mul_nonneg (ind_nonneg _) (f_nonneg _))]
71 exact mul_le_one₀ (ind_le_one _) (f_nonneg _) (f_le_one _))
72 have h4 : W.E (fun n => ind ((n + 1) % 54 = a) * f (n + 1 - 1)) = bcl W ((ρ * r + 53) % 54) := by
73 unfold bcl
74 congr 1
75 funext n
76 have : (n + 1) % 54 = a ↔ n % 54 = (ρ * r + 53) % 54 := by omega
77 rw [Nat.add_sub_cancel, ind_congr this]
78 beta_reduce at h3
79 rw [h4] at h3
80 have h5 : W.E (fun n => ind (n % 54 = a) * f (n - 1) * (M - rc (T ρ) n)) =
81 M * W.E (fun n => ind (n % 54 = a) * f (n - 1)) -
82 W.E (fun n => ind (n % 54 = a) * f (n - 1) * rc (T ρ) n) := by
83 rw [← Win.E_const_mul, ← Win.E_sub]
84 congr 1; funext n; ring
85 have h6 : W.E (fun n => ∑ s ∈ T ρ with s ∣ n, ind (n % 54 = a) * (f (n / s) - f (n - 1))) =
86 W.E (fun n => ∑ s ∈ T ρ with s ∣ n, ind (n / s % 54 = r) * f (n / s)) -
87 W.E (fun n => ind (n % 54 = a) * f (n - 1) * rc (T ρ) n) := by
88 rw [← Win.E_sub]
89 congr 1; funext n
90 rw [rc_eq_sum', mul_sum, ← sum_sub_distrib]
91 refine sum_congr rfl fun s hs => ?_
92 rw [mem_filter] at hs
93 obtain ⟨hsT, y, rfl⟩ := hs
94 have hsρ := (hR.mem s hsT).2.1
95 have hs0 : 0 < s := by rcases hρ with rfl | rfl <;> omega
96 rw [Nat.mul_div_cancel_left y hs0]
97 have hiff : s * y % 54 = a ↔ y % 54 = r := by
98 rw [Nat.mul_mod, hsρ, ha]
99 have hy := Nat.mod_lt y (show 0 < 54 by norm_num)
100 generalize y % 54 = y' at hy
101 rcases hρ with rfl | rfl <;> omega
102 rw [ind_congr hiff]
103 ring
104 rw [h6]
105 have hb : W.E (fun y => ind (y % 54 = r) * f y) = bcl W r := rfl
106 beta_reduce at h1
107 rw [hb] at h1
108 rw [h5] at h2
109 rw [abs_le] at *
110 have h7 : 1 * (4 / (W.lo * W.len)) ≤ W.edge := by linarith
111 push_cast at h3
112 have h8 : -W.edge ≤ bcl W ((ρ * r + 53) % 54) - W.E (fun n => ind (n % 54 = a) * f (n - 1)) := by linarith [h3.1]
113 have h9 : bcl W ((ρ * r + 53) % 54) - W.E (fun n => ind (n % 54 = a) * f (n - 1)) ≤ W.edge := by linarith [h3.2]
114 have h10 := mul_le_mul_of_nonneg_left h8 hM0.le
115 have h11 := mul_le_mul_of_nonneg_left h9 hM0.le
116 constructor <;> nlinarith [h1.1, h1.2, h2.1, h2.2]
117
118/-- **Lemma 18.** The total defect and the class identity. -/
119theorem L18 (K η : ℝ) (hη : 0 < η) : ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
120 ∀ ρ : ℕ, ρ = 53 ∨ ρ = 23 →
121 W.E (fun n => ∑ s ∈ T ρ with s ∣ n, (f (n / s) - f (n - 1))) / ms (T ρ) ≤
122 54 * (x + 2 * W.edge) ∧
123 ∀ r < 54, |bcl W r - bcl W ((ρ * r + 53) % 54)| ≤ 55 * (x + 2 * W.edge) := by
124 obtain ⟨N1, haux⟩ := L18_aux K η hη
125 obtain ⟨N2, hexp⟩ := exp_sq_lt
126 refine ⟨max N1 N2, fun W J T x hS ρ hρ => ?_⟩
127 have hL := hS.adm.len_pos hη
128 have hR := hS.rig ρ hρ
129 have hsq := hexp W.lo ((le_max_right _ _).trans hS.adm.le_lo)
130 set M := ms (T ρ) with hM
131 have hJ0 : (0 : ℝ) < J := by have := hS.three_le; positivity
132 have hM0 : 0 < M := by
133 rcases (ms_nonneg (T ρ)).lt_or_eq with h | h
134 · exact h
135 · exfalso; have := hR.le_ms; rw [← h] at this; linarith
136 set d : ℕ → ℝ := fun r =>
137 W.E (fun n => ∑ s ∈ T ρ with s ∣ n, ind (n % 54 = ρ * r % 54) * (f (n / s) - f (n - 1))) with hd
138 have hb : ∀ r < 54, |d r - M * (bcl W r - bcl W ((ρ * r + 53) % 54))| ≤ M * (x + 2 * W.edge) :=
139 fun r hr => haux W J T x (hS.mono (le_max_left _ _)) ρ hρ r hr
140 have hd0 : ∀ r, 0 ≤ d r := fun r => by
141 refine Win.E_nonneg hL.le fun n hn => sum_nonneg fun s hs => mul_nonneg (ind_nonneg _) ?_
142 rw [mem_filter] at hs
143 have hmem := hR.mem s hs.1
144 have hn1 := one_le_of_mem_pts hS.adm hn
145 refine defect_nonneg hmem.1 (by omega) hn1 hs.2 fun h => ?_
146 have h1 := Win.lo_lt_of_mem_pts hS.adm.lo_pos.le hn
147 have h2 : (n : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo)) ^ 2 := by
148 rw [← h]; push_cast; rw [sq]
149 exact mul_le_mul hmem.2.2 hmem.2.2 (Nat.cast_nonneg _) (Real.exp_pos _).le
150 linarith
151 have htot : W.E (fun n => ∑ s ∈ T ρ with s ∣ n, (f (n / s) - f (n - 1))) = ∑ r ∈ range 54, d r := by
152 have : (fun n => ∑ s ∈ T ρ with s ∣ n, (f (n / s) - f (n - 1))) = fun n =>
153 ∑ r ∈ range 54, ∑ s ∈ T ρ with s ∣ n, ind (n % 54 = ρ * r % 54) * (f (n / s) - f (n - 1)) := by
154 funext n
155 rw [sum_comm]
156 refine sum_congr rfl fun s _ => ?_
157 rw [← sum_mul]
158 have : ∑ r ∈ range 54, ind (n % 54 = ρ * r % 54) = 1 := by
159 have hn := Nat.mod_lt n (show 0 < 54 by norm_num)
160 generalize n % 54 = m at hn
161 have hex : ∃ r ∈ range 54, m = ρ * r % 54 ∧ ∀ r' ∈ range 54, m = ρ * r' % 54 → r' = r := by
162 rcases hρ with rfl | rfl
163 · exact ⟨53 * m % 54, mem_range.mpr (Nat.mod_lt _ (by norm_num)), by omega, fun r' h' h => by
164 rw [mem_range] at h'; omega⟩
165 · exact ⟨47 * m % 54, mem_range.mpr (Nat.mod_lt _ (by norm_num)), by omega, fun r' h' h => by
166 rw [mem_range] at h'; omega⟩
167 obtain ⟨r, hr, hm, huniq⟩ := hex
168 rw [sum_eq_single_of_mem r hr fun r' h' hne => ind_false fun h => hne (huniq r' h' h)]
169 exact ind_true hm
170 rw [this, one_mul]
171 rw [this]
172 unfold Win.E
173 rw [Win.sum_finset_sum, sum_div]
174 rfl
175 have hperm : ∑ r ∈ range 54, bcl W ((ρ * r + 53) % 54) = ∑ r ∈ range 54, bcl W r := by
176 generalize bcl W = β
177 rcases hρ with rfl | rfl <;> · simp [sum_range_succ]; ring
178 have hsumd : ∑ r ∈ range 54, d r ≤ 54 * (M * (x + 2 * W.edge)) := by
179 have h1 : ∑ r ∈ range 54, d r ≤
180 ∑ r ∈ range 54, (M * (bcl W r - bcl W ((ρ * r + 53) % 54)) + M * (x + 2 * W.edge)) :=
181 sum_le_sum fun r hr => by linarith [(abs_le.mp (hb r (mem_range.mp hr))).2]
182 rw [sum_add_distrib, ← mul_sum, sum_sub_distrib, hperm, sub_self, mul_zero, zero_add, sum_const,
183 card_range, nsmul_eq_mul] at h1
184 exact_mod_cast h1
185 refine ⟨?_, fun r hr => ?_⟩
186 · rw [htot, div_le_iff₀ hM0]; linarith
187 · have h1 := abs_le.mp (hb r hr)
188 have h2 : d r ≤ 54 * (M * (x + 2 * W.edge)) :=
189 (single_le_sum (fun i _ => hd0 i) (mem_range.mpr hr)).trans hsumd
190 have h3 := hd0 r
191 have hM' : M * |bcl W r - bcl W ((ρ * r + 53) % 54)| ≤ M * (55 * (x + 2 * W.edge)) := by
192 rw [← abs_of_pos hM0, ← abs_mul, abs_of_pos hM0, abs_le]
193 constructor <;> linarith
194 exact le_of_mul_le_mul_left hM' hM0
195
196/-- **Lemma 19** in the form used: if `β` is nearly invariant under `r ↦ 53 r - 1` and `r ↦ 23 r - 1` mod 54,
197it is nearly constant on the two orbits `{0,5} mod 6` and `{2,3} mod 6` of `U` mod 54. -/
198theorem L19 (β : ℕ → ℝ) (c : ℝ) (hc : 0 ≤ c)
199 (h : ∀ ρ : ℕ, ρ = 53 ∨ ρ = 23 → ∀ r < 54, |β r - β ((ρ * r + 53) % 54)| ≤ c) :
200 ∀ r < 54, r % 3 ≠ 1 → |β r - β (if r % 6 = 0 ∨ r % 6 = 5 then 0 else 2)| ≤ 36 * c := by
201 have e53 := h 53 (Or.inl rfl)
202 have e23 := h 23 (Or.inr rfl)
203 have h0 : |β 0 - β 0| ≤ 0 * c := by simp
204 have h2 : |β 2 - β 2| ≤ 0 * c := by simp
205 have h53 : |β 53 - β 0| ≤ 1 * c := by
206 have := e53 0 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h0.1, h0.2, this.1, this.2]
207 have h47 : |β 47 - β 0| ≤ 1 * c := by
208 have := e23 47 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h0.1, h0.2, this.1, this.2]
209 have h30 : |β 30 - β 0| ≤ 2 * c := by
210 have := e23 53 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h53.1, h53.2, this.1, this.2]
211 have h6 : |β 6 - β 0| ≤ 2 * c := by
212 have := e53 6 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h47.1, h47.2, this.1, this.2]
213 have h42 : |β 42 - β 0| ≤ 2 * c := by
214 have := e23 42 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h47.1, h47.2, this.1, this.2]
215 have h23 : |β 23 - β 0| ≤ 3 * c := by
216 have := e53 23 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h30.1, h30.2, this.1, this.2]
217 have h41 : |β 41 - β 0| ≤ 3 * c := by
218 have := e23 30 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h30.1, h30.2, this.1, this.2]
219 have h5 : |β 5 - β 0| ≤ 3 * c := by
220 have := e23 5 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h6.1, h6.2, this.1, this.2]
221 have h29 : |β 29 - β 0| ≤ 3 * c := by
222 have := e23 6 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h6.1, h6.2, this.1, this.2]
223 have h11 : |β 11 - β 0| ≤ 3 * c := by
224 have := e53 11 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h42.1, h42.2, this.1, this.2]
225 have h48 : |β 48 - β 0| ≤ 4 * c := by
226 have := e23 48 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h23.1, h23.2, this.1, this.2]
227 have h12 : |β 12 - β 0| ≤ 4 * c := by
228 have := e53 12 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h41.1, h41.2, this.1, this.2]
229 have h24 : |β 24 - β 0| ≤ 4 * c := by
230 have := e23 41 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h41.1, h41.2, this.1, this.2]
231 have h18 : |β 18 - β 0| ≤ 4 * c := by
232 have := e23 29 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h29.1, h29.2, this.1, this.2]
233 have h36 : |β 36 - β 0| ≤ 4 * c := by
234 have := e23 11 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h11.1, h11.2, this.1, this.2]
235 have h35 : |β 35 - β 0| ≤ 5 * c := by
236 have := e23 35 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h48.1, h48.2, this.1, this.2]
237 have h17 : |β 17 - β 0| ≤ 5 * c := by
238 have := e23 17 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h12.1, h12.2, this.1, this.2]
239 have h51 : |β 51 - β 2| ≤ 1 * c := by
240 have := e53 2 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h2.1, h2.2, this.1, this.2]
241 have h45 : |β 45 - β 2| ≤ 1 * c := by
242 have := e23 2 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h2.1, h2.2, this.1, this.2]
243 have h33 : |β 33 - β 2| ≤ 1 * c := by
244 have := e23 33 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h2.1, h2.2, this.1, this.2]
245 have h14 : |β 14 - β 2| ≤ 2 * c := by
246 have := e23 14 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h51.1, h51.2, this.1, this.2]
247 have h38 : |β 38 - β 2| ≤ 2 * c := by
248 have := e23 51 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h51.1, h51.2, this.1, this.2]
249 have h8 : |β 8 - β 2| ≤ 2 * c := by
250 have := e53 8 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h45.1, h45.2, this.1, this.2]
251 have h20 : |β 20 - β 2| ≤ 2 * c := by
252 have := e53 20 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h33.1, h33.2, this.1, this.2]
253 have h32 : |β 32 - β 2| ≤ 2 * c := by
254 have := e23 32 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h33.1, h33.2, this.1, this.2]
255 have h3 : |β 3 - β 2| ≤ 3 * c := by
256 have := e23 3 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h14.1, h14.2, this.1, this.2]
257 have h39 : |β 39 - β 2| ≤ 3 * c := by
258 have := e53 14 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h14.1, h14.2, this.1, this.2]
259 have h15 : |β 15 - β 2| ≤ 3 * c := by
260 have := e53 15 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h38.1, h38.2, this.1, this.2]
261 have h9 : |β 9 - β 2| ≤ 3 * c := by
262 have := e23 38 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h38.1, h38.2, this.1, this.2]
263 have h21 : |β 21 - β 2| ≤ 3 * c := by
264 have := e23 8 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h8.1, h8.2, this.1, this.2]
265 have h27 : |β 27 - β 2| ≤ 3 * c := by
266 have := e23 20 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h20.1, h20.2, this.1, this.2]
267 have h50 : |β 50 - β 2| ≤ 4 * c := by
268 have := e53 3 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h3.1, h3.2, this.1, this.2]
269 have h26 : |β 26 - β 2| ≤ 4 * c := by
270 have := e23 26 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h3.1, h3.2, this.1, this.2]
271 have h44 : |β 44 - β 2| ≤ 4 * c := by
272 have := e23 44 (by norm_num); norm_num at this; rw [abs_le] at *; constructor <;> linarith [h39.1, h39.2, this.1, this.2]
273 intro r hr hr3
274 interval_cases r <;> first | (exact absurd rfl hr3) | (norm_num; linarith)
275
276/-- The classes mod 54 of `T_s(U) = {s u - 1 : u ∈ U}`. -/
277def Tcl (s : ℕ) : Finset ℕ := (range 54).filter fun c => s ∣ c + 1 ∧ (c + 1) / s % 3 ≠ 1
278
279theorem sum_cl (W : Win) (P : ℕ → Prop) [DecidablePred P] (hP : ∀ n, P n ↔ P (n % 54)) :
280 W.E (fun n => ind (P n) * f n) = ∑ c ∈ range 54 with P c, bcl W c := by
281 have : (fun n => ind (P n) * f n) = fun n => ∑ c ∈ range 54 with P c, ind (n % 54 = c) * f n := by
282 funext n
283 rw [← sum_mul]
284 congr 1
285 have hn : n % 54 ∈ range 54 := mem_range.mpr (Nat.mod_lt _ (by norm_num))
286 by_cases h : P n
287 · rw [ind_true h, sum_eq_single_of_mem (n % 54) (mem_filter.mpr ⟨hn, (hP n).mp h⟩)
288 fun c _ hne => ind_false fun h => hne h.symm]
289 exact (ind_true rfl).symm
290 · rw [ind_false h]
291 refine (sum_eq_zero fun c hc => ind_false fun hcn => h ?_).symm
292 rw [hP, hcn]; exact (mem_filter.mp hc).2
293 rw [this]
294 unfold Win.E bcl Win.E
295 rw [Win.sum_finset_sum, sum_div]
296
297/-- Exact dilation read backwards: `∑_{y ∈ W} G(y)/y` as a sum over multiples of `s` in `sW`. -/
298theorem E_dilate_lower (η : ℝ) (hη : 0 < η) : ∃ N0 : ℝ, ∀ W : Win, W.Adm η N0 → ∀ s : ℕ, 1 ≤ s →
299 (s : ℝ) ≤ 9 → ∀ G : ℕ → ℝ, (∀ n, 0 ≤ G n) → (∀ n, G n ≤ 1) →
300 s * (W.E (fun n => if s ∣ n then G (n / s) else 0) - W.edge) ≤ W.E G := by
301 obtain ⟨N0, hd⟩ := dilate_le_edge η hη
302 obtain ⟨N1, hexp⟩ := const_le_exp 9
303 refine ⟨max N0 N1, fun W hW s hs hs9 G h0 h1 => ?_⟩
304 have hL := hW.len_pos hη
305 have hlo := hW.lo_pos
306 have hs0 : (0 : ℝ) < s := by exact_mod_cast hs
307 have hs1 : (1 : ℝ) ≤ s := by exact_mod_cast hs
308 set W' : Win := ⟨s * W.lo, s * W.hi⟩ with hW'
309 have hdiv : W'.div s = W := by
310 simp only [hW', Win.div]
311 rw [mul_div_cancel_left₀ _ hs0.ne', mul_div_cancel_left₀ _ hs0.ne']
312 have hlo' : 0 < W'.lo := by change 0 < s * W.lo; positivity
313 have hhi' : W'.lo ≤ W'.hi := mul_le_mul_of_nonneg_left hW.lo_lt.le hs0.le
314 have e1 := L17_dilate W' hlo'.le hhi' hs G
315 rw [hdiv] at e1
316 have e2 := L17_div W' hlo' hhi' s hs1 (fun n => if s ∣ n then G (n / s) else 0)
317 (fun n => by split_ifs <;> simp [h0]) (fun n => by split_ifs <;> simp [h1])
318 rw [hdiv, e1] at e2
319 have e3 := hd W (hW.mono (le_max_left _ _)) s hs1
320 (hs9.trans (hexp W.lo ((le_max_right _ _).trans hW.le_lo)))
321 rw [div_le_iff₀ hL] at e3
322 have e4 : (s : ℝ) / W'.lo ≤ s / W.lo := by
323 change (s : ℝ) / (s * W.lo) ≤ _
324 gcongr
325 nlinarith
326 have e5 := (abs_le.mp e2).2
327 have e6 : W.sum (fun n => if s ∣ n then G (n / s) else 0) - W.edge * W.len ≤ W.sum G / s := by linarith
328 rw [le_div_iff₀ hs0] at e6
329 unfold Win.E
330 rw [le_div_iff₀ hL]
331 calc s * (W.sum (fun n => if s ∣ n then G (n / s) else 0) / W.len - W.edge) * W.len
332 = (W.sum (fun n => if s ∣ n then G (n / s) else 0) - W.edge * W.len) * s := by
333 field_simp
334 _ ≤ _ := e6
335
336/-- **Lemma 20.** -/
337theorem L20 (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
338 ∀ s : ℕ, s = 2 ∨ s = 3 ∨ s = 9 → W.mu (Es s) ≤ C * dp W J x := by
339 classical
340 obtain ⟨N1, h18⟩ := L18 K η hη
341 obtain ⟨N2, hdil⟩ := E_dilate_lower η hη
342 refine ⟨72 * 36 * 55 * 3 + 18, by norm_num, max (max N1 N2) (max 9 (4 / η)), fun W J T x hS s hs => ?_⟩
343 have hA := hS.adm
344 have hL := hA.len_pos hη
345 have hlo9 : 9 ≤ W.lo := le_trans (by simp) hA.le_lo
346 have hsm := small_le_edge hη (hA.mono (N' := 4 / η) (by simp)) le_rfl
347 have hedge := edge_pos hA
348 set c := 55 * (x + 2 * W.edge) with hc
349 have hc0 : 0 ≤ c := by have := hS.x_nonneg; positivity
350 have hs1 : 1 ≤ s := by omega
351 have hs9 : (s : ℝ) ≤ 9 := by exact_mod_cast (by omega : s ≤ 9)
352 have hsA : s ∈ A := by rcases hs with rfl | rfl | rfl; exacts [two_mem, three_mem, nine_mem]
353 -- near constancy on the two orbits
354 have hnear := L19 (bcl W) c hc0 fun ρ hρ r hr => (h18 W J T x (hS.mono (by simp)) ρ hρ).2 r hr
355 -- upper bound by the difference of averages
356 set G : ℕ → ℝ := fun y => ind (y ∈ U) * f (s * y - 1) with hG
357 have hG0 : ∀ y, 0 ≤ G y := fun y => mul_nonneg (ind_nonneg _) (f_nonneg _)
358 have hG1 : ∀ y, G y ≤ 1 := fun y => mul_le_one₀ (ind_le_one _) (f_nonneg _) (f_le_one _)
359 have hmu : W.mu (Es s) ≤ W.E f - W.E G := by
360 rw [← Win.E_sub]
361 refine Win.E_mono hL.le fun y hy => ?_
362 have hy9 : (9 : ℝ) < y := hlo9.trans_lt (Win.lo_lt_of_mem_pts hA.lo_pos.le hy)
363 have hne : s ≠ y := fun h => by rw [h] at hs9; linarith
364 by_cases hU : y ∈ U
365 · have h4 := L4 hsA hU hne
366 simp only [hG]
367 rw [ind_true hU, one_mul]
368 by_cases he : f y = f (s * y - 1)
369 · rw [ind_false fun h => h.2 he]; linarith
370 · rw [ind_true (show y ∈ Es s from ⟨hU, he⟩)]
371 rcases f_eq_zero_or_one y with h | h <;> rcases f_eq_zero_or_one (s * y - 1) with h' | h' <;>
372 rw [h, h'] at h4 he ⊢ <;> first | linarith | exact absurd rfl he
373 · simp only [hG]
374 rw [ind_false hU, ind_false fun h => hU h.1, f_eq_zero_of_not_U hU]; simp
375 -- the dilated average in classes
376 set H : ℕ → ℝ := fun n => if s ∣ n then G (n / s) else 0 with hH
377 have hH0 : ∀ n, 0 ≤ H n := fun n => by simp only [hH]; split_ifs <;> simp [hG0]
378 have hH1 : ∀ n, H n ≤ 1 := fun n => by simp only [hH]; split_ifs <;> simp [hG1]
379 have hlow := hdil W (hA.mono (by simp)) s hs1 hs9 G hG0 hG1
380 have hsh := E_shift_le hη hA 1 H 1 fun n => by rw [abs_of_nonneg (hH0 n)]; exact hH1 n
381 have hcl : W.E (fun n => H (n + 1)) = ∑ a ∈ Tcl s, bcl W a := by
382 unfold Tcl
383 rw [← sum_cl W (fun n => s ∣ n + 1 ∧ (n + 1) / s % 3 ≠ 1) (fun n => by
384 rcases hs with rfl | rfl | rfl <;> omega)]
385 congr 1
386 funext n
387 simp only [hH, hG]
388 by_cases hd : s ∣ n + 1
389 · rw [if_pos hd]
390 obtain ⟨y, hy⟩ := hd
391 have hy1 : 1 ≤ y := Nat.pos_of_ne_zero fun h => by rw [h] at hy; omega
392 rw [hy, Nat.mul_div_cancel_left y hs1, show s * y - 1 = n by omega]
393 congr 1
394 refine ind_congr ⟨fun h => ⟨dvd_mul_right s y, h.2⟩, fun h => ⟨hy1, h.2⟩⟩
395 · rw [if_neg hd, ind_false fun h => hd h.1, zero_mul]
396 rw [hcl] at hsh
397 have hsh' := (abs_le.mp hsh).2
398 -- total average in classes
399 have hf : W.E f = ∑ a ∈ range 54 with a % 3 ≠ 1, bcl W a := by
400 rw [← sum_cl W (fun n => n % 3 ≠ 1) (fun n => by omega)]
401 congr 1; funext n
402 by_cases h : n % 3 ≠ 1
403 · rw [ind_true h, one_mul]
404 · rw [ind_false h, zero_mul, f_eq_zero_of_not_U fun hU => h hU.2]
405 set b : ℕ → ℝ := fun a => bcl W (if a % 6 = 0 ∨ a % 6 = 5 then 0 else 2) with hb
406 have hup : W.E f ≤ 18 * bcl W 0 + 18 * bcl W 2 + 36 * (36 * c) := by
407 have h1 : ∑ a ∈ range 54 with a % 3 ≠ 1, bcl W a ≤
408 ∑ a ∈ range 54 with a % 3 ≠ 1, (b a + 36 * c) := sum_le_sum fun a ha => by
409 rw [mem_filter, mem_range] at ha
410 linarith [(abs_le.mp (hnear a ha.1 ha.2)).2]
411 rw [hf]
412 refine h1.trans (le_of_eq ?_)
413 simp only [sum_filter, sum_range_succ, range_zero, sum_empty, hb]
414 norm_num
415 ring
416 have hdown : 18 * bcl W 0 + 18 * bcl W 2 - 36 * (36 * c) ≤ s * ∑ a ∈ Tcl s, bcl W a := by
417 have h1 : ∑ a ∈ Tcl s, (b a - 36 * c) ≤ ∑ a ∈ Tcl s, bcl W a := sum_le_sum fun a ha => by
418 rw [Tcl, mem_filter, mem_range] at ha
419 have h3 : a % 3 ≠ 1 := by rcases hs with rfl | rfl | rfl <;> omega
420 linarith [(abs_le.mp (hnear a ha.1 h3)).1]
421 have h2 : (s : ℝ) * ∑ a ∈ Tcl s, (b a - 36 * c) = 18 * bcl W 0 + 18 * bcl W 2 - 36 * (36 * c) := by
422 rcases hs with rfl | rfl | rfl
423 all_goals
424 simp only [Tcl, sum_filter, sum_range_succ, range_zero, sum_empty, hb]
425 norm_num
426 ring
427 rw [← h2]
428 exact mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _)
429 -- conclusion
430 have hdpx : c ≤ 55 * 3 * dp W J x := by
431 have h1 : (0 : ℝ) ≤ 1 / (J : ℝ) ^ 2 := by positivity
432 have h2 := hS.x_nonneg
433 rw [hc]; unfold dp; linarith
434 have hed := hS.edge_le_dp
435 have h1e : s * (∑ a ∈ Tcl s, bcl W a - 2 * W.edge) ≤ W.E G := by
436 refine le_trans (mul_le_mul_of_nonneg_left ?_ (Nat.cast_nonneg _)) hlow
437 push_cast at hsh'
438 linarith
439 have hs18 : (s : ℝ) * (2 * W.edge) ≤ 18 * W.edge := by nlinarith
440 have h1e' : s * ∑ a ∈ Tcl s, bcl W a - 18 * W.edge ≤ W.E G := by
441 have : s * (∑ a ∈ Tcl s, bcl W a - 2 * W.edge) = s * ∑ a ∈ Tcl s, bcl W a - s * (2 * W.edge) := by ring
442 linarith
443 linarith
444
445/-- `G1 ⊂ {3n ∈ E_3} ∪ E_9`, `G3 = {3n ∈ G1}`, `G2 ⊂ {9n ∈ E_2} ∪ {6n ∈ E_3} ∪ G3`. -/
446theorem G_subsets {n : ℕ} (hn : 1 ≤ n) :
447 (n ∈ G1 → 3 * n ∈ Es 3 ∨ n ∈ Es 9) ∧ (n ∈ G3 → 3 * n ∈ G1) ∧
448 (n ∈ G2 → (9 * n ∈ Es 2 ∨ 6 * n ∈ Es 3) ∨ n ∈ G3) := by
449 have hU : ∀ m : ℕ, 1 ≤ m → m % 3 = 0 → m ∈ U := fun m h1 h3 => ⟨h1, by omega⟩
450 refine ⟨fun ⟨hnU, hne⟩ => ?_, fun h => ⟨hU _ (by omega) (by omega), h⟩, fun h => ?_⟩
451 · by_contra hcon
452 rw [not_or] at hcon
453 have h1 : f (3 * n) = f (3 * (3 * n) - 1) := by
454 by_contra h; exact hcon.1 ⟨hU _ (by omega) (by omega), h⟩
455 have h2 : f n = f (9 * n - 1) := by
456 by_contra h; exact hcon.2 ⟨hnU, h⟩
457 refine hne ?_
458 unfold F
459 rw [h1, h2, show 3 * (3 * n) - 1 = 9 * n - 1 by omega]
460 · by_contra hcon
461 rw [not_or, not_or] at hcon
462 have h1 : f (9 * n) = f (2 * (9 * n) - 1) := by
463 by_contra h; exact hcon.1.1 ⟨hU _ (by omega) (by omega), h⟩
464 have h2 : f (6 * n) = f (3 * (6 * n) - 1) := by
465 by_contra h; exact hcon.1.2 ⟨hU _ (by omega) (by omega), h⟩
466 have h3 : F (3 * n) = F n := by
467 by_contra h; exact hcon.2 h
468 refine h ?_
469 rw [← h3]
470 unfold F
471 rw [show 3 * (2 * n) = 6 * n by omega, show 3 * (3 * n) = 9 * n by omega, h1, h2,
472 show 3 * (6 * n) - 1 = 2 * (9 * n) - 1 by omega]
473
474/-- **Lemma 21.** -/
475theorem L21 (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
476 W.mu G1 ≤ C * dp W J x ∧ W.mu G2 ≤ C * dp W J x ∧ W.mu G3 ≤ C * dp W J x := by
477 obtain ⟨C, hC, N1, h20⟩ := L20 K η hη
478 obtain ⟨N2, hmul⟩ := mu_mul_le η hη
479 obtain ⟨N3, hexp⟩ := const_le_exp 9
480 refine ⟨40 * (C + 1), by positivity, max N1 (max N2 N3), fun W J T x hS => ?_⟩
481 have hd := hS.dp_pos
482 have hed := hS.edge_le_dp
483 have hL := hS.adm.len_pos hη
484 have hlo := hS.adm.lo_pos
485 have h9 := hexp W.lo ((le_max_right _ _).trans ((le_max_right _ _).trans hS.adm.le_lo))
486 have hA2 : W.Adm η N2 := hS.adm.mono (by simp)
487 have hE := h20 W J T x (hS.mono (by simp))
488 have e2 := hE 2 (by simp)
489 have e3 := hE 3 (by simp)
490 have e9 := hE 9 (by simp)
491 have m3 := fun S => hmul W hA2 3 (by norm_num) (le_trans (by norm_num) h9) S
492 have m6 := fun S => hmul W hA2 6 (by norm_num) (le_trans (by norm_num) h9) S
493 have m9 := fun S => hmul W hA2 9 (by norm_num) (le_trans (by norm_num) h9) S
494 push_cast at m3 m6 m9
495 have hn1 : ∀ n ∈ W.pts, 1 ≤ n := fun n hn => by
496 have := Win.lo_lt_of_mem_pts hlo.le hn
497 have : (0 : ℝ) < n := by linarith
498 exact_mod_cast this
499 have hG1 : W.mu G1 ≤ W.E (fun n => ind (3 * n ∈ Es 3)) + W.mu (Es 9) := by
500 unfold Win.mu; rw [← Win.E_add]
501 exact Win.E_mono hL.le fun n hn => (ind_mono (G_subsets (hn1 n hn)).1).trans (ind_or_le _ _)
502 have hG3 : W.mu G3 ≤ W.E (fun n => ind (3 * n ∈ G1)) :=
503 Win.E_mono hL.le fun n hn => ind_mono (G_subsets (hn1 n hn)).2.1
504 have hG2 : W.mu G2 ≤ W.E (fun n => ind (9 * n ∈ Es 2)) + W.E (fun n => ind (6 * n ∈ Es 3)) + W.mu G3 := by
505 unfold Win.mu; rw [← Win.E_add, ← Win.E_add]
506 refine Win.E_mono hL.le fun n hn => (ind_mono (G_subsets (hn1 n hn)).2.2).trans ?_
507 refine (ind_or_le _ _).trans ?_
508 linarith [ind_or_le (9 * n ∈ Es 2) (6 * n ∈ Es 3)]
509 have k1 := m3 (Es 3)
510 have k2 := m3 G1
511 have k3 := m9 (Es 2)
512 have k4 := m6 (Es 3)
513 have hCd : 0 ≤ C * dp W J x := by positivity
514 have r : 40 * (C + 1) * dp W J x = 40 * (C * dp W J x) + 40 * dp W J x := by ring
515 rw [r]
516 refine ⟨by linarith, by linarith, by linarith⟩
517
518/-- The defect sum `g(m) = ∑_{s ∣ m} (f(m/s) - f(m-1))` sampled at `m = 9n`. -/
519theorem defect_nine (η : ℝ) (hη : 0 < η) : ∃ N0 : ℝ, ∀ W : Win, W.Adm η N0 → ∀ T : Finset ℕ,
520 (∀ s ∈ T, s ∈ A ∧ s % 3 = 2 ∧ (s : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo))) →
521 W.E (fun n => ∑ s ∈ T with s ∣ n, (f (9 * (n / s)) - f (9 * n - 1))) ≤
522 9 * W.E (fun n => ∑ s ∈ T with s ∣ n, (f (n / s) - f (n - 1))) + 9 * (ms T * W.edge) := by
523 obtain ⟨N1, hd⟩ := dilate_le_edge η hη
524 obtain ⟨N2, hexp⟩ := const_le_exp (Real.exp 4)
525 obtain ⟨N3, hsq⟩ := exp_sq_lt
526 refine ⟨max N1 (max N2 N3), fun W hW T hT => ?_⟩
527 have hL := hW.len_pos hη
528 have hlo := hW.lo_pos
529 have hhi := hW.hi_pos
530 have hlt := hW.lo_lt
531 set E := Real.exp (Real.sqrt (Real.log W.lo)) with hE
532 have hE2 : E ^ 2 < W.lo := hsq W.lo (le_trans (by simp) hW.le_lo)
533 have hE1 : 1 ≤ E := Real.one_le_exp (Real.sqrt_nonneg _)
534 have hElo : E ≤ W.lo := by nlinarith
535 have h4 := hd W (hW.mono (by simp)) (Real.exp 4) (Real.one_le_exp (by norm_num))
536 (hexp W.lo (le_trans (by simp) hW.le_lo))
537 rw [Real.log_exp, div_le_iff₀ hL] at h4
538 have h4' : 4 ≤ W.edge * W.len := by
539 have : 0 ≤ Real.exp 4 / W.lo := by positivity
540 linarith
541 set g : ℕ → ℝ := fun m => ∑ s ∈ T with s ∣ m, (f (m / s) - f (m - 1)) with hg
542 have hs1 : ∀ s ∈ T, 1 ≤ s := fun s hs => by have := (hT s hs).2.1; omega
543 -- nonnegativity of the summands above `lo`
544 have hnn : ∀ m : ℕ, W.lo < m → ∀ s ∈ T, s ∣ m → 0 ≤ f (m / s) - f (m - 1) := by
545 intro m hm s hs hsm
546 have hmem := hT s hs
547 have hm1 : 1 ≤ m := by
548 have : (0 : ℝ) < m := hlo.trans hm
549 exact_mod_cast this
550 refine defect_nonneg hmem.1 hmem.2.1 hm1 hsm fun h => ?_
551 have h2 : (m : ℝ) ≤ E ^ 2 := by
552 rw [← h]; push_cast; rw [sq]
553 exact mul_le_mul hmem.2.2 hmem.2.2 (Nat.cast_nonneg _) (Real.exp_pos _).le
554 linarith
555 have hgnn : ∀ m : ℕ, W.lo < m → 0 ≤ g m := fun m hm => sum_nonneg fun s hs => by
556 rw [mem_filter] at hs; exact hnn m hm s hs.1 hs.2
557 have hgrc : ∀ m, g m ≤ rc T m := fun m => by
558 simp only [hg]
559 rw [rc_eq_sum']
560 exact sum_le_sum fun s _ => by linarith [f_le_one (m / s), f_nonneg (m - 1)]
561 -- pointwise
562 have hpt : W.sum (fun n => ∑ s ∈ T with s ∣ n, (f (9 * (n / s)) - f (9 * n - 1))) ≤
563 W.sum (fun n => g (9 * n)) := by
564 refine Win.sum_mono fun n hn => ?_
565 have hn0 := Win.lo_lt_of_mem_pts hlo.le hn
566 have hn9 : W.lo < ((9 * n : ℕ) : ℝ) := by push_cast; linarith
567 simp only [hg]
568 have hsub : T.filter (· ∣ n) ⊆ T.filter (· ∣ 9 * n) := fun s hs => by
569 rw [mem_filter] at *; exact ⟨hs.1, hs.2.mul_left 9⟩
570 refine le_trans (le_of_eq ?_) (sum_le_sum_of_subset_of_nonneg hsub fun s hs _ => ?_)
571 · refine sum_congr rfl fun s hs => ?_
572 rw [mem_filter] at hs
573 rw [Nat.mul_div_assoc 9 hs.2]
574 · rw [mem_filter] at hs; exact hnn _ hn9 s hs.1 hs.2
575 -- dilation by 9
576 set W9 : Win := ⟨9 * W.lo, 9 * W.hi⟩ with hW9
577 have hdiv : W9.div (9 : ℕ) = W := by
578 simp only [hW9, Win.div]; push_cast
579 rw [mul_div_cancel_left₀ _ (by norm_num), mul_div_cancel_left₀ _ (by norm_num)]
580 have e1 := L17_dilate W9 (by change 0 ≤ 9 * W.lo; positivity)
581 (by change 9 * W.lo ≤ 9 * W.hi; linarith) (s := 9) (by norm_num) fun n => g (9 * n)
582 rw [hdiv] at e1
583 have e2 : W.sum (fun n => g (9 * n)) ≤ 9 * W9.sum g := by
584 have : W9.sum (fun n => if 9 ∣ n then g (9 * (n / 9)) else 0) ≤ W9.sum g := by
585 refine Win.sum_mono fun n hn => ?_
586 have h9n : W9.lo < n := Win.lo_lt_of_mem_pts (by change 0 ≤ 9 * W.lo; positivity) hn
587 change 9 * W.lo < n at h9n
588 split_ifs with h
589 · rw [Nat.mul_div_cancel' h]
590 · exact hgnn n (by linarith)
591 rw [e1] at this
592 push_cast at this
593 linarith
594 -- concatenation
595 have e3 : W9.sum g ≤ W.sum g + (Win.mk W.hi (9 * W.hi)).sum (rc T) := by
596 have h1 := Win.sum_concat (g := g) (show W.lo ≤ W.hi from hlt.le) (show W.hi ≤ 9 * W.hi by linarith)
597 have h2 : W9.sum g ≤ (Win.mk W.lo (9 * W.hi)).sum g := by
598 unfold Win.sum Win.pts
599 refine sum_le_sum_of_subset_of_nonneg
600 (Ioc_subset_Ioc_left (Nat.floor_mono (by change W.lo ≤ 9 * W.lo; linarith))) fun n hn _ => ?_
601 rw [mem_Ioc, Nat.floor_lt hlo.le] at hn
602 exact div_nonneg (hgnn n hn.1) (Nat.cast_nonneg _)
603 have h3 : (Win.mk W.hi (9 * W.hi)).sum g ≤ (Win.mk W.hi (9 * W.hi)).sum (rc T) :=
604 Win.sum_mono fun n _ => hgrc n
605 have h4 : (Win.mk W.lo W.hi).sum g = W.sum g := rfl
606 linarith
607 have e4 : (Win.mk W.hi (9 * W.hi)).sum (rc T) ≤ ms T * 4 := by
608 have h1 : (Win.mk W.hi (9 * W.hi)).sum (rc T) =
609 ∑ s ∈ T, ((Win.mk W.hi (9 * W.hi)).div s).sum (fun _ => 1) / s := by
610 rw [← L17_family (Win.mk W.hi (9 * W.hi)) hhi.le (by change W.hi ≤ 9 * W.hi; linarith) T hs1
611 fun _ _ => 1]
612 exact Win.sum_congr fun n _ => rc_eq_sum' T n
613 rw [h1, ms, sum_mul]
614 refine sum_le_sum fun s hs => ?_
615 have hs0 : (0 : ℝ) < s := by exact_mod_cast hs1 s hs
616 have hsle : (s : ℝ) ≤ W.hi := ((hT s hs).2.2.trans hElo).trans hlt.le
617 have h2 := (abs_le.mp (sum_one_le ((Win.mk W.hi (9 * W.hi)).div s)
618 (by simp only [Win.div]; positivity)
619 (by simp only [Win.div]; gcongr; linarith))).2
620 rw [Win.len_div hs0.ne'] at h2
621 have h3 : (Win.mk W.hi (9 * W.hi)).len = Real.log 9 := by
622 simp only [Win.len]; rw [mul_div_cancel_right₀ _ hhi.ne']
623 have h5 : Real.log 9 ≤ 3 := by
624 rw [Real.log_le_iff_le_exp (by norm_num)]
625 have : (2.7 : ℝ) ≤ Real.exp 1 := by linarith [Real.exp_one_gt_d9]
626 calc (9 : ℝ) ≤ 2.7 ^ 3 := by norm_num
627 _ ≤ Real.exp 1 ^ 3 := by gcongr
628 _ = Real.exp 3 := by rw [← Real.exp_nat_mul]; norm_num
629 have h6 : 1 / ((Win.mk W.hi (9 * W.hi)).div s).lo ≤ 1 := by
630 simp only [Win.div]
631 rw [one_div_div, div_le_one hhi]; exact hsle
632 rw [div_eq_mul_inv, mul_comm, one_div]
633 refine mul_le_mul_of_nonneg_left ?_ (by positivity)
634 linarith
635 have hfin : W.sum (fun n => ∑ s ∈ T with s ∣ n, (f (9 * (n / s)) - f (9 * n - 1))) ≤
636 9 * W.sum g + 9 * (ms T * W.edge) * W.len := by
637 have := mul_le_mul_of_nonneg_left h4' (ms_nonneg T)
638 nlinarith
639 unfold Win.E
640 rw [div_le_iff₀ hL]
641 refine hfin.trans (le_of_eq ?_)
642 field_simp
643
644/-- Chain of Lemma 22: for `n = s z`, `s ≡ 2 mod 3`, `F(n) ≠ F(z)` only if `3n ∈ E_3`, or `(s, 9n)` is a
645defect pair, or `z ∈ G3`. -/
646theorem bad_le {s n : ℕ} (hn : 1 ≤ n) (hdef : 0 ≤ f (9 * (n / s)) - f (9 * n - 1)) :
647 ind (F n ≠ F (n / s)) ≤
648 ind (3 * n ∈ Es 3) + (f (9 * (n / s)) - f (9 * n - 1)) + ind (n / s ∈ G3) := by
649 by_cases h1 : 3 * n ∈ Es 3
650 · rw [ind_true h1]
651 linarith [ind_le_one (F n ≠ F (n / s)), ind_nonneg (n / s ∈ G3)]
652 by_cases h3 : n / s ∈ G3
653 · rw [ind_true h3]
654 linarith [ind_le_one (F n ≠ F (n / s)), ind_nonneg (3 * n ∈ Es 3)]
655 rw [ind_false h1, ind_false h3]
656 have e1 : F n = f (9 * n - 1) := by
657 by_contra h
658 refine h1 ⟨⟨by omega, by omega⟩, ?_⟩
659 rw [show 3 * (3 * n) - 1 = 9 * n - 1 by omega]
660 exact h
661 have e2 : F (n / s) = f (9 * (n / s)) := by
662 have : F (3 * (n / s)) = F (n / s) := by by_contra h; exact h3 h
663 rw [← this]; unfold F
664 rw [show 3 * (3 * (n / s)) = 9 * (n / s) by ring]
665 rw [e1, e2]
666 rcases f_eq_zero_or_one (9 * (n / s)) with h | h <;> rcases f_eq_zero_or_one (9 * n - 1) with h' | h' <;>
667 first | (rw [h, h'] at hdef; linarith) | simp [ind, h, h']
668
669/-- Consequences of `RigHyp` used repeatedly. -/
670theorem RigHyp.ms_pos {K : ℝ} {W : Win} {J ρ : ℕ} {T : Finset ℕ} (h : RigHyp K W J ρ T) (hJ : 3 ≤ J) :
671 0 < ms T := by
672 have hJ0 : (0 : ℝ) < J := by positivity
673 rcases (ms_nonneg T).lt_or_eq with h1 | h1
674 · exact h1
675 · exfalso; have := h.le_ms; rw [← h1] at this; linarith
676
677theorem RigHyp.K_pos {K : ℝ} {W : Win} {J ρ : ℕ} {T : Finset ℕ} (h : RigHyp K W J ρ T) (hJ : 3 ≤ J) :
678 0 < K := by
679 have hJ0 : (0 : ℝ) < J := by positivity
680 have := h.le_ms
681 have := h.ms_pos hJ
682 by_contra hK
683 nlinarith
684
685/-- `J² / M^4 ≤ K^4 / J²`. -/
686theorem RigHyp.ratio {K : ℝ} {W : Win} {J ρ : ℕ} {T : Finset ℕ} (h : RigHyp K W J ρ T) (hJ : 3 ≤ J) :
687 (J : ℝ) ^ 2 / ms T ^ 4 ≤ K ^ 4 * (1 / (J : ℝ) ^ 2) := by
688 have hJ0 : (0 : ℝ) < J := by positivity
689 have hM := h.ms_pos hJ
690 have h4 : (J : ℝ) ^ 4 ≤ (K * ms T) ^ 4 := pow_le_pow_left₀ hJ0.le h.le_ms 4
691 rw [mul_one_div, div_le_div_iff₀ (by positivity) (by positivity)]
692 calc (J : ℝ) ^ 2 * (J : ℝ) ^ 2 = (J : ℝ) ^ 4 := by ring
693 _ ≤ (K * ms T) ^ 4 := h4
694 _ = _ := by ring
695
696/-- **Lemma 22.** -/
697theorem L22 (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
698 ∀ ρ : ℕ, ρ = 53 ∨ ρ = 23 → W.E (badCount (T ρ)) / ms (T ρ) ≤ C * dp W J x := by
699 obtain ⟨N1, h18⟩ := L18 K η hη
700 obtain ⟨C20, hC20, N2, h20⟩ := L20 K η hη
701 obtain ⟨C21, hC21, N3, h21⟩ := L21 K η hη
702 obtain ⟨N4, h9⟩ := defect_nine η hη
703 obtain ⟨N5, hfam⟩ := E_family_le η hη
704 obtain ⟨N6, hmul⟩ := mu_mul_le η hη
705 obtain ⟨N7, hexp⟩ := const_le_exp 3
706 obtain ⟨N8, hsq⟩ := exp_sq_lt
707 refine ⟨6 * (C20 + 1) + 2 * |K| ^ 5 + 2 + 9 * 54 * 3 + 9 + C21 + 1, by positivity,
708 max (max (max N1 N2) (max N3 N4)) (max (max N5 N6) (max N7 N8)), fun W J T x hS ρ hρ => ?_⟩
709 have hA := hS.adm
710 have hL := hA.len_pos hη
711 have hR := hS.rig ρ hρ
712 have hM := hR.ms_pos hS.three_le
713 have hK := hR.K_pos hS.three_le
714 have hratio := hR.ratio hS.three_le
715 set M := ms (T ρ) with hMdef
716 have hsqlt := hsq W.lo (le_trans (by simp) hA.le_lo)
717 have hρ3 : ∀ s ∈ T ρ, s ∈ A ∧ s % 3 = 2 ∧ (s : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo)) :=
718 fun s hs => ⟨(hR.mem s hs).1, by have := (hR.mem s hs).2.1; omega, (hR.mem s hs).2.2⟩
719 -- the pointwise bound
720 have hpt : W.E (badCount (T ρ)) ≤
721 W.E (fun n => (2 * M * ind (3 * n ∈ Es 3) + 2 / M ^ 3 * (rc (T ρ) n - M) ^ 4) +
722 ∑ s ∈ T ρ with s ∣ n, (f (9 * (n / s)) - f (9 * n - 1)) +
723 ∑ s ∈ T ρ with s ∣ n, ind (n / s ∈ G3)) := by
724 refine Win.E_mono hL.le fun n hn => ?_
725 have hn1 := one_le_of_mem_pts hA hn
726 have hnlo := Win.lo_lt_of_mem_pts hA.lo_pos.le hn
727 have h1 : badCount (T ρ) n ≤ ∑ s ∈ T ρ with s ∣ n,
728 (ind (3 * n ∈ Es 3) + (f (9 * (n / s)) - f (9 * n - 1)) + ind (n / s ∈ G3)) := by
729 refine sum_le_sum fun s hs => ?_
730 rw [mem_filter] at hs
731 have hmem := hρ3 s hs.1
732 refine bad_le hn1 ?_
733 have h9 : 9 * (n / s) = 9 * n / s := (Nat.mul_div_assoc 9 hs.2).symm
734 rw [h9]
735 refine defect_nonneg hmem.1 hmem.2.1 (by omega) (hs.2.mul_left 9) fun h => ?_
736 have h2 : ((9 * n : ℕ) : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo)) ^ 2 := by
737 rw [← h]; push_cast; rw [sq]
738 exact mul_le_mul hmem.2.2 hmem.2.2 (Nat.cast_nonneg _) (Real.exp_pos _).le
739 push_cast at h2
740 linarith [hA.lo_pos]
741 refine h1.trans ?_
742 rw [sum_add_distrib, sum_add_distrib]
743 have h2 : ∑ s ∈ T ρ with s ∣ n, ind (3 * n ∈ Es 3) = rc (T ρ) n * ind (3 * n ∈ Es 3) := by
744 rw [sum_const, nsmul_eq_mul]; rfl
745 rw [h2]
746 have h3 : rc (T ρ) n * ind (3 * n ∈ Es 3) ≤
747 2 * M * ind (3 * n ∈ Es 3) + 2 / M ^ 3 * (rc (T ρ) n - M) ^ 4 := by
748 have hr0 := rc_nonneg (T ρ) n
749 have hi0 := ind_nonneg (3 * n ∈ Es 3)
750 have hi1 := ind_le_one (3 * n ∈ Es 3)
751 rcases le_or_gt (rc (T ρ) n) (2 * M) with h | h
752 · have : 0 ≤ 2 / M ^ 3 * (rc (T ρ) n - M) ^ 4 := by positivity
753 nlinarith
754 · set u := rc (T ρ) n - M with hu
755 have hu1 : M ≤ u := by linarith
756 have h4 : u ≤ 1 / M ^ 3 * u ^ 4 := by
757 rw [one_div, inv_mul_eq_div, le_div_iff₀ (by positivity)]
758 have : M ^ 3 ≤ u ^ 3 := pow_le_pow_left₀ hM.le hu1 3
759 nlinarith
760 have h5 : 2 / M ^ 3 * u ^ 4 = 2 * (1 / M ^ 3 * u ^ 4) := by ring
761 have h6 : rc (T ρ) n * ind (3 * n ∈ Es 3) ≤ rc (T ρ) n := mul_le_of_le_one_right hr0 hi1
762 have : 0 ≤ 2 * M * ind (3 * n ∈ Es 3) := by positivity
763 linarith
764 linarith
765 rw [Win.E_add, Win.E_add, Win.E_add, Win.E_const_mul, Win.E_const_mul] at hpt
766 have b1 := hmul W (hA.mono (by simp)) 3 (by norm_num)
767 (by exact_mod_cast hexp W.lo (le_trans (by simp) hA.le_lo)) (Es 3)
768 have b2 := h20 W J T x (hS.mono (by simp)) 3 (by simp)
769 have b3 := hR.m4
770 have b4 := h9 W (hA.mono (by simp)) (T ρ) hρ3
771 have b5 := (h18 W J T x (hS.mono (by simp)) ρ hρ).1
772 rw [div_le_iff₀ hM] at b5
773 have b6 := (abs_le.mp (hfam W (hA.mono (by simp)) (T ρ)
774 (fun s hs => ⟨by have := (hρ3 s hs).2.1; omega, (hρ3 s hs).2.2⟩) (fun z => ind (z ∈ G3))
775 (fun _ => ind_nonneg _) fun _ => ind_le_one _)).2
776 have b7 := (h21 W J T x (hS.mono (by simp))).2.2
777 have hd := hS.dp_pos
778 have hed := hS.edge_le_dp
779 have hx0 := hS.x_nonneg
780 have hedge := edge_pos hA
781 have hJ2 : 1 / (J : ℝ) ^ 2 ≤ dp W J x := by unfold dp; linarith
782 have hxd : x + 2 * W.edge ≤ 3 * dp W J x := by
783 have : (0 : ℝ) ≤ 1 / (J : ℝ) ^ 2 := by positivity
784 unfold dp; linarith
785 set d := dp W J x with hddef
786 -- assemble, dividing by `M`
787 rw [div_le_iff₀ hM]
788 have t1 : 2 * M * W.E (fun n => ind (3 * n ∈ Es 3)) ≤ 6 * (C20 + 1) * d * M := by
789 push_cast at b1
790 have : W.E (fun n => ind (3 * n ∈ Es 3)) ≤ 3 * (C20 + 1) * d := by nlinarith
791 nlinarith
792 have t2 : 2 / M ^ 3 * W.E (fun n => (rc (T ρ) n - M) ^ 4) ≤ 2 * |K| ^ 5 * d * M := by
793 rw [abs_of_pos hK]
794 calc 2 / M ^ 3 * W.E (fun n => (rc (T ρ) n - M) ^ 4) ≤ 2 / M ^ 3 * (K * (J : ℝ) ^ 2) := by
795 gcongr
796 _ = 2 * K * M * ((J : ℝ) ^ 2 / M ^ 4) := by field_simp
797 _ ≤ 2 * K * M * (K ^ 4 * d) := by
798 gcongr
799 exact hratio.trans (by gcongr)
800 _ = _ := by ring
801 have t3 : W.E (fun n => ∑ s ∈ T ρ with s ∣ n, (f (9 * (n / s)) - f (9 * n - 1))) ≤
802 (9 * 54 * 3 + 9) * d * M := by
803 have h1 : 54 * (x + 2 * W.edge) * M ≤ 54 * 3 * d * M := by nlinarith
804 have h2 : M * W.edge ≤ M * d := by gcongr
805 linarith
806 have t4 : W.E (fun n => ∑ s ∈ T ρ with s ∣ n, ind (n / s ∈ G3)) ≤ (C21 + 1) * d * M := by
807 have h1 : M * W.E (fun z => ind (z ∈ G3)) ≤ M * (C21 * d) := by
808 have : W.E (fun z => ind (z ∈ G3)) ≤ C21 * d := b7
809 gcongr
810 have h2 : M * W.edge ≤ M * d := by gcongr
811 linarith
812 have hdM : 0 ≤ d * M := by positivity
813 linarith
814
815/-- **Lemma 23**, the classes `n ≢ 2 mod 3`: `F(n) = F(n-1)` off a small set. -/
816theorem L23_aux (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
817 W.E (fun n => ind (n % 3 ≠ 2 ∧ F n ≠ F (n - 1))) ≤ C * dp W J x := by
818 obtain ⟨N1, h18⟩ := L18 K η hη
819 obtain ⟨C21, hC21, N3, h21⟩ := L21 K η hη
820 obtain ⟨C22, hC22, N4, h22⟩ := L22 K η hη
821 obtain ⟨N5, hfam⟩ := E_family_le η hη
822 obtain ⟨N8, hsq⟩ := exp_sq_lt
823 refine ⟨C21 + 1 + 16 * |K| ^ 5 + 2 * (54 * 3) + 2 * (C21 + 1) + 2 * C22, by positivity,
824 max (max N1 N3) (max (max N4 N5) (max N8 (4 / η))), fun W J T x hS => ?_⟩
825 have hA := hS.adm
826 have hL := hA.len_pos hη
827 have hR := hS.rig 53 (Or.inl rfl)
828 have hM := hR.ms_pos hS.three_le
829 have hK := hR.K_pos hS.three_le
830 have hratio := hR.ratio hS.three_le
831 have hsm := small_le_edge hη (hA.mono (N' := 4 / η) (by simp)) le_rfl
832 set M := ms (T 53) with hMdef
833 have hsqlt := hsq W.lo (le_trans (by simp) hA.le_lo)
834 have hρ3 : ∀ s ∈ T 53, s ∈ A ∧ s % 3 = 2 ∧ (s : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo)) :=
835 fun s hs => ⟨(hR.mem s hs).1, by have := (hR.mem s hs).2.1; omega, (hR.mem s hs).2.2⟩
836 have hpt : W.E (fun n => ind (n % 3 ≠ 2 ∧ F n ≠ F (n - 1))) ≤
837 W.E (fun n => (ind (n - 1 ∈ G1) + 16 / M ^ 4 * (rc (T 53) n - M) ^ 4) +
838 2 / M * ((∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1)) +
839 ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1)) + badCount (T 53) n)) := by
840 refine Win.E_mono hL.le fun n hn => ?_
841 have hn1 := one_le_of_mem_pts hA hn
842 have hnlo := Win.lo_lt_of_mem_pts hA.lo_pos.le hn
843 have hdef : ∀ s ∈ T 53, s ∣ n → 0 ≤ f (n / s) - f (n - 1) := fun s hs hsn => by
844 have hmem := hρ3 s hs
845 refine defect_nonneg hmem.1 hmem.2.1 hn1 hsn fun h => ?_
846 have h2 : (n : ℝ) ≤ Real.exp (Real.sqrt (Real.log W.lo)) ^ 2 := by
847 rw [← h]; push_cast; rw [sq]
848 exact mul_le_mul hmem.2.2 hmem.2.2 (Nat.cast_nonneg _) (Real.exp_pos _).le
849 linarith
850 have hs1 : 0 ≤ ∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1)) := sum_nonneg fun s hs => by
851 rw [mem_filter] at hs; exact hdef s hs.1 hs.2
852 have hs2 : 0 ≤ ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1) := sum_nonneg fun s _ => ind_nonneg _
853 have hs3 : 0 ≤ badCount (T 53) n := sum_nonneg fun s _ => ind_nonneg _
854 have hq : 0 ≤ 16 / M ^ 4 * (rc (T 53) n - M) ^ 4 := by positivity
855 have hrest : 0 ≤ 2 / M * ((∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1)) +
856 ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1)) + badCount (T 53) n) := by positivity
857 by_cases hP : n % 3 ≠ 2 ∧ F n ≠ F (n - 1)
858 swap
859 · rw [ind_false hP]; linarith [ind_nonneg (n - 1 ∈ G1)]
860 rw [ind_true hP]
861 by_cases hg : n - 1 ∈ G1
862 · rw [ind_true hg]; linarith
863 rcases lt_or_ge (rc (T 53) n) (M / 2) with hr | hr
864 · have h1 : (M / 2) ^ 4 ≤ (rc (T 53) n - M) ^ 4 := by
865 have : (rc (T 53) n - M) ^ 4 = (M - rc (T 53) n) ^ 4 := by ring
866 rw [this]
867 exact pow_le_pow_left₀ (by positivity) (by linarith) 4
868 have h2 : 1 ≤ 16 / M ^ 4 * (rc (T 53) n - M) ^ 4 := by
869 rw [div_mul_eq_mul_div, le_div_iff₀ (by positivity)]
870 nlinarith
871 linarith [ind_nonneg (n - 1 ∈ G1)]
872 · -- every divisor is bad
873 have hn2 : 2 ≤ n := by
874 have := hA.three_le
875 have : (3 : ℝ) < n := by linarith
876 exact_mod_cast (by linarith : (2 : ℝ) ≤ n)
877 have hnU : n - 1 ∈ U := ⟨by omega, by omega⟩
878 have hFn : F (n - 1) = f (n - 1) := by
879 by_contra h; exact hg ⟨hnU, h⟩
880 have h1 : rc (T 53) n ≤ (∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1)) +
881 ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1)) + badCount (T 53) n := by
882 rw [rc_eq_sum']
883 unfold badCount
884 rw [← sum_add_distrib, ← sum_add_distrib]
885 refine sum_le_sum fun s hs => ?_
886 rw [mem_filter] at hs
887 obtain ⟨hsT, hsn⟩ := hs
888 have hd := hdef s hsT hsn
889 by_cases c1 : n / s ∈ G1
890 · rw [ind_true c1]; linarith [ind_nonneg (F n ≠ F (n / s))]
891 by_cases c2 : F n ≠ F (n / s)
892 · rw [ind_true c2]; linarith [ind_nonneg (n / s ∈ G1)]
893 rw [ind_false c1, ind_false c2]
894 rw [not_not] at c2
895 obtain ⟨y, rfl⟩ := hsn
896 have hsm3 := (hρ3 s hsT).2.1
897 have hs0 : 0 < s := by omega
898 have hy1 : 1 ≤ y := Nat.pos_of_mul_pos_left (show 0 < s * y by omega)
899 rw [Nat.mul_div_cancel_left y hs0] at *
900 have hyU : y ∈ U := (mem_U_iff_of_mod hsm3 hy1).mp hnU
901 have hFy : F y = f y := by by_contra h; exact c1 ⟨hyU, h⟩
902 have hne : f y ≠ f (s * y - 1) := fun h => hP.2 (by rw [c2, hFy, h, ← hFn])
903 rcases f_eq_zero_or_one y with h | h <;> rcases f_eq_zero_or_one (s * y - 1) with h' | h' <;>
904 rw [h, h'] at hne hd ⊢ <;> first | exact absurd rfl hne | linarith
905 have h2 : 1 ≤ 2 / M * rc (T 53) n := by
906 rw [div_mul_eq_mul_div, le_div_iff₀ hM]; linarith
907 have h3 := mul_le_mul_of_nonneg_left h1 (show 0 ≤ 2 / M by positivity)
908 linarith [ind_nonneg (n - 1 ∈ G1)]
909 rw [Win.E_add, Win.E_add, Win.E_const_mul, Win.E_const_mul, Win.E_add, Win.E_add] at hpt
910 have b1 := (abs_le.mp (E_shift_le hη hA 1 (fun n => ind (n - 1 ∈ G1)) 1 fun n => by
911 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).1
912 simp only [Nat.add_sub_cancel] at b1
913 have b1' : W.E (fun n => ind (n ∈ G1)) = W.mu G1 := rfl
914 rw [b1'] at b1
915 have b2 := h21 W J T x (hS.mono (by simp))
916 have b3 := hR.m4
917 have b5 := (h18 W J T x (hS.mono (by simp)) 53 (Or.inl rfl)).1
918 rw [div_le_iff₀ hM] at b5
919 have b6 := (abs_le.mp (hfam W (hA.mono (by simp)) (T 53)
920 (fun s hs => ⟨by have := (hρ3 s hs).2.1; omega, (hρ3 s hs).2.2⟩) (fun z => ind (z ∈ G1))
921 (fun _ => ind_nonneg _) fun _ => ind_le_one _)).2
922 have b6' : W.E (fun z => ind (z ∈ G1)) = W.mu G1 := rfl
923 rw [b6'] at b6
924 have b7 := h22 W J T x (hS.mono (by simp)) 53 (Or.inl rfl)
925 rw [div_le_iff₀ hM] at b7
926 have hd := hS.dp_pos
927 have hed := hS.edge_le_dp
928 have hx0 := hS.x_nonneg
929 have hedge := edge_pos hA
930 have hJ2 : 1 / (J : ℝ) ^ 2 ≤ dp W J x := by unfold dp; linarith
931 have hxd : x + 2 * W.edge ≤ 3 * dp W J x := by
932 have : (0 : ℝ) ≤ 1 / (J : ℝ) ^ 2 := by positivity
933 unfold dp; linarith
934 set d := dp W J x with hddef
935 have t1 : W.E (fun n => ind (n - 1 ∈ G1)) ≤ (C21 + 1) * d := by
936 push_cast at b1
937 linarith [b2.1]
938 have t2 : 16 / M ^ 4 * W.E (fun n => (rc (T 53) n - M) ^ 4) ≤ 16 * |K| ^ 5 * d := by
939 rw [abs_of_pos hK]
940 calc 16 / M ^ 4 * W.E (fun n => (rc (T 53) n - M) ^ 4) ≤ 16 / M ^ 4 * (K * (J : ℝ) ^ 2) := by
941 gcongr
942 _ = 16 * K * ((J : ℝ) ^ 2 / M ^ 4) := by field_simp
943 _ ≤ 16 * K * (K ^ 4 * d) := by
944 gcongr
945 exact hratio.trans (by gcongr)
946 _ = _ := by ring
947 have t3 : (W.E (fun n => ∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1))) +
948 W.E (fun n => ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1))) + W.E (badCount (T 53)) ≤
949 (54 * 3 + (C21 + 1) + C22) * d * M := by
950 have h1 : 54 * (x + 2 * W.edge) * M ≤ 54 * 3 * d * M := by nlinarith
951 have h2 : M * W.edge ≤ M * d := by gcongr
952 have h3 : M * W.mu G1 ≤ M * (C21 * d) := by gcongr; exact b2.1
953 linarith
954 have t4 : 2 / M * ((W.E (fun n => ∑ s ∈ T 53 with s ∣ n, (f (n / s) - f (n - 1))) +
955 W.E (fun n => ∑ s ∈ T 53 with s ∣ n, ind (n / s ∈ G1))) + W.E (badCount (T 53))) ≤
956 2 * (54 * 3 + (C21 + 1) + C22) * d := by
957 calc _ ≤ 2 / M * ((54 * 3 + (C21 + 1) + C22) * d * M) := by gcongr
958 _ = _ := by field_simp
959 linarith
960
961/-- **Lemma 23.** -/
962theorem L23 (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
963 W.D 1 ≤ C * dp W J x := by
964 obtain ⟨Ca, hCa, N1, haux⟩ := L23_aux K η hη
965 obtain ⟨C20, hC20, N2, h20⟩ := L20 K η hη
966 obtain ⟨C21, hC21, N3, h21⟩ := L21 K η hη
967 obtain ⟨N4, hmul⟩ := E_mul_le η hη
968 obtain ⟨N5, hexp⟩ := const_le_exp 2
969 refine ⟨Ca + 2 * (Ca + C21 + 3) + C21 * 3 + C20 + 5, by positivity,
970 max (max N1 N2) (max (max N3 N4) (max N5 (4 / η))), fun W J T x hS => ?_⟩
971 have hA := hS.adm
972 have hL := hA.len_pos hη
973 have hsm := small_le_edge hη (hA.mono (N' := 4 / η) (by simp)) le_rfl
974 have ha := haux W J T x (hS.mono (by simp))
975 have hG := h21 W J T x (hS.mono (by simp))
976 have hE2 := h20 W J T x (hS.mono (by simp)) 2 (by simp)
977 have hd := hS.dp_pos
978 have hed := hS.edge_le_dp
979 -- `D(1)` versus the set `F n ≠ F (n - 1)`
980 set P : ℕ → Prop := fun n => F n ≠ F (n - 1) with hP
981 set Q : ℕ → Prop := fun n => n % 3 ≠ 2 ∧ F n ≠ F (n - 1) with hQ
982 have e1 : W.D 1 ≤ W.E (fun n => ind (P n)) + W.edge := by
983 have := (abs_le.mp (E_shift_le hη hA 1 (fun n => ind (P n)) 1 fun n => by
984 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).2
985 have h2 : W.E (fun n => ind (P (n + 1))) = W.D 1 := rfl
986 beta_reduce at this
987 rw [h2] at this
988 push_cast at this
989 linarith
990 have e2 : W.E (fun n => ind (P n)) ≤ W.E (fun n => ((((ind (Q n) + ind (n - 1 ∈ G2)) +
991 ind (Q (2 * n - 1))) + ind (2 * n - 1 ∈ G1)) + ind (n ∈ Es 2)) + ind (n ∈ G1)) := by
992 refine Win.E_mono hL.le fun n hn => ?_
993 have hn1 := one_le_of_mem_pts hA hn
994 by_contra hcon
995 rw [not_le] at hcon
996 have i1 := ind_nonneg (Q n)
997 have i2 := ind_nonneg (n - 1 ∈ G2)
998 have i3 := ind_nonneg (Q (2 * n - 1))
999 have i4 := ind_nonneg (2 * n - 1 ∈ G1)
1000 have i5 := ind_nonneg (n ∈ Es 2)
1001 have i6 := ind_nonneg (n ∈ G1)
1002 have hp1 := ind_le_one (P n)
1003 have hPn : P n := by
1004 rcases em (P n) with h | h
1005 · exact h
1006 · rw [ind_false h] at hcon; linarith
1007 have nt : ∀ p : Prop, ind p < 1 → ¬ p := fun p h hp => by rw [ind_true hp] at h; linarith
1008 have k1 := nt _ (show ind (Q n) < 1 by linarith)
1009 have k2 := nt _ (show ind (n - 1 ∈ G2) < 1 by linarith)
1010 have k3 := nt _ (show ind (Q (2 * n - 1)) < 1 by linarith)
1011 have k4 := nt _ (show ind (2 * n - 1 ∈ G1) < 1 by linarith)
1012 have k5 := nt _ (show ind (n ∈ Es 2) < 1 by linarith)
1013 have k6 := nt _ (show ind (n ∈ G1) < 1 by linarith)
1014 have hn3 : n % 3 = 2 := by
1015 by_contra h; exact k1 ⟨h, hPn⟩
1016 have hnU : n ∈ U := ⟨hn1, by omega⟩
1017 have hmU : 2 * n - 1 ∈ U := ⟨by omega, by omega⟩
1018 have f1 : F (2 * (n - 1)) = F (n - 1) := by by_contra h; exact k2 h
1019 have f2 : F (2 * n - 1) = F (2 * n - 1 - 1) := by by_contra h; exact k3 ⟨by omega, h⟩
1020 have f3 : F (2 * n - 1) = f (2 * n - 1) := by by_contra h; exact k4 ⟨hmU, h⟩
1021 have f4 : f n = f (2 * n - 1) := by by_contra h; exact k5 ⟨hnU, h⟩
1022 have f5 : F n = f n := by by_contra h; exact k6 ⟨hnU, h⟩
1023 refine hPn ?_
1024 rw [f5, f4, ← f3, f2, ← f1, show 2 * n - 1 - 1 = 2 * (n - 1) by omega]
1025 rw [Win.E_add, Win.E_add, Win.E_add, Win.E_add, Win.E_add] at e2
1026 -- the two dilated terms
1027 have dil : ∀ R : ℕ → Prop, W.E (fun n => ind (R (2 * n - 1))) ≤ 2 * (W.E (fun n => ind (R n)) + 2 * W.edge) := by
1028 intro R
1029 have h1 := hmul W (hA.mono (by simp)) 2 (by norm_num)
1030 (by exact_mod_cast hexp W.lo (le_trans (by simp) hA.le_lo)) (fun n => ind (R (n - 1)))
1031 (fun _ => ind_nonneg _) fun _ => ind_le_one _
1032 have h2 := (abs_le.mp (E_shift_le hη hA 1 (fun n => ind (R (n - 1))) 1 fun n => by
1033 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).1
1034 simp only [Nat.add_sub_cancel] at h2
1035 push_cast at h1 h2
1036 linarith
1037 have d1 := dil Q
1038 have d2 := dil fun n => n ∈ G1
1039 have s1 : W.E (fun n => ind (n - 1 ∈ G2)) ≤ W.mu G2 + W.edge := by
1040 have h2 := (abs_le.mp (E_shift_le hη hA 1 (fun n => ind (n - 1 ∈ G2)) 1 fun n => by
1041 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).1
1042 simp only [Nat.add_sub_cancel] at h2
1043 have h3 : W.E (fun n => ind (n ∈ G2)) = W.mu G2 := rfl
1044 rw [h3] at h2
1045 push_cast at h2
1046 linarith
1047 have m1 : W.E (fun n => ind (n ∈ G1)) = W.mu G1 := rfl
1048 have m2 : W.E (fun n => ind (n ∈ Es 2)) = W.mu (Es 2) := rfl
1049 have m3 : W.E (fun n => ind (Q n)) ≤ Ca * dp W J x := ha
1050 rw [m1] at d2 e2
1051 rw [m2] at e2
1052 have hCd : 0 ≤ C21 * dp W J x := by positivity
1053 linarith [hG.1, hG.2.1]
1054
1055/-- Shifts by `2h`, `h ≤ lo^0.01`, cost at most `edge`. -/
1056theorem shift_le_edge (η : ℝ) (hη : 0 < η) : ∃ N0 : ℝ, ∀ W : Win, W.Adm η N0 → ∀ h : ℕ,
1057 (h : ℝ) ≤ W.lo ^ (0.01 : ℝ) → 2 * h * (4 / (W.lo * W.len)) ≤ W.edge := by
1058 have ev := (tendsto_rpow_atTop (show (0 : ℝ) < 0.98 by norm_num)).eventually_ge_atTop (800 / η)
1059 obtain ⟨N0, hN0⟩ := Filter.eventually_atTop.mp ev
1060 refine ⟨N0, fun W hW h hle => ?_⟩
1061 have h1 := hN0 W.lo hW.le_lo
1062 have hlo := hW.lo_pos
1063 have hl := hW.one_lt_log
1064 have hL := hW.len_pos hη
1065 have hlen := hW.le_len
1066 have hlog : Real.log W.lo ≤ 100 * W.lo ^ (0.01 : ℝ) := by
1067 have := Real.log_le_rpow_div hlo.le (show (0 : ℝ) < 0.01 by norm_num)
1068 have e : W.lo ^ (0.01 : ℝ) / 0.01 = 100 * W.lo ^ (0.01 : ℝ) := by norm_num; ring
1069 linarith
1070 have hedge : 1 / Real.log W.lo ≤ W.edge := by
1071 rw [one_div, ← Real.rpow_neg_one]
1072 exact Real.rpow_le_rpow_of_exponent_le hl.le (by norm_num)
1073 refine le_trans ?_ hedge
1074 have e98 : W.lo = W.lo ^ (0.98 : ℝ) * (W.lo ^ (0.01 : ℝ) * W.lo ^ (0.01 : ℝ)) := by
1075 rw [← Real.rpow_add hlo, ← Real.rpow_add hlo]; norm_num
1076 set u := W.lo ^ (0.01 : ℝ) with hu
1077 have hu0 : 0 < u := Real.rpow_pos_of_pos hlo _
1078 rw [mul_div_assoc', div_le_div_iff₀ (by positivity) (by linarith), one_mul]
1079 have h2 : 800 ≤ W.lo ^ (0.98 : ℝ) * η := by rwa [div_le_iff₀ hη] at h1
1080 have h3 : 800 * (u * u) ≤ W.lo * η := by
1081 calc 800 * (u * u) ≤ W.lo ^ (0.98 : ℝ) * η * (u * u) := by gcongr
1082 _ = W.lo ^ (0.98 : ℝ) * (u * u) * η := by ring
1083 _ = W.lo * η := by rw [← e98]
1084 have h4 : W.lo * η ≤ W.lo * W.len := by
1085 gcongr
1086 nlinarith
1087 calc 2 * (h : ℝ) * 4 * Real.log W.lo ≤ 2 * u * 4 * (100 * u) := by gcongr
1088 _ = 800 * (u * u) := by ring
1089 _ ≤ _ := h3.trans h4
1090
1091/-- **Lemma 24**, doubling step. -/
1092theorem L24_double (K η : ℝ) (hη : 0 < η) : ∃ C > 0, ∃ N0 : ℝ, ∀ W J T x, Setup K η N0 W J T x →
1093 ∀ h : ℕ, 1 ≤ h → (h : ℝ) ≤ W.lo ^ (0.01 : ℝ) → W.D (2 * h) ≤ W.D h + C * dp W J x := by
1094 obtain ⟨C23, hC23, N1, h23⟩ := L23 K η hη
1095 obtain ⟨C21, hC21, N2, h21⟩ := L21 K η hη
1096 obtain ⟨N3, hdiv⟩ := E_div_le η hη
1097 obtain ⟨N4, hexp⟩ := const_le_exp 2
1098 obtain ⟨N5, hshift⟩ := shift_le_edge η hη
1099 refine ⟨2 * C21 + 2 * C23 + 20, by positivity,
1100 max (max (max N1 N2) (max N3 N4)) (max N5 (4 / η)), fun W J T x hS h hh hle => ?_⟩
1101 have hA := hS.adm
1102 have hL := hA.len_pos hη
1103 have hedge := edge_pos hA
1104 have hsm := small_le_edge hη (hA.mono (N' := 4 / η) (by simp)) le_rfl
1105 have hshh := hshift W (hA.mono (by simp)) h hle
1106 have hD1 := h23 W J T x (hS.mono (by simp))
1107 have hG2 := (h21 W J T x (hS.mono (by simp))).2.1
1108 have hed := hS.edge_le_dp
1109 have hd := hS.dp_pos
1110 set K1 : ℕ → ℝ := fun m => ind (m ∈ G2) with hK1
1111 set K2' : ℕ → ℝ := fun m => ind (m + h ∈ G2) with hK2
1112 set K3 : ℕ → ℝ := fun m => ind (F (m + h) ≠ F m) with hK3
1113 set ev : (ℕ → ℝ) → ℕ → ℝ := fun G n => if 2 ∣ n then G (n / 2) else 0 with hev
1114 -- dilation by 2 for each piece
1115 have dil : ∀ G : ℕ → ℝ, (∀ n, 0 ≤ G n) → (∀ n, G n ≤ 1) → W.E (ev G) ≤ (W.E G + W.edge) / 2 := by
1116 intro G h0 h1
1117 have e1 := L17_dilate W hA.lo_pos.le hA.lo_lt.le (s := 2) (by norm_num) G
1118 have e2 := (abs_le.mp (hdiv W (hA.mono (by simp)) 2 (by norm_num)
1119 (hexp W.lo (le_trans (by simp) hA.le_lo)) G h0 h1)).2
1120 have e3 : W.E (ev G) = (W.div 2).E G / 2 := by
1121 unfold Win.E
1122 rw [Win.len_div (by norm_num)]
1123 simp only [hev]
1124 rw [e1]
1125 push_cast
1126 ring
1127 rw [e3]; linarith
1128 -- pointwise
1129 set Kall : ℕ → ℝ := fun n => (ev K1 n + ev K2' n) + ev K3 n with hKall
1130 have hKall0 : ∀ n, 0 ≤ Kall n := fun n => by
1131 simp only [hKall, hev, hK1, hK2, hK3]
1132 split_ifs
1133 · have := ind_nonneg (n / 2 ∈ G2)
1134 have := ind_nonneg (n / 2 + h ∈ G2)
1135 have := ind_nonneg (F (n / 2 + h) ≠ F (n / 2))
1136 linarith
1137 · norm_num
1138 have hKall3 : ∀ n, Kall n ≤ 3 := fun n => by
1139 simp only [hKall, hev, hK1, hK2, hK3]
1140 split_ifs
1141 · have := ind_le_one (n / 2 ∈ G2)
1142 have := ind_le_one (n / 2 + h ∈ G2)
1143 have := ind_le_one (F (n / 2 + h) ≠ F (n / 2))
1144 linarith
1145 · norm_num
1146 have heven : ∀ n, 2 ∣ n → ind (F (n + 2 * h) ≠ F n) ≤ Kall n := by
1147 rintro n ⟨m, rfl⟩
1148 simp only [hKall, hev, hK1, hK2, hK3, dvd_mul_right, if_true,
1149 Nat.mul_div_cancel_left m (show 0 < 2 by norm_num)]
1150 by_cases c1 : m ∈ G2
1151 · rw [ind_true c1]
1152 linarith [ind_le_one (F (2 * m + 2 * h) ≠ F (2 * m)), ind_nonneg (m + h ∈ G2),
1153 ind_nonneg (F (m + h) ≠ F m)]
1154 by_cases c2 : m + h ∈ G2
1155 · rw [ind_true c2]
1156 linarith [ind_le_one (F (2 * m + 2 * h) ≠ F (2 * m)), ind_nonneg (m ∈ G2),
1157 ind_nonneg (F (m + h) ≠ F m)]
1158 have e1 : F (2 * m) = F m := by by_contra h; exact c1 h
1159 have e2 : F (2 * (m + h)) = F (m + h) := by by_contra h; exact c2 h
1160 rw [show 2 * m + 2 * h = 2 * (m + h) by ring, e1, e2]
1161 linarith [ind_nonneg (m ∈ G2), ind_nonneg (m + h ∈ G2)]
1162 set P : ℕ → ℝ := fun n => ind (F (n + 1) ≠ F n) with hP
1163 have hpt : W.D (2 * h) ≤ W.E (fun n => ((Kall n + Kall (n - 1)) + ind (F n ≠ F (n - 1))) +
1164 P (n + (2 * h - 1))) := by
1165 refine Win.E_mono hL.le fun n hn => ?_
1166 have hn1 := one_le_of_mem_pts hA hn
1167 have p0 := hKall0 n
1168 have p1 := hKall0 (n - 1)
1169 have p2 := ind_nonneg (F n ≠ F (n - 1))
1170 have p3 : 0 ≤ P (n + (2 * h - 1)) := ind_nonneg _
1171 by_cases h2 : 2 ∣ n
1172 · linarith [heven n h2]
1173 · have h2' : 2 ∣ n - 1 := by omega
1174 by_cases c1 : F n ≠ F (n - 1)
1175 · rw [ind_true c1]; linarith [ind_le_one (F (n + 2 * h) ≠ F n)]
1176 by_cases c2 : F (n + (2 * h - 1) + 1) ≠ F (n + (2 * h - 1))
1177 · have : P (n + (2 * h - 1)) = 1 := ind_true c2
1178 rw [this]; linarith [ind_le_one (F (n + 2 * h) ≠ F n)]
1179 rw [not_not] at c1 c2
1180 have e1 : n + (2 * h - 1) + 1 = n + 2 * h := by omega
1181 have e2 : n + (2 * h - 1) = n - 1 + 2 * h := by omega
1182 rw [e1, e2] at c2
1183 have e3 : ind (F (n + 2 * h) ≠ F n) = ind (F (n - 1 + 2 * h) ≠ F (n - 1)) := by rw [c2, c1]
1184 rw [e3]
1185 linarith [heven (n - 1) h2']
1186 rw [Win.E_add, Win.E_add, Win.E_add] at hpt
1187 -- shifts
1188 have s1 : W.E (fun n => Kall (n - 1)) ≤ W.E Kall + 3 * W.edge := by
1189 have := (abs_le.mp (E_shift_le hη hA 1 (fun n => Kall (n - 1)) 3 fun n => by
1190 rw [abs_of_nonneg (hKall0 _)]; exact hKall3 _)).1
1191 simp only [Nat.add_sub_cancel] at this
1192 push_cast at this
1193 linarith
1194 have s2 : W.E (fun n => ind (F n ≠ F (n - 1))) ≤ W.D 1 + W.edge := by
1195 have := (abs_le.mp (E_shift_le hη hA 1 (fun n => ind (F n ≠ F (n - 1))) 1 fun n => by
1196 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).1
1197 simp only [Nat.add_sub_cancel] at this
1198 have h2 : W.E (fun n => ind (F (n + 1) ≠ F n)) = W.D 1 := rfl
1199 rw [h2] at this
1200 push_cast at this
1201 linarith
1202 have hfrac : 0 ≤ 4 / (W.lo * W.len) := by have := hA.lo_pos; positivity
1203 have s3 : W.E (fun n => P (n + (2 * h - 1))) ≤ W.D 1 + W.edge := by
1204 have := (abs_le.mp (E_shift_le hη hA (2 * h - 1) P 1 fun n => by
1205 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).2
1206 have h2 : W.E P = W.D 1 := rfl
1207 rw [h2] at this
1208 have h3 : ((2 * h - 1 : ℕ) : ℝ) ≤ 2 * h := by exact_mod_cast Nat.sub_le _ _
1209 have h4 : ((2 * h - 1 : ℕ) : ℝ) * 1 * (4 / (W.lo * W.len)) ≤ 2 * h * (4 / (W.lo * W.len)) := by
1210 rw [mul_one]; gcongr
1211 linarith
1212 have s4 : W.E (fun n => ind (n + h ∈ G2)) ≤ W.mu G2 + W.edge := by
1213 have := (abs_le.mp (E_shift_le hη hA h (fun n => ind (n ∈ G2)) 1 fun n => by
1214 rw [abs_of_nonneg (ind_nonneg _)]; exact ind_le_one _)).2
1215 have h2 : W.E (fun n => ind (n ∈ G2)) = W.mu G2 := rfl
1216 rw [h2] at this
1217 have h4 : (h : ℝ) * 1 * (4 / (W.lo * W.len)) ≤ 2 * h * (4 / (W.lo * W.len)) := by
1218 rw [mul_one]
1219 have : (0 : ℝ) ≤ h := Nat.cast_nonneg _
1220 gcongr
1221 linarith
1222 linarith
1223 have hE : W.E Kall = W.E (ev K1) + W.E (ev K2') + W.E (ev K3) := by
1224 simp only [hKall]; rw [Win.E_add, Win.E_add]
1225 have d1 := dil K1 (fun _ => ind_nonneg _) fun _ => ind_le_one _
1226 have d2 := dil K2' (fun _ => ind_nonneg _) fun _ => ind_le_one _
1227 have d3 := dil K3 (fun _ => ind_nonneg _) fun _ => ind_le_one _
1228 have r1 : W.E K1 = W.mu G2 := rfl
1229 have r3 : W.E K3 = W.D h := rfl
1230 have r2 : W.E K2' ≤ W.mu G2 + W.edge := s4
1231 have r4 : W.E (fun n => Kall n) = W.E Kall := rfl
1232 rw [r1] at d1
1233 rw [r3] at d3
1234 rw [r4] at hpt
1235 linarith
1236
1237end E424
1238