Esempio n. 1
0
    def two_selmer(self,curves,rank=True,reduced=False,
                   output_filename="rank_output.txt",problems_filename="rank_problems.txt",\
                   return_data=True,print_timing=True):
        r"""
        Compute rank or size of two-Selmer for a list of curves ordered by height.

        INPUT:
 
            - ``curves``            -- A list of height/a-invariant tuples of
              curves, as returned by the coefficients_over_height_range() method.
              Each tuple is of the form
              (H, [a1,a2,a3,a4,a6]) where
              H is the height of the curve, and
              [a1,...,a6] the curve's a-invariants

            - ``rank``              -- (Default True) Compute the rank versus size
              of the curve's 2-Selmer group. If True, rank is computed; if set to
              False size (i.e. 2^rank) is computed instead.

            - ``reduced``           -- (Default False) Compute full 2-Selmer or
              reduced 2-Selmer. If True, full 2-Selmer is computed; if False, the
              reduced group rank/size (i.e. 2-Selmer rank - 2-torsion rank or
              2^(2-Selmer rank - 2-torsion rank) as per whether 'rank' is set to
              True or False) is computed.

            - ``output_filename``   -- String, the name of the file to which the
              output will be saved. Each line of the save file describes a
              single curve, and consists of seven tab-separated integers:
              the first is the height of the curve; the following five are
              the curve's a-invariants, and the final integer is the curve's rank.
            - ``problems_filename`` -- String: the file name to which problem
              curves will be written. These are curves for which rank could not
              be computed. Write format is the same as above, except rank is
              omitted at the end.

            - ``return_data``       -- (Default True): If set to False, the data
              is not returned at the end of computation; only written to file.

            - ``print_timing``      -- (Default True): If set to False, wall time
              of total computation will not be printed.

        OUTPUT:

            - Writes data to file. Each line of the written file consists of seven
              tab separated entries of the form
              H, a1, a2, a3, a4, a6, d
              H: The curve's height
              a1,...,a6: The curve's a-invariants
              d: The computed datum for that curve

            - (only if return_data==True) A list consisting of two lists:
              The first is a list of triples of the form
              (H, (a1,a2,a3,a4,a6), d)
              where the entries are as above.
              The second is a list of curve for which the datum could not be provably
              computed; each entry of this list is just a pair consisting of height
              and a-invariants.

        EXAMPLES::

            sage: from sage.schemes.elliptic_curves.curve_enumerator import *
            sage: C = CurveEnumerator(family="short_weierstrass")
            sage: L = C.coefficients_over_height_range(0,4)
            sage: R = C.two_selmer(L,rank=True,return_data=True,print_timing=False)
            sage: R[1]
            []
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 1)
            (4, [0, 0, 0, -1, 2], 0)
            (4, [0, 0, 0, 0, -2], 1)
            (4, [0, 0, 0, 0, 2], 1)
            (4, [0, 0, 0, 1, -2], 1)
            (4, [0, 0, 0, 1, 2], 1)
            sage: R = C.two_selmer(L,rank=False,return_data=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 2)
            (4, [0, 0, 0, -1, 2], 1)
            (4, [0, 0, 0, 0, -2], 2)
            (4, [0, 0, 0, 0, 2], 2)
            (4, [0, 0, 0, 1, -2], 2)
            (4, [0, 0, 0, 1, 2], 2)
            sage: R = C.two_selmer(L,reduced=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 1)
            (4, [0, 0, 0, -1, 2], 0)
            (4, [0, 0, 0, 0, -2], 1)
            (4, [0, 0, 0, 0, 2], 1)
            (4, [0, 0, 0, 1, -2], 0)
            (4, [0, 0, 0, 1, 2], 0)
            sage: R = C.two_selmer(L,rank=False,reduced=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 2)
            (4, [0, 0, 0, -1, 2], 1)
            (4, [0, 0, 0, 0, -2], 2)
            (4, [0, 0, 0, 0, 2], 2)
            (4, [0, 0, 0, 1, -2], 1)
            (4, [0, 0, 0, 1, 2], 1)
        """
        if print_timing:
            t = time.time()

        out_file = open(output_filename, "w")
        prob_file = open(problems_filename, "w")
        if return_data:
            output = []
            problems = []
        for C in curves:
            # Attempt to compute datum and write curve+datum to file
            try:
                E = EllipticCurve(C[1])

                d = E.selmer_rank()
                if reduced:
                    d -= E.two_torsion_rank()
                if not rank:
                    d = 2**d

                out_file.write(str(C[0]) + "\t")
                for a in C[1]:
                    out_file.write(str(a) + "\t")
                out_file.write(str(d) + "\n")
                out_file.flush()

                if return_data:
                    output.append((C[0], C[1], d))
            # Write to problem file if fail
            except:
                prob_file.write(str(C[0]) + "\t")
                for a in C[1]:
                    prob_file.write(str(a) + "\t")
                prob_file.write("\n")
                prob_file.flush()

                if return_data:
                    problems.append(C)
        out_file.close()
        prob_file.close()

        if print_timing:
            print(time.time() - t)
        if return_data:
            return output, problems
Esempio n. 2
0
    def two_selmer(self,curves,rank=True,reduced=False,
                   output_filename="rank_output.txt",problems_filename="rank_problems.txt",\
                   return_data=True,print_timing=True):
        r"""
        Compute rank or size of two-Selmer for a list of curves ordered by height.

        INPUT:
 
            - ``curves``            -- A list of height/a-invariant tuples of
              curves, as returned by the coefficients_over_height_range() method.
              Each tuple is of the form
              (H, [a1,a2,a3,a4,a6]) where
              H is the height of the curve, and
              [a1,...,a6] the curve's a-invariants

            - ``rank``              -- (Default True) Compute the rank versus size
              of the curve's 2-Selmer group. If True, rank is computed; if set to
              False size (i.e. 2^rank) is computed instead.

            - ``reduced``           -- (Default False) Compute full 2-Selmer or
              reduced 2-Selmer. If True, full 2-Selmer is computed; if False, the
              reduced group rank/size (i.e. 2-Selmer rank - 2-torsion rank or
              2^(2-Selmer rank - 2-torsion rank) as per whether 'rank' is set to
              True or False) is computed.

            - ``output_filename``   -- String, the name of the file to which the
              output will be saved. Each line of the save file describes a
              single curve, and consists of seven tab-separated integers:
              the first is the height of the curve; the following five are
              the curve's a-invariants, and the final integer is the curve's rank.
            - ``problems_filename`` -- String: the file name to which problem
              curves will be written. These are curves for which rank could not
              be computed. Write format is the same as above, except rank is
              omitted at the end.

            - ``return_data``       -- (Default True): If set to False, the data
              is not returned at the end of computation; only written to file.

            - ``print_timing``      -- (Default True): If set to False, wall time
              of total computation will not be printed.

        OUTPUT:

            - Writes data to file. Each line of the written file consists of seven
              tab separated entries of the form
              H, a1, a2, a3, a4, a6, d
              H: The curve's height
              a1,...,a6: The curve's a-invariants
              d: The computed datum for that curve

            - (only if return_data==True) A list consisting of two lists:
              The first is a list of triples of the form
              (H, (a1,a2,a3,a4,a6), d)
              where the entries are as above.
              The second is a list of curve for which the datum could not be provably
              computed; each entry of this list is just a pair consisting of height
              and a-invariants.

        EXAMPLES::

            sage: from sage.schemes.elliptic_curves.curve_enumerator import *
            sage: C = CurveEnumerator(family="short_weierstrass")
            sage: L = C.coefficients_over_height_range(0,4)
            sage: R = C.two_selmer(L,rank=True,return_data=True,print_timing=False)
            sage: R[1]
            []
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 1)
            (4, [0, 0, 0, -1, 2], 0)
            (4, [0, 0, 0, 0, -2], 1)
            (4, [0, 0, 0, 0, 2], 1)
            (4, [0, 0, 0, 1, -2], 1)
            (4, [0, 0, 0, 1, 2], 1)
            sage: R = C.two_selmer(L,rank=False,return_data=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 2)
            (4, [0, 0, 0, -1, 2], 1)
            (4, [0, 0, 0, 0, -2], 2)
            (4, [0, 0, 0, 0, 2], 2)
            (4, [0, 0, 0, 1, -2], 2)
            (4, [0, 0, 0, 1, 2], 2)
            sage: R = C.two_selmer(L,reduced=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 1)
            (4, [0, 0, 0, -1, 2], 0)
            (4, [0, 0, 0, 0, -2], 1)
            (4, [0, 0, 0, 0, 2], 1)
            (4, [0, 0, 0, 1, -2], 0)
            (4, [0, 0, 0, 1, 2], 0)
            sage: R = C.two_selmer(L,rank=False,reduced=True,print_timing=False)
            sage: for r in R[0]: print(r)
            ....: 
            (4, [0, 0, 0, -1, -2], 2)
            (4, [0, 0, 0, -1, 2], 1)
            (4, [0, 0, 0, 0, -2], 2)
            (4, [0, 0, 0, 0, 2], 2)
            (4, [0, 0, 0, 1, -2], 1)
            (4, [0, 0, 0, 1, 2], 1)
        """
        if print_timing:
            t = time.time()

        out_file  = open(output_filename,"w")
        prob_file = open(problems_filename,"w")
        if return_data:
            output = []
            problems = []
        for C in curves:
            # Attempt to compute datum and write curve+datum to file
            try:
                E = EllipticCurve(C[1])

                d = E.selmer_rank()
                if reduced:
                    d -= E.two_torsion_rank()
                if not rank:
                    d = 2**d

                out_file.write(str(C[0])+"\t")
                for a in C[1]:
                    out_file.write(str(a)+"\t")
                out_file.write(str(d)+"\n")
                out_file.flush()

                if return_data:
                    output.append((C[0],C[1],d))
            # Write to problem file if fail
            except:
                prob_file.write(str(C[0])+"\t")
                for a in C[1]:
                    prob_file.write(str(a)+"\t")
                prob_file.write("\n")
                prob_file.flush()

                if return_data:
                    problems.append(C)
        out_file.close()
        prob_file.close()

        if print_timing:
            print(time.time()-t)
        if return_data:
            return output,problems