Skip to content

Commit 6eaaf7e

Browse files
committed
change sorting order for WeierstrassIsomorphisms
1 parent d92c9f4 commit 6eaaf7e

File tree

2 files changed

+71
-16
lines changed

2 files changed

+71
-16
lines changed

src/sage/schemes/elliptic_curves/ell_generic.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,9 @@ def automorphisms(self, field=None):
24302430
"""
24312431
Return the set of isomorphisms from self to itself (as a list).
24322432
2433+
The identity and negation morphisms are guaranteed to appear
2434+
as the first and second entry of the returned list.
2435+
24332436
INPUT:
24342437
24352438
- ``field`` (default ``None``) -- a field into which the
@@ -2447,23 +2450,52 @@ def automorphisms(self, field=None):
24472450
sage: E = EllipticCurve_from_j(QQ(0)) # a curve with j=0 over QQ
24482451
sage: E.automorphisms()
24492452
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
2450-
Via: (u,r,s,t) = (-1, 0, 0, -1), Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
2451-
Via: (u,r,s,t) = (1, 0, 0, 0)]
2453+
Via: (u,r,s,t) = (1, 0, 0, 0),
2454+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
2455+
Via: (u,r,s,t) = (-1, 0, 0, -1)]
24522456
24532457
We can also find automorphisms defined over extension fields::
24542458
24552459
sage: K.<a> = NumberField(x^2+3) # adjoin roots of unity
24562460
sage: E.automorphisms(K)
24572461
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2458-
Via: (u,r,s,t) = (-1, 0, 0, -1),
2459-
...
2460-
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2461-
Via: (u,r,s,t) = (1, 0, 0, 0)]
2462+
Via: (u,r,s,t) = (1, 0, 0, 0),
2463+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2464+
Via: (u,r,s,t) = (-1, 0, 0, -1),
2465+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2466+
Via: (u,r,s,t) = (-1/2*a - 1/2, 0, 0, 0),
2467+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2468+
Via: (u,r,s,t) = (1/2*a + 1/2, 0, 0, -1),
2469+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2470+
Via: (u,r,s,t) = (1/2*a - 1/2, 0, 0, 0),
2471+
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
2472+
Via: (u,r,s,t) = (-1/2*a + 1/2, 0, 0, -1)]
24622473
24632474
::
24642475
24652476
sage: [len(EllipticCurve_from_j(GF(q,'a')(0)).automorphisms()) for q in [2,4,3,9,5,25,7,49]]
24662477
[2, 24, 2, 12, 2, 6, 6, 6]
2478+
2479+
TESTS:
2480+
2481+
Random testing::
2482+
2483+
sage: p = random_prime(100)
2484+
sage: k = randrange(1,30)
2485+
sage: F.<t> = GF((p,k))
2486+
sage: while True:
2487+
....: try:
2488+
....: E = EllipticCurve(list((F^5).random_element()))
2489+
....: except ArithmeticError:
2490+
....: continue
2491+
....: break
2492+
sage: Aut = E.automorphisms()
2493+
sage: Aut[0] == E.multiplication_by_m_isogeny(1)
2494+
True
2495+
sage: Aut[1] == E.multiplication_by_m_isogeny(-1)
2496+
True
2497+
sage: sorted(Aut) == Aut
2498+
True
24672499
"""
24682500
if field is not None:
24692501
self = self.change_ring(field)
@@ -2493,9 +2525,9 @@ def isomorphisms(self, other, field=None):
24932525
sage: F = EllipticCurve('27a3') # should be the same one
24942526
sage: E.isomorphisms(F)
24952527
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
2496-
Via: (u,r,s,t) = (-1, 0, 0, -1),
2528+
Via: (u,r,s,t) = (1, 0, 0, 0),
24972529
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
2498-
Via: (u,r,s,t) = (1, 0, 0, 0)]
2530+
Via: (u,r,s,t) = (-1, 0, 0, -1)]
24992531
25002532
We can also find isomorphisms defined over extension fields::
25012533

src/sage/schemes/elliptic_curves/weierstrass_morphism.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@
3232
from sage.structure.sequence import Sequence
3333
from sage.rings.all import Integer, PolynomialRing
3434

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
3561

3662
@richcmp_method
3763
class baseWI():
@@ -91,12 +117,7 @@ def __richcmp__(self, other, op):
91117
"""
92118
Standard comparison function.
93119
94-
The ordering is just lexicographic on the tuple `(u,r,s,t)`.
95-
96-
.. NOTE::
97-
98-
In a list of automorphisms, there is no guarantee that the
99-
identity will be first!
120+
The ordering is done according to :func:`_urst_sorting_key`.
100121
101122
EXAMPLES::
102123
@@ -117,7 +138,9 @@ def __richcmp__(self, other, op):
117138
"""
118139
if not isinstance(other, baseWI):
119140
return op == op_NE
120-
return richcmp(self.tuple(), other.tuple(), op)
141+
key1 = _urst_sorting_key(self.tuple())
142+
key2 = _urst_sorting_key(other.tuple())
143+
return richcmp(key1, key2, op)
121144

122145
def tuple(self):
123146
r"""
@@ -543,7 +566,7 @@ def _comparison_impl(left, right, op):
543566
sage: w1 = E.isomorphism_to(F)
544567
sage: w1 == w1
545568
True
546-
sage: w2 = F.automorphisms()[0] * w1
569+
sage: w2 = F.automorphisms()[1] * w1
547570
sage: w1 == w2
548571
False
549572

0 commit comments

Comments
 (0)