Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 68 ยท Derivatives

The Chain Rule

Differentiate composite functions with the chain rule, handle nested chains, implicit differentiation and inverse functions, and avoid the usual mistakes.

Most real formulas are not plain polynomials. The pressure of a gas depends on volume, which depends on time. The voltage across a capacitor is e^(-t/RC), an exponential whose exponent is itself a function of time. In each case one function sits inside another, and you need the chain rule to differentiate it.

The chain rule is the most used rule in calculus, and the heart of backpropagation in neural networks. This lesson explains it with a gears picture, applies it to nested functions, extends it to implicit differentiation (curves like circles that are not written as y = f(x)), uses it to find derivatives of inverse functions, and lists the mistakes to watch for. You should already know the basic differentiation rules.

Composite functions

A composite function feeds the output of one function into another. Write y = f(g(x)): first compute u = g(x), then y = f(u). For example y = (3x + 1)^5 is f(u) = u^5 applied to u = 3x + 1. We call g the inner function and f the outer function.

You met composition in Functions and Graphs. Differentiation must respect its order: you cannot treat the inside and outside as separate problems.

The rule

TEXT
d/dx f(g(x)) = f'(g(x)) * g'(x)

In Leibniz notation, with y = f(u) and u = g(x):

TEXT
dy/dx = (dy/du) * (du/dx)

Differentiate the outside while leaving the inside untouched, then multiply by the derivative of the inside. Picture three gears: if u turns 3 times as fast as x, and y turns twice as fast as u, then y turns 6 times as fast as x. Rates multiply.

flowchart LR
    X["x"] -->|"du/dx"| U["u = g(x)"]
    U -->|"dy/du"| Y["y = f(u)"]
    X -.->|"dy/dx = dy/du * du/dx"| Y

Rates of change along a chain multiply, like meshed gears.

For y = (3x + 1)^5: the outer derivative is 5u^4 = 5(3x + 1)^4, the inner derivative is 3, so dy/dx = 15(3x + 1)^4.

Python Chain rule by hand versus sympy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the square root, the outer function is sqrt(u) with derivative 1 / (2 sqrt(u)), and the inner derivative is 2x - 1. Sympy writes the result in a slightly different but equivalent form, which is why the second pair is printed side by side for you to compare.

Nested chains

When there are three or more layers, repeat the idea from the outside in. For y = sin^3(2x), which means (sin(2x))^3:

  1. Outer: u^3 gives 3u^2 = 3 sin^2(2x).
  2. Middle: sin(v) gives cos(v) = cos(2x).
  3. Inner: 2x gives 2.

Multiply all three: 3 sin^2(2x) * cos(2x) * 2 = 6 sin^2(2x) cos(2x).

You will meet the derivatives of sin, cos, e^x and ln x properly in the next lesson; for now accept sin' = cos. A reliable method is to write each layer on its own line (u, v, w), differentiate each, and multiply.

Python A three-layer chain, checked numerically

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If your hand formula is wrong, even by a missing factor of 2, the two columns drift apart at once. That makes numeric checks very effective for chains.

Implicit differentiation

Some curves cannot be written neatly as y = f(x). The circle x^2 + y^2 = 25 is one: solving for y gives two branches. Implicit differentiation avoids solving. Treat y as a function of x, differentiate both sides with respect to x, and apply the chain rule whenever you differentiate something containing y.

Differentiating x^2 + y^2 = 25:

TEXT
2x + 2y * (dy/dx) = 0
dy/dx = -x / y

The factor dy/dx appears because d/dx (y^2) = 2y * dy/dx by the chain rule: y is the inside function. At the point (3, 4), the slope is -3/4. That makes sense: the radius to (3, 4) has slope 4/3, and the tangent is perpendicular to it.

Python Implicit slope of a circle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The formula dy/dx = -F_x / F_y (partial derivatives) is a shortcut that works for any curve F(x, y) = 0; you will see where it comes from in Partial Derivatives. Both approaches give -3/4 at (3, 4).

Inverse functions

If y = f(x) has an inverse x = f^(-1)(y), the chain rule applied to f(f^(-1)(y)) = y gives

TEXT
d/dy f^(-1)(y) = 1 / f'(f^(-1)(y))

Geometrically, reflecting a graph in the line y = x swaps rise and run, so slopes become reciprocals. Example: f(x) = x^3 has inverse cube root of y. At y = 8 the inverse is 2, and f'(2) = 12, so the inverse's slope is 1/12. Direct differentiation of y^(1/3) gives (1/3) y^(-2/3) = 1/(3 * 4) = 1/12. The same idea yields the derivative of ln x from e^x and of arcsin x from sin x.

Common mistakes

  • Forgetting the inner derivative: d/dx (3x + 1)^5 is not 5(3x + 1)^4. The missing factor is 3.
  • Differentiating the inside twice: take the outer derivative with the inside unchanged.
  • Dropping dy/dx in implicit work: d/dx (y^2) is 2y y', not 2y.
  • Mixing up the layers: sin(x^2) and sin^2(x) are different compositions with different derivatives (2x cos(x^2) versus 2 sin(x) cos(x)).

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is d/dx (2x + 7)^4?

    The outer derivative is 4u^3 = 4(2x + 7)^3 and the inner derivative is 2, so the product is 8(2x + 7)^3.
  2. 2. In dy/dx = (dy/du)(du/dx), what does u represent?

    u = g(x) is the intermediate variable between x and y, the output of the inside function.
  3. 3. For x^2 + y^2 = 25, implicit differentiation gives which slope formula?

    Differentiating gives 2x + 2y dy/dx = 0, so dy/dx = -x/y.
  4. 4. If f(2) = 5 and f'(2) = 4, and f has an inverse, what is the slope of the inverse at y = 5?

    The derivative of the inverse at y is 1 / f'(x) where f(x) = y. Here that is 1/4.
  5. 5. Which is the correct derivative of sin(x^2)?

    Outer: sin gives cos(x^2). Inner: x^2 gives 2x. The product is 2x cos(x^2).

Summary

  • For a composite f(g(x)), d/dx = f'(g(x)) * g'(x): outer derivative with the inside unchanged, times the inner derivative.
  • With several layers, work from the outside in and multiply every factor.
  • Implicit differentiation applies the chain rule to every y term, giving y' factors you then solve for.
  • The inverse's derivative is the reciprocal: 1 / f'(f^(-1)(y)).
  • Check chain-rule answers numerically; the usual error is a missing inner derivative.

Continue with Derivatives of Exponentials, Logs and Trig Functions.