Ejemplo n.º 1
0
def egros_from_j(j, S=[]):
    r"""
    Given a rational j and a list of primes S, returns a list of
    elliptic curves over Q with j-invariant j and good reduction
    outside S, by checking all relevant quadratic twists.

    INPUT:

        -  j - a rational number.

        -  S - list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

        A sorted list of all elliptic curves defined over `Q` with
        `j`-invariant equal to `j` and with good reduction at
        all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j
        sage: [e.label() for e in egros_from_j(0,[3])]
        ['27a1', '27a3', '243a1', '243a2', '243b1', '243b2']
        sage: [e.label() for e in egros_from_j(1728,[2])]
        ['32a1', '32a2', '64a1', '64a4', '256b1', '256b2', '256c1', '256c2']
        sage: elist=egros_from_j(-4096/11,[11])
        sage: [e.label() for e in elist]
        ['11a3', '121d1']

    """
    if j == 1728:
        return egros_from_j_1728(S)

    if j == 0:
        return egros_from_j_0(S)

    # Now j != 0, 1728

    E = EllipticCurve_from_j(j)
    Elist = []

    for ei in xmrange([2] * (1 + len(S))):
        u = prod([p**e for p, e in zip(reversed([-1] + S), ei)], QQ(1))
        Eu = E.quadratic_twist(u).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]

    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 2
0
def egros_from_j(j,S=[]):
    r"""
    Given a rational j and a list of primes S, returns a list of
    elliptic curves over `\QQ` with j-invariant j and good reduction
    outside S, by checking all relevant quadratic twists.

    INPUT:

    - j -- a rational number.

    - S -- list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

    A sorted list of all elliptic curves defined over `\QQ` with
    `j`-invariant equal to `j` and with good reduction at
    all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j
        sage: [e.label() for e in egros_from_j(0,[3])]
        ['27a1', '27a3', '243a1', '243a2', '243b1', '243b2']
        sage: [e.label() for e in egros_from_j(1728,[2])]
        ['32a1', '32a2', '64a1', '64a4', '256b1', '256b2', '256c1', '256c2']
        sage: elist=egros_from_j(-4096/11,[11])
        sage: [e.label() for e in elist]
        ['11a3', '121d1']

    """
    if j == 1728:
        return egros_from_j_1728(S)

    if j == 0:
        return egros_from_j_0(S)

    # Now j != 0, 1728

    E = EllipticCurve_from_j(j)
    Elist=[]

    for ei in xmrange([2]*(1+len(S))):
        u = prod([p**e for p,e in zip(reversed([-1]+S),ei)],QQ(1))
        Eu = E.quadratic_twist(u).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]

    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 3
0
def egros_from_j_0(S=[]):
    r"""
    Given a list of primes S, returns a list of elliptic curves over `\QQ`
    with j-invariant 0 and good reduction outside S, by checking all
    relevant sextic twists.

    INPUT:

    - S -- list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

    A sorted list of all elliptic curves defined over `\QQ` with
    `j`-invariant equal to `0` and with good reduction at
    all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j_0
        sage: egros_from_j_0([])
        []
        sage: egros_from_j_0([2])
        []
        sage: [e.label() for e in egros_from_j_0([3])]
        ['27a1', '27a3', '243a1', '243a2', '243b1', '243b2']
        sage: len(egros_from_j_0([2,3,5]))  # long time (8s on sage.math, 2013)
        432
    """
    Elist=[]
    if not 3 in S:
        return Elist
    no2 = not 2 in S
    for ei in xmrange([2] + [6]*len(S)):
        u = prod([p**e for p,e in zip([-1]+S,ei)],QQ(1))
        if no2:
            u*=16 ## make sure 12|val(D,2)
        Eu = EllipticCurve([0,0,0,0,u]).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]
    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 4
0
def egros_from_j_0(S=[]):
    r"""
    Given a list of primes S, returns a list of elliptic curves over Q
    with j-invariant 0 and good reduction outside S, by checking all
    relevant sextic twists.

    INPUT:

        -  S - list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

        A sorted list of all elliptic curves defined over `Q` with
        `j`-invariant equal to `0` and with good reduction at
        all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j_0
        sage: egros_from_j_0([])
        []
        sage: egros_from_j_0([2])
        []
        sage: [e.label() for e in egros_from_j_0([3])]
        ['27a1', '27a3', '243a1', '243a2', '243b1', '243b2']
        sage: len(egros_from_j_0([2,3,5]))
        432
    """
    Elist = []
    if not 3 in S:
        return Elist
    no2 = not 2 in S
    for ei in xmrange([2] + [6] * len(S)):
        u = prod([p**e for p, e in zip([-1] + S, ei)], QQ(1))
        if no2:
            u *= 16  ## make sure 12|val(D,2)
        Eu = EllipticCurve([0, 0, 0, 0, u]).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]
    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 5
