From d0fe6f30fc34ea059761aac40e3e39a9d204be8e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 4 Jan 2025 02:23:13 +0300 Subject: [PATCH 1/2] add check for zero monomial --- .../polynomial/multi_polynomial_libsingular.pyx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index adf3df1cf95..a4f031798ea 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -2985,6 +2985,15 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): -1 sage: f.monomial_coefficient(x^10) 0 + + TESTS:: + + sage: R. = 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 @@ -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 == 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) From 9230780040f3b4f22c6ebca9d4237544c9ad243d Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 18 Jan 2025 00:08:00 +0300 Subject: [PATCH 2/2] fix review comments --- src/sage/rings/polynomial/multi_polynomial_libsingular.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index a4f031798ea..297554da4c3 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -2993,7 +2993,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): sage: f.monomial_coefficient(x - x) Traceback (most recent call last): ... - ValueError: mon must not be equal to 0. + ValueError: mon must not be equal to 0 """ cdef poly *p = self._poly cdef poly *m = mon._poly @@ -3002,8 +3002,8 @@ 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 == NULL: - raise ValueError("mon must not be equal to 0.") + if mon._poly is NULL: + raise ValueError("mon must not be equal to 0") while p: if p_ExpVectorEqual(p, m, r) == 1: