III.7 · Calculus
How does a surface change when only one input moves?
Move a point across a contour map. Two slices through it — one along x, one along y — are ordinary curves, and their slopes are the two partial derivatives.
Hold one input fixed and differentiate the slice
Contour map of f(x, y) = x² − y²
Level curves of f(x, y) = x² − y² at heights -4, -3.5, -3, -2.5, -2, -1.5…. The point (1, 0.5) has height 0.75. The solid blue line holds y = 0.5; the dashed green line holds x = 1.
Slice y = 0.5: t ↦ f(t, 0.5)
Holding y fixed, the slice is the one-variable polynomial t² − 0.25. Its tangent at t = 1 has slope 2 = ∂f/∂x.
Slice x = 1: t ↦ f(1, t)
Holding x fixed, the slice is the one-variable polynomial −t² + 1. Its tangent at t = 0.5 has slope −1 = ∂f/∂y.
- Input x
- 1
- Input y
- 0.5
- Height
- 0.75
- Rate along x, y held fixed
- 2
- Rate along y, x held fixed
- −1
- Secant along x (h = 0.25)
- 2.25
- Secant along y (h = 0.25)
- −1.25
Exact values use =; binary64 approximations use ≈. Undefined values state their reason.
Moving along x with y fixed changes f at rate 2; moving along y with x fixed changes it at rate −1. Two different questions, two different slices of the same surface.
Hold y fixed
Set y = 0.5. What remains is a function of x alone.
from −2.5 to 2.5, up to 2 decimal places
from −2.5 to 2.5, up to 2 decimal places
On the saddle at , the slice along rises with slope while the slice along falls with slope . Drag the point to the origin: both slices are flat, although the surface is a saddle, not a bowl.
Intuition: one knob at a time
A function assigns a height to every point of the plane. Its contour map draws the curves at several heights, like an elevation map. Standing at a point, you can ask how the height changes if you walk east (change only) or north (change only). Each question fixes one input and leaves an ordinary function of one variable, whose derivative you already know.
Definition
The partial derivatives of at are
Equivalently, is the derivative of the slice at . Other common notations are , and .
Mechanics: what the explorer computes
The surfaces are polynomials with rational coefficients, so the height, both slices and both partial derivatives are exact. The contour lines are a drawing aid computed numerically on a grid; no value is read from them. Each slice plane shows the one-variable polynomial obtained by fixing the other input, and the inspector adds an exact secant along each axis with as evidence.
Derivation: differentiate the slice
For at , fix :
whose derivative is at . Fix instead:
whose derivative is at . In practice we write this as a rule: differentiate with respect to one variable, treating the others as constants. So and .
Worked example
Take at . The -slice is , a line of slope ; the -slice is , slope . Hence and . Because is linear in each variable separately, every secant along an axis equals the partial derivative exactly.
Replay the worked derivation
Hold y fixed
Set y = 0.5. What remains is a function of x alone.
What partial derivatives do not say
Two partial derivatives describe change along two directions only. A function can have both partial derivatives at a point and still behave badly along a diagonal; and zero partial derivatives do not identify a minimum (the saddle at the origin). III.8 combines the partials into the gradient, which describes change in every direction for differentiable functions, and III.11 uses second derivatives to classify flat points.
Executable reference code
The pedagogical reference computes partial derivatives of an exact polynomial by differentiating slices with Fraction and checks them against exact secant limits. The NumPy version samples a surface on a grid and compares numpy.gradient with the analytic partials.
"""Partial derivatives as derivatives of slices, with exact Fractions (III.7)."""
from fractions import Fraction as F
# f(x, y) = sum c * x**i * y**j, stored as {(i, j): c}
f = {(2, 0): F(1), (0, 2): F(-1)} # x**2 - y**2
def value(p, x, y):
return sum(c * x**i * y**j for (i, j), c in p.items())
def d_dx(p):
return {(i - 1, j): c * i for (i, j), c in p.items() if i > 0}
def d_dy(p):
return {(i, j - 1): c * j for (i, j), c in p.items() if j > 0}
x, y = F(1), F(1, 2)
assert (value(d_dx(f), x, y), value(d_dy(f), x, y)) == (2, -1)
# The same numbers as limits of exact secants along each axis: m(h) is a polynomial in h, so 2 nonzero steps fix it.
def axis_slope(axis, h):
step = (h, 0) if axis == 'x' else (0, h)
return (value(f, x + step[0], y + step[1]) - value(f, x, y)) / h
for axis, expected in (('x', 2), ('y', -1)):
m1, m2 = axis_slope(axis, F(1, 4)), axis_slope(axis, F(1, 2))
# linear in h: extrapolate to h = 0
assert m1 - (m2 - m1) == expected"""Grid partial derivatives with numpy.gradient versus the analytic ones (III.7)."""
import numpy as np
x = np.linspace(-2, 2, 81)
y = np.linspace(-2, 2, 81)
X, Y = np.meshgrid(x, y, indexing="ij")
Z = X**2 * Y + 3 * Y
dZdx, dZdy = np.gradient(Z, x, y)
# Central differences are exact for this quadratic in x and linear in y in the interior.
interior = (slice(1, -1), slice(1, -1))
assert np.allclose(dZdx[interior], (2 * X * Y)[interior], atol=1e-12)
assert np.allclose(dZdy[interior], (X**2 + 3)[interior], atol=1e-12)Explore
On Tilted plane the partials are the same everywhere: a plane has constant slopes. On Valley, compare how much faster the height changes along than along — the contours are squeezed in the direction. Move the point along a contour line and notice that the height row stays fixed while the partials change.
Common mistakes
Holding the wrong variable fixed, or forgetting to treat it as a constant (, not ). Reading a partial derivative as the total change when both inputs move. Assuming zero partial derivatives mean a minimum.
Numerical considerations
Grid-based partial derivatives (as in numpy.gradient) are finite differences with spacing errors; at boundaries they become one-sided and less accurate. Contour plots depend on the grid resolution and chosen levels and can miss narrow features. Exact slices avoid both issues for polynomials.
Engineering and ML connections
A model’s loss depends on many parameters at once. Each partial derivative measures sensitivity to one parameter while all others are fixed; together they form the gradient used by optimisation (VI.4). Partial derivatives also describe sensitivities of physical models — temperature to position, cost to each resource.
Exercises
Summary and checkpoints
A partial derivative is the derivative of a one-variable slice, holding the other inputs fixed. Two partials give rates along the coordinate axes; they are not yet a full description of change. Next, III.8 assembles them into the gradient and measures change in any direction.