Pratik Patil

LogEnclosure.lean

1module23public import Mathlib.Analysis.SpecialFunctions.Log.Deriv4public import Mathlib.Tactic56/-! Rational enclosures of the logarithm used in Appendix F.2. -/7@[expose] public section8noncomputable section9open Finset Set Real10namespace SubentropyCertificates.LogEnclosure1112/-- Half the remainder of the logarithm series, with the denominator 2N+113that is used in the paper's numerical certificates. -/14theorem half_log_error {z : ℝ} (hz : 0 ≤ z) (hz1 : z < 1) (N : ℕ) :15    let s := ∑ i ∈ range N, z ^ (2*i+1) / (2*i+1 : ℝ)16    0 ≤ 1/2 * log ((1+z)/(1-z)) - s ∧17      1/2 * log ((1+z)/(1-z)) - s ≤ z^(2*N+1)/((2*N+1 : ℝ)*(1-z^2)) := by18  dsimp only19  refine ⟨sub_nonneg.mpr (sum_range_le_log_div hz hz1 N), ?_⟩20  let C : ℝ := (2*N+1 : ℝ)*(1-z^2)21  let F (x : ℝ) := x^(2*N+1)/C -22    (1/2 * log ((1+x)/(1-x)) - ∑ i ∈ range N, x^(2*i+1)/(2*i+1 : ℝ))23  have hzsq : 0 < 1-z^2 := by nlinarith [mul_pos (sub_pos.mpr hz1) (by linarith : 0 < 1+z)]24  have hD (x : ℝ) (hx : x ∈ Icc 0 z) :25      HasDerivAt F (x^(2*N)/(1-z^2) - (x^2)^N/(1-x^2)) x := by26    have hp := (hasDerivAt_pow (2*N+1) x).div_const C27    have h := hp.sub (hasDerivAt_half_log_one_add_div_one_sub_sub_sum_range N28      (by linarith [hx.1]) (lt_of_le_of_lt hx.2 hz1))29    apply h.congr_deriv30    dsimp [C]31    push_cast32    field_simp33  have hm : MonotoneOn F (Icc 0 z) := by34    refine monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 z)35      (fun x hx ↦ (hD x hx).continuousAt.continuousWithinAt)36      (fun x hx ↦ (hD x (interior_subset hx)).hasDerivWithinAt) ?_37    intro x hx38    have hx' := interior_subset hx39    rw [sub_nonneg, ← pow_mul]40    exact div_le_div_of_nonneg_left (pow_nonneg hx'.1 _) hzsq41      (sub_le_sub_left (pow_le_pow_left₀ hx'.1 hx'.2 2) _)42  have h := hm (show 0 ∈ Icc 0 z from ⟨le_rfl,hz⟩) ⟨hz,le_rfl⟩ hz43  simpa [F, C, sub_nonneg] using h4445/-- The two-sided enclosure applies in particular to rational y in [1,2],46including the endpoint used to enclose log 2. -/47theorem rational_log_enclosure {y : ℝ} (hy : 1 ≤ y) (N : ℕ) :48    let z := (y-1)/(y+1)49    let s := ∑ i ∈ range N, z^(2*i+1)/(2*i+1 : ℝ)50    0 ≤ log y - 2*s ∧ log y - 2*s ≤ 2*z^(2*N+1)/((2*N+1 : ℝ)*(1-z^2)) := by51  dsimp only52  let z := (y-1)/(y+1)53  have hp : 0 < y+1 := by linarith54  have h0 : 0 ≤ z := div_nonneg (sub_nonneg.mpr hy) hp.le55  have h1 : z < 1 := (div_lt_one hp).mpr (by linarith)56  have hfrac : (1+z)/(1-z) = y := by57    apply (div_eq_iff (sub_pos.mpr h1).ne').mpr58    dsimp [z]59    field_simp60    ring61  have h := half_log_error h0 h1 N62  dsimp only at h63  rw [hfrac] at h64  change 0 ≤ log y - 2*_ ∧ log y - 2*_ ≤ 2*z^(2*N+1)/_65  rw [mul_div_assoc]66  constructor <;> linarith [h.1,h.2]6768end SubentropyCertificates.LogEnclosure

Axioms used

Choose a statement to see which axioms its proof uses.