ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Jan 2014 00:13:13 -0600define a polynomial ringhttp://ask.sagemath.org/question/10771/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?
Thanks in advance!Sun, 24 Nov 2013 00:24:27 -0600http://ask.sagemath.org/question/10771/define-a-polynomial-ring/Answer by ppurka for <p>Dear all,</p>
<pre><code>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.
</code></pre>
<hr/>
<pre><code> 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
</code></pre>
<p>I want to know the reason ..
Why </p>
<blockquote>
<p>a multivariate polynomial ring is
returned when an explicit number is
given.</p>
</blockquote>
<p>?</p>
<p>Does it offer users of SAGE any simplicity/convenience?</p>
<p>Thanks in advance!</p>
http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?answer=15725#post-id-15725Yes. 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
Sun, 24 Nov 2013 00:58:44 -0600http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?answer=15725#post-id-15725Comment by Sébastien Palcoux for <p>Yes. It offers the convenience of not having to define your variables. The number denotes the number of variables in the multivariate polynomial ring.</p>
<pre><code>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
</code></pre>
<p>So, now you can programmatically access the variables and play around with them.</p>
<pre><code>sage: xvars = R.gens(); xvars
(x0, x1, x2, x3, x4)
sage: xvars[0] in R
True
</code></pre>
http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?comment=16479#post-id-16479For 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 ?Fri, 03 Jan 2014 00:13:13 -0600http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?comment=16479#post-id-16479Comment by gundamlh for <p>Yes. It offers the convenience of not having to define your variables. The number denotes the number of variables in the multivariate polynomial ring.</p>
<pre><code>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
</code></pre>
<p>So, now you can programmatically access the variables and play around with them.</p>
<pre><code>sage: xvars = R.gens(); xvars
(x0, x1, x2, x3, x4)
sage: xvars[0] in R
True
</code></pre>
http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?comment=16636#post-id-16636Thanks! Quick and in detail!Sun, 24 Nov 2013 01:06:41 -0600http://ask.sagemath.org/question/10771/define-a-polynomial-ring/?comment=16636#post-id-16636