TExcelTAD
Home › Calculus in Depth › Representations of Functions as Power Series

Representations of Functions as Power Series

Starting from one series you already know, the geometric series, you can build series for ln⁡(1+x)\ln(1 + x), arctan⁡x\arctan x and many more by substituting, multiplying, differentiating and integrating term by term. This lesson states the theorem that allows that, sketches why it holds, and uses the results to compute π\pi and to see why numerical libraries ship a log1p function.

The Power Series lesson covered radius and interval of convergence; read it first.

The seed: the geometric series

11−x=∑n=0∞xn=1+x+x2+x3+⋯for ∣x∣<1\frac{1}{1 - x} = \sum_{n=0}^{\infty} x^n = 1 + x + x^2 + x^3 + \cdots \qquad \text{for } \lvert x \rvert < 1

Algebraic substitutions turn it into series for related functions. The radius follows from the substitution.

Function Substitution Series Valid for
1/(1+x)1/(1 + x) x→−xx \to -x ∑(−1)nxn\sum (-1)^n x^n ∣x∣<1\lvert x \rvert < 1
1/(1+x2)1/(1 + x^2) x→−x2x \to -x^2 ∑(−1)nx2n\sum (-1)^n x^{2n} ∣x∣<1\lvert x \rvert < 1
1/(3−x)1/(3 - x) 1/(3(1−x/3))1/(3(1 - x/3)) ∑xn/3n+1\sum x^n/3^{n+1} ∣x∣<3\lvert x \rvert < 3
x3/(1−2x)x^3/(1 - 2x) x→2xx \to 2x, times x3x^3 ∑2nxn+3\sum 2^n x^{n+3} ∣x∣<1/2\lvert x \rvert < 1/2

Term-by-term differentiation and integration

Theorem. If f(x)=∑cn(x−a)nf(x) = \sum c_n(x - a)^n has radius of convergence R>0R > 0, then ff is differentiable on (a−R,a+R)(a - R, a + R) and

f′(x)=∑n=1∞ncn(x−a)n−1∫f(x) dx=C+∑n=0∞cn(x−a)n+1n+1\begin{aligned} f'(x) &= \sum_{n=1}^{\infty} n c_n (x - a)^{n-1} \\ \int f(x)\,dx &= C + \sum_{n=0}^{\infty} c_n \frac{(x - a)^{n+1}}{n + 1} \end{aligned}

and both new series have the same radius RR.

Why the radius does not change. By Cauchy–Hadamard, 1/R=lim sup⁡∣cn∣1/n1/R = \limsup \lvert c_n \rvert^{1/n}. Multiplying cnc_n by nn or dividing by n+1n + 1 multiplies the nn-th root by n1/nn^{1/n} or (n+1)−1/n(n + 1)^{-1/n}, and both tend to 1 (take logs: ln⁡n/n→0\ln n / n \to 0). So the lim sup, and hence RR, is unchanged.

Why the derivative is the series of derivatives (sketch). Fix xx with ∣x−a∣<r<R\lvert x - a \rvert < r < R. On [a−r,a+r][a - r, a + r] the terms obey ∣cn(x−a)n∣≤∣cn∣rn\lvert c_n(x - a)^n \rvert \le \lvert c_n \rvert r^n, and ∑∣cn∣rn\sum \lvert c_n \rvert r^n converges. So the series converges uniformly there (the Weierstrass M-test), and the same holds for the differentiated series. Uniform convergence lets limits pass through integrals: integrating the differentiated series term by term gives back f(x)−f(a)f(x) - f(a), and the Fundamental Theorem of Calculus then says f′f' equals the differentiated series. A full proof is in Proofs of Theorems.

Note: Endpoints can change. ∑xn/n2\sum x^n/n^2 converges on [−1,1][-1, 1], but its derivative ∑xn−1/n\sum x^{n-1}/n converges only on [−1,1)[-1, 1). Integration can gain endpoints, differentiation can lose them, so recheck them each time.

Two important series

ln⁡(1+x)\ln(1 + x). Integrate 1/(1+t)=∑(−1)ntn1/(1 + t) = \sum (-1)^n t^n from 0 to xx:

ln⁡(1+x)=∑n=1∞(−1)n−1xnn=x−x22+x33−⋯for −1<x≤1\ln(1 + x) = \sum_{n=1}^{\infty} (-1)^{n-1} \frac{x^n}{n} = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots \qquad \text{for } -1 < x \le 1

At x=1x = 1 the series still converges (alternating harmonic), and Abel's theorem on continuity at the endpoint gives 1−12+13−⋯=ln⁡21 - \frac{1}{2} + \frac{1}{3} - \cdots = \ln 2.

arctan⁡x\arctan x. Integrate 1/(1+t2)=∑(−1)nt2n1/(1 + t^2) = \sum (-1)^n t^{2n}:

