With one additional rule, we will have the power to take the derivative of any function we can write down. What is this amazing rule? Why, it’s called the chain rule. The chain rule is [latex]\frac{d}{dx} f(g(x)) = f'(g(x)) \cdot g'(x)[/latex]. If we drop the [latex](x)[/latex] on each function (note that it is still there, it is just implied), we have a slightly shorter version:
[latex]\boxed{\cfrac{d}{dx} f(g) = f'(g) \cdot g'}[/latex]
Here, [latex]f(g)[/latex] is called function composition. It does not mean [latex]f[/latex] times [latex]g[/latex]. It means we are sticking [latex]g[/latex] inside of [latex]f[/latex]! Like [latex]f[/latex] is eating [latex]g[/latex]! That’s actually cannibalism if you think about it — so don’t think about it too closely. But do remember how to do function composition.
Why does this work? I’m not going to do a formal proof, but let’s run through an idea behind it. Recall that the derivative is the slope or how steep the graph of a function is. This is a lot easier to think about if we’re talking about lines. For example, suppose [latex]{\color{red}f = 6x - 10}[/latex], and [latex]{\color{blue}g = \frac{1}{2}x + 3}[/latex]. As we know from algebra, the slope of the [latex]{\color{red}f}[/latex] line is [latex]{\color{red}6}[/latex], and the slope of the [latex]{\color{blue}g}[/latex] line is [latex]{\color{blue} \frac{1}{2}}[/latex].
So what is the slope of [latex]{\color{red}f}({\color{blue}g})[/latex]? What this means is we are putting [latex]{\color{blue}g}[/latex] inside of [latex]{\color{red}f}[/latex]. So if [latex]{\color{red}f = 6x - 10}[/latex], and [latex]{\color{blue}g = \frac{1}{2}x + 3}[/latex], we take the blue [latex]{\color{blue}\frac{1}{2}x + 3}[/latex] and use that to replace the red [latex]{\color{red}x}[/latex]. Here is what is would look like:
\begin{align*}
{\color{red}f}({\color{blue}g}) & = {\color{red}6{\color{blue}\left(\frac{1}{2}x + 3\right)}-10} \\
& = 6\left(\frac{1}{2}x + 3\right)-10 \\
& = 3x + 18 – 10 \\
& = 3x – 8
\end{align*}
So again, what is the slope of [latex]{\color{red}f}({\color{blue}g})[/latex]? We can see from this calculation that it is [latex]3[/latex], the product of the two slopes [latex]{\color{red}6}[/latex] and [latex]{\color{blue} \frac{1}{2}}[/latex]. That’s why you have [latex]f' \cdot g'[/latex] in the formula.
Okay, but what about the [latex](g)[/latex] after the [latex]f'[/latex] in the formula? One way to think about the function composition [latex]f(g)[/latex] is we are looking at the [latex]f[/latex] curve at the [latex]x[/latex]-location of [latex]g[/latex]. When you take the derivative, you’re still looking at that same location (now on the [latex]f'[/latex] curve), so you still need that [latex](g)[/latex] there to specify that location.
We must identify an “inside” (g) and “outside” (f) function in order to use the chain rule. Often, the “inside” function will be in parentheses (though not always). That works in this case, so the “inside” function is [latex]x^2 + x[/latex], so [latex]g = x^2 + x[/latex]. The outside function is [latex]\ln[/latex], and hence [latex]f =\ln(x)[/latex]. We also know [latex]f' = \frac{1}{x}[/latex] and [latex]g' = 2x + 1[/latex]. Now to use the chain rule, we first need [latex]f'(g)[/latex]. What is this? Well, remember that this is not multiplication, but it is sticking one function inside another. In this case, we are taking [latex]g = x^2 + x[/latex] and sticking it into the function [latex]f' = \frac{1}{x}[/latex]. This means we replace the [latex]x[/latex] in [latex]\frac{1}{x}[/latex], replacing it with [latex]x^2 + x[/latex], and get [latex]f'(g) = \frac{1}{x^2 + x}[/latex]. Hence we have
\begin{align*}
\frac{d}{dx} \ln(x^2 + x) & = f'(g) \cdot g’ \\
& = \frac{1}{(x^2 + x)} \cdot (2x + 1) \\
& = \boxed{\frac{2x + 1}{x^2 + x}}.
\end{align*}
There you have it!
Using the power rule, we first multiply [latex](3x + 1)^2 = (3x + 1)(3x + 1) = 9x^2 + 3x + 3x + 1 = 9x^2 + 6x + 1[/latex]. In this form, it is easy to find the derivative: [latex]\frac{d}{dx} 9x^2 + 6x + 1 = 18x + 6[/latex].
Using the chain rule, we identify the inside [latex]g[/latex] function as [latex]3x + 1[/latex], and the outside function as [latex]x^2[/latex]. We then have
\begin{align*}
\frac{d}{dx} (3x + 1)^2 & = f'(g) \cdot g’ \\
& = 2(3x + 1)(3) \\
& = 6(3x + 1) \\
& = \boxed{18x + 6}.
\end{align*}
Again, math just works!
Things can get quite complicated with the chain rule.
There are no explicit parentheses here, but the square root acts like parentheses, and it designates an inside function of [latex]g = x^2 + 2e^x[/latex]. The outside function is therefore [latex]f = \sqrt[4]{x}[/latex]. If we rewrite [latex]\sqrt[4]{x}[/latex] as [latex]x^{1/4}[/latex], we can use the power rule and find [latex]f' = \frac{1}{4} x^{-3/4}[/latex]. We also have [latex]g' = 2x + 2e^x[/latex]. Hence, the chain rule gives
\begin{align*}
\frac{d}{dx} \sqrt[4]{ x^2 + 2e^x} & = f'(g) \cdot g’ \\
& = \frac{1}{4} (x^2 + 2e^x)^{-3/4} (2x + 2e^x) \\
& = \frac{2x + 2e^x}{4} \frac{1}{\sqrt[4]{x^2 + 2e^x}^3} \\
& = \boxed{\frac{x + e^x}{2 \sqrt[4]{x^2 + 2e^x}^3 }}.
\end{align*}
That’s as simplified as we can get the answer to be.
One more quick example.
Recall that [latex]e^{\ln(a)} = a[/latex]. To prove this rule, we rewrite [latex]a^x = (e^{\ln(a)})^x = e^{x \ln(a)}[/latex]. We are then computing
[latex]\frac{d}{dx} \ a^x = \frac{d}{dx} \ e^{x \ln(a)}[/latex]
To compute this derivative, we set [latex]f = e^x[/latex] and [latex]g = x \ln(a)[/latex]. We find [latex]f' = e^x[/latex] and [latex]g' = \ln(a)[/latex], so by the chain rule
\begin{align*}
\frac{d}{dx} \ a^x & = \frac{d}{dx} \ e^{x \ln(a)} \\
& = f'(g) \cdot g’ \\
& = e^{x \ln(a)} \cdot \ln(a) \\
\end{align*}
We’ve already shown that [latex]a^x = e^{x \ln(a)}[/latex], so this simplifies to [latex]a^x \cdot \ln(a)[/latex], as desired.