Ask Your Question
1

Construct polynomial ring from list of variables

asked 2021-04-18 03:32:31 +0100

weafpiojasdf gravatar image

updated 2022-04-14 14:05:47 +0100

FrédéricC gravatar image

In constructing polynomial rings, documentation says that diamond brackets are used "to make the variable ready for use after you define the ring", but the variables are entered explicitly: R.<x,y> .

What if I have a list of (an unknown number of) variables?

E.g. if I have xs = [x_1,x_2,x_3], I want to construct a polynomial ring and subsequently manipulate x_1 + x_2, etc., within that ring instead of "symbolic ring". I'd like to do something like R.<xs> but that doesn't seem to work.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-04-18 12:35:46 +0100

tmonteil gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-04-18 03:19:54 +0100

Seen: 632 times

Last updated: Apr 18 '21