Skip to content

Commit b5d7b78

Browse files
author
Release Manager
committed
sagemathgh-39044: provide default argument for monomial_coefficients This is a followup to sagemath#38767, where we put polynomials into the category of modules with basis. Back then, we missed the fact that `monomial_coefficients` should take an optional argument `copy`, which we fix here. Fixes sagemath#39037 URL: sagemath#39044 Reported by: Martin Rubey Reviewer(s): Marc Mezzarobba
2 parents 28c162e + e7abaf6 commit b5d7b78

12 files changed

+179
-33
lines changed

src/sage/algebras/commutative_dga.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ def homogeneous_parts(self):
15591559
res[deg] = term
15601560
return {i: res[i] for i in sorted(res.keys())}
15611561

1562-
def monomial_coefficients(self):
1562+
def monomial_coefficients(self, copy=True):
15631563
r"""
15641564
A dictionary that determines the element.
15651565
@@ -1578,7 +1578,7 @@ def monomial_coefficients(self):
15781578
sage: sorted(elt.dict().items())
15791579
[((0, 1, 1, 0), -5), ((1, 1, 0, 0), 1), ((1, 2, 3, 1), 7)]
15801580
"""
1581-
return self.lift().monomial_coefficients()
1581+
return self.lift().monomial_coefficients(copy=copy)
15821582

15831583
dict = monomial_coefficients
15841584

src/sage/algebras/splitting_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def is_unit(self):
102102

103103
return super().is_unit()
104104

105-
def monomial_coefficients(self):
105+
def monomial_coefficients(self, copy=True):
106106
r"""
107107
Return the dictionary of ``self`` according to its lift to the cover.
108108
@@ -119,7 +119,7 @@ def monomial_coefficients(self):
119119
sage: f.dict()
120120
{0: 42, 1: 1}
121121
"""
122-
return self.lift().monomial_coefficients()
122+
return self.lift().monomial_coefficients(copy=copy)
123123

124124
dict = monomial_coefficients
125125

src/sage/categories/modules_with_basis.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,18 @@ def leading_item(self, *args, **kwds):
18601860
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
18611861
sage: f.leading_item() # needs sage.combinat sage.modules
18621862
([3], -5)
1863+
1864+
The term ordering of polynomial rings is taken into account::
1865+
1866+
sage: R.<x,y,z> = QQ[]
1867+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_item()
1868+
((0, 4, 0), 1)
1869+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
1870+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_item()
1871+
((1, 2, 0), 3)
1872+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
1873+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_item()
1874+
((0, 1, 3), 2)
18631875
"""
18641876
k = self.leading_support(*args, **kwds)
18651877
return k, self[k]
@@ -1890,6 +1902,18 @@ def leading_monomial(self, *args, **kwds):
18901902
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
18911903
sage: f.leading_monomial() # needs sage.combinat sage.modules
18921904
s[3]
1905+
1906+
The term ordering of polynomial rings is taken into account::
1907+
1908+
sage: R.<x,y,z> = QQ[]
1909+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_monomial()
1910+
y^4
1911+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
1912+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_monomial()
1913+
x*y^2
1914+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
1915+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_monomial()
1916+
y*z^3
18931917
"""
18941918
return self.parent().monomial(self.leading_support(*args, **kwds))
18951919

@@ -1919,6 +1943,18 @@ def leading_coefficient(self, *args, **kwds):
19191943
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
19201944
sage: f.leading_coefficient() # needs sage.combinat sage.modules
19211945
-5
1946+
1947+
The term ordering of polynomial rings is taken into account::
1948+
1949+
sage: R.<x,y,z> = QQ[]
1950+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_coefficient()
1951+
1
1952+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
1953+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_coefficient()
1954+
3
1955+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
1956+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_coefficient()
1957+
2
19221958
"""
19231959
return self.leading_item(*args, **kwds)[1]
19241960

@@ -1948,6 +1984,18 @@ def leading_term(self, *args, **kwds):
19481984
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
19491985
sage: f.leading_term() # needs sage.combinat sage.modules
19501986
-5*s[3]
1987+
1988+
The term ordering of polynomial rings is taken into account::
1989+
1990+
sage: R.<x,y,z> = QQ[]
1991+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_term()
1992+
y^4
1993+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
1994+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_term()
1995+
3*x*y^2
1996+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
1997+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).leading_term()
1998+
2*y*z^3
19511999
"""
19522000
return self.parent().term(*self.leading_item(*args, **kwds))
19532001

