Ask Your Question

Zero Matrix has an Inverse over Finite Field?

asked 2020-07-15 21:15:30 -0600

brantmv gravatar image

updated 2020-07-17 12:03:00 -0600

slelievre gravatar image

The following code

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

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


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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2020-07-16 15:06:01 -0600

nbruin gravatar image

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.

edit flag offensive delete link more



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

brantmv gravatar imagebrantmv ( 2020-07-16 16:45:54 -0600 )edit

answered 2020-07-17 12:18:06 -0600

slelievre gravatar image

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
sage: M.inverse()

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-07-15 21:15:30 -0600

Seen: 56 times

Last updated: Jul 17 '20