Skip to content

Commit 9666ae7

Browse files
author
Release Manager
committed
Trac #34722: some code cleanup in WeierstrassIsomorphism
This is mainly to reduce the amount of code duplication in `sage.schemes.elliptic_curves.weierstrass_morphism.isomorphism` by turning it into a generator, plus generic style tweaks. I consider the second commit (renaming `isomorphisms()` to `_isomorphisms()`) optional: The function has been marked as "not intended for users" forever, so I figured we might as well just hide it. Note that this does not affect the `EllipticCurve_generic.isomorphisms()` ''method'' in any way. URL: https://trac.sagemath.org/34722 Reported by: lorenz Ticket author(s): Lorenz Panny Reviewer(s): John Cremona
2 parents f41abf6 + 99a6e3b commit 9666ae7

File tree

3 files changed

+114
-126
lines changed

3 files changed

+114
-126
lines changed

src/sage/schemes/elliptic_curves/ell_curve_isogeny.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
from sage.schemes.elliptic_curves.ell_generic import is_EllipticCurve
9393

9494
from sage.schemes.elliptic_curves.weierstrass_morphism \
95-
import WeierstrassIsomorphism, isomorphisms, baseWI
95+
import WeierstrassIsomorphism, _isomorphisms, baseWI
9696

9797
#
9898
# Private function for parsing input to determine the type of
@@ -3372,9 +3372,9 @@ def compute_intermediate_curves(E1, E2):
33723372
# We cannot even just use pre_iso = E1.isomorphism_to(E1w) since
33733373
# it may have u=-1; similarly for E2
33743374

3375-
urst = [w for w in isomorphisms(E1, E1w) if w[0] == 1][0]
3375+
urst = [w for w in _isomorphisms(E1, E1w) if w[0] == 1][0]
33763376
pre_iso = WeierstrassIsomorphism(E1, urst, E1w)
3377-
urst = [w for w in isomorphisms(E2w, E2) if w[0] == 1][0]
3377+
urst = [w for w in _isomorphisms(E2w, E2) if w[0] == 1][0]
33783378
post_iso = WeierstrassIsomorphism(E2w, urst, E2)
33793379
return E1w, E2w, pre_iso, post_iso
33803380

src/sage/schemes/elliptic_curves/ell_generic.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,21 +2437,21 @@ def automorphisms(self, field=None):
24372437
24382438
OUTPUT:
24392439
2440-
(list) A list of ``WeierstrassIsomorphism`` objects
2440+
(list) A list of :class:`~wm.WeierstrassIsomorphism` objects
24412441
consisting of all the isomorphisms from the curve ``self`` to
24422442
itself defined over ``field``.
24432443
24442444
EXAMPLES::
24452445
2446-
sage: E = EllipticCurve_from_j(QQ(0)) # a curve with j=0 over QQ
2447-
sage: E.automorphisms();
2446+
sage: E = EllipticCurve_from_j(QQ(0)) # a curve with j=0 over QQ
2447+
sage: E.automorphisms()
24482448
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
24492449
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
24502450
Via: (u,r,s,t) = (1, 0, 0, 0)]
24512451
24522452
We can also find automorphisms defined over extension fields::
24532453
2454-
sage: K.<a> = NumberField(x^2+3) # adjoin roots of unity
2454+
sage: K.<a> = NumberField(x^2+3) # adjoin roots of unity
24552455
sage: E.automorphisms(K)
24562456
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Number Field in a with defining polynomial x^2 + 3
24572457
Via: (u,r,s,t) = (-1, 0, 0, -1),
@@ -2461,15 +2461,12 @@ def automorphisms(self, field=None):
24612461
24622462
::
24632463
2464-
sage: [ len(EllipticCurve_from_j(GF(q,'a')(0)).automorphisms()) for q in [2,4,3,9,5,25,7,49]]
2464+
sage: [len(EllipticCurve_from_j(GF(q,'a')(0)).automorphisms()) for q in [2,4,3,9,5,25,7,49]]
24652465
[2, 24, 2, 12, 2, 6, 6, 6]
24662466
"""
2467-
if field is None:
2468-
return [wm.WeierstrassIsomorphism(self, urst, self)
2469-
for urst in wm.isomorphisms(self, self)]
2470-
E = self.change_ring(field)
2471-
return [wm.WeierstrassIsomorphism(E, urst, E)
2472-
for urst in wm.isomorphisms(E, E)]
2467+
if field is not None:
2468+
self = self.change_ring(field)
2469+
return self.isomorphisms(self)
24732470

24742471
def isomorphisms(self, other, field=None):
24752472
"""
@@ -2485,15 +2482,15 @@ def isomorphisms(self, other, field=None):
24852482
24862483
OUTPUT:
24872484
2488-
(list) A list of ``WeierstrassIsomorphism`` objects consisting of all
2485+
(list) A list of :class:`~wm.WeierstrassIsomorphism` objects consisting of all
24892486
the isomorphisms from the curve ``self`` to the curve
24902487
``other`` defined over ``field``.
24912488
24922489
EXAMPLES::
24932490
24942491
sage: E = EllipticCurve_from_j(QQ(0)) # a curve with j=0 over QQ
24952492
sage: F = EllipticCurve('27a3') # should be the same one
2496-
sage: E.isomorphisms(F);
2493+
sage: E.isomorphisms(F)
24972494
[Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
24982495
Via: (u,r,s,t) = (-1, 0, 0, -1),
24992496
Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 over Rational Field
@@ -2514,13 +2511,11 @@ def isomorphisms(self, other, field=None):
25142511
To: Elliptic Curve defined by y^2 = x^3 + x + 6 over Finite Field in a of size 7^2
25152512
Via: (u,r,s,t) = (6*a + 4, 0, 0, 0)]
25162513
"""
2517-
if field is None:
2518-
return [wm.WeierstrassIsomorphism(self, urst, other)
2519-
for urst in wm.isomorphisms(self, other)]
2520-
E = self.change_ring(field)
2521-
F = other.change_ring(field)
2522-
return [wm.WeierstrassIsomorphism(E, urst, F)
2523-
for urst in wm.isomorphisms(E, F)]
2514+
if field is not None:
2515+
self = self.change_ring(field)
2516+
other = other.change_ring(field)
2517+
return sorted(wm.WeierstrassIsomorphism(self, urst, other)
2518+
for urst in wm._isomorphisms(self, other))
25242519

25252520
def is_isomorphic(self, other, field=None):
25262521
"""
@@ -2554,17 +2549,16 @@ def is_isomorphic(self, other, field=None):
25542549
if field is None:
25552550
if self.base_ring() != other.base_ring():
25562551
return False
2557-
elif self.j_invariant() != other.j_invariant(): # easy check
2558-
return False
2559-
else:
2560-
return wm.isomorphisms(self, other, True) is not None
25612552
else:
2562-
E = self.base_extend(field)
2563-
F = other.base_extend(field)
2564-
if E.j_invariant() != F.j_invariant(): # easy check
2565-
return False
2566-
else:
2567-
return wm.isomorphisms(E, other, F) is not None
2553+
self = self.base_extend(field)
2554+
other = other.base_extend(field)
2555+
if self.j_invariant() != other.j_invariant(): # easy check
2556+
return False
2557+
try:
2558+
next(wm._isomorphisms(self, other))
2559+
except StopIteration:
2560+
return False
2561+
return True
25682562

25692563
def change_weierstrass_model(self, *urst):
25702564
r"""

0 commit comments

Comments
 (0)