]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: implement element trace in terms of charpoly coefficients.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 23 Jul 2019 04:38:48 +0000 (00:38 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 29 Jul 2019 03:19:01 +0000 (23:19 -0400)
mjo/eja/euclidean_jordan_algebra.py

index 44ec225b35e4468dd34661983e186e2c429652dc..a0ba1c68bb30bf54383807c52961ad82e4a69f03 100644 (file)
@@ -1190,17 +1190,34 @@ class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra):
             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):