0
def egros_from_j_1728(S=[]):
    r"""
    Given a list of primes S, returns a list of elliptic curves over `\QQ`
    with j-invariant 1728 and good reduction outside S, by checking
    all relevant quartic twists.

    INPUT:

    - S -- list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

    A sorted list of all elliptic curves defined over `\QQ` with
    `j`-invariant equal to `1728` and with good reduction at
    all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j_1728
        sage: egros_from_j_1728([])
        []
        sage: egros_from_j_1728([3])
        []
        sage: [e.cremona_label() for e in egros_from_j_1728([2])]
        ['32a1', '32a2', '64a1', '64a4', '256b1', '256b2', '256c1', '256c2']

    """
    Elist=[]
    no2 = not 2 in S
    for ei in xmrange([2] + [4]*len(S)):
        u = prod([p**e for p,e in zip([-1]+S,ei)],QQ(1))
        if no2:
            u*=4 ## make sure 12|val(D,2)
        Eu = EllipticCurve([0,0,0,u,0]).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]
    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 6
0
def egros_from_j_1728(S=[]):
    r"""
    Given a list of primes S, returns a list of elliptic curves over `\QQ`
    with j-invariant 1728 and good reduction outside S, by checking
    all relevant quartic twists.

    INPUT:

    - S -- list of primes (default: empty list).

    .. note::

        Primality of elements of S is not checked, and the output
        is undefined if S is not a list or contains non-primes.

    OUTPUT:

    A sorted list of all elliptic curves defined over `\QQ` with
    `j`-invariant equal to `1728` and with good reduction at
    all primes outside the list ``S``.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_from_j_1728
        sage: egros_from_j_1728([])
        []
        sage: egros_from_j_1728([3])
        []
        sage: [e.cremona_label() for e in egros_from_j_1728([2])]
        ['32a1', '32a2', '64a1', '64a4', '256b1', '256b2', '256c1', '256c2']

    """
    Elist = []
    no2 = not 2 in S
    for ei in xmrange([2] + [4] * len(S)):
        u = prod([p**e for p, e in zip([-1] + S, ei)], QQ(1))
        if no2:
            u *= 4  ## make sure 12|val(D,2)
        Eu = EllipticCurve([0, 0, 0, u, 0]).minimal_model()
        if Eu.has_good_reduction_outside_S(S):
            Elist += [Eu]
    Elist.sort(cmp=curve_cmp)
    return Elist
Ejemplo n.º 7
0
def egros_get_j(S=[], proof=None, verbose=False):
    r"""
    Returns a list of rational `j` such that all elliptic curves
    defined over `\QQ` with good reduction outside `S` have
    `j`-invariant in the list, sorted by height.

    INPUT:

    - ``S`` -- list of primes (default: empty list).

    - ``proof`` -- ``True``/``False`` (default ``True``): the MW basis for
      auxiliary curves will be computed with this proof flag.

    - ``verbose`` -- ``True``/``False`` (default ``False````): if ``True``, some
      details of the computation will be output.

    .. note::

        Proof flag: The algorithm used requires determining all
        S-integral points on several auxiliary curves, which in turn
        requires the computation of their generators.  This is not
        always possible (even in theory) using current knowledge.

        The value of this flag is passed to the function which
        computes generators of various auxiliary elliptic curves, in
        order to find their S-integral points.  Set to ``False`` if the
        default (``True``) causes warning messages, but note that you can
        then not rely on the set of invariants returned being
        complete.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_get_j
        sage: egros_get_j([])
        [1728]
        sage: egros_get_j([2])  # long time (3s on sage.math, 2013)
        [128, 432, -864, 1728, 3375/2, -3456, 6912, 8000, 10976, -35937/4, 287496, -784446336, -189613868625/128]
        sage: egros_get_j([3])  # long time (3s on sage.math, 2013)
        [0, -576, 1536, 1728, -5184, -13824, 21952/9, -41472, 140608/3, -12288000]
        sage: jlist=egros_get_j([2,3]); len(jlist) # long time (30s)
        83

    """
    if not all([p.is_prime() for p in S]):
        raise ValueError("Elements of S must be prime.")

        if proof is None:
            from sage.structure.proof.proof import get_flag
            proof = get_flag(proof, "elliptic_curve")
        else:
            proof = bool(proof)

    if verbose:
        import sys  # so we can flush stdout for debugging

    SS = [-1] + S

    jlist=[]
    wcount=0
    nw = 6**len(S) * 2

    if verbose:
        print "Finding possible j invariants for S = ",S
        print "Using ", nw, " twists of base curve"
        sys.stdout.flush()

    for ei in xmrange([6]*len(S) + [2]):
        w = prod([p**e for p,e in zip(reversed(SS),ei)],QQ(1))
        wcount+=1
        if verbose:
            print "Curve #",wcount, "/",nw,":";
            print "w = ",w,"=",w.factor()
            sys.stdout.flush()
        a6 = -1728*w
        d2 = 0
        d3 = 0
        u0 = (2**d2)*(3**d3)
        E = EllipticCurve([0,0,0,0,a6])
        # This curve may not be minimal at 2 or 3, but the
        # S-integral_points function requires minimality at primes in
        # S, so we find a new model which is p-minimal at both 2 and 3
        # if they are in S.  Note that the isomorphism between models
        # will preserve S-integrality of points.
        E2 = E.local_minimal_model(2) if 2 in S else E
        E23 = E2.local_minimal_model(3) if 3 in S else E2
        urst = E23.isomorphism_to(E)

        try:
            pts = E23.S_integral_points(S,proof=proof)
        except RuntimeError:
            pts=[]
            print "Failed to find S-integral points on ",E23.ainvs()
            if proof:
                if verbose:
                    print "--trying again with proof=False"
                    sys.stdout.flush()
                pts = E23.S_integral_points(S,proof=False)
                if verbose:
                    print "--done"
        if verbose:
            print len(pts), " S-integral points: ",pts
            sys.stdout.flush()
        for P in pts:
            P = urst(P)
            x = P[0]
            y = P[1]
            j = x**3 /w
            assert j-1728 == y**2 /w
            if is_possible_j(j,S):
                if not j in jlist:
                    if verbose:
                        print "Adding possible j = ",j
                        sys.stdout.flush()
                    jlist += [j]
            else:
                if True: #verbose:
                    print "Discarding illegal j = ",j
                    sys.stdout.flush()
    return sorted(jlist, key=lambda j: j.height())
