@@ -2056,6 +2056,15 @@ cdef class MPolynomial_libsingular(MPolynomial):
2056
2056
9
2057
2057
sage: a. parent( ) is QQ
2058
2058
True
2059
+
2060
+ See :trac:`33373`::
2061
+
2062
+ sage: k. <a> = GF( 2^ 4)
2063
+ sage: R. <x> = PolynomialRing( k, 1)
2064
+ sage: f = R( 1)
2065
+ sage: S. <y> = PolynomialRing( k, 1)
2066
+ sage: f( y) . parent( )
2067
+ Multivariate Polynomial Ring in y over Finite Field in a of size 2^ 4
2059
2068
"""
2060
2069
if len (kwds) > 0 :
2061
2070
f = self .subs(** kwds)
@@ -2075,29 +2084,28 @@ cdef class MPolynomial_libsingular(MPolynomial):
2075
2084
if l != parent._ring.N:
2076
2085
raise TypeError (" number of arguments does not match number of variables in parent" )
2077
2086
2087
+ res_parent = coercion_model.common_parent(parent._base, * x)
2088
+ cdef poly * res # ownership will be transferred to us in the else block
2078
2089
try :
2079
2090
# Attempt evaluation via singular.
2080
2091
coerced_x = [parent.coerce(e) for e in x]
2081
2092
except TypeError :
2082
2093
# give up, evaluate functional
2083
- y = parent.base_ring().zero()
2094
+ sage_res = parent.base_ring().zero()
2084
2095
for (m,c) in self .dict().iteritems():
2085
- y += c* mul([ x[i]** m[i] for i in m.nonzero_positions()])
2086
- return y
2087
-
2088
- cdef poly * res # ownership will be transferred to us in the next line
2089
- singular_polynomial_call(& res, self ._poly, _ring, coerced_x, MPolynomial_libsingular_get_element)
2090
- res_parent = coercion_model.common_parent(parent._base, * x)
2091
-
2092
- if res == NULL :
2093
- return res_parent(0 )
2094
- if p_LmIsConstant(res, _ring):
2095
- sage_res = si2sa( p_GetCoeff(res, _ring), _ring, parent._base )
2096
- p_Delete(& res, _ring) # sage_res contains copy
2096
+ sage_res += c* mul([ x[i]** m[i] for i in m.nonzero_positions()])
2097
2097
else :
2098
- sage_res = new_MP(parent, res) # pass on ownership of res to sage_res
2098
+ singular_polynomial_call(& res, self ._poly, _ring, coerced_x, MPolynomial_libsingular_get_element)
2099
+
2100
+ if res == NULL :
2101
+ return res_parent(0 )
2102
+ if p_LmIsConstant(res, _ring):
2103
+ sage_res = si2sa( p_GetCoeff(res, _ring), _ring, parent._base )
2104
+ p_Delete(& res, _ring) # sage_res contains copy
2105
+ else :
2106
+ sage_res = new_MP(parent, res) # pass on ownership of res to sage_res
2099
2107
2100
- if parent(sage_res ) is not res_parent:
2108
+ if sage_res. parent() is not res_parent:
2101
2109
sage_res = res_parent(sage_res)
2102
2110
return sage_res
2103
2111
0 commit comments