From fc84daf06800ae377dc6558f1c35da57828403a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 22 Aug 2017 18:06:23 +0200 Subject: [PATCH] py3: some work on cmp in heegner.py --- src/sage/schemes/elliptic_curves/heegner.py | 93 ++++++++++++++++----- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index 5344a9ef227..10ff79f1112 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -98,6 +98,8 @@ from sage.misc.cachefunc import cached_method from sage.structure.sage_object import SageObject +from sage.structure.richcmp import (richcmp_method, richcmp, + richcmp_not_equal, rich_to_bool) import sage.rings.number_field.number_field_element import sage.rings.number_field.number_field as number_field @@ -252,7 +254,8 @@ def __eq__(self, other): EXAMPLES:: - sage: E = EllipticCurve('389a'); K5 = E.heegner_point(-7,5).ring_class_field() + sage: E = EllipticCurve('389a') + sage: K5 = E.heegner_point(-7,5).ring_class_field() sage: K11 = E.heegner_point(-7,11).ring_class_field() sage: K5 == K11 False @@ -263,6 +266,24 @@ def __eq__(self, other): """ return isinstance(other, RingClassField) and self.__D == other.__D and self.__c == other.__c + def __ne__(self, other): + """ + Check whether ``self`` is not equal to ``other``. + + EXAMPLES:: + + sage: E = EllipticCurve('389a') + sage: K5 = E.heegner_point(-7,5).ring_class_field() + sage: K11 = E.heegner_point(-7,11).ring_class_field() + sage: K5 != K11 + True + sage: K5 != K5 + False + sage: K11 != 11 + True + """ + return not (self == other) + def __hash__(self): """ Used for computing hash of ``self``. @@ -628,6 +649,21 @@ def __eq__(self, G): """ return isinstance(G, GaloisGroup) and (G.__field,G.__base) == (self.__field,self.__base) + def __ne__(self, other): + """ + EXAMPLES:: + + sage: G = EllipticCurve('389a').heegner_point(-7,5).ring_class_field().galois_group() + sage: G != G + False + sage: G != 0 + True + sage: H = EllipticCurve('389a').heegner_point(-7,11).ring_class_field().galois_group() + sage: G != H + True + """ + return not (self == other) + def __hash__(self): """ Return hash of this Galois group, which is the same as the @@ -1193,6 +1229,7 @@ def complex_conjugation(self): # ################################################################################## + class GaloisAutomorphism(SageObject): """ An abstract automorphism of a ring class field. @@ -1244,6 +1281,7 @@ def domain(self): """ return self.parent().field() + class GaloisAutomorphismComplexConjugation(GaloisAutomorphism): """ The complex conjugation automorphism of a ring class field. @@ -1306,6 +1344,18 @@ def __eq__(self, right): return isinstance(right, GaloisAutomorphismComplexConjugation) and \ self.parent() == right.parent() + def __ne__(self, other): + """ + EXAMPLES:: + + sage: G = EllipticCurve('389a').heegner_point(-7,5).ring_class_field().galois_group() + sage: conj = G.complex_conjugation() + sage: conj2 = sage.schemes.elliptic_curves.heegner.GaloisAutomorphismComplexConjugation(G) + sage: conj != conj2 + False + """ + return not (self == other) + def _repr_(self): """ Return print representation of the complex conjugation automorphism. @@ -1352,6 +1402,8 @@ def order(self): """ return ZZ(2) + +@richcmp_method class GaloisAutomorphismQuadraticForm(GaloisAutomorphism): """ An automorphism of a ring class field defined by a quadratic form. @@ -1494,11 +1546,14 @@ def __hash__(self): """ return hash((self.parent(), tuple(self.__quadratic_form))) - def __eq__(self, right): + def __richcmp__(self, right, op): """ + Comparison. + EXAMPLES:: - sage: H = heegner_points(389,-7,5); s = H.ring_class_field().galois_group(H.quadratic_field())[1] + sage: H = heegner_points(389,-7,5) + sage: s = H.ring_class_field().galois_group(H.quadratic_field())[1] sage: s == s True sage: s == s*s @@ -1507,31 +1562,23 @@ def __eq__(self, right): False sage: s == s*s*s*s*s*s*s True - """ - return isinstance(right, GaloisAutomorphismQuadraticForm) and \ - self.parent() == right.parent() and \ - self.quadratic_form().is_equivalent(right.quadratic_form()) - def __cmp__(self, right): - """ - Compare ``self`` and right. Used mainly so that lists of - automorphisms are sorted consistently between runs. - - EXAMPLES:: - - sage: H = heegner_points(389,-20,3); s = H.ring_class_field().galois_group(H.quadratic_field())[0] - sage: s.__cmp__(s) - 0 - sage: s.__cmp__(0) != 0 + sage: H = heegner_points(389,-20,3) + sage: s = H.ring_class_field().galois_group(H.quadratic_field())[0] + sage: s == s True + sage: s == 0 + False """ if not isinstance(right, GaloisAutomorphismQuadraticForm): - return cmp(type(self), type(right)) - c = cmp(self.parent(), right.parent()) - if c: return c + return NotImplemented + lx = self.parent() + rx = right.parent() + if lx != rx: + return richcmp_not_equal(lx, rx, op) if self.quadratic_form().is_equivalent(right.quadratic_form()): - return 0 - return cmp(self.quadratic_form(), right.quadratic_form()) + return rich_to_bool(op, 0) + return richcmp(self.quadratic_form(), right.quadratic_form(), op) def _repr_(self): """