Ticket #13615: trac_13615_review.patch

File trac_13615_review.patch, 54.7 KB (added by cremona, 6 years ago)

Apply after previous patches

  • doc/en/reference/plane_curves/index.rst

    # HG changeset patch
    # User John Cremona <john.cremona@gmail.com>
    # Date 1374837115 -3600
    # Node ID 77f072e8ef8b032017f1622bd2905570406b87c1
    # Parent  de0b02bc6b89721b3d585c5f716a883d630bf9ef
    Add elliptic curve isogenies for several new small degrees
    
    diff --git a/doc/en/reference/plane_curves/index.rst b/doc/en/reference/plane_curves/index.rst
    a b  
    3131   sage/schemes/elliptic_curves/kodaira_symbol
    3232   sage/schemes/elliptic_curves/weierstrass_morphism
    3333   sage/schemes/elliptic_curves/ell_curve_isogeny
     34   sage/schemes/elliptic_curves/isogeny_genus_0
    3435   sage/schemes/elliptic_curves/ell_wp
    3536   sage/schemes/elliptic_curves/period_lattice
    3637   sage/schemes/elliptic_curves/formal_group
  • sage/schemes/elliptic_curves/ell_curve_isogeny.py

    diff --git a/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/sage/schemes/elliptic_curves/ell_curve_isogeny.py
    a b  
    4040
    4141.. Warning::
    4242
    43    Only cyclic isogenies are implemented (except for [2]). Some
     43   Only cyclic, separable isogenies are implemented (except for [2]). Some
    4444   algorithms may need the isogeny to be normalized.
    4545
    4646AUTHORS:
     
    5050- Chris Wuthrich : 7/09: changes: add check of input, not the full list is needed.
    5151  10/09: eliminating some bugs.
    5252
    53 - John Cremona and Jenny Cooley: 2009-07..11: implement `l`-isogenies
    54   for `l` = 2, 3, 5, 7 13 (the genus 0 cases) and also for `l` = 11,
    55   17, 19, 37, 43, 67 or 163 over `\QQ` (the sporadic cases with only
    56   finitely many `j`-invariants each).
    5753"""
    5854
    5955#*****************************************************************************
  • sage/schemes/elliptic_curves/ell_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_field.py b/sage/schemes/elliptic_curves/ell_field.py
    a b  
    835835        """
    836836        return isogeny_codomain_from_kernel(self, kernel, degree=None)
    837837
    838     def isogenies_prime_degree(self, l=None):
     838    def isogenies_prime_degree(self, l=None, max_l=31):
    839839        """
    840         Generic code, valid for all fields, for those l for which the
    841         modular curve has genus 0.
     840        Generic code, valid for all fields, for arbitrary prime `l` not equal to the characteristic.
    842841
    843842        INPUT:
    844843
    845         - ``l`` -- either None, a prime or a list of primes, from [2,3,5,7,13].
     844        - ``l`` -- either None, a prime or a list of primes.
     845        - ``max_l`` -- a bound on the primes to be tested (ignored unless `l` is None).
    846846
    847847        OUTPUT:
    848848
     
    851851        METHOD:
    852852
    853853        Calls the generic function
    854         ``isogenies_prime_degree_genus_0()``.  This requires that
     854        ``isogenies_prime_degree()``.  This requires that
    855855        certain operations have been implemented over the base field,
    856856        such as root-finding for univariate polynomials.
    857857
     
    860860            sage: F = QQbar                     
    861861            sage: E = EllipticCurve(F, [1,18]); E
    862862            Elliptic Curve defined by y^2 = x^3 + x + 18 over Algebraic Field
    863            
     863            sage: E.isogenies_prime_degree()
     864            Traceback (most recent call last):
     865            ...
     866            NotImplementedError: This code could be implemented for QQbar, but has not been yet.
     867
    864868            sage: F = CC
    865869            sage: E = EllipticCurve(F, [1,18]); E
    866870            Elliptic Curve defined by y^2 = x^3 + 1.00000000000000*x + 18.0000000000000 over Complex Field with 53 bits of precision
     
    873877
    874878            sage: E = EllipticCurve(GF(next_prime(1000000)), [7,8])
    875879            sage: E.isogenies_prime_degree()
    876             [Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 970389*x + 794257 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 29783*x + 206196 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 999960*x + 78 over Finite Field of size 1000003, Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 878063*x + 845666 over Finite Field of size 1000003, Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 375648*x + 342776 over Finite Field of size 1000003]
     880            [Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 970389*x + 794257 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 29783*x + 206196 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 999960*x + 78 over Finite Field of size 1000003, Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 878063*x + 845666 over Finite Field of size 1000003, Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 375648*x + 342776 over Finite Field of size 1000003, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 347438*x + 594729 over Finite Field of size 1000003, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 674846*x + 7392 over Finite Field of size 1000003, Isogeny of degree 23 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 390065*x + 605596 over Finite Field of size 1000003]
    877881            sage: E.isogenies_prime_degree(2)           
    878882            [Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 970389*x + 794257 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 29783*x + 206196 over Finite Field of size 1000003, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 7*x + 8 over Finite Field of size 1000003 to Elliptic Curve defined by y^2 = x^3 + 999960*x + 78 over Finite Field of size 1000003]           
    879883            sage: E.isogenies_prime_degree(3)
     
    892896            Traceback (most recent call last):
    893897            ...
    894898            ValueError: 4 is not prime.
    895             sage: E.isogenies_prime_degree([2, 29])
    896             Traceback (most recent call last):
    897             ...
    898             NotImplementedError: Over general fields, only isogenies of degree 2, 3, 5, 7 or 13 have been implemented.
    899899            sage: E.isogenies_prime_degree(4)
    900900            Traceback (most recent call last):
    901901            ...
    902902            ValueError: 4 is not prime.
    903903            sage: E.isogenies_prime_degree(11)
    904             Traceback (most recent call last):
    905             ...
    906             NotImplementedError: Over general fields, only isogenies of degree 2, 3, 5, 7 or 13 have been implemented.
    907            
     904            []
    908905            sage: E = EllipticCurve(GF(17),[2,0])                     
    909906            sage: E.isogenies_prime_degree(3)
    910907            []
     
    917914
    918915            sage: E.isogenies_prime_degree(3)
    919916            [Isogeny of degree 3 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 9*x + 11 over Finite Field in a of size 13^4]
    920             sage: E.isogenies_prime_degree([2, 3, 5, 7, 13])
    921             Traceback (most recent call last):
    922             ...
    923             NotImplementedError: 2, 3, 5, 7 and 13-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny.
    924             sage: E.isogenies_prime_degree([2, 3, 5, 7])               
    925             [Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 7*x + 4 over Finite Field in a of size 13^4, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + (8*a^3+2*a^2+7*a+5)*x + (12*a^3+3*a^2+4*a+4) over Finite Field in a of size 13^4, Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + (5*a^3+11*a^2+6*a+11)*x + (a^3+10*a^2+9*a) over Finite Field in a of size 13^4, Isogeny of degree 3 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 9*x + 11 over Finite Field in a of size 13^4, Isogeny of degree 7 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 3*x + 11 over Finite Field in a of size 13^4, Isogeny of degree 7 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 9*x + 2 over Finite Field in a of size 13^4]
     917
     918        Example to show that separable isogenies of degree equal to the characteristic are now implemented::
     919
     920            sage: E.isogenies_prime_degree(13)
     921            [Isogeny of degree 13 from Elliptic Curve defined by y^2 = x^3 + 2*x + 8 over Finite Field in a of size 13^4 to Elliptic Curve defined by y^2 = x^3 + 6*x + 5 over Finite Field in a of size 13^4]
    926922
    927923        Examples over number fields (other than QQ)::
    928924
    929925            sage: QQroot2.<e> = NumberField(x^2-2)
    930             sage: E = EllipticCurve(QQroot2,[1,1])
    931             sage: E.isogenies_prime_degree(11)
    932             Traceback (most recent call last):
    933             ...
    934             NotImplementedError: Over general fields, only isogenies of degree 2, 3, 5, 7 or 13 have been implemented.
    935             sage: E.isogenies_prime_degree(5)
    936             []
     926            sage: E = EllipticCurve(QQroot2, j=8000)
     927            sage: E.isogenies_prime_degree()
     928            [Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + (-150528000)*x + (-629407744000) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 = x^3 + (-602112000)*x + 5035261952000 over Number Field in e with defining polynomial x^2 - 2,
     929            Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + (-150528000)*x + (-629407744000) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 = x^3 + (903168000*e-1053696000)*x + (14161674240000*e-23288086528000) over Number Field in e with defining polynomial x^2 - 2,
     930            Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 + (-150528000)*x + (-629407744000) over Number Field in e with defining polynomial x^2 - 2 to Elliptic Curve defined by y^2 = x^3 + (-903168000*e-1053696000)*x + (-14161674240000*e-23288086528000) over Number Field in e with defining polynomial x^2 - 2]
    937931
    938932            sage: E = EllipticCurve(QQroot2, [1,0,1,4, -6]); E
    939933            Elliptic Curve defined by y^2 + x*y + y = x^3 + 4*x + (-6) over Number Field in e with defining polynomial x^2 - 2
     
    950944        if F == rings.QQbar:
    951945            raise NotImplementedError, "This code could be implemented for QQbar, but has not been yet."
    952946
    953         from isogeny_genus_0 import isogenies_prime_degree_genus_0
     947        from isogeny_genus_0 import isogenies_prime_degree
    954948        if l is None:
    955             l = [2, 3, 5, 7, 13]
    956         if l in [2, 3, 5, 7, 13]:
    957             return isogenies_prime_degree_genus_0(self, l)
     949            from sage.rings.all import prime_range
     950            l = prime_range(max_l+1)
     951
    958952        if type(l) != list:
     953            try:
     954                l = rings.ZZ(l)
     955            except TypeError:
     956                raise ValueError, "%s is not prime."%l
    959957            if l.is_prime():
    960                 raise NotImplementedError, "Over general fields, only isogenies of degree 2, 3, 5, 7 or 13 have been implemented."
     958                return isogenies_prime_degree(self, l)
    961959            else:
    962960                raise ValueError, "%s is not prime."%l
    963         isogs = []
    964         i = 0
    965         while i<len(l):
    966             isogenies = [f for f in self.isogenies_prime_degree(l[i]) if not f in isogs]
    967             isogs.extend(isogenies)
    968             i = i+1
    969         return isogs
     961
     962        L = list(set(l))
     963        try:
     964            L = [rings.ZZ(l) for l in L]
     965        except TypeError:
     966            raise ValueError, "%s is not a list of primes."%l
     967
     968        L.sort()
     969        return sum([isogenies_prime_degree(self,l) for l in L],[])
    970970
    971971    def is_isogenous(self, other, field=None):
    972972        """
  • sage/schemes/elliptic_curves/ell_number_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_number_field.py b/sage/schemes/elliptic_curves/ell_number_field.py
    a b  
    20452045        # over general number fields.  But here we do at least try
    20462046        # some easy cases:
    20472047
    2048         for l in [2,3,5,7,13]:
    2049             if any([E2.is_isomorphic(f.codomain()) for f in E1.isogenies_prime_degree(l)]):
    2050                 return True
     2048        if any([E2.is_isomorphic(f.codomain()) for f in E1.isogenies_prime_degree()]):
     2049            return True
    20512050
    20522051        # Next we try looking modulo some more primes:
    20532052       
  • sage/schemes/elliptic_curves/isogeny_genus_0.py

    diff --git a/sage/schemes/elliptic_curves/isogeny_genus_0.py b/sage/schemes/elliptic_curves/isogeny_genus_0.py
    a b  
    11r"""
    2 Isogenies
     2Isogenies of small prime degree.
    33
    4 We compute isogenies of degree l = 2, 3, 5, 7, or 13, where the modular curve X_0(l) has genus 0.
     4Functions for the computation of isogenies of small primes
     5degree. First: `l` = 2, 3, 5, 7, or 13, where the modular curve
     6`X_0(l)` has genus 0.  Second: `l` = 11, 17, 19, 23, 29, 31, 41, 47,
     759, or 71, where `X_0^+(l)` has genus 0 and `X_0(l)` is elliptic or
     8hyperelliptic.  Also: `l` = 11, 17, 19, 37, 43, 67 or 163 over `\QQ`
     9(the sporadic cases with only finitely many `j`-invariants each).  All
     10the above only require factorization of a polynomial of degree `l+1`.
     11Finally, a generic function which works for arbitrary odd primes `l`
     12(including the characteristic), but requires factorization of the
     13`l`-division polynomial, of degree `(l^2-1)/2`.
    514
    615
    716AUTHORS:
    817
    9 - YOUR NAME (2012-10-18): initial version
     18- John Cremona and Jenny Cooley: 2009-07..11: the genus 0 cases the sporadic cases over `\QQ`.
    1019
    11 - person (date in ISO year-month-day format): short desc
     20- Kimi Tsukazaki and John Cremona: 2013-07: The 10 (hyper)-elliptic
     21  cases and the generic algorithm.  See [KT2013]_.
    1222
    13 ...
     23REFERENCES:
    1424
    15 - person (date in ISO year-month-day format): short desc
     25.. [KT2013] Explicit Isogenies of Elliptic Curves, PhD thesis, University of Warwick, 2013.
    1626
    17 ...
    18 
    19 Lots and lots of examples.
    2027"""
    2128
    2229#*****************************************************************************
     
    2835#                  http://www.gnu.org/licenses/
    2936#*****************************************************************************
    3037
    31 from copy import deepcopy, copy
    32 
    3338from sage.categories import homset
    3439
    35 from sage.categories.morphism import Morphism
    36 
    3740from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    3841from sage.rings.polynomial.polynomial_ring import polygen
    39 from sage.rings.all import Integer, ZZ
    40 from sage.rings.laurent_series_ring import LaurentSeriesRing
    41 from sage.rings.polynomial.all import is_Polynomial
     42from sage.rings.all import Integer, ZZ, QQ
    4243from sage.schemes.elliptic_curves.all import EllipticCurve
    43 from sage.schemes.elliptic_curves.all import is_EllipticCurve
    44 
    45 from sage.rings.number_field.number_field_base import is_NumberField
    46 
    47 from sage.rings.rational_field import is_RationalField, QQ
    48 
    49 from sage.schemes.elliptic_curves.weierstrass_morphism import WeierstrassIsomorphism
    50 
    51 from sage.sets.set import Set
    5244
    5345from sage.misc.cachefunc import cached_function
    5446
     
    10395    elif l==7: return (t**2+5*t+1)**3 * (t**2+13*t+49)
    10496    elif l==13: return (t**2+5*t+13)*(t**4+7*t**3+20*t**2+19*t+1)**3
    10597    else:
    106         raise ValueError, "The only genus zero primes are 2, 3, 5, 7 or 13."
     98        raise ValueError("The only genus zero primes are 2, 3, 5, 7 or 13.")
    10799
    108100@cached_function
    109101def Fricke_module(l):
     
    140132        sage: Fricke_module(13)
    141133        (t^14 + 26*t^13 + 325*t^12 + 2548*t^11 + 13832*t^10 + 54340*t^9 + 157118*t^8 + 333580*t^7 + 509366*t^6 + 534820*t^5 + 354536*t^4 + 124852*t^3 + 15145*t^2 + 746*t + 13)/t
    142134    """
    143     try:       
     135    try:
    144136        t = PolynomialRing(QQ,'t').gen()
    145137        return Fricke_polynomial(l) / t
    146138    except ValueError:
    147         raise ValueError, "The only genus zero primes are 2, 3, 5, 7 or 13."
     139        raise ValueError("The only genus zero primes are 2, 3, 5, 7 or 13.")
    148140
    149141@cached_function
    150142def Psi(l, use_stored=True):
    151143    r"""
    152     Generic kernel polynomial for genus one primes.
     144    Generic kernel polynomial for genus zero primes.
    153145
    154146    For each of the primes `l` for which `X_0(l)` has genus zero
    155147    (namely `l=2,3,5,7,13`), we may define an elliptic curve `E_t`
     
    200192        sage: assert Psi(13, use_stored=True) == Psi(13, use_stored=False) # not tested (very long time)
    201193    """
    202194    if not l in [2,3,5,7,13]:
    203         raise ValueError, "Genus zero primes are 2, 3, 5, 7 or 13."
     195        raise ValueError("Genus zero primes are 2, 3, 5, 7 or 13.")
    204196
    205197    R = PolynomialRing(ZZ,2,'Xt')
    206198    X,t = R.gens()
     
    279271        Isogeny of degree 5 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field]
    280272    """
    281273    if not l in [2, 3, 5, 7, 13, None]:
    282         raise ValueError, "Isogenies must be of degree 2, 3, 5, 7 or 13."
     274        raise ValueError("%s is not a genus 0 prime."%l)
    283275    F = E.base_ring()
    284276    j = E.j_invariant()
    285277    if F.characteristic() in [2, 3, l]:
    286         raise NotImplementedError, "2, 3, 5, 7 and 13-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny."
     278        raise NotImplementedError("2, 3, 5, 7 and 13-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny.")
    287279    if l==2:
    288280        return isogenies_2(E)
    289281    if l==3:
     
    470462        [Isogeny of degree 163 from Elliptic Curve defined by y^2 = x^3 - 34790720*x - 78984748304 over Rational Field to Elliptic Curve defined by y^2 = x^3 - 924354639680*x + 342062961763303088 over Rational Field]
    471463    """
    472464    if E.base_ring() != QQ:
    473         raise ValueError, "The elliptic curve must be defined over QQ."
     465        raise ValueError("The elliptic curve must be defined over QQ.")
    474466    j = E.j_invariant()
    475467    j = QQ(j)
    476468    if l != None:
     
    627619    """
    628620    F = E.base_field()
    629621    if E.j_invariant() != 0:
    630         raise ValueError, "j-invariant must be 0."
     622        raise ValueError("j-invariant must be 0.")
    631623    if F.characteristic() in [2,3,5]:
    632         raise NotImplementedError, "Not implemented in characteristic 2, 3 or 5."
     624        raise NotImplementedError("Not implemented in characteristic 2, 3 or 5.")
    633625    if not F(5).is_square():
    634626        return []
    635627    Ew = E.short_weierstrass_model()
     
    702694    """
    703695    F = E.base_field()
    704696    if E.j_invariant() != 1728:
    705         raise ValueError, "j-invariant must be 1728."
     697        raise ValueError("j-invariant must be 1728.")
    706698    if F.characteristic() in [2,3,5]:
    707         raise NotImplementedError, "Not implemented in characteristic 2, 3 or 5."
     699        raise NotImplementedError("Not implemented in characteristic 2, 3 or 5.")
    708700    model = "minimal" if F is QQ else None
    709701    # quick test for a negative answer (from Fricke module)
    710702    square5 = F(5).is_square()
     
    792784        -158428486656000/7*a^3 - 34534529335296000]
    793785    """
    794786    if E.j_invariant()!=0:
    795         raise ValueError, "j-invariant must be 0."
     787        raise ValueError("j-invariant must be 0.")
    796788    F = E.base_field()
    797789    if F.characteristic() in [2,3,7]:
    798         raise NotImplementedError, "Not implemented when the characteristic of the base field is 2, 3 or 7."
     790        raise NotImplementedError("Not implemented when the characteristic of the base field is 2, 3 or 7.")
    799791    x = polygen(F)
    800792    Ew = E.short_weierstrass_model()
    801793    iso = E.isomorphism_to(Ew)
     
    888880        -1
    889881    """
    890882    if E.j_invariant()!=1728:
    891         raise ValueError, "j_invariant must be 1728 (in base field)."
     883        raise ValueError("j_invariant must be 1728 (in base field).")
    892884    F = E.base_field()
    893885    if F.characteristic() in [2,3,7]:
    894         raise NotImplementedError, "Not implemented when the characteristic of the base field is 2, 3 or 7."
     886        raise NotImplementedError("Not implemented when the characteristic of the base field is 2, 3 or 7.")
    895887    Ew = E.short_weierstrass_model()
    896888    iso = E.isomorphism_to(Ew)
    897889    a = Ew.a4()
     
    986978        [(0, 0, 0, -739946459/23857162861049856*a^11 - 2591641747/1062017577504*a^8 + 16583647773233/4248070310016*a^5 - 14310911337/378211388*a^2, 26146225/4248070310016*a^9 + 7327668845/14750244132*a^6 + 174618431365/756422776*a^3 - 378332499709/94552847), (0, 0, 0, 3501275/5964290715262464*a^11 + 24721025/531008788752*a^8 - 47974903745/1062017577504*a^5 - 6773483100/94552847*a^2, 6699581/4248070310016*a^9 + 1826193509/14750244132*a^6 - 182763866047/756422776*a^3 - 321460597/94552847)]
    987979    """
    988980    if E.j_invariant()!=0:
    989         raise ValueError, "j-invariant must be 0."
     981        raise ValueError("j-invariant must be 0.")
    990982    F = E.base_field()
    991983    if F.characteristic() in [2,3,13]:
    992         raise NotImplementedError, "Not implemented when the characteristic of the base field is 2, 3 or 13."
     984        raise NotImplementedError("Not implemented when the characteristic of the base field is 2, 3 or 13.")
    993985    Ew = E.short_weierstrass_model()
    994986    iso = E.isomorphism_to(Ew)
    995987    a = Ew.a6()
     
    10971089   
    10981090    """
    10991091    if E.j_invariant()!=1728:
    1100         raise ValueError, "j-invariant must be 1728."
     1092        raise ValueError("j-invariant must be 1728.")
    11011093    F = E.base_field()
    1102     if F.characteristic() in [2, 3, 7, 13, 167, 233, 271, 1117]:
    1103         raise NotImplementedError, "Not implemented when the characteristic of the base field is 2, 3 or 13."
     1094    if F.characteristic() in [2, 3, 13]:
     1095        raise NotImplementedError("Not implemented when the characteristic of the base field is 2, 3 or 13.")
    11041096    Ew = E.short_weierstrass_model()
    11051097    iso = E.isomorphism_to(Ew)
    11061098    a = Ew.a4()
     
    11441136   
    11451137    return isogs
    11461138
     1139# List of primes l for which X_0(l) is (hyper)elliptic and X_0^+(l) has genus 0
     1140
     1141hyperelliptic_primes = [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]
     1142
    11471143@cached_function
    11481144def hyperelliptic_isogeny_data(l):
     1145    r"""
     1146    Helper function for elliptic curve isogenies.
     1147
     1148    INPUT:
     1149
     1150    - ``l`` -- a prime in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]
     1151
     1152    OUTPUT:
     1153
     1154    - A dict holding a collection of precomputed data needed for computing `l`-isogenies.
     1155
     1156    EXAMPLES::
     1157
     1158        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import hyperelliptic_isogeny_data
     1159        sage: HID = hyperelliptic_isogeny_data(11)
     1160        sage: HID['A2']
     1161        55*u - 33
     1162        sage: HID['A4']
     1163        -183*u^2 + 738*u - 180*v - 135
     1164        sage: HID['A6']
     1165        1330*u^3 - 11466*u^2 + 1332*u*v + 2646*u - 1836*v + 1890
     1166        sage: HID['alpha']
     1167        u^11 - 55*u^10 + 1188*u^9 - 12716*u^8 + 69630*u^7 - 177408*u^6 + 133056*u^5 + 132066*u^4 - 187407*u^3 + 40095*u^2 + 24300*u - 6750
     1168        sage: HID['beta']
     1169        u^9 - 47*u^8 + 843*u^7 - 7187*u^6 + 29313*u^5 - 48573*u^4 + 10665*u^3 + 27135*u^2 - 12150*u
     1170        sage: HID['hyper_poly']
     1171        u^4 - 16*u^3 + 2*u^2 + 12*u - 7
     1172
     1173        sage: hyperelliptic_isogeny_data(37)
     1174        Traceback (most recent call last):
     1175        ...
     1176        ValueError: 37 must be one of [11, 17, 19, 23, 29, 31, 41, 47, 59, 71].
     1177
     1178    """
     1179    if not l in hyperelliptic_primes:
     1180        raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
    11491181    data = {}
    11501182    Zu = PolynomialRing(ZZ,'u')
    11511183    Zuv = PolynomialRing(ZZ,['u','v'])
     
    12551287@cached_function
    12561288def Psi2(l):
    12571289    """
     1290    Returns the generic kernel polynomial for hyperelliptic `l`-isogenies.
    12581291
    12591292    INPUT:
    12601293
    1261     - ``l`` -- either 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71. 
     1294    - ``l`` -- either 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
    12621295
    12631296    OUTPUT:
    12641297
    1265     The generic l-kernel polynomial.
     1298    The generic `l`-kernel polynomial.
     1299
     1300    TESTS::
     1301
     1302        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import Psi2
     1303        sage: Psi2(11)
     1304        x^5 - 55*x^4*u + 994*x^3*u^2 - 8774*x^2*u^3 + 41453*x*u^4 - 928945/11*u^5 + 33*x^4 + 276*x^3*u - 7794*x^2*u^2 + 4452*x*u^3 + 1319331/11*u^4 + 216*x^3*v - 4536*x^2*u*v + 31752*x*u^2*v - 842616/11*u^3*v + 162*x^3 + 38718*x^2*u - 610578*x*u^2 + 33434694/11*u^3 - 4536*x^2*v + 73872*x*u*v - 2745576/11*u^2*v - 16470*x^2 + 580068*x*u - 67821354/11*u^2 - 185976*x*v + 14143896/11*u*v + 7533*x - 20437029/11*u - 12389112/11*v + 19964151/11
    12661305
    12671306    """
    1268     if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]:
    1269         raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1307    if not l in hyperelliptic_primes:
     1308        raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
    12701309
    12711310    data = hyperelliptic_isogeny_data(l)
    12721311    R = PolynomialRing(QQ,['x','u'])
     
    13011340    return R(psi)
    13021341
    13031342
    1304 def isogenies_prime_degree_genus_plus_0(E, l):
     1343def isogenies_prime_degree_genus_plus_0(E, l=None):
    13051344    """
    13061345    Returns list of ``l`` -isogenies with domain ``E``.
    13071346
     
    13621401        sage: K = QuadraticField(5,'a')
    13631402        sage: a = K.gen()
    13641403        sage: E = EllipticCurve_from_j(184068066743177379840*a - 411588709724712960000)
    1365         sage: isogenies_prime_degree_genus_plus_0(E, 47)
     1404        sage: isogenies_prime_degree_genus_plus_0(E, 47) # long time (4.3s)
    13661405        [Isogeny of degree 47 from Elliptic Curve defined by y^2 = x^3 + (454562028554080355857852049849975895490560*a-1016431595837124114668689286176511361024000)*x + (-249456798429896080881440540950393713303830363999480904280965120*a+557802358738710443451273320227578156598454035482869042774016000) over Number Field in a with defining polynomial x^2 - 5 to Elliptic Curve defined by y^2 = x^3 + (39533118442361013730577638493616965245992960*a-88398740199669828340617478832005245173760000)*x + (214030321479466610282320528611562368963830105830555363061803253760*a-478586348074220699687616322532666163722004497458452316582576128000) over Number Field in a with defining polynomial x^2 - 5]
    13671406
    13681407        sage: K = QuadraticField(-66827,'a')
    13691408        sage: a = K.gen()
    13701409        sage: E = EllipticCurve_from_j(-98669236224000*a + 4401720074240000)
    13711410        sage: isogenies_prime_degree_genus_plus_0(E, 59)   # long time (25s, 2012)
    1372         [Isogeny of degree 59 from Elliptic Curve defined by y^2 = x^3 + (2605886146782144762297974784000*a+1893681048912773634944634716160000)*x + (-116918454256410782232296183198067568744071168000*a+17012043538294664027185882358514011304812871680000) over Number Field in a with defining polynomial x^2 + 66827 to Elliptic Curve defined by y^2 = x^3 + (-25125660899199083720535404527484928000*a-6327148599909127875668412155100659712000)*x + (-1197186521943291638242049193401511283464564457793912832000*a-121120755853676988879960565040225568460861222428113633280000) over Number Field in a with defining polynomial x^2 + 66827]
     1411        [Isogeny of degree 59 from Elliptic Curve defined by y^2 = x^3 + (2605886146782144762297974784000*a+1893681048912773634944634716160000)*x + (-116918454256410782232296183198067568744071168000*a+17012043538294664027185882358514011304812871680000) over Number Field in a with defining polynomial x^2 + 66827 to Elliptic Curve defined by y^2 = x^3 + (-19387084027159786821400775098368000*a-4882059104868154225052787156713472000)*x + (-25659862010101415428713331477227179429538847260672000*a-2596038148441293485938798119003462972840818381946880000) over Number Field in a with defining polynomial x^2 + 66827]
    13731412
    13741413        sage: E = EllipticCurve_from_j(GF(13)(5))
    1375         sage: isogenies_prime_degree_genus_plus_0(E, 71)
     1414        sage: isogenies_prime_degree_genus_plus_0(E, 71) # long time
    13761415        [Isogeny of degree 71 from Elliptic Curve defined by y^2 = x^3 + x + 4 over Finite Field of size 13 to Elliptic Curve defined by y^2 = x^3 + 10*x + 7 over Finite Field of size 13, Isogeny of degree 71 from Elliptic Curve defined by y^2 = x^3 + x + 4 over Finite Field of size 13 to Elliptic Curve defined by y^2 = x^3 + 10*x + 7 over Finite Field of size 13]
    13771416
     1417        sage: E = EllipticCurve(GF(13),[0,1,1,1,0])
     1418        sage: isogenies_prime_degree_genus_plus_0(E)
     1419        [Isogeny of degree 17 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 10*x + 1 over Finite Field of size 13,
     1420        Isogeny of degree 17 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 4 over Finite Field of size 13,
     1421        Isogeny of degree 29 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 6 over Finite Field of size 13,
     1422        Isogeny of degree 29 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 5*x + 6 over Finite Field of size 13,
     1423        Isogeny of degree 41 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 4 over Finite Field of size 13,
     1424        Isogeny of degree 41 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 5*x + 6 over Finite Field of size 13]
     1425
    13781426    """
    1379     if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
    1380         raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1427    if l is None:
     1428        return sum([isogenies_prime_degree_genus_plus_0(E, l) for l in hyperelliptic_primes],[])
     1429
     1430    if not l in hyperelliptic_primes:
     1431        raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
     1432
    13811433    F = E.base_ring()
    13821434    j = E.j_invariant()
    13831435    if F.characteristic() in [2, 3, l]:
    1384         raise NotImplementedError, "11, 17, 19, 23, 29, 31, 41, 47, 59, and 71-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny."
     1436        raise NotImplementedError("11, 17, 19, 23, 29, 31, 41, 47, 59, and 71-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny.")
     1437
    13851438    if j == F(0):
    13861439        return isogenies_prime_degree_genus_plus_0_j0(E, l)
    13871440    if j == F(1728):
    13881441        return isogenies_prime_degree_genus_plus_0_j1728(E, l)
    1389        
    1390     if l!= None:
    1391         Fu = PolynomialRing(F,'u')
    1392         u = Fu.gen()
    1393         Fuv = PolynomialRing(F,['u','v'])
    1394         Fxuv = PolynomialRing(F,['x','u','v'])
    1395         X = u
    1396         data = hyperelliptic_isogeny_data(l)
    1397         a = Fu(data['alpha'])
    1398         b = Fu(data['beta'])
    1399         f = Fu(data['hyper_poly'])
    1400         P = a
    1401         Q = Fu((a**2 - f*b**2)/Fu(4))
    1402         u_list = (j**2-P*j+Q).roots(multiplicities=False)
    14031442
    1404         S = []
    1405         for u0 in u_list:
    1406             if b(u0) == 0:
    1407                 S += [[u0,v0] for v0 in (X**2-f(u0)).roots(multiplicities=False)]
    1408             else:
    1409                 S += [[u0,(2*j-a(u0))/b(u0)]]
    1410         if len(S) == 0:
    1411             return []
    1412         S.sort()
     1443    Fu = PolynomialRing(F,'u')
     1444    u = Fu.gen()
     1445    Fuv = PolynomialRing(F,['u','v'])
     1446    Fxuv = PolynomialRing(F,['x','u','v'])
     1447    X = u
     1448    data = hyperelliptic_isogeny_data(l)
     1449    a = Fu(data['alpha'])
     1450    b = Fu(data['beta'])
     1451    f = Fu(data['hyper_poly'])
     1452    P = a
     1453    Q = Fu((a**2 - f*b**2)/Fu(4))
     1454    u_list = (j**2-P*j+Q).roots(multiplicities=False)
    14131455
    1414         c4, c6 = E.c_invariants()
    1415         b2 = E.b2()
    1416         kernels = []
     1456    S = []
     1457    for u0 in u_list:
     1458        if b(u0) == 0:
     1459            S += [[u0,v0] for v0 in (X**2-f(u0)).roots(multiplicities=False)]
     1460        else:
     1461            S += [[u0,(2*j-a(u0))/b(u0)]]
     1462    if len(S) == 0:
     1463        return []
     1464    S.sort()
    14171465
    1418         psi = Fxuv(Psi2(l))
    1419         for u0, v0 in S:
    1420             A4 = Fuv(data['A4'])(u0,v0) #non-zero since j!=0
    1421             A6 = Fuv(data['A6'])(u0,v0) #non-zero since j!=1728
    1422             T = (c4*A6)/(2*c6*A4)
    1423             kernels += [psi((36*X+3*b2)*T,u0,v0).monic()]
    1424         isogs = [E.isogeny(ker) for ker in kernels]
    1425         return isogs
     1466    c4, c6 = E.c_invariants()
     1467    b2 = E.b2()
     1468    kernels = []
    14261469
    1427     if l == None:
    1428         return sum([isogenies_prime_degree_genus_plus_0(E, l) for l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]],[])
     1470    psi = Fxuv(Psi2(l))
     1471    for u0, v0 in S:
     1472        A4 = Fuv(data['A4'])(u0,v0) #non-zero since j!=0
     1473        A6 = Fuv(data['A6'])(u0,v0) #non-zero since j!=1728
     1474        T = (c4*A6)/(2*c6*A4)
     1475        kernels += [psi((36*X+3*b2)*T,u0,v0).monic()]
     1476    return [E.isogeny(ker) for ker in kernels]
     1477
    14291478
    14301479
    14311480def isogenies_prime_degree_genus_plus_0_j0(E, l):
    14321481    """
    1433     Returns a list of ``l`` -isogenies  with domain ``E`` when the
    1434     j-invariant is 0.
     1482    Returns a list of hyperelliptic ``l`` -isogenies  with domain ``E`` when `j(E)=0`.
    14351483
    14361484    INPUT:
    14371485
    14381486    - ``E`` -- an elliptic curve with j-invariant 0.
    14391487
    1440     - ``l`` -- 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71. 
     1488    - ``l`` -- 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
    14411489
    14421490    OUTPUT:
    14431491
     
    14651513        sage: isogenies_prime_degree_genus_plus_0_j0(E,17)
    14661514        [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6]
    14671515    """
    1468     if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
    1469         raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1516    if not l in hyperelliptic_primes:
     1517        raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
    14701518    F = E.base_field()
    14711519    if E.j_invariant() != 0:
    1472         raise ValueError, "j-invariant must be 0."
     1520        raise ValueError,("j-invariant must be 0.")
    14731521    if F.characteristic() in [2,3,l]:
    1474         raise NotImplementedError, "Not implemented in characteristic 2, 3 or l."
     1522        raise NotImplementedError("Not implemented in characteristic 2, 3 or l.")
    14751523
    14761524    Fu = PolynomialRing(F,'u')
    14771525    u = Fu.gen()
     
    15081556    for u0,v0 in S:
    15091557        A6 = Fuv(data['A6'])(u0,v0) # non-zero since j!=1728
    15101558        kernels += [psi((36*X+3*b2)*T,u0,v0).monic() for T in (X**3-A6/(-54*c6)).roots(multiplicities=False)]
    1511     isogs = [E.isogeny(ker) for ker in kernels]
    1512     return isogs
    1513 
     1559    return [E.isogeny(ker) for ker in kernels]
    15141560
    15151561def isogenies_prime_degree_genus_plus_0_j1728(E, l):
    15161562    """
    1517     Returns a list of ``l`` -isogenies  with domain ``E`` when the
    1518     j-invariant is 1728.
     1563    Returns a list of ``l`` -isogenies  with domain ``E`` when `j(E)=1728`.
    15191564
    15201565    INPUT:
    15211566
    1522     - ``E`` -- an elliptic curve with j-invariant 0.
     1567    - ``E`` -- an elliptic curve with j-invariant 1728.
    15231568
    15241569    - ``l`` -- 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71. 
    15251570
     
    15451590        sage: isogenies_prime_degree_genus_plus_0_j1728(E,11)
    15461591        [Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-75295/1335852*a^5+13066735/445284*a^4+44903485/74214*a^3+17086861/24738*a^2+11373021/16492*a-1246245/2356)*x over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103 to Elliptic Curve defined by y^2 = x^3 + (9110695/1335852*a^5-1581074935/445284*a^4-5433321685/74214*a^3-3163057249/24738*a^2+1569269691/16492*a+73825125/2356)*x + (-3540460*a^3+30522492*a^2-7043652*a-5031180) over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103, Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-75295/1335852*a^5+13066735/445284*a^4+44903485/74214*a^3+17086861/24738*a^2+11373021/16492*a-1246245/2356)*x over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103 to Elliptic Curve defined by y^2 = x^3 + (9110695/1335852*a^5-1581074935/445284*a^4-5433321685/74214*a^3-3163057249/24738*a^2+1569269691/16492*a+73825125/2356)*x + (3540460*a^3-30522492*a^2+7043652*a+5031180) over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103]
    15471592    """
    1548     if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
    1549         raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1593    if not l in  hyperelliptic_primes:
     1594        raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes))
    15501595    F = E.base_ring()
    15511596    if E.j_invariant() != 1728:
    1552         raise ValueError, "j-invariant must be 1728."
     1597        raise ValueError("j-invariant must be 1728.")
    15531598    if F.characteristic() in [2,3,l]:
    1554         raise NotImplementedError, "Not implemented in characteristic 2, 3 or l."
     1599        raise NotImplementedError("Not implemented in characteristic 2, 3 or l.")
    15551600
    15561601    Fu = PolynomialRing(F,'u')
    15571602    u = Fu.gen()
     
    15891634    for u0,v0 in S:
    15901635        A4 = Fuv(data['A4'])(u0,v0) # non-zero since j!=0
    15911636        kernels += [psi((36*X+3*b2)*T,u0,v0).monic() for T in (X**2-A4/(-27*c4)).roots(multiplicities=False)]
    1592     isogs = [E.isogeny(ker) for ker in kernels]
    1593     return isogs
     1637    return [E.isogeny(ker) for ker in kernels]
    15941638
     1639@cached_function
    15951640def least_semi_primitive(p):
    15961641    """
    1597     Returns the smallest semi-primitive root modulo p, i.e., the smallest multiplicative generator of the group (ZZ/pZZ)/{1,-1}.
     1642    Returns the smallest semi-primitive root modulo `p`, i.e., generator of the group `(\ZZ/p\ZZ)^*/{1,-1}`.
    15981643
    15991644    INPUT:
    16001645
    1601     - ``p`` -- a prime. 
     1646    - ``p`` -- an odd prime.
    16021647
    16031648    OUTPUT:
    16041649
    1605     the smallest semi-primitive root modulo p, i.e., the smallest multiplicative generator of the group (ZZ/pZZ)/{1,-1}.
     1650    the smallest semi-primitive root modulo `p`.
    16061651
    16071652    .. note::
    16081653
     
    16221667        sage: least_semi_primitive(997)
    16231668        7
    16241669    """
    1625     if not p.is_prime():
    1626         raise ValueError, "p is not prime"
     1670    if not p.is_prime() or p<3:
     1671        raise ValueError("%s is not an odd prime"%p)
    16271672
    16281673    def is_semi_primitive(a,p):
    16291674        from sage.rings.finite_rings.integer_mod_ring import Integers
     
    16321677            return (d==p-1)
    16331678        else:
    16341679            return d >= (p-1)/2
    1635    
     1680
    16361681    a = 2
    16371682    while not is_semi_primitive(a,p):
    16381683        a += 1
     
    16531698
    16541699    (list) a list of all isogenies of degree l.
    16551700
     1701    .. note::
     1702
     1703       This function works for any prime `l`.  Normally one should use
     1704       the function :meth:`isogenies_prime_degree` which uses special
     1705       functions for certain small primes.
     1706
    16561707    EXAMPLES::
    16571708
    16581709        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_general
     
    16731724        sage: E = EllipticCurve([0, -1, 0, -6288, 211072])
    16741725        sage: isogenies_prime_degree_general(E, 37)  # long time (10s)
    16751726        [Isogeny of degree 37 from Elliptic Curve defined by y^2 = x^3 - x^2 - 6288*x + 211072 over Rational Field to Elliptic Curve defined by y^2 = x^3 - x^2 - 163137088*x - 801950801728 over Rational Field]
     1727
    16761728        sage: E = EllipticCurve([-3440, 77658])
    16771729        sage: isogenies_prime_degree_general(E, 43)  # long time (16s)
    16781730        [Isogeny of degree 43 from Elliptic Curve defined by y^2 = x^3 - 3440*x + 77658 over Rational Field to Elliptic Curve defined by y^2 = x^3 - 6360560*x - 6174354606 over Rational Field]
     1731
     1732    Isogenies of degree equal to the characteristic are computed (but
     1733    only the separable isogeny).  In the following example we consider
     1734    an elliptic curve which is supersingular in characteristic 2
     1735    only::
     1736
     1737        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_general
     1738        sage: ainvs = (0,1,1,-1,-1)
     1739        sage: for l in prime_range(50):
     1740        ....:     E = EllipticCurve(GF(l),ainvs)
     1741        ....:     isogenies_prime_degree_general(E,l)
     1742        []
     1743        [Isogeny of degree 3 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 2*x + 2 over Finite Field of size 3 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 3]
     1744        [Isogeny of degree 5 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4*x + 4 over Finite Field of size 5 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4*x + 4 over Finite Field of size 5]
     1745        [Isogeny of degree 7 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 6*x + 6 over Finite Field of size 7 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4 over Finite Field of size 7]
     1746        [Isogeny of degree 11 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 10*x + 10 over Finite Field of size 11 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + x + 1 over Finite Field of size 11]
     1747        [Isogeny of degree 13 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 12 over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 12 over Finite Field of size 13]
     1748        [Isogeny of degree 17 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 16*x + 16 over Finite Field of size 17 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 15 over Finite Field of size 17]
     1749        [Isogeny of degree 19 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 18*x + 18 over Finite Field of size 19 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 3*x + 12 over Finite Field of size 19]
     1750        [Isogeny of degree 23 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 22*x + 22 over Finite Field of size 23 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 22*x + 22 over Finite Field of size 23]
     1751        [Isogeny of degree 29 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 28*x + 28 over Finite Field of size 29 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 7*x + 27 over Finite Field of size 29]
     1752        [Isogeny of degree 31 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 30*x + 30 over Finite Field of size 31 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 15*x + 16 over Finite Field of size 31]
     1753        [Isogeny of degree 37 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 36*x + 36 over Finite Field of size 37 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 16*x + 17 over Finite Field of size 37]
     1754        [Isogeny of degree 41 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 40*x + 40 over Finite Field of size 41 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 33*x + 16 over Finite Field of size 41]
     1755        [Isogeny of degree 43 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 42*x + 42 over Finite Field of size 43 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 36 over Finite Field of size 43]
     1756        [Isogeny of degree 47 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 46*x + 46 over Finite Field of size 47 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 42*x + 34 over Finite Field of size 47]
     1757
    16791758    """
    16801759    if not l.is_prime():
    1681         raise ValueError, "l is not prime"
     1760        raise ValueError("%s is not prime."%l)
     1761    if l==2:
     1762        return isogenies_2(E)
     1763    if l==3:
     1764        return isogenies_3(E)
     1765
    16821766    psi_l = E.division_polynomial(l)
    16831767    factors = [h for h,e in psi_l.factor() if (l-1)/2 % h.degree() == 0]
    16841768    a = least_semi_primitive(l)
     
    17021786                factors.remove(g)
    17031787        if mult(S[-1]) == f:
    17041788            ker.append(prod(S))
    1705     isogs = [E.isogeny(k) for k in ker]
    1706     return isogs
     1789    return [E.isogeny(k) for k in ker]
     1790
     1791def isogenies_prime_degree(E, l):
     1792    """
     1793    Returns a list of ``l`` -isogenies  with domain ``E``.
     1794
     1795    INPUT:
     1796
     1797    - ``E`` -- an elliptic curve.
     1798
     1799    - ``l`` -- a prime. 
     1800
     1801    OUTPUT:
     1802
     1803    (list) a list of all isogenies of degree `l`.  If the
     1804    characteristic is `l` then only separable isogenies are
     1805    constructed.
     1806
     1807    EXAMPLES::
     1808
     1809        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree
     1810        sage: E = EllipticCurve_from_j(GF(2^6,'a')(1))
     1811        sage: isogenies_prime_degree(E, 7)
     1812        [Isogeny of degree 7 from Elliptic Curve defined by y^2 + x*y = x^3 + 1 over Finite Field in a of size 2^6 to Elliptic Curve defined by y^2 + x*y = x^3 + x over Finite Field in a of size 2^6]
     1813        sage: E = EllipticCurve_from_j(GF(3^12,'a')(2))
     1814        sage: isogenies_prime_degree(E, 17)
     1815        [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2 over Finite Field in a of size 3^12 to Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2*x over Finite Field in a of size 3^12, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2 over Finite Field in a of size 3^12 to Elliptic Curve defined by y^2 = x^3 + 2*x^2 + x + 2 over Finite Field in a of size 3^12]
     1816        sage: E = EllipticCurve('50a1')
     1817        sage: isogenies_prime_degree(E, 3)
     1818        [Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 126*x - 552 over Rational Field]
     1819        sage: isogenies_prime_degree(E, 5)
     1820        [Isogeny of degree 5 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field]
     1821        sage: E = EllipticCurve([0, 0, 1, -1862, -30956])
     1822        sage: isogenies_prime_degree(E, 19)
     1823        [Isogeny of degree 19 from Elliptic Curve defined by y^2 + y = x^3 - 1862*x - 30956 over Rational Field to Elliptic Curve defined by y^2 + y = x^3 - 672182*x + 212325489 over Rational Field]
     1824        sage: E = EllipticCurve([0, -1, 0, -6288, 211072])
     1825        sage: isogenies_prime_degree(E, 37)
     1826        [Isogeny of degree 37 from Elliptic Curve defined by y^2 = x^3 - x^2 - 6288*x + 211072 over Rational Field to Elliptic Curve defined by y^2 = x^3 - x^2 - 163137088*x - 801950801728 over Rational Field]
     1827
     1828
     1829    Isogenies of degree equal to the characteristic are computed (but
     1830    only the separable isogeny).  In the following example we consider
     1831    an elliptic curve which is supersingular in characteristic 2
     1832    only::
     1833
     1834        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree
     1835        sage: ainvs = (0,1,1,-1,-1)
     1836        sage: for l in prime_range(50):
     1837        ....:     E = EllipticCurve(GF(l),ainvs)
     1838        ....:     isogenies_prime_degree(E,l)
     1839        []
     1840        [Isogeny of degree 3 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 2*x + 2 over Finite Field of size 3 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + x over Finite Field of size 3]
     1841        [Isogeny of degree 5 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4*x + 4 over Finite Field of size 5 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4*x + 4 over Finite Field of size 5]
     1842        [Isogeny of degree 7 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 6*x + 6 over Finite Field of size 7 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 4 over Finite Field of size 7]
     1843        [Isogeny of degree 11 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 10*x + 10 over Finite Field of size 11 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + x + 1 over Finite Field of size 11]
     1844        [Isogeny of degree 13 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 12 over Finite Field of size 13 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 12*x + 12 over Finite Field of size 13]
     1845        [Isogeny of degree 17 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 16*x + 16 over Finite Field of size 17 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 15 over Finite Field of size 17]
     1846        [Isogeny of degree 19 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 18*x + 18 over Finite Field of size 19 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 3*x + 12 over Finite Field of size 19]
     1847        [Isogeny of degree 23 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 22*x + 22 over Finite Field of size 23 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 22*x + 22 over Finite Field of size 23]
     1848        [Isogeny of degree 29 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 28*x + 28 over Finite Field of size 29 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 7*x + 27 over Finite Field of size 29]
     1849        [Isogeny of degree 31 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 30*x + 30 over Finite Field of size 31 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 15*x + 16 over Finite Field of size 31]
     1850        [Isogeny of degree 37 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 36*x + 36 over Finite Field of size 37 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 16*x + 17 over Finite Field of size 37]
     1851        [Isogeny of degree 41 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 40*x + 40 over Finite Field of size 41 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 33*x + 16 over Finite Field of size 41]
     1852        [Isogeny of degree 43 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 42*x + 42 over Finite Field of size 43 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 36 over Finite Field of size 43]
     1853        [Isogeny of degree 47 from Elliptic Curve defined by y^2 + y = x^3 + x^2 + 46*x + 46 over Finite Field of size 47 to Elliptic Curve defined by y^2 + y = x^3 + x^2 + 42*x + 34 over Finite Field of size 47]
     1854
     1855    Note that the computation is faster for degrees equal to one of
     1856    the genus 0 primes (2, 3, 5, 7, 13) or one of the hyperelliptic
     1857    primes (11, 17, 19, 23, 29, 31, 41, 47, 59, 71) than when the
     1858    generic code must be used::
     1859
     1860        sage: E = EllipticCurve(GF(101), [-3440, 77658])
     1861        sage: E.isogenies_prime_degree(71) # fast
     1862        []
     1863        sage: E.isogenies_prime_degree(73) # not tested (very long time: 32s)
     1864        []
     1865
     1866
     1867    """
     1868    if not l.is_prime():
     1869        raise ValueError("%s is not prime."%l)
     1870    if l==2:
     1871        return isogenies_2(E)
     1872    if l==3:
     1873        return isogenies_3(E)
     1874
     1875    p = E.base_ring().characteristic()
     1876    if l==p:
     1877        return isogenies_prime_degree_general(E,l)
     1878
     1879    if l in [5,7,13] and not p in [2,3]:
     1880        return isogenies_prime_degree_genus_0(E,l)
     1881
     1882    if l in hyperelliptic_primes and not p in [2,3]:
     1883        return isogenies_prime_degree_genus_plus_0(E,l)
     1884
     1885    return isogenies_prime_degree_general(E,l)