Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
change sorting order for WeierstrassIsomorphisms
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyx4 committed Nov 7, 2022
1 parent d92c9f4 commit 6eaaf7e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
48 changes: 40 additions & 8 deletions src/sage/schemes/elliptic_curves/ell_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,9 @@ def automorphisms(self, field=None):
"""
Return the set of isomorphisms from self to itself (as a list).
The identity and negation morphisms are guaranteed to appear
as the first and second entry of the returned list.
INPUT:
- ``field`` (default ``None``) -- a field into which the
Expand All @@ -2447,23 +2450,52 @@ def automorphisms(self, field=None):
sage: E = EllipticCurve_from_j(QQ(0)) # a curve with j=0 over QQ
sage: E.automorphisms()
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
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
Via: (u,r,s,t) = (1, 0, 0, 0)]
Via: (u,r,s,t) = (1, 0, 0, 0),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
Via: (u,r,s,t) = (-1, 0, 0, -1)]
We can also find automorphisms defined over extension fields::
sage: K.<a> = NumberField(x^2+3) # adjoin roots of unity
sage: E.automorphisms(K)
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (-1, 0, 0, -1),
...
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (1, 0, 0, 0)]
Via: (u,r,s,t) = (1, 0, 0, 0),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (-1, 0, 0, -1),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (-1/2*a - 1/2, 0, 0, 0),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (1/2*a + 1/2, 0, 0, -1),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (1/2*a - 1/2, 0, 0, 0),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
Via: (u,r,s,t) = (-1/2*a + 1/2, 0, 0, -1)]
::
sage: [len(EllipticCurve_from_j(GF(q,'a')(0)).automorphisms()) for q in [2,4,3,9,5,25,7,49]]
[2, 24, 2, 12, 2, 6, 6, 6]
TESTS:
Random testing::
sage: p = random_prime(100)
sage: k = randrange(1,30)
sage: F.<t> = GF((p,k))
sage: while True:
....: try:
....: E = EllipticCurve(list((F^5).random_element()))
....: except ArithmeticError:
....: continue
....: break
sage: Aut = E.automorphisms()
sage: Aut[0] == E.multiplication_by_m_isogeny(1)
True
sage: Aut[1] == E.multiplication_by_m_isogeny(-1)
True
sage: sorted(Aut) == Aut
True
"""
if field is not None:
self = self.change_ring(field)
Expand Down Expand Up @@ -2493,9 +2525,9 @@ def isomorphisms(self, other, field=None):
sage: F = EllipticCurve('27a3') # should be the same one
sage: E.isomorphisms(F)
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
Via: (u,r,s,t) = (-1, 0, 0, -1),
Via: (u,r,s,t) = (1, 0, 0, 0),
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
Via: (u,r,s,t) = (1, 0, 0, 0)]
Via: (u,r,s,t) = (-1, 0, 0, -1)]
We can also find isomorphisms defined over extension fields::
Expand Down
39 changes: 31 additions & 8 deletions src/sage/schemes/elliptic_curves/weierstrass_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@
from sage.structure.sequence import Sequence
from sage.rings.all import Integer, PolynomialRing

def _urst_sorting_key(tup):
r"""
Return a sorting key for `(u,r,s,t)` tuples representing
elliptic-curve isomorphisms. The key is chosen in such a
way that an isomorphism and its negative appear next to
one another in a sorted list, and such that normalized
isomorphisms come first. One particular consequence of
this is that the identity and negation morphisms are the
first and second entries of the list returned by
:meth:`~sage.schemes.elliptic_curves.ell_generic.EllipticCurve_generic.automorphisms`.
TESTS::
sage: from sage.schemes.elliptic_curves.weierstrass_morphism import _urst_sorting_key
sage: _urst_sorting_key((1,0,0,0)) < _urst_sorting_key((-1,0,0,0))
True
sage: _urst_sorting_key((-1,0,0,0)) < _urst_sorting_key((2,0,0,0))
True
sage: _urst_sorting_key((1,2,3,4)) < _urst_sorting_key((-1,0,0,0))
True
"""
v = tup[0]
h = 0 if v == 1 else 1 if v == -1 else 2
if -v < v:
v = -v
return (h, v) + tup

@richcmp_method
class baseWI():
Expand Down Expand Up @@ -91,12 +117,7 @@ def __richcmp__(self, other, op):
"""
Standard comparison function.
The ordering is just lexicographic on the tuple `(u,r,s,t)`.
.. NOTE::
In a list of automorphisms, there is no guarantee that the
identity will be first!
The ordering is done according to :func:`_urst_sorting_key`.
EXAMPLES::
Expand All @@ -117,7 +138,9 @@ def __richcmp__(self, other, op):
"""
if not isinstance(other, baseWI):
return op == op_NE
return richcmp(self.tuple(), other.tuple(), op)
key1 = _urst_sorting_key(self.tuple())
key2 = _urst_sorting_key(other.tuple())
return richcmp(key1, key2, op)

def tuple(self):
r"""
Expand Down Expand Up @@ -543,7 +566,7 @@ def _comparison_impl(left, right, op):
sage: w1 = E.isomorphism_to(F)
sage: w1 == w1
True
sage: w2 = F.automorphisms()[0] * w1
sage: w2 = F.automorphisms()[1] * w1
sage: w1 == w2
False
Expand Down

0 comments on commit 6eaaf7e

Please sign in to comment.