Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sagemathgh-39256: Add check for zero monomial in monomial_coefficient
    
Fixes sagemath#39255

Added check for zero monomial and corresponding test case.



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39256
Reported by: Vladimir
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Mar 9, 2025
2 parents b84a0da + 9230780 commit e5cb9ec
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,15 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
-1
sage: f.monomial_coefficient(x^10)
0
TESTS::
sage: R.<x,y> = PolynomialRing(ZZ)
sage: f = x + y
sage: f.monomial_coefficient(x - x)
Traceback (most recent call last):
...
ValueError: mon must not be equal to 0
"""
cdef poly *p = self._poly
cdef poly *m = mon._poly
Expand All @@ -2993,6 +3002,9 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
if mon._parent is not self._parent:
raise TypeError("mon must have same parent as self.")

if mon._poly is NULL:
raise ValueError("mon must not be equal to 0")

while p:
if p_ExpVectorEqual(p, m, r) == 1:
return si2sa(p_GetCoeff(p, r), r, self._parent._base)
Expand Down

0 comments on commit e5cb9ec

Please sign in to comment.