Ask Your Question
2

Pass a list of variable names as parameter to a polynomial ring

asked 2016-05-23 19:17:44 +0100

KittyL gravatar image

updated 2016-05-23 19:20:55 +0100

I am trying to write a function that compute a vector space basis $B$ for the quotient ring $k[x_1,\dots,x_n]/I$. I want to make the list of variables as the input parameter.

I tried this:

var("x,y")
Vlist=[x,y] 
P.<Vlist>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()

It gave me error message. I also tried

Vlist=['x,y']

or

Vlist=["x,y"]

None of them works. I know that

P.<x,y>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()

works. So I can just type this before I run my function. But is there a way that I can make this as input of the function?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-05-23 19:24:07 +0100

tmonteil gravatar image

updated 2016-05-23 19:26:15 +0100

You can get the list of strings representing your variables as follows:

sage: [str(i) for i in Vlist]
['x', 'y']

So you can define your polynomial ring directly, without the <> construction:

sage: P = PolynomialRing(QQ, [str(i) for i in Vlist], order='degrevlex')
sage: P
Multivariate Polynomial Ring in x, y over Rational Field

But now, the Python variables x and y still point to the symbols x and y (that belong to the Symbolic Ring), not the indeterminates x and y that belong to P. For this you can do:

sage: P.inject_variables()
Defining x, y

Then:

sage: f=x^2+y^3
sage: f.lm()
y^3

By the way, note that if your variables are going to be x0, x1,...,x9 (say), you can use the following construction:

sage: P = PolynomialRing(QQ, 10, 'x', order='degrevlex')
sage: P
Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field
sage: P.inject_variables()
Defining x0, x1, x2, x3, x4, x5, x6, x7, x8, x9
edit flag offensive delete link more

Comments

Thank you! That problem is solved! Now another related question is, I have to pass a list of Groebner basis as input parameter too. Since they are defined before the polynomial ring $P$ is defined in the function, I still cannot use $f.lm()$ on them. Is there a way to make the $x,y$ in $f$ indeterminates?

KittyL gravatar imageKittyL ( 2016-05-23 19:37:28 +0100 )edit

I am not sure to understand your new question (perhaps could you make an explicit one with examples), but if f is already defined as a symbolic expression, you can try to do P(f) to transform it into an element of P, with correct indeterminates.

tmonteil gravatar imagetmonteil ( 2016-05-23 19:55:58 +0100 )edit

Problem solved! Thank you!

KittyL gravatar imageKittyL ( 2016-05-23 20:35:31 +0100 )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: 2016-05-23 19:17:44 +0100

Seen: 1,366 times

Last updated: May 23 '16