Pratik Patil

HarmonicAncillaRate.lean

1module23public import Mathlib.NumberTheory.Harmonic.Defs4public import Mathlib.Analysis.SpecialFunctions.Log.Basic5public import Mathlib.Analysis.Asymptotics.Defs6import all SubentropyCertificates.AncillaLogRemainder78/-! The finite remainder for the binary maximally mixed example in Section 6.3. -/9@[expose] public section10noncomputable section11open Asymptotics Filter1213namespace SubentropyCertificates.AncillaExamples1415private def corrected (n : ℕ) : ℝ :=16  Real.log n - (harmonic n : ℝ) + 1 / (2 * (n : ℝ))1718private theorem corrected_step (n : ℕ) (hn : 0 < n) :19    |corrected (n + 1) - corrected n| ≤ 1 / (2 * (n : ℝ)^3) := by20  let u := 1 / (n : ℝ)21  have hn' : (0 : ℝ) < n := by exact_mod_cast hn22  have hu : 0 ≤ u := by dsimp [u]; positivity23  have hlog : Real.log ((n : ℝ) + 1) = Real.log (n : ℝ) + Real.log (1 + u) := by24    rw [← Real.log_mul hn'.ne' (by positivity : 1 + u ≠ 0)]25    congr 126    dsimp [u]27    field_simp28  let err := Real.log (1 + u) - u + u^2/229  have herr := AncillaLimit.log_quadratic_error hu30  have hid : corrected (n + 1) - corrected n = err - u^3/(2*(1+u)) := by31    simp only [corrected, harmonic_succ, Rat.cast_add, Rat.cast_inv, Rat.cast_natCast,32      Nat.cast_add, Nat.cast_one, hlog, err]33    dsimp [u]34    field_simp [hn'.ne', show (n : ℝ)+1 ≠ 0 by positivity]35    ring36  have hterm : u^3/(2*(1+u)) ≤ u^3/2 := by37    apply div_le_div_of_nonneg_left (by positivity) (by norm_num)38    linarith39  have hbound : |err - u^3/(2*(1+u))| ≤ u^3/2 := by40    apply abs_le.mpr41    constructor42    · linarith [show 0 ≤ err from herr.1]43    · linarith [show err ≤ u^3/3 from herr.2, show 0 ≤ u^3/(2*(1+u)) by positivity,44        show 0 ≤ u^3 by positivity]45  rw [hid]46  convert hbound using 147  dsimp [u]48  ring4950/-- In every dimension d≥1 the remainder after the term 1/(4d) is at most 1/(2d²). -/51theorem harmonic_ancilla_remainder (d : ℕ) (hd : 0 < d) :52    |Real.log 2 - (harmonic (2*d) : ℝ) + (harmonic d : ℝ) - 1 / (4*(d:ℝ))| ≤53      1 / (2*(d:ℝ)^2) := by54  have hd' : (0 : ℝ) < d := by exact_mod_cast hd55  have hseg (r : ℕ) : |corrected (d+r) - corrected d| ≤ (r : ℝ) / (2*(d:ℝ)^3) := by56    induction r with57    | zero => simp58    | succ r ih =>59      have hstep := corrected_step (d+r) (by omega)60      have hsmall : 1 / (2*((d+r : ℕ) : ℝ)^3) ≤ 1 / (2*(d:ℝ)^3) := by61        apply one_div_le_one_div_of_le (by positivity)62        gcongr63        exact_mod_cast Nat.le_add_right d r64      calc65        |corrected (d+(r+1)) - corrected d| ≤66            |corrected ((d+r)+1) - corrected (d+r)| + |corrected (d+r) - corrected d| := by67          simpa only [Nat.add_assoc] using abs_sub_le (corrected ((d+r)+1))68            (corrected (d+r)) (corrected d)69        _ ≤ 1 / (2*(d:ℝ)^3) + (r : ℝ) / (2*(d:ℝ)^3) := add_le_add (hstep.trans hsmall) ih70        _ = _ := by push_cast; ring71  have hlog := Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) hd'.ne'72  have he : corrected (d+d) - corrected d =73      Real.log 2 - (harmonic (2*d) : ℝ) + (harmonic d : ℝ) - 1 / (4*(d:ℝ)) := by74    rw [← two_mul, corrected, corrected, Nat.cast_mul, Nat.cast_ofNat, hlog]75    field_simp76    ring77  rw [← he]78  convert hseg d using 179  field_simp8081/-- The asymptotic expansion in Section 6.3, with dimension tending to infinity. -/82theorem harmonic_ancilla_asymptotic :83    (fun d : ℕ ↦ Real.log 2 - (harmonic (2*d) : ℝ) + (harmonic d : ℝ) - 1/(4*(d:ℝ)))84      =O[atTop] (fun d : ℕ ↦ 1/(d:ℝ)^2) := by85  refine isBigO_iff.mpr ⟨1/2, ?_⟩86  filter_upwards [eventually_gt_atTop 0] with d hd87  rw [Real.norm_eq_abs, Real.norm_of_nonneg (by positivity : 0 ≤ 1 / (d : ℝ)^2)]88  calc89    _ ≤ 1/(2*(d:ℝ)^2) := harmonic_ancilla_remainder d hd90    _ = _ := by ring9192end SubentropyCertificates.AncillaExamples93

Axioms used

Choose a statement to see which axioms its proof uses.