The Chain Rule
The chain rule allows us to take the derivative of compound
functions like $\sin\left(x^2\right)$ or $\bigl(\sin(x)\bigr)^2$. If $f(x)=\sin(x)$ and
$g(x)=x^2$, then $\sin\left(x^2\right)=f\left(g(x)\right)$ and $\left(\sin(x)\right)^2 =
g\left(f(x)\right)$.
Version 1 of the chain rule says:
$$ \frac{d}{dx} \Bigl(f\bigl(g(x)\bigr)\Bigr) = f'\left(g(x)\right) \cdot g'(x)$$

So the derivative of $\sin\left(x^2\right)$ is $\cos\left(x^2\right)\cdot 2x$, or $2x
\cos\left(x^2\right)$, while the derivative of $\sin^2(x)$ is $2 \sin(x) \cdot
\cos(x)$.
It's often useful to let $u=g(x)$, so our rule becomes
$$\frac{d}{dx}\left(f(u)\right) = f'(u) \frac{du}{dx}$$

Combining this with our derivatives
of basic functions, we get:
$$
\frac{d}{dx}\bigl( u^n\bigr)=nu^{n1}\frac{du}{dx}
$$
$$
\frac{d}{dx}\bigl( e^u\bigr)=e^u\frac{du}{dx}
$$
$$
\frac{d}{dx}\bigl( \ln(u)\bigr)=\frac{1}{u}\frac{du}{dx}
$$
$$
\frac{d}{dx}\bigl( \sin(u)\bigr)=\cos(u)\frac{du}{dx}
$$
$$
\frac{d}{dx}\bigl( \cos(u)\bigr)=\sin(u)\frac{du}{dx}
$$

In particular, when taking the derivative of $\sin\left(x^2\right)$, just let
$u=x^2$, so we get the derivative of $\sin(u)$ being $\cos(u)\cdot 2x
= 2x\cos\left(x^2\right)$. When taking the derivative of $\sin^2(x)$, take
$u=\sin(x)$, so the derivative of $u^2$ is $\displaystyle 2 u \frac{du}{dx} = 2
\sin(x)\cos(x)$.
Version 2 of the chain rule comes from taking $y=f(u)$, where
$u=g(x)$, so we have $$\frac{dy}{dx} = \frac{dy}{du} \frac{du}{dx}.$$
Recall that $\displaystyle\frac{dy}{du}$ is another name for $f'(u)=f'\left(g(x)\right)$, while $\displaystyle\frac{du}{dx}$ is another
name for $g'(x)$.
