The Chain Rule and Computational Graphs

The chain rule computes the derivative of a composition of functions by multiplying the derivatives of the constituent functions. In words: to differentiate , multiply the rate of change of (at ) by the rate of change of (at ). It applies everywhere derivatives appear — single-variable calculus, multivariable analysis, differential geometry, and modern machine learning (where its computational-graph form is called backpropagation). First systematized by Leibniz (1676) via differential notation; the computational-graph perspective matured with reverse-mode automatic differentiation in the 1970s–80s.

The chain rule states that if and are differentiable, then the composite is differentiable with derivative . It matters because almost every function encountered in practice is a composition of simpler primitives, and differentiation must respect that structure. A computational graph is a directed acyclic graph (DAG) representing such a composition node-by-node, turning the chain rule into a mechanical bookkeeping procedure over edges. The surprising fact: when a scalar output depends on many inputs, reverse-mode application of the chain rule computes all partial derivatives in a single backward pass costing roughly the same as one forward evaluation — the algorithmic heart of training neural networks with billions of parameters.

The Core Insight

A composition is a pipeline: . The chain rule says the overall sensitivity is the product of local sensitivities along the pipeline. On a graph with branches and merges, "product along a path" generalizes to "sum over all paths, each path being a product of edge derivatives." Reverse-mode differentiation is just an efficient order of summation that reuses shared subexpressions.

Formal Statement

Composite Function

Given functions and with , the composite is defined by . We call the inner function and the outer function. The intermediate value is the node variable connecting them.

Chain Rule — Single Variable

Let be differentiable at and let be differentiable at . Then is differentiable at and

1
⟳Differentiate at the point , then multiply by the inner rate ; see the proof below using the error-form of differentiability.

In Leibniz notation, with , :

2
⟳Treat and as ratios of differentials; the cancellation of is suggestive but must be justified by the limit argument in the proof.

Chain Rule — Multivariable

Let be differentiable at and differentiable at . Then the Jacobian of the composite is the matrix product of the Jacobians:

3
⟳Apply the linear-approximation definition of total differentiability to both maps; the composite's best linear approximation is the composition of the linear approximations, whose matrix is the product.

Componentwise, for a scalar where each :

4
⟳Expand the matrix product in for a single output row and single input column; the sum runs over the shared intermediate variables — this is the "sum over paths through the layer."

Computational Graph

A computational graph for an expression is a directed acyclic graph where each vertex holds a variable computed by an elementary operation of its parent vertices : . Source vertices are inputs; a designated sink is the output. Each edge carries the local partial derivative , evaluated at the current values. The full derivative of the output with respect to an input is obtained by applying the chain rule across the graph.

Computational graph for $y = \sin(x_1 x_2) + x_1$ with edge-local derivatives; backward pass accumulates $\partial y/\partial x_i$ by summing over paths.

x₁ x₂ u=x₁x₂ v=sin u y=v+x₁ ∂u/∂x₁=x₂ ∂u/∂x₂=x₁ ∂v/∂u=cos u ∂y/∂v=1 ∂y/∂x₁ = 1 (direct path)

Why It Holds / Derivation

proof[Single-Variable Chain Rule via the Error Form] Step 1 — Differentiability as linear approximation with controlled error. Because is differentiable at , there is a function with such that for all small :

5
⟳Define for and ; differentiability forces .

Step 2 — Set the inner increment. Let be a small increment in , and define . By differentiability of , as . Step 3 — Substitute. Then
6
⟳Replace by in ; this remains valid even when because the right side then vanishes too.
Step 4 — Divide by and take the limit.
7
⟳As : (since ), and the difference quotient of tends to ; multiply the limits.

Taking gives .

Why the naïve "cancel $du$" proof fails

The seductive argument followed by taking limits breaks when for some sequence of (e.g. locally constant or oscillating). Division by is then illegal. The error-form proof above avoids any division by , which is exactly why it is the correct argument.

Gottfried Wilhelm Leibniz | 1646–1716

Leibniz, co-inventor of calculus, gave us the differential notation in which the chain rule appears as the almost-tautological cancellation . His manuscripts from November 1676 already manipulate composite differentials. While the notation makes the rule memorable, it obscures the subtlety (see the warning above) — a gap rigorously closed only with the 19th-century – definition of the limit by Cauchy and Weierstrass. Leibniz's deeper gift was the operational viewpoint: differentiation as a symbolic process that propagates along the structure of an expression — the conceptual seed of computational graphs three centuries later.

Building Intuition

Think of nested gears. If gear drives gear at ratio (B turns 3× as fast), and drives at ratio , then drives at — ratios multiply. The derivative is the local gear ratio from to ; is the ratio from to ; the composite ratio is their product.

Now add branching. If influences through two independent gear trains (paths), the total effect is the sum of the two products — small pushes from each route add up. That is exactly : sum over paths, multiply along each. The computational graph is the literal gear diagram, and backpropagation is the disciplined way to total up all the ratios without recomputing shared gears.

Worked Examples

Single-Variable: a nested trig–power function

Given: . Find at . Step 1 — Identify the layers. Outer: . Middle: . Inner: . Three nested functions. Step 2 — Local derivatives.
Step 3 — Multiply (chain rule for a 3-chain).
8
⟳Apply twice: ; substitute , .
Step 4 — Evaluate at . Here , so , .

