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

Commit

Permalink
py3: some care for cmp in modular (lseries, congroup, smoothchar)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Jun 22, 2017
1 parent 61fa91f commit d0bdb05
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 50 deletions.
113 changes: 81 additions & 32 deletions src/sage/modular/abvar/lseries.py
Expand Up @@ -32,6 +32,9 @@
class Lseries(SageObject):
"""
Base class for `L`-series attached to modular abelian varieties.
This is a common base class for complex and `p`-adic `L`-series
of modular abelian varieties.
"""
def __init__(self, abvar):
"""
Expand Down Expand Up @@ -65,6 +68,7 @@ def abelian_variety(self):
"""
return self.__abvar


class Lseries_complex(Lseries):
"""
A complex `L`-series attached to a modular abelian variety.
Expand Down Expand Up @@ -140,7 +144,7 @@ def __call__(self, s, prec=53):

return prod(L(s) for L in factors)

def __cmp__(self, other):
def __eq__(self, other):
"""
Compare this complex `L`-series to another one.
Expand All @@ -150,22 +154,43 @@ def __cmp__(self, other):
OUTPUT:
-1, 0, or 1
boolean
EXAMPLES::
sage: L = J0(37)[0].lseries(); M = J0(37)[1].lseries()
sage: cmp(L,M)
-1
sage: cmp(L,L)
0
sage: cmp(M,L)
1
sage: L = J0(37)[0].lseries()
sage: M = J0(37)[1].lseries()
sage: L == M
False
sage: L == L
True
"""
if not isinstance(other, Lseries_complex):
return cmp(type(self), type(other))
return cmp(self.abelian_variety(), other.abelian_variety())
return False
return self.abelian_variety() == other.abelian_variety()

def __ne__(self, other):
"""
Check whether ``self`` is not equal to ``other``.
INPUT:
- ``other`` -- object
OUTPUT:
boolean
EXAMPLES::
sage: L = J0(37)[0].lseries()
sage: M = J0(37)[1].lseries()
sage: L != M
True
sage: L != L
False
"""
return not (self == other)

def _repr_(self):
"""
Expand All @@ -181,7 +206,7 @@ def _repr_(self):
sage: L._repr_()
'Complex L-series attached to Abelian variety J0(37) of dimension 2'
"""
return "Complex L-series attached to %s"%self.abelian_variety()
return "Complex L-series attached to %s" % self.abelian_variety()

def vanishes_at_1(self):
"""
Expand Down Expand Up @@ -270,6 +295,7 @@ def rational_part(self):

lratio = rational_part


class Lseries_padic(Lseries):
"""
A `p`-adic `L`-series attached to a modular abelian variety.
Expand All @@ -289,7 +315,7 @@ def __init__(self, abvar, p):
raise ValueError("p (=%s) must be prime"%p)
self.__p = p

def __cmp__(self, other):
def __eq__(self, other):
"""
Compare this `p`-adic `L`-series to another one.
Expand All @@ -302,29 +328,50 @@ def __cmp__(self, other):
OUTPUT:
-1, 0, or 1
boolean
EXAMPLES::
sage: L = J0(37)[0].padic_lseries(5); M = J0(37)[1].padic_lseries(5)
sage: L = J0(37)[0].padic_lseries(5)
sage: M = J0(37)[1].padic_lseries(5)
sage: K = J0(37)[0].padic_lseries(3)
sage: cmp(L,K)
1
sage: cmp(K,L)
-1
sage: K < L
sage: L == K
False
sage: L == M
False
sage: L == L
True
sage: cmp(L,M)
-1
sage: cmp(M,L)
1
sage: cmp(L,L)
0
"""
if not isinstance(other, Lseries_padic):
return cmp(type(self), type(other))
return cmp((self.abelian_variety(), self.__p),
(other.abelian_variety(), other.__p))
return False
return (self.abelian_variety() == other.abelian_variety() and
self.__p == other.__p)

def __ne__(self, other):
"""
Check whether ``self`` is not equal to ``other``.
INPUT:
other -- object
OUTPUT:
boolean
EXAMPLES::
sage: L = J0(37)[0].padic_lseries(5)
sage: M = J0(37)[1].padic_lseries(5)
sage: K = J0(37)[0].padic_lseries(3)
sage: L != K
True
sage: L != M
True
sage: L != L
False
"""
return not (self == other)

def prime(self):
"""
Expand All @@ -340,7 +387,9 @@ def prime(self):
def power_series(self, n=2, prec=5):
"""
Return the `n`-th approximation to this `p`-adic `L`-series as
a power series in `T`. Each coefficient is a `p`-adic number
a power series in `T`.
Each coefficient is a `p`-adic number
whose precision is provably correct.
NOTE: This is not yet implemented.
Expand Down Expand Up @@ -369,5 +418,5 @@ def _repr_(self):
sage: L._repr_()
'5-adic L-series attached to Simple abelian subvariety 37a(1,37) of dimension 1 of J0(37)'
"""
return "%s-adic L-series attached to %s"%(self.__p, self.abelian_variety())

