Skip to content

Commit 2111efa

Browse files
author
Release Manager
committed
Trac #34599: add helper function to compute all monomials of a given degree
This comes in handy occasionally: {{{#!python sage: R.<x,y,z> = ZZ[] sage: R.monomials_of_degree(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] }}} URL: https://trac.sagemath.org/34599 Reported by: lorenz Ticket author(s): Lorenz Panny Reviewer(s): Marc Mezzarobba
2 parents 4f7754a + c28b7e1 commit 2111efa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sage/rings/polynomial/multi_polynomial_ring_base.pyx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,27 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
11841184
"""
11851185
return self({exponents: self.base_ring().one()})
11861186

1187+
def monomials_of_degree(self, degree):
1188+
r"""
1189+
Return a list of all monomials of the given total degree in this
1190+
multivariate polynomial ring.
1191+
1192+
EXAMPLES::
1193+
1194+
sage: R.<x,y,z> = ZZ[]
1195+
sage: mons = R.monomials_of_degree(2)
1196+
sage: mons
1197+
[x^2, x*y, x*z, y^2, y*z, z^2]
1198+
1199+
The number of such monomials equals `\binom{n+k-1}{k}`
1200+
where `n` is the number of variables and `k` the degree::
1201+
1202+
sage: len(mons) == binomial(3+2-1,2)
1203+
True
1204+
"""
1205+
from sage.combinat.integer_vector import IntegerVectors
1206+
return [self.monomial(*a) for a in IntegerVectors(degree, self.ngens())]
1207+
11871208
def _macaulay_resultant_getS(self, mon_deg_tuple, dlist):
11881209
r"""
11891210
In the Macaulay resultant algorithm the list of all monomials of the total degree is partitioned into sets `S_i`.

0 commit comments

Comments
 (0)