Foundations to Frontier
Tests
A. Mathematical Foundations › A3 Calculus and Analysis › Multivariable calculus

The Multivariable Chain Rule

When a quantity depends on things that themselves change, the rates multiply along each path and add across paths. This one rule is backpropagation, robot hand velocity from joint speeds, implicit differentiation, and the update step of every extended Kalman filter.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

What you feel while walking

The air is warmer to the north and cooler to the east. You go for a walk. How fast does the temperature you feel change? It depends on two things: how the temperature changes from place to place, and how fast you’re moving in each direction. Multiply “degrees per km northward” by “km per hour northward”, do the same eastward, and add.

That recipe is the multivariable chain rule.

The chain rule: what you feel while walking through a field
·
z(t) = f(x(t), y(t))
∂f/∂x·x′ + ∂f/∂y·y′ = (0.909)(-0.841) + (0.292)(0.540) = -0.6074 = dz/dt (green tangent slope)
Black arrow = your velocity r′(t); orange arrow = direction of ∇f. You feel the fastest change when they line up, and none when you move along a contour (perpendicular to ∇f).
Why engineers care

A robot arm’s hand position depends on its joint angles, and the angles change over time. How fast the hand moves comes from the chain rule. Training a neural network uses the same rule, run backwards through millions of connections: that’s backpropagation.

📝 Quick check (Level 0)
0/3 answered
  1. 1. It warms 2 °C per km going north. You walk north at 3 km/h. You feel it warm at…
  2. 2. If you stand still in a field that doesn't change, the temperature you feel changes at…
  3. 3. Walking along a contour line (equal temperature), you feel…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

One parameter, two variables

If z=f(x,y)z = f(x,y) with x=x(t)x = x(t) and y=y(t)y = y(t):

dzdt=∂f∂xdxdt+∂f∂ydydt=∇f⋅r′(t)\frac{dz}{dt} = \frac{\partial f}{\partial x}\frac{dx}{dt} + \frac{\partial f}{\partial y}\frac{dy}{dt} = \nabla f\cdot\mathbf r'(t)

Example. f=x2yf = x^2y along the circle x=cos⁡tx = \cos t, y=sin⁡ty = \sin t:

dzdt=2xy⋅(−sin⁡t)+x2⋅cos⁡t\frac{dz}{dt} = 2xy\cdot(-\sin t) + x^2\cdot\cos t

At t=0t = 0, (x,y)=(1,0)(x,y) = (1,0), so dz/dt=0+1=1dz/dt = 0 + 1 = 1.

Check by direct substitution. For f=x2+y2f = x^2 + y^2, x=tx = t, y=2ty = 2t, we get z=5t2z = 5t^2 and dz/dt=10tdz/dt = 10t. The chain rule gives 2t⋅1+4t⋅2=10t2t\cdot1 + 4t\cdot2 = 10t. ✓

📝 Quick check (Level 1)
0/3 answered
  1. 1. f = xy with x = t, y = t². dz/dt at t = 1?
  2. 2. f = x² + y² along the unit circle: dz/dt = ?
  3. 3. f = 3x + 4y, x = cos t, y = sin t, at t = 0?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

The general rule

If zz depends on x1,…,xnx_1,\dots,x_n, and each xix_i depends on s1,…,sms_1,\dots,s_m:

∂z∂sj=∑i=1n∂z∂xi∂xi∂sj\frac{\partial z}{\partial s_j} = \sum_{i=1}^n\frac{\partial z}{\partial x_i}\frac{\partial x_i}{\partial s_j}

In words: multiply along each path, add over paths. Draw a tree diagram, with zz at the top, the xix_i below it, and the sjs_j at the bottom. In matrix form, the Jacobians multiply (A3.2-5):

Jf∘g(s)=Jf(g(s)) Jg(s)J_{f\circ g}(\mathbf s) = J_f(g(\mathbf s))\,J_g(\mathbf s)

Implicit differentiation

If F(x,y)=0F(x,y) = 0 defines y(x)y(x), the chain rule on F(x,y(x))=0F(x,y(x)) = 0 gives Fx+Fy y′=0F_x + F_y\,y' = 0, so

dydx=−FxFy\frac{dy}{dx} = -\frac{F_x}{F_y}

For the circle x2+y2=25x^2 + y^2 = 25 at (3,4)(3,4): −68=−0.75-\frac{6}{8} = -0.75. You never need to solve for yy.

Changing coordinates

In polar coordinates x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta: ∂θf=fx(−rsin⁡θ)+fy(rcos⁡θ)\partial_\theta f = f_x(-r\sin\theta) + f_y(r\cos\theta). For f=x2+y2=r2f = x^2 + y^2 = r^2, this gives ∂θf=0\partial_\theta f = 0 and ∂rf=2r\partial_rf = 2r, as expected.

🐍 Exercise 1: chain rule vs direct differentiation
Compute dz/dt for z = x²y along the unit circle with the chain rule, and match the numerical derivative of the composite at several times.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Implicit dy/dx for x² + y² = 25 at (3, 4)?
  2. 2. J_{f∘g} = ?
  3. 3. ∂f/∂r for f = x² + y² at r = 3?

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proof via linear approximations

If gg is differentiable at s\mathbf s and ff is differentiable at g(s)g(\mathbf s):

g(s+h)=g(s)+Jgh+o(∥h∥),f(x+k)=f(x)+Jfk+o(∥k∥)g(\mathbf s + \mathbf h) = g(\mathbf s) + J_g\mathbf h + o(\lVert\mathbf h\rVert), \qquad f(\mathbf x + \mathbf k) = f(\mathbf x) + J_f\mathbf k + o(\lVert\mathbf k\rVert)

