Skip to content

Commit 46ef3fd

Browse files
author
Release Manager
committed
gh-37240: add one method to integer-valued polynomials as this appeared to be useful and missing during #sd125 ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. URL: #37240 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents b33cb75 + 3985bfc commit 46ef3fd

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def from_polynomial(self, p):
188188
"""
189189
Convert a polynomial into the ring of integer-valued polynomials.
190190
191-
This raises a ``ValueError`` if this is not possible.
191+
This raises a :class:`ValueError` if this is not possible.
192192
193193
INPUT:
194194
@@ -1174,6 +1174,45 @@ def _poly(self, i):
11741174
return binomial(x, i)
11751175

11761176
class Element(CombinatorialFreeModule.Element):
1177-
pass
1177+
def variable_shift(self, k=1):
1178+
r"""
1179+
Return the image by the shift of variables.
1180+
1181+
On polynomials, the action is the shift
1182+
on variables `x \mapsto x + k`.
1183+
1184+
INPUT:
1185+
1186+
- `k` -- integer (default: 1)
1187+
1188+
EXAMPLES::
1189+
1190+
sage: A = IntegerValuedPolynomialRing(ZZ).B()
1191+
sage: B = A.basis()
1192+
sage: B[5].variable_shift()
1193+
B[4] + B[5]
1194+
sage: B[5].variable_shift(-1)
1195+
-B[0] + B[1] - B[2] + B[3] - B[4] + B[5]
1196+
1197+
TESTS::
1198+
1199+
sage: B[5].variable_shift(0)
1200+
B[5]
1201+
sage: B[5].variable_shift().variable_shift(-1)
1202+
B[5]
1203+
"""
1204+
if k == 0:
1205+
return self
1206+
A = self.parent()
1207+
1208+
def on_basis(n):
1209+
return {A._indices(j): binomial(k, n - j)
1210+
for j in range(n + 1)}
1211+
1212+
from sage.data_structures.blas_dict import linear_combination
1213+
mc = self._monomial_coefficients
1214+
ret = linear_combination((on_basis(index), coeff)
1215+
for (index, coeff) in mc.items())
1216+
return A.element_class(A, ret)
11781217

11791218
B = Binomial

0 commit comments

Comments
 (0)