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

Ensure degree and total degree return Integer type for MPolynomial_polydict class #37611

Merged
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
25 changes: 23 additions & 2 deletions src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,21 @@ def degree(self, x=None, std_grading=False):
sage: R.<x,y> = GF(3037000453)[] # needs sage.rings.finite_rings
sage: R.zero().degree(x)
-1

Ensure that :issue:`37603` is fixed::

sage: R.<x,y,z> = PolynomialRing(QQbar)
sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5
sage: type(f.degree())
<class 'sage.rings.integer.Integer'>
sage: type(f.degree(x))
<class 'sage.rings.integer.Integer'>
sage: type(f.degree(x)) == type(f.degree(y)) == type(f.degree(z))
True
"""
if x is None:
if std_grading or not self.parent().term_order().is_weighted_degree_order():
return self.element().degree(None)
return Integer(self.element().degree(None))
return self.weighted_degree(self.parent().term_order().weights())
if isinstance(x, MPolynomial):
if not x.parent() is self.parent():
Expand All @@ -683,7 +694,7 @@ def degree(self, x=None, std_grading=False):
raise TypeError("x must be one of the generators of the parent")
else:
raise TypeError("x must be one of the generators of the parent")
return self.element().degree(x.element())
return Integer(self.element().degree(x.element()))

def total_degree(self):
"""
Expand Down Expand Up @@ -712,6 +723,16 @@ def total_degree(self):
sage: f = z^9 + 10*x^4 + y^8*x^2
sage: f.total_degree()
10

TESTS:

Ensure that :issue:`37603` is fixed::
sage: R.<x,y,z> = QQbar[]
sage: f = 2*x*y^3*z^2
sage: f.total_degree()
6
sage: type(f.total_degree())
<class 'sage.rings.integer.Integer'>
"""
return self.degree()

Expand Down
Loading