Ask Your Question
0

Shift polynomials

asked 6 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

tmonteil gravatar image

You can do:

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

sage: p(x+2) in R
True

Actually, the following works too:

sage: p.subs(x=x+2)
5*x^2 + 17*x + 15
Preview: (hide)
link

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

Stats

Asked: 6 years ago

Seen: 869 times

Last updated: Jul 14 '18