A function inside a function
is not a power of . It is a power of the expression , so the power rule of lesson 2.3.1 does not apply to it directly. It is a composition (lesson 1.1.3): an inner function fed into an outer function .
The letter names the inner function's output, so and .
To spot the two parts, evaluate the function at a number. At , you first work out (the inner function), then (the outer one). The last step is the outer function.
| function | inner | outer, in terms of |
|---|---|---|
You could expand into six terms and use lesson 2.3.1, but it is long. cannot be expanded at all. The chain rule handles both in one line.
Slopes multiply
Rates that feed into each other multiply. A car that uses 0.06 litres of fuel per km, driving at 80 km per hour, uses litres per hour. The units cancel like fractions: litres per km times km per hour is litres per hour.
A composition works the same way. When moves, moves times as much, and then moves times as much as . So moves times as much as .
Take at . The inner function has slope 2, and at it gives . The outer function has slope , which is 6 at .
A step of 0.05 in is stretched by 2 on the way to , then by about 6 on the way to . The stretches multiply, so moves about times as far as .
As the step shrinks, each stretch settles on a slope, and the total settles on their product.
| step | 0.05 | 0.01 | 0.001 |
|---|---|---|---|
| stretch | 2 | 2 | 2 |
| stretch | 6.1 | 6.02 | 6.002 |
| total | 12.2 | 12.04 | 12.004 |
Algebra agrees. Expanding, , with derivative , which is 12 at .
Rule: Chain rule
Differentiate the outer function, leaving the inside as it is; then multiply by the derivative of the inside. means the outer slope taken at , not at .
That last point matters. For at , the outer slope is taken at , giving 6. Taking it at would give an outer slope of 2 and a total of , which is wrong.
Try it
The loop measures both stretches for from , then the total, for three step sizes.
SymPy then differentiates directly and evaluates the slope at 1.
Worked examples
A linear inside. For , the outer gives and the inner gives 3. So the derivative is , which is 15 at . An inside always adds the factor .
A falling inside. For the inner slope is . The derivative is , so the slope is at . The inner function falls, and its negative factor carries through.
A root. Write as . The outer power gives , and the inside gives :
At that is . Central differences agree.
| gap | 0.1 | 0.01 | 0.001 |
|---|---|---|---|
| central difference at 1 | 0.706222 | 0.707098 | 0.707107 |
A negative power. Write as . The chain rule gives , the same answer as the quotient rule in lesson 2.3.2.
A flat inside. has derivative . At the inner slope is 0, so the whole slope is 0. At it is 24.
The chain rule also agrees with the power rule. , and the chain rule gives , as the power rule does.
Try it
The loop prints the central differences of at 1. SymPy then differentiates each worked example.
SymPy writes as -6*(2*x - 5)**2. The two are equal, because squaring hides the sign inside.
Chains of three
A function can have more than two layers. Take and peel it from the outside in.
| layer | function | its slope | at |
|---|---|---|---|
| inside | , slope 2 | ||
| middle | , slope 6 | ||
| outside | , slope 0.1 |
Each layer adds one stretch factor: . At that is . Central differences give 1.201943, 1.200019 and 1.2 for gaps 0.1, 0.01 and 0.001.
As a formula, the three factors are
Work from the outside in, one layer at a time, and write one factor for each. Skipping a layer is the usual slip.
Where the chain rule breaks
The chain rule needs both slopes: the inner one at , and the outer one at . If either is missing, so is the slope of the composition.
is , the corner of lesson 2.2.2. Its outer function has no slope at (lesson 2.3.1), and its inside is 0 at . The rule gives : 1 for every , for every , and nothing at 0.
Compare . Its inside is never below 1, so the outer slope always exists, and the curve has a slope everywhere.
Try it
The first lines check the chain of three at 1. Then SymPy differentiates and evaluates the slope on both sides of 0.
SymPy writes the slope as sqrt(x**2)/x, which is . It is 1 on the right of 0 and on the left.
Which rule?
Evaluate the function at a number in your head, and look at the last step. That step decides the first rule; the pieces it leaves may need others.
| function | last step | first rule | then |
|---|---|---|---|
| a multiplication | product | chain, for | |
| a division | quotient | chain, for the bottom | |
| a square | chain | quotient, for the inside |
Product, then chain. For , the product rule gives . The chain rule gives . Together:
At the slope is .
Quotient, then chain. For , the slope of the bottom comes from the chain rule: , as worked out above. The quotient rule then gives the first line below. Multiplying its top and bottom by clears the small fraction:
At the slope is 1.
Chain, then quotient. For , the outer square gives . The inside, by the quotient rule, has slope . Multiplied, the derivative is , which is at .
Try it
SymPy differentiates each function in the table and evaluates the slopes quoted above.
sp.factor gathers each answer into one fraction or product, which is how the text writes it.
Lessons 2.3.4 and 2.3.5 use the chain rule with , , sine and cosine as outer functions. Module 2.4 relies on it to find peaks, and lesson 2.6.1 runs it backwards as integration by substitution. Case study 2.3.7 uses it on every discounted payment of a bond, .
Common mistakes
- Forgetting the inner derivative. gives , not .
- Taking the outer slope at . It is taken at : for at 1, the outer slope is 6, not 2.
- Putting the inner derivative inside. gives , not .
- Mixing up inner and outer. The outer function is the last step of the evaluation. In it is the root.
- Skipping a layer. A chain of three functions gives three factors.
- No slope where a link has none. has no slope at 0, because has none at .
The chain rule
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- A composition has an inner function and an outer function . The outer one is the last step of an evaluation.
- Chain rule: , or . The outer slope is taken at .
- Slopes multiply like stretch factors, and units cancel like fractions. A chain of three gives three factors.
- There is no slope where a link has none, as for at 0.
- Which rule? The last step of the evaluation chooses the first rule; its pieces may need others. Check with
sp.diff.