Skip to content
Glacius
CalculusConcept reference

Multivariable chain rule

For differentiable vector maps in output-row convention, the composition Jacobian is the outer Jacobian at the inner output times the inner Jacobian at the original input.

On this page 10 sections
  1. Overview
  2. Follow a concrete composition
  3. Build each Jacobian where its function operates
  4. Compose the local maps in order
  5. Check the result and the evaluation point
  6. Check dimensions and account for every path
  7. Key takeaway
  8. Further questions
  9. Sources & further reading
  10. Concept connections

01Follow a concrete composition#

A change in one input can reach an output through several intermediate coordinates. The multivariable chain rule accounts for all those paths. We will first follow actual values, then calculate the two local derivative maps.

Let the first function be G(x,y)=(x+y,xy)G(x,y)=(x+y,xy). It adds and multiplies the original inputs. Let the second be F(u,v)=(u2,u+v)F(u,v)=(u^2,u+v). It squares the first intermediate coordinate and adds the two.

Start at p=(2,1)p=(2,1). Here pp is simply a name for the input point. Apply GG to get the intermediate point qq:

q=G(p)=(3,2).q=G(p)=(3,2).

Then apply FF to those coordinates: F(q)=(9,5)F(q)=(9,5). The notation F∘GF\circ G means this composition: GG first, then FF.

Start with input p = (2, 1). G adds and multiplies the inputs, producing the intermediate point q = (3, 2). F squares the first intermediate coordinate and adds both, producing (9, 5). These boxes show forward values; Jacobians describe changes around them. Position indicates computation order, not a numerical axis.Start with input p = (2, 1). G adds and multiplies the inputs, producing the intermediate point q = (3, 2). F squares the first intermediate coordinate and adds both, producing (9, 5). These boxes show forward values; Jacobians describe changes around them. Position indicates computation order, not a numerical axis.
Figure 1Start with input p = (2, 1). G adds and multiplies the inputs, producing the intermediate point q = (3, 2). F squares the first intermediate coordinate and adds both, producing (9, 5). These boxes show forward values; Jacobians describe changes around them. Position indicates computation order, not a numerical axis.
Link to this figure ↗Download SVGDownload PNG

02Build each Jacobian where its function operates#

The diagram shows values, not derivatives. To describe small changes around them, build one Jacobian for each function. We use output rows and input columns.

For G(x,y)=(x+y,xy)G(x,y)=(x+y,xy), the two rows are (1,1)(1,1) and (y,x)(y,x). At the original point p=(2,1)p=(2,1):

JG(p)=(1112).J_G(p)=\begin{pmatrix}1&1\\1&2\end{pmatrix}.

Read JG(p)J_G(p) as “the Jacobian of GG, evaluated at pp.” The subscript GG names the function. The parentheses identify the point where its partial derivatives are evaluated. Neither symbol denotes an extra multiplication.

This matrix turns a small change in (x,y)(x,y) into a first-order change in (u,v)(u,v) near pp.

For F(u,v)=(u2,u+v)F(u,v)=(u^2,u+v), the first row of derivatives is (2u,0)(2u,0) and the second is (1,1)(1,1). This function received q=(3,2)q=(3,2), so its Jacobian is

JF(q)=(6011).J_F(q)=\begin{pmatrix}6&0\\1&1\end{pmatrix}.

The six comes from 2u2u at u=3u=3. The zero records that u2u^2 has no dependence on vv.

You will often see JF(G(p))J_F(G(p)) instead of JF(q)J_F(q). They mean exactly the same thing because q=G(p)q=G(p).

Evaluating the outer derivative at the original p=(2,1)p=(2,1) would put 44 in its first entry instead of 66. That is the derivative at an input the outer function did not receive.

03Compose the local maps in order#

Write A=JG(p)A=J_G(p) and B=JF(q)B=J_F(q) for a moment. A small original input change Δp\Delta p first becomes approximately AΔpA\Delta p. The next map turns that into B(AΔp)B(A\Delta p).

That is why the combined Jacobian is BABA: the rightmost matrix acts first. In full notation, for differentiable maps,

JF∘G(p)=JF(G(p))JG(p)\begin{gathered}J_{F\circ G}(p)\\=J_F(G(p))J_G(p)\end{gathered}

Multiply the outer Jacobian by the inner one:

(6011)(1112)=(6623).\begin{gathered}\begin{pmatrix}6&0\\1&1\end{pmatrix}\begin{pmatrix}1&1\\1&2\end{pmatrix}\\=\begin{pmatrix}6&6\\2&3\end{pmatrix}.\end{gathered}

The first row comes from 6⋅1+0⋅1=66\cdot1+0\cdot1=6 and 6⋅1+0⋅2=66\cdot1+0\cdot2=6. The second comes from 1⋅1+1⋅1=21\cdot1+1\cdot1=2 and 1⋅1+1⋅2=31\cdot1+1\cdot2=3. Each entry adds contributions through both intermediate coordinates.

