# [Maxima] Some issues (a bug?) with triangularize

Stefano Ferri ferriste at gmail.com
Wed Mar 10 10:42:45 CST 2010

```I was trying to solve a linear system (4 equations in 4 unknowns) by
reducing the complete matrix, and I came to this issue with
triangularize. When reducing the matrix in symbolic  form, one gets a
(wrong?) result, a different one (correct) if the triangularization is

This is the example: a system which, for h=-1, has 1 free unknown,
with infinite^1 solutions, with the following complete matrix:

(%i1) display2d:false;
(%o1) false

(%i2) M:matrix([h-1,h,h+2,h+1,1],[1-h,2,-h-2,1,1],[h-1,h,1,0,1],[0,-h-2,0,-2,1]);
(%o2) matrix([h-1,h,h+2,h+1,1],[1-h,2,-h-2,1,1],[h-1,h,1,0,1],[0,-h-2,0,-2,1])

(%i3) Mt:triangularize(M);
(%o3) matrix([h-1,h,1,0,1],[0,-h^2-h+2,0,2-2*h,h-1],
[0,0,-h^3-2*h^2+h+2,-h^3-2*h^2+h+2,0],
[0,0,0,-h^4-2*h^3+h^2+2*h,-3*h^3-6*h^2+3*h+6])

(%i4) ev(Mt,h=-1);
(%o4) matrix([-2,-1,1,0,1],[0,2,0,4,-2],[0,0,0,0,0],[0,0,0,0,0])

(%i5) Mr:triangularize(ev(M,h=-1));
(%o5) matrix([-2,-1,1,0,1],[0,-2,0,-2,-4],[0,0,0,2,-6],[0,0,0,0,0])

(%i9) rank(ev(Mt,h=-1));
(%o9) 2

(%i10)  rank(Mr);
(%o10) 3

(%i11) rank(ev(M,h=-1));
(%o11) 3

I have checked by hand, and Mt seems wrong (see the rank in the last
outputs). What's happening here? Is this a bug or I am missing
something?
The triangularization is correct if made over the only coefficient matrix.

Moreover, triangularize yelds to complicated expressions. See, in
example, the triangularization of the coefficient matrix above:

(%i20) Mc:submatrix(M,5);
(%o20) matrix([h-1,h,h+2,h+1],[1-h,2,-h-2,1],[h-1,h,1,0],[0,-h-2,0,-2])
(%i21) Mtc:triangularize(Mc);
(%o21) matrix([h-1,h,1,0],[0,-h^2-h+2,0,2-2*h],[0,0,h^3+2*h^2-h-2,h^2+h-2],
[0,0,0,h^4+2*h^3-h^2-2*h])

while with some simple rows transformations, we get:

(%i12) Mc[2]:Mc[2]+Mc[1];
(%o12) [0,h+2,0,h+2]

(%i13) Mc[3]:Mc[3]-Mc[1];
(%o13) [0,0,-h-1,-h-1]

(%i14) Mc[4]:Mc[4]+Mc[2];
(%o14) [0,0,0,h]

%i15) Mc;
(%o15) matrix([h-1,h,h+2,h+1],[0,h+2,0,h+2],[0,0,-h-1,-h-1],[0,0,0,h])

The latter expression looks better to me (it has ony first order terms).

Can someone please check these results?

Thanks.
Stefano
```