# Chain Rule

The **chain rule** is used to differentiate composite functions. Specifically, it allows us to use differentiation rules on more complicated functions by differentiating the inner function and outer function separately.

#### Contents

## Definition

Intuitively, oftentimes a function will have another function "inside" it that is first related to the input variable. Since we know the derivative of a function is the rate of change, we need to compute the rate of change of this "inner" function as well as the total function in its entirety relative to the input variable. The chain rule allows us to accomplish this.

The chain rule states that given a composite function \(f\big(g(x)\big)\), its derivative is the derivative of the outer function (leaving the inner function unchanged and in place) multiplied by the derivative of the inner function. Concisely,

Chain Rule\[\frac{d}{dx} f\big(g(x)\big) \equiv f'\big(g(x)\big) \cdot g'(x)\]

The alternative statement of the chain in terms of function composition is

\[(f \circ g)' = (f' \circ g) \cdot g'.\]

Another way of stating this which makes it intuitive (almost trivial) would be

\[\frac{d f \circ g}{dx}=\frac{d f \circ g}{dg} \frac{d g}{dx}.\]

Let's see how it works by taking a look at some examples.

Evaluate \(\frac{d}{dx} ( 2x + 1) ^ 2 \).

Let \( g(x) = 2x + 1 \) and \( f(x) = x^2 \). Then, \((2x+1)^2 = f\big(g(x)\big)\). We know that \( g'(x) = 2 \) and \( f'(x) = 2x \). Hence,

\[\begin{align} \frac{ d}{dx} (2x+1)^2 &= f'\big(g(x)\big) \cdot g'(x) \\ &= f' (2x+1) \cdot 2 \\ &= 2(2x+1) \cdot 2 \\ &= 8x+4.\ _\square \end{align}\]

## Evaluate \( \frac{d}{dx} e^{ x^2} \).

Let \( g(x) = x^2 \) and \( f(x) = e^x \). Then, \( e^{x^2} = f \big(g (x)\big) \). We know that \( g'(x) = 2x \) and \( f'(x) = e^x \). Hence,

\[\begin{align} \frac{ d}{dx} e^{x^2} &= f'\big(g(x)\big) \cdot g'(x) \\ &= f' \big(x^2\big) \cdot 2x \\ &= e^{x^2} \cdot 2x \\ &= 2xe^{x^2}.\ _\square \end{align}\]

Find the derivative of \(\cos^5x\).

Let \(g(x)=\cos x\) and \(f(x)=x^5\). Then, \(\cos^5x=f\big(g(x)\big)\). We know that \(g'(x)=-\sin x\) and \(f'(x)=5x^4\). Hence,

\[\begin{align} \frac{d}{dx} f\big(g(x)\big) &= f'\big(g(x)\big) \cdot g'(x) \\ &= f'(\cos x) \cdot (-\sin x) \\ &= -5\cos^4x\sin x.\ _\square \end{align}\]

There is a certain function \(f\) such that the tangent line at \(x=\frac{1}{2}\) is \(y=2x+1.\)

Given that \(g(x)=f(\sin x),\) find the sum of all possible values of \(\frac{dg}{dx}\) when evaluated at \(x=\frac{\pi}{6}\).

## Proof

Then, how do we prove the chain rule? The proof goes as follows:

We begin by recalling the definition of differentiation:

\[\frac{d}{dx}f(x) = \lim_{\Delta x\rightarrow0}\frac{f(x+\Delta x)-f(x)}{\Delta x}.\]

We thus have

\[\begin{align} \frac{d}{dx} f\big(g(x)\big) &= \lim_{\Delta x \to 0} \dfrac{f\big(g(x+\Delta x)\big)-f\big(g(x)\big)}{\Delta x} \\ &= \lim_{\Delta x \to 0} \dfrac{f\big(g(x+\Delta x)\big)-f\big(g(x)\big)}{\Delta x} \cdot \dfrac{g(x+\Delta x)-g(x)}{g(x+\Delta x)-g(x)} \\ &= \lim_{\Delta x \to 0} \dfrac{f\big(g(x+\Delta x)\big)-f\big(g(x)\big)}{g(x+\Delta x)-g(x)} \cdot \lim_{\Delta x \to 0} \dfrac{g(x+\Delta x)-g(x)}{\Delta x} \\ &= \lim_{\Delta x \to 0} \dfrac{f\big(g(x+\Delta x)\big)-f\big(g(x)\big)}{g(x+\Delta x)-g(x)} \cdot g'(x). \end{align}\]

Making the substitution \(g(x+\Delta x)-g(x) = \Delta g\), we have \(\Delta g \to 0\) as \(\Delta x \to 0\), so

\[\begin{align} \frac{d}{dx} f\big(g(x)\big) &= \lim_{\Delta g \to 0} \dfrac{f\big(g(x)+\Delta g\big)-f\big(g(x)\big)}{\Delta g} \cdot g'(x) \\ &= f'\big(g(x)\big) \cdot g'(x).\ _\square \end{align}\]

## Iterated Chain Rule

At times, we may need to apply the chain rule repeatedly in order to find the derivative. For example, if \(f(x) = \sqrt{\tan (x^3)}\), the inner function is itself a composite function.

In situations like this, we must apply the chain rule more than once. Specifically, for three functions composed, we have

\[\frac{d}{dx} f\Big(g\big(h(x)\big)\Big) = f'\big(g(h(x)\big) \cdot g'\big(h(x)\big) \cdot h'(x).\]

This can easily be extended to any number of composed functions.

Find the derivative of \(\sqrt{\tan(x^3)}\).

We begin by identifying the given function's basic parts, which we know how to differentiate. We can call \(\sqrt{\tan(x^3)} = f\Big(g\big(h(x)\big)\Big)\), where \(f(x) = \sqrt{x}\), \(g(x) = \tan x,\) and \(h(x) = x^3\).

We then have \( f'(x) = \frac{1}{2\sqrt{x}} \), \( g'(x) = \sec^2 x, \) and \( h'(x) = 3x^2 \).

Applying the chain rule, we can see that \(\frac{d}{dx} \sqrt{\tan(x^3)} = f'\Big(g\big(h(x)\big)\Big) \cdot \frac{d}{dx} g\big(h(x)\big) \). However, in order to find the derivative of \(g\big(h(x)\big)\), we have to apply the chain rule again, which gives us the following:

\[\begin{align} \frac{d}{dx} \sqrt{\tan (x^3) } &= f'\Big(g\big(h(x)\big)\Big) \cdot \frac{d}{dx} g\big(h(x)\big) \\ &= f'\Big(g\big(h(x)\big)\Big) \cdot \Big[g'\big(h(x)\big) \cdot h'(x)\Big] \\ &= \frac{1}{2\sqrt{\tan \left(x^3\right)}} \cdot \sec^2\left(x^3\right) \cdot 3x^2 \\\\ &= \frac{3x^2 \sec^2\left(x^3\right)}{2\sqrt{\tan\left(x^3\right)}}.\ _\square \end{align}\]

For a harder challenge, try: