Search code examples
matlabsympysymbolic-mathsymbolic-computationcomputer-algebra-systems

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?


Solution

  • 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.