ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 17 Jul 2020 12:18:06 -0500Zero Matrix has an Inverse over Finite Field?https://ask.sagemath.org/question/52487/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.Wed, 15 Jul 2020 21:15:30 -0500https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/Answer by slelievre for <p>The following code</p>
<pre><code>M = Matrix([0], ring=GF(4))
M
</code></pre>
<p>Prints "[0]" as expected. The inverse of M clearly does not exist. Even so, running</p>
<pre><code>M.inverse()
</code></pre>
<p>does not throw an error, and instead prints "[1]". What's going on here?</p>
<p>I am running Sage 8.1. Thanks for the help.</p>
https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?answer=52530#post-id-52530Thanks for reporting this bug here and on Sage Trac:
- [Sage Trac ticket #30161: Zero Matrix has Inverse over Finite Field](https://trac.sagemath.org/ticket/30161)
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
- https://github.com/malb/m4rie/blob/9f39ae950a733bd1e9ced74f59d9b594f5a7296c/src/newton_john.c#L508
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.
Fri, 17 Jul 2020 12:18:06 -0500https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?answer=52530#post-id-52530Answer by nbruin for <p>The following code</p>
<pre><code>M = Matrix([0], ring=GF(4))
M
</code></pre>
<p>Prints "[0]" as expected. The inverse of M clearly does not exist. Even so, running</p>
<pre><code>M.inverse()
</code></pre>
<p>does not throw an error, and instead prints "[1]". What's going on here?</p>
<p>I am running Sage 8.1. Thanks for the help.</p>
https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?answer=52515#post-id-52515Looks 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.Thu, 16 Jul 2020 15:06:01 -0500https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?answer=52515#post-id-52515Comment by brantmv for <p>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.</p>
https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?comment=52517#post-id-52517Thank you, I will try my hand at making a ticket.Thu, 16 Jul 2020 16:45:54 -0500https://ask.sagemath.org/question/52487/zero-matrix-has-an-inverse-over-finite-field/?comment=52517#post-id-52517