ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 14 Jul 2018 11:20:00 -0500Shift polynomialshttp://ask.sagemath.org/question/43012/shift-polynomials/ 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!Sat, 14 Jul 2018 10:27:35 -0500http://ask.sagemath.org/question/43012/shift-polynomials/Answer by tmonteil for <p>Say we have a polynomial over the rationals:</p>
<pre><code>R.<x> = PolynomialRing(QQ)
p = 5*x^2-3*x+1
</code></pre>
<p>I want to shift this polynomial by an integer, i.e. I want to do something like (note that the <code>shift</code> function already exists but it does something different)</p>
<pre><code>p.shift(2) # should give the polynomial 5*(x+2)^2-3*(x+2)+1 in R
</code></pre>
<p>This seems to be quite a simple thing. However, I cannot figure out how to do this. I tried to use substitute (<code>p.subs(x=x+2)</code>), 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.</p>
<p>Does anyone have an idea how this could be done conveniently?</p>
<p>Thank you very much for your help!</p>
http://ask.sagemath.org/question/43012/shift-polynomials/?answer=43013#post-id-43013You 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 + 15Sat, 14 Jul 2018 11:20:00 -0500http://ask.sagemath.org/question/43012/shift-polynomials/?answer=43013#post-id-43013