# Chain rule

992pages on
this wiki

The chain rule is a formula for finding the derivative of a composite function. It uses a variable y depending on a second variable, u, which in turn depend on a third variable, x.

${dy\over dx} = {dy\over du} {du\over dx}$

The derivative of any function is the derivative of the function itself, as per the power rule, then the derivative of the inside of the function.

${d\over dx} f(g(x)) = f'(g(x)) \cdot g'(x)$

and so on, for as many interwoven functions as there are.

For a multivariable function of n variables, the chain rule becomes the dot product of the gradient and the derivative of a vector function.

${\partial \over \partial t} f(\mathbf{r} (t) ) = {df \over dx_1} {dx_1 \over dt} \cdots {df \over dx_n} {dx_n \over dt} = \nabla f \cdot \mathbf{r} ' (t)$

## Examples

For the function $f(g(x)) = (3x + 1)^2$, $f(x) = x^2$ and $g(x) = 3x + 1$, so $f'(x) = 2x$ and $g(x) = 3$. Therefore, the derivative of the function is

$f(g(x))' = 2(3x + 1)(3) = 18x + 6$

$f(g(x)) = \sin(x^2+2)$, $f(x) = \sin(x)$, $g(x) = x^2 + 2$, $f(x)' = \cos(x)$, $g(x)' = 2x$

$f(g(x))' = \cos(x^2+2) \cdot 2x = 2x \cdot \cos(x^2+2)$

This can get rather crowded with more than 3 functions:

${d\over x} \sec^3({x^3-12\over 2x})$

which has an inlaid Quotient rule, which results from taking the derivative of the inner piece.

Make sure that you take note of how many functions there are so that you know how many pieces you should have. Also, remember that the inside of the internal functions remain the same.

## Proof

Let $g : D \to \R$ be differentiable at $x$, and let $f : g\left({D}\right) \to \R$ be differentiable at $g(x)$.

Define a function $\phi : g\left({D}\right) \to \R$ such that $\phi \left({z}\right) = \begin{cases} \frac {f \left({z}\right) - f \left({g \left({x}\right)}\right)} {z - g \left({x}\right)} & : z \ne g \left({x}\right) \\ f^\prime \left({z}\right) & : z = g \left({x}\right) \end{cases}.$

Note that $\lim_{z \to g \left({x}\right)} \phi \left({z}\right) = f^\prime \left({g \left({x}\right)}\right)$, ie $\phi$ is continuous at $g \left({x}\right)$, and as $g$ is differentiable at $x$ it is also continuous there, so by continuity of composition $\phi \circ g$ is continuous at $x$.

Now $\forall y \ne x$, $\frac {f \left({g \left({y}\right)}\right) - f \left({g \left({x}\right)}\right)} {y - x} = \begin{cases} \frac {f \left({g \left({y}\right)}\right) - f \left({g \left({x}\right)}\right)} {g \left({y}\right) - g \left({x}\right)} \frac {g \left({y}\right) - g \left({x}\right)} {y - x} & : g \left({y}\right) \ne g \left({x}\right) \\ 0 & : g \left({y}\right) = g \left({x}\right) \end{cases},$
which is equal to $\phi \left({g \left({y}\right)}\right) \frac {g \left({y}\right) - g \left({x}\right)} {y - x}.$

So $\lim_{y \to x} \frac {f \left({g \left({y}\right)}\right) - f \left({g \left({x}\right)}\right)} {y - x} = \lim_{y \to x} \phi \left({g \left({y}\right)}\right) \frac {g \left({y}\right) - g \left({x}\right)} {y - x} = \phi \left({g \left({x}\right)}\right) g^\prime \left({x}\right) = f^\prime \left({g \left({x}\right)}\right) g^\prime \left({x}\right),$ with the second equality relying on the Algebra of Limits and continuity of $\phi \circ g$ at $x$.

Therefore $f \circ g$ is differentiable at $x$ with derivative $f^\prime \left({g \left({x}\right)}\right) g^\prime \left({x}\right)$.