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

Commit

Permalink
Implement division as true division for CategoryObject
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Nov 6, 2015
1 parent 94635cc commit df04f20
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ it makes sense to build on top of the base class
This base class provides a lot more methods than a general parent::

sage: [p for p in dir(Field) if p not in dir(Parent)]
['__div__',
'__fraction_field',
['__fraction_field',
'__ideal_monoid',
'__iter__',
'__pow__',
'__rdiv__',
'__rpow__',
'__rtruediv__',
'__rxor__',
'__truediv__',
'__xor__',
'_an_element',
'_an_element_c',
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def quotient_ring(self, I, names=None):
"""
return self.quotient(I,names=names)

def __div__(self, I):
def __truediv__(self, I):
"""
Since assigning generator names would not work properly,
the construction of a quotient ring using division syntax
Expand Down
4 changes: 2 additions & 2 deletions src/sage/modular/abvar/abvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ def quotient(self, other):
sage: J0(11).direct_product(J1(13))
Abelian variety J0(11) x J1(13) of dimension 3
"""
return self.__div__(other)
return self / other

def __div__(self, other):
def __truediv__(self, other):
"""
Compute the quotient of self and other, where other is either an
abelian subvariety of self or a finite subgroup of self.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/fg_pid/fgp_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _repr_(self):
I = str(self.invariants()).replace(',)',')')
return "Finitely generated module V/W over %s with invariants %s"%(self.base_ring(), I)

def __div__(self, other):
def __truediv__(self, other):
"""
Return the quotient self/other, where other must be a
submodule of self.
Expand Down
12 changes: 4 additions & 8 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2989,12 +2989,10 @@ def quotient(self, sub, check=True):
else:
raise NotImplementedError("quotients of modules over rings other than fields or ZZ is not fully implemented")

def __div__(self, sub, check=True):
def __truediv__(self, sub):
"""
Return the quotient of self by the given submodule sub.
This just calls self.quotient(sub, check).
EXAMPLES::
sage: V1 = ZZ^2; W1 = V1.span([[1,2],[3,4]])
Expand All @@ -3004,7 +3002,7 @@ def __div__(self, sub, check=True):
sage: V2/W2
Finitely generated module V/W over Integer Ring with invariants (4, 12)
"""
return self.quotient(sub, check)
return self.quotient(sub, check=True)

class FreeModule_generic_field(FreeModule_generic_pid):
"""
Expand Down Expand Up @@ -3826,12 +3824,10 @@ def linear_dependence(self, vectors, zeros='left', check=True):
A = sage.matrix.constructor.matrix(vectors) # as rows, so get left kernel
return A.left_kernel(basis=basis).basis()

def __div__(self, sub, check=True):
def __truediv__(self, sub):
"""
Return the quotient of self by the given subspace sub.
This just calls self.quotient(sub, check)
EXAMPLES::
sage: V = RDF^3; W = V.span([[1,0,-1], [1,-1,0]])
Expand All @@ -3851,7 +3847,7 @@ def __div__(self, sub, check=True):
sage: Q(W.0)
(0.0)
"""
return self.quotient(sub, check)
return self.quotient(sub, check=True)

def quotient(self, sub, check=True):
"""
Expand Down
17 changes: 1 addition & 16 deletions src/sage/quivers/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,24 +1501,9 @@ def _repr_(self):
"""
return "Representation with dimension vector {}".format(self.dimension_vector())

def __div__(self, sub):
"""
This and :meth:`__truediv__` below together overload the ``/``
operator.
TESTS::
sage: Q = DiGraph({1:{2:['a']}}).path_semigroup()
sage: P = Q.P(GF(3), 1)
sage: R = P.radical()
sage: (P/R).is_simple()
True
"""
return self.quotient(sub)

def __truediv__(self, sub):
"""
This and :meth:`__div__` above together overload the ``/`` operator.
Overload the ``/`` operator.
TESTS::
Expand Down
5 changes: 2 additions & 3 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ cdef class Ring(ParentWithGens):
"""
return self.quotient(I, names=names)

def __div__(self, I):
def __truediv__(self, I):
"""
Dividing one ring by another is not supported because there is no good
way to specify generator names.
Expand All @@ -647,8 +647,7 @@ cdef class Ring(ParentWithGens):
...
TypeError: Use self.quo(I) or self.quotient(I) to construct the quotient ring.
"""
raise TypeError, "Use self.quo(I) or self.quotient(I) to construct the quotient ring."
#return self.quotient(I, names=None)
raise TypeError("Use self.quo(I) or self.quotient(I) to construct the quotient ring.")

def quotient_ring(self, I, names=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/generic/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def _point_homset(self, *args, **kwds):
"""
raise NotImplementedError

def __div__(self, Y):
def __truediv__(self, Y):
"""
Return the base extension of self to Y.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/toric/chow_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def _rational_equivalence_relations(self, V):
return V.span(relations)


def __div__(self, other):
def __truediv__(self, other):
r"""
Return the quotient of the Chow group by a subgroup.
Expand Down
27 changes: 27 additions & 0 deletions src/sage/structure/category_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ This example illustrates generators for a free module over `\ZZ`.
((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))
"""

from __future__ import division

#*****************************************************************************
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -800,6 +802,31 @@ cdef class CategoryObject(sage_object.SageObject):
self._hash_value = hash(repr(self))
return self._hash_value

##############################################################################
# For compatibility with Python 2
##############################################################################
def __div__(self, other):
"""
Implement Python 2 division as true division.
EXAMPLES::
sage: V = QQ^2
sage: V.__div__(V.span([(1,3)]))
Vector space quotient V/W of dimension 1 over Rational Field where
V: Vector space of dimension 2 over Rational Field
W: Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 3]
sage: V.__truediv__(V.span([(1,3)]))
Vector space quotient V/W of dimension 1 over Rational Field where
V: Vector space of dimension 2 over Rational Field
W: Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 3]
"""
return self / other


class localvars:
r"""
Expand Down

0 comments on commit df04f20

Please sign in to comment.