From: Michael Orlitzky Date: Sat, 29 Jun 2019 17:26:13 +0000 (-0400) Subject: eja: add det() and trace() for regular elements. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=cd902de2b1956ec808d084941b503ba7b08677d5;p=sage.d.git eja: add det() and trace() for regular elements. --- diff --git a/mjo/eja/euclidean_jordan_algebra.py b/mjo/eja/euclidean_jordan_algebra.py index a55b7e3..2404af0 100644 --- a/mjo/eja/euclidean_jordan_algebra.py +++ b/mjo/eja/euclidean_jordan_algebra.py @@ -138,7 +138,33 @@ class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra): if self.is_regular(): return self.minimal_polynomial() else: - return NotImplementedError('irregular element') + raise NotImplementedError('irregular element') + + + def det(self): + """ + Return my determinant, the product of my eigenvalues. + + EXAMPLES:: + + sage: J = eja_ln(2) + sage: e0,e1 = J.gens() + sage: x = e0 + e1 + sage: x.det() + 0 + sage: J = eja_ln(3) + sage: e0,e1,e2 = J.gens() + sage: x = e0 + e1 + e2 + sage: x.det() + -1 + + """ + 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') def is_nilpotent(self): @@ -462,6 +488,25 @@ class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra): return self.parent().linear_combination(zip(c_coordinates, basis)) + def trace(self): + """ + Return my trace, the sum of my eigenvalues. + + EXAMPLES:: + + sage: J = eja_ln(3) + sage: e0,e1,e2 = J.gens() + sage: x = e0 + e1 + e2 + sage: x.trace() + 2 + + """ + cs = self.characteristic_polynomial().coefficients(sparse=False) + if len(cs) >= 2: + return -1*cs[-2] + else: + raise ValueError('charpoly had fewer than 2 coefficients') + def eja_rn(dimension, field=QQ): """