Ejemplo n.º 8
0
def egros_get_j(S=[], proof=None, verbose=False):
    r"""
    Returns a list of rational `j` such that all elliptic curves
    defined over `Q` with good reduction outside `S` have
    `j`-invariant in the list, sorted by height.

    INPUT:

        -  ``S`` - list of primes (default: empty list).

        - ``proof`` - True/False (default True): the MW basis for
          auxiliary curves will be computed with this proof flag.

        - ``verbose`` - True/False (default False): if True, some
          details of the computation will be output.

    .. note::

        Proof flag: The algorithm used requires determining all
        S-integral points on several auxiliary curves, which in turn
        requires the computation of their generators.  This is not
        always possible (even in theory) using current knowledge.

        The value of this flag is passed to the function which
        computes generators of various auxiliary elliptic curves, in
        order to find their S-integral points.  Set to False if the
        default (True) causes warning messages, but note that you can
        then not rely on the set of invariants returned being
        complete.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_egros import egros_get_j
        sage: egros_get_j([])
        [1728]
        sage: egros_get_j([2])
        [128, 432, -864, 1728, 3375/2, -3456, 6912, 8000, 10976, -35937/4, 287496, -784446336, -189613868625/128]
        sage: egros_get_j([3])
        [0, -576, 1536, 1728, -5184, -13824, 21952/9, -41472, 140608/3, -12288000]
        sage: jlist=egros_get_j([2,3]); len(jlist) # long time (30s)
        83

    """
    if not all([p.is_prime() for p in S]):
        raise ValueError, "Elements of S must be prime."

        if proof is None:
            from sage.structure.proof.proof import get_flag
            proof = get_flag(proof, "elliptic_curve")
        else:
            proof = bool(proof)

    if verbose:
        import sys  # so we can flush stdout for debugging

    SS = [-1] + S

    jlist = []
    wcount = 0
    nw = 6**len(S) * 2

    if verbose:
        print "Finding possible j invariants for S = ", S
        print "Using ", nw, " twists of base curve"
        sys.stdout.flush()

    for ei in xmrange([6] * len(S) + [2]):
        w = prod([p**e for p, e in zip(reversed(SS), ei)], QQ(1))
        wcount += 1
        if verbose:
            print "Curve #", wcount, "/", nw, ":"
            print "w = ", w, "=", w.factor()
            sys.stdout.flush()
        a6 = -1728 * w
        d2 = 0
        d3 = 0
        u0 = (2**d2) * (3**d3)
        E = EllipticCurve([0, 0, 0, 0, a6])
        # This curve may not be minimal at 2 or 3, but the
        # S-integral_points function requires minimality at primes in
        # S, so we find a new model which is p-minimal at both 2 and 3
        # if they are in S.  Note that the isomorphism between models
        # will preserve S-integrality of points.
        E2 = E.local_minimal_model(2) if 2 in S else E
        E23 = E2.local_minimal_model(3) if 3 in S else E2
        urst = E23.isomorphism_to(E)

        try:
            pts = E23.S_integral_points(S, proof=proof)
        except RuntimeError:
            pts = []
            print "Failed to find S-integral points on ", E23.ainvs()
            if proof:
                if verbose:
                    print "--trying again with proof=False"
                    sys.stdout.flush()
                pts = E23.S_integral_points(S, proof=False)
                if verbose:
                    print "--done"
        if verbose:
            print len(pts), " S-integral points: ", pts
            sys.stdout.flush()
        for P in pts:
            P = urst(P)
            x = P[0]
            y = P[1]
            j = x**3 / w
            assert j - 1728 == y**2 / w
            if is_possible_j(j, S):
                if not j in jlist:
                    if verbose:
                        print "Adding possible j = ", j
                        sys.stdout.flush()
                    jlist += [j]
            else:
                if True:  #verbose:
                    print "Discarding illegal j = ", j
                    sys.stdout.flush()
    height_cmp = lambda j1, j2: cmp(j1.height(), j2.height())
    jlist.sort(cmp=height_cmp)
    return jlist