# define a polynomial ring

Dear all,

sage: R.<x> = PolynomialRing(QQ); R
Univariate Polynomial Ring in x over Rational Field
sage: R([1,2,3])
3*x^2 + 2*x + 1
sage: R1.<x> = PolynomialRing(QQ,1); R1
Multivariate Polynomial Ring in x over Rational Field
sage: R1([1,2,3])
---------------------------------------------------------------------------
TypeError: Could not find a mapping of the passed element to this ring.


  Note that a multivariate polynomial ring is returned when an
explicit number is given.

sage: PolynomialRing(QQ,"x",1)
Multivariate Polynomial Ring in x over Rational Field
sage: PolynomialRing(QQ,"x",0)
Multivariate Polynomial Ring in no variables over Rational Field


I want to know the reason .. Why

a multivariate polynomial ring is returned when an explicit number is given.

?

Does it offer users of SAGE any simplicity/convenience?

edit retag close merge delete

Sort by » oldest newest most voted

Yes. It offers the convenience of not having to define your variables. The number denotes the number of variables in the multivariate polynomial ring.

sage: PolynomialRing(QQ,"x",2)
Multivariate Polynomial Ring in x0, x1 over Rational Field
sage: R = PolynomialRing(QQ,"x",5); R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Rational Field
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: x0 in R
True


So, now you can programmatically access the variables and play around with them.

sage: xvars = R.gens(); xvars
(x0, x1, x2, x3, x4)
sage: xvars[0] in R
True

more

Thanks! Quick and in detail!

( 2013-11-24 08:06:41 +0200 )edit

For PolynomialRing(QQ,"x",n) the integer n must be < 2**15 (otherwise "OverflowError: value too large to convert to short"). Do you know a way for having arbitrary large integer n ?

( 2014-01-03 07:13:13 +0200 )edit