The chain rule, gradients, and Jacobians
Compose local linear maps in the correct order and distinguish gradients from general derivatives.
On this page
The question for today
What you’ll understand
- Compose Jacobians with compatible dimensions and evaluation points.
- Recover directional derivatives from the Euclidean gradient.
- Pull an output sensitivity backward using a transposed Jacobian.
A measurement pipeline rarely maps inputs directly to the final quantity of interest. Coordinates become features, features become predictions, and predictions become a scalar objective. The chain rule links these stages without expanding the entire formula. Its essential operation is composition of local linear maps. Matrix multiplication is simply the coordinate form of that composition, and its order, dimensions, and evaluation points carry mathematical meaning rather than being bookkeeping conventions.
Compose the local maps in the order of the computation
Suppose g maps an open subset of n-space to m-space and is differentiable at a. Suppose f is defined on a neighborhood of g(a) and is differentiable there. A small input displacement first becomes Dg(a)h, then becomes Df(g(a))Dg(a)h. The neglected terms remain smaller than the original displacement because the first derivative is a bounded linear map and differentiability also gives continuity. This reasoning proves the chain rule without assuming that all second derivatives exist.
With column vectors, the Jacobian of g has m rows and n columns; the Jacobian of f has as many columns as g has output coordinates. Their product therefore has the expected final-output by initial-input shape. The outer derivative must be evaluated at the intermediate value g(a), not at the original point a unless those happen to coincide. A dimension check detects many errors before any arithmetic begins. Reversing the product generally describes a different operation or produces no defined matrix multiplication.
A gradient represents a scalar derivative using a metric
For a differentiable scalar function f, its derivative is naturally a linear functional: it accepts a displacement and returns a first-order output change. In Euclidean coordinates, the gradient is the unique column vector whose dot product with that displacement equals the derivative. For a unit vector u, the directional derivative is therefore the dot product of the gradient and u. The Cauchy–Schwarz inequality shows that the largest directional derivative is the gradient norm, attained in the gradient direction when that norm is nonzero.
A zero gradient makes every first-order directional derivative zero, but does not determine whether a point is a minimum, maximum, or saddle. Also, changing coordinates can alter what counts as a unit displacement. The familiar gradient formula uses the Euclidean inner product in the chosen coordinates; on a space with another metric, the same derivative functional is represented by a different gradient vector. Keeping the functional and its vector representation conceptually separate becomes essential when working with constrained coordinates or curved spaces.
Sensitivities can move backward without reversing the model
Forward differentiation propagates an input perturbation through each Jacobian. Backward sensitivity propagation starts with a scalar objective's output covector and applies transposed Jacobians in reverse stage order. Both compute the same chain rule. The backward calculation is especially economical when there are many input coordinates but only one scalar objective. It does not invert the forward map and does not require the Jacobians to be square or nonsingular. Multiplication by a transpose is an adjoint action, not generally an inverse action.
For a time-dependent path r(t), the chain rule gives the rate of f along the path as the gradient dotted with velocity. This separates spatial sensitivity from actual motion. A large gradient need not produce a large observed rate if the path follows a level set; then the velocity is perpendicular to the gradient. Conversely, a non-unit velocity scales the rate with speed. Before calling a computed quantity a directional derivative, check whether the direction was normalized or whether the intended object was a derivative with respect to time.
Work it through
A two-coordinate feature map
Let g(s,t)=(s²+t,st) and f(u,v)=u²+3v. Compute the gradient of f∘g at (1,2), then its derivative in the unit direction (3/5,4/5).
At (1,2), the intermediate coordinates are (u,v)=(3,2), so the outer gradient is (2u,3)=(6,3).
The Jacobian of g at (1,2) has rows (2,1) and (2,1). Multiplying its transpose by (6,3) gives the input gradient (18,9).
Dotting that gradient with the specified unit direction gives 18·3/5+9·4/5=18. Expanding (s²+t)²+3st and differentiating directly gives the same gradient.
The gradient is (18,9), and the directional derivative is 18. The singular intermediate Jacobian does not invalidate the chain rule.
The living notebook
Explore the model
Interactive lab · network
Inspect a chain rule through one nonlinear gate
Reset, set input x=1 and weight w=2. Predict z=1.5 and output σ(z)≈0.818 before reading the sigmoid instrument. Its input derivative is wσ(z)(1−σ(z))≈0.298; verify that calculation using the displayed output. The model contains one sigmoid gate with fixed bias −0.5, not a trainable multilayer network.
- Product · wx
- 1.2
- Logit · wx − 0.5
- 0.7
- Sigmoid output
- 0.6682
One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA nonlinear pipeline's local sensitivity is a product of local derivatives, evaluated at the actual intermediate values.
Pause & reason
Check your understanding
Your turn
Try it yourself
For f(x,y)=x²+2y² and r(t)=(cos t,sin t), find the rate of f(r(t)) at t=π/4 and explain why it is not the gradient norm there.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute the velocity r′(t), then take its dot product with the gradient evaluated on the path.
Compare with the solution
At t=π/4, the gradient is (√2,2√2) and velocity is (−1/√2,1/√2), giving rate −1+2=1. Directly, f(r(t))=1+sin²t has derivative sin(2t), also 1 there. The gradient norm is √10, which is the largest derivative over all unit directions. The path has unit speed but its tangent is not the maximizing gradient direction, so its rate is smaller.
Keep the idea
Take it with you
- Jacobian dimensions and intermediate evaluation points are part of the chain rule.
- The Euclidean gradient represents a scalar derivative through a dot product.
- Transposed Jacobians propagate sensitivities without inverting the forward computation.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.