From cc75c4e093a920c44f1eaaef4a1baa525b5c5727 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 23 Jul 2019 00:38:48 -0400 Subject: [PATCH] eja: implement element trace in terms of charpoly coefficients. --- mjo/eja/euclidean_jordan_algebra.py | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mjo/eja/euclidean_jordan_algebra.py b/mjo/eja/euclidean_jordan_algebra.py index 44ec225..a0ba1c6 100644 --- a/mjo/eja/euclidean_jordan_algebra.py +++ b/mjo/eja/euclidean_jordan_algebra.py @@ -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): -- 2.44.2