From: Michael Orlitzky Date: Thu, 29 Aug 2019 14:06:01 +0000 (-0400) Subject: eja: ensure that we get a polynomial over the right ring in _charpoly_coeff(). X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e665779f0a07f31f53f7f1001dab9dc4cb7a0239;p=sage.d.git eja: ensure that we get a polynomial over the right ring in _charpoly_coeff(). --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index d1658c2..c131c5f 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -939,8 +939,9 @@ class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra): 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) @@ -949,7 +950,14 @@ class MatrixEuclideanJordanAlgebra(FiniteDimensionalEuclideanJordanAlgebra): # 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