Ask Your Question

Shift polynomials

asked 2018-07-14 10:27:35 -0500

philipp7 gravatar image

Say we have a polynomial over the rationals:

R.<x> = PolynomialRing(QQ)
p = 5*x^2-3*x+1

I want to shift this polynomial by an integer, i.e. I want to do something like (note that the shift function already exists but it does something different)

p.shift(2)  # should give the polynomial 5*(x+2)^2-3*(x+2)+1 in R

This seems to be quite a simple thing. However, I cannot figure out how to do this. I tried to use substitute (p.subs(x=x+2)), but it did not work. One way it might work is to consider the polynomial in the symbolic ring, substitute there and convert it back to the polynomial ring. This seems too complicated for this small problem.

Does anyone have an idea how this could be done conveniently?

Thank you very much for your help!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-07-14 11:20:00 -0500

tmonteil gravatar image

You can do:

sage: p(x+2)
5*x^2 + 17*x + 15

sage: p(x+2) in R

Actually, the following works too:

sage: p.subs(x=x+2)
5*x^2 + 17*x + 15
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-07-14 10:27:35 -0500

Seen: 28 times

Last updated: Jul 14