A speedometer reads. How far have you traveled?
You can’t see out the window. You only have the speedometer and a stopwatch. The speed is changing — sometimes 30, sometimes 60, sometimes 0. What’s the total distance? The intuition is to break the trip into short intervals where the speed is “almost constant,” multiply each interval’s speed by its duration, and add. That’s a Riemann sum, and the limit of those sums — as the intervals shrink — is the
In the widget below, drag N (the rectangle count) and watch the orange sum approach the green exact integral. Pick the velocity function and you’ve recovered the projectile-motion story from the other direction: the integral of g·t over time is the distance you’ve fallen.
- what
: the accumulated total of over . Limit of Riemann sums: . Geometrically, the signed area between the curve and the x-axis. The pair operation to the derivative — what differentiation undoes.
- applies when
Any time you want a total from a rate. Distance from velocity, work from force, charge from current, expected value from a probability density, area from a height function. Numerically: every solver from
scipy.integrateto PDE codes is a Riemann-style sum with a smarter rule.- breaks when
Discontinuities and unbounded intervals require improper integrals. Functions whose antiderivative has no closed form (, ) must be evaluated numerically. Higher-dimensional analogs (line, surface, volume integrals, measure theory) keep the same intuition but require careful bookkeeping. And: the FTC requires the integrand to be continuous on the interval; sharper versions ease this, but the one-sentence theorem doesn’t apply to every function you can write down.
Area first — accumulating a constant rate
The simplest case is a constant rate. If you drive at for , you cover . On a graph of speed-vs-time, that’s the area of a rectangle: width × height. The total distance is the area under the speed curve, even when the curve isn’t constant. The whole module is reframing this trivial case for non-constant rates.
For a rate that changes linearly — say , what gravity gives an object dropped from rest — the area under the line over is a triangle: . That’s the falling distance. No new physics, no new calculus — just area.
Riemann sum — finite bookkeeping
For a curve that isn’t a triangle, you can’t read the area off geometry. Instead, approximate. Chop the interval into strips of width . Pick a sample point in each strip — left edge, right edge, or midpoint, your choice — and use that one value as the strip’s “constant” height. Add up the strip areas. The result is a
The widget above shows this directly. Pick over and slide N upward. At the rectangle is laughably wrong; at it’s recognizable; at the gap from the true value is invisible. Different rules (left/right/midpoint) approach the same limit at different speeds — left and right rules at , midpoint at . That’s why every numerical integrator picks midpoint or better.
# Riemann sum — turn 'area under the curve' into a finite computation.
# Chop [a, b] into N strips, evaluate f once per strip, multiply by Δx,
# add. Three rule choices give different errors at the same N.
def riemann(f, a, b, n, rule="midpoint"):
dx = (b - a) / n
s = 0.0
for i in range(n):
if rule == "left": x = a + i * dx
elif rule == "right": x = a + (i + 1) * dx
else: x = a + (i + 0.5) * dx
s += f(x) * dx
return s
# ∫_0^1 x² dx — the exact answer is 1/3 ≈ 0.333.
[(rule, riemann(lambda x: x*x, 0, 1, n=20, rule=rule))
for rule in ("left", "right", "midpoint")]
# → [('left', 0.30875), a bit under 1/3
# ('right', 0.35875), a bit over 1/3
# ('midpoint', 0.333125)] essentially exact at N=20
# Midpoint converges as ~1/N², the others as ~1/N. That's why every
# practical numerical integrator picks midpoint or higher (Simpson, Gauss).Definite integral — limit of Riemann sums
The
A single number — the accumulated total. The notation predates Riemann; the symbol is a stretched “S” for “sum,” the is the descendant of after the limit shrinks it. Reading "" as “sum of times tiny ‘s, from to ” is exactly correct intuition; it’s also the pre-Riemann intuition Newton and Leibniz used.
The widget’s “exact integral” readout is this number, computed in closed form (because we picked easy functions). For most real functions, the limit is taken numerically — and Riemann sums of one form or another are how computers actually compute integrals.
Antiderivative — reverse of the derivative
Integration meets differentiation. From the derivatives module, differentiating gives . Reading right-to-left: has an antiderivative, namely . An
Antiderivatives aren’t unique — and both differentiate to . Any constant can be added without changing the derivative, which is why textbooks write . The set of all antiderivatives of one is a one-parameter family, all parallel translates of each other.
For polynomials, the rule is mechanical: the derivative of is , so the antiderivative of is . Reverse the formula’s bookkeeping. For the antiderivative is ; for it’s (back where you started). A finite list of these and the chain rule cover most of what one runs into in practice.
# Antiderivative — the function whose derivative is f.
# For polynomials, the rule is mechanical: x^n → x^(n+1)/(n+1).
# But the antiderivative isn't unique — F(x) and F(x) + 5 both differentiate
# to the same f. The +C is a fixed point of the operation.
def antideriv_poly(coeffs):
"""Coefficients of polynomial Σ c_i x^i → coeffs of antiderivative
Σ c_i x^(i+1)/(i+1). The constant C is dropped (you supply it)."""
return [0.0] + [c / (i + 1) for i, c in enumerate(coeffs)]
# f(x) = 3x² + 2x + 1 → F(x) = x³ + x² + x (+ C)
antideriv_poly([1, 2, 3])
# → [0.0, 1.0, 1.0, 1.0] coefficients of x⁰, x¹, x², x³Fundamental theorem — area equals reverse-derivative
The two stories — area under the curve and reverse of derivative — turn out to be the same story. The
for any antiderivative of . The infinite limit of Riemann sums collapses to two function evaluations and a subtraction. Most definite integrals you ever evaluate by hand or in a calculator are computed this way; the Riemann limit is what the integral is, but the FTC is how you do it.
Try the projectile-motion case. The velocity is ; an antiderivative is . By the FTC, the distance fallen between and is — the same triangle area we read off geometry in arc 1, now derived from the antiderivative. Two routes, one number.
The other half of the theorem — the part that says — is what makes the connection tight in both directions. Differentiation undoes integration; integration accumulates derivatives. They are not separate operations sharing a textbook chapter; they are inverses in the same way that addition and subtraction are inverses.
# Fundamental Theorem of Calculus, Part 2:
# ∫_a^b f(x) dx = F(b) − F(a)
# for any antiderivative F of f. The infinite limit of Riemann sums
# becomes two function evaluations and a subtraction.
def evaluate_poly(coeffs, x):
return sum(c * x**i for i, c in enumerate(coeffs))
def integral_via_ftc(coeffs, a, b):
F = antideriv_poly(coeffs)
return evaluate_poly(F, b) - evaluate_poly(F, a)
# ∫_0^2 (3t² + 2t + 1) dt — by FTC.
integral_via_ftc([1, 2, 3], 0, 2)
# → 14.0 F(2) − F(0) = (8 + 4 + 2) − 0 = 14
#
# Sanity check via Riemann at N=10000 with the lambda form:
def f(t): return 3*t*t + 2*t + 1
riemann(f, 0, 2, n=10000, rule="midpoint")
# → 13.99999... matches FTC to four decimals
#
# The Riemann sum 'is what the integral is.' FTC says you almost never
# have to take the limit — pick an antiderivative and subtract.Where this shows up — same accumulator, two pillars
Integration adds change across time. In physics that change becomes distance; in finance it becomes present value. The Riemann-sum picture is the same in both pillars; only the rate being summed differs.
physics : velocity is accumulated into distance; force·velocity into energy. finance : a continuous payment rate is accumulated — discounted — into present value.
Projectile motion — fall distance is . The velocity is the rate; integrating gives the area under it; that area is the distance. Two derivatives turn position into acceleration; two integrations run the ladder back the other way.
Terminal velocity — velocity is no longer linear; it bends toward an asymptote. Distance fallen is still — area under the curve, only the curve has shape now. Same accumulator, harder shape.
Damped oscillator — average power input under sinusoidal forcing is , an integral over a cycle. The peak — resonance — is exactly where this integral is largest; off-resonance, alternating contributions cancel under the integral sign.
Present value — a continuous cash-flow rate has present value . The discount factor shrinks each future moment before the integral adds them. Money over time is structurally identical to velocity over time: a rate, accumulated.
Same machine, different nouns: distance in physics, present value in finance — both are the area under a rate curve, with the rate set by the application.
Differentiation asks how fast a quantity is changing. Integration asks how much change has accumulated. Riemann sums are what the integral is. Antiderivatives are how you compute it. The fundamental theorem says those two pictures are the same picture — the inverse of the derivative.
A car drives at a constant for 2 hours. Compute the total distance two ways: (a) by reading the area of the rectangle on a speed-vs-time graph, (b) by computing the antiderivative of the constant function and applying the FTC.
Compute the midpoint Riemann sum for over with rectangles. (Midpoints are ; .) Compare to the exact value .
Compute via the FTC. Also compute it via the widget at midpoint and confirm the two agree.
A ball is dropped from rest. Gravity gives constant acceleration , so the velocity after time is . How far has it fallen by ?