Skip to content
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

inverting a non-invertible matrix over RDF returns weird results #2468

Closed
aghitza opened this issue Mar 11, 2008 · 7 comments
Closed

inverting a non-invertible matrix over RDF returns weird results #2468

aghitza opened this issue Mar 11, 2008 · 7 comments

Comments

@aghitza
Copy link

aghitza commented Mar 11, 2008

Check this out:

sage: A = Matrix(RDF, [[1, 0], [0, 0]])
sage: A.inverse()

[nan nan]
[nan inf]

This is, to say the least, weird. This should throw a ZeroDivisionError instead.

Component: linear algebra

Issue created by migration from https://trac.sagemath.org/ticket/2468

@dfdeshom
Copy link

comment:2

I don't see why a ZeroDivisionError should be thrown. Note that Matlab doesn't complain either:

>> a = [1 0; 0 0];
>> inv(a)
Warning: Matrix is singular to working precision.

ans =

   Inf   Inf
   Inf   Inf

@williamstein
Copy link
Contributor

comment:3

I agree with dfdeshom. The relevant code that does the inverse is

result_invert = gsl_linalg_LU_invert(self._LU,self._p,M._matrix)

Note that 1/RDF(0) also doesn't give ZeroDivisionError:

sage: 1/RDF(0)
inf

So I think that (1) this ticket should be resolved with a patch
that simply adds a doctest with this nan/inf behavior and says
what the deal is in the docs.

@dfdeshom
Copy link

comment:4

I've added a patch that, in addition:

  • adds some doctests to this file
  • corrects a bug where subtraction of RDF matrices would always throw an error

@dfdeshom
Copy link

Attachment: 2468.hg.gz

correct a small typo in patch

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Mar 18, 2008

comment:5

Replying to @dfdeshom:

I've added a patch that, in addition:

  • adds some doctests to this file
  • corrects a bug where subtraction of RDF matrices would always throw an error

Very nice! Before the patch:

----------------------------------------------------------------------
| SAGE Version 2.10.4, Release Date: 2008-03-16                      |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------

sage: m = Matrix(RDF, [[1,2],[3,4]])
sage: n=m^2
sage: n+m

[ 8.0 12.0]
[18.0 26.0]
sage: n-m
---------------------------------------------------------------------------
<type 'exceptions.ValueError'>            Traceback (most recent call last)

/scratch/mabshoff/release-cycle/sage-2.11.alpha0/<ipython console> in <module>()

/scratch/mabshoff/release-cycle/sage-2.11.alpha0/element.pyx in sage.structure.element.ModuleElement.__sub__()

/scratch/mabshoff/release-cycle/sage-2.11.alpha0/coerce.pxi in sage.structure.element._sub_c()

/scratch/mabshoff/release-cycle/sage-2.11.alpha0/matrix_real_double_dense.pyx in sage.matrix.matrix_real_double_dense.Matrix_real_double_dense._sub_c_impl()

<type 'exceptions.ValueError'>: GSL routine had an error
sage:

I will add a doctest patch for this bug since it is currently missing.

Cheers,

Michael

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Mar 18, 2008

comment:6

Ok, I now figured out that you also added a doctest for the bug you fixed. So disregard my comment about adding a doctest.

Cheers,

Michael

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Mar 18, 2008

comment:7

Merged in Sage 2.11.alpha0

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Mar 18, 2008
@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-3.0, sage-2.11 Mar 18, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants