From 80e34789a1507c32f0cd71d35e49ed3b23440354 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 10 Aug 2022 13:11:39 +0200 Subject: [PATCH 1/4] fix offset of remainder --- .../rings/polynomial/laurent_polynomial.pyx | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index ae56110610d..eb603944563 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1341,8 +1341,8 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): @coerce_binop def quo_rem(self, right_r): """ - Attempts to divide ``self`` by ``right`` and returns a quotient and - a remainder. + Attempts to divide ``self`` by ``right`` and returns a quotient ``q``and + a remainder ``r`` such that ``self = q*other + r``. EXAMPLES:: @@ -1351,11 +1351,24 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): (t^-2 + 1 + t^2, 0) sage: (t^-2 + 3 + t).quo_rem(t^-4) (t^2 + 3*t^4 + t^5, 0) - sage: (t^-2 + 3 + t).quo_rem(t^-4 + t) - (0, 1 + 3*t^2 + t^3) + + sage: num, den = t^-2 + t, t^-2 + 1 + sage: q, r = num.quo_rem(den) + sage: num == q * den + r + True + + TESTS: + + Check that :trac:`34330` is fixed:: + + sage: num, den = t^-2 + 3 + t, t^-4 + t + sage: q, r = num.quo_rem(den); q, r + (0, t^-2 + 3 + t) + sage: num == q * den + r + True """ cdef LaurentPolynomial_univariate right = right_r - q,r = self.__u.quo_rem(right.__u) + q, r = self.__u.quo_rem(right.__u) cdef LaurentPolynomial_univariate ql, qr ql = self._new_c() ql.__u = q @@ -1363,9 +1376,9 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ql.__normalize() qr = self._new_c() qr.__u = r - qr.__n = 0 + qr.__n = self.__n qr.__normalize() - return (ql, qr) + return ql, qr cpdef _richcmp_(self, right_r, int op): r""" @@ -3726,4 +3739,3 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): if new_ring is not None: return new_ring(ans) return ans - From e4479ed6b72f2e4391559877abd283eb3633556f Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 10 Aug 2022 13:56:54 +0200 Subject: [PATCH 2/4] fix missing space --- src/sage/rings/polynomial/laurent_polynomial.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index eb603944563..67650c76158 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1341,8 +1341,8 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): @coerce_binop def quo_rem(self, right_r): """ - Attempts to divide ``self`` by ``right`` and returns a quotient ``q``and - a remainder ``r`` such that ``self = q*other + r``. + Attempts to divide ``self`` by ``right`` and returns a quotient + ``q`` and a remainder ``r`` such that ``self = q*other + r``. EXAMPLES:: From 3da6b3deb53c37dab9676cf60c9aaff6e9e43e14 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Thu, 11 Aug 2022 00:01:29 +0200 Subject: [PATCH 3/4] better docstring --- src/sage/rings/polynomial/laurent_polynomial.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 67650c76158..0fc936f4bba 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1339,10 +1339,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): return ret @coerce_binop - def quo_rem(self, right_r): + def quo_rem(self, other): """ - Attempts to divide ``self`` by ``right`` and returns a quotient - ``q`` and a remainder ``r`` such that ``self = q*other + r``. + Divide ``self`` by ``other`` and return a quotient ``q`` + and a remainder ``r`` such that ``self == q * other + r``. EXAMPLES:: @@ -1367,7 +1367,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: num == q * den + r True """ - cdef LaurentPolynomial_univariate right = right_r + cdef LaurentPolynomial_univariate right = other q, r = self.__u.quo_rem(right.__u) cdef LaurentPolynomial_univariate ql, qr ql = self._new_c() From 87981391d758ccad3db3e5945ccff74dfb383ad9 Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Thu, 11 Aug 2022 12:41:32 +0900 Subject: [PATCH 4/4] Adding a slightly more complicated doctest and other small tweaks. --- src/sage/rings/polynomial/laurent_polynomial.pyx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 0fc936f4bba..da9b447f879 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -1340,7 +1340,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): @coerce_binop def quo_rem(self, other): - """ + r""" Divide ``self`` by ``other`` and return a quotient ``q`` and a remainder ``r`` such that ``self == q * other + r``. @@ -1352,7 +1352,8 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: (t^-2 + 3 + t).quo_rem(t^-4) (t^2 + 3*t^4 + t^5, 0) - sage: num, den = t^-2 + t, t^-2 + 1 + sage: num = t^-2 + t + sage: den = t^-2 + 1 sage: q, r = num.quo_rem(den) sage: num == q * den + r True @@ -1361,11 +1362,18 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): Check that :trac:`34330` is fixed:: - sage: num, den = t^-2 + 3 + t, t^-4 + t + sage: num = t^-2 + 3 + t + sage: den = t^-4 + t sage: q, r = num.quo_rem(den); q, r (0, t^-2 + 3 + t) sage: num == q * den + r True + + sage: num = 2*t^-4 + t^-3 + t^-2 + 2*t + 2*t^2 + sage: q, r = num.quo_rem(den); q, r + (2 + 2*t, -t^-3 + t^-2) + sage: num == q * den + r + True """ cdef LaurentPolynomial_univariate right = other q, r = self.__u.quo_rem(right.__u)