The Chain Rule

Updated 19 min read Intermediate Baca dalam Bahasa Indonesia

Calculus Proof Computing

Quick answer

The chain rule says that the derivative of a composite function is the derivative of the outside function, evaluated at the inside function, times the derivative of the inside function: (f\circ g)'(x)=f'(g(x))· g'(x). In Leibniz's notation, with y=f(u) and u=g(x), it reads (dy)/(dx)=(dy)/(du)·(du)/(dx): rates of change multiply. It is the reason that (d)/(dx)\sin 2x=2\cos 2x and (d)/(dx)e^x^2=2x e^x^2.

Key takeaways

  • A composite function f(g(x)) puts the inside function g into the outside function f; the outside is the last thing done to x, and finding the two layers is the first step of every chain rule problem.
  • (dy)/(dx)=(dy)/(du)·(du)/(dx): if y changes half as fast as u and u changes three times as fast as x, then y changes \frac32 times as fast as x, like a train of gears.
  • Outside-inside rule: differentiate the outside function and leave the inside alone, then multiply by the derivative of the inside; for example (d)/(dx)e^u=e^u(du)/(dx) and (d)/(dx)\sin u=\cos u (du)/(dx).
  • The power chain rule (d)/(dx)u^n=n u^n-1(du)/(dx) handles \left(5x^3-x^4\right)^7, (1)/(3x-2), \sin^5x and √(3x+1), and gives (d)/(dx)|x|=(x)/(|x|) for x\ne0.
  • A constant k inside a sine brings out a factor k: doubling the frequency of a piston doubles its velocity, quadruples its acceleration and multiplies its jerk by 8; in degrees the factor is (π)/(180).
  • The second derivative of a composite is f''(g) (g')^2+f'(g) g'', not f''(g) g''; and the rule needs both functions to be differentiable where they are used.

What is a composite function, and how do you find its inside and outside?

A composite function applies one function to the result of another: (f\circ g)(x)=f(g(x)), where g is the inside function, applied first, and f is the outside function, applied last. The function F(x)=\sin\left(x^2-4\right) is of this kind. It cannot be differentiated by the rules so far, but it is built from two functions that can: the outside f(u)=\sin u and the inside u=g(x)=x^2-4.

To find the layers, ask what is the last thing done to x? That is the outside function. What it is done to is the inside.

FunctionOutside f(u)Inside u=g(x)
\left(3x^2+1\right)^2u^23x^2+1
\sin\left(x^2-4\right)\sin ux^2-4
e^\cos xe^u\cos x
√(3x+1)√ u3x+1
(1)/(3x-2)u^-13x-2
\sin^5xu^5\sin x

The order matters. f(g(x)) is not g(f(x)): \sin\left(x^2\right) puts the square inside the sine, while \sin^2x=(\sin x)^2 puts the sine inside the square. At x=2 they are \sin4≈-0.757 and \sin^22≈0.827.

More than two layers. The function \tan\left(5-\sin2x\right) is a tangent of 5-\sin2x, which is 5 minus a sine of 2x, which is twice x. Peeling it like an onion gives four layers: tangent, "5 minus", sine, and "twice". Each layer will cost one factor in the derivative.

Not every combination is a composition. x^2\sin x is a product of two functions of x, and x^2+\sin x is a sum: neither puts one function inside the other, so the product rule and the sum rule are the ones to use. A function can need both, as x\sin2x does.

What is the chain rule?

The chain rule says that if g is differentiable at x and f is differentiable at g(x), then f\circ g is differentiable at x and (f\circ g)'(x)=f'(g(x))· g'(x). In Leibniz's notation, with y=f(u) and u=g(x), (dy)/(dx)=(dy)/(du)·(du)/(dx), where (dy)/(du) is evaluated at u=g(x).

Why rates multiply. Three gears are meshed in a line. When gear A turns x times, gear B turns u=3x times, because B turns three times for each turn of A, and gear C turns y=u/2 times, because C turns half a turn for each turn of B. So y=(3x)/(2) and (dy)/(dx)=\frac32=\frac12·3=(dy)/(du)·(du)/(dx). If y changes half as fast as u and u changes three times as fast as x, then y changes \frac32 times as fast as x. For curves the same is true instant by instant: the slope of the composite at x is the rate of the outside at the point g(x) that the inside has reached times the rate of the inside at x.

The outside-inside rule. In words: differentiate the outside function and evaluate it at the inside function left alone, then multiply by the derivative of the inside function. The Leibniz form hides where each derivative is evaluated; the functional form f'(g(x))· g'(x) shows it: f' at g(x), not at x.

Example 1. Find the derivative of y=\left(3x^2+1\right)^2. The outside is y=u^2 and the inside is u=3x^2+1, so (dy)/(du)=2u=2\left(3x^2+1\right) and (du)/(dx)=6x: (dy)/(dx)=2\left(3x^2+1\right)·6x=36x^3+12x. Expanding first gives y=9x^4+6x^2+1 and the same 36x^3+12x. The chain rule is not needed for this one, but it is for \left(3x^2+1\right)^50.

Example 2. A body moves along a line with position x(t)=\cos\left(t^2+1\right) at time t\ge0. The outside is \cos u, with derivative -\sin u, and the inside is u=t^2+1, with derivative 2t. The velocity is v=-\sin\left(t^2+1\right)·2t =-2t\sin\left(t^2+1\right).

A proof of one case, and its gap. Let \Delta u=g(x+\Delta x)-g(x) and \Delta y=f(u+\Delta u)-f(u). If \Delta u\ne0 we can write (\Delta y)/(\Delta x)=(\Delta y)/(\Delta u)·(\Delta u)/(\Delta x). As \Delta x→0 we also have \Delta u→0, because g is continuous, so the right side tends to f'(u)· g'(x). The gap is that if g oscillates rapidly near x, \Delta u can be 0 even when \Delta x\ne0, and then the cancellation is not allowed. A complete proof avoids dividing by \Delta u: it writes \Delta y=\left(f'(u)+\varepsilon\right)\Delta u, where \varepsilon→0 as \Delta u→0 and \varepsilon=0 when \Delta u=0. That form is true in every case.

Pick an outside function and an inside function below, slide x, and compare the product of the two rates with the slope of the graph of the composite.

Interactive: rates multiply

Pick an outside function and an inside function, slide x, and see that the rate of the inside times the rate of the outside is the slope of the composite graph.

How do you differentiate sin u, e^u and other functions of a function?

For any differentiable function u(x), each formula for x gets one extra factor (du)/(dx): (d)/(dx)\sin u=\cos u·(du)/(dx), (d)/(dx)\cos u=-\sin u·(du)/(dx), (d)/(dx)e^u=e^u·(du)/(dx), and so on. The chain rule turns the table of the derivatives of trigonometric functions into one for any inside function:

  • (d)/(dx)\sin u=\cos u· u' and (d)/(dx)\cos u=-\sin u· u';
  • (d)/(dx)\tan u=\sec^2u· u' and (d)/(dx)\cot u=-\csc^2u· u';
  • (d)/(dx)\sec u=\sec u\tan u· u' and (d)/(dx)\csc u=-\csc u\cot u· u';
  • (d)/(dx)e^u=e^u· u'.

Example 3. Differentiate \sin\left(x^2+e^x\right). The outside is the sine, the inside is x^2+e^x, and the inside has derivative 2x+e^x: (d)/(dx)\sin\left(x^2+e^x\right) =\cos\left(x^2+e^x\right)·\left(2x+e^x\right).

Example 4. Differentiate y=e^\cos x. The outside is the exponential, and its derivative at the inside \cos x is e^\cos x again. The inside has derivative -\sin x: (dy)/(dx)=e^\cos x·(-\sin x)=-\sin x e^\cos x.

A constant inside. For a constant k the inside kx has derivative k, so (d)/(dx)e^kx=k e^kx (d)/(dx)\sin(kx)=k\cos(kx) (d)/(dx)\tan(4x)=4\sec^2(4x). Also (d)/(dx)e^x^2=e^x^2·2x and (d)/(dx)\sec\left(x^2\right)=2x\sec\left(x^2\right)\tan\left(x^2\right). The chain rule works together with the other rules: for x\sin2x the product rule gives \sin2x+x·(d)/(dx)\sin2x=\sin2x+2x\cos2x.

Type any function below built from these pieces, and read off each rule it uses, with its outside and inside function.

Interactive: differentiate a composite function

Type a function built from powers, e^u, sin, cos, tan, cot, sec, csc and square roots of other functions, and see each chain rule step with its outside and inside function, the derivative and higher derivatives, checked against a difference quotient.

What do you do when functions are nested three or more deep?

Apply the chain rule once for each layer, from the outside in: differentiate the outermost function with everything inside left alone, multiply by the derivative of what was inside, and repeat on that until the inside is just x. Write the layers down first, and the derivative is a product with one factor for each of them.

Example 5. Find the derivative of g(t)=\tan\left(5-\sin2t\right). The tangent is a function of 5-\sin2t; the sine is a function of 2t, which is itself a function of t. Peel the layers: g'(t)=\sec^2\left(5-\sin2t\right) ·(d)/(dt)\left(5-\sin2t\right) =\sec^2\left(5-\sin2t\right) ·\left(-\cos2t·(d)/(dt)(2t)\right) =-2\cos2t \sec^2\left(5-\sin2t\right).

Example 6. The function \sin\left(\cos(\tan x)\right) has three layers, so three factors: (d)/(dx)\sin\left(\cos(\tan x)\right) =\cos\left(\cos(\tan x)\right) ·\left(-\sin(\tan x)\right)·\sec^2x. Each factor is the derivative of one layer with the layers inside it left alone: the cosine of the cosine, the minus sine of the tangent, and the secant squared.

Example 7. For y=√(1+\cos^2x) the layers are a square root, "1 plus", a square, and a cosine: y'=(1)/(2√(1+\cos^2x))·2\cos x·(-\sin x) =-(\sin x\cos x)/(√(1+\cos^2x)).

Try the function of Example 5, and any of your own, in the tool of the previous section: it lists one chain rule step for each layer.

What is the power chain rule, and when does it replace the quotient rule?

If u is a differentiable function of x and n is any real number, then (d)/(dx)u^n=n u^n-1 (du)/(dx). This is the chain rule with the outside function f(u)=u^n, whose derivative is the power rule nu^n-1. The inside function u may be any function: a sum, a sine, a quotient.

Example 8. Four derivatives with the power chain rule.

  • (d)/(dx)\left(5x^3-x^4\right)^7=7\left(5x^3-x^4\right)^6·\left(15x^2-4x^3\right).
  • (d)/(dx)(1)/(3x-2)=(d)/(dx)(3x-2)^-1=-(3x-2)^-2·3=-(3)/((3x-2)^2). The quotient rule gives the same answer, with more writing.
  • (d)/(dx)\sin^5x=5\sin^4x·\cos x, because \sin^5x means (\sin x)^5.
  • (d)/(dx)e^√(3x+1)=e^√(3x+1)·(d)/(dx)(3x+1)^1/2=e^√(3x+1)·(3)/(2√(3x+1)). Two layers sit inside the exponential, so there are two chain steps.

Example 9: the absolute value. Since |x|=√(x^2), the power chain rule with u=x^2 and n=\frac12 gives, for x\ne0, (d)/(dx)|x|=\frac12\left(x^2\right)^-1/2·2x =(x)/(√(x^2))=(x)/(|x|). That is 1 for x>0 and -1 for x<0. At x=0 the formula is undefined, which agrees with the corner of the graph, a point where there is no derivative.

Example 10: always uphill. Show that every tangent line to y=(1)/((1-2x)^3) has a positive slope. Write y=(1-2x)^-3. Then (dy)/(dx)=-3(1-2x)^-4·(-2)=(6)/((1-2x)^4). At any point of the curve x\ne\frac12, so the denominator is a fourth power and positive: the slope is a quotient of two positive numbers.

Another useful one. (d)/(dx)√(x^2+1)=(1)/(2√(x^2+1))·2x=(x)/(√(x^2+1)), which is the slope of the curve whose points are √(x^2+1) above the axis, a hyperbola.

How does the chain rule explain frequency, amplitude and degrees?

A constant k inside a sine multiplies the derivative by k: (d)/(dx)\sin(kx)=k\cos(kx), so a wave that oscillates k times as fast is k times as steep. The inside function kx has derivative k, and nothing else changes. The curves y=\sin x, y=\sin2x and y=\sinx/2 cross the axis at the origin with slopes 1, 2 and \frac12.

sin x (green), sin 2x (orange) and sin(x/2) (blue): at the origin the slopes are 1, 2 and 1/2, the constant inside.

Higher derivatives. Each derivative of \sin(kx) brings out one more factor k, so the derivatives follow the cycle of four with k^n in front: k\cos(kx), then -k^2\sin(kx), then -k^3\cos(kx), then k^4\sin(kx).

A piston. Let a piston's position be s=A\cos(2π bt), with amplitude A and frequency b cycles per second. Put w=2π b. Then v=-wA\sin(wt) a=-w^2A\cos(wt) j=w^3A\sin(wt), so the greatest velocity, acceleration and jerk are wA, w^2A and w^3A. Doubling the frequency doubles the velocity, quadruples the acceleration and multiplies the jerk by 8. This is why machinery can break when it is run too fast: the forces, which follow the acceleration, grow with the square of the speed of the motion. The motion along a line of the spring is the case b=(1)/(2π).

Temperature in Fairbanks, Alaska. The average temperature on day x of the year, in degrees Celsius, is approximately y=20\sin\left((2π)/(365)(x-101)\right)-4. By the chain rule its rate of change is y'=(40π)/(365)\cos\left((2π)/(365)(x-101)\right). The temperature is rising fastest when the cosine equals 1, at x=101, which is April 11, and then it rises (40π)/(365)≈0.34 degrees per day. The factor (40π)/(365) is the amplitude 20 times the constant inside, (2π)/(365).

Degrees. Since x^\circ=(π x)/(180) radians, the inside function of \sin\left(x^\circ\right) is (π x)/(180), and (d)/(dx)\sin\left(x^\circ\right)=(π)/(180)\cos\left(x^\circ\right). The sine of x degrees oscillates only (π)/(180)≈0.01745 times as often as \sin x, and its greatest slope is (π)/(180). The factor would appear again in every derivative, which is the advantage of radian measure that the limit of sin h over h already showed.

Change k, switch to degrees, or double the frequency of the piston below.

Interactive: the constant inside a sine

Change k in A sin(kx) and see the slope grow by the factor k, switch to degrees to see the factor π/180, or double the frequency of a piston and watch its velocity, acceleration and jerk grow by 2, 4 and 8.

How do you find the second derivative of a composite function?

Differentiate f'(g(x))· g'(x) with the product rule, and the chain rule on its first factor, and you get (f\circ g)''=f''(g(x))·\left(g'(x)\right)^2+f'(g(x))· g''(x). Here is the step. The first derivative is y'=f'(g) g'. The product rule gives y''=\left((d)/(dx)f'(g)\right)g'+f'(g) g''. By the chain rule (d)/(dx)f'(g)=f''(g) g', so the first term is f''(g) g'· g'=f''(g)\left(g'\right)^2. There are two terms because the inside function enters twice: once through its rate g' and once through its own rate of change g''.

Example 11. Find y'' for y=\sin\left(x^2\right). With f=\sin and g=x^2: f'(g)=\cos\left(x^2\right), g'=2x, f''(g)=-\sin\left(x^2\right), g''=2. So y'=2x\cos\left(x^2\right), y''=-\sin\left(x^2\right)·4x^2+\cos\left(x^2\right)·2 =2\cos\left(x^2\right)-4x^2\sin\left(x^2\right).

Example 12. For y=\left(x^2+1\right)^3 take f=u^3 and g=x^2+1: f'=3u^2, f''=6u, g'=2x, g''=2. Then y''=6\left(x^2+1\right)·4x^2 +3\left(x^2+1\right)^2·2 =30x^4+36x^2+6. Expanding first gives y=x^6+3x^4+3x^2+1 and y''=30x^4+36x^2+6, the same.

The common slip is to write f''(g)· g'' for the second derivative. The term f'(g) g'' is lost, and the factor \left(g'\right)^2 too. If the inside is a straight line g=ax+b, then g''=0 and only f''(g)· a^2 is left: that is why (d^2)/(dx^2)\sin(kx)=-k^2\sin(kx).

The tool of the section on nested functions also shows second and third derivatives of what you type.

When does the chain rule apply, and what happens when it does not?

The chain rule is an if statement: if the inside function is differentiable at x and the outside function is differentiable at g(x), then the composite is differentiable and the formula holds. It does not say what happens when a hypothesis fails, and in that case the composite may or may not be differentiable.

Example 13: the inside is not differentiable, the composite is. Let f(x)=x^2 and g(x)=|x|. Both f\circ g and g\circ f equal x^2, because |x|^2=x^2 and \left|x^2\right|=x^2, and both are differentiable at x=0 although g=|x| is not. This does not contradict the chain rule: the rule needs g to be differentiable at 0, it does not say the composite is not differentiable otherwise.

A derivative that is not continuous. Consider f(x)=x^2\sin\frac1x for x\ne0, with f(0)=0. For x\ne0 the chain rule on \sin\frac1x and the product rule give f'(x)=2x\sin\frac1x-\cos\frac1x. At x=0 the inside function \frac1x does not exist, so the chain rule cannot be used; we go back to the definition. The quotient is (h^2\sin(1/h))/(h)=h\sin\frac1h, and since \left|h\sin\frac1h\right|\le|h| it tends to 0: f'(0)=0. Yet f'(x) has no limit as x→0, because \cos\frac1x oscillates between -1 and 1. So f is differentiable everywhere, and its derivative is not continuous at 0.

A function that is continuous but has no derivative. For x\sin\frac1x (and 0 at 0) the quotient at 0 is \sin\frac1h, which oscillates and has no limit: the function is continuous at 0 and not differentiable there. This is the kind of rapid oscillation that caused the gap in the proof of the chain rule.

How do you apply the chain rule in code?

**SymPy applies the chain rule to any composite function: sp.diff(sp.sin(2x), x) gives 2cos(2*x), and sp.diff(f, x, 2) gives the second derivative. It writes \sec^2u as `tan(u)2 + 1, the same function. The numbers of the examples above come out as they should: (3*x2 + 1)2 has the derivative 12x(3*x**2 + 1), and sp.simplify turns the derivative of (5*x3 - x4)7 into x20(105 - 28x)*(x - 5)**6`, which is 7\left(5x^3-x^4\right)^6\left(15x^2-4x^3\right) with the common factors collected.

Python and SymPy: the chain rule on composites
import sympy as sp

x = sp.symbols('x')
for f in (sp.sin(2 * x), (3 * x**2 + 1) ** 2, sp.exp(sp.cos(x)),
          sp.sin(x**2 + sp.exp(x)), sp.sqrt(3 * x + 1), sp.tan(5 - sp.sin(2 * x))):
    print(f, '->', sp.diff(f, x))
# sin(2*x) -> 2*cos(2*x)
# (3*x**2 + 1)**2 -> 12*x*(3*x**2 + 1)
# exp(cos(x)) -> -exp(cos(x))*sin(x)
# sin(x**2 + exp(x)) -> (2*x + exp(x))*cos(x**2 + exp(x))
# sqrt(3*x + 1) -> 3/(2*sqrt(3*x + 1))
# -tan(sin(2*x) - 5) -> -2*(tan(sin(2*x) - 5)**2 + 1)*cos(2*x)

print(sp.diff(sp.sin(x**2), x, 2))                    # 2*(-2*x**2*sin(x**2) + cos(x**2))
print(sp.simplify(sp.diff((5 * x**3 - x**4) ** 7, x)))   # x**20*(105 - 28*x)*(x - 5)**6

A program can apply the chain rule to numbers instead of formulas. Carry with every value its derivative, a pair (v,d), and give each operation its chain rule: for the sine, (v,d)\mapsto\left(\sin v, \cos v· d\right), which is f'(u)· u' again. Start with x=(0.7,1), because x has derivative 1, and the program computes \sin\left(x^2+e^x\right) and its derivative at the same time. This is forward-mode automatic differentiation. It gives -2.742554, the same as the formula \cos\left(x^2+e^x\right)\left(2x+e^x\right) at x=0.7 and the same as a central difference.

Applying the rule from the outside in, to a program of millions of steps, is reverse-mode automatic differentiation, which is what backpropagation in a neural network does: one pass computes the output, and one pass back multiplies the rates of the layers.

Python: forward-mode differentiation with a pair (value, derivative)
import math

f = lambda x: math.sin(x**2 + math.exp(x))
x0 = 0.7
chain = math.cos(x0**2 + math.exp(x0)) * (2 * x0 + math.exp(x0))     # the formula
central = (f(x0 + 1e-6) - f(x0 - 1e-6)) / 2e-6                       # a difference quotient
print(round(chain, 6), round(central, 6))                            # -2.742554 -2.742554


class Dual:
    """A number and its derivative, carried together."""
    def __init__(self, v, d=0.0):
        self.v, self.d = v, d
    def __add__(self, o):
        o = o if isinstance(o, Dual) else Dual(o)
        return Dual(self.v + o.v, self.d + o.d)
    __radd__ = __add__
    def __mul__(self, o):
        o = o if isinstance(o, Dual) else Dual(o)
        return Dual(self.v * o.v, self.d * o.v + self.v * o.d)     # the product rule
    __rmul__ = __mul__

def sin(u): return Dual(math.sin(u.v), math.cos(u.v) * u.d)        # the chain rule: f'(u) * u'
def exp(u): return Dual(math.exp(u.v), math.exp(u.v) * u.d)

x = Dual(0.7, 1.0)                                                  # x has derivative 1
y = sin(x * x + exp(x))
print(round(y.v, 6), round(y.d, 6))                                 # 0.595461 -2.742554
C++
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

// A dual number is {value, derivative}: the two travel together through every operation.
void add(const double a[], const double b[], double r[]) { r[0] = a[0] + b[0]; r[1] = a[1] + b[1]; }
void mul(const double a[], const double b[], double r[]) {
  r[0] = a[0] * b[0];
  r[1] = a[1] * b[0] + a[0] * b[1];                    // the product rule
}
void dsin(const double u[], double r[]) { r[0] = sin(u[0]); r[1] = cos(u[0]) * u[1]; }   // the chain rule: f'(u) u'
void dexp(const double u[], double r[]) { r[0] = exp(u[0]); r[1] = exp(u[0]) * u[1]; }

double f(double x) { return sin(x * x + exp(x)); }

int main() {
  double x0 = 0.7;
  double chain = cos(x0 * x0 + exp(x0)) * (2 * x0 + exp(x0));              // the formula
  double central = (f(x0 + 1e-6) - f(x0 - 1e-6)) / 2e-6;                    // a difference quotient
  printf("%.6f %.6f\n", chain, central);

  double x[2] = {0.7, 1};                              // x has derivative 1
  double xx[2], e[2], s[2], y[2];
  mul(x, x, xx);
  dexp(x, e);
  add(xx, e, s);
  dsin(s, y);                                          // y = sin(x * x + exp(x))
  printf("%.6f %.6f\n", y[0], y[1]);
  return 0;
}

/* output:
-2.742554 -2.742554
0.595461 -2.742554
*/

Who discovered the chain rule, and how was it first proved?

The chain rule is as old as the calculus, but a proof that has no gap took about two centuries more.

  • Leibniz. The chain rule seems to have been used first by Gottfried Leibniz, in a manuscript of 1676, to differentiate the square root of a+bz+cz^2 as a square root of a quadratic. His notation (dy)/(dx)=(dy)/(du)·(du)/(dx) makes the rule look like fractions that cancel, which is why it is easy to remember, and why it is not a proof.
  • Bernoulli and l'Hôpital. Johann Bernoulli taught the new calculus to the Marquis de l'Hôpital, whose 1696 textbook Analyse des infiniment petits spread it across Europe.
  • Lagrange. The prime notation f'(x), which writes the chain rule as f'(g(x))· g'(x) and shows where each derivative is taken, was introduced by Joseph-Louis Lagrange.
  • A proof without the gap. In the 20th century Constantin Carathéodory's way of defining the derivative, f(x)-f(a)=φ(x)(x-a) with φ continuous at a, gave a short proof of the chain rule that never divides by \Delta u.
  • Backpropagation. Applying the rule from the output back to the input of a computation, in reverse mode, was described by Seppo Linnainmaa in 1970, and David Rumelhart, Geoffrey Hinton and Ronald Williams made it the standard way of training neural networks in 1986.

What mistakes do people make with the chain rule?

The most common mistakes with the chain rule are the nine below, each with the correct statement.

MistakeCorrect
❌ (d)/(dx)\sin2x=\cos2xThe derivative of the inside is a factor: (d)/(dx)\sin2x=2\cos2x.
❌ (d)/(dx)\left(x^2+1\right)^5=5\left(x^2+1\right)^4The power rule gives only the outside: multiply by 2x to get 10x\left(x^2+1\right)^4.
❌ (d)/(dx)e^2x=2x e^2x-1The exponent contains x, so the power rule does not apply. The derivative of e^u is e^u· u', which is 2e^2x.
❌ (d)/(dx)\cos\left(x^2\right)=-\sin x·2xThe outside derivative is evaluated at the inside, not at x: -\sin\left(x^2\right)·2x.
❌ (d)/(dx)\sin^2x=2\sin xThere are two layers, a square and a sine: 2\sin x·\cos x.
❌ The second derivative of f(g(x)) is f''(g(x))· g''(x)It is f''(g)\left(g'\right)^2+f'(g) g'': the second term and the square were lost.
❌ (f\circ g)'=f'\circ g', the composition of the derivativesIt is a product: f'(g(x))· g'(x), with f' taken at g(x).
❌ If g is not differentiable at a, then f(g(x)) is not eitherNot necessarily: with g=|x| and f=x^2 the composite is x^2, differentiable at 0.
❌ (d)/(dx)\sin\left(x^\circ\right)=\cos\left(x^\circ\right)The inside (π x)/(180) adds a factor: (π)/(180)\cos\left(x^\circ\right).

Practice: test your understanding

These questions mix everything above. A wrong answer costs nothing here: read the hint and try again.

True or false?

Decide whether each statement is True or False.

  • (f\circ g)'(x)=f'(g(x))· g'(x).
  • (d)/(dx)\sin3x=3\cos3x.
  • (d)/(dx)e^x^2=e^x^2.
  • (d)/(dx)\left(x^2+1\right)^5=5\left(x^2+1\right)^4.
  • If g is not differentiable at a, then f(g(x)) cannot be differentiable at a.
  • (d)/(dx)\sin^2x=2\sin x\cos x.

Select all that apply

Choose all the correct derivatives.

  • (d)/(dx)\cos5x=-5\sin5x
  • (d)/(dx)e^-x=-e^-x
  • (d)/(dx)√(x^2+1)=(x)/(√(x^2+1))
  • (d)/(dx)\tan\left(x^2\right)=2x\sec^2\left(x^2\right)
  • (d)/(dx)\sin\left(x^2\right)=\cos\left(x^2\right)

A power of a sum

For y=\left(3x^2+1\right)^2 find y'(1).

A constant inside a sine

Find the slope of y=\sin2x at x=0.

Always uphill

Find the slope of y=(1)/((1-2x)^3) at x=0.

Outside at the inside

What is (d)/(dx)\cos\left(x^2\right)?

  • -2x\sin\left(x^2\right)
  • -\sin\left(x^2\right)
  • -2x\sin x
  • 2x\cos x

A second derivative

For y=\sin\left(x^2\right) find y''(0).

The second derivative formula

What is (d^2)/(dx^2)f(g(x))?

  • f''(g)\left(g'\right)^2+f'(g) g''
  • f''(g) g''
  • f''(g)\left(g'\right)^2
  • f'(g) g''

A faster piston

A piston moves as s=A\cos(2π bt). By what factor does its greatest acceleration grow when the frequency b is doubled?

The warmest rise

The temperature is y=20\sin\left((2π)/(365)(x-101)\right)-4 on day x. On which day is it rising fastest?

Cosine in degrees

What is (d)/(dx)\cos\left(x^\circ\right)?

  • -\sin\left(x^\circ\right)
  • -(π)/(180)\sin\left(x^\circ\right)
  • (π)/(180)\sin\left(x^\circ\right)
  • -(180)/(π)\sin\left(x^\circ\right)

A derivative at the origin

Let f(x)=x^2\sin\frac1x for x\ne0 and f(0)=0. What is f'(0)?

  • 0
  • 1
  • it does not exist
  • -1

Summary: the chain rule at a glance

  • The rule: (f\circ g)'(x)=f'(g(x))· g'(x), or (dy)/(dx)=(dy)/(du)·(du)/(dx): differentiate the outside with the inside left alone, then multiply by the derivative of the inside.
  • Layers: find the outside by asking what is done last to x; with three or more layers, one factor for each, from the outside in.
  • Formulas: (\sin u)'=\cos u· u', (e^u)'=e^u· u', \left(u^n\right)'=n u^n-1u', and likewise for the other functions.
  • Constants inside: (d)/(dx)\sin(kx)=k\cos(kx); doubling a piston's frequency multiplies velocity, acceleration and jerk by 2, 4, 8; in degrees the factor is (π)/(180).
  • Second derivative: f''(g)\left(g'\right)^2+f'(g) g''.
  • Limits of the rule: both functions must be differentiable where used; a composite can be differentiable when the inside is not, as |x|^2 is.
  • Code: sp.diff for formulas; a pair (v,d) with f'(u)· u' for numbers.

Glossary: key terms

Composite function
A function formed by applying one function to the output of another, written f of g of x, where the inside function g is applied first and the outside function f last.
Inside function
The function in a composite that is applied first, so that its output is the input of the outside function; it is the u in y equals f of u.
Outside function
The function in a composite that is applied last, to the result of the inside function; it is the f in y equals f of u.
Chain rule
The rule that the derivative of a composite function is the derivative of the outside function evaluated at the inside function, times the derivative of the inside function.
Power chain rule
The chain rule for a power of a function: the derivative of u to the n is n times u to the n minus 1 times the derivative of u.
Frequency
The number of complete cycles an oscillation makes per unit of time; in the sine of 2 pi b t it is b, and every derivative multiplies the motion by 2 pi b.
Automatic differentiation
A way of computing exact derivatives of a program by carrying a derivative along with every value and applying the chain rule at every operation.

Frequently asked questions

What is the chain rule in calculus?

The chain rule gives the derivative of a composite function. It says to differentiate the outside function at the inside function and multiply by the derivative of the inside function, so the derivative of f of g of x is f prime of g of x times g prime of x.

How do you know when to use the chain rule?

Use it when one function is put inside another, such as sine of two x, e to the x squared or a power of a sum. If the last operation done to x is a function applied to an expression, and not a sum or product of separate pieces, there is a chain.

What is the outside-inside rule?

It is the chain rule in words: differentiate the outside function and evaluate it at the inside function left alone, then multiply by the derivative of the inside function. It reminds you that the outside derivative is evaluated at the inside, not at x.

What is the derivative of sin 2x?

It is two cosine of two x. The outside function is sine, whose derivative is cosine evaluated at two x, and the inside function two x has derivative 2, so the factor 2 comes out in front. Forgetting it is the most common mistake.

What is the derivative of e to the x squared?

It is two x times e to the x squared. The derivative of e to the u is e to the u times the derivative of u, and here u is x squared with derivative two x. The power rule does not apply to an exponent that contains x.

How do you use the chain rule more than once?

Work from the outside in, one layer at a time. Differentiate the outermost function with everything inside it left alone, multiply by the derivative of what was inside, and apply the rule again to that, until the inside is just x. Each layer gives one factor.

What is the power chain rule?

It is the chain rule for a power of a function: the derivative of u to the n is n times u to the n minus one times the derivative of u. It handles powers of sums, reciprocals and square roots of any expression.

What is the second derivative of a composite function?

It is f double prime of g times the square of g prime, plus f prime of g times g double prime. The product rule makes two terms, and the chain rule on f prime of g supplies the extra factor g prime in the first one.

Does the chain rule work if the inside function is not differentiable?

The rule itself needs the inside function to be differentiable where it is used. The composite may still be differentiable, though: the square of the absolute value of x is x squared, which has a derivative at zero even though the absolute value does not.

References

  1. Joel Hass, Christopher Heil, Maurice D. Weir et al. (2023). Thomas' Calculus: Early Transcendentals in SI Units (15th ed.), Section 3.6: The Chain Rule. Pearson.
  2. James Stewart (2015). Calculus (8th ed.), section 3.4: The Chain Rule. Cengage Learning.
  3. Stephen Kuhn (1991). The derivative à la Carathéodory. The American Mathematical Monthly, 98(1), 40–44.
  4. David E. Rumelhart, Geoffrey E. Hinton, Ronald J. Williams (1986). Learning representations by back-propagating errors. Nature, 323, 533–536.
  • Derivatives of Trigonometric Functions: Derivatives of trigonometric functions with proofs: sin x and cos x, then tan, cot, sec and csc, why radians, simple harmonic motion, higher derivatives, and code.
  • Differentiation Rules: Differentiation rules with proofs and examples: constant, power, multiple, sum, product and quotient rules, the derivative of e^x, and higher-order derivatives.
  • Related Rates: Related rates: differentiate an equation in time to find an unknown rate, with the four-step strategy, six worked examples, a sliding ladder and common mistakes.
  • Implicit Differentiation: Implicit differentiation explained: find dy/dx without solving for y, tangent and normal lines, second derivatives, rational powers, pitfalls, and code.