# Zero Matrix has an Inverse over Finite Field?

The following code

M = Matrix([0], ring=GF(4))
M


Prints "[0]" as expected. The inverse of M clearly does not exist. Even so, running

M.inverse()


does not throw an error, and instead prints "[1]". What's going on here?

I am running Sage 8.1. Thanks for the help.

edit retag close merge delete

Sort by ยป oldest newest most voted

Looks like this bug is still present in current versions too. As far as I can see, it's limited to non-prime finite fields of characteristic 2 (which have their own implementation), and it does seem to apply to non-invertible square matrices of size larger than 1 too. I wasn't able to find a trac ticket for it, so please do report (should it be reported already, we can manage then). There's a good chance it's not too difficult to fix once someone with knowledge of the code looks at it.

more

1

Thank you, I will try my hand at making a ticket.

( 2020-07-16 23:45:54 +0200 )edit

Thanks for reporting this bug here and on Sage Trac:

To analyse the error coming from:

sage: M = Matrix([0], ring=GF(4))
sage: M
[0]
sage: M.inverse()
[1]


we can check the documentation and the source code for the inverse method of M:

sage: M.inverse?
sage: M.inverse??


and we see that it calls ~M. In Sage, ~M calls M.__invert__().

The source code for the __invert__ method revealed by

sage: M.__invert__??


involves mzed_invert_newton_john from m4rie.

The source code for that function is at

and it echelonizes the augmented matrix to compute the inverse --- a fine thing to do for an invertible matrix.

There is now a fix at the Sage Trac ticket. After the fix, we first check whether the matrix has full rank; if not, we raise an error; if yes, we compute the inverse by echelonizing the augmented matrix.

more