Repository: sagemath/sage

Issue:
Incorrect parent when evaluating constant multivariate polynomial
<div id="comment:0"></div>

When evaluating a univariate polynomial, it correctly takes the parent of the input into account:

```
sage: k.<a> = GF(2^4)
sage: R.<x> = PolynomialRing(k)
sage: f = R(1)
sage: S.<y> = PolynomialRing(k)
sage: f(y).parent()
Univariate Polynomial Ring in y over Finite Field in a of size 2^4
```
Multivariate polynomials do not:

```
sage: k.<a> = GF(2^4)
sage: R.<x> = PolynomialRing(k, 1)
sage: f = R(1)
sage: S.<y> = PolynomialRing(k, 1)
sage: f(y).parent()
Finite Field in a of size 2^4
```

Component: **algebra**

Keywords: **pAdicBordeaux**

Author: **David Roe**

Reviewer: **Marc Mezzarobba**

_Issue created by migration from https://trac.sagemath.org/ticket/33373_




Discussion:
Branch: **[u/roed/incorrect_parent_when_evaluating_constant_multivariate_polynomial](https://github.com/sagemath/sagetrac-mirror/tree/u/roed/incorrect_parent_when_evaluating_constant_multivariate_polynomial)**
Author: **David Roe**
Commit: **[`826061a`](https://github.com/sagemath/sagetrac-mirror/commit/826061adbb03db0d3140a38f798b4e267d960e56)**

Resolving patch:
diff --git a/src/sage/modular/modform_hecketriangle/graded_ring_element.py b/src/sage/modular/modform_hecketriangle/graded_ring_element.py
--- a/src/sage/modular/modform_hecketriangle/graded_ring_element.py
+++ b/src/sage/modular/modform_hecketriangle/graded_ring_element.py
@@ -1566,7 +1566,9 @@ def _q_expansion_cached(self, prec, fix_d, subs_d, d_num_prec, fix_prec = False)
         Y  = SC.f_i_ZZ().base_extend(formal_d.parent())
 
         if (self.parent().is_modular()):
-            qexp = self._rat.subs(x=X, y=Y, d=formal_d)
+            # z does not appear in self._rat but we need to specialize it for
+            # the evaluation to land in the correct parent
+            qexp = self._rat.subs(x=X, y=Y, z=0, d=formal_d)
         else:
             Z = SC.E2_ZZ().base_extend(formal_d.parent())
             qexp = self._rat.subs(x=X, y=Y, z=Z, d=formal_d)
diff --git a/src/sage/schemes/riemann_surfaces/riemann_surface.py b/src/sage/schemes/riemann_surfaces/riemann_surface.py
--- a/src/sage/schemes/riemann_surfaces/riemann_surface.py
+++ b/src/sage/schemes/riemann_surfaces/riemann_surface.py
@@ -2128,6 +2128,7 @@ def rigorous_line_integral(self, upstairs_edge, differentials, bounding_data):
         # CCzg is required to be known as we need to know the ring which the minpolys
         # lie in.
         CCzg, bounding_data_list = bounding_data
+        CCz = CCzg.univariate_ring(CCzg.gen(1)).base_ring()
 
         d_edge = tuple(u[0] for u in upstairs_edge)
         # Using a try-catch here allows us to retain a certain amount of back
@@ -2193,7 +2194,7 @@ def local_N(ct, rt):
                 z_1 = a0lc.abs() * prod((cz - r).abs() - rho_z for r in a0roots)
                 n = minpoly.degree(CCzg.gen(1))
                 ai_new = [
-                    (minpoly.coefficient({CCzg.gen(1): i}))(z=cz + self._CCz.gen(0))
+                    CCz(minpoly.coefficient({CCzg.gen(1): i}))(z=cz + self._CCz.gen(0))
                     for i in range(n)
                 ]
                 ai_pos = [self._RRz([c.abs() for c in h.list()]) for h in ai_new]
diff --git a/src/sage/schemes/toric/points.py b/src/sage/schemes/toric/points.py
--- a/src/sage/schemes/toric/points.py
+++ b/src/sage/schemes/toric/points.py
@@ -849,7 +849,7 @@ def inhomogeneous_equations(self, ring, nonzero_coordinates, cokernel):
         z = [ring.zero()] * nrays
         for i, value in zip(nonzero_coordinates, z_nonzero):
             z[i] = value
-        return [poly(z) for poly in self.polynomials]
+        return [poly.change_ring(ring)(z) for poly in self.polynomials]
 
     def solutions_serial(self, inhomogeneous_equations, log_range):
         """


Test patch: