What is the most rigorous definition of a matrix?

Let $I_n:=\{1,\cdots, n\}$.

A $n \times m$-matrix with coefficients in a ring $\mathcal{R}$ is a function $a: I_n \times I_m \to \mathcal{R}$. We define $a_{i,j}:=a(i,j)$.

In other words, a rectangular array.

Sidenote: In my point of view, I think it is particularly useful to see the above definition as a model for the concept of a matrix, and retain subconsciously the relevant idea of a rectangular array as the core concept. If you truly understand the core concept and has relative comfort with mathematics, coming up with the above definition is a simple matter.


Let $R$ be a commutative ring with identity, and $n,m$ be positive integers. The set of $n\times m$ matrices $R^{n\times m}$ is defined as an $R$-module (vector space, if $R$ is a field) freely generated by elements $\{e_{i,j}\}$, where $1\leq i \leq n$ and $1 \leq j \leq m$. The element $e_{i,j}$ represents the matrix with all entries equal to zero, except the entry in $i$-th row and $j$-th column, which is equal to one.

For example, for $n=5, m=6$

$$e_{2,4}=\begin{pmatrix}0&0&0&0&0&0\\0&0&0&1&0&0\\0&0&0&0&0&0\\0&0&0&0&0&0\\0&0&0&0&0&0\end{pmatrix}$$

Any matrix is a linear combination of $e_{i,j}$, with the coefficients being just the matrix entries.

This is still just an $n \times m$-dimensional $R$-module, but there is also a natural multiplication map $\times : R^{n\times m} \times R^{m \times p} \rightarrow R^{n \times p}$, defined by $$e_{i,j} \times e_{k,l} = \begin{cases} e_{i,l} & j = k \\ 0 & j \neq k \end{cases}$$ and extended by linearity. In fact, it is the standard matrix product.

In case $n=m$, this multiplication makes $R^{n\times n}$ into an $R$-algebra, isomorphic to the algebra of all endomorphisms on $R^n$.


The standard way to define a table of values in some set $S$ as a mathematical object is to encode the positions as an index set $S$, and to represent the table as the map $I\to S$ that associates to each position it value in the table. Then matrices with $n$ rows and $m$ columns and values in $R$ could be represented (taking the usual convention of putting the row index before the column index) as maps $([n]\times[m])\to R$, where $[n]$ is an abbreviation for the $n$-element set $\{1,\ldots,n\}$, and "$\times$" denotes the Cartesian product.

However this definition has a drawback that the values $n,m$ cannot always be recovered from a matrix, even though the domain can be recovered from a map. The problem is that $[n]\times[m]=\emptyset$ whenever $n=0$ or $m=0$, so for a matrix that is the unique map $\emptyset\to R$, one cannot reconstruct the values of $n,m$. Bourbaki even explicitly states that there is a unique empty matrix, overlooking the fact that this causes problems with definitions that immediately follow in their own presentation. In everyday use of matrices, it is very common to assume that given an $n\times m$ matrix one knows what $n$ and $m$ are, but with the definition of a matrix as a map, this is simply not true in the case of an empty matrix. And empty matrices are necessary for encoding linear maps between finite dimensional vector spaces, in case a vector space of dimension$~0$ is the domain or codomain of the linear map.

One reason this is a real problem is that matrix multiplication is defined in such a way that any product of a $n\times k$ matrix with a $k\times m$ matrix should be an $n\times m$ matrix, each of whose entries is obtained as a sum of $k$ terms. If $k=0$ then both operands of the multiplication are empty matrices, so each entry of the product being a sum of $0$ terms must be $0$, giving the zero matrix of size $n\times m$. However this requires knowing the values of $n$ and $m$, and with the definition of matrix as map, this is not possible. One simply cannot define the product of the unique empty matrix with itself to be a different size zero matrix according to the circumstances.

So the conclusion is that for a rigorous definition of a matrix, one must record the dimensions as components of the matrix itself. So a proper and rigorous definition of a matrix is the following.

A matrix with entries in $R$ is a triple $(n,m,f)$ where $n,m\in\Bbb N$ and $f$ is a map $([n]\times[m])\to R$.