Why Parentheses Matter—and When They Do Not
Matrix multiplication is not commutative: changing the order of two factors can change the product, or make it undefined. But when three matrices have compatible dimensions, changing only the parentheses does not change the result. This property is called associativity. It matters because it allows a long product to be grouped in a convenient way without altering the order of its factors.
For example, to form both \((\mathbf{A}\mathbf{B})\mathbf{C}\) and \(\mathbf{A}(\mathbf{B}\mathbf{C})\), take \(\mathbf{A}\in\mathbb{R}^{m\times n}\), \(\mathbf{B}\in\mathbb{R}^{n\times p}\), and \(\mathbf{C}\in\mathbb{R}^{p\times q}\), where \(m,n,p,q\) are positive integers. Then \(\mathbf{A}\mathbf{B}\) is \(m\times p\), so \((\mathbf{A}\mathbf{B})\mathbf{C}\) is defined; also \(\mathbf{B}\mathbf{C}\) is \(n\times q\), so \(\mathbf{A}(\mathbf{B}\mathbf{C})\) is defined. Both results have size \(m\times q\).
Proof by Expanding Entries
Recall the entry formula for matrix multiplication: if \(\mathbf{X}\) is \(r\times s\) and \(\mathbf{Y}\) is \(s\times t\), then the entry in row \(i\), column \(j\) of their product is \(\sum_{k=1}^{s}x_{ik}y_{kj}\). Apply this formula to each grouping of three compatible matrices.
Proof. Both products are \(m\times q\), so it is enough to show that their entries agree for every row index \(i\) with \(1\le i\le m\) and column index \(j\) with \(1\le j\le q\). The entry in position \((i,j)\) of the left-hand product is
The entry in position \((i,j)\) of the right-hand product is
These are the same finite sum: both include one term \(a_{i\ell}b_{\ell k}c_{kj}\) for each pair of indices \(1\le \ell\le n\) and \(1\le k\le p\). The order in which the terms are grouped and added can be changed because scalar addition is associative and commutative, and scalar multiplication is associative. Thus the two products agree in every entry. Equal-sized matrices with equal corresponding entries are equal, so \((\mathbf{A}\mathbf{B})\mathbf{C}=\mathbf{A}(\mathbf{B}\mathbf{C})\). \(\square\)
The proof depends on both conformability and finite sums. The dimensions ensure that the index \(k\) ranges over the \(p\) columns of \(\mathbf{B}\) and rows of \(\mathbf{C}\), while \(\ell\) ranges over the \(n\) columns of \(\mathbf{A}\) and rows of \(\mathbf{B}\). The same terms occur in either expansion; associativity does not assert that the matrices themselves can be reordered.
Checking Both Groupings in Examples
Worked Example: A Product with Three Different Dimensions
Let \(\mathbf{A}\) be \(2\times2\), \(\mathbf{B}\) be \(2\times3\), and \(\mathbf{C}\) be \(3\times2\). Compute the two groupings.
First calculate \(\mathbf{A}\mathbf{B}\), taking each entry as a row-by-column product:
Now multiply by \(\mathbf{C}\):
For the other grouping, first compute \(\mathbf{B}\mathbf{C}\):
Then multiply on the left by \(\mathbf{A}\):
Check: both groupings produce the same \(2\times2\) matrix, \(\begin{bmatrix}7&12\\2&5\end{bmatrix}\), as the theorem predicts.
Worked Example: A Row Matrix, a Rectangular Matrix, and a Column Matrix
Take a \(1\times3\) matrix, a \(3\times2\) matrix, and a \(2\times1\) matrix. The final result in either grouping must be \(1\times1\).
Compute the first grouping:
For the second grouping, multiply \(\mathbf{B}\) by \(\mathbf{C}\), then \(\mathbf{A}\) by the result:
Check: each route gives the \(1\times1\) matrix \(\begin{bmatrix}8\end{bmatrix}\). The dimensions also show why both routes are allowed: the first intermediate product has size \(1\times2\), and the second has size \(3\times1\).
Worked Example: A Column Matrix Followed by Two Row Matrices
Now let the first matrix be \(3\times1\), the second \(1\times2\), and the third \(2\times2\). This example checks associativity when the first product has repeated rows scaled by entries of a row matrix.
First, \(\mathbf{A}\mathbf{B}\) is a \(3\times2\) matrix:
Multiplying this result by \(\mathbf{C}\) gives
For the other grouping, calculate \(\mathbf{B}\mathbf{C}\) first:
Then
Check: the two computed \(3\times2\) results agree entry by entry.
Grouping Four Factors
Associativity is useful beyond a product of three matrices. For four compatible matrices, it guarantees that all possible groupings give the same result, as long as the factors stay in their original order. There are five ways to place parentheses in a product of four factors; the next result lists and compares them directly.
Proof. All products below are defined because the four matrices are compatible in the stated order. Applying associativity to \(\mathbf{A},\mathbf{B},\mathbf{C}\) shows \(((\mathbf{A}\mathbf{B})\mathbf{C})\mathbf{D}=(\mathbf{A}(\mathbf{B}\mathbf{C}))\mathbf{D}\). Applying it to \(\mathbf{A},\mathbf{B}\mathbf{C},\mathbf{D}\) gives \((\mathbf{A}(\mathbf{B}\mathbf{C}))\mathbf{D}=\mathbf{A}((\mathbf{B}\mathbf{C})\mathbf{D})\). Applying it to \(\mathbf{B},\mathbf{C},\mathbf{D}\) gives \(\mathbf{A}((\mathbf{B}\mathbf{C})\mathbf{D})=\mathbf{A}(\mathbf{B}(\mathbf{C}\mathbf{D}))\). Finally, applying it to \(\mathbf{A}\mathbf{B},\mathbf{C},\mathbf{D}\) gives \(((\mathbf{A}\mathbf{B})\mathbf{C})\mathbf{D}=(\mathbf{A}\mathbf{B})(\mathbf{C}\mathbf{D})\). These equalities connect all five groupings, proving the claim. \(\square\)
This result says that parentheses can be chosen to make a calculation more convenient. It does not say that the order of multiplication can change. The distinction is important even when all matrices are square and every possible product is defined.
Common Pitfall: Reassociating Is Not Reordering
Consider the matrices \(\mathbf{A}=\begin{bmatrix}1&1\\0&1\end{bmatrix}\), \(\mathbf{B}=\begin{bmatrix}1&0\\1&1\end{bmatrix}\), and \(\mathbf{C}=\begin{bmatrix}1&0\\0&2\end{bmatrix}\). A mistaken use of associativity might replace \((\mathbf{A}\mathbf{B})\mathbf{C}\) by \(\mathbf{A}(\mathbf{C}\mathbf{B})\), moving \(\mathbf{C}\) past \(\mathbf{B}\). That changes the order, which associativity does not permit.
Compute the original product. First, \(\mathbf{A}\mathbf{B}=\begin{bmatrix}2&1\\1&1\end{bmatrix}\), so
The incorrect reordering gives \(\mathbf{C}\mathbf{B}=\begin{bmatrix}1&0\\2&2\end{bmatrix}\), and hence
These matrices differ, so the claimed replacement is false. The valid reassociation keeps the order \(\mathbf{A},\mathbf{B},\mathbf{C}\): indeed \(\mathbf{B}\mathbf{C}=\begin{bmatrix}1&0\\1&2\end{bmatrix}\), and \(\mathbf{A}(\mathbf{B}\mathbf{C})=\begin{bmatrix}2&2\\1&2\end{bmatrix}\), matching the original product.
Why Associativity Is Useful
Matrix multiplication often represents a sequence of operations. If the first two operations are represented by \(\mathbf{A}\) and \(\mathbf{B}\), and a third by \(\mathbf{C}\), then the product in the order \(\mathbf{A}\mathbf{B}\mathbf{C}\) can be calculated as either \((\mathbf{A}\mathbf{B})\mathbf{C}\) or \(\mathbf{A}(\mathbf{B}\mathbf{C})\). The result is unchanged, but the intermediate matrices may have different sizes. Associativity lets us select the grouping that is easier to compute, while preserving the sequence of factors.
Before regrouping, check that the dimensions form a compatible chain: the number of columns of each factor must equal the number of rows of the factor immediately to its right. Then keep the factor order fixed, change only the parentheses, and compare entries if a numerical check is useful. These steps separate the dimension question from the algebraic question and prevent a valid use of associativity from becoming an invalid reordering.
Check Your Understanding
Use dimensions and entry expansions to justify each conclusion.
- If \(\mathbf{A}\) is \(3\times2\), \(\mathbf{B}\) is \(2\times4\), and \(\mathbf{C}\) is \(4\times1\), what size are \((\mathbf{A}\mathbf{B})\mathbf{C}\) and \(\mathbf{A}(\mathbf{B}\mathbf{C})\)?
- In the associativity proof, which index runs from \(1\) to \(n\), and which runs from \(1\) to \(p\)?
- For \(\mathbf{A}=\begin{bmatrix}1&2\end{bmatrix}\), \(\mathbf{B}=\begin{bmatrix}1&0\\0&3\end{bmatrix}\), and \(\mathbf{C}=\begin{bmatrix}2\\1\end{bmatrix}\), compute both groupings.
- Explain why replacing \(\mathbf{A}(\mathbf{B}\mathbf{C})\) by \(\mathbf{A}(\mathbf{C}\mathbf{B})\) is not an application of associativity.
- Write the five parenthesizations of an ordered product of four compatible matrices.