|
27 | 27 |
|
28 | 28 | from .constructor import EllipticCurve
|
29 | 29 | from sage.schemes.elliptic_curves.hom import EllipticCurveHom
|
30 |
| -from sage.structure.richcmp import (richcmp_method, richcmp, richcmp_not_equal, |
31 |
| - op_NE) |
| 30 | +from sage.structure.richcmp import (richcmp, richcmp_not_equal, op_EQ, op_NE) |
32 | 31 | from sage.structure.sequence import Sequence
|
33 | 32 | from sage.rings.all import Integer, PolynomialRing
|
34 | 33 |
|
35 |
| -def _urst_sorting_key(tup): |
36 |
| - r""" |
37 |
| - Return a sorting key for `(u,r,s,t)` tuples representing |
38 |
| - elliptic-curve isomorphisms. The key is chosen in such a |
39 |
| - way that an isomorphism and its negative appear next to |
40 |
| - one another in a sorted list, and such that normalized |
41 |
| - isomorphisms come first. One particular consequence of |
42 |
| - this is that the identity and negation morphisms are the |
43 |
| - first and second entries of the list returned by |
44 |
| - :meth:`~sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic.automorphisms`. |
45 |
| -
|
46 |
| - TESTS:: |
47 |
| -
|
48 |
| - sage: from sage.schemes.elliptic_curves.weierstrass_morphism import _urst_sorting_key |
49 |
| - sage: _urst_sorting_key((1,0,0,0)) < _urst_sorting_key((-1,0,0,0)) |
50 |
| - True |
51 |
| - sage: _urst_sorting_key((-1,0,0,0)) < _urst_sorting_key((2,0,0,0)) |
52 |
| - True |
53 |
| - sage: _urst_sorting_key((1,2,3,4)) < _urst_sorting_key((-1,0,0,0)) |
54 |
| - True |
55 |
| - """ |
56 |
| - v = tup[0] |
57 |
| - h = 0 if v == 1 else 1 if v == -1 else 2 |
58 |
| - if -v < v: |
59 |
| - v = -v |
60 |
| - return (h, v) + tup |
61 |
| - |
62 |
| -@richcmp_method |
63 | 34 | class baseWI():
|
64 | 35 | r"""
|
65 | 36 | This class implements the basic arithmetic of isomorphisms between
|
@@ -113,35 +84,6 @@ def __init__(self, u=1, r=0, s=0, t=0):
|
113 | 84 | self.s = s
|
114 | 85 | self.t = t
|
115 | 86 |
|
116 |
| - def __richcmp__(self, other, op): |
117 |
| - """ |
118 |
| - Standard comparison function. |
119 |
| -
|
120 |
| - The ordering is done according to :func:`_urst_sorting_key`. |
121 |
| -
|
122 |
| - EXAMPLES:: |
123 |
| -
|
124 |
| - sage: from sage.schemes.elliptic_curves.weierstrass_morphism import baseWI |
125 |
| - sage: baseWI(1,2,3,4) == baseWI(1,2,3,4) |
126 |
| - True |
127 |
| - sage: baseWI(1,2,3,4) != baseWI(1,2,3,4) |
128 |
| - False |
129 |
| - sage: baseWI(1,2,3,4) < baseWI(1,2,3,5) |
130 |
| - True |
131 |
| - sage: baseWI(1,2,3,4) > baseWI(1,2,3,4) |
132 |
| - False |
133 |
| -
|
134 |
| - It will never return equality if ``other`` is of another type:: |
135 |
| -
|
136 |
| - sage: baseWI() == 1 |
137 |
| - False |
138 |
| - """ |
139 |
| - if not isinstance(other, baseWI): |
140 |
| - return op == op_NE |
141 |
| - key1 = _urst_sorting_key(self.tuple()) |
142 |
| - key2 = _urst_sorting_key(other.tuple()) |
143 |
| - return richcmp(key1, key2, op) |
144 |
| - |
145 | 87 | def tuple(self):
|
146 | 88 | r"""
|
147 | 89 | Return the parameters `u,r,s,t` as a tuple.
|
@@ -595,7 +537,21 @@ def _comparison_impl(left, right, op):
|
595 | 537 | if lx != rx:
|
596 | 538 | return richcmp_not_equal(lx, rx, op)
|
597 | 539 |
|
598 |
| - return baseWI.__richcmp__(left, right, op) |
| 540 | + if op in (op_EQ, op_NE): |
| 541 | + return richcmp(left.tuple(), right.tuple(), op) |
| 542 | + |
| 543 | + # This makes sure that the identity and negation morphisms |
| 544 | + # come first in a sorted list of WeierstrassIsomorphisms. |
| 545 | + # More generally, we're making sure that a morphism and its |
| 546 | + # negative appear next to each other, and that those pairs |
| 547 | + # of isomorphisms satisfying u=+-1 come first. |
| 548 | + def _sorting_key(iso): |
| 549 | + v, w = iso.tuple(), (-iso).tuple() |
| 550 | + i = 0 if (1,0,0,0) in (v,w) else 1 |
| 551 | + j = 0 if v[0] == 1 else 1 if w[0] == 1 else 2 |
| 552 | + return (i,) + min(v,w) + (j,) + v |
| 553 | + |
| 554 | + return richcmp(_sorting_key(left), _sorting_key(right), op) |
599 | 555 |
|
600 | 556 | def _eval(self, P):
|
601 | 557 | r"""
|
|
0 commit comments