20
20
from sage .matrix .constructor import matrix
21
21
from sage .misc .cachefunc import cached_method
22
22
from sage .modules .free_module_element import vector
23
- from sage .rings .integer import Integer
24
23
from sage .rings .integer_ring import ZZ
25
24
from sage .rings .polynomial .polynomial_ring import polygen
26
25
from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
@@ -77,6 +76,12 @@ class IntegerValuedPolynomialRing(UniqueRepresentation, Parent):
77
76
TypeError: argument R must be a commutative ring
78
77
"""
79
78
def __init__ (self , R ):
79
+ """
80
+ TESTS::
81
+
82
+ sage: IV = IntegerValuedPolynomialRing(ZZ)
83
+ sage: TestSuite(IV).run()
84
+ """
80
85
if R not in Rings ().Commutative ():
81
86
raise TypeError ("argument R must be a commutative ring" )
82
87
self ._base = R
@@ -97,6 +102,20 @@ def _repr_(self) -> str:
97
102
br = self .base_ring ()
98
103
return f"Integer-Valued Polynomial Ring over { br } "
99
104
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
+
100
119
class Bases (Category_realization_of_parent ):
101
120
def super_categories (self ) -> list :
102
121
r"""
@@ -223,10 +242,12 @@ def from_polynomial(self, p):
223
242
result += top_coeff * B [N ]
224
243
return result
225
244
226
- def gen (self ):
245
+ def gen (self , i = 0 ):
227
246
r"""
228
247
Return the generator of this algebra.
229
248
249
+ The optional argument is ignored.
250
+
230
251
EXAMPLES::
231
252
232
253
sage: F = IntegerValuedPolynomialRing(ZZ).B()
@@ -334,8 +355,14 @@ def sum_of_coefficients(self):
334
355
sage: B = F.basis()
335
356
sage: (B[2]*B[4]).sum_of_coefficients()
336
357
1
358
+
359
+ TESTS::
360
+
361
+ sage: (0*B[2]).sum_of_coefficients().parent()
362
+ Integer Ring
337
363
"""
338
- return sum (c for _ , c in self )
364
+ R = self .parent ().base_ring ()
365
+ return R .sum (self ._monomial_coefficients .values ())
339
366
340
367
def content (self ):
341
368
"""
@@ -349,9 +376,14 @@ def content(self):
349
376
sage: B = F.basis()
350
377
sage: (3*B[4]+6*B[7]).content()
351
378
3
379
+
380
+ TESTS::
381
+
382
+ sage: (0*B[2]).content()
383
+ 0
352
384
"""
353
385
from sage .arith .misc import gcd
354
- return gcd (c for _ , c in self )
386
+ return gcd (self . _monomial_coefficients . values () )
355
387
356
388
class Shifted (CombinatorialFreeModule , BindableClass ):
357
389
r"""
@@ -516,7 +548,8 @@ def from_h_vector(self, h):
516
548
m = matrix (QQ , d + 1 , d + 1 ,
517
549
lambda j , i : (- 1 )** (d - j ) * binomial (d - i , d - j ))
518
550
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 )
520
553
for i , c in enumerate (m * v )})
521
554
522
555
def _element_constructor_ (self , x ):
@@ -525,7 +558,7 @@ def _element_constructor_(self, x):
525
558
526
559
INPUT:
527
560
528
- - ``x`` -- an integer or something convertible
561
+ - ``x`` -- an element of the base ring or something convertible
529
562
530
563
EXAMPLES::
531
564
@@ -536,10 +569,6 @@ def _element_constructor_(self, x):
536
569
sage: R(x)
537
570
S[1]
538
571
"""
539
- if x in NonNegativeIntegers ():
540
- W = self .basis ().keys ()
541
- return self .monomial (W (x ))
542
-
543
572
P = x .parent ()
544
573
if isinstance (P , IntegerValuedPolynomialRing .Shifted ):
545
574
if P is self :
@@ -585,7 +614,7 @@ def _coerce_map_from_(self, R):
585
614
6*S[1] + 2*S[2]
586
615
587
616
Elements of the integers coerce in, since there is a coerce map
588
- from `\ZZ` to GF(7)::
617
+ from `\ZZ` to `\ GF(7)` ::
589
618
590
619
sage: F.coerce(1) # indirect doctest
591
620
S[0]
@@ -614,8 +643,9 @@ def _coerce_map_from_(self, R):
614
643
sage: z.parent() is F
615
644
True
616
645
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`::
619
649
620
650
sage: G.coerce(x^3+x)
621
651
Traceback (most recent call last):
@@ -975,10 +1005,6 @@ def _element_constructor_(self, x):
975
1005
sage: R(x)
976
1006
B[1]
977
1007
"""
978
- if x in NonNegativeIntegers ():
979
- W = self .basis ().keys ()
980
- return self .monomial (W (x ))
981
-
982
1008
P = x .parent ()
983
1009
if isinstance (P , IntegerValuedPolynomialRing .Binomial ):
984
1010
if P is self :
@@ -1020,7 +1046,7 @@ def _coerce_map_from_(self, R):
1020
1046
B[1] + 2*B[2]
1021
1047
1022
1048
Elements of the integers coerce in, since there is a coerce map
1023
- from `\ZZ` to GF(7)::
1049
+ from `\ZZ` to `\ GF(7)` ::
1024
1050
1025
1051
sage: F.coerce(1) # indirect doctest
1026
1052
B[0]
@@ -1049,8 +1075,9 @@ def _coerce_map_from_(self, R):
1049
1075
sage: z.parent() is F
1050
1076
True
1051
1077
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`::
1054
1081
1055
1082
sage: G.coerce(x^3+x)
1056
1083
Traceback (most recent call last):
0 commit comments