Exemplo n.º 1
0
def primes_arith_prog(bound=10**4, out='arith_prog.pdf', d=3):
    '''
    Run through all prime powers r up to `bound`, and select for each
    the smallest u such that ur+1 is prime.
    
    Then do degree `d` linear regression, and plot everything into 
    `out`.
    '''
    # Find primes
    x, y = np.array([(p, next(u for u in xrange(p) if is_prime(u * p + 1)))
                     for p in prime_powers(3, bound)]).T
    # linear regression
    lstsq = np.polyfit(np.log10(x), y, d)

    # Figure settings
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif', serif='Computer Modern')
    plt.figure(figsize=(8, 3))

    # Plot a 2D histogram of the data, with abscissa in log scale
    plt.hist2d(np.log10(x),
               y,
               bins=(1.5 * max(y), max(y) / 2),
               weights=np.log10(x) / x,
               cmap=cm.jet,
               norm=LogNorm())
    plt.colorbar()
    # Plot the linear regression
    x = np.linspace(*plt.xlim(), num=100)
    plt.plot(x,
             np.polyval(lstsq, x),
             c='black',
             label='degree %d polynomial regression' % d)
    plt.legend(loc='upper left')

    # More figure settings
    locs, _ = plt.xticks()
    plt.xticks(locs, map(lambda l: '$10^%d$' % l, locs))
    plt.tight_layout()
    # Write to file
    plt.savefig(out, bbox_inches='tight')
    plt.close()
Exemplo n.º 2
0
    def __init__(self, K, N_max=10**5):
        """
        Compute J working over the field K.
        """
        self.N_max   = N_max
        self.K = K

        from sage.all import prime_powers, factor
        PP = prime_powers(N_max+1)[1:]

        n  = len(PP)
        self.a   = [K(0)]*n
        self.s   = [K(0)]*n
        self.pv  = [0]*n
        i = 0
        for pv in PP:
            F = factor(pv)
            p, v = F[0]
            self.pv[i] = K(pv)
            logp = K(p).log()
            self.a[i] = logp/K(pv).sqrt()
            self.s[i] = v*logp
            i += 1
Exemplo n.º 3
0
    def __init__(self, K, N_max=10**5):
        """
        Compute J working over the field K.
        """
        self.N_max = N_max
        self.K = K

        from sage.all import prime_powers, factor
        PP = prime_powers(N_max + 1)[1:]

        n = len(PP)
        self.a = [K(0)] * n
        self.s = [K(0)] * n
        self.pv = [0] * n
        i = 0
        for pv in PP:
            F = factor(pv)
            p, v = F[0]
            self.pv[i] = K(pv)
            logp = K(p).log()
            self.a[i] = logp / K(pv).sqrt()
            self.s[i] = v * logp
            i += 1
Exemplo n.º 4
0
def primes_arith_prog(bound=10**4, out='arith_prog.pdf', d=3):
    '''
    Run through all prime powers r up to `bound`, and select for each
    the smallest u such that ur+1 is prime.
    
    Then do degree `d` linear regression, and plot everything into 
    `out`.
    '''
    # Find primes
    x, y = np.array([(p, next(u for u in xrange(p) if is_prime(u*p+1)))
                     for p in prime_powers(3,bound)]).T
    # linear regression
    lstsq = np.polyfit(np.log10(x), y, d)

    # Figure settings
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif', serif='Computer Modern')
    plt.figure(figsize=(8,3))

    # Plot a 2D histogram of the data, with abscissa in log scale
    plt.hist2d(np.log10(x), y, bins=(1.5*max(y),max(y)/2),
               weights=np.log10(x)/x,
               cmap=cm.jet, norm=LogNorm())
    plt.colorbar()
    # Plot the linear regression
    x = np.linspace(*plt.xlim(), num=100)
    plt.plot(x, np.polyval(lstsq, x), c='black', label='degree %d polynomial regression' % d)
    plt.legend(loc='upper left')

    # More figure settings
    locs, _ = plt.xticks()
    plt.xticks(locs, map(lambda l: '$10^%d$' % l, locs))
    plt.tight_layout()
    # Write to file
    plt.savefig(out, bbox_inches='tight')
    plt.close()
