Power Series
A power series is a polynomial that never ends. Inside its interval of convergence it behaves like an ordinary function: you can evaluate it, differentiate it and integrate it term by term. That makes power series the way to turn functions like , and into plain arithmetic a computer can do.
Definition
is the centre and the are the coefficients. For each value of this is an ordinary series that either converges or diverges.
Radius and interval of convergence
Every power series has a radius of convergence (possibly 0 or ):
- it converges (absolutely) when ,
- it diverges when ,
- at the two endpoints anything can happen; check them separately.
The ratio test usually finds . For : , so . At it is the harmonic series (diverges), at the alternating harmonic series (converges): the interval is .
| Series | Function | Radius |
|---|---|---|
| 1 | ||
| 1 | ||
| () | 1 | |
| 1 | ||
The first row is the geometric series with ratio . Watch what happens inside and outside the radius:
def partial(x, terms):
return sum(x**n for n in range(terms))
for x in [0.5, 0.9, 1.5]:
sums = [round(partial(x, t), 4) for t in (5, 20, 80)]
target = 1 / (1 - x)
print(f"x={x}: partial sums {sums} 1/(1-x) = {target:.4f}")x=0.5: partial sums [1.9375, 2.0, 2.0] 1/(1-x) = 2.0000
x=0.9: partial sums [4.0951, 8.7842, 9.9978] 1/(1-x) = 10.0000
x=1.5: partial sums [13.1875, 6648.5135, 244529196111407.28] 1/(1-x) = -2.0000
At it converges quickly, at slowly (close to the edge), and at it explodes even though is a perfectly good number there. The function exists outside the radius; the series just stops representing it.
Calculus term by term
Inside the radius you can differentiate or integrate each term, and the radius stays the same. Starting from the geometric series:
Putting into the arctan series gives the Leibniz series . It converges painfully slowly because sits on the edge of the interval. Machin's formula evaluates the same series at small , where it converges fast. Formulas like it were used to compute to millions of digits.
import math
def arctan_series(x, terms):
return sum((-1) ** n * x ** (2 * n + 1) / (2 * n + 1) for n in range(terms))
for terms in [10, 1000]:
leibniz = 4 * arctan_series(1, terms)
print(f"Leibniz, {terms:4d} terms: {leibniz:.12f} error {abs(leibniz - math.pi):.1e}")
for terms in [5, 10]:
machin = 4 * (4 * arctan_series(1 / 5, terms) - arctan_series(1 / 239, terms))
print(f"Machin, {terms:4d} terms: {machin:.12f} error {abs(machin - math.pi):.1e}")Leibniz, 10 terms: 3.041839618929 error 1.0e-01
Leibniz, 1000 terms: 3.140592653840 error 1.0e-03
Machin, 5 terms: 3.141592682404 error 2.9e-08
Machin, 10 terms: 3.141592653590 error 1.3e-15
In software: evaluating polynomials with Horner's method
A truncated power series is a polynomial, and the standard way to evaluate one is Horner's method: rewrite as . It needs only multiplications and additions, no powers, and is more accurate in floating point. Math libraries, shader code and fixed-point DSP code all evaluate their approximations this way.
import math
def horner(coeffs, x): # coeffs lowest power first
result = 0.0
for c in reversed(coeffs):
result = result * x + c
return result
# first 12 terms of the series for e^x: c_n = 1/n!
coeffs = [1 / math.factorial(n) for n in range(12)]
for x in [0.5, 1.0, 2.0]:
print(f"x={x}: Horner {horner(coeffs, x):.10f} math.exp {math.exp(x):.10f}")x=0.5: Horner 1.6487212707 math.exp 1.6487212707
x=1.0: Horner 2.7182818262 math.exp 2.7182818285
x=2.0: Horner 7.3890460157 math.exp 7.3890560989
Twelve terms agree with math.exp to all ten digits at , but the error grows with (about at ). Real libraries therefore first shrink into a small range, as the next lesson shows.
Generating functions in combinatorics are another use: an algorithm's counting problem becomes the coefficients of a power series, and algebra on the series (like the geometric-series trick) solves it.
Exercises
Exercise 1: Find the radius
Find the radius of convergence of and its sum inside that radius.
Answer
; the sum is .
Solution
Exercise 2: Infinite radius
Use the ratio test to show that converges for every .
Answer
.
Solution
Exercise 3: Build a new series
Starting from , find a power series for and use it to compute .
Answer
; .
Solution
Exercise 4: two ways
The series for at converges slowly. Since and , compare 20 terms of each.
Answer
at : error about ; at : error about .
Solution
import math
slow = sum((-1) ** (n + 1) / n for n in range(1, 21))
fast = sum(0.5**n / n for n in range(1, 21))
print(f"slow: {slow:.10f} error {abs(slow - math.log(2)):.1e}")
print(f"fast: {fast:.10f} error {abs(fast - math.log(2)):.1e}")slow: 0.6687714032 error 2.4e-02
fast: 0.6931471371 error 4.4e-08
Evaluating a series well inside its radius is far more efficient than at the edge.
Test yourself
What is the radius of convergence of ?
- 2
- 1
Integrating the series for term by term gives the series of which function?
Why is Horner's method preferred for evaluating polynomials?
- It uses fewer multiplications and avoids computing powers
- It is exact in floating point
- It works only for even polynomials
- It finds the roots