Basis Lab

Answers · The mathematics underneath

Why do derivatives multiply along a chain but add when the path splits?

In shortAlong a chain each step scales the effect that arrived, so the scalings multiply; at a split each use contributes its own effect to the same change, so the contributions add.

Derivatives multiply along a chain because each operation scales the same small disturbance in turn, and successive scalings compose by multiplication. They add across a split because a small change at the shared value reaches the end by several separate routes, and the total effect is the sum of those routes' effects.

Along a chain

Let xx feed bb, let bb feed cc, and let cc feed the loss LL. A small change dxdx first changes bb by (∂b/∂x)dx(\partial b/\partial x)dx. The second operation sees that change in bb and scales it again, producing dc=(∂c/∂b)db=(∂c/∂b)(∂b/∂x)dxdc = (\partial c/\partial b)db = (\partial c/\partial b)(\partial b/\partial x)dx. The final operation scales once more, so dL=(∂L/∂c)dc=(∂L/∂c)(∂c/∂b)(∂b/∂x)dxdL = (\partial L/\partial c)dc = (\partial L/\partial c)(\partial c/\partial b)(\partial b/\partial x)dx. Divide by dxdx and the three local factors multiply. Each factor is local: it knows only its own operation, not the rest of the graph.

∂L∂x=∂L∂c⋅∂c∂b⋅∂b∂x\frac{\partial L}{\partial x} = \frac{\partial L}{\partial c} \cdot \frac{\partial c}{\partial b} \cdot \frac{\partial b}{\partial x}

Take local factors 0.40.4 at cc, 2.02.0 at bb, and 0.250.25 at xx. Start at the loss with derivative 11. The third operation leaves 1×0.4=0.41 \times 0.4 = 0.4; the second leaves 0.4×2.0=0.80.4 \times 2.0 = 0.8; the first leaves 0.8×0.25=0.20.8 \times 0.25 = 0.2. The same product is 0.4×2.0×0.25=0.20.4 \times 2.0 \times 0.25 = 0.2. A factor below one shrinks the signal, a factor above one magnifies it, and both happen in the same chain. The product can become very small or very large simply because many factors are multiplied; that is arithmetic, not a separate failure mode.

Where the path splits

Let aa be used by two operations, one producing pp and one producing qq, and let both pp and qq affect LL. A small dada changes pp by (∂p/∂a)da(\partial p/\partial a)da and qq by (∂q/∂a)da(\partial q/\partial a)da. The effect on LL through pp is (∂L/∂p)(∂p/∂a)da(\partial L/\partial p)(\partial p/\partial a)da; the effect through qq is (∂L/∂q)(∂q/∂a)da(\partial L/\partial q)(\partial q/\partial a)da. Because these are two first-order changes to the same LL, their sum is the first-order change in LL. Divide by dada and the two terms add.

∂L∂a=∂L∂p⋅∂p∂a+∂L∂q⋅∂q∂a\frac{\partial L}{\partial a} = \frac{\partial L}{\partial p} \cdot \frac{\partial p}{\partial a} + \frac{\partial L}{\partial q} \cdot \frac{\partial q}{\partial a}

With ∂L/∂p=3\partial L/\partial p = 3 and ∂p/∂a=0.5\partial p/\partial a = 0.5, the first route contributes 3×0.5=1.53 \times 0.5 = 1.5. With ∂L/∂q=2\partial L/\partial q = 2 and ∂q/∂a=0.25\partial q/\partial a = 0.25, the second route contributes 2×0.25=0.52 \times 0.25 = 0.5. The total is 1.5+0.5=2.01.5 + 0.5 = 2.0. If the second term is omitted, the derivative is 1.51.5, too small by 0.50.5.

FIG 1One value, two uses
A change at a reaches L by two separate routes; neither route replaces the other.

The add rule is also why sharing a parameter does not make its derivative smaller. If the same weight is used in several places, each use contributes a term; the gradient is the total of those terms. It is the forward value that was shared, not the derivative. The derivative is accumulated, not divided.

The natural guess is that a split should force a choice: take the largest path, average the paths, or follow one route. That fails because the derivative is a linear approximation. For the same infinitesimal dada, both uses change, and neither is selected. The two effects are separate first-order terms, so they add. Multiplication along a chain is not a different rule; it is the same linear approximation applied twice, where the output of one scaling becomes the input of the next. A common hand-written error is to miss a branch term. No error is raised; the gradient is simply too small in that direction.

Where it stops

This is first-order calculus. If the functions are not differentiable, or a branch is a hard switch that does not respond locally, its term is zero rather than a small contribution; for a maximum, the inactive side contributes nothing locally. For a finite change rather than an infinitesimal one, cross terms and curvature appear and the simple sum of first derivatives is no longer exact. It is exact in the limit of small changes, which is the sense in which a derivative is a coefficient.

Worth keeping

  • Along a chain, the derivative is a product because each operation scales the change that arrives before passing it on.
  • At a branch, the derivative is a sum because the same change travels through each use separately and all those effects count.
  • Missing one branch term does not raise an error; it silently makes the gradient too small in that direction.

Where this goes next

This question is one step of Backpropagation in Full, a course that works through its subject from the beginning. The page that teaches this part of it is Composing Derivatives, and it reads the whole way through whether or not you have an account.

What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.

Read that pageThe whole course

Other questions people ask about this

  1. Why does backpropagation never build the full Jacobian?Backpropagation only needs a vector multiplied by each layer's derivative matrix, so it computes that product directly and never builds the matrix.
  2. Why does softmax followed by cross entropy have gradient p minus y?Because the derivative of the loss through softmax simplifies to the predicted probability minus the target, one number per class, with the exponentials and fractions cancelling out.
  3. What does a computation graph actually let you differentiate?It lets you differentiate a final number with respect to any earlier value in the graph by multiplying local derivatives along each route and adding across routes.
  4. Why does adding a shortcut connection stop gradients from vanishing?A shortcut gives the gradient a route whose factor is one plus the layer's own factor, so many layers in series no longer multiply the signal down to nothing.
  5. What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
  6. How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.

Read alongside