Skip to content

Commit c9e9646

Browse files
committed
compare entire (u,r,s,t) tuple
In characteristics 2 and 3, there can be multiple (u,r,s,t) between two curves with the same u-coefficient.
1 parent 4c4ce93 commit c9e9646

File tree

1 file changed

+16
-60
lines changed

1 file changed

+16
-60
lines changed

src/sage/schemes/elliptic_curves/weierstrass_morphism.py

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,10 @@
2727

2828
from .constructor import EllipticCurve
2929
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)
3231
from sage.structure.sequence import Sequence
3332
from sage.rings.all import Integer, PolynomialRing
3433

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
6334
class baseWI():
6435
r"""
6536
This class implements the basic arithmetic of isomorphisms between
@@ -113,35 +84,6 @@ def __init__(self, u=1, r=0, s=0, t=0):
11384
self.s = s
11485
self.t = t
11586

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-
14587
def tuple(self):
14688
r"""
14789
Return the parameters `u,r,s,t` as a tuple.
@@ -595,7 +537,21 @@ def _comparison_impl(left, right, op):
595537
if lx != rx:
596538
return richcmp_not_equal(lx, rx, op)
597539

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)
599555

600556
def _eval(self, P):
601557
r"""

0 commit comments

Comments
 (0)