arctan⁡x=∑n=0∞(−1)nx2n+12n+1=x−x33+x55−⋯for −1≤x≤1\arctan x = \sum_{n=0}^{\infty} (-1)^n \frac{x^{2n+1}}{2n + 1} = x - \frac{x^3}{3} + \frac{x^5}{5} - \cdots \qquad \text{for } -1 \le x \le 1

At x=1x = 1 this is Leibniz's series π/4=1−13+15−⋯\pi/4 = 1 - \frac{1}{3} + \frac{1}{5} - \cdots.

python · try it yourself
import sympy as sp

x, t = sp.symbols("x t")
geo = sum((-t**2) ** k for k in range(6))         # 1/(1 + t²) up to t¹⁰
arctan_poly = sp.integrate(geo, (t, 0, x))
print("integrated:", arctan_poly)
print("SymPy     :", sp.series(sp.atan(x), x, 0, 12).removeO())
print("difference:", sp.expand(arctan_poly - sp.series(sp.atan(x), x, 0, 12).removeO()))
integrated: -x**11/11 + x**9/9 - x**7/7 + x**5/5 - x**3/3 + x
SymPy     : -x**11/11 + x**9/9 - x**7/7 + x**5/5 - x**3/3 + x
difference: 0

SymPy lists terms from highest to lowest degree; the difference 0 confirms the two derivations agree.

Computing π\pi with arctan series

Leibniz's series converges far too slowly (the computed π\pi is off by about 1/N1/N after NN terms, as the run below shows). The fix is to evaluate arctan only at small xx, where x2n+1x^{2n+1} shrinks fast. Machin's formula (1706)

π4=4arctan⁡15−arctan⁡1239\frac{\pi}{4} = 4 \arctan\frac{1}{5} - \arctan\frac{1}{239}

follows from the tangent addition formula. Each term of arctan⁡(1/5)\arctan(1/5) gains about 1.4 decimal digits (a factor 25 per term).

python · try it yourself
from fractions import Fraction
import math

def arctan_series(x, terms):
    return sum(Fraction((-1) ** n, 2 * n + 1) * x ** (2 * n + 1) for n in range(terms))

for N in (5, 10, 20):
    leibniz = 4 * float(arctan_series(Fraction(1), N))
    machin = 4 * (4 * arctan_series(Fraction(1, 5), N) - arctan_series(Fraction(1, 239), N))
    print(f"N={N:2d}  Leibniz error={abs(leibniz - math.pi):.1e}   Machin error={abs(float(machin) - math.pi):.1e}")
N= 5  Leibniz error=2.0e-01   Machin error=2.9e-08
N=10  Leibniz error=1.0e-01   Machin error=1.3e-15
N=20  Leibniz error=5.0e-02   Machin error=0.0e+00

Twenty Machin terms already exhaust double precision (the printed error 0 means "below float resolution"). Machin-type formulas with exact rational or big-integer arithmetic computed π\pi to record lengths for 250 years; today's records use faster series (Chudnovsky), but the principle, a rapidly convergent power series evaluated at a small argument, is the same.

In software: log1p and expm1

For tiny xx, computing log(1 + x) in floating point first rounds 1+x1 + x to the nearest double, destroying most of xx's digits. The series ln⁡(1+x)=x−x2/2+x3/3−⋯\ln(1 + x) = x - x^2/2 + x^3/3 - \cdots shows the true answer is almost exactly xx, so a library can return the series directly for small arguments. That is what math.log1p (and np.log1p, and C's log1p) is for; expm1⁡(x)=ex−1\operatorname{expm1}(x) = e^x - 1 exists for the same reason.

python · try it yourself
import math

for x in (1e-5, 1e-10, 1e-15):
    naive = math.log(1 + x)
    series = x - x**2 / 2 + x**3 / 3
    print(f"x={x:.0e}  log(1+x)={naive:.15e}  log1p={math.log1p(x):.15e}  series={series:.15e}")
x=1e-05  log(1+x)=9.999950000398841e-06  log1p=9.999950000333332e-06  series=9.999950000333334e-06
x=1e-10  log(1+x)=1.000000082690371e-10  log1p=9.999999999500001e-11  series=9.999999999500001e-11
x=1e-15  log(1+x)=1.110223024625156e-15  log1p=9.999999999999995e-16  series=9.999999999999995e-16

At x=10−15x = 10^{-15} the naive result is 11% too large, while log1p and the three-term series agree to the last digit. Machine-learning code meets this constantly: the softplus activation ln⁡(1+ez)\ln(1 + e^z), log-likelihoods of probabilities near 1, and binary cross-entropy are written with log1p to stay accurate (see Logistic Regression).

Exercises

Exercise 1: Substitute

Find a power series for f(x)=x/(4+x2)f(x) = x/(4 + x^2) and its radius of convergence.

