# How to get a list of monomials of a given degree

Is there a nice way to get all monomials of a given degree in a multivariable polynomial ring?

For example I want to input x,y,3 and get

x^3, x^2y, xy^2, y^3.

I think I could code it myself with not too much work, but it seems like something that might already have a nice method.

edit retag close merge delete

Sort by » oldest newest most voted I don't think there is a method that allows you to do this. This is one step away:

sage: list(WeightedIntegerVectors(3, [1,1]))
[[0, 3], [1, 2], [2, 1], [3, 0]]


(This gives all lists of integers [a,b] so that 1*a + 1*b = 3.) So:

sage: R.<x,y> = PolynomialRing(QQ, 2)
sage: degs = WeightedIntegerVectors(3, [1,1])
sage: [x^d * y^d for d in degs]
[y^3, x*y^2, x^2*y, x^3]

more

You can map exponent vectors more directly to monomials:

sage: P.<x,y,z>=QQ[]
sage: [P({tuple(a):1}) for a in WeightedIntegerVectors(3,[1,1,1])]
[z^3, y*z^2, x*z^2, y^2*z, x*y*z, x^2*z, y^3, x*y^2, x^2*y, x^3]

more