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, 30 Aug 2019 10:41:00 -0500weighted univariate polynomialshttp://ask.sagemath.org/question/47628/weighted-univariate-polynomials/I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in
sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4
However if I want to do this with only one variable this does not work
sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1
I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables.
Tue, 27 Aug 2019 13:55:48 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/Comment by heluani for <p>I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in </p>
<pre><code>sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4
</code></pre>
<p>However if I want to do this with only one variable this does not work</p>
<pre><code>sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1
</code></pre>
<p>I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47645#post-id-47645That doesn't work for a number of other reasons, I have a particular derivation of degree 1 and doubling the degrees is not an option. I need a number of methods from PolynomialRings and Groebner bases that I cannot coalesce to GradedCommutativeAlgebra and a few more. But still it's striking why that example as in my question is implemented the way it isWed, 28 Aug 2019 07:03:57 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47645#post-id-47645Comment by John Palmieri for <p>I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in </p>
<pre><code>sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4
</code></pre>
<p>However if I want to do this with only one variable this does not work</p>
<pre><code>sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1
</code></pre>
<p>I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47630#post-id-47630You can use `GradedCommutativeAlgebra`, as I suggested in my answer to another of your questions.Tue, 27 Aug 2019 15:13:43 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47630#post-id-47630Answer by B r u n o for <p>I have a polynomial algebra in n variables k[x_1,...,x_n]. I know how assign different degrees to each of the generators as in </p>
<pre><code>sage: P = PolynomialRing(QQ, 'x,y,z', order = TermOrder('wdegrevlex', (2,3,4)))
sage: P.inject_variables()
Defining x, y, z
sage: z.degree()
sage:
4
</code></pre>
<p>However if I want to do this with only one variable this does not work</p>
<pre><code>sage: P = PolynomialRing(QQ, 'x', order = TermOrder('wdegrevlex', (2)))
sage: P.inject_variables()
Defining x
sage: x.degree()
1
</code></pre>
<p>I wander if I can do this in an uniform way cause I need to use a class that takes an arbitrary number of variables. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?answer=47646#post-id-47646This (mainly) comes from the construction of your univariate polynomial ring. Compare
sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, `R1` and `R2` in my example use two completely distinct implementations.
Now you can do what you need:
sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
Note the two changes: 1. add the number of variables ; 2. change `(2)` into `(2,)`. The second change is due to the fact that `TermOrder` needs a tuple, and `(2)` is an integer for Python while `(2,)` is a 1-tuple containing an integer.
It is a pity that you did not get any warning: In my sense, you should have been told that `order = ...` has no effect for a univariate polynomial ring, and that `TermOrder(...)` requires a tuple rather than an integer. Wed, 28 Aug 2019 09:49:39 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?answer=47646#post-id-47646Comment by B r u n o for <p>This (mainly) comes from the construction of your univariate polynomial ring. Compare</p>
<pre><code>sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
</code></pre>
<p>This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, <code>R1</code> and <code>R2</code> in my example use two completely distinct implementations.</p>
<p>Now you can do what you need:</p>
<pre><code>sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
</code></pre>
<p>Note the two changes: 1. add the number of variables ; 2. change <code>(2)</code> into <code>(2,)</code>. The second change is due to the fact that <code>TermOrder</code> needs a tuple, and <code>(2)</code> is an integer for Python while <code>(2,)</code> is a 1-tuple containing an integer.</p>
<p>It is a pity that you did not get any warning: In my sense, you should have been told that <code>order = ...</code> has no effect for a univariate polynomial ring, and that <code>TermOrder(...)</code> requires a tuple rather than an integer. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47673#post-id-47673I need advice on [28420](https://trac.sagemath.org/ticket/28420) which happens to be more complicated than I thought!Fri, 30 Aug 2019 10:41:00 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47673#post-id-47673Comment by tmonteil for <p>This (mainly) comes from the construction of your univariate polynomial ring. Compare</p>
<pre><code>sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
</code></pre>
<p>This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, <code>R1</code> and <code>R2</code> in my example use two completely distinct implementations.</p>
<p>Now you can do what you need:</p>
<pre><code>sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
</code></pre>
<p>Note the two changes: 1. add the number of variables ; 2. change <code>(2)</code> into <code>(2,)</code>. The second change is due to the fact that <code>TermOrder</code> needs a tuple, and <code>(2)</code> is an integer for Python while <code>(2,)</code> is a 1-tuple containing an integer.</p>
<p>It is a pity that you did not get any warning: In my sense, you should have been told that <code>order = ...</code> has no effect for a univariate polynomial ring, and that <code>TermOrder(...)</code> requires a tuple rather than an integer. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47667#post-id-47667These are now [trac ticket 28420](https://trac.sagemath.org/ticket/28420) and [trac ticket 28421](https://trac.sagemath.org/ticket/28421), thanks !Fri, 30 Aug 2019 02:57:27 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47667#post-id-47667Comment by B r u n o for <p>This (mainly) comes from the construction of your univariate polynomial ring. Compare</p>
<pre><code>sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
</code></pre>
<p>This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, <code>R1</code> and <code>R2</code> in my example use two completely distinct implementations.</p>
<p>Now you can do what you need:</p>
<pre><code>sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
</code></pre>
<p>Note the two changes: 1. add the number of variables ; 2. change <code>(2)</code> into <code>(2,)</code>. The second change is due to the fact that <code>TermOrder</code> needs a tuple, and <code>(2)</code> is an integer for Python while <code>(2,)</code> is a 1-tuple containing an integer.</p>
<p>It is a pity that you did not get any warning: In my sense, you should have been told that <code>order = ...</code> has no effect for a univariate polynomial ring, and that <code>TermOrder(...)</code> requires a tuple rather than an integer. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47651#post-id-47651@Thierry: I'll open one (or two for the two silent behaviors), soon ;-).Wed, 28 Aug 2019 11:56:40 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47651#post-id-47651Comment by heluani for <p>This (mainly) comes from the construction of your univariate polynomial ring. Compare</p>
<pre><code>sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
</code></pre>
<p>This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, <code>R1</code> and <code>R2</code> in my example use two completely distinct implementations.</p>
<p>Now you can do what you need:</p>
<pre><code>sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
</code></pre>
<p>Note the two changes: 1. add the number of variables ; 2. change <code>(2)</code> into <code>(2,)</code>. The second change is due to the fact that <code>TermOrder</code> needs a tuple, and <code>(2)</code> is an integer for Python while <code>(2,)</code> is a 1-tuple containing an integer.</p>
<p>It is a pity that you did not get any warning: In my sense, you should have been told that <code>order = ...</code> has no effect for a univariate polynomial ring, and that <code>TermOrder(...)</code> requires a tuple rather than an integer. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47649#post-id-47649Thanks a lot this is precisely what I needed. I had tried (2,) before but not explicitly adding the ,1,Wed, 28 Aug 2019 10:46:02 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47649#post-id-47649Comment by tmonteil for <p>This (mainly) comes from the construction of your univariate polynomial ring. Compare</p>
<pre><code>sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field
</code></pre>
<p>This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, <code>R1</code> and <code>R2</code> in my example use two completely distinct implementations.</p>
<p>Now you can do what you need:</p>
<pre><code>sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2
</code></pre>
<p>Note the two changes: 1. add the number of variables ; 2. change <code>(2)</code> into <code>(2,)</code>. The second change is due to the fact that <code>TermOrder</code> needs a tuple, and <code>(2)</code> is an integer for Python while <code>(2,)</code> is a 1-tuple containing an integer.</p>
<p>It is a pity that you did not get any warning: In my sense, you should have been told that <code>order = ...</code> has no effect for a univariate polynomial ring, and that <code>TermOrder(...)</code> requires a tuple rather than an integer. </p>
http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47647#post-id-47647A ticket ?Wed, 28 Aug 2019 09:56:58 -0500http://ask.sagemath.org/question/47628/weighted-univariate-polynomials/?comment=47647#post-id-47647