Matrices map between biproducts

Why are linear functions between finite-dimensional vector spaces representable by matrices? And why does matrix multiplication compose the corresponding linear maps? There’s geometric intuition for this, e.g. presented by 3Blue1Brown. I will alternatively present a category-theoretic analysis. The short version is that, in the category of vector spaces and linear maps, products are also coproducts (hence biproducts); and in categories with biproducts, maps between biproducts decompose as (generalized) matrices. These generalized matrices align with traditional numeric matrices and matrix multiplication in the category of vector spaces. The category-theoretic lens reveals matrices as an elegant abstraction, contra The New Yorker.

I’ll use a standard notion of a vector space over the field \mathbb{R}. A vector space has addition, zero, and scalar multiplication defined, which have the standard commutativity/associativity/distributivity properties. The category \mathsf{Vect} has as objects vector spaces (over the field \mathbb{R}), and as morphisms linear maps. A linear map f : U \rightarrow V between vector spaces U, V satisfies f(u_1 + u_2) = f(u_1) + f(u_2) and f(au) = af(u). (Advanced readers may see nlab on Vect.)

Clearly, \mathbb{R} is a vector space, as is 0 (the vector space with only one element, which is zero). 0 is both an initial and a terminal object. Any linear map from 0 must always return the zero vector; and so must any linear map into 0. Therefore, by definition 0 is a category-theoretic zero object.

If U and V are vector spaces, then the direct sum U \oplus V, which has as elements pairs (u, v) with u \in U, v \in V, and for which addition and scalar multiplication are element-wise, is also a vector space. The direct sum is both a product and a coproduct.

To show that the direct sum is a product, let U and V be vector spaces, and let \pi_1 : U \oplus V \rightarrow U and \pi_2 : U \oplus V \rightarrow V be the projections of the direct sum onto its elements. Let us suppose a third vector space T and linear maps f : T \rightarrow U and g : T \rightarrow V. Let \langle f, g \rangle : T \rightarrow U \oplus V be defined as \langle f, g \rangle (t) = (f(t), g(t)). Now \langle f, g \rangle uniquely commutes:

To show that the direct sum is a coproduct, let U and V be vector spaces, and let i_1 : U \rightarrow U \oplus V be defined as i_1(u) = (u, 0), and similarly let i_2 : V \rightarrow U \oplus V be defined as i_2(v) = (0, v). Let us suppose a third vector space W and linear maps f : U \rightarrow W and g : V \rightarrow W. Let [f, g] : U \oplus V \rightarrow W be defined as [f, g](u, v) = f(u) + g(v). Now [f, g] uniquely commutes:

The upshot is that the direct sum is both a product and a coproduct. Let 0_{A,B} : A \rightarrow B be a zero function; since the direct sum also satisfies the identities \pi_1 \circ i_1 = id_U, \pi_2 \circ i_2 = id_V, \pi_1 \circ i_2 = 0_{V,U}, \pi_2 \circ i_1 = 0_{U,V}, by definition it is a biproduct. We can now abstract from the category \mathsf{Vect} to semiadditive categories, which are by definition categories with a zero object and all pairwise biproducts. Let C stand for any semiadditive category, with biproduct \oplus.

Biproducts enable powerful decomposition of morphisms (such as linear maps). Given h : T \rightarrow U \oplus V (in C), we may uniquely decompose it as h = \langle f, g \rangle for some f : T \rightarrow U and g : T \rightarrow V, specifically f = \pi_1 \circ h, g = \pi_2 \circ h. And similarly, we may uniquely decompose h : U \oplus V \rightarrow W as h = [f, g] for some f : U \rightarrow W and g : V \rightarrow W, specifically f = h \circ i_1, g = h \circ i_2.

Biproducts generalize from binary to n-ary. Suppose n is natural and U_i is an object for natural 1 \leq i \leq n. Now the n-ary biproduct is \bigoplus_{i=1}^n U_i = U_1 \oplus \ldots \oplus U_n. We take the empty biproduct to be 0. We can also generalize the projections \pi_i, the injections i_i, the “row-wise” combination \langle f, g \rangle, and the “column-wise” combination [f, g], from binary to n-ary.

This generalization to n-ary biproducts enables conceiving of matrices categorically. Let m, n be natural, and let U_i and V_j be objects in C, for natural 1 \leq i \leq m and 1 \leq j \leq n. Suppose h : \bigoplus_{i=1}^m U_i \rightarrow \bigoplus_{j=1}^n V_j. We first decompose h “row-wise”, as h = \langle h_1, \ldots, h_n \rangle where h_j = \pi_j \circ h. Then we decompose each row “column-wise”, as h_j = [h_{j,1}, \ldots, h_{j,m}] where h_{j,i} = \pi_j \circ h \circ i_i. We can now write h in matrix style, as h = \langle [ h_{1, 1}, \ldots, h_{1, m} ], \ldots, [h_{n, 1}, \ldots, h_{n, m}] \rangle; the notation \langle \ldots \rangle can be visualized as vertical matrix concatenation, and [ \ldots ] can be visualized as horizontal matrix concatenation.

