Esempio n. 1
0
    def rank(self,curves,output_filename="rank_output.txt",\
             problems_filename="rank_problems.txt",\
             return_data=True,use_database=True,use_only_mwrank=False,\
             print_timing=True):
        r"""
        Compute the algebraic rank 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

            - ``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.

            - ``use_database``      -- (Default True): If set to False, the 
              Cremona database is not used to look up curve ranks.

            - ``use_only_mwrank``   -- (Default False): If set to True, will not
              try to use analytic methods to compute rank before consulting the
              Cremona database

            - ``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.rank(L,return_data=True,print_timing=False)
            sage: R[1]
            []
            sage: for r in R[0]: print(r)
            ....: 
            (1, [0, 0, 0, -1, 0], 0)
            (1, [0, 0, 0, 1, 0], 0)
            (1, [0, 0, 0, 0, -1], 0)
            (1, [0, 0, 0, 0, 1], 0)
            (1, [0, 0, 0, -1, -1], 0)
            (1, [0, 0, 0, -1, 1], 1)
            (1, [0, 0, 0, 1, -1], 1)
            (1, [0, 0, 0, 1, 1], 1)
            (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)
        """
        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 rank and write curve+rank to file
            try:
                E = EllipticCurve(C[1])
                d = E.rank(use_database=use_database,
                           only_use_mwrank=use_only_mwrank)
                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 rank(self,curves,output_filename="rank_output.txt",\
             problems_filename="rank_problems.txt",\
             return_data=True,use_database=True,use_only_mwrank=False,\
             print_timing=True):
        r"""
        Compute the algebraic rank 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

            - ``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.

            - ``use_database``      -- (Default True): If set to False, the 
              Cremona database is not used to look up curve ranks.

            - ``use_only_mwrank``   -- (Default False): If set to True, will not
              try to use analytic methods to compute rank before consulting the
              Cremona database

            - ``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.rank(L,return_data=True,print_timing=False)
            sage: R[1]
            []
            sage: for r in R[0]: print(r)
            ....: 
            (1, [0, 0, 0, -1, 0], 0)
            (1, [0, 0, 0, 1, 0], 0)
            (1, [0, 0, 0, 0, -1], 0)
            (1, [0, 0, 0, 0, 1], 0)
            (1, [0, 0, 0, -1, -1], 0)
            (1, [0, 0, 0, -1, 1], 1)
            (1, [0, 0, 0, 1, -1], 1)
            (1, [0, 0, 0, 1, 1], 1)
            (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)
        """
        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 rank and write curve+rank to file
            try:
                E = EllipticCurve(C[1])
                d = E.rank(use_database=use_database,only_use_mwrank=use_only_mwrank)
                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