Skip to content

Commit fc8db57

Browse files
Release Managervbraun
Release Manager
authored andcommitted
Trac #20062: Make _floordiv_() return the Euclidean quotient for power series over fields
There exists a method `PowerSeries_poly.__floordiv__()`, but it is not clear how it differs from ordinary division (see comment:43:ticket:15601), or how it should differ mathematically. We replace this method by a new method `PowerSeries._floordiv_()`, which returns the Euclidean quotient over fields and is a deprecated alias for `_div_()` over other rings. URL: http://trac.sagemath.org/20062 Reported by: pbruin Ticket author(s): Peter Bruin Reviewer(s): Bruno Grenet
2 parents dcf6f2a + b7cd5cb commit fc8db57

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

src/sage/rings/power_series_poly.pyx

-30
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ from power_series_ring_element cimport PowerSeries
1010
from sage.structure.element cimport Element, ModuleElement, RingElement
1111
from infinity import infinity, is_Infinite
1212
from sage.libs.all import PariError
13-
from power_series_ring_element import is_PowerSeries
14-
import rational_field
1513
from sage.misc.superseded import deprecated_function_alias
1614

1715
cdef class PowerSeries_poly(PowerSeries):
@@ -557,34 +555,6 @@ cdef class PowerSeries_poly(PowerSeries):
557555
"""
558556
return PowerSeries_poly(self._parent, c * self.__f, self._prec, check=False)
559557

560-
def __floordiv__(self, denom):
561-
"""
562-
EXAMPLES::
563-
564-
sage: R.<t> = ZZ[[]] ; f = t**10-1 ; g = 1+t+t^7 ; h = f.add_bigoh(20)
565-
sage: f // g
566-
-1 + t - t^2 + t^3 - t^4 + t^5 - t^6 + 2*t^7 - 3*t^8 + 4*t^9 - 4*t^10 + 5*t^11 - 6*t^12 + 7*t^13 - 9*t^14 + 12*t^15 - 16*t^16 + 20*t^17 - 25*t^18 + 31*t^19 + O(t^20)
567-
sage: (f // g) * g
568-
-1 + t^10 + O(t^20)
569-
sage: g // h
570-
-1 - t - t^7 - t^10 - t^11 - t^17 + O(t^20)
571-
sage: (g // h) * h
572-
1 + t + t^7 + O(t^20)
573-
sage: h // g
574-
-1 + t - t^2 + t^3 - t^4 + t^5 - t^6 + 2*t^7 - 3*t^8 + 4*t^9 - 4*t^10 + 5*t^11 - 6*t^12 + 7*t^13 - 9*t^14 + 12*t^15 - 16*t^16 + 20*t^17 - 25*t^18 + 31*t^19 + O(t^20)
575-
sage: (h // g) * g
576-
-1 + t^10 + O(t^20)
577-
"""
578-
try:
579-
return PowerSeries.__div__(self, denom)
580-
except (PariError, ZeroDivisionError) as e: # PariError to general?
581-
if is_PowerSeries(denom) and denom.degree() == 0 and denom[0] in self._parent.base_ring():
582-
denom = denom[0]
583-
elif not denom in self._parent.base_ring():
584-
raise ZeroDivisionError, e
585-
return PowerSeries_poly(self._parent,
586-
self.__f // denom, self._prec)
587-
588558
def __lshift__(PowerSeries_poly self, n):
589559
"""
590560
Shift self to the left by n, i.e. multiply by x^n.

src/sage/rings/power_series_ring_element.pyx

+28-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ import rational_field, integer_ring
108108
from integer import Integer
109109
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
110110
from sage.libs.pari.all import pari
111-
from sage.misc.superseded import deprecated_function_alias
111+
from sage.misc.superseded import deprecated_function_alias, deprecation
112+
from warnings import warn
112113

113114
from sage.categories.fields import Fields
114115
_Fields = Fields()
@@ -1039,6 +1040,32 @@ cdef class PowerSeries(AlgebraElement):
10391040
num = self
10401041
return num*inv
10411042

1043+
cpdef RingElement _floordiv_(self, RingElement denom):
1044+
"""
1045+
Euclidean division (over fields) or ordinary division (over
1046+
other rings; deprecated).
1047+
1048+
EXAMPLES::
1049+
1050+
sage: A.<q> = GF(7)[[]]
1051+
sage: (q^2 - 1) // (q + 1)
1052+
doctest:...: UserWarning: the operator // now returns the Euclidean quotient for power series over fields, use / for the true quotient
1053+
6 + q + O(q^20)
1054+
1055+
sage: R.<t> = ZZ[[]]
1056+
sage: (t**10 - 1) // (1 + t + t^7)
1057+
doctest:...: DeprecationWarning: the operator // is deprecated for power series over non-fields, use / instead
1058+
See http://trac.sagemath.org/20062 for details.
1059+
-1 + t - t^2 + t^3 - t^4 + t^5 - t^6 + 2*t^7 - 3*t^8 + 4*t^9 - 4*t^10 + 5*t^11 - 6*t^12 + 7*t^13 - 9*t^14 + 12*t^15 - 16*t^16 + 20*t^17 - 25*t^18 + 31*t^19 + O(t^20)
1060+
"""
1061+
try:
1062+
q, r = self.quo_rem(denom)
1063+
warn("the operator // now returns the Euclidean quotient for power series over fields, use / for the true quotient")
1064+
return q
1065+
except (AttributeError, NotImplementedError):
1066+
deprecation(20062, "the operator // is deprecated for power series over non-fields, use / instead")
1067+
return self._div_(denom)
1068+
10421069
def __mod__(self, other):
10431070
"""
10441071
EXAMPLES::

0 commit comments

Comments
 (0)