# Revision history [back]

### The minimum of a matrix

So I have been writing some code using Sage, which by the way is awesome so far. And I had some simple check to do, i.e. all elements of some matrices have to be nonnegative. So I figured I would just see if the minimum of these matrices is nonnegative. In programms like matlab this is usualy achieved by min(min(A)) for some matrix A. I figured it would be the same for sage, so I tested this to be sure and everything seemed to work. But then I stumbeled upon something weird and I found this case (that is this is some of the output of the case)

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000   4.4444   5.5556  0.00000]
[ 0.00000  0.00000   5.5556 -0.55556  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000  1.0000 0.00000 0.00000]
[0.00000 0.00000  1.3333  1.6667 0.00000]
[ 1.0000  1.3333  4.4444  2.2222  1.0000]
[0.00000  1.6667  2.2222  1.1111 0.00000]
[0.00000 0.00000  1.0000 0.00000 0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
[ 0.00000  0.00000   3.3333 -0.33333  0.00000]
[ 0.00000   3.3333   4.4444   2.2222  0.00000]
[  1.0000 -0.33333   2.2222   1.1111   1.0000]
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, 0, 0, 0, 0]


Now I actually have a case which is very similar, that is, it is a permutation of these set of matrices above and for those I do get the correct answers

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000 -0.55556   5.5556  0.00000]
[ 0.00000  0.00000   5.5556   4.4444  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
[ 0.00000  0.00000 -0.33333   3.3333  0.00000]
[  1.0000 -0.33333   1.1111   2.2222   1.0000]
[ 0.00000   3.3333   2.2222   4.4444  0.00000]
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000  1.0000 0.00000]
[0.00000 0.00000  1.6667  1.3333 0.00000]
[0.00000  1.6667  1.1111  2.2222 0.00000]
[ 1.0000  1.3333  2.2222  4.4444  1.0000]
[0.00000 0.00000 0.00000  1.0000 0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, -5/9, -1/3, 0, 0]


So apparently the min operator is not doing exactly what I thought it is doing, w.r.t. matrices? Or is this a weird bug?

### The minimum of a matrix

So I have been writing some code using Sage, which by the way is awesome so far. And I had some simple check to do, i.e. all elements of some matrices have to be nonnegative. So I figured I would just see if the minimum of these matrices is nonnegative. In programms like matlab this is usualy achieved by min(min(A)) for some matrix A. I figured it would be the same for sage, so I tested this to be sure and everything seemed to work. But then I stumbeled upon something weird and I found this case (that is this is some of the output of the case)case). These are the 5 matrices followed by the minima of the same 5 matrices respectively.

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000   4.4444   5.5556  0.00000]
[ 0.00000  0.00000   5.5556 -0.55556  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000  1.0000 0.00000 0.00000]
[0.00000 0.00000  1.3333  1.6667 0.00000]
[ 1.0000  1.3333  4.4444  2.2222  1.0000]
[0.00000  1.6667  2.2222  1.1111 0.00000]
[0.00000 0.00000  1.0000 0.00000 0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
[ 0.00000  0.00000   3.3333 -0.33333  0.00000]
[ 0.00000   3.3333   4.4444   2.2222  0.00000]
[  1.0000 -0.33333   2.2222   1.1111   1.0000]
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, 0, 0, 0, 0]


Now I actually have a case which is very similar, that is, it is a permutation of these set of matrices above and for those I do get the correct answers

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000 -0.55556   5.5556  0.00000]
[ 0.00000  0.00000   5.5556   4.4444  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
[ 0.00000  0.00000 -0.33333   3.3333  0.00000]
[  1.0000 -0.33333   1.1111   2.2222   1.0000]
[ 0.00000   3.3333   2.2222   4.4444  0.00000]
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000  1.0000 0.00000]
[0.00000 0.00000  1.6667  1.3333 0.00000]
[0.00000  1.6667  1.1111  2.2222 0.00000]
[ 1.0000  1.3333  2.2222  4.4444  1.0000]
[0.00000 0.00000 0.00000  1.0000 0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, -5/9, -1/3, 0, 0]


So apparently the min operator is not doing exactly what I thought it is doing, w.r.t. matrices? Or is this a weird bug?

### The minimum of a matrix

So I have been writing some code using Sage, which by the way is awesome so far. And I had some simple check to do, i.e. all elements of some matrices have to be nonnegative. So I figured I would just see if the minimum of these matrices is nonnegative. In programms like matlab this is usualy achieved by min(min(A)) for some matrix A. I figured it would be the same for sage, so I tested this to be sure and everything seemed to work. But then I stumbeled upon something weird and I found this case (that is this is some of the output of the case). These are the 5 matrices followed by the minima of the same 5 matrices respectively.

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000   4.4444   5.5556  0.00000]
[ 0.00000  0.00000   5.5556 -0.55556  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000  1.0000 0.00000 0.00000]
[0.00000 0.00000  1.3333  1.6667 0.00000]
[ 1.0000  1.3333  4.4444  2.2222  1.0000]
[0.00000  1.6667  2.2222  1.1111 0.00000]
[0.00000 0.00000  1.0000 0.00000 0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
[ 0.00000  0.00000   3.3333 -0.33333  0.00000]
[ 0.00000   3.3333   4.4444   2.2222  0.00000]
[  1.0000 -0.33333   2.2222   1.1111   1.0000]
[ 0.00000  0.00000  0.00000   1.0000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  10.000 0.00000 0.00000]
[0.00000 0.00000 0.00000  5.0000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, 0, 0, 0, 0]


Now I actually have a case which is very similar, that is, it is a permutation of these set of matrices above and for those I do get the correct answers

[ 1.0000 0.00000 0.00000 0.00000 0.00000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[0.00000 0.00000 0.00000 0.00000  1.0000]
-------------------------------------------------------------
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
[  1.0000   1.0000  0.00000  0.00000   1.0000]
[ 0.00000  0.00000 -0.55556   5.5556  0.00000]
[ 0.00000  0.00000   5.5556   4.4444  0.00000]
[ 0.00000   1.0000  0.00000  0.00000  0.00000]
-------------------------------------------------------------
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
[ 0.00000  0.00000 -0.33333   3.3333  0.00000]
[  1.0000 -0.33333   1.1111   2.2222   1.0000]
[ 0.00000   3.3333   2.2222   4.4444  0.00000]
[ 0.00000  0.00000   1.0000  0.00000  0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000  1.0000 0.00000]
[0.00000 0.00000  1.6667  1.3333 0.00000]
[0.00000  1.6667  1.1111  2.2222 0.00000]
[ 1.0000  1.3333  2.2222  4.4444  1.0000]
[0.00000 0.00000 0.00000  1.0000 0.00000]
-------------------------------------------------------------
[0.00000 0.00000 0.00000 0.00000  1.0000]
[0.00000  3.0000 0.00000 0.00000 0.00000]
[0.00000 0.00000  5.0000 0.00000 0.00000]
[0.00000 0.00000 0.00000  10.000 0.00000]
[ 1.0000 0.00000 0.00000 0.00000 0.00000]
-----minima--------------------------------------------------
[0, -5/9, -1/3, 0, 0]


So apparently the min operator is not doing exactly what I thought it is doing, w.r.t. matrices? Or is this a weird bug?

Edit: so to be clear the minima were obtained like this

print([min(min(Q0)),min(min(Q1)),min(min(Q2)),min(min(Q3)),min(min(Q4))])


Where the matrices Q0,...,Q4 are the 5 by 5 matrices printed above, which were made over QQ (rationals).