04 - Visualizing the chain rule and product rule
3.28M subscribers
SUBSCRIBED
A visual explanation of what the chain rule and product rule are, and why they are true. Full series: http://3b1b.co/calculusBrought to you by you: http://3b1b.co/eoc4-thanksAnd by Brilliant: https://brilliant.org/3b1bSeries like this one are funded largely by the community, through Patreon, where supporters get early access as the series is being produced.http://3b1b.co/support------------------ 3blue1brown is a channel about animating math, in all senses of the word animate. And you know the drill with YouTube, if you want to stay posted about new videos, subscribe, and click the bell to receive notifications (if you're into that). If you are new to this channel and want to see more, a good place to start is this playlist: http://3b1b.co/recommendedVarious social media stuffs: Website: https://www.3blue1brown.comTwitter: https://twitter.com/3Blue1BrownPatreon: https://patreon.com/3blue1brownFacebook: https://www.facebook.com/3blue1brownReddit: https://www.reddit.com/r/3Blue1Brown
00:15
In the last videos I talked about the derivatives of simple functions, things like powers of
00:18
x, sin(x), and exponentials, the goal being to have a clear picture or intuition to hold
00:22
in your mind that explains where these formulas come from.
00:27
Most functions you use to model the world involve mixing, combining and tweaking these
00:32
these simple functions in some way; so our goal now is to understand how to take derivatives
00:38
of more complicated combinations; where again, I want you to have a clear picture in mind
00:45
for each rule.
00:50
This really boils down into three basic ways to combine functions together: Adding them,
00:55
multiplying them, and putting one inside the other; also known as composing them.
01:00
Sure, you could say subtracting them, but that’s really just multiplying the second
01:04
by -1, then adding.
01:08
Likewise, dividing functions is really just the same as plugging one into the function
01:14
1/x, then multiplying.
01:18
Most functions you come across just involve layering on these three types of combinations,
01:23
with no bound on how monstrous things can become.
01:27
But as long as you know how derivatives play with those three types of combinations, you
01:31
can always just take it step by step and peal through the layers.
01:37
So, the question is, if you know the derivatives of two functions, what is the derivative of
01:44
their sum, of their product, and of the function compositions between them?
01:50
The sum rule is the easiest, if somewhat tounge-twisting to say out loud: The derivative of a sum of
01:56
two functions is the sum of their derivatives.
01:59
But it’s worth warming up with this example by really thinking through what it means to
02:04
take a derivative of a sum of two functions, since the derivative patterns for products
02:09
and function composition won’t be so straight forward, and will require this kind of deeper
02:15
thinking.
02:16
The function f(x) = sin(x) + x2 is a function where, for every input, you add together the
02:24
values of sin(x) and x2 at that point.
02:30
For example, at x = 0.5, the height of the sine graph is given by this bar, the height
02:38
of the x2 parabola is given by this bar, and their sum is the length you get by stacking
02:46
them together.
02:48
For the derivative, you ask what happens as you nudge the input slightly, maybe increasing
02:53
it to 0.5+dx.
02:57
The difference in the value of f between these two values is what we call df.
03:03
Well, pictured like this, I think you’ll agree that the total change in height is whatever
03:09
the change to the sine graph is, what we might call d(sin(x)), plus whatever the change to
03:16
x2 is, d(x2).
03:23
We know the derivative of sine is cosine, and what that means is that this little change
03:29
d(sin(x)) would be about cos(x)dx.
03:33
It’s proportional to the size of dx, with a proportionality constant equal to cosine
03:40
of whatever input we started at.
03:43
Similarly, because the derivative of x2 is 2x, the change in the height of the x2 graph
03:50
is about 2x*dx.
03:53
So, df/dx, the ratio of the tiny change to the sum function to the tiny change in x that
04:03
caused it, is indeed cos(x)+2x, the sum of the derivatives of its parts.
04:11
But like I said, things are a bit different for products.
04:15
Let’s think through why, in terms of tiny nudges.
04:20
In this case, I don’t think graphs are our best bet for visualizing things.
04:23
Pretty commonly in math, all levels of math really, if you’re dealing with a product
04:28
of two things, it helps to try to understand it as some form of area.
04:33
In this case, you might try to configure some mental setup of a box whose side-lengths are
04:37
sin(x) and x2.
04:40
What would that mean?
04:41
Well, since these are functions, you might think of these sides as adjustable; dependent
04:47
on the value of x, which you might think of as a number that you can freely adjust.
04:51
So, just getting the feel for this, focus on that top side, whose changes as the function
04:59
sin(x).
05:01
As you change the value of x up from 0, it increases in up to a length of 1 as sin(x)
05:07
moves towards its peak.
05:09
After that, it starts decreasing as sin(x) comes down from 1.
05:15
And likewise, that height changes as x2.
05:19
So f(x), defined as this product, is the area of this box.
05:27
For the derivative, think about how a tiny change to x by dx influences this area; that
05:34
resulting change in area is df.
05:38
That nudge to x causes the width to change by some small d(sin(x)), and the height to
05:46
change by some d(x2).
05:50
This gives us three little snippets of new area: A thin rectangle on the bottom, whose
05:55
area is its width, sin(x), times its thin height, d(x2); there’s a thin rectangle
06:02
on the right, whose area is its height, x2, times its thin width, d(sin(x)).
06:11
And there’s also bit in the corner.
06:12
But we can ignore it, since its area will ultimately be proportional to dx2, which becomes
06:20
negligible as dx goes to 0.
06:24
This is very similar to what I showed last video, with the x2 diagram.
06:29
Just like then, keep in mind that I’m using somewhat beefy changes to draw things, so
06:34
we can see them, but in principle think of dx as very very small, meaning d(x2) and d(sin(x))
06:43
are also very very small.
06:47
Applying what we know about the derivative of sine and x2, that tiny change d(x2) is
06:53
2x*dx, and that tiny change d(sin(x)) is cos(x)dx.
07:04
Dividing out by that dx, the derivative df/dx is sin(x) by the derivative of x2, plus x2
07:13
by the derivative of sine.
07:21
This line of reasoning works for any two functions.
07:29
A common mnemonic for the product rule is to say in your head “left d right, right
07:32
d left”.
07:34
In this example, sin(x)*x2, “left d right” means you take the left function, in this
07:41
case sin(x), times the derivative of the right, x2, which gives 2x.
07:45
Then you add “right d left”: the right function, x2, times the derivative of the
07:51
left, cos(x).
07:52
Out of context, this feels like kind of a strange rule, but when you think of this adjustable
08:02
box you can actually see how those terms represent slivers of area.
08:06
“Left d right” is the area of this bottom rectangle, and “right d left” is the area
08:13
of this rectangle on the right.
08:20
By the way, I should mention that if you multiply by a constant, say 2*sin(x), things end up
08:26
much simpler.
08:27
The derivative is just that same constant times the derivative of the function, in this
08:32
case 2*cos(x).
08:33
I’ll leave it to you to pause and ponder to verify that this makes sense.
08:42
Aside from addition and multiplication, the other common way to combine functions that
08:47
comes up all the time is function composition.
08:53
For example, let’s say we take the function x2, and shove it on inside sin(x) to get a
08:58
new function, sin(x2).
09:01
What’s the derivative of this new function?
09:04
Here I’ll choose yet another way to visualize things, just to emphasize that in creative
09:10
math, we have lots of options.
09:12
I’ll put up three number lines.
09:15
The top one will hold the value of x, the second one will represent the value of x2,
09:22
and that third line will hold the value of sin(x2).
09:26
That is, the function x2 gets you from line 1 to line 2, and the function sine gets you
09:31
from line 2 to line 3.
09:34
As I shift that value of x, maybe up to the value 3, then value on the second shifts to
09:42
whatever x2 is, in this case 9.
09:45
And that bottom value, being the sin(x2), will go over to whatever the sin(9) is.
09:55
So for the derivative, let’s again think of nudging that x-value by some little dx,
10:01
and I always think it’s helpful to think of x starting as some actual number, maybe
10:06
1.5.
10:08
The resulting nudge to this second value, the change to x2 caused by such a dx, is what
10:15
we might call d(x2).
10:16
You can expand this as 2xdx, which for our specific input that length would be 2(1.5)*dx,
10:26
but it helps to keep it written as d(x2) for now.
10:31
In fact let me go one step further and give a new name to x2, maybe h, so this nudge d(x2)
10:40
is just dh.
10:42
Now think of that third value, which is pegged at sin(h).
10:47
It’s change d(sin(h)); the tiny change caused by the nudge dh.
10:55
By the way, the fact that it’s moving left while the dh bump is to the right just means
11:00
that this change d(sin(h)) is some negative number.
11:05
Because we know the derivative of sine, we can expand d(sin(h)) as cos(h)*dh; that’s
11:15
what it means for the derivative of sine to be cosine.
11:19
Unfolding things, replacing h with x2 again, that bottom nudge is cos(x2)d(x2).
11:26
And we could unfold further, noting that d(x2) is 2x*dx.
11:36
And it’s always good to remind yourself of what this all actually means.
11:44
In this case where we started at x = 1.5 up top, this means that the size of that nudge
11:51
on the third line is about cos(1.52)2(1.5)(the size of dx); proportional to the size of dx,
12:04
where the derivative here gives us that proportionality constant.
12:11
Notice what we have here, we have the derivative of the outside function, still taking in the
12:17
unaltered inside function, and we multiply it by the derivative of the inside function.
12:25
Again, there’s nothing special about sin(x) and x2.
12:29
If you have two functions g(x) and h(x), the derivative of their composition function g(h(x))
12:37
is the derivative of g, evaluated at h(x), times the derivative of h.
12:47
This is what we call the “chain rule”.
12:51
Notice, for the derivative of g, I’m writing it as dg/dh instead of dg/dx.
12:58
On the symbolic level, this serves as a reminder that you still plug in the inner function
13:05
to this derivative.
13:06
But it’s also an important reflection of what this derivative of the outer function
13:11
actually represents.
13:13
Remember, in our three-lines setup, when we took the derivative of sine on the bottom,
13:18
we expanded the size of the nudge d(sin) as cos(h)*dh.
13:24
This was because we didn’t immediately know how the size of that bottom nudge depended
13:29
on x, that’s kind of the whole thing we’re trying to figure out, but we could take the
13:34
derivative with respect to the intermediate variable h.
13:38
That is, figure out how to express the size of that nudge as multiple of dh.
13:45
Then it unfolded by figuring out what dh was.
13:53
So in this chain rule expression, we’re saying look at the ratio between a tiny change
13:57
in g, the final output, and a tiny change in h that caused it, h being the value that
14:03
we’re plugging into g.
14:05
Then multiply that by the tiny change in h divided by the tiny change in x that caused
14:10
it.
14:13
The dh’s cancel to give the ratio between a tiny change in the final output, and the
14:18
tiny change to the input that, through a certain chain of events, brought it about.
14:24
That cancellation of dh is more than just a notational trick, it’s a genuine reflection
14:29
of the tiny nudges that underpin calculus.
14:36
So those are the three basic tools in your belt to handle derivatives of functions that
14:41
combine many smaller things: The sum rule, the product rule and the chain rule.
14:47
I should say, there’s a big difference between knowing what the chain rule and product rules
14:54
are, and being fluent with applying them in even the most hairy of situations.
14:58
I said this at the start of the series, but it’s worth repeating: Watching videos, any
15:00
videos, about these mechanics of calculus will never substitute for practicing them
15:06
yourself, and building the muscles to do these computations yourself.
15:10
I wish I could offer to do that for you, but I’m afraid the ball is in your court, my
15:15
friend, to seek out practice.
15:18
What I can offer, and what I hope I have offered, is to show you where these rules come from,
15:24
to show that they’re not just something to be memorized and hammered away; but instead
15:27
are natural patterns that you too could have discovered by just patiently thinking through
15:33
what a derivative means.
15:37
Thank you to everyone who supported this series, and once more I’d like to say a special
15:43
thanks to Brilliant.org.
15:46
For those of you who want to go flex those problem solving muscles, Brilliant offers
15:50
a platform aimed at training you to think like a mathematician.
15:54
I don’t know about you, but I’ve always found it all too easy to fall into the habit
16:00
of just reading math or watching lectures without taking the time to do some real problem-solving
16:05
in between, even though that’s always the part where I learn the most.
16:10
Brilliant is a great place to get that practice, and if you visit brilliant.org/3b1b, or more
16:16
simply follow the link on the screen and in the description, it lets them know you came
16:20
from this channel.
16:22
Their calculus material is a nice complement to this series, but some of my other favorites
16:27
are their probability and complex algebra sequences.