Answer

f(x)=∑n=0∞(−1)nx2n+1/4n+1f(x) = \sum_{n=0}^{\infty} (-1)^n x^{2n+1}/4^{n+1}, R=2R = 2.

Solution
x4+x2=x4⋅11+x2/4=x4∑(−x24)n=∑(−1)nx2n+14n+1Valid when x2/4<1, i.e. ∣x∣<2.\begin{aligned} \frac{x}{4 + x^2} &= \frac{x}{4} \cdot \frac{1}{1 + x^2/4} = \frac{x}{4} \sum \left(-\frac{x^2}{4}\right)^n = \sum (-1)^n \frac{x^{2n+1}}{4^{n+1}} \\ &\text{Valid when } x^2/4 < 1, \text{ i.e. } \lvert x \rvert < 2. \end{aligned}

Exercise 2: Differentiate

Differentiate the geometric series to find ∑n=1∞nxn\sum_{n=1}^{\infty} n x^n in closed form, then evaluate ∑n/3n\sum n/3^n.

Answer

∑nxn=x/(1−x)2\sum n x^n = x/(1 - x)^2 for ∣x∣<1\lvert x \rvert < 1, so ∑n/3n=3/4\sum n/3^n = 3/4.

Solution
ddx11−x=1(1−x)2=∑n=1∞nxn−1⇒∑nxn=x(1−x)2x=13:1/34/9=34\begin{aligned} \frac{d}{dx} \frac{1}{1 - x} &= \frac{1}{(1 - x)^2} = \sum_{n=1}^{\infty} n x^{n-1} \quad\Rightarrow\quad \sum n x^n = \frac{x}{(1 - x)^2} \\ x = \tfrac{1}{3}&: \frac{1/3}{4/9} = \frac{3}{4} \end{aligned}
python · try it yourself
print(sum(n / 3**n for n in range(1, 60)))
0.75

Exercise 3: Integrate for a logarithm

Find the Maclaurin series of ln⁡((1+x)/(1−x))\ln((1 + x)/(1 - x)) and use it to compute ln⁡2\ln 2 with 5 terms. (Hint: (1+x)/(1−x)=2(1 + x)/(1 - x) = 2 when x=1/3x = 1/3.)

Answer

ln⁡((1+x)/(1−x))=2(x+x3/3+x5/5+⋯ )\ln((1 + x)/(1 - x)) = 2(x + x^3/3 + x^5/5 + \cdots) for ∣x∣<1\lvert x \rvert < 1; 5 terms at x=1/3x = 1/3 give ln⁡2≈0.693146\ln 2 \approx 0.693146, error about 1.1×10−61.1 \times 10^{-6}.

Solution
ln⁡(1+x)−ln⁡(1−x)=(x−x22+x33−⋯ )−(−x−x22−x33−⋯ )=2∑x2n+12n+1\ln(1 + x) - \ln(1 - x) = \left(x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots\right) - \left(-x - \frac{x^2}{2} - \frac{x^3}{3} - \cdots\right) = 2 \sum \frac{x^{2n+1}}{2n + 1}

This converges much faster than the ln⁡(1+x)\ln(1 + x) series at x=1x = 1, because x=1/3x = 1/3 makes the terms shrink by a factor 9 each time.

python · try it yourself
import math

x = 1 / 3
approx = 2 * sum(x ** (2 * n + 1) / (2 * n + 1) for n in range(5))
print(f"{approx:.6f}  error {abs(approx - math.log(2)):.1e}")
0.693146  error 1.1e-06

Exercise 4: Endpoint behaviour

The series for arctan⁡x\arctan x converges at x=1x = 1. Does the series for its derivative, ∑(−1)nx2n\sum (-1)^n x^{2n}, converge at x=1x = 1?

Answer

No: it becomes 1−1+1−⋯1 - 1 + 1 - \cdots, which diverges.

Solution

The terms (−1)n(-1)^n do not tend to 0, so the Test for Divergence applies. The radius stays 1, but differentiating lost the endpoint x=1x = 1 (and x=−1x = -1), as the note above warned.

Test yourself

f(x)=∑cnxnf(x) = \sum c_n x^n has radius 4. What is the radius of the series for f′(x)f'(x)?

  1. 2
  2. 4
  3. 16
  4. It depends on the cnc_n

Why is Machin's formula much faster than Leibniz's series for π\pi?

  1. It uses more terms
  2. It avoids fractions
  3. It evaluates arctan at small arguments, so x2n+1x^{2n+1} shrinks fast
  4. It is not alternating

Why does math.log1p(x) exist when log(1 + x) already works?

  1. It is faster for large xx
  2. For tiny xx, 1+x1 + x rounds and loses xx's digits; log1p uses the series ≈x\approx x directly
  3. It handles negative logarithms
  4. It returns exact fractions