return "%s-adic L-series attached to %s" % (self.__p,
self.abelian_variety())
16 changes: 8 additions & 8 deletions src/sage/modular/arithgroup/congroup_gammaH.py
Expand Up @@ -282,7 +282,7 @@ def divisor_subgroups(self):
v = self.__H
ans = []
for M in self.level().divisors():
w = [a % M for a in v if a%M]
w = [a % M for a in v if a % M]
ans.append(GammaH_constructor(M, w))
return ans

Expand Down Expand Up @@ -314,9 +314,9 @@ def __cmp__(self, other):
EXAMPLES::
sage: G = GammaH(86, [9])
sage: G.__cmp__(G)
0
sage: G.__cmp__(GammaH(86, [11])) is not 0
sage: G == G
True
sage: G != GammaH(86, [11])
True
sage: Gamma1(11) < Gamma0(11)
True
Expand All @@ -325,9 +325,9 @@ def __cmp__(self, other):
sage: Gamma0(11) == GammaH(11, [2])
True
sage: G = Gamma0(86)
sage: G.__cmp__(G)
0
sage: G.__cmp__(GammaH(86, [11])) is not 0
sage: G == G
True
sage: G != GammaH(86, [11])
True
sage: Gamma1(17) < Gamma0(17)
True
Expand All @@ -354,7 +354,7 @@ def __cmp__(self, other):
[1, 11, 17, 19],
[1, 5, 7, 11, 13, 17, 19, 23]]
"""
if is_GammaH(other):
if isinstance(other, GammaH_class):
return (cmp(self.level(), other.level())
or -cmp(self.index(), other.index())
or cmp(self._list_of_elements_in_H(), other._list_of_elements_in_H()))
Expand Down
52 changes: 42 additions & 10 deletions src/sage/modular/local_comp/smoothchar.py
Expand Up @@ -46,6 +46,7 @@
from sage.structure.element import MultiplicativeGroupElement, parent
from sage.structure.parent_base import ParentWithBase
from sage.structure.sequence import Sequence
from sage.structure.richcmp import richcmp_not_equal, richcmp
from sage.rings.all import QQ, ZZ, Zmod, NumberField
from sage.rings.ring import is_Ring
from sage.misc.cachefunc import cached_method
Expand Down Expand Up @@ -103,10 +104,18 @@ def _check_level(self):
self._c = self._c - 1
self._check_level()

def __cmp__(self, other):
def _richcmp_(self, other, op):
r"""
Compare self and other. Note that this only gets called when the
parents of self and other are identical.
Compare ``self`` and ``other``.
Note that this only gets called when the
parents of ``self`` and ``other`` are identical.
INPUT:
- ``other`` -- another smooth character
- ``op`` -- a comparison operator (see :mod:`sage.structure.richcmp`)
EXAMPLES::
Expand All @@ -122,8 +131,12 @@ def __cmp__(self, other):
sage: chi1 == loads(dumps(chi1))
True
"""
assert other.parent() is self.parent()
return cmp(self.level(), other.level()) or cmp(self._values_on_gens, other._values_on_gens)
lx = self.level()
rx = other.level()
if lx != rx:
return richcmp_not_equal(lx, rx, op)

return richcmp(self._values_on_gens, other._values_on_gens, op)

def multiplicative_order(self):
r"""
Expand Down Expand Up @@ -371,7 +384,7 @@ def _element_constructor_(self, x):
else:
raise TypeError

def __cmp__(self, other):
def __eq__(self, other):
r"""
TESTS::
Expand All @@ -386,10 +399,29 @@ def __cmp__(self, other):
sage: G == SmoothCharacterGroupQp(3, QQ)
True
"""
return cmp(type(self), type(other)) \
or cmp(self.prime(), other.prime()) \
or cmp(self.number_field(), other.number_field()) \
or cmp(self.base_ring(), other.base_ring())
return (type(self) == type(other) and
self.prime() == other.prime() and
self.number_field() == other.number_field() and
self.base_ring() == other.base_ring())

def __ne__(self, other):
"""
Check whether ``self`` is not equalt to ``other``.
EXAMPLES::
sage: from sage.modular.local_comp.smoothchar import SmoothCharacterGroupQp
sage: G = SmoothCharacterGroupQp(3, QQ)
sage: G != SmoothCharacterGroupQp(3, QQ[I])
True
sage: G != 7
True
sage: G != SmoothCharacterGroupQp(7, QQ)
True
sage: G != SmoothCharacterGroupQp(3, QQ)
False
"""
return not (self == other)

def _coerce_map_from_(self, other):
r"""
Expand Down

0 comments on commit d0bdb05

Please sign in to comment.