# Chain rule overview

A quick overview sheet of the chain rule.

## Introduction

If f, left parenthesis, x, right parenthesis and g, left parenthesis, x, right parenthesis are two functions, for instance f, left parenthesis, x, right parenthesis, equals, x, start superscript, 2, end superscript and g, left parenthesis, x, right parenthesis, equals, sine, left parenthesis, x, right parenthesis, we know how to take the derivative of their sum:
Rule:start fraction, d, divided by, d, x, end fraction, left parenthesis, f, left parenthesis, x, right parenthesis, plus, g, left parenthesis, x, right parenthesis, right parenthesis, equals, f, prime, left parenthesis, x, right parenthesis, plus, g, prime, left parenthesis, x, right parenthesis
Example:start fraction, d, divided by, d, x, end fraction, left parenthesis, x, start superscript, 2, end superscript, plus, sine, left parenthesis, x, right parenthesis, right parenthesis, equals, 2, x, plus, cosine, left parenthesis, x, right parenthesis
We also know how to take the derivative of their product:
Rule:start fraction, d, divided by, d, x, end fraction, left parenthesis, f, left parenthesis, x, right parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis, equals, f, left parenthesis, x, right parenthesis, g, prime, left parenthesis, x, right parenthesis, plus, g, left parenthesis, x, right parenthesis, f, prime, left parenthesis, x, right parenthesis
Example:start fraction, d, divided by, d, x, end fraction, left parenthesis, x, start superscript, 2, end superscript, dot, sine, left parenthesis, x, right parenthesis, right parenthesis, equals, x, start superscript, 2, end superscript, cosine, left parenthesis, x, right parenthesis, plus, sine, left parenthesis, x, right parenthesis, dot, 2, x
The chain rule now tells us how to take the derivative of their composition, meaning f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis:
Rule:start color blueE, start fraction, d, divided by, d, x, end fraction, left parenthesis, f, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis, equals, f, prime, left parenthesis, g, left parenthesis, x, right parenthesis, right parenthesis, g, prime, left parenthesis, x, right parenthesis, end color blueE
Example:start color blueE, start fraction, d, divided by, d, x, end fraction, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, start superscript, 2, end superscript, equals, 2, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, cosine, left parenthesis, x, right parenthesis, end color blueE

## Intuition using fake algebra

Warning: The following section may induce headache or queasiness for readers who are sensitive to violent abuse of notation.
We tend to write functions and derivatives in terms of the variable x.
start fraction, d, divided by, d, x, end fraction, left parenthesis, x, start superscript, 2, end superscript, right parenthesis, equals, 2, x
But of course, we could use any other letter.
start fraction, d, divided by, d, start color blueD, a, end color blueD, end fraction, left parenthesis, start color blueD, a, end color blueD, start superscript, 2, end superscript, right parenthesis, equals, 2, start color blueD, a, end color blueD
What if we did something crazy, and replaced x with a function instead of another letter.
start fraction, d, divided by, d, left parenthesis, start color blueD, sine, left parenthesis, x, right parenthesis, end color blueD, right parenthesis, end fraction, left parenthesis, start color blueD, sine, left parenthesis, x, right parenthesis, end color blueD, right parenthesis, start superscript, 2, end superscript, equals, 2, start color blueD, sine, left parenthesis, x, right parenthesis, end color blueD
It's unclear exactly what this start fraction, d, divided by, d, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, end fraction symbol would mean, but let's just go with it for a second. We can imagine multiplying it by start fraction, d, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, divided by, d, x, end fraction to "cancel out" the d, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis term:
This is not really a mathematically legitimate thing to do, since these "d, x" and "d, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis" terms are not numbers or functions that we can cancel out. There are ways to make this more legitimate that involve some more advanced math, but for now you can think of it as a useful memory trick. The usefulness is that when we expand start fraction, d, divided by, d, x, end fraction, left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, start superscript, 2, end superscript like this, we know what each individual term is, even if we don't know how to take the derivative of left parenthesis, sine, left parenthesis, x, right parenthesis, right parenthesis, start superscript, 2, end superscript:
This trick looks particularly clean when we write it in the abstract, rather than with the specific case of x, start superscript, 2, end superscript and sine, left parenthesis, x, right parenthesis:

## Example 3:

One pretty cool thing we can now do is find the derivative of the absolute value function vertical bar, x, vertical bar, which can be defined as square root of, x, start superscript, 2, end superscript, end square root. For example, vertical bar, minus, 5, vertical bar, equals, square root of, left parenthesis, minus, 5, right parenthesis, start superscript, 2, end superscript, end square root, equals, square root of, 25, end square root, equals, 5

## Arbitrarily long composition

The chain rule can apply to composing multiple functions, not just two. For example, suppose A, left parenthesis, x, right parenthesis, B, left parenthesis, x, right parenthesis, C, left parenthesis, x, right parenthesis and D, left parenthesis, x, right parenthesis are four different functions, and define f to be their composition:
f, left parenthesis, x, right parenthesis, equals, A, left parenthesis, B, left parenthesis, C, left parenthesis, D, left parenthesis, x, right parenthesis, right parenthesis, right parenthesis, right parenthesis
Using the start fraction, d, f, divided by, d, x, end fraction notation for the derivative, we can apply the chain rule as:
start fraction, d, f, divided by, d, x, end fraction, equals, start fraction, d, divided by, d, x, end fraction, A, left parenthesis, B, left parenthesis, C, left parenthesis, D, left parenthesis, x, right parenthesis, right parenthesis, right parenthesis, equals, start fraction, d, A, divided by, d, B, end fraction, dot, start fraction, d, B, divided by, d, C, end fraction, dot, start fraction, d, C, divided by, d, D, end fraction, dot, start fraction, d, D, divided by, d, x, end fraction
Using f, prime notation, we get more of a snowman aesthetic:
f, prime, left parenthesis, x, right parenthesis, equals, A, prime, left parenthesis, B, left parenthesis, C, left parenthesis, D, left parenthesis, x, right parenthesis, right parenthesis, right parenthesis, right parenthesis, dot, B, prime, left parenthesis, C, left parenthesis, D, left parenthesis, x, right parenthesis, right parenthesis, right parenthesis, dot, C, prime, left parenthesis, D, left parenthesis, x, right parenthesis, right parenthesis, dot, D, prime, left parenthesis, x, right parenthesis

## Example 4:

Suppose f, left parenthesis, x, right parenthesis, equals, sine, left parenthesis, e, start superscript, x, start superscript, 2, end superscript, plus, x, end superscript, right parenthesis.
We think of f as being the composition of
\begin{aligned} A(x) &= \blueE{\sin(x)}\\ B(x) &= \greenE{e^x} \\ C(x) &= \redE{x^2 + x} \end{aligned}
Where the derivative of each function is
\begin{aligned} A'(x) &= \blueE{\cos(x)}\\ B'(x) &= \greenE{e^x} \\ C'(x) &= \redE{2x + 1} \end{aligned}
According to the chain rule, the derivative of the composition is