]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add det() and trace() for regular elements.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 29 Jun 2019 17:26:13 +0000 (13:26 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 29 Jul 2019 03:19:01 +0000 (23:19 -0400)
mjo/eja/euclidean_jordan_algebra.py

index a55b7e39ff43cd0607284ee272e077d972f3ce71..2404af03d7f249fec64caab63e9954aca91af7ab 100644 (file)
@@ -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):
     """