# The Chain Rule

So far we have seen how to compute the derivative of a function built up from other functions by addition, subtraction, multiplication and division. There is another very important way that we combine simple functions to make more complicated functions: function composition, as discussed in section __2.3__. For example, consider \( \sqrt{625-x^2}\). This function has many simpler components, like 625 and \( x^2\), and then there is that square root symbol, so the square root function \( \sqrt{x}=x^{1/2}\) is involved. The obvious question is: can we compute the derivative using the derivatives of the constituents \( 625-x^2\) and \( \sqrt{x}\)? We can indeed. In general, if \(f(x)\) and \(g(x)\) are functions, we can compute the derivatives of \(f(g(x))\) and \(g(f(x))\) in terms of \(f'(x)\) and \(g'(x)\).

Example 3.5.1

**SOLUTION**

First, \( f(g(x))=\sqrt{625-x^2}\), and the derivative is \( -x/\sqrt{625-x^2}\) as we have seen.

Second, \( g(f(x))=625-(\sqrt{x})^2=625-x\) with derivative \(-1\). Of course, these calculations do not use anything new, and in particular the derivative of \(f(g(x))\) was somewhat tedious to compute from the definition.

Suppose we want the derivative of \(f(g(x))\). Again, let's set up the derivative and play some algebraic tricks:

\[\eqalign{ {d\over dx}f(g(x))& =\lim_{\Delta x\to0} {f(g(x+\Delta x))-f(g(x))\over\Delta x}\cr& =\lim_{\Delta x\to0} {f(g(x+\Delta x))-f(g(x))\over g(x+\Delta x))-g(x)} {g(x+\Delta x))-g(x)\over\Delta x}\cr }\]

Now we see immediately that the second fraction turns into \(g'(x)\) when we take the limit. The first fraction is more complicated, but it too looks something like a derivative. The denominator, \(g(x+\Delta x))-g(x)\), is a change in the value of \(g\), so let's abbreviate it as \(\Delta g=g(x+\Delta x))-g(x)\), which also means \(g(x+\Delta x)=g(x)+\Delta g\). This gives us

\[\lim_{\Delta x\to0} {f(g(x)+\Delta g)-f(g(x))\over \Delta g}.\]

As \(\Delta x\) goes to 0, it is also true that \(\Delta g\) goes to 0, because \(g(x+\Delta x)\) goes to \(g(x)\). So we can rewrite this limit as

\[\lim_{\Delta g\to0} {f(g(x)+\Delta g)-f(g(x))\over \Delta g}.\]

Now this looks exactly like a derivative, namely \(f'(g(x))\), that is, the function \(f'(x)\) with \(x\) replaced by \(g(x)\). If this all withstands scrutiny, we then get

\[{d\over dx}f(g(x))=f'(g(x))g'(x).\]

Unfortunately, there is a small flaw in the argument. Recall that what we mean by \(\lim_{\Delta x\to0}\) involves what happens when \(\Delta x\) is close to 0, *but not equal to 0.* The qualification is very important, since we must be able to divide by \(\Delta x\). But when \(\Delta x\) is close to 0 but not equal to 0, \(\Delta g=g(x+\Delta x))-g(x)\) is close to 0 *and possibly equal to 0.* This means it doesn't really make sense to divide by \(\Delta g\).

Fortunately, it is possible to recast the argument to avoid this difficulty, but it is a bit tricky; we will not include the details, which can be found in many calculus books. Note that many functions \(g\) do have the property that \(g(x+\Delta x)-g(x)\not=0\) when \(\Delta x\) is small, and for these functions the argument above is fine.

The chain rule has a particularly simple expression if we use the Leibniz notation for the derivative. The quantity \(f'(g(x))\) is the derivative of \(f\) with \(x\) replaced by \(g\); this can be written \(df/dg\). As usual, \(g'(x)=dg/dx\). Then the chain rule becomes

\[{df\over dx} = {df\over dg}{dg\over dx}.\]

