Ask Your Question

Revision history [back]

Getting the list of monomials are "one-liners". Using the monomial method as in

sage: R.<x,y,z> = QQ[]
sage: R.monomial(1,2,3)
x*y^2*z^3

You can do

sage: degree = 2; [R.monomial(*[x-1 for x in c]) for c in Compositions(3+degree, length=3)]
[x^2, x*y, x*z, y^2, y*z, z^2]
sage: degree = 3; [R.monomial(*[x-1 for x in c]) for c in Compositions(3+degree, length=3)]
[x^3, x^2*y, x^2*z, x*y^2, x*y*z, x*z^2, y^3, y^2*z, y*z^2, z^3]

(note you can also do the more convenient [R.monomial(*c) for c in Compositions(3+degree, length=3, min_part=0)] but you get an annoying warning).

Getting the list of monomials are "one-liners". Using the monomial method as in

sage: R.<x,y,z> = QQ[]
sage: R.monomial(1,2,3)
x*y^2*z^3

You can do

sage: degree = 2; [R.monomial(*[x-1 for x in c]) for c in Compositions(3+degree, length=3)]
[x^2, x*y, x*z, y^2, y*z, z^2]
sage: degree = 3; [R.monomial(*[x-1 for x in c]) for c in Compositions(3+degree, length=3)]
[x^3, x^2*y, x^2*z, x*y^2, x*y*z, x*z^2, y^3, y^2*z, y*z^2, z^3]

(note you can also do the more convenient [R.monomial(*c) for c in Compositions(3+degree, length=3, min_part=0)] but you get an annoying warning).

EDIT: It will help you to learn a bit of Python. Given a polynomial, here is how to multiply it by the list of monomials

sage: degree = 2
sage: monomials = [R.monomial(*[x-1 for x in c]) for c in Compositions(3+degree, length=3)]
sage: f = x + y + z
sage: [f * m for m in monomials]
[x^3 + x^2*y + x^2*z, x^2*y + x*y^2 + x*y*z, ..., x*z^2 + y*z^2 + z^3]