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

Commit

Permalink
Trac #18578: Add special function __truediv__() to some pyx-modules
Browse files Browse the repository at this point in the history
This also increases the number of methods of "MatrixSpace(QQ,2)" in
coercion_and_categories.rst by one.
  • Loading branch information
wluebbe committed Jun 22, 2015
1 parent 610a2c4 commit 8941921
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ And indeed, ``MS2`` has *more* methods than ``MS1``::
sage: len([s for s in dir(MS1) if inspect.ismethod(getattr(MS1,s,None))])
57
sage: len([s for s in dir(MS2) if inspect.ismethod(getattr(MS2,s,None))])
85
86

This is because the class of ``MS2`` also inherits from the parent
class for algebras::
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_GF2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ cdef class ntl_GF2:
GF2_mul(r.x, (<ntl_GF2>self).x, (<ntl_GF2>other).x)
return r

def __div__(self, other):
def __truediv__(self, other):
"""
sage: o = ntl.GF2(1)
sage: z = ntl.GF2(0)
Expand All @@ -149,6 +149,9 @@ cdef class ntl_GF2:
GF2_div(r.x, (<ntl_GF2>self).x, (<ntl_GF2>other).x)
return r

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __sub__(self, other):
"""
sage: o = ntl.GF2(1)
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_GF2E.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ cdef class ntl_GF2E:
GF2E_add(r.x, self.x, (<ntl_GF2E>other).x)
return r

def __div__(ntl_GF2E self, other):
def __truediv__(ntl_GF2E self, other):
"""
EXAMPLES:
sage: ctx = ntl.GF2EContext(ntl.GF2X([1,1,0,1,1,0,0,0,1]))
Expand All @@ -274,6 +274,9 @@ cdef class ntl_GF2E:
GF2E_div(r.x, self.x, (<ntl_GF2E>other).x)
return r

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __neg__(ntl_GF2E self):
"""
EXAMPLES:
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_GF2X.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ cdef class ntl_GF2X:
GF2X_mul(r.x, self.x, (<ntl_GF2X>other).x)
return r

def __div__(ntl_GF2X self, b):
def __truediv__(ntl_GF2X self, b):
"""
EXAMPLES:
sage: a = ntl.GF2X(4)
Expand All @@ -217,6 +217,9 @@ cdef class ntl_GF2X:
raise ArithmeticError, "self (=%s) is not divisible by b (=%s)"%(self, b)
return q

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def DivRem(ntl_GF2X self, b):
"""
EXAMPLES:
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_ZZX.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ cdef class ntl_ZZX:
sig_off()
return r

def __div__(ntl_ZZX self, ntl_ZZX other):
def __truediv__(ntl_ZZX self, ntl_ZZX other):
"""
Compute quotient self / other, if the quotient is a polynomial.
Otherwise an Exception is raised.
Expand Down Expand Up @@ -351,6 +351,9 @@ cdef class ntl_ZZX:
result = make_ZZX_sig_off(q)
return result

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __mod__(ntl_ZZX self, ntl_ZZX other):
"""
Given polynomials a, b in ZZ[X], there exist polynomials q, r
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_ZZ_pEX.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ cdef class ntl_ZZ_pEX:
sig_off()
return r

def __div__(ntl_ZZ_pEX self, ntl_ZZ_pEX other):
def __truediv__(ntl_ZZ_pEX self, ntl_ZZ_pEX other):
"""
Compute quotient self / other, if the quotient is a polynomial.
Otherwise an Exception is raised.
Expand Down Expand Up @@ -371,6 +371,9 @@ cdef class ntl_ZZ_pEX:
raise ArithmeticError, "self (=%s) is not divisible by other (=%s)"%(self, other)
return r

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __mod__(ntl_ZZ_pEX self, ntl_ZZ_pEX other):
"""
Given polynomials a, b in ZZ_pE[X], if p is prime and the defining modulus irreducible,
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_ZZ_pX.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ cdef class ntl_ZZ_pX:
sig_off()
return r

def __div__(ntl_ZZ_pX self, ntl_ZZ_pX other):
def __truediv__(ntl_ZZ_pX self, ntl_ZZ_pX other):
"""
Compute quotient self / other, if the quotient is a polynomial.
Otherwise an Exception is raised.
Expand Down Expand Up @@ -410,6 +410,9 @@ cdef class ntl_ZZ_pX:
raise ArithmeticError, "self (=%s) is not divisible by other (=%s)"%(self, other)
return r

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __mod__(ntl_ZZ_pX self, ntl_ZZ_pX other):
"""
Given polynomials a, b in ZZ_p[X], if p is prime, then there exist polynomials q, r
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_lzz_p.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ cdef class ntl_zz_p:
zz_p_mul(y.x, self.x, (<ntl_zz_p>other).x)
return y

def __div__(ntl_zz_p self, other):
def __truediv__(ntl_zz_p self, other):
"""
EXAMPLES:
sage: ntl.zz_p(5,23) / ntl.zz_p(2,23)
Expand All @@ -255,6 +255,9 @@ cdef class ntl_zz_p:
sig_off()
return q

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __pow__(ntl_zz_p self, long n, ignored):
"""
Return the n-th nonnegative power of self.
Expand Down
5 changes: 4 additions & 1 deletion src/sage/libs/ntl/ntl_lzz_pX.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ cdef class ntl_zz_pX:
sig_off()
return y

def __div__(ntl_zz_pX self, other):
def __truediv__(ntl_zz_pX self, other):
"""
Compute quotient self / other, if the quotient is a polynomial.
Otherwise an Exception is raised.
Expand Down Expand Up @@ -359,6 +359,9 @@ cdef class ntl_zz_pX:
raise ArithmeticError, "self (=%s) is not divisible by other (=%s)"%(self, other)
return q

def __div__(self, other):
return PyNumber_TrueDivide(self, other)

def __mod__(ntl_zz_pX self, other):
"""
Given polynomials a, b in ZZ[X], there exist polynomials q, r
Expand Down
4 changes: 3 additions & 1 deletion src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
return self.roots(ring=ring, multiplicities=False)[0]


def __div__(self, right):
def __truediv__(self, right):
"""
EXAMPLES::
Expand Down Expand Up @@ -1797,6 +1797,8 @@ cdef class Polynomial(CommutativeAlgebraElement):
pass
return RingElement.__div__(self, right)

def __div__(self, other):
return Polynomial.__truediv__(self, other)

def __pow__(self, right, modulus):
"""
Expand Down
5 changes: 4 additions & 1 deletion src/sage/schemes/elliptic_curves/period_lattice_region.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ cdef class PeriodicRegion:
m, n = self.data.shape
return self.data[int(m * i), int(n * j)]

def __div__(self, unsigned int n):
def __truediv__(self, unsigned int n):
"""
Returns a new region of the same resolution that is the image
of this region under the map z -> z/n.
Expand Down Expand Up @@ -446,6 +446,9 @@ cdef class PeriodicRegion:
new_data[(a*rows+i)//n, (b*cols+j)//n] = data[i,j]
return PeriodicRegion(self.w1, self.w2, new_data)

def __div__(self, other):
return PeriodicRegion.__truediv__(self, other)

def __invert__(self):
"""
Returns the complement of this region.
Expand Down

0 comments on commit 8941921

Please sign in to comment.