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.Thu, 15 Aug 2013 15:15:12 -0500How to get a list of monomials of a given degreehttp://ask.sagemath.org/question/8994/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^2*y, x*y^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.Tue, 22 May 2012 16:43:08 -0500http://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/Answer by John Palmieri for <p>Is there a nice way to get all monomials of a given degree in a multivariable polynomial ring?</p>
<p>For example I want to input x,y,3 and get</p>
<p>x^3, x^2<em>y, x</em>y^2, y^3.</p>
<p>I think I could code it myself with not too much work, but it seems like something that might already have a nice method.</p>
http://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=13602#post-id-13602I 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]
Tue, 22 May 2012 17:08:32 -0500http://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=13602#post-id-13602Answer by nbruin for <p>Is there a nice way to get all monomials of a given degree in a multivariable polynomial ring?</p>
<p>For example I want to input x,y,3 and get</p>
<p>x^3, x^2<em>y, x</em>y^2, y^3.</p>
<p>I think I could code it myself with not too much work, but it seems like something that might already have a nice method.</p>
http://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=15350#post-id-15350You 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]
Thu, 15 Aug 2013 15:15:12 -0500http://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=15350#post-id-15350