True
"""
not_invertible_msg = "element is not invertible"
- if self.parent()._charpoly_coefficients.is_in_cache():
+
+ algebra = self.parent()
+ if algebra._charpoly_coefficients.is_in_cache():
# We can invert using our charpoly if it will be fast to
# compute. If the coefficients are cached, our rank had
# better be too!
if self.det().is_zero():
raise ZeroDivisionError(not_invertible_msg)
- r = self.parent().rank()
+ r = algebra.rank()
a = self.characteristic_polynomial().coefficients(sparse=False)
- return (-1)**(r+1)*sum(a[i+1]*self**i for i in range(r))/self.det()
+ return (-1)**(r+1)*algebra.sum(a[i+1]*self**i
+ for i in range(r))/self.det()
try:
inv = (~self.quadratic_representation())(self)