Skip to content
Glacius
Linear algebraConcept reference

Composing maps

For column vectors, applying B first and A second is represented by AB, because A(Bx) equals (AB)x.

On this page 7 sections
  1. Overview
  2. All vectors here are columns
  3. Let A double the first coordinate and B swap coordinates
  4. Check your understanding
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

01All vectors here are columns#

All vectors here are columns. If a vector passes through BB first and AA second, its output is A(Bx)A(Bx).

The composition matrix is

ABAB

The first map sits nearest the input vector, on the right.

Use A=(2001)A=\begin{pmatrix}2&0\\0&1\end{pmatrix} and B=(0110)B=\begin{pmatrix}0&1\\1&0\end{pmatrix}.

First B, then A:

AB=(0210)AB=\begin{pmatrix}0&2\\1&0\end{pmatrix}

Entry (1,2)(1,2) is 2(1)+0(0)=22(1)+0(0)=2.

For compatible matrices and a column vector xx:

Associativity groups the stages:

A(Bx)=(AB)xA(Bx)=(AB)x

If BB is p×np\times n and AA is m×pm\times p, then ABAB is m×nm\times n.

Check your reasoning

A=(3001)A=\begin{pmatrix}3&0\\0&1\end{pmatrix}, B=(0110)B=\begin{pmatrix}0&1\\1&0\end{pmatrix}. First AA, then BB. Find entry (2,1)(2,1) of the composition matrix.

Show answer and explanation
3

The product is BABA. Its entry (2,1)(2,1) is 1(3)+0(0)=31(3)+0(0)=3.

02Let A double the first coordinate and B swap coordinates#

Let AA double the first coordinate and BB swap coordinates. Starting at x=(1,3)x=(1,3), reversing the maps changes the result.

A doubles the first coordinate; B swaps coordinates. From x=(1,3), B then A reaches (3,1) then (6,1). A then B reaches (2,3) then (3,2). Lines connect successive states, not additional vector sums.A doubles the first coordinate; B swaps coordinates. From x=(1,3), B then A reaches (3,1) then (6,1). A then B reaches (2,3) then (3,2). Lines connect successive states, not additional vector sums.
Figure 1The same input gives different outputs in the two orders.
Link to this figure ↗Download SVGDownload PNG
Check your reasoning

Column vectors pass through SS (3×23\times2), then PP (1×31\times3). Choose the product.

  1. ASPSP
  2. BPSPS
  3. CP+SP+S
Show answer and explanation
PSPS

Use PSPS: SS acts first.

03Check your understanding#

Check your reasoning

AA: 2×32\times3, BB: 3×23\times2. A column vector goes through AA, then BB. Repair the claim ABAB.

  1. AABAB: 2×22\times2
  2. BBABA: 2×22\times2
  3. CBABA: 3×33\times3
Show answer and explanation
BABA: 3×33\times3

Use BABA: 3 inputs and 3 outputs.

Key takeaway

With column vectors, the rightmost map acts first.

  • Write the matrix product in the order the maps act on a column vector.

Sources & further reading

  1. [1]

Reference this concept

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

Glacius. “Composing maps.” Math behind ML. /learn/la-composition