# Computer Algebra Systems that support variable sized matrices

I'm familiar with sympy, the matlab symbolic package, reduce, and have tried out a few other computer algebra systems. However, as far as I can tell, none of them seem to be able to do algebra on variable sized matrices - they can only work with fixed sized matrices.

Are there any that can do algebra for variable sized matrices? I understand there would be quite a few gross cases but I feel like there is a significant amount that is doable simply because of the ease of many simplifications/algebra one can do by hand in with matrices in R^nxn.

It is possible to just work with non-communiative algebraic elements in many of these, and so that covers addition and Hadamard product with matrices, which is useful and a start. However it covers a very small portion of what one actually does with matrices (say, transpose, inverses, eigenvalue decomposition, using matrices in R^nxm, etc.). Does any more general software exist?

(this question is reposted from here because mathoverflow seemed like a more appropriate place to ask this question)

• stackoverflow.com/questions/5708208/… Nov 21 '15 at 18:05
• You might consider adding a top-level tag in order to make more people see this question. Nov 21 '15 at 18:17
• What do you want to do with the software? It seems to me any software that can deal with fixed dimension matrices can more or less tautologically deal with arbitrary-sized matrices. In C++ or Python you could easily code-up such routines. But what would you want to do with them? Nov 21 '15 at 19:44
• Ideally I would like a way to have an input optimization problem (in terms of the minimization function and contraints described by matrices), and be able to transform it to a problem that is already known how to solve, or at least simplify it, and automatically generate the dual problem and perhaps compute the duality gap. Optimization problems typically are n-dimensional and it's usually nice to have a general form that is independent of dimension for a given problem. Nov 21 '15 at 19:49
• I understand that some of those steps are non-trivial, so I'm really just wondering what software exists so I don't have to reinvent the wheel as much as possible and instead focus on the more interesting problems here such as reductions. Nov 21 '15 at 19:52

SymPy has a matrix expressions module that does this. Example:

>>> from sympy import MatrixSymbol, Matrix, symbols
>>> n, m = symbols('n m', integer=True)
>>> X = MatrixSymbol('X', n, m)
>>> Y = MatrixSymbol('Y', m, n)
>>> (X*Y).T
Y'*X'


Matrix expressions can have symbolic sizes (like n and m) or explicit integer sizes, in which case they can be combined with explicit matrices.

It's also worth noting that there are a lot of things that aren't documented in the doc page I linked to, so take a look at https://github.com/sympy/sympy/tree/master/sympy/matrices/expressions for the full functionality.

You can also look at this talk which uses this module, along with some modules that are separate from SymPy.

I am not sure what precisely you are looking for, but the GAP package MatricesForHomalg provides elaborate functionality for dealing with matrices in the context of homological algebra. This package is part of the homalg project which is a larger open source software project for constructive homological algebra.