- cs = self.characteristic_polynomial().coefficients(sparse=False)
- r = len(cs) - 1
- if r >= 0:
- return cs[0] * (-1)**r
- else:
- raise ValueError('charpoly had no coefficients')
+ P = self.parent()
+ r = P.rank()
+ p = P._charpoly_coeff(0)
+ # The _charpoly_coeff function already adds the factor of
+ # -1 to ensure that _charpoly_coeff(0) is really what
+ # appears in front of t^{0} in the charpoly. However,
+ # we want (-1)^r times THAT for the determinant.
+ return ((-1)**r)*p(*self.vector())