Skip to content
Glacius
CalculusConcept reference

Scalar chain rule

The derivative of a composition is the outer derivative evaluated at the inner output, times the inner derivative.

On this page 9 sections
  1. Overview
  2. Follow the values before the derivatives
  3. Multiply the two local rates
  4. Evaluate the outer derivative at the inner value
  5. Work through a nonlinear inner function
  6. Track signs and dependency paths
  7. Key takeaway
  8. Sources & further reading
  9. Concept connections

01Follow the values before the derivatives#

Suppose a computation first forms u=2x+3u=2x+3, then squares it to get y=u2y=u^2. To find how yy changes with xx, we must account for both operations.

Call the inner function g(x)=2x+3g(x)=2x+3 and the outer function f(u)=u2f(u)=u^2. Their composition is y=f(g(x))y=f(g(x)). The inner function acts first, even though it is written inside the outer one.

At x=1x=1, the intermediate value is u=5u=5 and the output is y=25y=25. These are the forward values. Keep them available: the derivative of the square depends on which value we are squaring.

The diagram follows this calculation and records the local rate of each operation.

Schematic composition, with no metric encoding. Input x=1 passes through g(x)=2x+3 to intermediate u=5, then f(u)=u² gives y=25. Inner local rate is 2 at x=1; outer local rate is 10 at u=5. End-to-end derivative is 10 times 2, or 20.Schematic composition, with no metric encoding. Input x=1 passes through g(x)=2x+3 to intermediate u=5, then f(u)=u² gives y=25. Inner local rate is 2 at x=1; outer local rate is 10 at u=5. End-to-end derivative is 10 times 2, or 20.
Figure 1Schematic composition, with no metric encoding. Input x=1 passes through g(x)=2x+3 to intermediate u=5, then f(u)=u² gives y=25. Inner local rate is 2 at x=1; outer local rate is 10 at u=5. End-to-end derivative is 10 times 2, or 20.
Link to this figure ↗Download SVGDownload PNG

02Multiply the two local rates#

The first operation has rate du/dx=2du/dx=2. A small input change hh therefore changes uu by 2h2h.

The square has rate dy/du=2udy/du=2u. At the intermediate value u=5u=5, that rate is 1010. It turns the small change 2h2h into an output change of about 10(2h)=20h10(2h)=20h.

The overall rate is 2020, obtained by multiplying the inner rate by the outer rate. The numbers 22 and 1010 are rates; the forward values 55 and 2525 are different quantities.

dydx=dydududx=10⋅2=20.\begin{gathered}\frac{dy}{dx}=\frac{dy}{du}\frac{du}{dx}\\=10\cdot2=20.\end{gathered}

The derivative notation helps track what changes with respect to what. The rule is a statement about differentiable functions, not ordinary cancellation of independent numbers.

For a numerical check, increase xx from 11 to 1.011.01. Then u=5.02u=5.02 and y=25.2004y=25.2004.

Our derivative predicted an output change of 20(0.01)=0.220(0.01)=0.2, giving 25.225.2. The extra 0.00040.0004 is the quadratic term. Multiplying derivatives captures the first-order effect.

03Evaluate the outer derivative at the inner value#

For differentiable functions gg and ff, the scalar chain rule is

ddxf(g(x))=f′(g(x))g′(x).\begin{gathered}\frac{d}{dx}f(g(x))\\=f'(g(x))g'(x).\end{gathered}

A prime means derivative. The expression f′(g(x))f'(g(x)) means evaluate the derivative of ff at the value g(x)g(x). The outer function receives that intermediate value, so its derivative must be evaluated there too.

In our example, f′(u)=2uf'(u)=2u, so f′(g(1))=2(5)=10f'(g(1))=2(5)=10. Using f′(1)=2f'(1)=2 would evaluate the outer rate at an input it never received.

This distinction becomes more consequential in long computations: each operation's derivative belongs at its own forward input.

Check your reasoning

y=f(g(x))y=f(g(x)). At x=2x=2, g(2)=7g(2)=7 and g′(2)=3g\prime(2)=3. Also, f′(7)=4f\prime(7)=4 and f′(2)=5f\prime(2)=5. Find y′y\prime at this input.

Show answer and explanation
12

Use the outer rate at 77, then multiply: 4(3)=124(3)=12.

04Work through a nonlinear inner function#

Consider y=(x2+1)3y=(x^2+1)^3. Identify the inner expression u=x2+1u=x^2+1 and the outer cube y=u3y=u^3.

The inner derivative is du/dx=2xdu/dx=2x. The outer derivative is dy/du=3u2dy/du=3u^2. Substitute the inner expression into the outer derivative, then multiply:

dydx=3(x2+1)2(2x).\frac{dy}{dx}=3(x^2+1)^2(2x).

Differentiating only the outer cube would leave out the factor 2x2x. That would treat a change in xx as if it produced an equal change in uu, which is generally false.

At x=2x=2, the inner value is 55, the outer rate is 7575, and the inner rate is 44. The combined rate is 300300.

Check your reasoning

y=(2x+1)3y=(2x+1)^{3}. Find y′(x)y\prime(x).

  1. A12x2+12x+312x^{2}+12x+3
  2. B24x2+24x+624x^{2}+24x+6
  3. C3x23x^{2}
Show answer and explanation
24x2+24x+624x^{2}+24x+6

Outer rate: 3(2x+1)23(2x+1)^{2}. Inner rate: 22. Multiply them.

05Track signs and dependency paths#

For y=(2−x)2y=(2-x)^2, the inner derivative is −1-1, giving

dydx=2(2−x)(−1).\frac{dy}{dx}=2(2-x)(-1).

At x=0x=0, the derivative is −4-4. Increasing xx slightly reduces the inner value from 22, which reduces its square. Losing the negative inner rate would predict the wrong direction.

An inner derivative of zero also matters: the first-order effect through that path is zero at that point. It does not necessarily mean the entire composition is constant.

For example, the derivative of x2x^2 vanishes at x=0x=0, even though x2x^2 changes away from zero. Derivatives describe local first-order behavior.

Check your reasoning

y=f(g(x))y=f(g(x)). At x=−1x=-1, g(−1)=4g(-1)=4 and g′(−1)=−2g\prime(-1)=-2. Also, f′(4)=6f\prime(4)=6 and f′(−1)=3f\prime(-1)=3. Claim: use f′(−1)f\prime(-1). Repair y′(−1)y\prime(-1).

Show answer and explanation
-12

Use f′(4)f\prime(4): 6(−2)=−126(-2)=-12.

In a chain of several scalar operations, multiply the local rates along the dependency path. If an input affects the output through several paths, each path contributes.

The multivariable chain rule adds those path contributions. Jacobian multiplication is the matrix form of this same operation: multiply along a path, then sum over intermediate coordinates.

Key takeaway

Evaluate the outer rate at the inner output, then multiply by the inner rate.

  • Differentiate a composition of two scalar functions.

Sources & further reading

  1. [1]
    OpenStax Calculus Volume 1, 3.6: The chain rule ↗OpenStax Calculus Volume 1 · Book

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Scalar chain rule.” Math behind ML. /learn/c-chain