Skip to content

Commit f6da2bd

Browse files
author
Release Manager
committed
gh-35043: fix the method monomials_of_degree <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> Fixes #35042. The goal of this PR is to fix two bugs of the method `monomials_of_degree`. First, the code does not take into account the case of weighted polynomial ring: ``` sage: P = PolynomialRing(QQ, 3, 'x,y,z', order=TermOrder('wdeglex', [4,5,6])) sage: P.inject_variables() Defining x, y, z sage: x.degree() 4 sage: P.monomials_of_degree(1) [x, y, z] ``` Next, as pointed out by @videlec, the current list of monomial that is returned is not sorted: ``` 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] sage: sorted(mons) [z^2, y*z, x*z, y^2, x*y, x^2] sage: ``` CC: @videlec, @yyyyx4 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35043 Reported by: David Ayotte Reviewer(s):
2 parents 2cbf029 + f119d2c commit f6da2bd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/sage/rings/polynomial/multi_polynomial_ring_base.pyx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,16 +1379,28 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
13791379
sage: R.<x,y,z> = ZZ[]
13801380
sage: mons = R.monomials_of_degree(2)
13811381
sage: mons
1382-
[x^2, x*y, x*z, y^2, y*z, z^2]
1382+
[z^2, y*z, x*z, y^2, x*y, x^2]
1383+
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order=TermOrder('wdeglex', [1, 2, 1]))
1384+
sage: P.monomials_of_degree(2)
1385+
[z^2, y, x*z, x^2]
1386+
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='lex')
1387+
sage: P.monomials_of_degree(3)
1388+
[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]
1389+
sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='invlex')
1390+
sage: P.monomials_of_degree(3)
1391+
[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]
13831392
13841393
The number of such monomials equals `\binom{n+k-1}{k}`
13851394
where `n` is the number of variables and `k` the degree::
13861395
13871396
sage: len(mons) == binomial(3+2-1,2)
13881397
True
13891398
"""
1390-
from sage.combinat.integer_vector import IntegerVectors
1391-
return [self.monomial(*a) for a in IntegerVectors(degree, self.ngens())]
1399+
deg_of_gens = [x.degree() for x in self.gens()]
1400+
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
1401+
mons = [self.monomial(*a) for a in WeightedIntegerVectors(degree, deg_of_gens)]
1402+
mons.sort() # This could be implemented in WeightedIntegerVectors instead
1403+
return mons
13921404

13931405
def _macaulay_resultant_getS(self, mon_deg_tuple, dlist):
13941406
r"""

0 commit comments

Comments
 (0)