26. Higher-order derivatives and what each one measures
f' is a function, so you can differentiate it again. And again.
f'' = (f')', \qquad f''' = (f'')', \qquad f^{(n)} = \left(f^{(n-1)}\right)'
Notation: primes up to three, then f^{(4)} with the order in parentheses — the parentheses distinguish it from the power f^4. In Leibniz form, \frac{d^ny}{dx^n}.
Each order answers a genuinely different question, and knowing which is which is most of the value.
What each one means
For position s(t):
| Order | Name | Meaning |
|---|---|---|
| s | position | where you are |
| s' | velocity | how fast, and which way |
| s'' | acceleration | how the velocity is changing |
| s''' | jerk | how the acceleration is changing |
| s^{(4)} | snap (or jounce) | rarely useful, genuinely named |
Jerk is not a joke. It's what you feel as discomfort in a vehicle: constant acceleration is a smooth push, but changing acceleration is the lurch. Lift and train control systems are designed with explicit jerk limits, and railway track transitions use a curve (the Euler spiral) chosen precisely so curvature — and hence lateral acceleration — changes linearly, keeping jerk bounded.
More generally: the n-th derivative measures the rate of change of the (n-1)-th. That's the only rule; the names are just labels.
What f'' tells you about shape
This is the one you'll use constantly, and §3.5 develops it fully.
f''>0 means f' is increasing — the slope is getting steeper as you move right. The curve bends upward: concave up, holding water.
f'' < 0 means the slope is decreasing. Concave down, spilling water.
f'' = 0 at a point where concavity changes is an inflection point.
The two derivatives answer separate questions and you need both:
- f' > 0: going up. f' < 0: going down.
- f'' > 0: bending up. f'' < 0: bending down.
A function can be increasing while concave down (\sqrt x — rising, but levelling off) or decreasing while concave up (e^{-x} — falling, but flattening). Those two combinations describe most of the "diminishing returns" phenomena you'll ever model.
Patterns
Polynomials terminate. Each derivative drops the degree by one, so a degree-n polynomial has f^{(n+1)} = 0 identically. That's a characterisation, not a curiosity: f^{(n+1)} \equiv 0 iff f is a polynomial of degree \le n.
Exponentials are fixed points. \frac{d^n}{dx^n}e^x = e^x for every n, and \frac{d^n}{dx^n}e^{kx} = k^ne^{kx}.
Sine and cosine cycle with period 4 (§2.5), so reduce n \bmod 4.
Reciprocals produce factorials. This one's worth deriving:
f(x) = \frac1x = x^{-1}
f' = -x^{-2}, \quad f'' = 2x^{-3}, \quad f''' = -6x^{-4}, \quad f^{(4)} = 24x^{-5}
The coefficients are 1, 2, 6, 24 — factorials — and the signs alternate:
\frac{d^n}{dx^n}x^{-1} = \frac{(-1)^n n!}{x^{n+1}}
Those factorials in the denominator are exactly what cancels the n! in Taylor's formula in §8.1, which is why \frac{1}{1-x} = 1 + x + x^2 + \cdots comes out with all coefficients equal to 1.
Products get binomial coefficients. Differentiating fg repeatedly gives
(fg)^{(n)} = \sum_{k=0}^{n}\binom nk f^{(k)}g^{(n-k)}
the Leibniz rule — structurally identical to the binomial theorem, and for the same reason: at each of n steps, the derivative lands on f or on g.
Smoothness classes
- f \in C^0: continuous.
- f \in C^1: f' exists and is continuous.
- f \in C^n: derivatives up to order n exist and are continuous.
- f \in C^\infty: smooth — derivatives of every order exist.
The classes are strictly nested, and the separating examples matter. |x| is C^0 but not C^1. x|x| is C^1 but not C^2. In general x^n|x| is C^n but not C^{n+1}.
This is why spline interpolation cares: joining cubic pieces with matching first and second derivatives gives a C^2 curve, which looks smooth to the eye, and that's exactly what a cubic spline does. Match only values and you get a visible kink; match only slopes and the curvature jumps.
And C^\infty is still not the end. f(x) = e^{-1/x^2} (with f(0)=0) has every derivative equal to zero at the origin, so its Taylor series is identically 0 — and yet the function isn't. Smooth but not analytic, a distinction §8.2 has to confront.
Doing it in Python
Position, velocity, acceleration, jerk, from one function:
def s(t):
return t**4 - 6*t**3 + 9*t**2 + 2
def deriv(f, order, t, h=1e-3):
"""Repeated central differences -- crude, but it makes the point."""
if order == 0:
return f(t)
return (deriv(f, order-1, t+h) - deriv(f, order-1, t-h)) / (2*h)
print(f"{'t':>5} {'position':>12} {'velocity':>12} {'accel':>12} {'jerk':>12}")
for t in (0.0, 1.0, 1.5, 2.0, 3.0):
print(f"{t:>5} {deriv(s,0,t):>12.4f} {deriv(s,1,t):>12.4f} "
f"{deriv(s,2,t):>12.4f} {deriv(s,3,t):>12.4f}")
print("\nexact: v = 4t^3-18t^2+18t, a = 12t^2-36t+18, jerk = 24t-36")
Concavity, read off the sign of f'':
from math import exp, sqrt, log
def second(f, x, h=1e-4):
return (f(x+h) - 2*f(x) + f(x-h)) / (h*h)
def first(f, x, h=1e-6):
return (f(x+h) - f(x-h)) / (2*h)
funcs = [("x^2", lambda x: x*x), ("sqrt(x)", sqrt),
("e^-x", lambda x: exp(-x)), ("ln x", log)]
x = 2.0
print(f"{'f':>10} {'f-prime':>12} {'f-double':>12} {'shape':>28}")
for name, f in funcs:
d1, d2 = first(f, x), second(f, x)
shape = ("increasing" if d1 > 0 else "decreasing") + \
(", concave up" if d2 > 0 else ", concave down")
print(f"{name:>10} {d1:>12.6f} {d2:>12.6f} {shape:>28}")
The factorial pattern:
import sympy as sp
from math import factorial
x = sp.Symbol('x')
for n in range(1, 7):
sym = sp.diff(1/x, x, n)
formula = (-1)**n * factorial(n) / x**(n+1)
print(f"n={n} {str(sym):<14} formula {str(formula):<14} "
f"same={sp.simplify(sym - formula) == 0}")
Smoothness classes, separated. This one needs one-sided differences, exactly as in §2.1 — and the reason is worth pausing on. A centred difference at x=0 averages the two sides, and for an even function the sides cancel exactly: it reports f'(0) = 0 for |x|, which is precisely the wrong answer. The failure is invisible unless you look at each side separately.
from math import comb
def one_sided(f, x, n, h=1e-6, side=+1):
"""n-th derivative estimate built from one side only: forward (+1), backward (-1)."""
total = sum((-1)**k * comb(n, k) * f(x + side * (n - k) * h)
for k in range(n + 1))
return total / (side * h) ** n
abs_x = abs
x_abs_x = lambda x: x * abs(x)
x2_abs_x = lambda x: x * x * abs(x)
print("at x = 0, comparing the two sides at each order:")
print(f" {'f':<8} {'order':>5} {'from left':>11} {'from right':>11} verdict")
for name, f, order in [("|x|", abs_x, 1),
("x|x|", x_abs_x, 1),
("x|x|", x_abs_x, 2),
("x^2|x|", x2_abs_x, 2),
("x^2|x|", x2_abs_x, 3)]:
left = one_sided(f, 0.0, order, side=-1)
right = one_sided(f, 0.0, order, side=+1)
verdict = "agree -> exists" if abs(left - right) < 1e-3 else "differ -> DOES NOT EXIST"
print(f" {name:<8} {order:>5} {left:>11.4f} {right:>11.4f} {verdict}")
print("\n|x| fails at order 1; x|x| survives order 1 and fails at 2;")
print("x^2|x| survives order 2 and fails at 3. each is C^n but not C^(n+1).")
print("\nwhat a centred difference would have said about |x| at 0:")
print(f" (f(h) - f(-h)) / 2h = {(abs(1e-6) - abs(-1e-6)) / 2e-6:.4f}"
" <- the two sides cancel, hiding the corner")
The smooth-but-not-analytic function:
from math import exp
def f(x):
return exp(-1 / (x * x)) if x != 0 else 0.0
print("f(x) = e^(-1/x^2), approaching 0:")
for k in range(1, 7):
x = 10.0 ** -k
print(f" x=1e-{k} f(x) = {f(x):.3e} f(x)/x^10 = {f(x)/x**10:.3e}")
print("\nf vanishes faster than every power of x, so every derivative at 0 is 0.")
print("its Taylor series is identically zero -- and f is not. smooth, not analytic.")
Worked example
A particle's position is s(t) = t^3 - 6t^2 + 9t metres. Describe its motion.
v(t) = s'(t) = 3t^2 - 12t + 9 = 3(t-1)(t-3)
a(t) = s''(t) = 6t - 12 = 6(t-2)
\text{jerk} = s'''(t) = 6 \quad\text{(constant)}
Velocity is zero at t = 1 and t = 3. Sign analysis on 3(t-1)(t-3):
- 0 < t < 1: both factors negative → v > 0, moving forward
- 1 < t < 3: signs differ → v < 0, moving backward
- t > 3: both positive → v > 0, forward again
So the particle reverses direction twice.
Acceleration is zero at t=2, negative before, positive after. So it's slowing its forward motion, then speeding up backward, then... careful here.
Speeding up or slowing down? The rule is about signs agreeing: the particle speeds up when v and a have the same sign, and slows when they differ.
| Interval | v | a | Speed |
|---|---|---|---|
| (0,1) | + | - | slowing |
| (1,2) | - | - | speeding up |
| (2,3) | - | + | slowing |
| (3,\infty) | + | + | speeding up |
This is the distinction people miss: negative acceleration doesn't mean slowing down. On (1,2) the particle is moving backward and accelerating backward, so it's getting faster while its acceleration is negative.
Distance vs displacement. Over [0,4]: s(0) = 0, s(4) = 64-96+36 = 4, so displacement is 4 m. But the particle went forward to s(1) = 4, back to s(3) = 0, then forward to s(4)=4 — total distance travelled 4 + 4 + 4 = 12 m. §5.0 makes this the difference between \int v\,dt and \int|v|\,dt.
Your turn
1. Find f^{(4)}(x) for f(x) = x^5 - 3x^3 + 2x.
2. Find \frac{d^{20}}{dx^{20}}\cos x.
3. Find \frac{d^n}{dx^n}e^{3x}.
4. If f'' > 0 everywhere and f'(2) = 0, what does f look like near x=2?
Solutions
1. Differentiate four times:
f' = 5x^4 - 9x^2 + 2, \quad f'' = 20x^3 - 18x, \quad f''' = 60x^2 - 18, \quad f^{(4)} = \boxed{120x}
Degree drops by one each time, as it must. Note f^{(5)} = 120 = 5! and f^{(6)} = 0 — a degree-5 polynomial's 6th derivative vanishes.
2. Cosine cycles with period 4. 20 \bmod 4 = 0, so twenty derivatives returns cosine unchanged:
\boxed{\cos x}
3. Each differentiation brings down a factor of 3 by the chain rule:
e^{3x} \to 3e^{3x} \to 9e^{3x} \to 27e^{3x} \to \cdots
\boxed{\frac{d^n}{dx^n}e^{3x} = 3^ne^{3x}}
4. f'(2) = 0 gives a horizontal tangent, and f'' > 0 makes the curve concave up everywhere. So x = 2 is a local minimum.
It's stronger than local, in fact. f'' > 0 everywhere means f' is strictly increasing, so f' is negative before 2 and positive after — the function decreases then increases, with no other turning points possible. x=2 is the global minimum.
That combination — a stationary point plus global convexity — is the entire basis of why gradient descent works on convex problems (§14.1). Find a point where the derivative vanishes and you're done; there is nowhere better.
Check yourself in code
Verify the factorial pattern for derivatives of \frac1x.
For n = 1 \ldots 5, print SymPy's \frac{d^n}{dx^n}x^{-1} and whether it equals \frac{(-1)^n n!}{x^{n+1}}.
Print exactly this:
n=1 -1/x**2 formula matches: True
n=2 2/x**3 formula matches: True
n=3 -6/x**4 formula matches: True
n=4 24/x**5 formula matches: True
n=5 -120/x**6 formula matches: True
import sympy as sp
from math import factorial
x = sp.Symbol('x')
for n in range(1, 6):
d = sp.diff(1/x, x, n)
# compare against (-1)^n * n! / x^(n+1)
print(f"n={n} {str(d):<12} formula matches: ...")
import sympy as sp
from math import factorial
x = sp.Symbol('x')
for n in range(1, 6):
d = sp.diff(1/x, x, n)
formula = (-1)**n * factorial(n) / x**(n+1)
print(f"n={n} {str(d):<12} formula matches: {sp.simplify(d - formula) == 0}")
Differentiating repeatedly gives velocity, then acceleration, then jerk — each the rate of change of the last. The second derivative is the one that earns its keep: its sign is concavity, and combined with f' it tells you whether a curve is rising or falling and how it bends. Polynomials terminate, exponentials are fixed points, trig functions cycle by 4, and \frac1x generates factorials that Taylor series will later cancel. Smoothness comes in classes C^n, and C^\infty still isn't the same as analytic.
That closes the derivative rules. Next module: putting them to work — related rates, approximation, optimization, and root-finding.