# Idiomatic way to express a polynomial in terms of a shifted variable

I have a polynomial of known degree, $$f(x) = \sum_{n = 0}^N a_n x^n$$ and I' d like to express it in terms of a shifted variable $$x - x_ 0$$, so that $$f(x) = \sum_{n = 0}^N b_n (x - x_ 0)^n$$.

I can do this by hand on paper, and I have a round about way of achieving the same result in Mathematica, but I' m pretty sure there has to be a standard name for the procedure I' m following when doing it manually. The round about way I currently use exploits the Taylor series, and goes like this:

Normal[Series[1 + x + x^6, {x, x0, 6}]]
Simplify[Normal[Series[1 + x + x^6, {x, x0, 6}]]] == 1 + x + x^6


Is there a more compact way of achieving this?

• Check here. Mar 23 at 13:57
• Interesting; however, that post is a close, but different, problem. I merely want a re-expression of the same function. To take their example, I want $f(x) = x^2$ to be expressed in the form $f(x) = (x+1)^2 - 2(x+1) +1$. That is, I want the polynomial in $x$ to be expressed as polynomial in $(x+1)$. Mar 23 at 15:34
• But are they not basically inverses? So you could use that on x-1 instead of x+1, that is? Mar 23 at 15:59

I don't think it's more compact, but just for the sake of it, here's another way:

Collect[Expand[1 + x + x^6 /. x :> xdiff + x0], xdiff] /. xdiff :> x - x0


If you want it organized, apply HoldForm after evaluating Collect, but before replacing xdiff, which can be, for example, achieved with

HoldForm @@ {Collect[Expand[1 + x + x^6 /. x :> xdiff + x0], xdiff]} /. xdiff :> x - x0


This relies on xdiff being clear, so you may want to package it in a function which keeps your variables fresh, and which gives you the option to hold the form or not as an optional fourth argument (false by default here):

PolynomialShift[poly_, x_Symbol, x0_, hold : (True | False) : False] :=
Module[{xdiff},
If[hold, HoldForm, Identity]
@@ {Collect[Expand[poly /. x :> xdiff + x0], xdiff]} /. xdiff :> x - x0]

(* E.g. *)

In[1]:=  PolynomialShift[1 + x + x^6, x, x0]
Out[1]:=  1 + (x - x0)^6 + x0 + 6 (x - x0)^5 x0 + 15 (x - x0)^4 x0^2 +
20 (x - x0)^3 x0^3 + 15 (x - x0)^2 x0^4 + x0^6 + (x - x0) (1 + 6 x0^5)

In[2]:=  PolynomialShift[1 + x + x^6, x, x0, True]
Out[2]:=  1 + x0 + x0^6 + (1 + 6 x0^5) (x - x0) + 15 x0^4 (x - x0)^2 +
20 x0^3 (x - x0)^3 + 15 x0^2 (x - x0)^4 + 6 x0 (x - x0)^5 + (x - x0)^6


If you don't care about the ordering, though,

PolynomialShift[poly_, x_Symbol, x0_] :=
Normal[Series[poly, {x, x0, Exponent[poly, x]}]


is probably the most compact you'll get.