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 is_homogeneous weight bug #38575

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,17 @@ def is_homogeneous(self):
False
sage: (x^2*y + y^2*x).is_homogeneous()
True

The weight of the parent ring is respected::

sage: term_order = TermOrder("wdegrevlex", [1, 3])
sage: R.<x, y> = PolynomialRing(Qp(5), order=term_order)
sage: (x + y).is_homogeneous()
False
sage: (x^3 + y).is_homogeneous()
True
"""
return self.element().is_homogeneous()
return self.element().is_homogeneous(self.parent().term_order().weights())

def _homogenize(self, var):
r"""
Expand Down
20 changes: 14 additions & 6 deletions src/sage/rings/polynomial/polydict.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ cdef class PolyDict:
ans[ETuple(t)] = self.__repn[S]
return self._new(ans)

def is_homogeneous(self):
def is_homogeneous(self, tuple w=None):
r"""
Return whether this polynomial is homogeneous.

Expand All @@ -688,12 +688,20 @@ cdef class PolyDict:
"""
if not self.__repn:
return True
cdef size_t s
it = iter(self.__repn)
cdef size_t s = (<ETuple> next(it)).unweighted_degree()
for elt in it:
if (<ETuple> elt).unweighted_degree() != s:
return False
return True
if w is None:
s = (<ETuple> next(it)).unweighted_degree()
for elt in it:
if (<ETuple> elt).unweighted_degree() != s:
return False
return True
else:
s = (<ETuple> next(it)).weighted_degree(w)
for elt in it:
if (<ETuple> elt).weighted_degree(w) != s:
return False
return True

def is_constant(self):
"""
Expand Down
Loading