Chapter 5Visualizing the chain rule and product rule
“Using the chain rule is like peeling an onion: you have to deal with each layer at a time, and if it is too big you will start crying.” (Anonymous professor)
In the last videos I talked about the derivatives of simple functions, things like powers of , , and exponentials, the goal being to have a clear picture or intuition to hold in your mind that explains where these formulas come from.
Most functions you use to model the world involve mixing, combining and tweaking these simple functions in some way; so our goal now is to understand how to take derivatives of more complicated combinations; where again, I want you to have a clear picture in mind for each rule.
This really boils down into three basic ways to combine functions together: Adding them, multiplying them, and putting one inside the other; also known as composing them. Sure, you could say subtracting them, but that’s really just multiplying the second by , then adding. Likewise, dividing functions is really just the same as plugging one into the function , then multiplying.
Most functions you come across just involve layering on these three types of combinations, with no bound on how monstrous things can become. But as long as you know how derivatives play with those three types of combinations, you can always just take it step by step and peel through the layers.
So, the question is, if you know the derivatives of two functions, what is the derivative of their sum, of their product, and of the function compositions between them?
The sum rule is the easiest, if somewhat tongue-twisting to say out loud: The derivative of a sum of two functions is the sum of their derivatives. But it’s worth warming up with an example and really thinking through what it means to take a derivative of a sum of two functions, since the derivative patterns for products and function composition won’t be so straight forward, and will require this kind of deeper thinking.
For example, let's think about this function . It's a function where, for every input, you add together the values of and at that point.
Given the input , the output of the function is the height of the sine graph represented by the blue bar plus the height of the parabola represented by the green bar.
For the derivative, you ask what happens as you nudge the input slightly, maybe increasing it to . The difference in the value of between these two values is what we call .
Well, pictured like this, I think you’ll agree that the total change in height is whatever the change to the sine graph is, what we might call , plus whatever the change to is, .
This gives us as the sum of change of the two functions.
We know the derivative of sine is cosine, and what that means is that this little change would be about . It’s proportional to the size of , with a proportionality constant equal to cosine of whatever input we started at. Similarly, because the derivative of is , the change in the height of the graph is about .
So, , the ratio of the tiny change to the sum function to the tiny change in that caused it, is indeed , the sum of the derivatives of its parts.
What is the derivative of the function ?
Things are a bit different for the product of two functions. Let’s think through why, in terms of tiny nudges. In this case, I don’t think graphs are our best bet for visualizing things. Pretty commonly in math, all levels of math really, if you’re dealing with a product of two things, it helps to try to understand it as some form of area.
For example, for the function , you might try to configure some mental setup of a box whose side-lengths are and .
What would that mean? Well, since these are functions, you might think of these sides as adjustable; dependent on the value of , which you might think of as a number that you can freely adjust.
So, just getting the feel for this, focus on that top side, whose changes as the function . As you change the value of up from , it increases up to a length of as moves towards its peak. After that, it starts decreasing as comes down from . And likewise, that height changes as .
So , defined as this product, is the area of this box. For the derivative, think about how a tiny change to by influences this area; that resulting change in area is . That nudge to causes the width to change by some small , and the height to change by some .
This gives us three little snippets of new area: A thin rectangle on the bottom, whose area is its width, , times its thin height, ; there’s a thin rectangle on the right, whose area is its height, , times its thin width, . And there’s also a bit in the corner. But we can ignore it, since its area will ultimately be proportional to , which becomes negligible as goes to .
This is very similar to what I showed in the last chapter, with the diagram. Just like then, keep in mind that I’m using somewhat beefy changes to draw things, so we can see them, but in principle think of as very small, meaning and are also very small.
So we are interested in finding the change to the area of this rectangle represented by the two smaller rectangles highlighted in yellow.
Applying what we know about the derivative of sine and , that tiny change is , and that tiny change is .
Dividing out by that , the derivative is by the derivative of , plus by the derivative of sine.
This line of reasoning works for any two functions.
A common mnemonic for the product rule is to say in your head "left d right, right d left". In this example, , "left d right" means you take the left function, in this case , times the derivative of the right, , which gives . Then you add "right d left": the right function, , times the derivative of the left, .
Out of context, this feels like kind of a strange rule, but when you think of this adjustable box you can actually see how those terms represent slivers of area. "Left d right" is the area of this bottom rectangle, and “right d left” is the area of this rectangle on the right.
By the way, I should mention that if you multiply by a constant, say , things end up much simpler. The derivative is just that same constant times the derivative of the function, in this case . I’ll leave it to you to pause and ponder to verify that this makes sense.
Aside from addition and multiplication, the other common way to combine functions that comes up all the time is function composition. For example, let’s say we take the function , and shove it inside to get a new function, . Or, in other words, the output of the function gets fed as input to sine function.
What’s the derivative of this new function?
Here I’ll choose yet another way to visualize things, just to emphasize that in creative math, we have lots of options. I’ll put up three number lines. The top one will hold the value of , the second one will represent the value of , and the third line will hold the value of .
That is, the function gets you from line to line , and the function sine gets you from line to line . In the image, I'm showing an value of on the first number line. So the second number line, which just displays , is showing the ouput of the inner function, . The third number line shows , which is really just the sine of the previous value, so .
What is the value of the composed function given the input ? To get a hang of this visualization technique, go from the first line to the second line to the third line.
As I shift that value of , maybe up to the value , then the value on the second shifts to whatever is, in this case . And that bottom value, being the , will go over to whatever is.
So for the derivative, let’s again think of nudging that -value by some little . I find it helpful to imagine starting out as some actual number, maybe , and as some small number approaching zero, like .
The resulting nudge to this second value, the change to caused by such a , is what we might call . You can expand this as . For our specific input that length would be , but it helps to keep it written as for now. In fact let me go one step further and give a new name to , maybe , so this nudge is just .
Now think of that third value, which is pegged at . Its change is , the tiny change caused by the nudge . Well, we know the derivative of sine, so we can expand as ; that’s what it means for the derivative of sine to be cosine.
Now we can unfold the transformation, replacing with and with . So the bottom nudge becomes and the middle nudge becomes . Of course, we also know that and so we can substitute that into the diagram as well.
It’s always good to remind yourself of what this all actually means. In this case where we started at up top, this means that the size of that nudge on the third line is about multiplied by the size of ; proportional to the size of , where the derivative here gives us that proportionality constant.
Since the nudge on the third line represents the change to our initial function when we introduced the small nudge , we can rearrange the expression and this gives us the derivative of the function.
Notice what we have here, we have the derivative of the outside function, still taking in the unaltered inside function, and we multiply it by the derivative of the inside function.
Again, there’s nothing special about and . If you have two functions and , the derivative of their composition function is the derivative of , evaluated at , times the derivative of . This is what we call the “chain rule”.
Notice, for the derivative of , I’m writing it as instead of . On the symbolic level, this serves as a reminder that you still plug in the inner function to this derivative. But it’s also an important reflection of what this derivative of the outer function actually represents.
Remember, in our three-lines setup, when we took the derivative of sine on the bottom, we expanded the size of the nudge as . This was because we didn’t immediately know how the size of that bottom nudge depended on , that’s kind of the whole thing we’re trying to figure out, but we could take the derivative with respect to the intermediate variable . That is, figure out how to express the size of that nudge as multiple of . Then it unfolded by figuring out what was.
So in this chain rule expression we’re saying to look at the ratio between the tiny change in and the tiny change in that caused it, where is the value that we’re plugging into . Then multiply that by the tiny change in divided by the tiny change in that caused it.
The ’s cancel to give the ratio between a tiny change in the final output, and the tiny change to the input that, through a certain chain of events, brought it about. That cancellation of is more than just a notational trick, it’s a genuine reflection of the tiny nudges that underpin calculus.
So those are the three basic tools in your belt to handle derivatives of functions that combine many smaller things: The sum rule, the product rule and the chain rule. I should say, there’s a big difference between knowing what the chain rule and product rules are, and being fluent with applying them in even the most hairy of situations.
I said this at the start of the series, but it’s worth repeating: Watching and reading about the mechanics of calculus will never substitute for practicing them yourself, and building the muscles to do these computations yourself. I wish I could offer to do that for you, but I’m afraid the ball is in your court, my friend, to seek out practice.
What I can offer, and what I hope I have offered, is to show you where these rules come from, to show that they’re not just something to be memorized and hammered away; but instead are natural patterns that you too could have discovered by just patiently thinking through what a derivative means.
In the next lesson, I’ll be talking about related rates.
As a fun exercise, think about the derivative of . First, use the chain rule, thinking of this as shoving the function into the function , then taking the derivative of the outside multiplied by the derivative of the inside.
Then, think of it using the product rule, interpreting it as , and think about how this relates to the visual for the derivative of shown in the last video. That should give a deeper feel for the chain rule.
Special thanks to those below for supporting the original video behind this post, and to current patrons for funding ongoing projects. If you find these lessons valuable, consider joining.