Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the method monomials_of_degree #35043

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/sage/rings/polynomial/multi_polynomial_ring_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
1/2*x^3 + x*y + z^2 - 1/2*x + y + 25

.. SEEALSO::

:meth:`lagrange_polynomial<sage.rings.polynomial.polynomial_ring.PolynomialRing_field.lagrange_polynomial>`
"""
# get ring and number of variables
Expand Down Expand Up @@ -1379,16 +1379,28 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
sage: R.<x,y,z> = ZZ[]
sage: mons = R.monomials_of_degree(2)
sage: mons
[x^2, x*y, x*z, y^2, y*z, z^2]
[z^2, y*z, x*z, y^2, x*y, x^2]
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order=TermOrder('wdeglex', [1, 2, 1]))
sage: P.monomials_of_degree(2)
[z^2, y, x*z, x^2]
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='lex')
sage: P.monomials_of_degree(3)
[z^3, y*z^2, y^2*z, y^3, x*z^2, x*y*z, x*y^2, x^2*z, x^2*y, x^3]
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='invlex')
sage: P.monomials_of_degree(3)
[x^3, x^2*y, x*y^2, y^3, x^2*z, x*y*z, y^2*z, x*z^2, y*z^2, z^3]

The number of such monomials equals `\binom{n+k-1}{k}`
where `n` is the number of variables and `k` the degree::

sage: len(mons) == binomial(3+2-1,2)
True
"""
from sage.combinat.integer_vector import IntegerVectors
return [self.monomial(*a) for a in IntegerVectors(degree, self.ngens())]
deg_of_gens = [x.degree() for x in self.gens()]
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
mons = [self.monomial(*a) for a in WeightedIntegerVectors(degree, deg_of_gens)]
mons.sort() # This could be implemented in WeightedIntegerVectors instead
return mons

def _macaulay_resultant_getS(self, mon_deg_tuple, dlist):
r"""
Expand Down