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 $\ds \sqrt{625-x^2}$. This function has many simpler components, like 625 and $\ds x^2$, and then there is that square root symbol, so the square root function $\ds \sqrt{x}=x^{1/2}$ is involved. The obvious question is: can we compute the derivative using the derivatives of the constituents $\ds 625-x^2$ and $\ds \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 Form the two possible compositions of $\ds f(x)=\sqrt{x}$ and $\ds g(x)=625-x^2$ and compute the derivatives. First, $\ds f(g(x))=\sqrt{625-x^2}$, and the derivative is $\ds -x/\sqrt{625-x^2}$ as we have seen. Second, $\ds 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. $\square$

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 $\ds \sqrt{625-x^2}$. We already know that the answer is $\ds -x/\sqrt{625-x^2}$, computed directly from the limit. In the context of the chain rule, we have $\ds f(x)=\sqrt{x}$, $\ds g(x)=625-x^2$. We know that $\ds f'(x)=(1/2)x^{-1/2}$, so $\ds 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}}. $$

$\square$

Example 3.5.3 Compute the derivative of $\ds 1/\sqrt{625-x^2}$. 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 $\ds (625-x^2)^{-1/2}$, the composition of $\ds f(x)=x^{-1/2}$ and $\ds g(x)=625-x^2$. We compute $\ds 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}}. $$

$\square$

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 3.5.4 Compute the derivative of $$f(x)={x^2-1\over x\sqrt{x^2+1}}.$$ 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 $\ds 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{\ds{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. $\square$

Example 3.5.5 Compute the derivative of $\ds \sqrt{1+\sqrt{1+\sqrt{x}}}$. Here we have a more complicated chain of compositions, so we use the chain rule twice. At the outermost "layer'' we have the function $\ds g(x)=1+\sqrt{1+\sqrt{x}}$ plugged into $\ds 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 $\ds \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}}}} }$$

$\square$

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 $\ds f(x)={x^3\over x^2+1}$. Write $\ds 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. $\square$

## 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**
$\ds x^4-3x^3+(1/2)x^2+7x-\pi$
(answer)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

**Ex 3.5.36**
Find an equation for the tangent line to
$\ds 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 $\ds y=9x^{-2}$ at $(3,1)$.
(answer)

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

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

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