Opened 13 years ago

Closed 13 years ago

#3734 closed defect (fixed)

[with patch, positive review] inverse() fails for 0 by 0 matrices

Reported by: cremona Owned by: was
Priority: minor Milestone: sage-3.1
Component: linear algebra Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

As reported to sage-devel on 2008-07-19:

Puzzle question:  find a matrix with rank 0 but determinant 1:

sage: type(M)
<type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
sage: M.rank()
0
sage: M.determinant()
1.00000000000000

Answer:  M is 0x0:
sage: M
[]
sage: [M.nrows(), M.ncols()]
[0, 0]

Now I am happy with all that (since I am computing regulators of
elliptic curves which may have rank 0).  And with this:
sage: M.is_invertible()
True
but then disappointed by this:
sage: M.inverse()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/home/john/sage-3.0.4/<ipython console> in <module>()

/home/john/sage-3.0.4/matrix2.pyx in
sage.matrix.matrix2.Matrix.inverse (sage/matrix/matrix2.c:19932)()

/home/john/sage-3.0.4/matrix0.pyx in
sage.matrix.matrix0.Matrix.__invert__ (sage/matrix/matrix0.c:14525)()

/home/john/sage-3.0.4/matrix0.pyx in
sage.matrix.matrix0.Matrix.__getitem__ (sage/matrix/matrix0.c:3129)()

IndexError: matrix index out of range

The matrix inversion code should catch this case and return the same matrix.

Attachments (1)

sage-trac3734.patch (1.4 KB) - added by cremona 13 years ago.

Download all attachments as: .zip

Change History (5)

Changed 13 years ago by cremona

comment:1 Changed 13 years ago by cremona

  • Summary changed from inverse() fails for 0 by 0 matrices to [with patch, needs review] inverse() fails for 0 by 0 matrices

Before:

sage: MatrixSpace(ZZ,0,0)(0).inverse()  
[]
sage: MatrixSpace(QQ,0,0)(0).inverse()
[]
sage: MatrixSpace(RR,0,0)(0).inverse()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/home/john/sage-3.0.4/<ipython console> in <module>()

/home/john/sage-3.0.4/matrix2.pyx in sage.matrix.matrix2.Matrix.inverse (sage/matrix/matrix2.c:19932)()

/home/john/sage-3.0.4/matrix0.pyx in sage.matrix.matrix0.Matrix.__invert__ (sage/matrix/matrix0.c:14525)()

/home/john/sage-3.0.4/matrix0.pyx in sage.matrix.matrix0.Matrix.__getitem__ (sage/matrix/matrix0.c:3129)()

IndexError: matrix index out of range

After applying sage-trac3734.patch:

sage: MatrixSpace(ZZ,0,0)(0).inverse()
[]
sage: MatrixSpace(QQ,0,0)(0).inverse()
[]
sage: MatrixSpace(RR,0,0)(0).inverse()
[]

Patch was based on 3.0.4

comment:2 Changed 13 years ago by mabshoff

  • Milestone set to sage-3.1.1

comment:3 Changed 13 years ago by dfdeshom

  • Summary changed from [with patch, needs review] inverse() fails for 0 by 0 matrices to [with patch, positive review] inverse() fails for 0 by 0 matrices

Patch looks good to me.

comment:4 Changed 13 years ago by mabshoff

  • Milestone changed from sage-3.1.1 to sage-3.1
  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.1.alpha0

Note: See TracTickets for help on using tickets.