]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: ensure that we get a polynomial over the right ring in _charpoly_coeff().
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 29 Aug 2019 14:06:01 +0000 (10:06 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 29 Aug 2019 14:06:01 +0000 (10:06 -0400)
mjo/eja/eja_algebra.py

index d1658c2fba1aaf43e1115dee500bfd6b9c3602ac..c131c5f6b612a6ffcae8e1d3357264e5f016176e 100644 (file)
@@ -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