## Why is matrix arithmetic associative?

I’m trying to get my head around homotopy type theory at the moment. One aspect of this involves paying far closer attention to *how* you prove a theorem rather than merely noting the end result and forgetting how you got there.

Here’s a fairly trivial example of what I mean, involving matrices over a ring R. How do we know that addition and multiplication of matrices are associative?

For addition, it’s straightforward – matrix addition is associative because addition in R is associative:

((A+B)+C)_{ij} = (A+B)_{ij}+C_{ij} = (A_{ij}+B_{ij})+C_{ij}

= A_{ij}+(B_{ij}+C_{ij}) = A_{ij}+(B+C)_{ij} = (A+(B+C))_{ij}

But for matrix multiplication to be associative we need a lot more than mere associativity of multiplication in R. We also need addition in R to be commutative, and multiplication to distribute over addition:

(A.(B.C))_{ij} = ΣA_{ik}.(B.C)_{kj} = ΣA_{ik}.(ΣB_{kl}.C_{lj})

= ΣΣA_{ik}.(B_{kl}.C_{lj}) = ΣΣ(A_{ik}.B_{kl}).C_{lj} = ΣΣ(A_{ik}.B_{kl}).C_{lj}

= Σ(ΣA_{ik}.B_{kl}).C_{lj} = Σ(A.B)_{il}.C_{lj} = ((A.B).C)_{ij}

Note that we need distributivity to “bubble” the Σs to the front of the expression and back again, and we need commutativity to swap round the two Σs in the central step (since we can only swap them round *because* the order of summands doesn’t matter).

Moreover, we need distributivity to prove that the identity matrix is in fact a multiplicative unit, since the proof relies on 0.r = 0 in R, and you need distribution to prove that.

So what? you might cry. Well I’m not entirely sure, but I certainly am bewildered that in all my years fiddling with matrices I’ve only just noticed all this. It suggests that the extra discipline type theory imposes on mathematics at the very least throws up all sorts of extra subtleties that would otherwise be missed.

TL;DR version: you need almost all the ringyness of a ring in order for matrix multiplication to be associative.

- e-schatology likes this
- bat020 posted this