@@ -2005,6 +2053,18 @@ def trailing_item(self, *args, **kwds):
20052053
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
20062054
sage: f.trailing_item() # needs sage.combinat sage.modules
20072055
([1], 2)
2056+
2057+
The term ordering of polynomial rings is taken into account::
2058+
2059+
sage: R.<x,y,z> = QQ[]
2060+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_item()
2061+
((1, 1, 1), 4)
2062+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
2063+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_item()
2064+
((0, 1, 3), 2)
2065+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
2066+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_item()
2067+
((1, 2, 0), 3)
20082068
"""
20092069
k = self.trailing_support(*args, **kwds)
20102070
return k, self[k]
@@ -2035,6 +2095,18 @@ def trailing_monomial(self, *args, **kwds):
20352095
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
20362096
sage: f.trailing_monomial() # needs sage.combinat sage.modules
20372097
s[1]
2098+
2099+
The term ordering of polynomial rings is taken into account::
2100+
2101+
sage: R.<x,y,z> = QQ[]
2102+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_monomial()
2103+
x*y*z
2104+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
2105+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_monomial()
2106+
y*z^3
2107+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
2108+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_monomial()
2109+
x*y^2
20382110
"""
20392111
return self.parent().monomial(self.trailing_support(*args, **kwds))
20402112

@@ -2064,6 +2136,18 @@ def trailing_coefficient(self, *args, **kwds):
20642136
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
20652137
sage: f.trailing_coefficient() # needs sage.combinat sage.modules
20662138
2
2139+
2140+
The term ordering of polynomial rings is taken into account::
2141+
2142+
sage: R.<x,y,z> = QQ[]
2143+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_coefficient()
2144+
4
2145+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
2146+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_coefficient()
2147+
2
2148+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
2149+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_coefficient()
2150+
3
20672151
"""
20682152
return self.trailing_item(*args, **kwds)[1]
20692153

@@ -2093,6 +2177,18 @@ def trailing_term(self, *args, **kwds):
20932177
sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # needs sage.combinat sage.modules
20942178
sage: f.trailing_term() # needs sage.combinat sage.modules
20952179
2*s[1]
2180+
2181+
The term ordering of polynomial rings is taken into account::
2182+
2183+
sage: R.<x,y,z> = QQ[]
2184+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_term()
2185+
4*x*y*z
2186+
sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
2187+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_term()
2188+
2*y*z^3
2189+
sage: R.<x,y,z> = PolynomialRing(QQ, order='invlex')
2190+
sage: (3*x*y^2 + 2*y*z^3 + y^4 + 4*x*y*z).trailing_term()
2191+
3*x*y^2
20962192
"""
20972193
return self.parent().term(*self.trailing_item(*args, **kwds))
20982194

src/sage/rings/derivation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def list(self):
996996
parent = self.parent()
997997
return [self(x) for x in parent.dual_basis()]
998998

999-
def monomial_coefficients(self):
999+
def monomial_coefficients(self, copy=None):
10001000
r"""
10011001
Return dictionary of nonzero coordinates (on the canonical
10021002
basis) of this derivation.

src/sage/rings/multi_power_series_ring_element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def __mod__(self, other):
10991099
return self.change_ring(Zmod(other))
11001100
raise NotImplementedError("Mod on multivariate power series ring elements not defined except modulo an integer.")
11011101

1102-
def monomial_coefficients(self):
1102+
def monomial_coefficients(self, copy=None):
11031103
"""
11041104
Return underlying dictionary with keys the exponents and values the
11051105
coefficients of this power series.

0 commit comments

Comments
 (0)