Home / Calculus

The Chain Rule

When one function feeds another, their slopes multiply. Nudge the input and watch the change travel down the chain — this is backpropagation, stripped to its essentials.

Controls

input x1.0

The chain diagram above the plot shows each link's local derivative. Their product is the total.

Composed Function y = f(g(x))

tangent shows the total slope

Live Calculation

du/dx
0
dy/du
0
dy/dx (product)
0
numeric check
0

The Chain

The Chain Rule

Derivatives of nested functions multiply — and that fact is the entire mechanism of backpropagation.

Quick Context

When a function feeds into another — y = f(g(x)) — a change in x must travel through both to reach y. The chain rule says the sensitivities simply multiply.

dy/dx = (dy/du) × (du/dx)

The Gear Analogy

Picture two gears. Turning the first makes the second turn 3× as fast; that second gear drives a third at 2×. Turn the first gear once and the last one spins 6 times — the ratios multiplied.

Derivatives are exactly these ratios: how much does the output move per unit of input? Press Nudge x and watch a small change in x produce a change in u, which produces a change in y — each link scaling the one before.

Reading the Diagram

The chain strip shows x → u → y with each link's local derivative underneath. The app also computes a numeric check — the slope measured by actually nudging x by a tiny amount — and it always matches the product. The rule is not an approximation.

This Is Backpropagation

A neural network is a deep composition: input → layer 1 → layer 2 → … → loss. To learn, you need the derivative of the loss with respect to a weight buried near the start. The chain rule provides it by multiplying every local derivative along the path:

∂L/∂w₁ = (∂L/∂a₃)(∂a₃/∂a₂)(∂a₂/∂a₁)(∂a₁/∂w₁)

Backpropagation is nothing more than this product, computed efficiently from the output backwards so shared terms are reused.

Why Deep Networks Struggle

Multiplying many numbers together is unstable. If each local derivative is less than 1, the product shrinks toward zero — the vanishing gradient. If each is greater than 1, it explodes.

Choose the sigmoid outer function and slide x outwards. Its derivative never exceeds 0.25, so stacking ten sigmoid layers scales the gradient by at most 0.25¹⁰ ≈ 0.00000095. That is precisely why ReLU replaced sigmoid in deep networks, and why LSTMs added a gated path that avoids repeated multiplication.

Interactive Exploration Guide

  1. Start with g = 2x+1, f = u². The product of local slopes matches the numeric check exactly.
  2. Press Nudge. Watch a small Δx become a larger Δu and then a larger Δy — magnification compounding through the chain.
  3. Set the inner function to sin(x) and slide to where its slope is zero. The total derivative collapses to zero too — one flat link kills the whole chain, however steep the others are.
  4. Switch the outer to sigmoid and push x to ±3. dy/du shrinks toward nothing: the saturation that stalls deep networks.

Key Takeaway

Nested functions multiply their slopes. That gives you the derivative of arbitrarily deep compositions — and because multiplication compounds, it also explains why gradients vanish or explode in deep networks.

Cheat sheet

The Chain Rule

When one function feeds another, their slopes multiply. Nudge the input and watch the change travel down the chain — this is backpropagation, stripped to its essentials.

MATHS · vizlearn.in/maths/the_chain_rule.html