Skip to content

Chapter 8: Calculus 2

Second-semester calculus extends integration to harder problems and then pivots to a deep idea: a function can be represented as an infinite sum. That idea is not a curiosity. It is how computers approximate transcendental functions such as exe^x, sin⁡x\sin x, and erf⁡\operatorname{erf}, and it is how you analyze the long-run behavior of algorithms and iterative methods, from the average cost of hashing to the smoothed loss curve of a training run.

Concepts from other sections (11)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This chapter follows that arc in two built sections and one problem set. The first section turns Taylor series into working code: a polynomial for exe^x with a proven error bound, range reduction so the bound holds for every input, and a series for erf that avoids catastrophic cancellation. The second section develops convergence of series and the geometric series, and uses them to explain why an exponential moving average starts out biased toward zero and how to correct it, the same correction Adam applies to its moments. The problem set then practises the hand techniques behind both: integration by parts and substitution, the Gaussian integral, convergence tests, Taylor remainders, polar curves, and first-order differential equations.

Learning objectives

  • Choose an integration technique (parts, substitution, partial fractions, trigonometric substitution) and carry it out.
  • Decide whether a series converges using the divergence, geometric, pp-series, integral, comparison, ratio, root, and alternating series tests.
  • Approximate a function with a Taylor polynomial, bound the error with the Lagrange remainder, and use range reduction to keep that error small.
  • Explain the exponential moving average as a geometric series and derive its bias correction.
  • Solve separable and first-order linear differential equations, and recognize gradient descent as Euler’s method.

You should be comfortable with limits, derivatives, and definite integrals from Calculus 1, in particular Derivatives and finite differences. The code sections also call two helpers from Precalculus: horner from Polynomials, Horner, and stable quadratic roots and the geometric-sequence helpers from Sequences, geometric series, and frequency ladders. The companion textbook is OpenStax, Calculus Volume 2 (free, CC BY-NC-SA 4.0).

  1. Taylor series, remainder bounds, and range reduction: derives Taylor polynomials and the Lagrange remainder, then builds exp_range_reduced (ex=2kere^x = 2^k e^r with a Cody-Waite reduction) and a cancellation-free erf_series, the float64 references for the exact GELU and the C expf.
  2. Series convergence, the EMA as a geometric series, and bias correction: defines convergence, sums the geometric series exactly, and builds an EMA class whose debiased value is exact for a constant input, the correction behind Adam.
  3. Calculus 2 problem set: 52 pen-and-paper problems with worked answers on integration techniques, the Gaussian, series, Taylor polynomials, polar curves, and ODEs.

The sections above go deep on Taylor series and the geometric series. The rest of second-semester calculus is summarized here, with a worked example for each topic, so that you have the whole toolkit in view. The OpenStax chapter numbers point to fuller treatments and exercise sets.

Calculus Volume 2, sections 1.1 to 1.5, covers four techniques. Integration by parts, ∫u dv=uv−∫v du\int u\,dv = uv - \int v\,du, handles products of two kinds of function; a common heuristic for choosing uu is LIATE (logarithmic, inverse trigonometric, algebraic, trigonometric, exponential), taking the earliest kind present. Trigonometric integrals reduce powers with identities like sin⁡2x=1−cos⁡2x2\sin^2 x = \frac{1 - \cos 2x}{2}. Trigonometric substitution removes square roots: for a2−x2\sqrt{a^2 - x^2} let x=asin⁡θx = a\sin\theta, for a2+x2\sqrt{a^2 + x^2} let x=atan⁡θx = a\tan\theta, and for x2−a2\sqrt{x^2 - a^2} let x=asec⁡θx = a\sec\theta. Partial fractions decompose P(x)/Q(x)P(x)/Q(x) into simpler fractions when deg⁡P<deg⁡Q\deg P < \deg Q.

Two short examples show the first and last of these. For ∫xex dx\int x e^x\,dx, take u=xu = x and dv=ex dxdv = e^x\,dx, so du=dxdu = dx and v=exv = e^x; the result is xex−∫ex dx=xex−ex+C=ex(x−1)+Cx e^x - \int e^x\,dx = x e^x - e^x + C = e^x(x - 1) + C. For ∫dxx2−1\int \frac{dx}{x^2 - 1}, write 1(x−1)(x+1)=Ax−1+Bx+1\frac{1}{(x-1)(x+1)} = \frac{A}{x-1} + \frac{B}{x+1}; solving gives A=12A = \frac12, B=−12B = -\frac12, and the integral is 12ln⁡∣x−1∣−12ln⁡∣x+1∣+C\frac12\ln|x-1| - \frac12\ln|x+1| + C.

Integrals measure more than area (sections 2.1 to 2.4). The arc length of y=f(x)y = f(x) on [a,b][a, b] is L=∫ab1+f′(x)2 dxL = \int_a^b \sqrt{1 + f'(x)^2}\,dx; the surface area of revolution is S=2π∫abf(x)1+f′(x)2 dxS = 2\pi\int_a^b f(x)\sqrt{1 + f'(x)^2}\,dx; and the center of mass of a lamina is xˉ=My/m\bar x = M_y / m with My=∫x ρ(x) f(x) dxM_y = \int x\,\rho(x)\,f(x)\,dx.

For example, the arc length of y=x3/2y = x^{3/2} from x=0x = 0 to x=4x = 4 uses f′(x)=32x1/2f'(x) = \frac32 x^{1/2}, so L=∫041+9x4 dxL = \int_0^4 \sqrt{1 + \frac{9x}{4}}\,dx. With u=1+9x4u = 1 + \frac{9x}{4}, du=94 dxdu = \frac94\,dx, this is L=49⋅23[u3/2]110=827(1010−1)L = \frac49 \cdot \frac23\left[u^{3/2}\right]_1^{10} = \frac{8}{27}\left(10\sqrt{10} - 1\right).

A parametric curve x=f(t)x = f(t), y=g(t)y = g(t) has slope dydx=dy/dtdx/dt\frac{dy}{dx} = \frac{dy/dt}{dx/dt} and arc length L=∫ab(dx/dt)2+(dy/dt)2 dtL = \int_a^b \sqrt{(dx/dt)^2 + (dy/dt)^2}\,dt: at each instant the speed is the hypotenuse of the two velocity components (sections 3.1 to 3.4). Polar coordinates use x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta, and the area swept by r(θ)r(\theta) from α\alpha to β\beta is A=12∫αβr(θ)2 dθA = \frac12\int_\alpha^\beta r(\theta)^2\,d\theta.

For example, one petal of r=cos⁡2θr = \cos 2\theta spans θ∈[−π4,π4]\theta \in [-\frac\pi4, \frac\pi4], so its area is 12∫−π/4π/4cos⁡22θ dθ=12⋅π4=π8\frac12\int_{-\pi/4}^{\pi/4}\cos^2 2\theta\,d\theta = \frac12 \cdot \frac\pi4 = \frac\pi8.

A sequence {an}\{a_n\} converges if lim⁡n→∞an\lim_{n\to\infty} a_n exists and is finite; a series ∑n=1∞an\sum_{n=1}^\infty a_n converges if its sequence of partial sums does (sections 5.1 to 5.6). A power series ∑cn(x−a)n\sum c_n (x - a)^n has a radius of convergence RR, and the Taylor series f(x)=∑n=0∞f(n)(a)n!(x−a)nf(x) = \sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}(x - a)^n is the power series built from derivatives.

The convergence tests form a decision tree, and each has a one-line intuition:

  • Divergence test: if lim⁡an≠0\lim a_n \ne 0, the series diverges. Terms must shrink to zero, but that is necessary, not sufficient.
  • Ratio test: if lim⁡∣an+1/an∣=L<1\lim |a_{n+1}/a_n| = L < 1 the series converges absolutely; if L>1L > 1 it diverges. It compares the series to a geometric one.
  • Root test: if lim⁡∣an∣1/n=L\lim |a_n|^{1/n} = L, the same conclusions hold as for the ratio test.
  • Integral test: if ff is positive, continuous, and decreasing with an=f(n)a_n = f(n), then ∑an\sum a_n and ∫1∞f(x) dx\int_1^\infty f(x)\,dx converge or diverge together.
  • Comparison test: bound the series by a known geometric or pp-series.
  • Alternating series test: if ∣an∣|a_n| decreases to 0, the alternating series converges.

