From 27f754acc6ebca54bc9296d0a272d28d572ffd38 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 4 Jan 2025 02:23:13 +0300 Subject: [PATCH] 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 d86aba9170c..e0bbd28a214 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)