Skip to content

Commit 2b03a1a

Browse files
author
Release Manager
committed
gh-35045: Convert result of multivariate polynomial evaluation into correct parent Importing trac/u/roed/incorrect_parent_when_evaluating_constant_multivar iate_polynomial... (meant to fix #33373) URL: #35045 Reported by: Marc Mezzarobba Reviewer(s): Marc Mezzarobba, Travis Scrimshaw
2 parents f6da2bd + 042fdc5 commit 2b03a1a

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

src/sage/modular/modform_hecketriangle/graded_ring_element.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,9 @@ def _q_expansion_cached(self, prec, fix_d, subs_d, d_num_prec, fix_prec = False)
15661566
Y = SC.f_i_ZZ().base_extend(formal_d.parent())
15671567

15681568
if (self.parent().is_modular()):
1569-
qexp = self._rat.subs(x=X, y=Y, d=formal_d)
1569+
# z does not appear in self._rat but we need to specialize it for
1570+
# the evaluation to land in the correct parent
1571+
qexp = self._rat.subs(x=X, y=Y, z=0, d=formal_d)
15701572
else:
15711573
Z = SC.E2_ZZ().base_extend(formal_d.parent())
15721574
qexp = self._rat.subs(x=X, y=Y, z=Z, d=formal_d)

src/sage/rings/polynomial/multi_polynomial_libsingular.pyx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,18 @@ cdef class MPolynomial_libsingular(MPolynomial):
20572057
9
20582058
sage: a.parent() is QQ
20592059
True
2060+
2061+
See :trac:`33373`::
2062+
2063+
sage: k.<a> = GF(2^4)
2064+
sage: R.<x> = PolynomialRing(k, 1)
2065+
sage: f = R(1)
2066+
sage: S.<y> = PolynomialRing(k, 1)
2067+
sage: f(y).parent()
2068+
Multivariate Polynomial Ring in y over Finite Field in a of size 2^4
20602069
"""
2070+
cdef Element sage_res
2071+
20612072
if len(kwds) > 0:
20622073
f = self.subs(**kwds)
20632074
if len(x) > 0:
@@ -2076,29 +2087,28 @@ cdef class MPolynomial_libsingular(MPolynomial):
20762087
if l != parent._ring.N:
20772088
raise TypeError("number of arguments does not match number of variables in parent")
20782089

2090+
res_parent = coercion_model.common_parent(parent._base, *x)
2091+
cdef poly *res # ownership will be transferred to us in the else block
20792092
try:
20802093
# Attempt evaluation via singular.
20812094
coerced_x = [parent.coerce(e) for e in x]
20822095
except TypeError:
20832096
# give up, evaluate functional
2084-
y = parent.base_ring().zero()
2097+
sage_res = parent.base_ring().zero()
20852098
for (m,c) in self.dict().iteritems():
2086-
y += c*mul([ x[i]**m[i] for i in m.nonzero_positions()])
2087-
return y
2088-
2089-
cdef poly *res # ownership will be transferred to us in the next line
2090-
singular_polynomial_call(&res, self._poly, _ring, coerced_x, MPolynomial_libsingular_get_element)
2091-
res_parent = coercion_model.common_parent(parent._base, *x)
2092-
2093-
if res == NULL:
2094-
return res_parent(0)
2095-
if p_LmIsConstant(res, _ring):
2096-
sage_res = si2sa( p_GetCoeff(res, _ring), _ring, parent._base )
2097-
p_Delete(&res, _ring) # sage_res contains copy
2099+
sage_res += c * mul([x[i] ** m[i] for i in m.nonzero_positions()])
20982100
else:
2099-
sage_res = new_MP(parent, res) # pass on ownership of res to sage_res
2101+
singular_polynomial_call(&res, self._poly, _ring, coerced_x, MPolynomial_libsingular_get_element)
2102+
2103+
if res == NULL:
2104+
return res_parent(0)
2105+
if p_LmIsConstant(res, _ring):
2106+
sage_res = si2sa( p_GetCoeff(res, _ring), _ring, parent._base )
2107+
p_Delete(&res, _ring) # sage_res contains copy
2108+
else:
2109+
sage_res = new_MP(parent, res) # pass on ownership of res to sage_res
21002110

2101-
if parent(sage_res) is not res_parent:
2111+
if sage_res._parent is not res_parent:
21022112
sage_res = res_parent(sage_res)
21032113
return sage_res
21042114

src/sage/schemes/riemann_surfaces/riemann_surface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ def rigorous_line_integral(self, upstairs_edge, differentials, bounding_data):
21282128
# CCzg is required to be known as we need to know the ring which the minpolys
21292129
# lie in.
21302130
CCzg, bounding_data_list = bounding_data
2131+
CCz = CCzg.univariate_ring(CCzg.gen(1)).base_ring()
21312132

21322133
d_edge = tuple(u[0] for u in upstairs_edge)
21332134
# Using a try-catch here allows us to retain a certain amount of back
@@ -2193,7 +2194,7 @@ def local_N(ct, rt):
21932194
z_1 = a0lc.abs() * prod((cz - r).abs() - rho_z for r in a0roots)
21942195
n = minpoly.degree(CCzg.gen(1))
21952196
ai_new = [
2196-
(minpoly.coefficient({CCzg.gen(1): i}))(z=cz + self._CCz.gen(0))
2197+
CCz(minpoly.coefficient({CCzg.gen(1): i}))(z=cz + self._CCz.gen(0))
21972198
for i in range(n)
21982199
]
21992200
ai_pos = [self._RRz([c.abs() for c in h.list()]) for h in ai_new]

src/sage/schemes/toric/points.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def inhomogeneous_equations(self, ring, nonzero_coordinates, cokernel):
849849
z = [ring.zero()] * nrays
850850
for i, value in zip(nonzero_coordinates, z_nonzero):
851851
z[i] = value
852-
return [poly(z) for poly in self.polynomials]
852+
return [poly.change_ring(ring)(z) for poly in self.polynomials]
853853

854854
def solutions_serial(self, inhomogeneous_equations, log_range):
855855
"""

0 commit comments

Comments
 (0)