A few series are worth knowing by heart. The geometric series ∑rn=11−r\sum r^n = \frac{1}{1 - r} for ∣r∣<1|r| < 1; the pp-series ∑1/np\sum 1/n^p converges if and only if p>1p > 1; the harmonic series ∑1/n\sum 1/n diverges (p=1p = 1); and ex=∑xnn!e^x = \sum \frac{x^n}{n!}, sin⁡x=∑(−1)nx2n+1(2n+1)!\sin x = \sum \frac{(-1)^n x^{2n+1}}{(2n+1)!}, cos⁡x=∑(−1)nx2n(2n)!\cos x = \sum \frac{(-1)^n x^{2n}}{(2n)!}.

For example, ∑n=1∞n22n\sum_{n=1}^\infty \frac{n^2}{2^n} yields to the ratio test: ∣an+1an∣=(n+1)22n2→12<1\left|\frac{a_{n+1}}{a_n}\right| = \frac{(n+1)^2}{2n^2} \to \frac12 < 1, so the series converges.

An ordinary differential equation relates a function to its derivatives (sections 4.1 to 4.3). A separable equation dydx=f(x) g(y)\frac{dy}{dx} = f(x)\,g(y) is solved by separating the variables and integrating both sides. A first-order linear equation dydx+P(x) y=Q(x)\frac{dy}{dx} + P(x)\,y = Q(x) is solved with the integrating factor μ(x)=e∫P(x) dx\mu(x) = e^{\int P(x)\,dx}.

For example, dydx=2xy\frac{dy}{dx} = 2xy with y(0)=1y(0) = 1 separates to dyy=2x dx\frac{dy}{y} = 2x\,dx; integrating gives ln⁡∣y∣=x2+C\ln|y| = x^2 + C, the initial condition gives C=0C = 0, and the solution is y=ex2y = e^{x^2}.

When you face a new problem, the first decision is which tool to reach for. This table collects the cues:

TechniqueWhen to useKey formula or idea
Integration by partsproduct of two kinds of functionLIATE priority for choosing uu
Trigonometric substitutiona2±x2\sqrt{a^2 \pm x^2} or x2−a2\sqrt{x^2 - a^2}substitute x=asin⁡θx = a\sin\theta, atan⁡θa\tan\theta, or asec⁡θa\sec\theta
Partial fractionsrational functions P(x)/Q(x)P(x)/Q(x)factor the denominator, decompose
Ratio testseries with factorials or exponentialscompute lim⁡∣an+1/an∣\lim \lvert a_{n+1}/a_n \rvert
Comparison testseries similar to a known pp-series or geometric seriesbound by a known convergent or divergent series
Taylor expansionapproximating f(x)f(x) near a pointf(x)=∑f(n)(a)(x−a)n/n!f(x) = \sum f^{(n)}(a)(x-a)^n/n!
Separable ODEdy/dx=f(x) g(y)dy/dx = f(x)\,g(y)separate and integrate both sides

