Ask Your Question

Revision history [back]

Given the list of strings :

sage: xs = ['x_1','x_2','x_3']

you can define the polynomial with this list as indeterminate names :

sage: R = PolynomialRing(QQ, names=xs)                                                                                                                                                                        
sage: R                                                                                                                                                                                                      
Multivariate Polynomial Ring in x_1, x_2, x_3 over Rational Field

In the R.<x,y> construction, there some Sage preparsing that hides the fact that there are two operations being done:

  • Creating the polynomial ring R with 'x' and 'y' as indetereminate names
  • Leting the Python names x and y point to the corresponding indeterminates

See:

sage: preparse('R.<x,y> = PolynomialRing(QQ)')                                                                                                                                                               
"R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)"

So, in order to be able to wrire x_1+x_2^3, we have to create those Python names. For this, there is a very handy method named inject_variables:

sage: R.inject_variables()                                                                                                                                                                                   
Defining x_1, x_2, x_3

Now, you can do things like:

sage: x_1 + x_2^3                                                                                                                                                                                            
x_2^3 + x_1