EXAMPLES::
sage: J = JordanSpinEJA(3)
- sage: e0,e1,e2 = J.gens()
- sage: x = e0 + e1 + e2
+ sage: x = sum(J.gens())
sage: x.trace()
2
+ ::
+
+ sage: J = RealCartesianProductEJA(5)
+ sage: J.one().trace()
+ 5
+
+ TESTS:
+
+ The trace of an element is a real number::
+
+ sage: set_random_seed()
+ sage: J = random_eja()
+ sage: J.random_element().trace() in J.base_ring()
+ True
+
"""
- cs = self.characteristic_polynomial().coefficients(sparse=False)
- if len(cs) >= 2:
- return -1*cs[-2]
- else:
- raise ValueError('charpoly had fewer than 2 coefficients')
+ P = self.parent()
+ r = P.rank()
+ p = P._charpoly_coeff(r-1)
+ # The _charpoly_coeff function already adds the factor of
+ # -1 to ensure that _charpoly_coeff(r-1) is really what
+ # appears in front of t^{r-1} in the charpoly. However,
+ # we want the negative of THAT for the trace.
+ return -p(*self.vector())
def trace_inner_product(self, other):