Chain Rule
To differentiate a function inside another function, use \frac{d}{dx}f(g(x))=f'(g(x))\cdot g'(x): differentiate the outside function, leave the inside alone, then multiply by the derivative of the inside. Every composite function, such as \sin(x^3) or e^{-x^2}, is handled this way, and the rule extends to any number of layers.
The rule holds wherever g is differentiable at x and f is differentiable at g(x).
Recognizing a composite function
A composite function applies one function to the result of another. In f(g(x)), the function g is the inner function and f is the outer function. To find the layers, imagine evaluating the expression at a number: the last operation you perform belongs to the outer function.
| Expression | Last operation | Layers |
|---|---|---|
| \sin(x^3) | take the sine | outer \sin u, inner x^3 |
| (3x^2+1)^5 | raise to the fifth power | outer u^5, inner 3x^2+1 |
| \ln(x^2+1) | take the logarithm | outer \ln u, inner x^2+1 |
If the last operation is an addition or a multiplication, the expression is a sum or a product, and that rule comes first. The chain rule then appears inside the pieces.
Two forms
The same rule is written in two ways, and each suits a different habit.
| Form | Statement | Convenient when |
|---|---|---|
| Prime (Lagrange) form | \dfrac{d}{dx}f(g(x))=f'(g(x))\cdot g'(x) | the functions have names |
| Leibniz form | with y=f(u) and u=g(x): \dfrac{dy}{dx}=\dfrac{dy}{du}\cdot\dfrac{du}{dx} | you introduce a letter u for the inside |
The Leibniz form says that rates multiply. If y changes twice as fast as u, and u changes three times as fast as x, then y changes six times as fast as x. The du does not literally cancel, but the fraction look is a reliable memory aid.
Step-by-step method
- Split into outer and inner. Call the inner expression u=g(x), so the function becomes f(u).
- Differentiate the outer function. Find f'(u) from the table of derivatives, treating u as the variable.
- Differentiate the inner function. Find u'=g'(x).
- Multiply, substitute back and simplify. Write f'(u)\cdot u', replace u by g(x), and tidy the result.
In step 4 the inside expression is copied unchanged into f'. That is the quickest check on a finished answer.
Examples
Each example uses the same layout: outer, inner, result.
1. (3x^2+1)^5
- Outer: u^5, so f'(u)=5u^4
- Inner: u=3x^2+1, so u'=6x
- Result: 5(3x^2+1)^4\cdot 6x=30x(3x^2+1)^4
2. \sin(x^3)
- Outer: \sin u, so f'(u)=\cos u
- Inner: u=x^3, so u'=3x^2
- Result: \cos(x^3)\cdot 3x^2=3x^2\cos(x^3)
3. e^{-x^2}
- Outer: e^u, so f'(u)=e^u
- Inner: u=-x^2, so u'=-2x
- Result: e^{-x^2}\cdot(-2x)=-2xe^{-x^2}
4. \ln(x^2+1)
- Outer: \ln u, so f'(u)=\dfrac1u
- Inner: u=x^2+1, so u'=2x
- Result: \dfrac{1}{x^2+1}\cdot 2x=\dfrac{2x}{x^2+1}
The logarithm is defined here for every real x, because x^2+1>0 always.
General power rule
When the outer function is a power with a constant exponent, the chain rule gives a shortcut. For a differentiable u=u(x) and a constant n,
\frac{d}{dx}\big[u^n\big]=n\,u^{n-1}\cdot u'.
Example 1 is an instance: n=5 and u=3x^2+1 give 5(3x^2+1)^4\cdot 6x. Setting u=x returns the ordinary power rule, since u'=1. For n=\tfrac12 the rule reads \dfrac{d}{dx}\sqrt u=\dfrac{u'}{2\sqrt u} for u>0.
Every row of the table has a chain-rule version: replace x by u and multiply by u'. Examples 3 and 4 are the exponential and logarithm cases, \dfrac{d}{dx}e^u=u'e^u and \dfrac{d}{dx}\ln u=\dfrac{u'}{u} for u>0.
The exponent n must be a constant. If the exponent also contains x, the power rule does not apply, and the logarithmic method is the right tool.
Nested compositions (three layers)
Each extra layer adds one more factor. For y=\sqrt{\cos(x^2)} there are three layers:
y=\sqrt{w},\qquad w=\cos v,\qquad v=x^2.
The Leibniz form becomes \dfrac{dy}{dx}=\dfrac{dy}{dw}\cdot\dfrac{dw}{dv}\cdot\dfrac{dv}{dx}. Peel one layer at a time:
\frac{dy}{dw}=\frac{1}{2\sqrt w},\qquad \frac{dw}{dv}=-\sin v,\qquad \frac{dv}{dx}=2x.
Multiply and substitute back w=\cos(x^2) and v=x^2:
\frac{dy}{dx}=\frac{1}{2\sqrt{\cos(x^2)}}\cdot\big(-\sin(x^2)\big)\cdot 2x=-\frac{x\sin(x^2)}{\sqrt{\cos(x^2)}}.
The derivative exists where \cos(x^2)>0.
A second case: \sin^2(3x) means (\sin 3x)^2. Its layers are y=w^2, w=\sin v and v=3x, with
\frac{dy}{dw}=2w,\qquad \frac{dw}{dv}=\cos v,\qquad \frac{dv}{dx}=3.
Multiplying and substituting back gives
\frac{dy}{dx}=2\sin 3x\cdot\cos 3x\cdot 3=6\sin 3x\cos 3x.
The double-angle identity \sin 2\theta=2\sin\theta\cos\theta with \theta=3x turns this into 3\sin 6x. Both forms are
the same function. The calculator prints the first one, 6\sin 3x\cos 3x, when
you enter sin(3*x)^2.
Chain rule together with the product rule
Many functions need both rules. Differentiate f(x)=x\sqrt{1-x^2} for \lvert x\rvert<1. The last operation is a multiplication, so start with the product rule using u=x and v=\sqrt{1-x^2}. Then u'=1, and v' needs the chain rule: the outer function is \sqrt w and the inner function is w=1-x^2, with w'=-2x.
v'=\frac{1}{2\sqrt{1-x^2}}\cdot(-2x)=-\frac{x}{\sqrt{1-x^2}}.
Now assemble the product rule u'v+uv' and put everything over a common denominator:
\begin{aligned} f'(x)&=1\cdot\sqrt{1-x^2}+x\cdot\left(-\frac{x}{\sqrt{1-x^2}}\right)\\ &=\frac{(1-x^2)-x^2}{\sqrt{1-x^2}}\\ &=\frac{1-2x^2}{\sqrt{1-x^2}}. \end{aligned}
In the second line, \sqrt{1-x^2} was rewritten as \dfrac{1-x^2}{\sqrt{1-x^2}} so that both terms share a denominator.
Mistakes to avoid
- Forgetting the inner derivative. For \sin(x^3), the answer \cos(x^3) is missing the factor 3x^2. Whenever the inside is anything other than x, a factor u' must appear.
- Evaluating the outer derivative at x instead of at g(x). For \ln(x^2+1), writing \dfrac{2x}{x} is wrong. The outer derivative \dfrac1u must be evaluated at the inside, so it becomes \dfrac{1}{x^2+1}.
- Mixing up \sin^2(3x) and \sin(3x^2). In \sin^2(3x) the square is applied last, so it is the outer function and sine sits in the middle. In \sin(3x^2) the sine is applied last and the inside is 3x^2. The last-operation test from the start of this page settles which is which.
Try it: Open
(3*x^2+1)^5with its steps. The first step is “Power rule + chain rule” with f=3x^2+1, which is the inner function from Example 1; the steps after it differentiate that inner function. The result is printed as 30x(3x^2+1)^4, exactly the form above.
Frequently asked questions
How do I know which function is “inside”?
The inside is whatever you compute first when you evaluate the expression at a number. It is the content of brackets, the expression under a root, the exponent of e, or the argument of a function. In e^{-x^2}, for instance, the exponent -x^2 is the inner function.
How many times can I apply the chain rule?
As many times as there are layers. Each extra layer adds one more factor to the product, so three layers give three factors, as in the \sqrt{\cos(x^2)} example. For long chains, work from the outside in, one layer at a time, and write down the inner expression at each step.
Is the chain rule the same as substitution?
Naming the inside u=g(x) is a substitution, and it is a handy way to organize the work. The chain rule is the statement that tells you what to do next: differentiate with respect to u and multiply by u'. In integration, the reverse of the chain rule is the technique called u-substitution.
Where to go next
- Implicit differentiation: the chain rule applied to a variable y that depends on x.
- Logarithmic differentiation: the tool for exponents that contain x and for long products or quotients.
- Table of derivatives and basic rules: the outer derivatives you look up in step 2.
To confirm your own results, run a composite function through the chain rule derivative calculator and compare it with the step named “Chain rule” or “Power rule + chain rule”.