Matrix Multiplication as Composition
Why is matrix multiplication defined by that strange row-times-column recipe? Why not use the simpler entrywise product? A concrete question makes the issue vivid. If scales the plane and rotates it, what single matrix describes "first scale, then rotate"? The entrywise product of the two matrices answers no natural question at all. But a certain sum-of-products formula answers exactly this one. This article shows that matrix multiplication is not an arbitrary convention. It is forced upon us the moment we insist that matrices should represent linear maps. It is also forced once we insist that composing matrices should represent composing maps. The big picture is that linear maps are the real objects of study. Matrices are merely their coordinates once bases are chosen. This works via the isomorphism The Isomorphism L(V,W) ≅ Matrices. Function composition is one of the most basic operations on maps. So any respectable coordinate system for maps must have a matching operation. Matrix multiplication is defined precisely so that the matrix of a composite equals the product of the matrices. No more, no less. Once this is accepted as the design goal, the formula for the entry of a product is not memorized. Instead it is derived from tracking how basis vectors move under Coordinate Vectors and Matrix Action. This perspective immediately explains two facts that otherwise look like arbitrary rules. Multiplication is associative because composition of functions is associative. Multiplication is generally non-commutative because composition of functions is generally non-commutative. Doing then is a different map from doing then . Associativity of matrix multiplication is often proved by a grinding index computation. But it becomes almost free once we know it mirrors composition. This article delivers a clean, motivated definition of the matrix product. It gives a full proof that this definition correctly represents composition. It also gives a separate direct proof of associativity, for comparison. It includes worked examples with genuinely asymmetric (non-square, non-commuting) matrices. It also includes a counterexample showing why matching dimensions is essential. It closes by pointing toward Invertibility of Linear Maps and Elementary Matrices and Row Operations. Both of these lean heavily on the composition viewpoint developed here.
- Matrix multiplication is defined so that for linear maps .
- The entry of is , forced by tracking basis vectors through two maps in a row.
- Dimensions must chain: an matrix times an matrix, matching the middle index .
- Associativity follows instantly from associativity of function composition.
- Non-commutativity in general reflects that "scale then rotate" differs from "rotate then scale".
- Key idea: matrix multiplication is composition of linear maps, written in coordinates.
Where this lives today
Matrix multiplication as composition underlies every place linear transformations are chained together. In computer graphics, a 3D object's position is transformed by successive matrices for scaling, rotation, and translation (via homogeneous coordinates), and the entire pipeline is a single matrix product precisely because applying transformations in sequence is composition. In quantum mechanics, sequential measurements or time evolutions correspond to products of operator matrices, and the physical fact that order of operations matters (non-commuting observables) is the same phenomenon as above, now carrying deep physical content (the uncertainty principle traces back to non-commutativity of position and momentum operators). In cryptography and coding theory, linear codes and certain cipher constructions compose linear transformations over finite fields, again multiplying matrices to represent "encode, then transmit, then decode" pipelines. In statistics and machine learning, a neural network's layers are (affine or linear) maps, and the composite map of a multi-layer network is captured, layer by layer, as a product of weight matrices, with the non-commutativity of layer order being exactly why architecture (which transformation comes first) matters. In numerical analysis, factorizations like or decompose one matrix as a product of simpler ones, implicitly asserting that a complicated linear map is literally a composition of easily-understood ones — an idea that leads directly to Elementary Matrices and Row Operations and to criteria for Invertibility of Linear Maps.
Ask the tutor: Can you show me why follows directly from viewing as a composition of maps?
Let be finite-dimensional vector spaces over a field , with ordered bases
Let and be linear maps, with matrices (relative to these bases)
meaning
The matrix product is defined entrywise by
This is defined only when the number of columns of equals the number of rows of (both equal to , the dimension of the shared intermediate space ).
Intuition
Think of a linear map as a machine that takes a vector, reads off its coordinates, and outputs new coordinates via a fixed table of instructions. If is such a machine turning -coordinates into -coordinates, and is a machine turning -coordinates into -coordinates, then bolting onto the output of builds a new machine, , turning -coordinates directly into -coordinates. Matrix multiplication is the recipe for building the instruction table of the bolted-together machine directly from the two original tables, without ever computing an intermediate vector by hand. The reason the formula involves a sum over an index is that a basis vector of does not land on a single basis vector of — it lands on a combination . Each of those 's is then pushed forward by into its own combination of 's, and all these contributions to the coefficient of must be added up. The index ranges over the intermediate basis, which is exactly why the shared dimension must match: it counts the number of routes a basis vector of can take to reach . ```mermaid ```
The mental model to keep
Every basis vector of fans out to all of 's basis vectors under (with coefficients ), and each of those fans out again to all of 's basis vectors under (with coefficients ). The total coefficient of in collects one term for each intermediate route through some , giving exactly . This is the entire content of the theorem below, made rigorous.
Let be finite-dimensional vector spaces over a field with ordered bases as above, where , , . Let and . Then the composite map satisfies
where matrix multiplication on the right is the product defined above, and matrices are taken with respect to the bases indicated.
Technique: direct computation of both sides against the basis , using linearity and uniqueness of coordinate representations. Write and , so that by definition of the matrix of a linear map (see The Isomorphism L(V,W) ≅ Matrices):
Fix . Since is linear (a composite of linear maps is linear: if are linear then by linearity of then ), we compute by substituting (1) into and using linearity of :
where the last equality uses linearity of (additivity applied times and homogeneity in each scalar ). Now substitute (2):
The double sum is finite, so we may swap the order of summation (commutativity and associativity of addition in , an abelian group under addition):
using the definition of the matrix product from the Definition block. On the other hand, by definition of the matrix of the linear map relative to bases , letting , we have by definition
Both (3) and (4) express as a linear combination of the basis of . Since coordinates of a vector relative to a basis are unique — if then , and since is linearly independent this forces for every — we conclude
Since was arbitrary, for all , i.e.
∎
Let , , . Then
Technique: realize each matrix as the matrix of a linear map between standard coordinate spaces, and reduce to associativity of function composition. Let , , , , each equipped with its standard basis. Standard basis vectors turn matrices into linear maps: define by , by , by . Relative to standard bases, , , (this is the content of Coordinate Vectors and Matrix Action: the matrix of the map "multiply by " relative to standard bases is itself). By the theorem just proved, applied to the pair :
Applying the theorem again to the pair :
Symmetrically, applying the theorem to the pair gives , and applying it to the pair gives
Function composition is associative: for any functions with compatible domains/codomains and any ,
so as functions (this uses only that unfolds to nested function application, no linearity needed). Hence the two matrices computed above represent the same linear map relative to the same pair of bases, and the matrix of a linear map relative to fixed bases is unique (this uniqueness is precisely the injectivity half of the isomorphism from The Isomorphism L(V,W) ≅ Matrices). Therefore
Worked examples
Example 1 (a genuinely non-square, non-commuting composition). Let , , , all with standard bases. Let and have matrices
Here (the shared middle dimension) matches: has rows, has columns, so is defined and lands in . Compute entrywise:
So
Sanity check via the composition meaning: take , the first standard basis vector of . Then
This matches column of , exactly as the theorem predicts: 's first column records the coordinates of . The computation confirms the entrywise product formula is not a bookkeeping accident but literally is tracking .
Example 2 ( vs — non-commutativity made concrete). Let have matrices
Compute ("rotate, then stretch"):
Now compute ("stretch, then rotate"):
Indeed . Trace the vector through each order to see why, geometrically: under , (rotate to , then stretching the -axis does nothing to it since its -coordinate is ). Under , (stretch to , then rotating sends to ). Stretching before rotating versus after gives different final lengths, because the stretch treats the -axis specially and rotation moves points off that axis. This is the concrete meaning of non-commutativity: composing functions in different orders produces different functions.
Suppose we try to define a "product" of and whenever , say by padding with zeros or simply pairing up entries mismatched in index. Concretely, take
Here has columns but has rows, so . There is no linear map built from whose domain matches the codomain of the map built from : represents a map , while represents a map . The composite is not even defined as a function, since the outputs of live in but only accepts inputs from . Any formula one invents for "" in this mismatched case — e.g., truncating to its first two rows before multiplying, giving — is not the matrix of any composition , because that composition does not exist. Such a formula might still be "computable," but it represents nothing; it fails the entire design goal of the Definition, namely that . This is exactly why the Definition insists the number of columns of equal the number of rows of : this shared number is the dimension of the intermediate space , without which "compose after " is meaningless. Dropping the dimension-matching hypothesis does not merely make the proof harder — it removes the object being proved about.
Scope, edge cases & common traps
| Situation | What happens | Why |
|---|---|---|
| is , is | defined, size | shared index = dim of intermediate space |
| is , is , | undefined | no linear map to compose (see counterexample) |
| both | both defined, same size | but generally (Example 2) |
| is (row), is (column) | is scalar, is | order changes even the shape of the answer |
| Composing or more maps | product is unambiguous, any grouping works | associativity (Corollary), inherited from function composition |
The mathematician behind it
Arthur Cayley, working in the mid-1800s, is credited with the first systematic treatment of matrices as objects in their own right, including the definition of matrix multiplication designed exactly to mirror composition of the linear substitutions (what we would now call linear maps) that matrices encode. Cayley's 1858 Memoir on the Theory of Matrices introduced matrix algebra abstractly, proved the Cayley–Hamilton theorem for small cases, and explicitly remarked that matrix multiplication corresponds to compounding linear substitutions — the same insight this article makes rigorous with modern coordinate-vector language.
Origins · 1 minArthur Cayley and how this was discovered
Cayley was a prolific English mathematician who, alongside legal work as a barrister, produced over 900 papers spanning algebra, geometry, and invariant theory. His matrix memoir treated arrays as single algebraic entities obeying their own laws, deliberately built so that multiplying matrices would correspond to composing the linear substitutions they represented — the exact motivating idea behind the Definition given here.
Why isn't matrix multiplication just the entrywise product of two matrices?
The entrywise product is a perfectly valid operation (the Hadamard product), but it does not correspond to composing linear maps. If and are matrices of linear maps and , tracking what happens to a basis vector as it passes through and then naturally produces the sum-of-products formula , not an entrywise product. Matrix multiplication is defined to solve the specific problem of representing composition in coordinates; the entrywise product solves a different (also useful, but unrelated) problem, such as combining independent per-coordinate scalings.
Do I need to check that both and are defined before asking whether ?
Yes. If is and is with , then is while is — different sizes entirely, so they cannot be equal (they are not even comparable). Only when and are both square of the same size does it make sense to ask whether , and even then the answer is usually no, as Example 2 shows with a rotation and a stretch.
Is matrix multiplication ever commutative?
Yes, in special cases: the identity matrix commutes with everything, scalar multiples of the identity commute with everything, and any matrix commutes with itself and its own powers. More generally, two matrices representing linear maps that are "simultaneously diagonalizable" (share an eigenbasis) commute. But for generic matrices, especially those representing geometrically different operations like rotation and non-uniform scaling, commutativity fails, as shown in Example 2.
Does associativity mean I can multiply matrices in any order I like?
No — associativity only says that the grouping of consecutive multiplications does not matter: . It does not say you may swap the order of the factors; computed strictly left to right or right to left with the same left-to-right sequence gives one unambiguous answer, but or (permuted factors) are generally completely different matrices. Associativity licenses dropping parentheses; it does not license commuting factors.
Why does the shared dimension have to be exactly the dimension of the intermediate vector space?
Because that dimension counts how many basis vectors of the intermediate space exist, and the entry sums over exactly those basis vectors — the "routes" a vector can take from to via . If the matrices did not agree on this count, there would be no consistent way to assign a route index to both factors simultaneously, which is precisely the failure illustrated in the counterexample block.
How does this relate to invertibility of linear maps?
If and satisfy and , then by the theorem here, and , exactly the definition of being the inverse matrix of . Composition is thus the conceptual bridge connecting invertible linear maps to invertible matrices, a connection developed fully in Invertibility of Linear Maps.
Why do elementary row operations correspond to left-multiplication by special matrices?
An elementary row operation on a matrix can itself be realized as a linear map applied to the columns of viewed as vectors, i.e., as composing (as a map) with first. By the theorem here, performing the row operation is the same as replacing with for the appropriate elementary matrix . This is exactly the perspective developed in Elementary Matrices and Row Operations, and it is only sensible because matrix multiplication was built to represent composition in the first place.