Ask Your Question

How to get a polynomial by changing base

asked 2022-03-07 12:01:15 +0200

mathboy gravatar image

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 flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question.

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

1 Answer

Sort by ยป oldest newest most voted

answered 2022-03-07 12:59:43 +0200

slelievre gravatar image

updated 2022-03-07 13:16:04 +0200

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

There was already a Sage Trac ticket about that:

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.


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.

edit flag offensive delete link more


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

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

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: 2022-03-07 12:01:15 +0200

Seen: 52 times

Last updated: Mar 07