Skip to content

Commit 4462607

Browse files
author
Release Manager
committed
gh-38721: Type of Z/nZ NTL polynomial evaluation should be scalar <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> When a polynomial over Z/n implemented in NTL is evaluated, the result should be in Z/n. Currently it's not; it's still an element of the polynomial ring. Example: ``` sage: R.<x> = PolynomialRing(Zmod(4), 'x', implementation='NTL') sage: x.subs(1).parent() Univariate Polynomial Ring in x over Ring of integers modulo 4 (using NTL) ``` This patch fixes this behavior. URL: #38721 Reported by: Kyle Hofmann Reviewer(s): Kwankyu Lee
2 parents a875710 + 69f9a59 commit 4462607

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

+37-2
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,22 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n):
12531253
sage: S.<y> = PolynomialRing(Integers(5), implementation='NTL')
12541254
sage: f(y)
12551255
y^3 + 2
1256+
1257+
TESTS::
1258+
1259+
sage: R.<x> = PolynomialRing(Integers(100), implementation='NTL')
1260+
sage: f = x^3 + 7
1261+
sage: f(1).parent() == R.base_ring()
1262+
True
1263+
sage: f(int(1)).parent() == R.base_ring()
1264+
True
1265+
sage: f(x + 1).parent() == f.parent()
1266+
True
1267+
1268+
sage: R.<x> = PolynomialRing(Zmod(12), 'x', implementation='NTL')
1269+
sage: u = Zmod(4)(3)
1270+
sage: x(u).parent() == u.parent()
1271+
True
12561272
"""
12571273
if len(args) != 1 or len(kwds) != 0:
12581274
return Polynomial.__call__(self, *args, **kwds)
@@ -1273,7 +1289,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n):
12731289
return Polynomial.__call__(self, *args, **kwds)
12741290
else:
12751291
zz_pX_eval(fx.x, self.x, x.x)
1276-
return self._parent(int(fx))
1292+
return self._parent._base(int(fx))
12771293

12781294

12791295
cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n):
@@ -1808,6 +1824,25 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n):
18081824
sage: S.<y> = PolynomialRing(Integers(5), implementation='NTL')
18091825
sage: f(y)
18101826
y^3 + 2
1827+
1828+
TESTS::
1829+
1830+
sage: R.<x> = PolynomialRing(Integers(10^30), implementation='NTL')
1831+
sage: f = x^3 + 7
1832+
sage: f(1).parent() == R.base_ring()
1833+
True
1834+
sage: f(int(1)).parent() == R.base_ring()
1835+
True
1836+
sage: f(x + 1).parent() == f.parent()
1837+
True
1838+
1839+
sage: R.<x> = PolynomialRing(Zmod(10^30), 'x', implementation='NTL')
1840+
sage: u = Zmod(10^29)(3)
1841+
sage: x(u).parent() == u.parent()
1842+
True
1843+
sage: v = Zmod(10)(3)
1844+
sage: x(v).parent() == v.parent()
1845+
True
18111846
"""
18121847
if len(args) != 1 or len(kwds) != 0:
18131848
return Polynomial.__call__(self, *args, **kwds)
@@ -1826,7 +1861,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n):
18261861
return Polynomial.__call__(self, *args, **kwds)
18271862
else:
18281863
ZZ_pX_eval(fx.x, self.x, x.x)
1829-
return self._parent(fx._integer_())
1864+
return self._parent._base(fx._integer_())
18301865

18311866

18321867
cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n):

0 commit comments

Comments
 (0)