From ff2d38d1e5b2dab7d7c5b8715da3035964f4868f Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 7 Feb 2023 17:33:54 +0100 Subject: [PATCH 1/3] fix the method monomials_of_degree --- src/sage/rings/polynomial/multi_polynomial_ring_base.pyx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index f6a46ac4898..c8cfc106236 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -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` """ # get ring and number of variables @@ -1387,8 +1387,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): 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 + return [self.monomial(*a) for a in WeightedIntegerVectors(degree, deg_of_gens)] def _macaulay_resultant_getS(self, mon_deg_tuple, dlist): r""" From a37eb292aadbf08ce2b6146ace3d1394f07f326d Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 7 Feb 2023 18:12:52 +0100 Subject: [PATCH 2/3] fix and add doctests --- src/sage/rings/polynomial/multi_polynomial_ring_base.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index c8cfc106236..f0c679c395b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -1379,7 +1379,10 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: R. = 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) + [y, z^2, x*z, x^2] The number of such monomials equals `\binom{n+k-1}{k}` where `n` is the number of variables and `k` the degree:: From f119d2ce0f1f9b764142db55e1669ce553826ec6 Mon Sep 17 00:00:00 2001 From: DavidAyotte Date: Tue, 7 Feb 2023 19:46:23 +0100 Subject: [PATCH 3/3] fix the ordering and add doctests --- .../polynomial/multi_polynomial_ring_base.pyx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index f0c679c395b..1a0faf98497 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -1380,9 +1380,15 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: mons = R.monomials_of_degree(2) sage: mons [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 = PolynomialRing(QQ, 3, 'x, y, z', order=TermOrder('wdeglex', [1, 2, 1])) sage: P.monomials_of_degree(2) - [y, z^2, x*z, x^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:: @@ -1392,7 +1398,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): """ deg_of_gens = [x.degree() for x in self.gens()] from sage.combinat.integer_vector_weighted import WeightedIntegerVectors - return [self.monomial(*a) for a in WeightedIntegerVectors(degree, deg_of_gens)] + 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"""