Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
implement Polynomial_generic_sparse.__floordiv__
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Oct 12, 2022
1 parent 54cd6fe commit 9577386
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/sage/rings/polynomial/polynomial_element_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from sage.libs.pari.all import pari_gen
from sage.structure.richcmp import richcmp, richcmp_item, rich_to_bool, rich_to_bool_sgn
from sage.structure.element import coerce_binop
from sage.structure.element import coerce_binop, parent

from sage.rings.infinity import infinity, Infinity
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -543,6 +543,29 @@ def degree(self, gen=None):
return -1
return max(self.__coeffs)

def __floordiv__(self, right):
"""
Return the quotient upon division (no remainder).
EXAMPLES::
sage: R.<x> = PolynomialRing(QQbar, sparse=True)
sage: f = (1+2*x)^3 + 3*x; f
8*x^3 + 12*x^2 + 9*x + 1
sage: g = f // (1+2*x); g
4*x^2 + 4*x + 5/2
sage: f - g * (1+2*x)
-3/2
sage: f.quo_rem(1+2*x)
(4*x^2 + 4*x + 5/2, -3/2)
"""
P = self.parent()
if P is parent(right):
return self._floordiv_(right)
d = P.base_ring()(right)
return self.map_coefficients(lambda c: c // d)

def _add_(self, right):
r"""
EXAMPLES::
Expand Down

0 comments on commit 9577386

Please sign in to comment.