This is the core abstract idea, but how to apply it more concretely? Back in \mathsf{Vect}, we can form the Euclidean space \mathbb{R}^n = \bigoplus_{i=1}^n \mathbb{R}. Now a map h : \mathbb{R}^m \rightarrow \mathbb{R}^n decomposes as a n \times m matrix of linear maps h_{j, i} : \mathbb{R} \rightarrow \mathbb{R}. This is not quite a traditional matrix, but note that linear maps of type \mathbb{R} \rightarrow \mathbb{R} are always multiplication by a constant real slope. Representing each h_{j, i} by its slope yields a more traditional numeric matrix.

We can generalize matrix representation of linear maps to finite-dimensional vector spaces (which by definition have finite bases), by noting that each of these is isomorphic to \mathbb{R}^n for some natural n. Specifically, if a space U has a basis \{u_1, \ldots, u_n\}, then the linear map f : \mathbb{R}^n \rightarrow U defined as f(x_1, \ldots, x_n) = \sum_{i=1}^n x_i u_i is an isomorphism. Hence, matrix representation extends to maps between finite-dimensional vector spaces.

So far, we have a treatment of matrix-vector multiplication, but not matrix-matrix multiplication. We would like to show that composition of linear maps leads to the matrix representations multiplying in the expected way. Let m, n, p be natural, and let U_i, V_j, W_k be objects in C (for naturals 1 \leq i \leq m, 1 \leq j \leq n, 1 \leq k \leq p). Suppose we have maps f : \bigoplus_{i=1}^m U_i \rightarrow \bigoplus_{j=1}^n V_j and g : \bigoplus_{j=1}^n V_j \rightarrow \bigoplus_{k=1}^p W_k. We can write f in matrix form (f_{j, i} = \pi_j \circ f \circ i_i), and similarly g (g_{k, j} = \pi_k \circ g \circ i_j).

Now we wish to find the matrix form of the composition h = g \circ f. We fix i, k and consider the entry h_{k, i} = \pi_k \circ g \circ f \circ i_i. Now note \pi_k \circ g = [g_{k, 1}, \ldots, g_{k, n}] and f \circ i_i = \langle f_{1, i}, \ldots, f_{n, i} \rangle. Therefore

h_{k, i} = [g_{k, 1}, \ldots, g_{k, n}] \circ \langle f_{1, i}, \ldots, f_{n, i} \rangle

This expression is a row-column matrix multiplication, similar to a vector dot product. In the case of \mathsf{Vect}, we can more explicitly write:

h_{k, i}(u) = \sum_{j=1}^n g_{k, j}(f_{j, i}(u))

Since Hom(U, V) in \mathsf{Vect}, the set of linear maps from U to V, naturally forms a vector space, h_{k, i} can also be written:

h_{k, i} = \sum_{j=1}^n (g_{k, j} \circ f_{j, i})

In the case where each U_i, V_j, W_k is \mathbb{R}, this aligns with traditional matrix multiplication; composing linear maps of type \mathbb{R} \rightarrow \mathbb{R} multiplies their slopes.

There is a way to generalize the row-column matrix multiplication [g_{k, 1}, \ldots, g_{k, n}] \circ \langle f_{1, i}, \ldots, f_{n, i} \rangle = \sum_{j=1}^n (g_{k, j} \circ f_{j, i}) to semiadditive categories in general; for details, see Wikipedia on additive categories.

To summarize general lessons about semiadditive categories:

  • A map between biproducts h : \bigoplus_{i=1}^m U_i \rightarrow \bigoplus_{j=1}^n V_j can be represented in matrix form as \langle [h_{1, 1}, \ldots, h_{1, m}], \ldots, [h_{n, 1}, \ldots, h_{n, m}] \rangle with h_{j, i} = \pi_j \circ h \circ i_i.
  • If we have maps f : \bigoplus_{i=1}^m U_i \rightarrow \bigoplus_{j=1}^n V_j and g : \bigoplus_{j=1}^n V_j \rightarrow \bigoplus_{k=1}^p W_k, the matrix entry h_{k, i} of the composition h = g \circ f is the row-column multiplication [g_{k, 1}, \ldots, g_{k, n}] \circ \langle f_{1, i}, \ldots, f_{n, i} \rangle.

And in the case of \mathsf{Vect}, these imply the standard results:

  • Linear maps between finite-dimensional vector spaces, with fixed bases, are uniquely represented as numeric matrices.
  • The matrix representation of a composition of linear maps equals the product of the matrices representing these maps.

This is a nice way of showing the standard results, and the abstract results generalize to other semiadditive categories, such as the category of Abelian groups. For more detailed category-theoretic study of linear algebra, see Filip Bár’s thesis, “On the Foundations of Geometric Algebra”. For an even more abstract treatment, see “Graphical Linear Algebra”.