Chain Rule

Calculus & Advanced Math

The chain rule differentiates composite functions by multiplying the derivative of the outer function by the derivative of the inner function.

Formula

\frac{d}{dx}[f(g(x))] = f'(g(x)) \cdot g'(x)

Definition

The chain rule handles functions inside other functions: differentiate the outside function first (leaving the inside alone), then multiply by the derivative of the inside. If $y = f(u)$ and $u = g(x)$, then $dy/dx = (dy/du)(du/dx) = f'(g(x)) \cdot g'(x)$, and this "cancellation" of $du$ in Leibniz notation makes the rule intuitive to apply. More generally, for $f: \mathbb{R}^m \to \mathbb{R}^k$ and $g: \mathbb{R}^n \to \mathbb{R}^m$, $D(f \circ g)(x) = Df(g(x)) \cdot Dg(x)$, where $D$ denotes the Jacobian matrix, reducing to the scalar rule when $m = n = k = 1$.

Example

For $d/dx[\sin(x^2)]$: the outside is $\sin(\ )$, giving $\cos(x^2)$, times the derivative of the inside $x^2$, which is $2x$, so the answer is $2x\cos(x^2)$. For $f(x) = (3x^2 + 1)^5$, let $u = 3x^2 + 1$; then $dy/dx = 5u^4 \cdot 6x = 30x(3x^2 + 1)^4$. Backpropagation in neural networks is a direct application of the multivariable chain rule, computing gradients layer by layer from output to input.

Key Insight

Think of it as a chain: the outer layer changes, so you must also account for how fast the inner layer is changing, and almost every non-trivial derivative requires this rule, so recognizing the "inside" and "outside" functions is the key skill. The chain rule is the computational heart of automatic differentiation and reverse-mode autodiff used in deep learning, making it one of the most practically powerful theorems in applied mathematics.