ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 15 Aug 2013 22:15:12 +0200How to get a list of monomials of a given degreehttps://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 23:43:08 +0200https://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/Answer 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>
https://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 22:15:12 +0200https://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=15350#post-id-15350Answer 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>
https://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]
Wed, 23 May 2012 00:08:32 +0200https://ask.sagemath.org/question/8994/how-to-get-a-list-of-monomials-of-a-given-degree/?answer=13602#post-id-13602