From d0bdb05ca416e50288c4552a137cc0643e155a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 22 Jun 2017 10:59:25 +0200 Subject: [PATCH] py3: some care for cmp in modular (lseries, congroup, smoothchar) --- src/sage/modular/abvar/lseries.py | 113 +++++++++++++----- .../modular/arithgroup/congroup_gammaH.py | 16 +-- src/sage/modular/local_comp/smoothchar.py | 52 ++++++-- 3 files changed, 131 insertions(+), 50 deletions(-) diff --git a/src/sage/modular/abvar/lseries.py b/src/sage/modular/abvar/lseries.py index e9095f9bae4..a8d4432eeb5 100644 --- a/src/sage/modular/abvar/lseries.py +++ b/src/sage/modular/abvar/lseries.py @@ -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): """ @@ -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. @@ -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. @@ -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): """ @@ -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): """ @@ -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. @@ -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. @@ -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): """ @@ -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. @@ -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()) diff --git a/src/sage/modular/arithgroup/congroup_gammaH.py b/src/sage/modular/arithgroup/congroup_gammaH.py index 687bf122699..c8ad9e7f1dc 100644 --- a/src/sage/modular/arithgroup/congroup_gammaH.py +++ b/src/sage/modular/arithgroup/congroup_gammaH.py @@ -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 @@ -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 @@ -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 @@ -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())) diff --git a/src/sage/modular/local_comp/smoothchar.py b/src/sage/modular/local_comp/smoothchar.py index afaa44310ea..8b1df1db11c 100644 --- a/src/sage/modular/local_comp/smoothchar.py +++ b/src/sage/modular/local_comp/smoothchar.py @@ -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 @@ -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:: @@ -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""" @@ -371,7 +384,7 @@ def _element_constructor_(self, x): else: raise TypeError - def __cmp__(self, other): + def __eq__(self, other): r""" TESTS:: @@ -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"""