From e665779f0a07f31f53f7f1001dab9dc4cb7a0239 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 29 Aug 2019 10:06:01 -0400 Subject: [PATCH] eja: ensure that we get a polynomial over the right ring in _charpoly_coeff(). --- mjo/eja/eja_algebra.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 -- 2.44.2