This looks like trivial arithmetic, but it is not: \(dg/dx\) is not a fraction, that is, not literal division, but a single symbol that means \(g'(x)\). Nevertheless, it turns out that what looks like trivial arithmetic, and is therefore easy to remember, is really true.

It will take a bit of practice to make the use of the chain rule come naturally---it is more complicated than the earlier differentiation rules we have seen.

Example 3.5.2

Compute the derivative of \( \sqrt{625-x^2}\).

**SOLUTION**

We already know that the answer is \( -x/ \sqrt{625-x^2}\), computed directly from the limit. In the context of the chain rule, we have \( f(x)=\sqrt{x}\), \(g(x)=625-x^2\).

We know that \( f'(x)=(1/2)x^{-1/2}\), so \( f'(g(x))= (1/2)(625-x^2)^{-1/2}\). Note that this is a two step computation: first compute \(f'(x)\), then replace \(x\) by \(g(x)\). Since \(g'(x)=-2x\) we have

\[f'(g(x))g'(x)={1\over 2\sqrt{625-x^2}}(-2x)={-x\over \sqrt{625-x^2}}. \]

Example 3.5.3

Compute the derivative of \( 1/\sqrt{625-x^2}\).

**SOLUTION**

This is a quotient with a constant numerator, so we could use the quotient rule, but it is simpler to use the chain rule. The function is \( (625-x^2)^{-1/2}\), the composition of \( f(x)=x^{-1/2}\) and \( g(x)=625-x^2\). We compute \( f'(x)=(-1/2)x^{-3/2}\) using the power rule, and then

\[f'(g(x))g'(x)={-1\over 2(625-x^2)^{3/2}}(-2x)={x\over (625-x^2)^{3/2}}. \]

Example 3.5.4

Compute the derivative of

\[f(x)={x^2-1\over x\sqrt{x^2+1}}.\]

**SOLUTION**

The "last'' operation here is division, so to get started we need to use the quotient rule first. This gives

\[ \eqalign{ f'(x)&={(x^2-1)'x\sqrt{x^2+1}-(x^2-1)(x\sqrt{x^2+1})'\over x^2(x^2+1)}\cr& ={2x^2\sqrt{x^2+1}-(x^2-1)(x\sqrt{x^2+1})'\over x^2(x^2+1)}.\cr }\]

Now we need to compute the derivative of \( x\sqrt{x^2+1}\). This is a product, so we use the product rule:

\[{d\over dx}x\sqrt{x^2+1}=x{d\over dx}\sqrt{x^2+1}+\sqrt{x^2+1}.\]

Finally, we use the chain rule:

\[{d\over dx}\sqrt{x^2+1}={d\over dx}(x^2+1)^{1/2}= {1\over 2}(x^2+1)^{-1/2}(2x)={x\over \sqrt{x^2+1}}.\]

And putting it all together:

\[ \eqalign{ f'(x)&={2x^2\sqrt{x^2+1}-(x^2-1)(x\sqrt{x^2+1})'\over x^2(x^2+1)}.\cr& ={2x^2\sqrt{x^2+1}-(x^2-1)\left(x{ {x\over \sqrt{x^2+1}}} +\sqrt{x^2+1}\right)\over x^2(x^2+1)}.\cr }\]

This can be simplified of course, but we have done all the calculus, so that only algebra is left.

In practice, of course, you will need to use more than one of the rules we have developed to compute the derivative of a complicated function.

Example 2.5.5

Compute the derivative of \( \sqrt{1+\sqrt{1+\sqrt{x}}}\).

**SOLUTION**

Here we have a more complicated chain of compositions, so we use the chain rule twice. At the outermost "layer'' we have the function \( g(x)=1+\sqrt{1+\sqrt{x}}\) plugged into \( f(x)=\sqrt{x}\), so applying the chain rule once gives

\[{d\over dx}\sqrt{1+\sqrt{1+\sqrt{x}}}= {1\over 2}\left(1+\sqrt{1+\sqrt{x}}\right)^{-1/2}{d\over dx} \left(1+\sqrt{1+\sqrt{x}}\right).\]

Now we need the derivative of \( \sqrt{1+\sqrt{x}}\). Using the chain rule again:

\[{d\over dx}\sqrt{1+\sqrt{x}}={1\over 2}\left(1+\sqrt{x}\right)^{-1/2}{1\over 2}x^{-1/2}.\]

So the original derivative is

\[ \eqalign{ {d\over dx}\sqrt{1+\sqrt{1+\sqrt{x}}}&= {1\over 2}\left(1+\sqrt{1+\sqrt{x}}\right)^{-1/2} {1\over 2}\left(1+\sqrt{x}\right)^{-1/2}{1\over 2}x^{-1/2}.\cr& ={1\over 8 \sqrt{x}\sqrt{1+\sqrt{x}}\sqrt{1+\sqrt{1+\sqrt{x}}}} }\]

Using the chain rule, the power rule, and the product rule, it is possible to avoid using the quotient rule entirely.

Example 3.5.6

Compute the derivative of \( f(x)={x^3\over x^2+1}\).

**SOLUTION**

Write \( f(x)=x^3(x^2+1)^{-1}\), then

