New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matrix inverse over CC raises ZeroDivisionError #2256
Comments
comment:1
I made a similar ticket with the same issue with RQDF. I think the following is the underlying problem:
|
comment:2
mhansen's comment is right on. Indeed, SAGE is successfully computing the inverse, but the
Ah, the joys of inexact fields. See also the ticket #3162. |
comment:3
I'm attaching a patch which doesn't completely fix this, but makes it better -- I think. First, a brief description of the problem: the code creates an augmented matrix, puts it in echelon form, and asks if the lower right entry of the left half is equal to 1. This is correct over an exact field, but over an inexact ring like Now, if we're working over a base ring which we know is a field (or at least models a field), then we know the lower right entry of the matrix must be either 1 or 0. So rather than test to see if something equals 1, I simply test that the lower right entry is not 0. A better solution would be to ask that the determinant is nonzero -- unfortunately, our determinant over general inexact fields is a joke, and can't even deal with a Comments: This still isn't perfect -- it's easy enough to imagine cases where numerical instability causes trouble. Note that the current behavior is basically always wrong (since it almost always claims the matrix isn't invertible when it is), and it's also pretty confusing to newcomers. The new code has the disadvantage that it can now offer to return an inverse for non-invertible matrices, based on numerical issues. However, I think that to someone who's used matrices over inexact rings before in their life, this isn't so surprising -- it's just the way it goes with approximations. I don't know what the "right" solution is -- we should probably ask someone who studies numerical analysis. I'm adding |
comment:4
Attachment: trac-2256.patch.gz The LU decomposition patch at #3048 may go a long ways towards helping this. At least the determinant then is much, much better. Or even better, just examine the U of the LU decomposition and decide if a diagonal entry is zero (which avoids the overhead of a product). The LU decomposition patch (#3048) also changes the inverse function to use sove_right (which uses LU decomposition) as in general, that should be faster anyway. The real way to do this is to have a rank function which works by looking at the smallest singular value. That requires having a singular value decomposition... |
Reviewer: Jason Grout, Nick Alexander |
Merged: 4.0.2.alpha0 |
Author: Craig Citro |
comment:5
The LU stuff is not ready and this at least improves the situation. |
CC: @ncalexan @jasongrout @sagetrac-cwitty @robertwb
Component: linear algebra
Keywords: matrix inverse CC complex
Author: Craig Citro
Reviewer: Jason Grout, Nick Alexander
Merged: 4.0.2.alpha0
Issue created by migration from https://trac.sagemath.org/ticket/2256
The text was updated successfully, but these errors were encountered: