# Chain rule

## Video transcript

- [Instructor] What we're going to go over in this video is one of the
core principles in calculus, and you're going to use it any
time you take the derivative, anything even reasonably complex. And it's called the chain rule. And when you're first exposed to it, it can seem a little daunting
and a little bit convoluted. But as you see more and more examples, it'll start to make sense,
and hopefully it'd even start to seem a little bit simple
and intuitive over time. So let's say that I had a function. Let's say I have a function
h of x, and it is equal to, just for example, let's say
it's equal to sine of x, let's say it's equal to sine of x squared. Now, I could've written that, I could've written it like this, sine squared of x, but it'll
be a little bit clearer using that type of notation. So let me make it so I have h of x. And what I'm curious about
is what is h prime of x? So I want to know h prime of x, which another way of writing it is the derivative of h with respect to x. These are just different notations. And to do this, I'm going
to use the chain rule. I'm going to use the chain rule, and the chain rule comes
into play every time, any time your function can
be used as a composition of more than one function. And as that might not
seem obvious right now, but it will hopefully, maybe by the end of this
video or the next one. Now, what I want to do is a little bit of a thought experiment, a little bit of a thought experiment. If I were to ask you what is the derivative with respect to x, if I were to just apply
the derivative operator to x squared with respect
to x, what do I get? Well, this gives me two x. We've seen that many,
many, many, many times. Now, what if I were to take the
derivative with respect to a of a squared? Well, it's the exact same thing. I just swapped an a for the x's. This is still going to be equal to two a. Now I will do something that might be a little bit more bizarre. What if I were to take the
derivative with respect to sine of x, with respect to sine of x of, of sine of x, sine of x squared? Well, wherever I had the x's
up here, the a's over here, I just replace it with a sine of x. So this is just going to be
two times the thing that I had, so whatever I'm taking the
derivative with respect to. Here it was with respect to x. Here with respect to a. Here's with respect to sine of x. So it's going to be two times sine of x. Now, so the chain rule tells us that this derivative is
going to be the derivative of our whole function with respect, or the derivative of this
outer function, x squared, the derivative of x squared, the derivative of this outer function with respect to sine of x. So that's going to be two sine of x, two sine of x. So we could view it as the
derivative of the outer function with respect to the inner, two sine of x. We could just treat sine of
x like it's kind of an x. And it would've been just two x, but instead it's a sine of x. We say two sine of x times, times the derivative, do this is green, times the derivative of
sine of x with respect to x. Times the derivative of
sine of x with respect to x, well, that's more straightforward, a little bit more intuitive. The derivative of sine of x with respect to x, we've
seen multiple times, is cosine of x, so times cosine of x. And so there we've applied the chain rule. It was the derivative
of the outer function with respect to the inner. So derivative of sine of x squared with respect to sine
of x is two sine of x, and then we multiply that times
the derivative of sine of x with respect to x. So let me make it clear. This right over here is the derivative. We're taking the derivative of, we're taking the derivative
of sine of x squared. So let me make it clear. That's what we were
taking the derivative of with respect to sine of x, with respect to sine of x. And then we're multiplying that times the derivative of sine of x, the derivative of sine of x with respect to, with respect to x. And this is where it might start making a little bit of intuition. You can't really treat
these differentials, this d whatever, this
dx, this d sine of x, as a number. And you really can't, this notation makes it
look like a fraction because intuitively
that's what we're doing. But if you were to treat
'em like fractions, then you could think about
canceling that and that. And once again, this isn't
a rigorous thing to do, but it can help with the intuition. And then what you're left
with is the derivative of this whole sine of x
squared with respect to x. So you're left with, you're left with the derivative of essentially our original
function, sine of x squared with respect to x, with respect to x, which
is exactly what dh/dx is. This right over here, this right over here is
our original function h. That's our original function h. So it might seem a
little bit daunting now. What I'll do in the next video
is another several examples, and then we'll try to
abstract this a little bit.