else:
basis = ( (b/n) for (b,n) in izip(self.natural_basis(),
self._basis_normalizers) )
- field = self.base_ring().base_ring() # yeeeaahhhhhhh
- J = MatrixEuclideanJordanAlgebra(field,
+
+ # Do this over the rationals and convert back at the end.
+ J = MatrixEuclideanJordanAlgebra(QQ,
basis,
self.rank(),
normalize_basis=False)
# p might be missing some vars, have to substitute "optionally"
pairs = izip(x.base_ring().gens(), self._basis_normalizers)
substitutions = { v: v*c for (v,c) in pairs }
- return p.subs(substitutions)
+ result = p.subs(substitutions)
+
+ # The result of "subs" can be either a coefficient-ring
+ # element or a polynomial. Gotta handle both cases.
+ if result in QQ:
+ return self.base_ring()(result)
+ else:
+ return result.change_ring(self.base_ring())
@staticmethod