Skip to content

Commit

Permalink
Trac #29249: Fixing determinant for the zero matrix over the p-adics
Browse files Browse the repository at this point in the history
This fixes the bug below:
{{{
sage: matrix(Qp(37),[0]).determinant()
------------------------------------------------------------------------
---
UnboundLocalError                         Traceback (most recent call
last)
<ipython-input-323-f9ac4bb66315> in <module>()
----> 1 matrix(Zp(Integer(37)),[Integer(0)]).determinant()

/Applications/sage-dev/local/lib/python3.7/site-
packages/sage/matrix/matrix2.pyx in
sage.matrix.matrix2.Matrix.determinant
(build/cythonized/sage/matrix/matrix2.c:14548)()
   1640         R = self._base_ring
   1641         if hasattr(R, '_matrix_determinant'):
-> 1642             d = R._matrix_determinant(self)
   1643             self.cache('det', d)
   1644             return d

/Applications/sage-dev/local/lib/python3.7/site-
packages/sage/rings/padics/local_generic.py in _matrix_determinant(self,
M)
   1587                 break
   1588             val = curval
-> 1589             if S[pivi,pivj] == 0:
   1590                 if track_precision:
   1591                     return R(0, valdet + (n-piv)*val - shift)

UnboundLocalError: local variable 'pivi' referenced before assignment

}}}

URL: https://trac.sagemath.org/29249
Reported by: edgarcosta
Ticket author(s): Edgar Costa
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Feb 27, 2020
2 parents 610a582 + d5d16fe commit 103ed4b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/sage/rings/padics/local_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,10 @@ def _matrix_determinant(self, M):
True
sage: A.change_ring(QQ).det() == A.det()
True
sage: matrix(Qp(37),[0]).determinant()
0
sage: matrix(Qp(37),[O(37)]).determinant()
O(37)
"""
n = M.nrows()

Expand All @@ -1573,7 +1577,8 @@ def _matrix_determinant(self, M):
valdet = 0
val = -Infinity
for piv in range(n):
curval = Infinity
pivi = pivj = piv
curval = S[pivi, pivj].valuation()
for i in range(piv,n):
for j in range(piv,n):
v = S[i,j].valuation()
Expand Down

0 comments on commit 103ed4b

Please sign in to comment.