The zero makes sense: at , is at its maximum, so momentarily stops changing.

Multivariable / Graph: reverse-mode pass

Given: at . Compute and by a forward pass then a backward pass. Forward pass (compute node values).
Backward pass (seed , propagate adjoints).
9
⟳Each adjoint ; multiply the downstream adjoint by the local edge derivative.
Accumulate to inputs (sum over all incoming paths).
10
⟳ reaches by two paths — through and directly via the term; tells us to add them.
11
⟳ reaches only through ; one path, so a single product.

Note: a single backward pass produced both partials — the efficiency that powers backpropagation.

Common Misconceptions

Three classic errors

  1. Evaluating the outer derivative at instead of at . must be evaluated at , not . Writing is wrong; it is .
  2. Forgetting the inner derivative entirely. . The factor is mandatory.
  3. Treating as a genuine fraction. It is notation for a limit. The cancellation works as a mnemonic but is not a proof, and it fails to generalize cleanly to partial derivatives, where in general.

A composite that is differentiable while neither factor's quotient is "tame"

Let for , . Then is differentiable at with , but oscillates wildly near and equals infinitely often as . With (so ), the naïve "divide by " proof is invalid on those sequences — yet the chain rule still holds because the error-form proof (–) never divides by . This is the canonical example showing why rigor matters.

Connections

The chain rule is the connective tissue of differential calculus. It powers Implicit Differentiation (differentiate and solve for ), Related Rates (link to through ), and The Substitution Rule for Integration (which is the chain rule read backwards). In several variables it underlies the Gradient and Directional Derivative and the Jacobian Matrix. Its graph form is precisely Backpropagation in neural networks, and the abstract version — composition of linear approximations — is the statement of the Total Derivative in Differential Geometry (the functoriality of the tangent map: ).

Real-World Applications

  1. Deep learning (backpropagation). Training networks like GPT or ResNet computes gradients of a scalar loss over billions of parameters via reverse-mode chain rule on the computational graph — one forward + one backward pass.
  2. Automatic differentiation libraries. PyTorch's autograd, TensorFlow, and JAX build computational graphs and apply the chain rule mechanically; JAX's grad/jvp/vjp expose forward- and reverse-mode directly.
  3. Sensitivity analysis in engineering. Adjoint methods (reverse-mode chain rule) compute how a single performance metric depends on thousands of design variables in aircraft wing and turbine optimization.
  4. Computational fluid dynamics & weather. Adjoint models in data assimilation (e.g. ECMWF's 4D-Var) propagate sensitivities backward through time-stepping graphs to fit initial conditions.
  5. Computer graphics & differentiable rendering. Gradients of rendered images w.r.t. scene parameters flow through the rendering pipeline by the chain rule, enabling inverse rendering and neural radiance fields (NeRF).
  6. Economics & finance. Greeks (option sensitivities like delta, vega) are chain-rule derivatives of a price functional; adjoint algorithmic differentiation accelerates risk computation across portfolios.
  7. Physics — Lagrangian/Hamiltonian mechanics. Coordinate changes transform equations of motion via the multivariable chain rule (Jacobians of the transformation).

Historical Development

  • 1676 — Leibniz manipulates composite differentials in unpublished manuscripts, foreshadowing .
  • 1684 — Leibniz publishes his first calculus paper (Nova Methodus), establishing differential notation that encodes the chain rule.
  • 1690s — The Bernoullis and L'Hôpital apply chain-rule reasoning to curves and nested expressions across Europe.
  • 1820s — Cauchy's Cours d'analyse (1821) introduces limit-based rigor; the chain rule gets its first careful, if still informal, treatment.
  • 1860s–1870s — Weierstrass's – framework enables the modern error-form proof, closing the "divide by " gap.
  • 1870s — The multivariable / Jacobian chain rule is formalized in the work of Jacobi's successors on transformations and partial differentiation.
  • 1964 — Wengert publishes a method for the automatic evaluation of derivatives — an early forward-mode automatic differentiation.
  • 1970 — Seppo Linnainmaa describes the reverse-mode accumulation of derivatives (the algorithmic chain rule on a graph) in his master's thesis.
  • 1986 — Rumelhart, Hinton & Williams popularize backpropagation for neural networks, igniting modern deep learning.

Subtleties & Limits

Boundaries of the rule

The chain rule requires differentiability; at points where the inner or outer function is merely continuous (e.g. at ), the composite may fail to be differentiable or require subgradients — leading to the calculus of Clarke subdifferentials and questions about which "nonsmooth chain rules" hold for compositions like networks, where backpropagation is used in practice despite kink points. A related modern theme is numerical stability: repeated multiplication of edge derivatives causes vanishing or exploding gradients in deep graphs; understanding when the product of many Jacobians stays well-conditioned (via residual connections, normalization, orthogonal initialization) remains an active research area. Finally, in infinite-dimensional and stochastic settings, generalizations (Fréchet-derivative chain rule, Itô's formula as a "stochastic chain rule" with an extra second-order term) show that the simple product law is only the smooth, deterministic special case of a richer family of composition rules.

See Also

Product Rule · Quotient Rule · Jacobian Matrix · Gradient and Directional Derivative · Backpropagation · Automatic Differentiation · Faà di Bruno's Formula · Itô's Lemma · Total Derivative

Before this

Where this leads