Skip to content

Commit

Permalink
sagemathgh-38575: Fix is_homogeneous weight bug
Browse files Browse the repository at this point in the history
    
PoC:

```sage
term_order = TermOrder("wdegrevlex", [1, 3])
R.<x, y> = PolynomialRing(Qp(5), order=term_order)
assert not (x + y).is_homogeneous()
assert (x^3 + y).is_homogeneous()
```
    
URL: sagemath#38575
Reported by: grhkm21
Reviewer(s):
  • Loading branch information
Release Manager committed Sep 4, 2024
2 parents 0324a54 + 8fa25d9 commit 1b2cae5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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 @@ -1290,8 +1290,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

0 comments on commit 1b2cae5

Please sign in to comment.