Check your reasoning

JG(p)J_G(p) rows: (1,0);(2,1)(1,0);(2,1). JF(G(p))J_F(G(p)) rows: (3,0);(0,2)(3,0);(0,2). Return the ordered rows of JF∘G(p)J_{F\circ G}(p).

  1. A(3,0);(4,2)(3,0);(4,2)
  2. B(3,0);(6,2)(3,0);(6,2)
  3. C(3,0);(0,2)(3,0);(0,2)
Show answer and explanation
(3,0);(4,2)(3,0);(4,2)

(2,1)(2,1): 0+4=40+4=4.

04Check the result and the evaluation point#

We can verify the composition without using the matrix rule. Substitute GG directly into FF:

H1(x,y)=(x+y)2H2(x,y)=x+y+xy.\begin{gathered}H_1(x,y)=(x+y)^2\\H_2(x,y)=x+y+xy.\end{gathered}

The first output has partial derivatives 2(x+y)2(x+y) and 2(x+y)2(x+y). The second has partial derivatives 1+y1+y and 1+x1+x. At (2,1)(2,1), these give the same rows (6,6)(6,6) and (2,3)(2,3).

The original and intermediate points are both pairs, so either would fit into the outer formulas. Their equal dimensions do not make them interchangeable.

For a nonlinear outer function, moving its evaluation point can change the derivative. Always compute the forward intermediate values before substituting into the local Jacobians.

Check your reasoning

G(x,y)=(x+y,y)G(x,y)=(x+y,y), F(u,v)=(u2,v)F(u,v)=(u^2,v). At p=(1,2)p=(1,2), give JF∘G(p)J_{F\circ G}(p) as ordered rows.

  1. A(2,2);(0,1)(2,2);(0,1)
  2. B(6,6);(0,1)(6,6);(0,1)
  3. C(6,1);(0,1)(6,1);(0,1)
Show answer and explanation
(6,6);(0,1)(6,6);(0,1)

Outer entry: 2(3)=62(3)=6.

05Check dimensions and account for every path#

Reversing our two square matrices is possible arithmetically, but gives the wrong map:

(1112)(6011)=(7182).\begin{gathered}\begin{pmatrix}1&1\\1&2\end{pmatrix}\begin{pmatrix}6&0\\1&1\end{pmatrix}\\=\begin{pmatrix}7&1\\8&2\end{pmatrix}.\end{gathered}

Matching dimensions alone cannot establish the order. Follow the input change: inner derivative first, outer derivative second.

Rectangular maps make the dimensions more visible. If GG takes 2 inputs to 3 outputs, its Jacobian is 3×23\times2. If FF takes those 3 coordinates to 2 outputs, its Jacobian is 2×32\times3.

The product has shape (2×3)(3×2)=2×2(2\times3)(3\times2)=2\times2, matching two original inputs and two final outputs. Reversing these factors instead describes a 3×33\times3 array, the wrong shape for this composition.

Check your reasoning

JG(p)J_G(p) rows: (1,2);(0,1)(1,2);(0,1). JF(G(p))J_F(G(p)) rows: (2,0);(1,1)(2,0);(1,1). Repair reversed factors: give JF∘G(p)J_{F\circ G}(p) as ordered rows.

  1. A(4,2);(1,1)(4,2);(1,1)
  2. B(2,0);(0,1)(2,0);(0,1)
  3. C(2,4);(1,3)(2,4);(1,3)
Show answer and explanation
(2,4);(1,3)(2,4);(1,3)

(2,2)(2,2): 2+1=32+1=3.

The same rule includes a scalar output reached through two paths. Let u=x2u=x^2, v=3xv=3x, and L=uvL=uv. At x=2x=2, we have u=4u=4 and v=6v=6.

The outer derivative row is (v,u)=(6,4)(v,u)=(6,4). The inner derivative column is (2x,3)T=(4,3)T(2x,3)^T=(4,3)^T. Their product is 6(4)+4(3)=366(4)+4(3)=36: one contribution through uu, plus another through vv.

Direct substitution gives L=3x3L=3x^3, whose derivative at 22 is also 3636. Dropping either path would miss part of that change.

This is the connection to backpropagation: forward values determine where local derivatives are evaluated, multiplication carries effects through operations, and addition collects contributions that meet at the same variable.

Key takeaway

Evaluate the intermediate input, then multiply outer by inner.

  • Compute the derivative of a composed vector map using Jacobians.

Further questions

Why does the inner factor sit on the right?
Matrix products act on a vector from right to left. An input change first passes through the inner derivative, then through the outer derivative.

Sources & further reading

  1. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Multivariable chain rule.” Math behind ML. /learn/c-multi-chain