Ask Your Question
0

sage automatically expanding polynomial

asked 2014-11-27 21:24:13 +0200

Akanzar gravatar image

updated 2014-11-27 22:04:34 +0200

 R.<X>=PolynomialRing(ZZ,'X')
 X=R.gen()  
 P=(X+1)²+1
 show(P)

The result is X²+2X+2 while i would like sage to show (X+1)²+1.

How can i do that ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2014-11-27 22:09:05 +0200

FrédéricC gravatar image

Use symbolic variables ?

sage: X=var('X')
sage: ((X+1)**2+1)
(X + 1)^2 + 1
edit flag offensive delete link more

Comments

But P[2] (to get the coefficient before X²) doesn't work anymore with var.

Akanzar gravatar imageAkanzar ( 2014-11-27 22:19:04 +0200 )edit

Use P.coeffs() to get a list of all of the coefficients.

calc314 gravatar imagecalc314 ( 2014-11-28 02:51:00 +0200 )edit

But looks like sage will still expand e.g. 5(2x -7) into 10*x - 35. How to keep it in the original form?

pong gravatar imagepong ( 2016-06-26 16:16:53 +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

Stats

Asked: 2014-11-27 21:24:13 +0200

Seen: 688 times

Last updated: Nov 27 '14