#6442: Random(?) index error with determinant method
------------------------------+---------------------------------------------
Reporter: spancratz | Owner: somebody
Type: defect | Status: new
Priority: major | Milestone:
Component: linear algebra | Keywords: det, determinant, IndexError
Work_issues: | Upstream: N/A
Reviewer: | Author: Sebastian Pancratz
Merged: | Dependencies:
------------------------------+---------------------------------------------
Changes (by mjo):
* cc: mjo (added)
* upstream: => N/A
Comment:
We've got two charpoly() algorithms at the moment, but back when this bug
was reported, I think the hessenberg algorithm was the default. If we try
charpoly() on this matrix,
{{{
sage: A = load('/home/mjo/DetBugMatrix.sobj')
sage: A.charpoly(algorithm='hessenberg')
...
ValueError: element valuation cannot be negative.
}}}
If we look at the code for charpoly(), we see that the empty hash {} is
cached before the attempt to compute charpoly(). In matrix2.pyx,
{{{
D = self.fetch('charpoly')
if not D is None:
if D.has_key(var):
return D[var]
else:
D = {}
self.cache('charpoly',D)
<compute the charpoly>
# Cache the result
D[var] = f
return f
}}}
So if computation of charpoly() fails, we'll have {} cached, and det()
will blow up. A full example:
{{{
sage: A = load('/home/mjo/DetBugMatrix.sobj')
sage: A.charpoly(algorithm='hessenberg')
...
ValueError: element valuation cannot be negative.
sage: A.det()
...
IndexError: list index out of range
sage: A.charpoly()
(1 + O(5^3))*x^10 + (2 + 4*5 + 2*5^2 + O(5^3))*x^9 + (4 + 4*5 + 4*5^2 +
O(5^3))*x^8 + (4 + 5^2 + O(5^3))*x^7 + (4*5^2 + O(5^3))*x^6 + (3 + 5 + 5^2
+ O(5^3))*x^5 + (1 + 3*5 + 5^2 + O(5^3))*x^4 + (1 + 4*5 + 4*5^2 +
O(5^3))*x^3 + (1 + 4*5 + 4*5^2 + O(5^3))*x^2 + (2 + 4*5 + 4*5^2 +
O(5^3))*x + (2*5 + 4*5^2 + O(5^3))
sage: A.det()
2*5 + 4*5^2 + O(5^3)
}}}
So the solution, I think, is to avoid caching the empty hash until we know
we've got a charpoly.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6442#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.