# The Derivative Chain Rule
> In calculus, **the chain rule is a formula that expresses the derivative of the composition of two differentiable functions f and g in terms of the derivatives of f and g**.
> [Wikipedia](https://en.wikipedia.org/wiki/Chain%20rule)
$\frac d {dx}\bigg[f(g(x))\bigg] = f'(g(x)) \cdot g'(x)$ ^qnzl9i
![[The Derivative Chain Rule#^2p4rqb]]
First you evaluate the $f$ derivative at the 'stuff' (inside brackets, in this case $g(x)$), and then you multiply by the derivative of the 'stuff'.
## Reasoning 1
Let's look at $f(x) = \sin(2x)$. We can start by labeling the inside as $h(x) = 2x$.
$f$ then becomes $f(x) = \sin(h)$. And $df = \cos h \, dh$. However we're interested in the change of $f$ for a change of $x$, so we need to substitute $dh$ back into the last expression
$dh = 2dx$ so
$df = \cos (2x) 2 \, dx$
This reasoning comes from 3Blue1Brown: https://www.youtube.com/watch?v=YG15m2VwSjA&list=PLZHQObOWTQDMsr9K-rj53DwVRMYO3t5Yr
## Reasoning 2
When trying to reason about the chain look at $f(x) = \sin(x)$ and $h(x) = \sin(2x)$ as an example, and look at the derivative of the two functions close to the second hump:
<img src="https://d18l82el6cdm1i.cloudfront.net/uploads/Bc0r19TS7B-c3q4p2.svg" style="background: white; padding: 10px; width: 400px" />
The slope of $\sin(2x)$ evaluated at $a$ twice as big as the derivative of $\sin(x)$ evaluated at $b$. The factor 2 corresponds to the derivative of the inner function $g(x) = 2x$. This tells us that the derivatives multiply, when evaluated at corresponding points.
Here's another illustration of the same point:
<img src="https://d18l82el6cdm1i.cloudfront.net/uploads/N2Lq5cTRRl-c3q4p4.svg" style="background: white; padding: 10px; width: 400px" />
Lets look at the function $g$ and assume that $g'(a)=2$. If we increase $g$ input by $\Delta x$, $g$ output will increase by $2\Delta x$.
Also assume that $f'(b) = 3$. This means that if we increase $b$ by a small amount, $f$ output will increase by a factor of 3. So in total, if we increase the input of $f \circ g$ by a small amount, its output will increase by a factor of 6.
Now remember that $b = g(a)$, so we can say that the derivative of $f \circ g$ is $f'(b) \cdot g'(a) = f'(g(a)) \cdot g'(a)$.
> When doing $g$ and then $f$, the magnifying factors multiply, and hence the derivatives just multiply.
>
> But remember we have to multiply the derivatives at the corresponding points — that is, the derivative of $g$ at $a$ times the derivative of $f$ at $b$.[^1]
[^1]: Brilliant. Calculus Fundamentals. The Chain Rule.
## Reciprocal Derivatives
Reciprocal derivatives can be determined using the chain rule
$\frac d {dx}\left[ \frac 1 {f(x)} \right] = -\frac {f'(x)} {f(x)^2}$ ^1vw3jd
$
\begin{align}
\frac d {dx}\left[ \frac 1 {f(x)} \right] &= \frac d {dx}\left[ f(x)^{-1} \right] \\
&= -f(x)^{-2} \cdot f'(x) \\
&= - \frac {f'(x)}{f(x)^2}
\end{align}
$
By further extension we can also derive the derivative of $\frac 1 {x^n}$:
$
\frac d {dx} \left[ \frac 1 {x^n} \right] = -\frac {nx^{n-1}} {x^{2n}} = -\frac {nx^{n-1}} {x^{n-1 + n + 1}} = -\frac n {x^{n+1}}
$
$\frac d {dx} \left[ \frac 1 {x^n} \right] = -\frac n {x^{n+1}}$ ^h0ykgq
## Fraction Representation
When using Leibniz's derivative notation, the chain rule becomes easier to memorize, because deltas appear to cancel out:
$\frac {dx} {dy} \cdot \frac {dy}{dz} = \frac {dx}{dz}$
This comes into play when doing [[Implicit Differentiation]]. ^2p4rqb