Exemplo n.º 5
0
def extend_multiplicatively(Z):
    for pp in prime_powers(len(Z)-1):
        for k in range(1, (len(Z) - 1)//pp + 1):
            if gcd(k, pp) == 1:
                Z[pp*k] = Z[pp]*Z[k]
Exemplo n.º 6
0
def do(level,
       weight,
       lfun_filename=None,
       instances_filename=None,
       hecke_filename=None,
       traces_filename=None,
       only_traces=False,
       only_orbit=None):
    print "N = %s, k = %s" % (level, weight)
    polyinfile = os.path.join(base_import,
                              'polydb/{}.{}.polydb'.format(level, weight))
    mfdbinfile = os.path.join(base_import,
                              'mfdb/{}.{}.mfdb'.format(level, weight))
    Ldbinfile = os.path.join(base_import,
                             'mfldb/{}.{}.mfldb'.format(level, weight))

    notfound = False

    if not os.path.exists(polyinfile):
        print '{} not found'.format(polyinfile)
        notfound = True
    if not os.path.exists(mfdbinfile):
        print '{} not found'.format(mfdbinfile)
        notfound = True
    if not os.path.exists(Ldbinfile):
        print '{} not found'.format(Ldbinfile)
        notfound = True

    if only_orbit is not None:
        print "N = %s, k = %s, orbit = %s" % (level, weight, only_orbit)
        if lfun_filename is None:
            lfun_filename = os.path.join(
                base_export,
                'CMF_Lfunctions_%d_%d_%d.txt' % (level, weight, only_orbit))
        if instances_filename is None:
            instances_filename = os.path.join(
                base_export,
                'CMF_instances_%d_%d_%d.txt' % (level, weight, only_orbit))
        if hecke_filename is None:
            hecke_filename = os.path.join(
                base_export,
                'CMF_hecke_cc_%d_%d_%d.txt' % (level, weight, only_orbit))
        if traces_filename is None:
            traces_filename = os.path.join(
                base_export,
                'CMF_traces_%d_%d_%d.txt' % (level, weight, only_orbit))
    if lfun_filename is None:
        lfun_filename = os.path.join(
            base_export, 'CMF_Lfunctions_%d.txt' % (level * weight**2))
    if instances_filename is None:
        instances_filename = os.path.join(
            base_export, 'CMF_instances_%d.txt' % (level * weight**2))
    if hecke_filename is None:
        hecke_filename = os.path.join(
            base_export, 'CMF_hecke_cc_%d.txt' % (level * weight**2))
    if traces_filename is None:
        traces_filename = os.path.join(
            base_export, 'CMF_traces_%d.txt' % (level * weight**2))

    def write_traces(traces_filename):
        with open(traces_filename, 'a') as F:
            for ol in Set(orbit_labels.values()):
                if only_orbit is not None:
                    if ol != only_orbit:
                        continue

                F.write('{}:{}:{}:{}:{}\n'.format(level, weight, ol,
                                                  degrees_sorted[ol],
                                                  traces_sorted[ol]).replace(
                                                      ' ', ''))

    #level_list = set()
    #level_weight_list = []
    #for dirpath, dirnames, filenames in os.walk(inpath):
    #    for filename in filenames:
    #        if not filename.endswith('.polydb'):
    #            continue
    #        level, weight, _ = filename.split('.')
    #        level = int(level)
    #        weight = int(weight)
    #        level_weight_list.append( (level, weight, os.path.join(dirpath, filename)) )
    #        level_list.add(level)
    #
    #level_list = sorted(level_list)
    orbit_labels = {}
    G = DirichletGroup_conrey(level)
    orbits = G._galois_orbits()
    for k, orbit in enumerate(orbits):
        for chi in orbit:
            # we are starting at 1
            orbit_labels[chi] = k + 1
    if level == 1:
        k = 0
        orbit_labels = {1: 1}

    degrees_sorted = [[] for _ in range(k + 2)]
    traces_sorted = [[] for _ in range(k + 2)]

    dim = dimension_new_cusp_forms(Gamma1(level), weight)
    if notfound:
        assert dim == 0, "dim = %s" % dim
        write_traces(traces_filename)
        return 1

    degree_lists = {}
    traces_lists = {}

    db = sqlite3.connect(polyinfile)
    db.row_factory = sqlite3.Row
    '''
    expected schema:
    CREATE TABLE heckepolys (level INTEGER,
                             weight INTEGER,
                             chi INTEGER,
                             whatevernumber INTEGER,
                             labelnumber    INTEGER,
                             operator       BLOB,
                             degree         INTEGER,
                             mforbit        BLOB,
                             polynomial     BLOB);
    '''

    mfdb = sqlite3.connect(os.path.join(mfdbinfile))
    mfdb.row_factory = sqlite3.Row
    '''
    expected schema:
        CREATE TABLE modforms (level INTEGER, weight INTEGER, chi INTEGER, orbit INTEGER, j INTEGER,
            prec INTEGER, exponent INTEGER, ncoeffs INTEGER, coefficients BLOB)
    '''
    coeffs = {}

    for result in mfdb.execute(
            'SELECT prec, exponent, ncoeffs, coefficients, chi, j FROM modforms WHERE level={} AND weight={};'
            .format(level, weight)):
        chi = result['chi']
        chibar = inverse_mod(chi, level)
        if only_orbit is not None and only_orbit not in [
                orbit_labels[chi], orbit_labels[chibar]
        ]:
            continue

        is_trivial = False
        #is_quadratic = False
        if chi == 1:
            is_trivial = True
        #elif (chi*chi) % level == 1:
        #    is_quadratic = True

        j = result['j']
        offset = 0
        coeffblob = result['coefficients']
        exponent = QQ(result['exponent'])
        prec = QQ(result['prec'])
        # print prec, exponent
        _coeffs = [CCC(0)] * (to_compute + 1)
        #for k in range(35): # number of prime powers < 100
        for pp in prime_powers(to_compute):
            z, bytes_read = read_gmp_int(coeffblob, offset)
            #print z
            offset = offset + bytes_read
            real_part = CCC(z) * 2**exponent
            if prec != MF_PREC_EXACT:
                real_part = real_part.add_error(2**prec)
            imag_part = 0
            if not is_trivial:
                z, bytes_read = read_gmp_int(coeffblob, offset)
                offset = offset + bytes_read
                imag_part = CCC.gens()[0] * CCC(z) * 2**exponent
                if prec != MF_PREC_EXACT:
                    imag_part = imag_part.add_error(2**prec)
            #print real_part + imag_part
            _coeffs[pp] = real_part + imag_part
        #print coeffs
        _coeffs[1] = CCC(1)
        extend_multiplicatively(_coeffs)
        coeffs[(chi, j)] = _coeffs
        if chibar > chi:
            coeffs[(chibar, j)] = [elt.conjugate() for elt in _coeffs]

    if only_orbit is None:
        assert len(coeffs) == dim, "%s != %s, keys = %s" % (len(coeffs), dim,
                                                            coeffs.keys())

    if not only_traces:
        bad_euler_factors = {}
        euler_factors = {}
        angles = {}
        coeffs_f = {}

        for key, coeff in coeffs.iteritems():
            chi, j = key
            coeffs_f[key], angles[key], euler_factors[key], bad_euler_factors[
                key] = angles_euler_factors(coeff, level, weight, chi)

    #mforbits = {}

    for result in db.execute(
            'SELECT level, weight, chi, whatevernumber, labelnumber, degree, mforbit from heckepolys;'
    ):
        level = result['level']
        weight = result['weight']
        chi = result['chi']
        original_chi = chi
        if only_orbit is not None and only_orbit != orbit_labels[original_chi]:
            continue

        if (level, weight, chi) not in degree_lists:
            degree_lists[(level, weight, chi)] = []
            traces_lists[(level, weight, chi)] = []
        degree_lists[(level, weight, chi)].append(result['degree'])

        #whatever = result['whatevernumber']
        label = result['labelnumber']
        #degree = result['degree']
        mforbit = read_orbit(result['mforbit'])
        #mforbits[original_chi] = mforbit
        #print level, weight, chi, whatever, label, degree, mforbit

        #is_trivial = False
        #is_quadratic = False
        #if chi == 1:
        #    is_trivial = True
        #elif (chi*chi) % level == 1:
        #    is_quadratic = True

        traces_bound = to_compute + 1
        traces = [RRR(0)] * traces_bound
        for chi, j in mforbit:
            #if inverse_mod(chi, level) < chi:
            #    continue
            for k, z in enumerate(coeffs[(chi, j)][:traces_bound]):
                traces[k] += RRR(z.real())

        for i, z in enumerate(traces):
            try:
                traces[i] = z.unique_integer()
            except ValueError:
                traces = traces[:i]
                #print (level, weight, original_chi, orbit_labels[original_chi])
                #print degree_lists[(level, weight, original_chi)]
                #print i, z
                #print traces[:i]
                break
        traces_lists[(level, weight, original_chi)].append(
            (traces[1:], mforbit))
    Ldb = sqlite3.connect(os.path.join(Ldbinfile))
    Ldb.row_factory = sqlite3.Row
    '''
    expected schema:
    CREATE TABLE modformLfunctions
       (level     INTEGER,
        weight     INTEGER,
        chi        INTEGER,
        orbit      INTEGER,
        j          INTEGER,
        rank       INTEGER,
        rankverified INTEGER,
        signarg    REAL
        gamma1     REAL,
        gamma2     REAL,
        gamma3     REAL,
        zeroprec   INTEGER,
        nzeros     INTEGER,
        zeros      BLOB,
        valuesdelta         REAL,
        nvalues             INTEGER,
        Lvalues             BLOB);
    '''

    zeros = {}
    Ldbresults = {}
    if only_traces:
        cur = []
    else:
        cur = Ldb.execute(
            'SELECT level, weight, chi, j, rank, zeroprec, nzeros, zeros, valuesdelta, nvalues, Lvalues, signarg from modformLfunctions'
        )

    for result in cur:
        nzeros = result['nzeros']
        prec = result['zeroprec']
        chi = result['chi']
        if only_orbit is not None and only_orbit != orbit_labels[chi]:
            continue
        j = result['j']
        #print result['level'], result['weight'], chi, j
        _zeros = []
        offset = 0
        for k in range(nzeros):
            nlimbs = struct.unpack_from(">I", result['zeros'], offset)[0]
            offset = offset + 4
            zdata = struct.unpack_from("B" * nlimbs, result['zeros'], offset)
            offset = offset + nlimbs
            z = sum([x * 2**(8 * k) for (k, x) in enumerate(reversed(zdata))])
            _zeros.append(z)
        zeros[(chi, j)] = map(ZZ, _zeros)
        Ldbresults[(chi, j)] = result
    '''
    for level, weight, chi in sorted(degree_lists.keys()):
        toprint = '{}:{}:{}:[{}]:[{}]'.format(level, weight, orbit_labels[chi], sorted(degree_lists[(level, weight, chi)]), sorted(traces_lists[(level, weight, chi)]))
        print ''.join(toprint.split())
        for chi2, j in mforbits[chi]:
            print chi2, j, zeros[(chi2, j)]
    '''

    labels = {}
    original_pair = {}
    conjugates = {}
    selfduals = {}
    hecke_orbit_code = {}
    all_the_labels = {}
    embedding_m = {}

    for level, weight, originalchi in sorted(degree_lists.keys()):
        #toprint = '{}:{}:{}:{}'.format(level, weight, orbit_labels[originalchi], sorted(degree_lists[(level, weight, originalchi)]))
        #print ''.join(toprint.split())
        degrees_sorted[orbit_labels[originalchi]] = sorted(
            degree_lists[(level, weight, originalchi)])
        for mforbitlabel, (traces, mforbit) in enumerate(
                sorted(traces_lists[(level, weight, originalchi)])):
            selfdual = False
            if originalchi == 1:
                selfdual = True
            if (originalchi * originalchi) % level == 1:
                Z = coeffs[mforbit[0]]
                selfdual = True
                for z in Z:
                    if not z.imag().contains_zero():
                        selfdual = False
                        break
            #if selfdual:
            #    print '*',
            #print mforbit, traces
            traces_sorted[orbit_labels[originalchi]].append(traces[:to_store])
            if only_traces:
                continue
            chi_list = sorted(set(chi for (chi, j) in mforbit))
            coeffs_list = {}
            for chi in chi_list:
                j_list = [elt for (_, elt) in mforbit if _ == chi]
                coeffs_list[chi] = [(chi, elt, coeffs[(chi, elt)])
                                    for elt in j_list]
                coeffs_list[chi].sort(cmp=CBFlistcmp, key=lambda z: z[-1])
            d = len(j_list)
            m = 1
            for chi in chi_list:
                chibar = inverse_mod(chi, level)
                for k, _coeffs in enumerate(coeffs_list[chi]):
                    j = _coeffs[1]
                    assert chi == _coeffs[0]
                    sa, sn = cremona_letter_code(mforbitlabel), k + 1
                    ol = cremona_letter_code(orbit_labels[chi] - 1)
                    an_conjugate = [elt.conjugate() for elt in _coeffs[2]]
                    if selfdual:
                        chibar = chi
                        ca, cn = sa, sn
                    else:
                        ca = sa
                        # first try the obvious
                        for elt in [k] + list(range(0, k)) + list(
                                range(k + 1, d)):
                            if CBFlisteq(coeffs_list[chibar][elt][2],
                                         an_conjugate):
                                cn = elt + 1
                                break
                        else:
                            assert False
                    assert CBFlisteq(coeffs_list[chibar][cn - 1][2],
                                     an_conjugate)
                    # orbit_labels[chi] start at 1
                    # mforbitlabel starts at 0
                    hecke_orbit_code[(chi, j)] = int(level + (weight << 24) + (
                        (orbit_labels[chi] - 1) << 36) + (mforbitlabel << 52))
                    all_the_labels[(chi, j)] = (level, weight, ol, sa, chi, sn)
                    converted_label = (chi, sa, sn)
                    labels[(chi, j)] = converted_label
                    original_pair[converted_label] = (chi, j)
                    selfduals[converted_label] = selfdual
                    conjugates[converted_label] = (chibar, ca, cn)
                    embedding_m[(chi, j)] = m
                    m += 1
    if only_traces:
        write_traces(traces_filename)
        return 0

    #for key, val in labels.iteritems():
    #    print key,"  \t-new->\t", val
    #for key, val in conjugates.iteritems():
    #    print key,"\t--c-->\t", val

    #for key, val in all_the_labels.iteritems():
    #    print key," \t--->\t" + "\t".join( map(str, [val,hecke_orbit_code[key]]))

    def origin(chi, a, n):
        return "ModularForm/GL2/Q/holomorphic/%d/%d/%s/%s/%d/%d" % (
            level, weight, cremona_letter_code(orbit_labels[chi] - 1), a, chi,
            n)

    def rational_origin(chi, a):
        return "ModularForm/GL2/Q/holomorphic/%d/%d/%s/%s" % (
            level, weight, cremona_letter_code(orbit_labels[chi] - 1), a)

    def label(chi, j):
        return labels[(chi, j)]

    def self_dual(chi, a, n):
        return selfduals[(chi, a, n)]

    Lhashes = {}
    instances = {}
    # the function below assumes this order
    assert schema_instances == ['url', 'Lhash', 'type']

    def tuple_instance(row):
        return (row['origin'], row['Lhash'], default_type)

    real_zeros = {}
    rows = {}

    def populate_complex_row(Ldbrow):
        row = dict(constant_lf(level, weight, 2))
        chi = int(Ldbrow['chi'])
        j = int(Ldbrow['j'])
        chil, a, n = label(chi, j)
        assert chil == chi

        row['order_of_vanishing'] = int(Ldbrow['rank'])
        zeros_as_int = zeros[(chi, j)][row['order_of_vanishing']:]
        prec = row['accuracy'] = Ldbrow['zeroprec']
        two_power = 2**prec
        double_zeros = [float(z / two_power) for z in zeros_as_int]
        zeros_as_real = [
            RealNumber(z.str() + ".") / two_power for z in zeros_as_int
        ]
        real_zeros[(chi, a, n)] = zeros_as_real
        zeros_as_str = [z.str(truncate=False) for z in zeros_as_real]
        for i, z in enumerate(zeros_as_str):
            assert float(z) == double_zeros[i]
            assert (RealNumber(z) * two_power).round() == zeros_as_int[i]

        row['positive_zeros'] = str(zeros_as_str).replace("'", "\"")

        row['origin'] = origin(chi, a, n)
        row['central_character'] = "%s.%s" % (level, chi)
        row['self_dual'] = self_dual(chi, a, n)
        row['conjugate'] = None
        row['Lhash'] = str((zeros_as_int[0] * 2**(100 - prec)).round())
        if prec < 100:
            row['Lhash'] = '_' + row['Lhash']
        Lhashes[(chi, a, n)] = row['Lhash']
        row['sign_arg'] = float(Ldbrow['signarg'] / (2 * pi))
        for i in range(0, 3):
            row['z' + str(i + 1)] = (RealNumber(str(zeros_as_int[i]) + ".") /
                                     2**prec).str()

        row['plot_delta'] = Ldbrow['valuesdelta']
        row['plot_values'] = [
            float(CDF(elt).real_part())
            for elt in struct.unpack('{}d'.format(len(Ldbrow['Lvalues']) /
                                                  8), Ldbrow['Lvalues'])
        ]

        row['leading_term'] = '\N'
        if row['self_dual']:
            row['root_number'] = str(
                RRR(CDF(exp(2 * pi * I *
                            row['sign_arg'])).real()).unique_integer())
            if row['root_number'] == str(1):
                row['sign_arg'] = 0
            elif row['root_number'] == str(-1):
                row['sign_arg'] = 0.5
        else:
            row['root_number'] = str(CDF(exp(2 * pi * I * row['sign_arg'])))
        #row['dirichlet_coefficients'] = [None] * 10
        #print label(chi,j)
        for i, ai in enumerate(coeffs[(chi, j)][2:12]):
            if i + 2 <= 10:
                row['a' + str(i + 2)] = CBF_to_pair(ai)
                # print 'a' + str(i+2), ai_jsonb
            #row['dirichlet_coefficients'][i] = ai_jsonb

        row['coefficient_field'] = 'CDF'

        # only 30
        row['euler_factors'] = map(lambda x: map(CBF_to_pair, x),
                                   euler_factors[(chi, j)][:30])
        row['bad_lfactors'] = map(
            lambda x: [int(x[0]), map(CBF_to_pair, x[1])],
            bad_euler_factors[(chi, j)])

        for key in schema_lf:
            assert key in row, "%s not in row = %s" % (key, row)
        assert len(row) == len(schema_lf), "%s != %s" % (len(row),
                                                         len(schema_lf))

        #rewrite row as a list
        rows[(chi, a, n)] = [row[key] for key in schema_lf]
        instances[(chi, a, n)] = tuple_instance(row)

    def populate_complex_rows():
        for key, row in Ldbresults.iteritems():
            populate_complex_row(row)

    def populate_conjugates():
        #    print Lhashes.keys()
        for key, row in rows.iteritems():
            #        print "key = %s" % (key,)
            row[schema_lf_dict['conjugate']] = Lhashes[conjugates[key]]
            row_conj = rows[conjugates[key]]
            zero_val_conj = row_conj[schema_lf_dict['plot_values']][0]
            assert (row[schema_lf_dict['plot_values']][0] -
                    zero_val_conj) < 1e-10, "%s, %s: %s - %s = %s" % (
                        key, conjugates[key],
                        row[schema_lf_dict['plot_values']][0], zero_val_conj,
                        row[schema_lf_dict['plot_values']][0] - zero_val_conj)
            diff = (row[schema_lf_dict['sign_arg']] +
                    row_conj[schema_lf_dict['sign_arg']]) % 1
            assert min(diff, 1 - diff) < 1e-10, "%s  + %s  = %s" % (
                row[schema_lf_dict['sign_arg']],
                row_conj[schema_lf_dict['sign_arg']], diff)

    rational_rows = {}

    def populate_rational_rows():
        order_of_vanishing = schema_lf_dict['order_of_vanishing']
        accuracy = schema_lf_dict['accuracy']
        sign_arg = schema_lf_dict['sign_arg']
        Lhash = schema_lf_dict['Lhash']
        plot_delta = schema_lf_dict['plot_delta']
        plot_values = schema_lf_dict['plot_values']
        central_character = schema_lf_dict['central_character']
        # reverse euler factors from the table for  p^d < 1000
        rational_keys = {}
        for chi, a, n in rows.keys():
            orbit_label = orbit_labels[chi]
            if (orbit_label, a) not in rational_keys:
                rational_keys[(orbit_label, a)] = []
            rational_keys[(orbit_label, a)].append((chi, a, n))

        for (orbit_label, a), triples in rational_keys.iteritems():
            # for now skip degree >= 100
            if len(triples) > 80:  # the real limit is 87
                continue
            pairs = [original_pair[elt] for elt in triples]
            #print a, pairs, triples
            chi = triples[0][0]
            degree = 2 * len(triples)
            row = constant_lf(level, weight, degree)
            row['origin'] = rational_origin(chi, a)
            print row['origin']
            row['self_dual'] = 't'
            row['conjugate'] = '\N'
            row['order_of_vanishing'] = sum(
                [rows[elt][order_of_vanishing] for elt in triples])
            row['accuracy'] = min([rows[elt][accuracy] for elt in triples])

            ###
            zeros_as_real = []
            for elt in triples:
                zeros_as_real.extend(real_zeros[elt])
            zeros_as_real.sort()
            zeros_as_str = [z.str(truncate=False) for z in zeros_as_real]
            row['positive_zeros'] = str(zeros_as_str).replace("'", "\"")
            zeros_hash = sorted([(rows[elt][Lhash], real_zeros[elt][0])
                                 for elt in triples],
                                key=lambda x: x[1])
            row['Lhash'] = ",".join([elt[0] for elt in zeros_hash])
            # character
            if degree == 2:
                row['central_character'] = rows[triples[0]][central_character]
            else:
                G = DirichletGroup_conrey(level)
                chiprod = prod([
                    G[int(rows[elt][central_character].split(".")[-1])]
                    for elt in triples
                ])
                chiprod_index = chiprod.number()
                row['central_character'] = "%s.%s" % (level, chiprod_index)

            row['sign_arg'] = sum([rows[elt][sign_arg] for elt in triples])
            while row['sign_arg'] > 0.5:
                row['sign_arg'] -= 1
            while row['sign_arg'] <= -0.5:
                row['sign_arg'] += 1
            zeros_zi = []
            for i in range(0, 3):
                for elt in triples:
                    zeros_zi.append(rows[elt][schema_lf_dict['z' +
                                                             str(i + 1)]])
            zeros_zi.sort(key=lambda x: RealNumber(x))
            for i in range(0, 3):
                row['z' + str(i + 1)] = zeros_zi[i]

            deltas = [rows[elt][plot_delta] for elt in triples]
            values = [rows[elt][plot_values] for elt in triples]
            row['plot_delta'], row['plot_values'] = prod_plot_values(
                deltas, values)
            row['leading_term'] = '\N'
            row['root_number'] = str(
                RRR(CDF(exp(2 * pi * I *
                            row['sign_arg'])).real()).unique_integer())
            if row['root_number'] == str(1):
                row['sign_arg'] = 0
            elif row['root_number'] == str(-1):
                row['sign_arg'] = 0.5
            row['coefficient_field'] = '1.1.1.1'

            for chi, _, _ in triples:
                if (level, weight, chi) in traces_lists:
                    for elt in traces_lists[(level, weight, chi)]:
                        if set(elt[1]) <= set(pairs):
                            traces = elt[0]
                            break
                    else:
                        print pairs
                        print traces_lists[(level, weight, chi)]
                        assert False
                    break
            else:
                print pairs
                print traces_lists
                assert False

            euler_factors_cc = [euler_factors[elt] for elt in pairs]
            row['euler_factors'], row[
                'bad_lfactors'], dirichlet = rational_euler_factors(
                    traces, euler_factors_cc, level, weight)
            #handling Nones
            row['euler_factors'] = json.dumps(row['euler_factors'])
            row['bad_lfactors'] = json.dumps(row['bad_lfactors'])

            # fill in ai
            for i, ai in enumerate(dirichlet):
                if i > 1:
                    row['a' + str(i)] = int(dirichlet[i])
                    #print 'a' + str(i), dirichlet[i]

            for key in schema_lf:
                assert key in row, "%s not in row = %s" % (key, row.keys())
            for key in row.keys():
                assert key in schema_lf, "%s unexpected" % key
            assert len(row) == len(schema_lf), "%s != %s" % (len(row),
                                                             len(schema_lf))

            #rewrite row as a list
            rational_rows[(orbit_label, a)] = [row[key] for key in schema_lf]
            instances[(orbit_label, a)] = tuple_instance(row)

            # if dim == 1, drop row
            if len(triples) == 1:
                rows.pop(triples[0])
                instances.pop(triples[0])

    def get_hecke_cc():
        # if field_poly exists then compute the corresponding embedding of the root
        # add the conrey label
        hecke_cc = {}
        for key, label in labels.iteritems():
            # key = (chi,j)
            # label = (chi, a, n)
            chi, a, n = label
            ol = cremona_letter_code(orbit_labels[chi] - 1)
            lfuntion_label = ".".join(
                map(str, [level, weight] + [ol, a, chi, n]))
            hecke_cc[key] = [
                int(hecke_orbit_code[key]),
                lfuntion_label,  # N.k.c.x.n
                int(label[0]),  # conrey_label
                int(label[2]),  # embedding_index
                int(embedding_m[key]),
                '\N',  # embedding_root_real
                '\N',  # embedding_root_imag
                coeffs_f[key][1:],
                angles[key],
            ]
        return hecke_cc

    def json_hack(elt):
        if isinstance(elt, str):
            return elt
        else:
            return json.dumps(elt)

    def write_hecke_cc(hecke_filename):
        write_header_hecke_file(hecke_filename)
        with open(hecke_filename, 'a') as HF:
            for v in get_hecke_cc().values():
                try:
                    HF.write("\t".join(map(json_hack, v)).replace(
                        '[', '{').replace(']', '}') + "\n")
                except TypeError:
                    for elt in v:
                        print elt
                        print json_hack(elt)
                    raise

    def export_complex_rows(lfunctions_filename, instances_filename):
        write_header(lfunctions_filename, instances_filename)
        #str_parsing_lf = '\t'.join(['%r'] * len(schema_lf)) + '\n'
        #str_parsing_instances = '\t'.join(['%r'] * len(schema_instances)) + '\n'

        with open(lfunctions_filename, 'a') as LF:
            for key, row in rows.iteritems():
                try:
                    LF.write("\t".join(map(json_hack, row)) + "\n")
                except TypeError:
                    for i, elt in enumerate(row):
                        print schema_lf[i]
                        print elt
                        print json_hack(elt)
                    raise

            for key, row in rational_rows.iteritems():
                try:
                    LF.write("\t".join(map(json_hack, row)) + "\n")
                except TypeError:
                    for elt in row:
                        print elt
                        print json_hack(elt)
                    raise
        with open(instances_filename, 'a') as IF:
            for key, row in instances.iteritems():
                IF.write("\t".join(map(json_hack, row)) + "\n")

    populate_complex_rows()
    #populate_conjugates()
    #populate_rational_rows()
    #export_complex_rows(lfun_filename, instances_filename)
    write_hecke_cc(hecke_filename)
    #write_traces(traces_filename)
    return 0
Exemplo n.º 7
0
def extend_multiplicatively(Z):
    for pp in prime_powers(len(Z)-1):
        for k in range(1, (len(Z) - 1)//pp + 1):
            if gcd(k, pp) == 1:
                Z[pp*k] = Z[pp]*Z[k]