From 202a17cf16126f0b82db004fe7a38a03bcba0244 Mon Sep 17 00:00:00 2001 From: Dave Witte Morris Date: Tue, 10 Oct 2023 16:41:54 -0600 Subject: [PATCH] ZeroDivisionError in gcd of sparse polynomials --- .../polynomial/polynomial_element_generic.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 58a6a4d2308..8f8a296b488 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -953,6 +953,17 @@ def gcd(self,other,algorithm=None): 1 sage: (6*x).gcd(9) 3 + + Check that :trac:`36427` is fixed:: + + sage: P = PolynomialRing(ZZ, "q", sparse=True) + sage: q = P.gen() + sage: 2*q^-100 + 2/q^100 + sage: gcd(1, q^100) + 1 + sage: gcd(q^0, q^100) + 1 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -969,8 +980,8 @@ def gcd(self,other,algorithm=None): # sd = self.degree() od = other.degree() - if max(sd,od) < 100 or \ - min(len(self.__coeffs)/sd, len(other.__coeffs)/od) > .06: + if ((sd < 100 or len(self.__coeffs)/sd > .06) + and (od < 100 or len(other.__coeffs)/od > .06)): implementation = "FLINT" else: implementation = "NTL"