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]