These ideas recur well beyond this book. The harmonic series appears in average-case hashing analysis and the coupon-collector problem. Taylor series are how libraries compute sin⁡\sin, cos⁡\cos, and exp⁡\exp in floating point. The radius of convergence of a power series governs whether iterative algorithms converge, and convergence tests in general tell you whether an iterative method terminates. Differential equations model dynamic systems, from PID controllers to epidemics, and Fourier series in signal processing build on the same foundations.

  • Integration by parts: ∫u dv=uv−∫v du\int u\,dv = uv - \int v\,du, the product rule in reverse; it integrates products of two kinds of function, such as xexx e^x, and LIATE is a heuristic for choosing uu.
  • Trigonometric substitution: replacing xx by asin⁡θa\sin\theta, atan⁡θa\tan\theta, or asec⁡θa\sec\theta to remove a square root of the form a2−x2\sqrt{a^2 - x^2}, a2+x2\sqrt{a^2 + x^2}, or x2−a2\sqrt{x^2 - a^2} from an integrand.
  • Partial fractions: decomposing a rational function P(x)/Q(x)P(x)/Q(x) with deg⁡P<deg⁡Q\deg P < \deg Q into a sum of simpler fractions over the factors of QQ, each of which integrates to a logarithm or an arctangent.
  • Arc length: the length of a curve, L=∫ab1+f′(x)2 dxL = \int_a^b \sqrt{1 + f'(x)^2}\,dx for y=f(x)y = f(x), or ∫ab(dx/dt)2+(dy/dt)2 dt\int_a^b \sqrt{(dx/dt)^2 + (dy/dt)^2}\,dt for a parametric curve: the integral of speed.
  • Parametric curve: a curve given by x=f(t)x = f(t), y=g(t)y = g(t) in terms of a parameter tt, with slope dydx=dy/dtdx/dt\frac{dy}{dx} = \frac{dy/dt}{dx/dt}; it describes paths that are not graphs of a function.
  • Polar coordinates: describing a point by its distance rr from the origin and angle θ\theta, with x=rcos⁡θx = r\cos\theta and y=rsin⁡θy = r\sin\theta; a polar curve r(θ)r(\theta) sweeps area 12∫αβr(θ)2 dθ\frac12\int_\alpha^\beta r(\theta)^2\,d\theta.
  • Power series: a series ∑cn(x−a)n\sum c_n (x - a)^n in powers of x−ax - a; it converges for ∣x−a∣|x - a| less than its radius of convergence RR and can diverge beyond it.
  • Taylor series: the power series ∑n=0∞f(n)(a)n!(x−a)n\sum_{n=0}^\infty \frac{f^{(n)}(a)}{n!}(x - a)^n built from the derivatives of ff at aa; truncating it gives the polynomials that libraries use to compute exe^x, sin⁡\sin, and cos⁡\cos.
  • Divergence test: if lim⁡an≠0\lim a_n \ne 0, then ∑an\sum a_n diverges; terms shrinking to zero is necessary for convergence but not sufficient.
  • Integral test: if ff is positive, continuous, and decreasing with an=f(n)a_n = f(n), then ∑an\sum a_n and ∫1∞f(x) dx\int_1^\infty f(x)\,dx converge or diverge together.
  • Comparison test: a series of nonnegative terms converges if it is bounded term by term by a known convergent series, such as a geometric or pp-series, and diverges if it bounds a known divergent one.
  • Alternating series test: if ∣an∣|a_n| decreases to 0, the series ∑(−1)n∣an∣\sum (-1)^n |a_n| converges, even when ∑∣an∣\sum |a_n| does not.
  • p-series / harmonic series: ∑1/np\sum 1/n^p, which converges if and only if p>1p > 1; the harmonic series ∑1/n\sum 1/n is the case p=1p = 1 and diverges, growing like ln⁡n\ln n, which is why it appears in hashing and coupon-collector analyses.
  • Ordinary differential equation (ODE): an equation relating a function of one variable to its derivatives, such as dy/dx=2xydy/dx = 2xy; it models how a system changes, and gradient descent is Euler’s method applied to one.
  • Separable differential equation: an ODE of the form dy/dx=f(x) g(y)dy/dx = f(x)\,g(y), solved by moving all yy terms to one side, dy/g(y)=f(x) dxdy/g(y) = f(x)\,dx, and integrating both sides.
  • Integrating factor: the multiplier μ(x)=e∫P(x) dx\mu(x) = e^{\int P(x)\,dx} that turns the first-order linear ODE y′+P(x) y=Q(x)y' + P(x)\,y = Q(x) into (μy)′=μQ(\mu y)' = \mu Q, which can be integrated directly.
  • OpenStax, Calculus Volume 2 (free). Good exercise sets for each topic above: integration techniques, sections 1.1 (exercises 1 to 15), 1.3 (115 to 128), 1.4 (155 to 170), with challenge problems in 1.5 (200 to 210); applications, 2.1 (1 to 10), 2.2 (50 to 60), 2.4 (100 to 110, challenge 115 to 120); parametric and polar, 3.1 (1 to 12), 3.3 (110 to 122), 3.4 (150 to 162, challenge 168 to 175); series, 5.1 (1 to 14), 5.3 (120 to 138), 5.4 (175 to 190), 5.6 (260 to 275, challenge 280 to 288); differential equations, 4.1 (1 to 10), 4.3 (100 to 115, challenge 120 to 125).
  • Paul’s Online Math Notes, for worked examples of every technique.
  • 3Blue1Brown, calculus, for geometric intuition about series and Taylor polynomials.