Skip to content

Commit 8774a72

Browse files
committed
reviewer's fixes
1 parent 223820d commit 8774a72

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from sage.matrix.constructor import matrix
2121
from sage.misc.cachefunc import cached_method
2222
from sage.modules.free_module_element import vector
23-
from sage.rings.integer import Integer
2423
from sage.rings.integer_ring import ZZ
2524
from sage.rings.polynomial.polynomial_ring import polygen
2625
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
@@ -77,6 +76,12 @@ class IntegerValuedPolynomialRing(UniqueRepresentation, Parent):
7776
TypeError: argument R must be a commutative ring
7877
"""
7978
def __init__(self, R):
79+
"""
80+
TESTS::
81+
82+
sage: IV = IntegerValuedPolynomialRing(ZZ)
83+
sage: TestSuite(IV).run()
84+
"""
8085
if R not in Rings().Commutative():
8186
raise TypeError("argument R must be a commutative ring")
8287
self._base = R
@@ -97,6 +102,20 @@ def _repr_(self) -> str:
97102
br = self.base_ring()
98103
return f"Integer-Valued Polynomial Ring over {br}"
99104

105+
def a_realization(self):
106+
"""
107+
Return a default realization.
108+
109+
The Binomial realization is chosen.
110+
111+
EXAMPLES::
112+
113+
sage: IntegerValuedPolynomialRing(QQ).a_realization()
114+
Integer-Valued Polynomial Ring over Rational Field
115+
in the binomial basis
116+
"""
117+
return self.Binomial()
118+
100119
class Bases(Category_realization_of_parent):
101120
def super_categories(self) -> list:
102121
r"""
@@ -223,10 +242,12 @@ def from_polynomial(self, p):
223242
result += top_coeff * B[N]
224243
return result
225244

226-
def gen(self):
245+
def gen(self, i=0):
227246
r"""
228247
Return the generator of this algebra.
229248
249+
The optional argument is ignored.
250+
230251
EXAMPLES::
231252
232253
sage: F = IntegerValuedPolynomialRing(ZZ).B()
@@ -334,8 +355,14 @@ def sum_of_coefficients(self):
334355
sage: B = F.basis()
335356
sage: (B[2]*B[4]).sum_of_coefficients()
336357
1
358+
359+
TESTS::
360+
361+
sage: (0*B[2]).sum_of_coefficients().parent()
362+
Integer Ring
337363
"""
338-
return sum(c for _, c in self)
364+
R = self.parent().base_ring()
365+
return R.sum(self._monomial_coefficients.values())
339366

340367
def content(self):
341368
"""
@@ -349,9 +376,14 @@ def content(self):
349376
sage: B = F.basis()
350377
sage: (3*B[4]+6*B[7]).content()
351378
3
379+
380+
TESTS::
381+
382+
sage: (0*B[2]).content()
383+
0
352384
"""
353385
from sage.arith.misc import gcd
354-
return gcd(c for _, c in self)
386+
return gcd(self._monomial_coefficients.values())
355387

356388
class Shifted(CombinatorialFreeModule, BindableClass):
357389
r"""
@@ -516,7 +548,8 @@ def from_h_vector(self, h):
516548
m = matrix(QQ, d + 1, d + 1,
517549
lambda j, i: (-1)**(d - j) * binomial(d - i, d - j))
518550
v = vector(QQ, [h[i] for i in range(d + 1)])
519-
return self._from_dict({i: Integer(c)
551+
R = self.base_ring()
552+
return self._from_dict({i: R(c)
520553
for i, c in enumerate(m * v)})
521554

522555
def _element_constructor_(self, x):
@@ -525,7 +558,7 @@ def _element_constructor_(self, x):
525558
526559
INPUT:
527560
528-
- ``x`` -- an integer or something convertible
561+
- ``x`` -- an element of the base ring or something convertible
529562
530563
EXAMPLES::
531564
@@ -536,10 +569,6 @@ def _element_constructor_(self, x):
536569
sage: R(x)
537570
S[1]
538571
"""
539-
if x in NonNegativeIntegers():
540-
W = self.basis().keys()
541-
return self.monomial(W(x))
542-
543572
P = x.parent()
544573
if isinstance(P, IntegerValuedPolynomialRing.Shifted):
545574
if P is self:
@@ -585,7 +614,7 @@ def _coerce_map_from_(self, R):
585614
6*S[1] + 2*S[2]
586615
587616
Elements of the integers coerce in, since there is a coerce map
588-
from `\ZZ` to GF(7)::
617+
from `\ZZ` to `\GF(7)`::
589618
590619
sage: F.coerce(1) # indirect doctest
591620
S[0]
@@ -614,8 +643,9 @@ def _coerce_map_from_(self, R):
614643
sage: z.parent() is F
615644
True
616645
617-
However, `\GF{7}` does not coerce to `\ZZ`, so the shuffle
618-
algebra over `\GF{7}` does not coerce to the one over `\ZZ`::
646+
However, `\GF{7}` does not coerce to `\ZZ`, so the
647+
integer-valued polynomial algebra over `\GF{7}` does not
648+
coerce to the one over `\ZZ`::
619649
620650
sage: G.coerce(x^3+x)
621651
Traceback (most recent call last):
@@ -975,10 +1005,6 @@ def _element_constructor_(self, x):
9751005
sage: R(x)
9761006
B[1]
9771007
"""
978-
if x in NonNegativeIntegers():
979-
W = self.basis().keys()
980-
return self.monomial(W(x))
981-
9821008
P = x.parent()
9831009
if isinstance(P, IntegerValuedPolynomialRing.Binomial):
9841010
if P is self:
@@ -1020,7 +1046,7 @@ def _coerce_map_from_(self, R):
10201046
B[1] + 2*B[2]
10211047
10221048
Elements of the integers coerce in, since there is a coerce map
1023-
from `\ZZ` to GF(7)::
1049+
from `\ZZ` to `\GF(7)`::
10241050
10251051
sage: F.coerce(1) # indirect doctest
10261052
B[0]
@@ -1049,8 +1075,9 @@ def _coerce_map_from_(self, R):
10491075
sage: z.parent() is F
10501076
True
10511077
1052-
However, `\GF{7}` does not coerce to `\ZZ`, so the shuffle
1053-
algebra over `\GF{7}` does not coerce to the one over `\ZZ`::
1078+
However, `\GF{7}` does not coerce to `\ZZ`, so the
1079+
integer-valued polynomial algebra over `\GF{7}` does not
1080+
coerce to the one over `\ZZ`::
10541081
10551082
sage: G.coerce(x^3+x)
10561083
Traceback (most recent call last):

0 commit comments

Comments
 (0)