# How to get a polynomial by changing base

I want to have (x-3)^2 as a polynomial in (x-1) as opposed to x; I want it output (x-1)^2 - 4(x-1) + 4

edit retag close merge delete

( 2022-03-07 13:00:00 +0200 )edit

Sort by ยป oldest newest most voted

Symbolic expressions have a taylor method which is supposed to do that.

Below, f.taylor(x, 1, 2) does a Taylor expansion of f with respect to x at the point 1 to the order 2.

Unfortunately it does not keep the linear term in the desired form:

sage: f = (x - 3)^2
sage: f.taylor(x, 1, 2)
(x - 1)^2 - 4*x + 8


which was closed because the initial formulation of the ticket was that the result was incorrect; in fact the result is correct but the way it is displayed is incorrect, so I reopened that ticket.

Workaround

In your case, if you want to get the coefficients that should go in front of the various powers of (x - 1), you can shift f by 1:

sage: x = polygen(QQ)
sage: f = (x - 3)^2
sage: f(x + 1)
x^2 - 4*x + 4


This tells you f is (x -1)^2 - 4*(x - 1) + 4.

more

Is it then possible to substitute x - 1 for x in the expression without having it expand?

( 2022-03-07 13:59:34 +0200 )edit