# Matrix over non-field

This question came to my mind while trying to get the Eigen linear algebra library to play nicely with the Boost Units library; nevertheless, this is a question about mathematics, not about programming.

I'd like, for an application I'm developing, to be able to do some math over dimensioned numbers -- e.g. instead of adding 5 + 5, I want to make it explicit in the program's type system that I'm adding 5 meters plus 5 meters. Otherwise, I might accidentally try to add meters to seconds or something, and get a nonsensical answer. This is the use-case which Boost Units supports.

However, some of the arithmetic I want to do involves matrices -- for example, I have two three-dimensional vectors, both over meters, and I need to find the quaternion that represents the rotation between them, and then rotate other matrices by the same quaternion, etc etc. This is the use-case that Eigen supports.

It's been tricky trying to get these two libraries to play nicely together, and this morning I think I realized one reason that might be. Technically, I think what I want isn't linear algebra.

See, I want something that acts like linear algebra. But I can't really, in a purely mathematical sense, create a matrix over the set of lengths (in meters) -- because lengths aren't closed under multiplication. If you multiply a length by a length, you don't get a length - you get an area. In the same manner, if I multiply a matrix of lengths times a matrix of lengths, I expect to get a matrix of areas. (I don't know what physical sense that makes; I'm a programmer, not a physicist.)

In any case, now I'm curious. It seems like the thing-which-I-want is a thing that it makes sense to have -- linear algebra which isn't defined over a field, but which is defined over... I guess at least a set of abelian groups $S_n$, over which is defined a scalar multiplication function $S_n \times \mathbb{R} \rightarrow S_n$ and a multiplication function $S_n \times S_n \rightarrow S_{2n}$. (Actually it's more complicated than that, because I want to handle not only lengths but also times, masses, etc.)

Is this a thing which it makes mathematical sense to have? Is this a structure which already exists, and is known and studied? Are there any assumptions of linear algebra that break down, if multiplication isn't closed anymore?

• To the title: yes, there are matrices over non-fields, e.g., over commutative rings, like $\Bbb{Z}$. To "length". You can multiply two length as multiplication of real numbers. No need to interpret them as areas. Aug 9, 2018 at 14:28

Given a set of units $\{u_1,u_2,\dots,u_n\}$, the mathematical structure you are looking for is $\mathbb R(u_1,u_2,\dots,u_n)$. This is the set of rational functions in the variables $u_1,\dots,u_n$. This handles addition and multiplication the way you want: $5\text{ms}^{-2}+8\text{ms}^{-2}=13\text{ms}^{-2}$ and $5\text{ms}^{-2}× 8\text{ms}^{-2}=40\text{m}^2\text{s}^{-4}$, just like how $5xy^{-2}+8xy^{-2}=13xy^{-2}$ and $(5xy^{-2})(8xy^{-2})=40x^2y^{-4}$. Also, there is nothing wrong with having a matrix of functions, so you can indeed have a matrix of lengths and a matrix of frequencies and multiply them to get a matrix of speeds.

The only problem is that you are only interested in monomials, which are polynomials which are just a coefficient times a product of variables and their inverses. In the algebra of rational functions, it is OK to add $x$ to $y$, but you want it to not be OK to add $\text{kg}$ to $\text{ms}^{-2}$. You would need to implement this exception in your code somehow.

The question is a bit unclear, but I think I can say one germane thing.

In Clifford algebra (or maybe moreso in the denomination of practitioners who call it Geometric Algebra), it is routine to have a algebra $G$ with a class of elements you think of as "vectors" and a class of elements you think of as "(oriented) areas" and the product in $G$ of two linearly independent "vectors" does make an element that is an "area." Here is the relevant picture about the products from the wiki article: So working over a suitable algebra $G$ (probably the normal Euclidean one for $\mathbb R^3$, you could indeed build matrices whose entries are the "vector" type elements of $G$ and multiply them to get matrices whose entries are "area" type elements.

I haven't read any material doing this, but you might learn a bit while looking into it.

Naturally, there is a version of $G$ that is supposed to be able to do spacetime geometry (at least the flat version) too. I'm not sure if it could handle "time" like you want. As for incorporating "mass," I'm not sure how that would work. It is mixed up with spacetime, but I don't know if it can be packaged into something like this.

It seems to me you're making things more complicated than they are.

A matrix represents a linear map from one vector space to another (possibly the same) vector space. This representation is relative to a basis for each of the two vector spaces. The natural place for units would usually be in the basis elements. For instance, if you're describing three-dimensional physical space, you could have three basis vectors that correspond to moving north, west and up by one meter. When you add things, you need to check anyway whether they refer to the same basis, so that includes a natural check whether they refer to things expressed in the same units.