Skip to main content
\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)
Mathematics LibreTexts

3.4: The Chain Rule

We have covered almost all of the derivative rules that deal with combinations of two (or more) functions.  The operations of addition, subtraction, multiplication (including by a constant) and division led to the Sum and Difference rules, the Constant Multiple Rule, the Power Rule, the Product Rule and the Quotient Rule. To complete the list of differentiation rules, we look at the last way two (or more) functions can be combined: the process of composition (i.e. one function "inside''  another).

One example of a composition of functions is \(f(x) = \cos(x^2)\). We currently do not know how to compute this derivative. If forced to guess, one would likely guess \(f^\prime(x) = -\sin(2x)\),where we recognize \(-\sin x\) as the derivative of \(\cos x\) and \(2x\) as the derivative of \(x^2\). However, this is not the case; \(f^\prime(x)\neq -\sin(2x)\). In Example 62 we'll see the correct answer, which employs the new rule this section introduces, the Chain Rule

Before we define this new rule, recall the notation for composition of functions. We write \((f \circ g)(x)\) or \(f(g(x))\),read as "\(f\) of \(g\) of \(x\),'' to denote composing \(f\) with \(g\). In shorthand, we simply write \(f \circ g\) or \(f(g)\) and read it as "\(f\) of \(g\).''  Before giving the corresponding differentiation rule, we note that the rule extends to multiple compositions like \(f(g(h(x)))\) or \(f(g(h(j(x))))\),etc.

To motivate the rule, let's look at three derivatives we can already compute.

 

Example 59: Exploring similar derivatives

Find the derivatives of \(F_1(x) = (1-x)^2\),\(F_2(x) = (1-x)^3,\) and \(F_3(x) = (1-x)^4.\) (We'll see later why we are using subscripts for different functions and an uppercase \(F\).)

Solution:

In order to use the rules we already have, we must first expand each function as \(F_1(x) = 1 - 2x + x^2\), \(F_2(x) = 1 - 3x + 3x^2 - x^3\) and \(F_3(x) = 1 - 4x + 6x^2 - 4x^3 + x^4\).

It is not hard to see that:

\(F_1^\prime(x) = -2 + 2x\)

\(F_2^\prime(x) = -3 + 6x - 3x^2\) and

\(F_3^\prime (x) = -4 + 12x - 12x^2 + 4x^3.\)

An interesting fact is that these can be rewritten as

\[F_1^\prime (x) = -2(1-x),\quad  F_2^\prime(x) = -3(1-x)^2 \text{ and }F_3^\prime (x) = -4(1-x)^3.\] 

A pattern might jump out at you.  Recognize that each of these functions is a composition, letting \(g(x) = 1-x\):

\[\begin{eqnarray*}F_1(x) = f_1(g(x)),& \text{ where } f_1(x) = x^2,\\ F_2(x) = f_2(g(x)),& \text{ where } f_2(x) = x^3,\\ F_3(x) = f_3(g(x)),& \text{ where } f_3(x) = x^4. \end{eqnarray*}\]

We'll come back to this example after giving the formal statements of the Chain Rule; for now, we are just illustrating a pattern.

 

Theorem 18: The Chain Rule

Let \(y = f(u)\) be a differentiable function of \(u\) and let \(u = g(x)\) be a differentiable function of \(x\). Then \(y=f(g(x))\) is a differentiable function of \(x\),and \[y^\prime = f^\prime(g(x))\cdot g^\prime(x).\]

To help  understand the Chain Rule, we return to Example 59.

Example 60: Using the Chain Rule

Use the Chain Rule to find the derivatives of the following functions, as given in Example 59.

Solution:

Example 59 ended with the recognition that each of the given functions was actually a composition of functions. To avoid confusion, we ignore most of the subscripts here. 

\(F_1(x) = (1-x)^2\):

We found that \[y=(1-x)^2 = f(g(x)), \text{ where } f(x) = x^2\ \text{ and }\ g(x) = 1-x.\]

To find \(y^\prime\), we apply the Chain Rule. We need \(f^\prime(x)=2x\) and \(g^\prime(x)=-1.\)

Part of the Chain Rule uses \(f^\prime(g(x))\). This means substitute \(g(x)\) for \(x\) in the equation for \(f^\prime(x)\). That is, \(f^\prime(x) = 2(1-x)\). Finishing out the Chain Rule we have \[y^\prime = f^\prime(g(x))\cdot g^\prime(x) = 2(1-x)\cdot (-1) = -2(1-x)= 2x-2.\]

\(F_2(x) = (1-x)^3\):

Let \(y = (1-x)^3 = f(g(x))\),where \(f(x) = x^3\) and \(g(x) = (1-x)\). We have \(f^\prime(x) = 3x^2\),so \(f^\prime(g(x)) = 3(1-x)^2\). The Chain Rule then states \[y^\prime = f^\prime(g(x))\cdot g^\prime (x) = 3(1-x)^2\cdot(-1) = -3(1-x)^2.\]

\(F_3(x) = (1-x)^4\):

Finally, when \(y = (1-x)^4\),we have \(f(x)= x^4\) and \(g(x) = (1-x)\). Thus \(f^\prime(x) = 4x^3\) and \(f^\prime(g(x)) = 4(1-x)^3\). Thus \[y^\prime = f^\prime(g(x))\cdot g^\prime(x) = 4(1-x)^3\cdot (-1) = -4(1-x)^3.\]

Example 60 demonstrated a particular pattern: when \(f(x)=x^n\),then \(y^\prime =n\cdot (g(x))^{n-1}\cdot g^\prime (x)\). This  is called the Generalized Power Rule.

Theorem 19: Generalized Power Rule

Let \(g(x)\) be a differentiable function and let \(n\neq 0\) be an integer. Then \[\frac{d}{dx}\Big(g(x)^n\Big) = n\cdot \big(g(x)\big)^{n-1}\cdot g^\prime (x).\]

This allows us to quickly find the derivative of functions like \(y = (3x^2-5x+7+\sin x)^{20}\). While it may look intimidating, the Generalized Power Rule states that \[y^\prime = 20(3x^2-5x+7+\sin x)^{19}\cdot (6x-5+\cos x).\]

Treat the derivative--taking process step--by--step. In the example just given, first multiply by 20, then rewrite the inside of the parentheses, raising it all to the 19\(^{\text{th}}\) power. Then think about the derivative of the expression inside the parentheses, and multiply by that.

We now consider more examples that employ the Chain Rule.

Example 61: Using the Chain Rule

Find the derivatives of the following functions:

  1. \(y = \sin{2x}\)
  2. \(y= \ln (4x^3-2x^2)\)
  3. \(y = e^{-x^2}\)

Solution:

  1. Consider \(y = \sin 2x\). Recognize that this is a composition of functions, where \(f(x) = \sin x\) and \(g(x) = 2x\). Thus \[y^\prime = f^\prime(g(x))\cdot g^\prime(x) = \cos (2x)\cdot 2 = 2\cos 2x.\]
  2. Recognize that \(y = \ln (4x^3-2x^2)\) is the composition of \(f(x) = \ln x\) and \(g(x) = 4x^3-2x^2\). Also, recall that \[\frac{d}{dx}\Big(\ln x\Big) = \frac{1}{x}.\]This leads us to:\[y^\prime = \frac{1}{4x^3-2x^2} \cdot (12x^2-4x) = \frac{12x^2-4x}{4x^3-2x^2}= \frac{4x(3x-1)}{2x(2x^2-x)} = \frac{2(3x-1)}{2x^2-x}.\]
  3. Recognize  that \(y = e^{-x^2}\) is the composition of \(f(x) = e^x\) and \(g(x) = -x^2\). Remembering that \(f^\prime(x) = e^x\),we have \[y^\prime = e^{-x^2}\cdot (-2x) = (-2x)e^{-x^2}.\]

Example 62: Using the Chain Rule to find a tangent line

Let \(f(x) = \cos x^2\). Find the equation of the line tangent to the graph of \(f\) at \(x=1\).

Solution:

The tangent line goes through the point \((1,f(1)) \approx (1,0.54)\) with slope \(f^\prime(1)\). To find \(f^\prime\),we need the Chain Rule.

\(f^\prime(x) = -\sin(x^2) \cdot(2x) = -2x\sin x^2\). Evaluated at \(x=1\),we have \(f^\prime(1) = -2\sin 1\approx -1.68\). Thus the equation of the tangent line is \[y = -1.68(x-1)+0.54 .\]

The tangent line is sketched along with \(f\) in Figure 2.17.

The Chain Rule is used often in taking derivatives. Because of this, one can become familiar with the basic process and learn  patterns that facilitate finding derivatives quickly. For instance, \[\frac{d}{dx}\Big(\ln (\text{anything})\Big) = \frac{1}{\text{anything}}\cdot (\text{anything})^\prime = \frac{(\text{anything})^\prime}{\text{anything}}.\]

A concrete example of this is \[\frac{d}{dx}\Big(\ln(3x^{15}-\cos x+e^x)\Big) = \frac{45x^{14}+\sin x+e^x}{3x^{15}-\cos x+e^x}.\] While the derivative may  look intimidating at first, look for the pattern. The denominator is the same as what was inside the natural log function; the  numerator is simply its derivative.

This pattern recognition process can be applied to lots of functions. In general, instead of writing "anything'', we use \(u\) as a generic function of \(x\). We then say \[\frac{d}{dx}\Big(\ln u\Big) = \frac{u^\prime}{u}.\]

The following is a short list of how the Chain Rule can be quickly applied to familiar functions.

FIX THIS

\item \(\ds\frac{d}{dx}\Big(u^n\Big) = n\cdot u^{n-1}\cdot u^\prime.$

\item \(\ds\frac{d}{dx}\Big(e^u\Big) = u^\prime\cdot e^u.$

\item \(\ds\frac{d}{dx}\Big(\sin u\Big) = u^\prime\cdot \cos u.$

\end{enumerate}

\end{minipage}

\begin{minipage}[t]{.5\textwidth}

\begin{enumerate}\addtocounter{enumi}{3}

\item \(\ds\frac{d}{dx}\Big(\cos u\Big) = -u^\prime\cdot \sin u.$

\item \(\ds\frac{d}{dx}\Big(\tan u\Big) = u^\prime\cdot \sec^2 u.$

\end{enumerate}

\end{minipage}\\

\vskip \baselineskip

Of course, the Chain Rule can be applied in conjunction with any of the other rules we have already learned. We practice this next.

Example 63: Using the Product, Quotient and Chain Rules

Find the derivatives of the following functions. 

1. \(f(x) = x^5 \sin{2x^3}\) \quad 2.  \(f(x) = \frac{5x^3}{e^{-x^2}}.\)

Solution:

  1. We must use the Product and Chain Rules. Do not think that you must be able to "see'' the whole answer immediately; rather, just proceed step--by--step.\[f^\prime(x) = x^5\big(6x^2\cos 2x^3\big) + 5x^4\big(\sin 2x^3\big)= 6x^7\cos2x^3+5x^4\sin 2x^3.\]
  2. We must employ the Quotient Rule along with the Chain Rule. Again, proceed step--by--step.\[\begin{align*} f^\prime(x) = \frac{e^{-x^2}\big(15x^2\big) - 5x^3\big((-2x)e^{-x^2}\big)}{\big(e^{-x^2}\big)^2} &=\frac{e^{-x^2}\big(10x^4+15x^2\big)}{e^{-2x^2}}\\ &= e^{x^2}\big(10x^4+15x^2\big). \end{align*}\]


A key to correctly working these problems is to break the problem down into smaller, more manageable pieces. For instance, when using the Product and Chain Rules together, just consider the first part of the Product Rule at first: \(f(x)g^\prime(x)\). Just rewrite \(f(x)\),then find \(g^\prime(x)\). Then move on to the \(f^\prime(x)g(x)\) part. Don't attempt to figure out both parts at once.

Likewise, using the Quotient Rule, approach the numerator in two steps and handle the denominator after completing that. Only simplify afterward.

We can also employ the Chain Rule itself several times, as shown in the next example.

Example 64: Using the Chain Rule multiple times

Find the derivative of \(y = \tan^5(6x^3-7x)\).

Solution:

Recognize that we have the \(g(x)=\tan(6x^3-7x)\) function "inside'' the \(f(x)=x^5\) function; that is, we have \(y = \big(\tan(6x^3-7x)\big)^5\). We begin using the Generalized Power Rule; in this first step, we do not fully compute the derivative. Rather, we are approaching this step--by--step.

\[y^\prime = 5\big(\tan(6x^3-7x)\big)^4\cdot g^\prime(x).\]

We now find \(g^\prime(x)\). We again need the Chain Rule; \[g^\prime(x) = \sec^2(6x^3-7x)\cdot(18x^2-7).\]Combine this with what we found above to give

\[\begin{align*} y^\prime &= 5\big(\tan(6x^3-7x)\big)^4\cdot\sec^2(6x^3-7x)\cdot(18x^2-7)\\  &= (90x^2-35)\sec^2(6x^3-7x)\tan^4(6x^3-7x). \end{align*}\]

This function is frankly a ridiculous function, possessing no real practical value. It is very difficult to graph, as the tangent function has many vertical asymptotes and \(6x^3-7x\) grows so very fast. The important thing to learn from this is that the derivative can be found. In fact, it is not "hard;'' one must take several simple steps and be careful to keep track of how to apply each of these steps.


It is a traditional mathematical exercise to find the derivatives of arbitrarily complicated functions just to demonstrate that it can be done. Just break everything down into smaller pieces. 

Example 65: Using the Product, Quotient and Chain Rules

Find the derivative of \( f(x) = \frac{x\cos(x^{-2})-\sin^2(e^{4x})}{\ln(x^2+5x^4)}.\)

Solution:

This function likely has no practical use outside of demonstrating derivative skills. The answer is given below without simplification. It employs the Quotient Rule, the Product Rule, and the Chain Rule three times.

\[f^\prime(x) = \frac{\Big(\ln(x^2+5x^4)\Big)\cdot\Big[\big(x\cdot(-\sin(x^{-2}))\cdot(-2x^{-3})+1\cdot \cos(x^{-2})\big)-2\sin(e^{4x})\cdot\cos(e^{4x})\cdot(4e^{4x})\Big]-\Big(x\cos(x^{-2})-\sin^2(e^{4x})\Big)\cdot\frac{2x+20x^3}{x^2+5x^4}}{\big(\ln(x^2+5x^4)\big)^2}.\]

The reader is highly encouraged to look at each term and recognize why it is there. (I.e., the Quotient Rule is used; in the numerator, identify the "LOdHI'' term, etc.)  This example demonstrates that derivatives can be computed systematically, no matter how arbitrarily complicated the function is.


The Chain Rule also has theoretic value. That is, it can be used to find the derivatives of functions that we have not yet learned as we do in the following example.

Example 66: The Chain Rule and exponential functions

Use the Chain Rule to find the derivative of \(y= a^x\) where \(a>0\),\(a\neq 1\) is constant.

Solution:

We only know how to find the derivative of one exponential function: \(y = e^x\); this problem is asking us to find the derivative of functions such as \(y = 2^x\).

This can be accomplished by rewriting \(a^x\) in terms of \(e\). Recalling that \(e^x\) and \(\ln x\) are inverse functions, we can write

\[a = e^{\ln a} \quad \text{and so } \quad y = a^x = e^{\ln (a^x)}.\]

By the exponent property of logarithms, we can "bring down'' the power to get 

\[y = a^x = e^{x (\ln a)}.\]

The function is now the composition \(y=f(g(x))\),with \(f(x) = e^x\) and \(g(x) = x(\ln a)\). Since \(f^\prime(x) = e^x\) and \(g^\prime(x) = \ln a\), the Chain Rule  gives 

\[y^\prime = e^{x (\ln a)} \cdot \ln a.\]

Recall that the \(e^{x(\ln a)}\) term on the right hand side is just \(a^x\),our original function. Thus, the derivative contains the original function itself. We have

\[y^\prime = y \cdot \ln a = a^x\cdot \ln a.\]

The Chain Rule, coupled with the derivative rule of \(e^x\),allows us to find the derivatives of all exponential functions.


The previous example produced a result worthy of its own "box.''

Theorem 20: Derivatives of Exponential Functions

Let \(f(x)=a^x\),for \(a>0, a\neq 1\). Then \(f\) is differentiable for all real numbers and \[f^\prime(x) = \ln a\cdot a^x.\]

 

Alternate Chain Rule Notation

It is instructive to understand what the  Chain Rule "looks like'' using "\(\frac{dy}{dx}\)'' notation instead of \(y^\prime\) notation.  Suppose that \(y=f(u)\) is a function of \(u\),where \(u=g(x)\) is a function of \(x\),as stated in Theorem 18.  Then, through the composition \(f \circ g\),we can think of \(y\) as a function of \(x\),as \(y=f(g(x))\). Thus the derivative of \(y\) with respect to \(x\) makes sense; we can talk about \(\frac{dy}{dx}.\) This leads to an interesting progression of notation:

\[\begin{align*}y^\prime &= f^\prime(g(x))\cdot g^\prime(x) \\ \frac{dy}{dx} &= y^\prime(u) \cdot u^\prime(x)\quad \text{(since \(y=f(u)\) and \(u=g(x)\))}\\ \frac{dy}{dx} &= \frac{dy}{du} \cdot \frac{du}{dx}\quad  \text{(using "fractional'' notation for the derivative)}\end{align*}\]

Here the "fractional'' aspect of the derivative notation stands out. On the right hand side, it seems as though the "\(du\)'' terms cancel out, leaving \[ \frac{dy}{dx} = \frac{dy}{dx}.\]

It is important to realize that we are not canceling these terms; the derivative notation of \(\frac{dy}{dx}\) is one symbol. It is equally important to realize that this notation was chosen precisely because of this behavior. It makes applying the Chain Rule easy with multiple variables. For instance,

\[\frac{dy}{dt} = \frac{dy}{d\bigcirc} \cdot \frac{d\bigcirc}{d\triangle} \cdot \frac{d\triangle}{dt}.\]

where \(\bigcirc\) and \(\triangle\) are any variables you'd like to use.

One of the most common ways of "visualizing" the Chain Rule is to consider a set of gears, as shown in Figure 2.18. The gears have 36, 18, and 6 teeth, respectively. That means for every revolution of the \(x\) gear, the \(u\) gear revolves twice. That is, the rate at which the \(u\) gear makes a revolution is twice as fast as the rate at which the \(x\) gear makes a revolution. Using the terminology of calculus, the rate of \(u\)-change, with respect to \(x\),is \(\frac{du}{dx} = 2\).

Likewise, every revolution of \(u\) causes 3 revolutions of \(y\): \(\frac{dy}{du} = 3\). How does \(y\) change with respect to \(x\)? For each revolution of \(x\),\(y\) revolves 6 times; that is, \[\frac{dy}{dx} = \frac{dy}{du}\cdot \frac{du}{dx} = 2\cdot 3 = 6.\]

We can then extend the Chain Rule with more variables by adding more gears to the picture.

It is difficult to overstate the importance of the Chain Rule. So often the functions that we deal with are compositions of two or more functions, requiring us to use this rule to compute derivatives. It is often used in practice when actual functions are unknown. Rather, through measurement, we can calculate \(\frac{dy}{du}\) and \(\frac{du}{dx}\). With our knowledge of the Chain Rule, finding \(\frac{dy}{dx}\) is straightforward. 

In the next section, we use the Chain Rule to justify another differentiation technique. There are many curves that we can draw in the plane that fail the "vertical line test.'' For instance, consider \(x^2+y^2=1\),which describes the unit circle. We may still be interested in finding slopes of tangent lines to the circle at various points. The next section shows how we can find \(\frac{dy}{dx}\) without first "solving for \(y\).'' While we can in this instance, in many other instances solving for \(y\) is impossible. In these situations, implicit differentiation is indispensable.