The chain rule differentiates a composition by multiplying the derivatives along the dependence path. It is the mathematical rule behind backpropagation through a sequence of differentiable operations.
Worked example
Consider a scalar prediction p equal to w times x and a squared loss equal to (p minus y) squared. The loss derivative with respect to p is two times (p minus y), and the prediction derivative with respect to w is x. Multiplying them gives the loss derivative with respect to w. For x equal to two, w equal to three, and y equal to five, the derivative is four.
What to check
Check the local derivatives and the points where the model uses them. Holding x and y fixed is part of this parameter derivative. A finite-difference calculation can help check a small implementation, but the step size must balance approximation error against floating-point roundoff. Near a nondifferentiable point, the interpretation needs additional care. A correct gradient calculation also depends on a correctly specified loss.
Continue with the book
Explore the full treatment, worked examples, and exercises in Mathematics for AI and Machine Learning.
Companion article for Mathematics for AI and Machine Learning, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