Substitute k=Jgh+o(∥h∥)\mathbf k = J_g\mathbf h + o(\lVert\mathbf h\rVert). Since ∥k∥=O(∥h∥)\lVert\mathbf k\rVert = O(\lVert\mathbf h\rVert), the error stays o(∥h∥)o(\lVert\mathbf h\rVert), so f(g(s+h))=f(g(s))+JfJgh+o(∥h∥)f(g(\mathbf s + \mathbf h)) = f(g(\mathbf s)) + J_fJ_g\mathbf h + o(\lVert\mathbf h\rVert). ∎ Linear approximations compose by matrix multiplication.

Partial vs total derivatives

With f(x,y)=xyf(x,y) = xy and y=x2y = x^2, the partial derivative ∂f/∂x=y\partial f/\partial x = y holds yy fixed. The total derivative df/dx=y+x⋅2x=3x2df/dx = y + x\cdot2x = 3x^2 follows yy as it changes. At x=2x = 2, they are 4 and 12. Confusing the two is a classic bug in physics derivations and in hand-written gradients.

The implicit function theorem

If F(x,y)=0F(\mathbf x, y) = 0 at a point and ∂F/∂y≠0\partial F/\partial y\ne0, then near that point yy is a differentiable function of x\mathbf x, with ∇xy=−∇xF/Fy\nabla_{\mathbf x}y = -\nabla_{\mathbf x}F/F_y. The vector version needs the Jacobian ∂F/∂y\partial F/\partial\mathbf y to be invertible. This underlies constrained mechanics, robot loop-closure constraints, and implicit layers in deep learning.

Exercise 3.1: Differentiate f(x, y) = x²y with x = s + t, y = st, with respect to s

∂sf=fx⋅1+fy⋅t=2xy+x2t\partial_sf = f_x\cdot1 + f_y\cdot t = 2xy + x^2t. At s=t=1s = t = 1: x=2x = 2, y=1y = 1, so the result is 4+4=84 + 4 = 8.

📝 Quick check (Level 3)
0/3 answered
  1. 1. f = xy, y = x². df/dx at x = 2?
  2. 2. The implicit function theorem needs…
  3. 3. Linear approximations compose by…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Backpropagation = the chain rule, done backwards

A network is a composition L=ℓ(fK(⋯f1(x)))L = \ell(f_K(\cdots f_1(\mathbf x))). The chain rule gives ∂L∂hk−1=Jfk⊤∂L∂hk\frac{\partial L}{\partial\mathbf h_{k-1}} = J_{f_k}^\top\frac{\partial L}{\partial\mathbf h_k}. Starting from the scalar loss and moving backwards, each layer turns an incoming gradient into gradients for its parameters and its input. One backward pass costs about the same as a forward pass, and gives every derivative (Linnainmaa, 1970; Werbos, 1974; Rumelhart, Hinton and Williams, 1986). A3.3 builds this systematically.

🐍 Exercise 2 (research): backprop a 2-layer network by hand
For y = W₂ tanh(W₁x + b₁) + b₂ with loss ½‖y − t‖², derive all four gradients with the chain rule. Gradient-check every one of the 26 parameters against finite differences.

The chain rule in robotics and estimation

  • Differential kinematics. For hand position p=fk(θ(t))\mathbf p = \mathrm{fk}(\boldsymbol\theta(t)), the hand velocity is p˙=J(θ)θ˙\dot{\mathbf p} = J(\boldsymbol\theta)\dot{\boldsymbol\theta} (Practice Code 5). Inverting this relation gives resolved-rate control (Whitney, 1969).
  • Extended Kalman filter. A measurement h(x)h(\mathbf x) of a moving state changes at ddth=Hx˙\frac{d}{dt}h = H\dot{\mathbf x}, with H=∂h/∂xH = \partial h/\partial\mathbf x. Linearizing dynamics and measurements is the chain rule applied over and over.
  • Implicit layers and differentiable optimization. If a layer’s output solves F(z,x)=0F(\mathbf z,\mathbf x) = 0 (a fixed point, an optimization or an equilibrium), the implicit function theorem gives ∂z/∂x=−(∂F/∂z)−1∂F/∂x\partial\mathbf z/\partial\mathbf x = -(\partial F/\partial\mathbf z)^{-1}\partial F/\partial\mathbf x without unrolling the solver. Examples are OptNet (Amos and Kolter, 2017), deep equilibrium models (Bai, Kolter and Koltun, 2019), and differentiable MPC for robot control (Amos et al., 2018).

References

  1. S. Linnainmaa (1970). MSc thesis, University of Helsinki. (Reverse-mode automatic differentiation.)
  2. P. Werbos (1974). Beyond Regression: New Tools for Prediction and Analysis in the Behavioral Sciences. PhD thesis, Harvard.
  3. D. Whitney (1969). “Resolved motion rate control of manipulators and human prostheses.” IEEE Transactions on Man-Machine Systems, 10(2).
  4. D. Rumelhart, G. Hinton, R. Williams (1986). “Learning representations by back-propagating errors.” Nature, 323.
  5. B. Amos, J. Z. Kolter (2017). “OptNet: Differentiable optimization as a layer in neural networks.” ICML.
  6. B. Amos, I. Jimenez, J. Sacks, B. Boots, J. Z. Kolter (2018). “Differentiable MPC for end-to-end planning and control.” NeurIPS.
  7. S. Bai, J. Z. Kolter, V. Koltun (2019). “Deep equilibrium models.” NeurIPS.
  8. J. Nocedal, S. Wright (2006). Numerical Optimization, 2nd ed. Springer. Appendix A.