Skip to content

Commit 49c9359

Browse files
feat(SpecialFunctions/Log): tight bounds on artanh(x) (leanprover-community#31487)
We provide tight bounds, thanks to Taylor series, on `1/2 (log ((1+x)/(1-x)))`. It is more convenient, however, to avoid Taylor series in the proof, since the geometric sum formula can be used to more easily calculate the difference. From the [exponential-ramsey project](https://github.com/b-mehta/exponential-ramsey/blob/main/src/log_small.lean), and used to give [very tight estimates on logs (Zulip)](https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/A.20million.20digits.20of.20log.202/with/554793210). Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 6a9728e commit 49c9359

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Mathlib/Analysis/SpecialFunctions/Log/Deriv.lean

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public import Mathlib.Analysis.Calculus.Deriv.Pow
99
public import Mathlib.Analysis.Calculus.LogDeriv
1010
public import Mathlib.Analysis.SpecialFunctions.Log.Basic
1111
public import Mathlib.Analysis.SpecialFunctions.ExpDeriv
12+
public import Mathlib.Analysis.Calculus.Deriv.MeanValue
1213
public import Mathlib.Tactic.AdaptationNote
1314

1415
/-!
@@ -253,6 +254,100 @@ theorem abs_log_sub_add_sum_range_le {x : ℝ} (h : |x| < 1) (n : ℕ) :
253254
-- fourth step: conclude by massaging the inequality of the third step
254255
simpa [F, div_mul_eq_mul_div, pow_succ] using C
255256

257+
-- see https://github.com/leanprover-community/mathlib4/issues/29041
258+
set_option linter.unusedSimpArgs false in
259+
/--
260+
Compute the derivative of the difference between $\frac{1}{2} * \log(\frac{1+x}{1-x})$ and its
261+
Taylor series at `0` up to order `n`. This is an auxiliary lemma for
262+
`sum_range_sub_log_div_le` and `sum_range_le_log_div`.
263+
Note that thanks to the geometric series, the derivative has a particularly simple form, and means
264+
that it is more convenient to avoid Taylor's theorem.
265+
-/
266+
lemma hasDerivAt_half_log_one_add_div_one_sub_sub_sum_range
267+
{y : ℝ} (n : ℕ) (hy₁ : -1 < y) (hy₂ : y < 1) :
268+
HasDerivAt
269+
(fun x ↦ 1 / 2 * log ((1 + x) / (1 - x)) - (∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1)))
270+
((y ^ 2) ^ n / (1 - y ^ 2)) y := by
271+
refine ((((((hasDerivAt_id _).const_add _).div ((hasDerivAt_id _).const_sub _) (by grind)).log
272+
?_).const_mul _).sub (HasDerivAt.fun_sum fun i hi ↦ (hasDerivAt_pow _ _).div_const _))
273+
|>.congr_deriv ?_
274+
· simp only [id_eq, div_ne_zero_iff, Pi.div_apply]; grind
275+
have : (∑ i ∈ range n, (2*i+1) * y ^ (2*i) / (2*i+1)) = (∑ i ∈ range n, (y^2) ^ i) := by
276+
congr with i
277+
simp [field, mul_comm, ← pow_mul]
278+
have hy₃ : y ^ 21 := by simp [hy₁.ne', hy₂.ne]
279+
have hy₄ : (1 - y) * (1 + y) = 1 - y ^ 2 := by ring
280+
simp [this, field, geom_sum_eq hy₃, hy₄, sub_ne_zero_of_ne, hy₃.symm]
281+
ring
282+
283+
/-- A lemma estimating the difference between $\frac{1}{2} * \log(\frac{1+x}{1-x})$ and its
284+
Taylor series at `0`, where the bound tends to `0`. This bound is particularly useful for explicit
285+
estimates of logarithms.
286+
287+
Note that thanks to the geometric series, the derivative has a particularly simple form, and means
288+
that it is more convenient to avoid Taylor's theorem for this proof.
289+
-/
290+
lemma sum_range_sub_log_div_le {x : ℝ} (h : |x| < 1) (n : ℕ) :
291+
|1 / 2 * log ((1 + x) / (1 - x)) - ∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1)| ≤
292+
|x| ^ (2 * n + 1) / (1 - x ^ 2) := by
293+
let F (x : ℝ) : ℝ :=
294+
1 / 2 * log ((1 + x) / (1 - x)) - (∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1))
295+
let F' (y : ℝ) : ℝ := (y ^ 2) ^ n / (1 - y ^ 2)
296+
have hI : Icc (-|x|) |x| ⊆ Ioo (-1 : ℝ) 1 := Icc_subset_Ioo (by simp [h]) h
297+
-- First step: compute the derivative of `F`
298+
have A : ∀ y ∈ Ioo (-1 : ℝ) 1, HasDerivAt F (F' y) y := by
299+
intro y hy
300+
exact hasDerivAt_half_log_one_add_div_one_sub_sub_sum_range _ (by grind) (by grind)
301+
-- second step: show that the derivative of `F` is small
302+
have B : ∀ y ∈ Set.Icc (-|x|) |x|, ‖F' y‖ ≤ |x| ^ (2 * n) / (1 - x ^ 2) := fun y hy ↦ by
303+
have : y ^ 2 ≤ x ^ 2 := sq_le_sq.2 (abs_le.2 hy)
304+
calc
305+
‖F' y‖ = (y ^ 2) ^ n / |1 - y ^ 2| := by simp [F']
306+
_ = (y ^ 2) ^ n / (1 - y ^ 2) := by rw [abs_of_pos (by simpa [abs_lt] using hI hy)]
307+
_ ≤ (x ^ 2) ^ n / (1 - x ^ 2) := by gcongr ?_ ^ n / (1 - ?_); simpa [abs_lt] using h
308+
_ ≤ |x| ^ (2 * n) / (1 - x ^ 2) := by simp [pow_mul]
309+
-- third step: apply the mean value inequality
310+
have C : ‖F x - F 0‖ ≤ |x| ^ (2 * n) / (1 - x^2) * ‖x - 0‖ :=
311+
(convex_Icc (-|x|) |x|).norm_image_sub_le_of_norm_hasDerivWithin_le
312+
(fun y hy ↦ (A _ (hI hy)).hasDerivWithinAt) B
313+
(by simp) (by simp [le_abs_self, neg_le, neg_le_abs x])
314+
-- fourth step: conclude by massaging the inequality of the third step
315+
simpa [F, pow_succ, div_mul_eq_mul_div] using C
316+
317+
/--
318+
For `0 ≤ x < 1`, the partial sums of the series expansion of $\frac{1}{2} * \log(\frac{1+x}{1-x})$
319+
at `0` form a lower bound for it. This shows that the absolute value in `sum_range_sub_log_div_le`
320+
can be dropped, and gives explicit lower bounds for logarithms.
321+
-/
322+
lemma sum_range_le_log_div {x : ℝ} (h₀ : 0 ≤ x) (h : x < 1) (n : ℕ) :
323+
∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1) ≤ 1 / 2 * log ((1 + x) / (1 - x)) := by
324+
let F (x : ℝ) : ℝ :=
325+
1 / 2 * log ((1 + x) / (1 - x)) - (∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1))
326+
let F' (y : ℝ) : ℝ := (y ^ 2) ^ n / (1 - y ^ 2)
327+
-- First step: compute the derivative of `F`
328+
have A : ∀ y ∈ Icc 0 x, HasDerivAt F (F' y) y := by
329+
intro y hy
330+
exact hasDerivAt_half_log_one_add_div_one_sub_sub_sum_range _ (by grind) (by grind)
331+
-- It suffices to show that `F` is monotone on `[0, x]`
332+
suffices MonotoneOn F (Icc 0 x) by simpa [F] using this ⟨le_rfl, h₀⟩ ⟨h₀, le_rfl⟩ h₀
333+
-- Second step: show that the derivative of `F` is nonnegative; it has been computed already.
334+
refine monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 x)
335+
(fun y hy ↦ (A y hy).continuousAt.continuousWithinAt)
336+
(fun y hy ↦ (A y (interior_subset hy)).hasDerivWithinAt) ?_
337+
intro y hy
338+
simp only [interior_Icc, Set.mem_Ioo] at hy
339+
have : 01 - y ^ 2 := by calc
340+
01 - x ^ 2 := by simp [abs_of_nonneg h₀, h.le]
341+
_ ≤ 1 - y ^ 2 := sub_le_sub_left (pow_le_pow_left₀ hy.1.le hy.2.le 2) 1
342+
positivity
343+
344+
lemma log_div_le_sum_range_add {x : ℝ} (h₀ : 0 ≤ x) (h : x < 1) (n : ℕ) :
345+
1 / 2 * log ((1 + x) / (1 - x)) ≤
346+
(∑ i ∈ range n, x ^ (2 * i + 1) / (2 * i + 1)) + x ^ (2 * n + 1) / (1 - x ^ 2) := by
347+
have h₁ := sum_range_sub_log_div_le (by rwa [abs_of_nonneg h₀]) n
348+
rwa [abs_of_nonneg (sub_nonneg_of_le (sum_range_le_log_div h₀ h n)), abs_of_nonneg h₀,
349+
sub_le_iff_le_add'] at h₁
350+
256351
/-- Power series expansion of the logarithm around `1`. -/
257352
theorem hasSum_pow_div_log_of_abs_lt_one {x : ℝ} (h : |x| < 1) :
258353
HasSum (fun n : ℕ => x ^ (n + 1) / (n + 1)) (-log (1 - x)) := by

0 commit comments

Comments
 (0)