# How to define an MatrixReduce function that can reduce the symbol matrix to the simplest type

The RowReduce function of MMA can not effectively reduce the matrix with parameters to the row simplest type.

   RowReduce[{{1, a, 2}, {0, 1, 1}, {-1, 1, 1}}]


The row simplest form of matrix $$\left(\begin{array}{ccc} 1 & a & 2 \\ 0 & 1 & 1 \\ -1 & 1 & 1 \end{array}\right)$$ should be $$\left(\begin{array}{ccc} 1 & -1 & -1 \\ 0 & 1 & 1 \\ 0 & a-2 & 0 \end{array}\right)$$ instead of $$\left(\begin{array}{lll} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)$$.

Moreover, MMA also lacks a built-in function that transforms a symbol matrix into the simplest type through elementary row and column transformations.

How to write these custom functions which are widely used in linear algebra? If you can, I also need a user-defined function to judge the rank of the symbol matrix (output the discussion results according to the variable value range).

In addition, I don't know if the simplest form (it is obtained by elementary row transformation and column transformation) of a symbolic matrix is the same as Smith transformation.

A = {{1, 2, a}, {1, 3, 0}, {2, 7, -a}};
B = {{1, a, 2}, {0, 1, 1}, {-1, 1, 1}};
ControlPCSSmithForm[A, a]
ControlPCSSmithForm[B, a]


But the Smith canonical form of matrix A is independent of a, which is a little different from the simplest form of matrix A.

• Read this answer and use the LUDecomposition technique there. This gives me: {{1, a, 2}, {0, 1, 1}, {0, 0, 2 - a}}. I also looked around for a ResourceFunction and found these, though they don't solve your problem directly: rsb = ResourceFunction["RowSpaceBasis"] csb = ResourceFunction["ColumnSpaceBasis"]; pvc = ResourceFunction["PivotColumns"]; – flinty Aug 4 '20 at 22:55
• @flinty Thank you very much, but ResourceFunction["RowSpaceBasis"][{{1, a, 2}, {0, 1, 1}, {-1, 1, 1}}] still returns an identity matrix, which is not the row simplest form of matrix {{1, a, 2}, {0, 1, 1}, {-1, 1, 1}}. – A little mouse on the pampas Aug 4 '20 at 23:06