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/DivisorMoments/L13Aux.lean

All files · 325 lines · source at the verified commit

1module
2
3public import E424.Defs
4
5@[expose] public section
6
7/-!
8# Auxiliary lemmas for L13
9
10Exact count of an arithmetic progression in a real interval, as a floor difference.
11-/
12
13set_option linter.style.header false
14open MeasureTheory
15
16namespace E424
17namespace L13Aux
18
19section Count
20open Finset
21
22/-- The integers `m` in `(lo, x]` with `m ≡ r mod D` are counted by a floor difference. -/
23theorem count_eq_floor {lo x : ℝ} (hlo : 0 ≤ lo) (hx : lo ≤ x) {D : ℕ} (hD : 0 < D) (r : ℕ) :
24 (∑ m ∈ Ioc ⌊lo⌋₊ ⌊x⌋₊, ind (m ≡ r [MOD D]) : ℝ) =
25 ((⌊(x - r) / D⌋ - ⌊(lo - r) / D⌋ : ℤ) : ℝ) := by
26 have hD' : (0 : ℝ) < D := by exact_mod_cast hD
27 have hx0 : 0 ≤ x := hlo.trans hx
28 -- integers `k` with `lo < r + D k ≤ x`, parametrised by `k ∈ (q, p]`
29 have key : ∀ k : ℤ, (lo < (r : ℝ) + D * k ∧ (r : ℝ) + D * k ≤ x) ↔
30 (⌊(lo - r) / D⌋ < k ∧ k ≤ ⌊(x - r) / D⌋) := by
31 intro k
32 rw [Int.floor_lt, Int.le_floor, div_lt_iff₀ hD', le_div_iff₀ hD']
33 constructor <;> rintro ⟨h1, h2⟩ <;> constructor <;> linarith
34 have hmem : ∀ m : ℕ, m ∈ Ioc ⌊lo⌋₊ ⌊x⌋₊ ↔ lo < m ∧ (m : ℝ) ≤ x := by
35 intro m
36 rw [mem_Ioc, Nat.floor_lt hlo, Nat.le_floor_iff hx0]
37 have hfilt : ∑ m ∈ Ioc ⌊lo⌋₊ ⌊x⌋₊, ind (m ≡ r [MOD D]) =
38 ((Ioc ⌊lo⌋₊ ⌊x⌋₊).filter (fun m => m ≡ r [MOD D])).card := by
39 rw [Finset.card_filter, Nat.cast_sum]
40 refine Finset.sum_congr rfl fun m _ => ?_
41 simp only [ind]
42 split_ifs <;> simp
43 have hle : ⌊(lo - r) / D⌋ ≤ ⌊(x - r) / D⌋ :=
44 Int.floor_mono (div_le_div_of_nonneg_right (by linarith) hD'.le)
45 -- the cast of `(r + D k).toNat` when `r + D k ≥ 0`
46 have hcast : ∀ k : ℤ, 0 ≤ (r : ℤ) + D * k → (((r : ℤ) + D * k).toNat : ℝ) = (r : ℝ) + D * k := by
47 intro k hk
48 have h2 : (((r : ℤ) + D * k).toNat : ℤ) = (r : ℤ) + D * k := Int.toNat_of_nonneg hk
49 exact_mod_cast h2
50 have hnn : ∀ k : ℤ, ⌊(lo - r) / D⌋ < k → 0 ≤ (r : ℤ) + D * k := by
51 intro k hk
52 have h1 : (lo - r) / D < (k : ℝ) := Int.floor_lt.mp hk
53 rw [div_lt_iff₀ hD'] at h1
54 have : (0 : ℝ) ≤ (r : ℝ) + D * k := by linarith
55 exact_mod_cast this
56 have hcard : (Ioc ⌊(lo - r) / D⌋ ⌊(x - r) / D⌋).card =
57 ((Ioc ⌊lo⌋₊ ⌊x⌋₊).filter (fun m => m ≡ r [MOD D])).card := by
58 refine Finset.card_nbij (fun k : ℤ => ((r : ℤ) + D * k).toNat) ?_ ?_ ?_
59 · -- maps into the naturals of `(lo, x]` in the class
60 intro k hk
61 have hk' := Finset.mem_Ioc.mp (Finset.mem_coe.mp hk)
62 have hkey := (key k).mpr hk'
63 have h0 := hnn k hk'.1
64 refine Finset.mem_coe.mpr (Finset.mem_filter.mpr ⟨(hmem _).mpr ?_, ?_⟩)
65 · rw [hcast k h0]; exact hkey
66 · exact Nat.modEq_iff_dvd.mpr ⟨-k, by rw [Int.toNat_of_nonneg h0]; ring⟩
67 · -- injective
68 intro k hk k' hk' heq
69 have hk1 := Finset.mem_Ioc.mp (Finset.mem_coe.mp hk)
70 have hk2 := Finset.mem_Ioc.mp (Finset.mem_coe.mp hk')
71 have heq' : ((r : ℤ) + D * k).toNat = ((r : ℤ) + D * k').toNat := heq
72 have e1 := hcast k (hnn k hk1.1)
73 have e2 := hcast k' (hnn k' hk2.1)
74 rw [heq'] at e1
75 have h3 : (D : ℝ) * k = D * k' := by linarith
76 have h4 : (k : ℝ) = k' := mul_left_cancel₀ hD'.ne' h3
77 exact_mod_cast h4
78 · -- surjective
79 intro m hm
80 obtain ⟨hm1, hm2⟩ := Finset.mem_filter.mp (Finset.mem_coe.mp hm)
81 obtain ⟨c, hc⟩ := Nat.modEq_iff_dvd.mp hm2
82 have hmz : (r : ℤ) + D * (-c) = (m : ℤ) := by linarith
83 have hmR : (r : ℝ) + D * ((-c : ℤ) : ℝ) = m := by
84 have h := congrArg (Int.cast (R := ℝ)) hmz
85 push_cast at h ⊢
86 linarith
87 obtain ⟨hl, hu⟩ := (hmem m).mp hm1
88 refine ⟨-c, Finset.mem_coe.mpr (Finset.mem_Ioc.mpr ?_), ?_⟩
89 · exact (key (-c)).mp ⟨by rw [hmR]; exact hl, by rw [hmR]; exact hu⟩
90 · show ((r : ℤ) + D * (-c)).toNat = m
91 rw [hmz]
92 exact Int.toNat_natCast m
93 rw [hfilt, ← hcard, Int.card_Ioc]
94 have : ((⌊(x - r) / D⌋ - ⌊(lo - r) / D⌋).toNat : ℤ) = ⌊(x - r) / D⌋ - ⌊(lo - r) / D⌋ :=
95 Int.toNat_of_nonneg (by linarith)
96 exact_mod_cast this
97
98end Count
99
100/-- The count minus its expected value `(x - lo) / D` is at most one in absolute value. -/
101theorem count_sub_le {lo x : ℝ} (hlo : 0 ≤ lo) (hx : lo ≤ x) {D : ℕ} (hD : 0 < D) (r : ℕ) :
102 |(∑ m ∈ Finset.Ioc ⌊lo⌋₊ ⌊x⌋₊, ind (m ≡ r [MOD D]) : ℝ) - (x - lo) / D| ≤ 1 := by
103 rw [count_eq_floor hlo hx hD r]
104 have hsplit : (x - lo) / D = (x - r) / D - (lo - r) / D := by ring
105 rw [hsplit, abs_le]
106 push_cast
107 have h1 := Int.floor_le ((x - r) / D)
108 have h2 := Int.lt_floor_add_one ((x - r) / D)
109 have h3 := Int.floor_le ((lo - r) / D)
110 have h4 := Int.lt_floor_add_one ((lo - r) / D)
111 constructor <;> linarith
112
113/-- `x⁻¹ ^ 2` is continuous on `[lo, hi]` for `0 < lo`. -/
114theorem cont_inv_sq {lo hi : ℝ} (hlo : 0 < lo) :
115 ContinuousOn (fun x : ℝ => x⁻¹ ^ 2) (Set.Icc lo hi) :=
116 ((continuousOn_id.inv₀ fun _ hx => (lt_of_lt_of_le hlo hx.1).ne').pow 2)
117
118theorem integrable_inv_sq {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) :
119 IntervalIntegrable (fun x : ℝ => x⁻¹ ^ 2) volume lo hi :=
120 (cont_inv_sq hlo).intervalIntegrable_of_Icc hhi
121
122/-- `∫ x⁻¹ ^ 2 = a⁻¹ - b⁻¹` on `[a, b]`. -/
123theorem integral_inv_sq_eval {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) :
124 ∫ x in a..b, x⁻¹ ^ 2 = a⁻¹ - b⁻¹ := by
125 have hb : 0 < b := lt_of_lt_of_le ha hab
126 have hc : (fun x : ℝ => x⁻¹ ^ 2) = fun x : ℝ => x ^ (-2 : ℤ) := by
127 funext x; simp [zpow_neg, inv_pow]
128 have h0 : (0 : ℝ) ∉ Set.uIcc a b := Set.notMem_uIcc_of_lt ha hb
129 rw [hc, integral_zpow (Or.inr ⟨by norm_num, h0⟩)]
130 norm_num [zpow_neg]
131 ring
132
133/-- One step of the step-function integral: `∫_lo^hi 1[m ≤ x] x⁻² dx = m⁻¹ - hi⁻¹`. -/
134theorem term_integral {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) {m : ℕ} (hm1 : lo < m)
135 (hm2 : (m : ℝ) ≤ hi) :
136 ∫ x in lo..hi, (if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2 = (m : ℝ)⁻¹ - hi⁻¹ := by
137 have hm0 : (0 : ℝ) < m := lt_trans hlo hm1
138 have hfun : (fun x : ℝ => (if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) =
139 (Set.Ici (m : ℝ)).indicator (fun x : ℝ => x⁻¹ ^ 2) := by
140 funext x
141 by_cases h : (m : ℝ) ≤ x <;> simp [h]
142 rw [hfun, intervalIntegral.integral_of_le hhi,
143 MeasureTheory.setIntegral_indicator measurableSet_Ici]
144 have hset : Set.Ioc lo hi ∩ Set.Ici (m : ℝ) = Set.Icc (m : ℝ) hi := by
145 ext x
146 simp only [Set.mem_inter_iff, Set.mem_Ioc, Set.mem_Ici, Set.mem_Icc]
147 constructor
148 · rintro ⟨⟨_, h2⟩, h3⟩; exact ⟨h3, h2⟩
149 · rintro ⟨h1, h2⟩; exact ⟨⟨lt_of_lt_of_le hm1 h1, h2⟩, h1⟩
150 rw [hset, MeasureTheory.integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le hm2]
151 exact integral_inv_sq_eval hm0 hm2
152
153/-- Sum over `P` of step-function integrals, with the weights `k m`. -/
154theorem integral_sum_identity {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) (P : Finset ℕ)
155 (hP : ∀ m ∈ P, lo < m ∧ (m : ℝ) ≤ hi) (k : ℕ → ℝ) :
156 ∫ x in lo..hi, (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) * x⁻¹ ^ 2 =
157 ∑ m ∈ P, k m * ((m : ℝ)⁻¹ - hi⁻¹) := by
158 have hfun : (fun x : ℝ => (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) * x⁻¹ ^ 2) =
159 fun x => ∑ m ∈ P, k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) := by
160 funext x
161 rw [Finset.sum_mul]
162 refine Finset.sum_congr rfl fun m _ => ?_
163 ring
164 have hterm_int : ∀ m ∈ P, IntervalIntegrable
165 (fun x : ℝ => (if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) volume lo hi := by
166 intro m _
167 have hfn : (fun x : ℝ => (if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) =
168 (Set.Ici (m : ℝ)).indicator (fun x : ℝ => x⁻¹ ^ 2) := by
169 funext x
170 by_cases h : (m : ℝ) ≤ x <;> simp [h]
171 rw [hfn, intervalIntegrable_iff_integrableOn_Ioc_of_le hhi]
172 exact ((cont_inv_sq hlo).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self).indicator
173 measurableSet_Ici
174 rw [hfun, intervalIntegral.integral_finsetSum]
175 · refine Finset.sum_congr rfl fun m hm => ?_
176 rw [intervalIntegral.integral_const_mul, term_integral hlo hhi (hP m hm).1 (hP m hm).2]
177 · intro m hm
178 exact (hterm_int m hm).const_mul _
179
180/-- `x⁻¹` is continuous on `[lo, hi]` for `0 < lo`. -/
181theorem cont_inv {lo hi : ℝ} (hlo : 0 < lo) : ContinuousOn (fun x : ℝ => x⁻¹) (Set.Icc lo hi) :=
182 continuousOn_id.inv₀ fun _ hx => (lt_of_lt_of_le hlo hx.1).ne'
183
184/-- `P`-sums of the step function restricted to `[lo, x]` count `(lo, x]`. -/
185theorem sum_ite_eq_count {lo x hi : ℝ} (hlo : 0 ≤ lo) (hx : lo ≤ x) (hxhi : x ≤ hi) (k : ℕ → ℝ) :
186 ∑ m ∈ Finset.Ioc ⌊lo⌋₊ ⌊hi⌋₊, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0) =
187 ∑ m ∈ Finset.Ioc ⌊lo⌋₊ ⌊x⌋₊, k m := by
188 have hx0 : 0 ≤ x := hlo.trans hx
189 have h1 : ∀ m, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0) = if (m : ℝ) ≤ x then k m else 0 := by
190 intro m; split_ifs <;> simp
191 simp only [h1]
192 rw [← Finset.sum_filter]
193 congr 1
194 ext m
195 simp only [Finset.mem_filter, Finset.mem_Ioc]
196 constructor
197 · rintro ⟨⟨h1, _⟩, h3⟩
198 exact ⟨h1, (Nat.le_floor_iff hx0).mpr h3⟩
199 · rintro ⟨h1, h2⟩
200 exact ⟨⟨h1, h2.trans (Nat.floor_mono hxhi)⟩, (Nat.le_floor_iff hx0).mp h2⟩
201
202theorem sum_integrable {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) (P : Finset ℕ) (k : ℕ → ℝ) :
203 IntervalIntegrable (fun x : ℝ => (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) * x⁻¹ ^ 2)
204 volume lo hi := by
205 have hfun : (fun x : ℝ => (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) * x⁻¹ ^ 2) =
206 fun x => ∑ m ∈ P, k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) := by
207 funext x
208 rw [Finset.sum_mul]
209 refine Finset.sum_congr rfl fun m _ => ?_
210 ring
211 have hterm : ∀ m : ℕ, IntervalIntegrable
212 (fun x : ℝ => k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2)) volume lo hi := by
213 intro m
214 have hfn : (fun x : ℝ => k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2)) =
215 fun x => k m * (Set.Ici (m : ℝ)).indicator (fun x : ℝ => x⁻¹ ^ 2) x := by
216 funext x
217 by_cases h : (m : ℝ) ≤ x <;> simp [h]
218 rw [hfn, intervalIntegrable_iff_integrableOn_Ioc_of_le hhi]
219 have hind : IntegrableOn ((Set.Ici (m : ℝ)).indicator (fun x : ℝ => x⁻¹ ^ 2)) (Set.Ioc lo hi) :=
220 ((cont_inv_sq hlo).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self).indicator
221 measurableSet_Ici
222 exact hind.const_mul (k m)
223 have hfun2 : (fun x : ℝ => ∑ m ∈ P, k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2)) =
224 ∑ m ∈ P, fun x : ℝ => k m * ((if (m : ℝ) ≤ x then (1 : ℝ) else 0) * x⁻¹ ^ 2) := by
225 funext x
226 simp [Finset.sum_apply]
227 rw [hfun, hfun2]
228 exact IntervalIntegrable.sum P (fun m _ => hterm m)
229
230/-- `∫_lo^hi (x - lo) / D * x⁻² dx = (log (hi / lo) + lo / hi - 1) / D`. -/
231theorem integral_T {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) (D : ℝ) :
232 ∫ x in lo..hi, (x - lo) / D * x⁻¹ ^ 2 = (Real.log (hi / lo) + lo / hi - 1) / D := by
233 have hhi0 : 0 < hi := lt_of_lt_of_le hlo hhi
234 have hpt : Set.EqOn (fun x : ℝ => (x - lo) / D * x⁻¹ ^ 2)
235 (fun x : ℝ => (1 / D) * x⁻¹ - (lo / D) * x⁻¹ ^ 2) (Set.uIcc lo hi) := by
236 intro x hx
237 rw [Set.uIcc_of_le hhi] at hx
238 have hx0 : x ≠ 0 := (lt_of_lt_of_le hlo hx.1).ne'
239 field_simp
240 have hinv : IntervalIntegrable (fun x : ℝ => x⁻¹) volume lo hi :=
241 (cont_inv hlo).intervalIntegrable_of_Icc hhi
242 rw [intervalIntegral.integral_congr hpt, intervalIntegral.integral_sub (hinv.const_mul _)
243 ((integrable_inv_sq hlo hhi).const_mul _), intervalIntegral.integral_const_mul,
244 intervalIntegral.integral_const_mul, integral_inv_of_pos hlo hhi0, integral_inv_sq_eval hlo hhi]
245 field_simp
246 ring
247
248theorem integrable_T {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) (D : ℝ) :
249 IntervalIntegrable (fun x : ℝ => (x - lo) / D * x⁻¹ ^ 2) volume lo hi :=
250 have hc1 : ContinuousOn (fun x : ℝ => (x - lo) / D) (Set.Icc lo hi) :=
251 ((continuous_id.sub continuous_const).div_const D).continuousOn
252 (hc1.mul (cont_inv_sq hlo)).intervalIntegrable_of_Icc hhi
253
254/-- The sharp bound: the window sum of the residue indicator against `log (hi/lo) / D`. -/
255theorem main_bound {lo hi : ℝ} (hlo : 0 < lo) (hhi : lo ≤ hi) {D : ℕ} (hD : 0 < D) (r : ℕ) :
256 |(∑ n ∈ Finset.Ioc ⌊lo⌋₊ ⌊hi⌋₊, ind (n ≡ r [MOD D]) / n) - Real.log (hi / lo) / D| ≤ 1 / lo := by
257 have hD' : (0 : ℝ) < D := by exact_mod_cast hD
258 have hhi0 : 0 < hi := lt_of_lt_of_le hlo hhi
259 set P := Finset.Ioc ⌊lo⌋₊ ⌊hi⌋₊ with hPdef
260 set k : ℕ → ℝ := fun n => ind (n ≡ r [MOD D]) with hkdef
261 have hP : ∀ m ∈ P, lo < m ∧ (m : ℝ) ≤ hi := by
262 intro m hm
263 obtain ⟨h1, h2⟩ := Finset.mem_Ioc.mp hm
264 exact ⟨(Nat.floor_lt hlo.le).mp h1, (Nat.le_floor_iff hhi0.le).mp h2⟩
265 set F : ℝ → ℝ := fun x => (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) - (x - lo) / D
266 with hFdef
267 have hFbd : ∀ x ∈ Set.Icc lo hi, |F x| ≤ 1 := by
268 intro x hx
269 show |(∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) - (x - lo) / D| ≤ 1
270 rw [sum_ite_eq_count hlo.le hx.1 hx.2 k]
271 exact count_sub_le hlo.le hx.1 hD r
272 have hN : ∑ m ∈ P, k m * (if (m : ℝ) ≤ hi then (1 : ℝ) else 0) = ∑ m ∈ P, k m := by
273 refine Finset.sum_congr rfl fun m hm => ?_
274 rw [if_pos (hP m hm).2, mul_one]
275 have hI := integral_sum_identity hlo hhi P hP k
276 have hIint := sum_integrable hlo hhi P k
277 have hTint := integrable_T hlo hhi D
278 have hFint : ∫ x in lo..hi, F x * x⁻¹ ^ 2 =
279 (∑ m ∈ P, k m * ((m : ℝ)⁻¹ - hi⁻¹)) - (Real.log (hi / lo) + lo / hi - 1) / D := by
280 have hfun : (fun x : ℝ => F x * x⁻¹ ^ 2) =
281 fun x => (∑ m ∈ P, k m * (if (m : ℝ) ≤ x then (1 : ℝ) else 0)) * x⁻¹ ^ 2 -
282 (x - lo) / D * x⁻¹ ^ 2 := by
283 funext x
284 simp only [hFdef]
285 ring
286 rw [hfun, intervalIntegral.integral_sub hIint hTint, hI, integral_T hlo hhi D]
287 have hFbound : |∫ x in lo..hi, F x * x⁻¹ ^ 2| ≤ lo⁻¹ - hi⁻¹ := by
288 have hae : ∀ᵐ t ∂(volume : Measure ℝ), t ∈ Set.Ioc lo hi →
289 ‖F t * t⁻¹ ^ 2‖ ≤ (fun x : ℝ => x⁻¹ ^ 2) t := by
290 refine Filter.Eventually.of_forall fun t ht => ?_
291 have hb := hFbd t ⟨ht.1.le, ht.2⟩
292 have hnn : (0 : ℝ) ≤ t⁻¹ ^ 2 := by positivity
293 rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg hnn]
294 exact mul_le_of_le_one_left hnn hb
295 have h := intervalIntegral.norm_integral_le_of_norm_le hhi hae (integrable_inv_sq hlo hhi)
296 rw [integral_inv_sq_eval hlo hhi, Real.norm_eq_abs] at h
297 exact h
298 have hsum_eq : ∑ m ∈ P, k m * ((m : ℝ)⁻¹ - hi⁻¹) =
299 (∑ m ∈ P, k m / m) - (∑ m ∈ P, k m) * hi⁻¹ := by
300 rw [Finset.sum_mul, ← Finset.sum_sub_distrib]
301 refine Finset.sum_congr rfl fun m _ => ?_
302 ring
303 have hcountF : ∑ m ∈ P, k m = F hi + (hi - lo) / D := by
304 have hFhi : F hi = (∑ m ∈ P, k m * (if (m : ℝ) ≤ hi then (1 : ℝ) else 0)) - (hi - lo) / D := rfl
305 rw [hN] at hFhi
306 linarith
307 have hid : (hi - lo) / D * hi⁻¹ + (Real.log (hi / lo) + lo / hi - 1) / D =
308 Real.log (hi / lo) / D := by
309 field_simp
310 ring
311 have key : (∑ m ∈ P, k m / m) - Real.log (hi / lo) / D = (∫ x in lo..hi, F x * x⁻¹ ^ 2) + F hi * hi⁻¹ := by
312 linear_combination -hFint - hsum_eq + hi⁻¹ * hcountF + hid
313 show |(∑ m ∈ P, k m / m) - Real.log (hi / lo) / D| ≤ 1 / lo
314 rw [key]
315 have hFh : |F hi * hi⁻¹| ≤ hi⁻¹ := by
316 rw [abs_mul, abs_of_pos (inv_pos.mpr hhi0)]
317 exact mul_le_of_le_one_left (inv_nonneg.mpr hhi0.le) (hFbd hi ⟨hhi, le_rfl⟩)
318 calc |(∫ x in lo..hi, F x * x⁻¹ ^ 2) + F hi * hi⁻¹|
319 ≤ |∫ x in lo..hi, F x * x⁻¹ ^ 2| + |F hi * hi⁻¹| := abs_add_le _ _
320 _ ≤ (lo⁻¹ - hi⁻¹) + hi⁻¹ := add_le_add hFbound hFh
321 _ = 1 / lo := by ring
322
323end L13Aux
324end E424
325