Why Two Applications of the Chain Rule Produce Two Terms
The first derivative of a composite function \(f(g(x))\) is given by the chain rule: \(\dfrac{d}{dx}f(g(x))=f'(g(x))\,g'(x)\). To find the second derivative, differentiate that product. Both factors depend on \(x\), so the product rule is needed, and one of the factors, \(f'(g(x))\), is itself a composition that needs another chain-rule step.
The result is a formula with two terms. Students who memorize only the first term, or who forget to square the inner derivative, lose the structure that makes the formula reliable. Deriving it once makes it easy to rebuild whenever needed.
Deriving the Formula
Start with the first derivative \(f'(g(x))\,g'(x)\) and apply the product rule, treating \(f'(g(x))\) as the first factor and \(g'(x)\) as the second:
The derivative of the second factor is \(g''(x)\). For the first, apply the chain rule to \(f'\) with inner function \(g\): \(\dfrac{d}{dx}f'(g(x))=f''(g(x))\,g'(x)\). Substituting gives \(f''(g(x))\,g'(x)\cdot g'(x)+f'(g(x))\,g''(x)\), which is the formula above. The square appears because \(g'(x)\) enters twice: once from the first derivative and once from differentiating \(f'(g(x))\).
Worked Examples
Worked Example: A Power of a Polynomial
Find \(\dfrac{d^2}{dx^2}(x^2+1)^3\).
Let \(f(u)=u^3\) and \(g(x)=x^2+1\). Then \(f'(u)=3u^2\), \(f''(u)=6u\), \(g'(x)=2x\), and \(g''(x)=2\). Substitute into the formula:
Check: expand \((x^2+1)^3=x^6+3x^4+3x^2+1\). Its second derivative is \(30x^4+36x^2+6\). At \(x=1\) this equals \(72\), and the factored result gives \(6(2)(6)=72\), in agreement.
Worked Example: A Trigonometric Function of a Power
Find \(\dfrac{d^2}{dx^2}\sin(x^2)\).
Here \(f(u)=\sin u\) and \(g(x)=x^2\), so \(f'(u)=\cos u\), \(f''(u)=-\sin u\), \(g'(x)=2x\), and \(g''(x)=2\):
Check at \(x=0\): the formula gives \(2\). Near the origin, \(\sin(x^2)\approx x^2\), whose second derivative is \(2\), so the values agree.
Worked Example: An Exponential of a Quadratic
Find \(\dfrac{d^2}{dx^2}e^{2x^2}\).
With \(f(u)=e^u\) and \(g(x)=2x^2\), we have \(f'(u)=f''(u)=e^u\), \(g'(x)=4x\), and \(g''(x)=4\):
The result is positive for every \(x\), so the graph of \(e^{2x^2}\) is concave up everywhere. At \(x=0\), the second derivative is \(4\), matching the series \(e^{2x^2}=1+2x^2+\cdots\), whose second derivative at \(0\) is \(4\).
Worked Example: A Linear Inner Function
Find \(\dfrac{d^2}{dx^2}\ln(3x+1)\) for \(x>-\tfrac13\).
Let \(f(u)=\ln u\) and \(g(x)=3x+1\). Then \(f'(u)=\tfrac1u\), \(f''(u)=-\tfrac1{u^2}\), \(g'(x)=3\), and \(g''(x)=0\). The second term vanishes because \(g''=0\):
This is a useful special case: when the inner function is linear, the second derivative reduces to \(f''(g(x))\) times the square of the slope of the inner line.
Using the Formula for Concavity
The second derivative tells you where a graph is concave up or concave down, and a composite function is a common place to need this. When the second derivative changes sign, the graph has a point of inflection. The two-term formula organizes that analysis: the first term is nonnegative whenever \(f''(g(x))\ge0\), because \((g'(x))^2\) is never negative, so the sign of the whole expression depends on how the two terms compete.
Worked Example: Inflection Points of a Bell Curve
Find the points of inflection of \(f(x)=e^{-x^2}\).
Let the outer function be \(e^u\) and the inner function be \(g(x)=-x^2\), so \(g'(x)=-2x\) and \(g''(x)=-2\). Then
The exponential factor is positive, so the sign of \(f''\) is the sign of \(4x^2-2\). It is zero at \(x=\pm\tfrac1{\sqrt2}\), negative for \(|x|<\tfrac1{\sqrt2}\) (concave down), and positive for \(|x|>\tfrac1{\sqrt2}\) (concave up). The concavity changes at both values, so the graph has points of inflection at \(x=\pm\tfrac{1}{\sqrt2}\). This explains the familiar shape: the bell is concave down near its peak and concave up in its tails.
Worked Example: Acceleration of a Particle
A particle moves along a line with position \(s(t)=\sqrt{t^2+1}\) for \(t\ge0\). Find its acceleration.
Let \(f(u)=u^{1/2}\) and \(g(t)=t^2+1\). Then \(f'(u)=\tfrac12u^{-1/2}\), \(f''(u)=-\tfrac14u^{-3/2}\), \(g'(t)=2t\), and \(g''(t)=2\):
The acceleration is always positive, so the particle's velocity is always increasing, even though the velocity \(s'(t)=\dfrac{t}{\sqrt{t^2+1}}\) never exceeds \(1\). Check at \(t=0\): the formula gives \(s''(0)=1\), and direct differentiation of the velocity \(\dfrac{t}{\sqrt{t^2+1}}\) at \(0\) also gives \(1\).
Why the Product Is Not Just \(f''\) Times \(g''\)
A tempting shortcut is to treat the second derivative as the composite of the second derivatives, writing \(f''(g(x))\,g''(x)\). That mistake confuses repeated differentiation with composition. Each derivative applies the chain rule once, which multiplies by \(g'(x)\) each time, and the product rule then splits the second differentiation across the two factors. A numerical test shows how large the error can be: for \(\sin(x^2)\) at \(x=1\), the correct value is \(2\cos 1-4\sin 1\approx-2.28\), while \(f''(g(x))\,g''(x)=-2\sin 1\approx-1.68\).
The Formula in Leibniz Notation
If \(y=f(u)\) and \(u=g(x)\), the first-derivative chain rule reads \(\dfrac{dy}{dx}=\dfrac{dy}{du}\dfrac{du}{dx}\). The second-derivative version has the same two-term structure:
Notice that \(\dfrac{d^2y}{dx^2}\) is not obtained by multiplying \(\dfrac{d^2y}{du^2}\) by \(\dfrac{d^2u}{dx^2}\). The notation looks as if the \(du^2\) terms might cancel, but the symbols are not ordinary fractions here, so the correct formula must be derived with the product rule, as above.
Worked Example: Cosine of a Quadratic
Find \(\dfrac{d^2}{dx^2}\cos(3x^2)\) and evaluate it at \(x=0\).
Let \(f(u)=\cos u\) and \(g(x)=3x^2\), so \(f'(u)=-\sin u\), \(f''(u)=-\cos u\), \(g'(x)=6x\), and \(g''(x)=6\):
At \(x=0\), both terms are zero, so the second derivative is \(0\). The series confirms it: \(\cos(3x^2)=1-\tfrac92x^4+\cdots\) has no \(x^2\) term, so its second derivative at \(0\) vanishes. The graph is flat to second order at the origin, which is why the origin is a degenerate-looking maximum.
Common Mistakes
Dropping the square. The first term has \((g'(x))^2\), not \(g'(x)\). Writing \(f''(g(x))\,g'(x)\) confuses the second derivative with the first-derivative structure. In the \(\sin(x^2)\) example, using \(2x\) instead of \(4x^2\) gives the wrong coefficient.
Forgetting the second term. The term \(f'(g(x))\,g''(x)\) vanishes only when \(g''=0\), which happens when the inner function is linear. For any other inner function it contributes, as the examples with \(x^2\) and \(2x^2\) show.
Evaluating \(f''\) at the wrong place. Both \(f'\) and \(f''\) are evaluated at \(g(x)\), not at \(x\). For \(\sin(x^2)\), the second derivative of the outer function is \(-\sin(x^2)\), not \(-\sin x\).
A Reliable Procedure
Write the function as \(f(g(x))\) and identify \(f\) and \(g\) explicitly.
Find \(f'(u)\), \(f''(u)\), \(g'(x)\), and \(g''(x)\) separately before combining them.
Form \(f''(g(x))(g'(x))^2+f'(g(x))g''(x)\), substituting \(u=g(x)\) in the outer derivatives.
Compare with a direct expansion or a series at a convenient point such as \(x=0\) or \(x=1\).
Second derivatives of composite functions matter for concavity, for acceleration along a path described by a composite position function, and for deciding whether a critical point is a maximum or a minimum. The next tutorial explains from first principles why this formula always has exactly two terms.
Check Your Understanding
- Use the formula to find \(\dfrac{d^2}{dx^2}(2x+1)^4\). Which term vanishes, and why?
- Find \(\dfrac{d^2}{dx^2}\cos(3x^2)\) and evaluate it at \(x=0\).
- Find \(\dfrac{d^2}{dx^2}e^{x^2}\) and explain why the graph of \(e^{x^2}\) is concave up everywhere.
- A student writes \(\dfrac{d^2}{dx^2}\sin(x^2)=-\sin(x^2)\cdot2x\). Identify two errors.
- A particle has position \(s(t)=\sqrt{t^2+4}\). Use the formula with \(f(u)=\sqrt u\) to find its acceleration, and show that it equals \(4/(t^2+4)^{3/2}\).