]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: improve how we get the "real part" of a possibly-complex trace.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 9 Nov 2020 16:59:21 +0000 (11:59 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 9 Nov 2020 16:59:21 +0000 (11:59 -0500)
mjo/eja/eja_algebra.py

index 10b8eb338514a0ec611ced0bb0a9ca169dc67411..4bef201cd2d0bbda251dbfd347cd9006185d82a5 100644 (file)
@@ -1258,16 +1258,11 @@ class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra):
         Yu = cls.real_unembed(Y)
         tr = (Xu*Yu).trace()
 
-        if tr in RLF:
-            # It's real already.
-            return tr
-
-        # Otherwise, try the thing that works for complex numbers; and
-        # if that doesn't work, the thing that works for quaternions.
         try:
-            return tr.vector()[0] # real part, imag part is index 1
+            # Works in QQ, AA, RDF, et cetera.
+            return tr.real()
         except AttributeError:
-            # A quaternions doesn't have a vector() method, but does
+            # A quaternion doesn't have a real() method, but does
             # have coefficient_tuple() method that returns the
             # coefficients of 1, i, j, and k -- in that order.
             return tr.coefficient_tuple()[0]