Zulip Chat Archive

Stream: Is there code for X?

Topic: error term for summable alternating series?


Kim Morrison (Sep 04 2025 at 09:51):

import Mathlib

open Filter Finset Topology

example (f : β„• β†’ ℝ) (hfa : Antitone f) (hfs : Summable f)
    (hf0 : Tendsto f atTop (𝓝 0)) (n : β„•) :
    |(βˆ‘' i : β„•, (-1) ^ i * f i) - (βˆ‘ i ∈ range n, (-1) ^ i * f i)| ≀ f n :=
  sorry

SΓ©bastien GouΓ«zel (Sep 04 2025 at 09:56):

We have docs#Antitone.alternating_series_le_tendsto and docs#Antitone.tendsto_le_alternating_series which should imply your estimate, separating even and odd cases.

Kim Morrison (Sep 04 2025 at 11:38):

namespace Summable

open Filter Finset
open Topology

theorem alternating {f : β„• β†’ ℝ} (hf : Summable f) :
    Summable (fun n => (-1) ^ n * f n) :=
  Summable.of_abs (by simpa [summable_abs_iff])

theorem tendsto_alternating_series_tsum {f : β„• β†’ ℝ} (hfs : Summable f) :
    Tendsto (fun n => (βˆ‘ i ∈ range n, (-1) ^ i * f i)) atTop (𝓝 (βˆ‘' i : β„•, (-1) ^ i * f i)) :=
  Summable.tendsto_sum_tsum_nat hfs.alternating

theorem alternating_series_error_bound
    (f : β„• β†’ ℝ) (hfa : Antitone f) (hfs : Summable f) (n : β„•) :
    |(βˆ‘' i : β„•, (-1) ^ i * f i) - (βˆ‘ i ∈ range n, (-1) ^ i * f i)| ≀ f n := by
  obtain h := hfs.tendsto_alternating_series_tsum
  have upper := hfa.alternating_series_le_tendsto h
  have lower := hfa.tendsto_le_alternating_series h
  obtain (h | h) := even_or_odd n
  · obtain ⟨n, rfl⟩ := even_iff_exists_two_mul.mp h
    specialize upper n
    specialize lower n
    simp [Finset.sum_range_succ] at lower
    rw [abs_sub_le_iff]
    constructor <;> linarith
  · obtain ⟨n, rfl⟩ := odd_iff_exists_bit1.mp h
    specialize upper (n + 1)
    specialize lower n
    rw [Nat.mul_add, Finset.sum_range_succ,
      show (-1 : ℝ) ^ (2 * n + 1) = -1 by simp [pow_add]] at upper
    rw [abs_sub_le_iff]
    constructor <;> linarith

end Summable

seems to serve my purpose, thank you.

Kim Morrison (Sep 12 2025 at 05:20):

#29577

Jeremy Tan (Sep 12 2025 at 05:54):

Kim Morrison said:

#29577

I did some work in that direction in #10120; cf. #Is there code for X? > Bounds on alternating convergent series @ πŸ’¬

Jeremy Tan (Sep 12 2025 at 05:54):

docs#Monotone.tendsto_le_alternating_series

Jeremy Tan (Sep 12 2025 at 05:55):

wait… you used my lemmas?

Kim Morrison (Sep 12 2025 at 06:30):

That's why they call them lemmas. :-)


Last updated: Dec 20 2025 at 21:32 UTC