# Show correct output of polynomial

Hi, I am new to sage and I am trying to construct a polynomial to try to transform it. However, when writing it I am getting an incorrect output.

x=var("x")
s = (x^2+2*x+1) + 1/(x^2+2*x+1)
s.show()

And this is the output I am getting -

x^2+2x + 1/x^2+2x+1 +1 (I am unsure why the 1 is carrying over all the way to right side)

I am looking to obtain the following output to begin transforming it -

x^2+2x+1 + 1/x^2+2x+1

Appreciate any help!

This is a rational function, and an 'ordering of terms' is not part of the data, so Sage should not be expected to preserve it. Nevertheless the desired output can be obtained; see my answer.

I tried using the QQ command received the following:

R.<x> = QQ[]

s = (x^2 + 2

x + 1) + 1/(x^2 + 2x + 1)print s

output-

(x^4 + 4

x^3 + 6x^2 + 4x + 2)/(x^2 + 2x + 1)Do you know why the polynomial is expanding?

That is due to the implementation of fraction field elements. To render the expression in the desired way, see my answer.