Ask Your Question
2

How to get a list of monomials of a given degree

asked 12 years ago

paragon gravatar image

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 12 years ago

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[0] * y^d[1] for d in degs]
[y^3, x*y^2, x^2*y, x^3]
Preview: (hide)
link
2

answered 11 years ago

nbruin gravatar image

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]
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 3,059 times

Last updated: Aug 15 '13