Alternating Series
A series whose terms switch sign at every step can converge even when the sizes of its terms add up to infinity. This lesson proves the alternating series test, derives its remainder bound, and shows why the order in which a computer adds such terms matters.
For a first look at the test, see Convergence Tests. Here we prove it.
The setting
An alternating series has the form
The comparison and integral tests from The Comparison Tests and The Integral Test only handle positive terms, so they cannot see the cancellation that makes these series converge.
The Alternating Series Test
Theorem. If (i) for all (the sizes never grow) and (ii) , then converges.
Proof. Look at the even partial sums . Group the terms in pairs:
Each bracket is by (i), so is non-decreasing. Group differently:
Every bracket is and , so . A non-decreasing sequence bounded above converges (the Monotone Sequence Theorem from Sequences), say . For the odd sums, by (ii). Both subsequences tend to , so . ∎
The picture behind the proof: odd partial sums step down, even partial sums step up, and the two interleaved sequences squeeze s between them.
The remainder bound
Because always lies between two consecutive partial sums, the distance from to is less than the distance from to , which is :
That is a guaranteed error bar, not an estimate. It is why alternating series are popular in numerical code: you know when to stop.
import math
# s = ∑ (−1)^(n−1) / n³; exact value is (3/4)·ζ(3)
exact = 0.75 * 1.2020569031595942
s = 0.0
for n in range(1, 11):
s += (-1) ** (n - 1) / n**3
bound = 1 / (n + 1) ** 3
print(f"n={n:2d} s_n={s:.8f} |error|={abs(exact - s):.2e} bound={bound:.2e} {'below' if s < exact else 'above'}")n= 1 s_n=1.00000000 |error|=9.85e-02 bound=1.25e-01 above
n= 2 s_n=0.87500000 |error|=2.65e-02 bound=3.70e-02 below
n= 3 s_n=0.91203704 |error|=1.05e-02 bound=1.56e-02 above
n= 4 s_n=0.89641204 |error|=5.13e-03 bound=8.00e-03 below
n= 5 s_n=0.90441204 |error|=2.87e-03 bound=4.63e-03 above
n= 6 s_n=0.89978241 |error|=1.76e-03 bound=2.92e-03 below
n= 7 s_n=0.90269786 |error|=1.16e-03 bound=1.95e-03 above
n= 8 s_n=0.90074473 |error|=7.98e-04 bound=1.37e-03 below
n= 9 s_n=0.90211648 |error|=5.74e-04 bound=1.00e-03 above
n=10 s_n=0.90111648 |error|=4.26e-04 bound=7.51e-04 below
The partial sums alternate above and below the limit, and every error is under its bound, exactly as the proof predicts.
Tip: Averaging two consecutive partial sums, , usually lands much closer to than either one, because sits between them. Repeating that idea gives Euler's transformation and other series accelerators.
Both conditions matter
- Without the test fails trivially: diverges because its terms do not tend to 0 (Test for Divergence).
- Without monotonicity the conclusion can fail. Take for odd and for even . Then , but the positive terms alone add up like (divergent) while the negative terms add to a finite number, so the series diverges to .
Monotonicity only needs to hold eventually: dropping finitely many terms never changes convergence. To check it, show for the function with .
Conditional convergence and rearrangements
The alternating harmonic series converges (to ), but diverges. A convergent series whose absolute values diverge is conditionally convergent; the next lesson, Absolute Convergence and the Ratio and Root Tests, covers the stronger kind.
Riemann's rearrangement theorem (sketch). For a conditionally convergent series, both the positive terms and the negative terms diverge on their own (if one part converged, the other would equal the convergent total minus it, and would converge). Pick any target . Take positive terms until the running sum passes , then negative terms until it drops below , and repeat. Since each part has infinite total you can always cross again, and since the terms tend to 0 the overshoots shrink to 0. The rearranged series converges to .
import math
def rearranged(target, steps):
pos, neg, s = 1, 2, 0.0 # next odd and even denominators
for _ in range(steps):
if s <= target:
s += 1 / pos; pos += 2
else:
s -= 1 / neg; neg += 2
return s
print(f"natural order (10⁵ terms): {sum((-1)**(k-1)/k for k in range(1, 100001)):.5f} ln 2 = {math.log(2):.5f}")
for T in (-1.0, 0.25, 2.0):
print(f"rearranged toward {T:+.5f}: {rearranged(T, 200000):+.5f}")natural order (10⁵ terms): 0.69314 ln 2 = 0.69315
rearranged toward -1.00000: -0.99995
rearranged toward +0.25000: +0.25000
rearranged toward +2.00000: +1.99999
Same terms, different order, different sum. The small misses are the overshoots, which shrink as more terms are used.
In software
Floating-point addition is not associative, so summation order matters for any series, and alternating ones make it worse: large partial sums cancel and the rounding errors made along the way stay behind.
import math
terms = [(-1) ** (k - 1) / k for k in range(1, 200001)]
fwd = 0.0
for t in terms:
fwd += t
bwd = 0.0
for t in reversed(terms):
bwd += t
pairs = 0.0
for k in range(1, 200001, 2):
pairs += 1 / (k * (k + 1)) # (1/k − 1/(k+1)) combined exactly first
print(f"forward {fwd:.17f}")
print(f"backward {bwd:.17f}")
print(f"pairs {pairs:.17f}")
print(f"fsum {math.fsum(terms):.17f}")forward 0.69314468056623324
backward 0.69314468056619538
pairs 0.69314468056619072
fsum 0.69314468056619527
Against the fsum reference, the forward loop is off in the 14th digit, the backward loop in the 17th.
- Adding small terms first (backward) loses less, because the small terms are not swamped by a large running total.
- Pairing the terms into turns the alternating series into a positive one, removing the cancellation.
math.fsumtracks the lost low-order bits exactly; NumPy'snp.sumuses pairwise summation, a cheaper middle ground.
Exercises
Exercise 1: Apply the test
Does converge? Absolutely or conditionally?
Answer
It converges conditionally.
Solution
Exercise 2: Eventually decreasing
Show that converges. From which are the terms decreasing?
Answer
It converges; the terms decrease from on (, then ).
Solution
Exercise 3: Terms for an accuracy
How many terms of ( from 0) guarantee the sum to within ? Check numerically.
Answer
Terms (10 terms), because the first omitted term (while is not).
Solution
The error after stopping at is at most . We need : is too small, works, so .
import math
s = sum((-1) ** n / math.factorial(n) for n in range(10))
print(f"error = {abs(s - math.exp(-1)):.3e}, bound = {1 / math.factorial(10):.3e}")error = 2.525e-07, bound = 2.756e-07
Exercise 4: A rearrangement by formula
Rearrange the alternating harmonic series as "one positive, two negative": . Show the sum is and check with code.
Answer
The sum is .
Solution
import math
s = 0.0
for k in range(1, 200001):
s += 1 / (2 * k - 1) - 1 / (4 * k - 2) - 1 / (4 * k)
print(f"{s:.6f} {math.log(2) / 2:.6f}")0.346573 0.346574
Test yourself
A series satisfies the alternating series test and you stop after 20 terms. . What do you know about the error?
- It is exactly 0.003
- It is at most 0.003
- It is at least 0.003
- Nothing without more terms
Which statement about a conditionally convergent series is true?
- Every rearrangement has the same sum
- Its positive terms alone form a convergent series
- Some rearrangement converges to any real number you choose
- It must be alternating
In the proof of the AST, what kind of sequence are the even partial sums ?
- Non-decreasing and bounded above by
- Decreasing to 0
- Unbounded
- Constant