# Can sage compute a basis for the graded parts of a graded ring?

We can define a graded ring

sage: T = TermOrder("wdeglex", (1,2))
sage: S = PolynomialRing(QQ, 'x,y', order=T)
sage: S
Multivariate Polynomial Ring in x, y over Rational Field
sage: x,y = S.gens()
sage: (x*y).degree()
3


I want to find all monomials in S of a given degree d. Can this be done in sage?

This can be done in Macaulay2 with

i1 : QQ[x, y, Degrees => {{1}, {2}}]

o1 = S

o1 : PolynomialRing

i2 : basis(4, S)

o2 = | x4 x2y y2 |

1      3
o2 : Matrix S <--- S

edit retag close merge delete

Sort by ยป oldest newest most voted

For anyone interested, here's what I came up with.

def weighted_ring_basis(n, weights):
if not 1 in weights:
L = weights + [1]
X = toric_varieties.WP(L)
G = X.rational_class_group()
OO = G.gens()[0]
basis = (n*OO).lift().sections_monomials()
return [f for f in basis if not f.dict().keys()[0][len(weights)]]
X = toric_varieties.WP(weights)
G = X.rational_class_group()
OO = G.gens()[0]
return (n*OO).lift().sections_monomials()

more

This isn't perfect, but it's close: use GradedCommutativeAlgebra. The generators in odd degrees anti-commute, so if you want an honest polynomial algebra, double the degrees of the generators:

sage: S.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(2, 4))
sage: S
Graded Commutative Algebra with generators ('x', 'y') in degrees (2, 4) with relations [0] over Rational Field
sage: (x*y).degree()
6
sage: S.basis(10)
[x*y^2, x^3*y, x^5]

more