\[ \eqalign{ f'(x)&=x^3{d\over dx}(x^2+1)^{-1}+3x^2(x^2+1)^{-1}\cr& =x^3(-1)(x^2+1)^{-2}(2x)+3x^2(x^2+1)^{-1}\cr& =-2x^4(x^2+1)^{-2}+3x^2(x^2+1)^{-1}\cr& ={-2x^4\over (x^2+1)^{2}}+{3x^2\over x^2+1}\cr& ={-2x^4\over (x^2+1)^{2}}+{3x^2(x^2+1)\over (x^2+1)^{2}}\cr& ={-2x^4+3x^4+3x^2\over (x^2+1)^{2}}={x^4+3x^2\over (x^2+1)^{2}}\cr }\]

Note that we already had the derivative on the second line; all the rest is simplification. It is easier to get to this answer by using the quotient rule, so there's a trade off: more work for fewer memorized formulas.

### Exercises 3.5

Find the derivatives of the functions. For extra practice, and to check your answers, do some of these in more than one way if possible.

**Ex 3.5.1** \( x^4-3x^3+(1/2)x^2+7x-\pi\) (answer)

**Ex 3.5.2** \( x^3-2x^2+4\sqrt{x}\) (answer)

**Ex 3.5.3** \( (x^2+1)^3\) (answer)

**Ex 3.5.4** \( x\sqrt{169-x^2}\) (answer)

**Ex 3.5.5** \( (x^2-4x+5)\sqrt{25-x^2}\) (answer)

**Ex 3.5.6** \( \sqrt{r^2-x^2}\), \(r\) is a constant (answer)

**Ex 3.5.7** \( \sqrt{1+x^4}\) (answer)

**Ex 3.5.8** \( {1\over\sqrt{5-\sqrt{x}}}\). (answer)

**Ex 3.5.9** \( (1+3x)^2\) (answer)

**Ex 3.5.10** \( {(x^2+x+1)\over(1-x)}\) (answer)

**Ex 3.5.11** \( {\sqrt{25-x^2}\over x}\) (answer)

**Ex 3.5.12** \( \sqrt{{169\over x}-x}\) (answer)

**Ex 3.5.13** \( \sqrt{x^3-x^2-(1/x)}\) (answer)

**Ex 3.5.14** \( 100/(100-x^2)^{3/2}\) (answer)

**Ex 3.5.15** \( {\root 3 \of{x+x^3}}\) (answer)

**Ex 3.5.16** \( \sqrt{(x^2+1)^2+\sqrt{1+(x^2+1)^2}}\) (answer)

**Ex 3.5.17** \( (x+8)^5\) (answer)

**Ex 3.5.18** \( (4-x)^3\) (answer)

**Ex 3.5.19** \( (x^2+5)^3\) (answer)

**Ex 3.5.20** \( (6-2x^2)^3\) (answer)

**Ex 3.5.21** \( (1-4x^3)^{-2}\) (answer)

**Ex 3.5.22** \( 5(x+1-1/x)\) (answer)

**Ex 3.5.23** \( 4(2x^2-x+3)^{-2}\) (answer)

**Ex 3.5.24** \( {1\over 1+1/x}\) (answer)

**Ex 3.5.25** \( {-3\over 4x^2-2x+1}\) (answer)

**Ex 3.5.26** \( (x^2+1)(5-2x)/2\) (answer)

**Ex 3.5.27** \( (3x^2+1)(2x-4)^3\) (answer)

**Ex 3.5.28** \( {x+1\over x-1}\) (answer)

**Ex 3.5.29** \( {x^2-1\over x^2+1}\) (answer)

**Ex 3.5.30** \( {(x-1)(x-2)\over x-3}\) (answer)

**Ex 3.5.31** \( {2x^{-1}-x^{-2}\over 3x^{-1}-4x^{-2}}\) (answer)

**Ex 3.5.32** \( 3(x^2+1)(2x^2-1)(2x+3)\) (answer)

**Ex 3.5.33** \( {1\over (2x+1)(x-3)}\) (answer)

**Ex 3.5.34** \( ((2x+1)^{-1}+3)^{-1}\) (answer)

**Ex 3.5.35** \( (2x+1)^3(x^2+1)^2\) (answer)

**Ex 3.5.36** Find an equation for the tangent line to \( f(x) = (x-2)^{1/3}/(x^3 + 4x - 1)^2\) at \(x=1\). (answer)

**Ex 3.5.37** Find an equation for the tangent line to \( y=9x^{-2}\) at \((3,1)\). (answer)

**Ex 3.5.38** Find an equation for the tangent line to \( (x^2-4x+5)\sqrt{25-x^2}\) at \((3,8)\). (answer)

**Ex 3.5.39** Find an equation for the tangent line to \( {(x^2+x+1)\over(1-x)}\) at \((2,-7)\). (answer)

**Ex 3.5.40** Find an equation for the tangent line to \( \sqrt{(x^2+1)^2+\sqrt{1+(x^2+1)^2}}\) at \( (1,\sqrt{4+\sqrt{5}})\). (answer)