Integration is the second pillar of calculus: the mathematics of accumulation. Where the derivative chops a curve into instantaneous rates, the integral sums infinitely many tiny pieces into a total — an area, a distance, a probability. The chapter’s climax is the Fundamental Theorem of Calculus, which reveals that integration and differentiation are inverse operations, turning the hard area problem into easy antidifferentiation.

Antiderivatives

An antiderivative of \(f\) is a function \(F\) with \(F'=f\). Since constants differentiate to zero, antiderivatives come in families: the indefinite integral \[\int f(x)\,\dd x = F(x) + C,\] where \(C\) is an arbitrary constant. Reading the derivative table backwards gives the basic antiderivatives.

\(f(x)\) \(\int f\,\dd x\) \(f(x)\) \(\int f\,\dd x\)
\(x^n\ (n\neq-1)\) \(\dfrac{x^{n+1}}{n+1}+C\) \(\dfrac1x\) \(\ln|x|+C\)
\(e^x\) \(e^x+C\) \(\cos x\) \(\sin x+C\)
\(\sin x\) \(-\cos x+C\) \(\dfrac{1}{1+x^2}\) \(\arctan x+C\)

The definite integral as a limit of sums

The area problem is solved by approximating with rectangles and refining without bound.

Partition \([a,b]\) into \(n\) subintervals of width \(\Delta x=\tfrac{b-a}{n}\), pick a sample point \(x_i^*\) in each, and form the Riemann sum \(\sum_{i=1}^n f(x_i^*)\,\Delta x\). The definite integral is its limit as the rectangles become infinitely thin: \[\int_a^b f(x)\,\dd x = \lim_{n\to\infty}\sum_{i=1}^n f(x_i^*)\,\Delta x.\]

The integral sign \(\int\) is a stretched “S” for “sum,” and \(\dd x\) is the width of an infinitely thin slice: the integral literally adds up \(f(x)\,\dd x\), “height times width,” over the whole interval. If \(f\) can be negative, the integral counts area below the axis as negative — it is a signed area. This “sum of tiny contributions” picture is exactly how an expected value sums value \(\times\) probability in the next part.

Properties

The integral is linear (\(\int(af+bg)=a\int f+b\int g\)), additive over intervals (\(\int_a^c=\int_a^b+\int_b^c\)), and monotone (\(f\le g\Rightarrow\int f\le\int g\)). These mirror the limit/derivative laws and make integrals manipulable.

The Fundamental Theorem of Calculus

Here is the theorem that ties the whole subject together — arguably the most important in calculus.

Let \(f\) be continuous on \([a,b]\).

The accumulation function \(\displaystyle G(x)=\int_a^x f(t)\,\dd t\) is an antiderivative of \(f\): \(\,G'(x)=f(x)\).

If \(F\) is any antiderivative of \(f\), then \[\int_a^b f(x)\,\dd x = F(b)-F(a).\]

The FTC says differentiation and integration are inverse operations. This is monumental: instead of computing a hard limit of Riemann sums, you find an antiderivative and subtract two values. The area problem and the tangent problem — which looked unrelated in Chapter [ch:functions] — are revealed to be two sides of one coin. The rate of accumulation of area under \(f\) is exactly \(f\) itself.

\(\displaystyle\int_0^2 x^2\,\dd x = \left[\frac{x^3}{3}\right]_0^2 = \frac{8}{3}-0 = \frac{8}{3}.\) No Riemann sum needed — just antidifferentiate and subtract.

Part 1 is best felt physically. If \(f(t)\) is the rate at which water flows into a tank, then \(G(x)=\int_a^x f\) is the total water by time \(x\), and its rate of change \(G'\) is — of course — the current flow rate \(f(x)\). Accumulating and then measuring the rate of accumulation returns what you started with.

Three habits prevent most integration errors. (1) Never forget the \(+C\) on an indefinite integral — losing it loses a whole family of solutions and corrupts differential-equation work. (2) The variable of integration is a dummy: \(\int_a^b f(x)\dd x=\int_a^b f(t)\dd t\). (3) The integrand must be well-behaved; integrating across a vertical asymptote without treating it as an improper integral (Chapter [ch:techniques]) gives nonsense.

Integrals are how machine learning handles continuous probability. A probability density \(p(x)\) must integrate to \(1\), \(\int p(x)\,\dd x=1\); probabilities are areas \(\int_a^b p(x)\dd x\); and the all-important expected value \(\E[X]=\int x\,p(x)\,\dd x\) is an integral (Chapter [ch:appint]). Losses are typically expectations, hence integrals, which in practice we estimate by averaging samples (Monte Carlo) — a Riemann-sum-like approximation. The FTC’s “accumulate a rate” picture also underlies continuous-time models (neural ODEs, diffusion) in the capstone.

import numpy as np
from scipy import integrate
# Riemann sum vs exact integral of x^2 on [0,2] (exact = 8/3)
x = np.linspace(0, 2, 100_000)
print(np.trapz(x**2, x))                 # ~2.6667
val, _ = integrate.quad(lambda t: t**2, 0, 2)
print(val)                               # 2.6666666...
# a normal density integrates to 1
from math import pi
p = lambda t: np.exp(-t**2/2)/np.sqrt(2*pi)
print(integrate.quad(p, -np.inf, np.inf)[0])   # 1.0

Chapter summary

  • An antiderivative reverses differentiation; the indefinite integral \(\int f\,\dd x=F+C\).

  • The definite integral is a limit of Riemann sums — a signed area / total accumulation.

  • The Fundamental Theorem makes differentiation and integration inverses: \(\int_a^b f=F(b)-F(a)\).

  • Always keep \(+C\); the variable of integration is a dummy; mind asymptotes (improper integrals).

  • Densities, probabilities, and expectations are integrals — the continuous backbone of ML, estimated by sampling.