# 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.

edit retag close merge delete

You can use GradedCommutativeAlgebra, as I suggested in my answer to another of your questions.

That 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 is

Sort by » oldest newest most voted

This (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.

more

Thanks a lot this is precisely what I needed. I had tried (2,) before but not explicitly adding the ,1,

@Thierry: I'll open one (or two for the two silent behaviors), soon ;-).

I need advice on 28420 which happens to be more complicated than I thought!