The second derivative measures how fast the slope changes: acceleration for a moving cart, bending for a graph. Use it to tell peaks from valleys in one step, find inflection points, and prove that the flat point of a convex function, such as a squared-error loss, is its lowest point.
Compute a second derivative and read it as the rate of change of the slope: acceleration for the running trip, bending for a graph.
Find where a function is concave up or concave down, and locate its inflection points.
Classify critical points with the second-derivative test, and recognise when the test says nothing.
Prove that a flat point of a function whose second derivative is never negative is its lowest point, and apply this to the running loss.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
The running loss \({L(w)} = {7.5w^2 - 23.5w + 18.5}\) has one flat point, at \({w = 47/30}\). The double well \({x^4 - 2x^2}\) has three, and one of them is a peak. A training method that stops where the slope is zero needs to know which kind of curve it is on. What property of a function guarantees that a flat point is the lowest point of all, with nothing deeper anywhere else?
From the last lesson
1. State Fermat’s theorem, with both of its conditions on \(c\).
Show answer
If \(f\) has a local maximum or minimum at \(c\), \(c\) is not an end of the domain, and \({f'(c)}\) exists, then \({f'(c) = 0}\).
2. Why is 0 a critical point of \({x^3}\) but not an extreme?
Show answer
Its derivative \({3x^2}\) is zero at 0, but positive on both sides, so \({x^3}\) rises before 0 and after it.
Intuition
The first derivative is the slope. The second derivative is the slope of the slope: it says how fast the tilt of the tangent changes as you move right.
Walk along \({x^2}\). At \({x = -1}\) the tangent slopes down with slope \({-2}\), at 0 it is flat, and at 1 it slopes up with slope 2. The slopes rise, the tangent turns anticlockwise, and the curve bends up like a cup. Along \({-x^2}\) the slopes fall, from 2 through 0 to \({-2}\), the tangent turns clockwise, and the curve bends down like a cap.
M04.4.2-F1
Read the slopes from left to right. Rising slopes make a cup, falling slopes make a cap. The second derivative is the rate at which they rise or fall.
So the sign of the second derivative says which way a curve bends, and that settles the flat points: where the tangent is flat and the curve bends up, the point is a valley; where it bends down, a peak.
Build it up
Step 1. Differentiate twice. The second derivative of \(f\), written \({f''}\), is the derivative of \({f'}\). For the running cubic \({g'(x) = 3x^2 - 3}\), so \({g''(x) = 6x}\).
Step 2. Acceleration. For a moving object, position differentiates to velocity and velocity to acceleration. The running trip has position \({s(t) = 2t^2 - t^3/3}\) metres, so
The units divide by time twice: metres per second per second, m/s². At \({t = 1}\) the acceleration is 2 m/s² and the cart is speeding up; at \({t = 3}\) it is \({-2}\) m/s² and the cart is slowing down. At \({t = 2}\) it is 0, and the speed is at its top, 4 m/s.
M04.4.2-F2
The running trip. The acceleration (bottom) is the slope of the velocity (top) at each moment: positive while the cart speeds up, zero at top speed, negative while it slows down.
Step 3. Bending. On a graph the same number measures bending. If \({f'' > 0}\) on an interval, then \({f'}\) is increasing there: this is the rising theorem of M04.4.1, applied to \({f'}\), whose derivative is \({f''}\). The slopes rise from left to right, and the curve bends up.
Step 4. Flat and bending up. Now take a critical point \(c\) with \({f'(c) = 0}\) and \({f''(c) > 0}\). The slope is increasing through \(c\), so it is negative just before \(c\) and positive just after. By the first-derivative test, \(c\) is a valley. One number did the work of a sign chart.
The formal statement
NoteDefinitions: concavity and inflection
Let \(f\) be differentiable on an open interval \(I\). \(f\) is concave up on \(I\) if \({f'}\) is increasing on \(I\), and concave down on \(I\) if \({f'}\) is decreasing on \(I\). A point where \(f\) is continuous and its concavity changes is an inflection point.
Test for concavity (Step 3). If \({f''(x) > 0}\) for every \(x\) in \(I\), \(f\) is concave up on \(I\); if \({f''(x) < 0}\) for every \(x\) in \(I\), it is concave down.
NoteTheorem: the second-derivative test
Suppose \({f'(c) = 0}\) and \({f''(c)}\) exists.
If \({f''(c) > 0}\), \(f\) has a local minimum at \(c\).
If \({f''(c) < 0}\), \(f\) has a local maximum at \(c\).
If \({f''(c) = 0}\), the test says nothing.
Proof. Take \({f''(c) > 0}\). The second derivative is the derivative of \({f'}\), and \({f'(c) = 0}\), so
A positive limit forces the quotient to be positive for every \(h\) close enough to 0 (the argument of M04.4.1, with tolerance half the limit). So for small \(h\), \({f'(c + h)}\) has the sign of \(h\): negative just left of \(c\), positive just right. The first-derivative test gives a local minimum. If \({f''(c) < 0}\) the signs swap, and \(c\) is a local maximum.
The third case is silent for a reason. \({x^4}\), \({-x^4}\) and \({x^3}\) all have \({f'(0) = 0}\) and \({f''(0) = 0}\), yet 0 is a valley of the first, a peak of the second and neither for the third. When \({f''(c) = 0}\), go back to the first-derivative test.
M04.4.2-F4
Three functions with the same first and second derivative at 0, and three different answers.
Now the result that machine learning cares about most.
NoteDefinition: convex
A function with a second derivative is convex on an interval if \({f''(x) \geq 0}\) at every point of the interval.
This is the working definition of this course. The general one, which needs no derivatives, comes in M08.2 and agrees with this one for such functions. Convex asks a little less than concave up: the slope must never fall, but it may stay level, so even a straight line counts as convex.
NoteTheorem: the flat point of a convex function is its lowest point
If \(f\) is convex on an interval \(I\) and \({f'(c) = 0}\) at a point \(c\) inside \(I\), then \({f(x) \geq f(c)}\) for every \(x\) in \(I\).
Proof.First, \({f'}\) never decreases. For \({u < v}\) in \(I\), the mean value theorem applied to \({f'}\) gives a \(\xi\) between them with
because \({f''(\xi) \geq 0}\) and \({v - u > 0}\).
To the right of \(c\). Take \(x\) in \(I\) with \({x > c}\). The mean value theorem applied to \(f\) on \({[c, x]}\) gives a \(\xi\) with \({c < \xi < x}\) and
\[
f(x) - f(c) = f'(\xi)\,(x - c) .
\]
Since \({\xi > c}\) and \({f'}\) never decreases, \({f'(\xi) \geq f'(c) = 0}\), and \({x - c > 0}\). So the product is at least 0, and \({f(x) \geq f(c)}\).
To the left. For \({x < c}\) the same steps give \({x < \xi < c}\), so \({f'(\xi) \leq f'(c) = 0}\) while \({x - c < 0}\). A product of two numbers that are not positive is at least 0, so again \({f(x) \geq f(c)}\).
The running loss is convex.\({L'(w) = 15w - 23.5}\) (M04.3.1), so \({L''(w) = 15 > 0}\) for every \(w\). \({L'}\) is zero only at \({w = 23.5/15 = 47/30}\), so \({L(w)} \geq {L(47/30)} \approx {0.092}\) for every \(w\). No search, however long, can find a lower loss.
The double well is not. Its \({f''(x) = 12x^2 - 4}\) is negative when \({x^2 < 1/3}\), that is between about \({-0.577}\) and 0.577. The theorem does not apply, and rightly so: its flat point at 0 is a peak.
Worked example
Classify the critical points of the running cubic with the second derivative, and find its inflection point.
Step 1. From M04.4.1, \({g'(x) = 3x^2 - 3}\), zero at \({x = -1}\) and \({x = 1}\). Differentiating again gives \({g''(x) = 6x}\).
Step 2: the test.\({g''(-1) = -6 < 0}\), so \({x = -1}\) is a local maximum, with \({g(-1) = 2}\). \({g''(1) = 6 > 0}\), so \({x = 1}\) is a local minimum, with \({g(1) = -2}\). The same answers as the sign chart, from one number each.
Step 3: concavity.\({6x}\) is negative for \({x < 0}\) and positive for \({x > 0}\). So \(g\) is concave down on the left half of the line and concave up on the right half.
Step 4: inflection. The concavity changes at 0 and \(g\) is continuous there, so \({(0, g(0))}\), which is \({(0, 0)}\), is an inflection point. There the slope \({g'(0) = -3}\) is at its most negative: it stops falling and starts rising.
M04.4.2-F3
The worked example. The sign of \({g''}\) at each critical point names it, and the place where \({g''}\) changes sign is the inflection point.
Step 5: convex? No: \({g'' < 0}\) for \({x < 0}\). That is why the valley at 1 is not the lowest point of \(g\).
Code
From scratch, the second derivative found by hand is checked with the second central difference. Estimate the slope at \({x + h/2}\) by \({(f(x + h) - f(x))/h}\) and the slope at \({x - h/2}\) by \({(f(x) - f(x - h))/h}\). Their difference divided by \(h\) estimates \({f''(x)}\):
def second_difference(f, x, h=1e-4):return (f(x + h) -2* f(x) + f(x - h)) / h**2def g(x):return x**3-3* xdef well(x):return x**4-2* x**2def loss(w):return7.5* w**2-23.5* w +18.5for x in [-1.0, 0.0, 1.0]:print(f"x = {x:4.1f}: g'' by hand {6* x:5.1f}, numerically {second_difference(g, x):8.4f}")print("L'' numerically at w = 0, 1, 2:", [round(second_difference(loss, w), 3) for w in (0, 1, 2)])
x = -1.0: g'' by hand -6.0, numerically -6.0000
x = 0.0: g'' by hand 0.0, numerically 0.0000
x = 1.0: g'' by hand 6.0, numerically 6.0000
L'' numerically at w = 0, 1, 2: [15.0, 15.0, 15.0]
The test itself, with the curvature measured the same way:
def second_derivative_test(f, c, h=1e-4): curvature = second_difference(f, c, h)if curvature >1e-6:return"local minimum"if curvature <-1e-6:return"local maximum"return"the test is silent"for c in (-1, 0, 1):print(f"double well at x = {c:2d}: {second_derivative_test(well, c)}")print("x**4 at x = 0:", second_derivative_test(lambda x: x**4, 0))
double well at x = -1: local minimum
double well at x = 0: local maximum
double well at x = 1: local minimum
x**4 at x = 0: the test is silent
The library version differentiates exact polynomials twice and finds where the double well stops being convex:
coefficients of f'': [-4. 0. 12.]
f'' < 0 between [-0.577 0.577]
coefficients of L'': [15.]
Explore
The descent explorer in lesson M04.4.4 marks the sign of the second derivative under the ball. Choose the double well and drag the ball across the middle: \({f''}\) turns negative between about \({-0.58}\) and 0.58.
Pitfalls
M04.4.2-F5
Wrong beside right. On the double well a flat point can be a peak; on the convex running loss the one flat point is the lowest point, and every tangent line stays below the curve.
“The slope is zero here, so this is the minimum.”
Only on a convex function. The double well is flat at 0 and has a peak there. The running loss is convex, so its one flat point is the bottom. The squared-error loss of a linear model is convex; the loss of a neural network usually is not, so there a flat point may be a valley, a peak or neither (M08.11).
“\({f''(c) = 0}\), so \(c\) is an inflection point.”
\({x^4}\) has \({f''(0) = 0}\), yet \({f''(x) = 12x^2}\) is positive on both sides: concave up throughout, no inflection, and 0 is its lowest point. An inflection needs \({f''}\) to change sign, as \({6x}\) does for the running cubic.
“A convex function always has a lowest point.”
\({e^x}\) is convex, since its second derivative \({e^x}\) is positive, but its slope \({e^x}\) is never zero and it has no minimum: it sinks towards 0 as \(x\) moves left and never gets there. The theorem says a flat point of a convex function is the lowest point. It does not promise a flat point.
Check yourself
Recall
1. In words, what does \({f''}\) measure?
Show answer
How fast the slope \({f'}\) changes: acceleration for a moving object, bending for a graph.
2. What is the running trip’s acceleration at \({t = 3}\), and what does it mean?
Show answer
\({a(3) = 4 - 2 \cdot 3 = -2}\) m/s². It is negative, so the cart is slowing down.
3. State the second-derivative test.
Show answer
If \({f'(c) = 0}\) and \({f''(c) > 0}\), \(c\) is a local minimum; if \({f''(c) < 0}\), a local maximum; if \({f''(c) = 0}\), the test says nothing.
4. What does the test say about \({x^4}\) at 0, and what is the truth?
Show answer
Nothing, because \({f''(0) = 0}\). In fact 0 is the lowest point, since \({x^4 \geq 0}\) everywhere.
5. Why is \({w = 47/30}\) the lowest point of the running loss, not just a local minimum?
Show answer
\({L''(w) = 15 > 0}\) for every \(w\), so \(L\) is convex, and a flat point of a convex function is its lowest point.
Exercises
1.★ For \({f(x) = x^3 - 6x^2 + 9x + 1}\), classify the critical points with the second-derivative test and find the inflection point.
Show solution
\({f'(x)} = {3x^2 - 12x + 9} = {3(x - 1)(x - 3)}\), zero at 1 and 3, and \({f''(x) = 6x - 12}\). At 1, \({f''(1) = -6 < 0}\): a local maximum, \({f(1) = 1 - 6 + 9 + 1 = 5}\). At 3, \({f''(3) = 6 > 0}\): a local minimum, \({f(3)} = {27 - 54 + 27 + 1} = {1}\). \({f''}\) changes sign at \({x = 2}\), so the inflection point is \({(2, f(2)) = (2, 3)}\).
2.★★ Show that softplus, \({s(z) = \ln(1 + e^z)}\), is convex on the whole line but has no lowest point.
Show solution
By the chain rule (M04.3.4), with outer function \({\ln u}\) and inner \({u = 1 + e^z}\), \({s'(z) = e^z/(1 + e^z)}\). Dividing top and bottom by \({e^z}\) gives \({1/(e^{-z} + 1)}\), the sigmoid \({\sigma(z)}\). So \({s''(z)} = {\sigma'(z)} = {\sigma(z)(1 - \sigma(z))}\) (M04.3.3). Both factors lie between 0 and 1, so \({s'' > 0}\): \(s\) is convex. But \({s'(z) = \sigma(z) > 0}\) for every \(z\), so there is no critical point, and \(s\) is increasing: every value is beaten by the values to its left. As \(z\) falls, \({s(z)}\) sinks towards \({\ln 1 = 0}\) without reaching it.
3.★★★ Prove that a convex function lies above each of its tangent lines: if \({f'' \geq 0}\) on an interval \(I\) and \(a\) is inside \(I\), then for every \(x\) in \(I\),
\[
f(x) \geq f(a) + f'(a)\,(x - a) .
\]
Show solution
Let \({\varphi(x)} = {f(x) - f'(a)(x - a)}\). Then \({\varphi'(x)} = {f'(x) - f'(a)}\) and \({\varphi''(x) = f''(x) \geq 0}\), so \(\varphi\) is convex on \(I\), and \({\varphi'(a) = 0}\). By the theorem, \({\varphi(x) \geq \varphi(a) = f(a)}\) for every \(x\) in \(I\), which rearranges to the inequality. So on a convex loss the tangent line, the linear model behind a gradient step (M04.4.4), never lies above the loss: the true loss is always at least what the line predicts.
Summary card
The second derivative is the slope of the slope: it says which way a curve bends.
M04.4.2-F1
Rising slopes, a cup; falling slopes, a cap.
\({f'' > 0}\): concave up; \({f'' < 0}\): concave down. An inflection is where the sign changes.
Second-derivative test: \({f'(c) = 0}\) with \({f''(c) > 0}\) is a valley, with \({f''(c) < 0}\) a peak; \({f''(c) = 0}\) says nothing.
Convex, \({f'' \geq 0}\) on an interval: a flat point is the lowest point.
The running loss has \({L'' = 15}\), so \({w = 47/30}\) is its lowest point.
Sources and next steps
Sources. Each was opened and checked against this lesson on 12 November 2026.
Gilbert Strang and Edwin Herman, Calculus Volume 1 (OpenStax), Section 4.5: concave up and down defined by \({f'}\) increasing or decreasing, the test for concavity (Theorem 4.10), inflection points, and the second derivative test (Theorem 4.11), inconclusive when \({f''(c) = 0}\), shown with \({x^3}\), \({x^4}\) and \({-x^4}\).
Matthew Boelkins, Active Calculus, Section 1.6: the second derivative (Definition 1.6.4) as the rate of change of the first, read as acceleration, and concavity defined by an increasing derivative (Definition 1.6.8).
Stephen Boyd and Lieven Vandenberghe, Convex Optimization, free online. Section 3.1.4: a function on an interval is convex exactly when \({f'' \geq 0}\), which means its derivative never decreases; \({x^4}\) has zero second derivative at 0. Section 3.1.3: a convex function lies above its tangent lines, so a point with zero derivative is a global minimiser.
Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong, Mathematics for Machine Learning, Section 7.3: the general definition of a convex function (Definition 7.3) and the second-order condition for twice-differentiable functions.
Next.M04.4.3 Optimisation problems solved exactly turns these tests into a recipe and derives two results that data science uses daily: the mean and the maximum likelihood estimate.