
# q-expansion of newform 768.4.a.m, downloaded from the LMFDB on 25 April 2024.

# We generate the q-expansion using the Hecke eigenvalues a_p at the primes.
# Each a_p is given as a linear combination
# of the following basis for the coefficient ring.

def make_data():

    from sage.all import prod, floor, prime_powers, gcd, QQ, primes_first_n, next_prime, RR

    def discrete_log(elts, gens, mod):
        # algorithm 2.2, page 16 of https://arxiv.org/abs/0903.2785
        def table_gens(gens, mod):
            T = [1]
            n = len(gens)
            r = [None]*n
            s = [None]*n
            for i in range(n):
                beta = gens[i]
                r[i] = 1
                N = len(T)
                while beta not in T:
                    for Tj in T[:N]:
                        T.append((beta*Tj) % mod)
                    beta = (beta*gens[i]) % mod
                    r[i] += 1
                s[i] = T.index(beta)
            return T, r, s
        T, r, s = table_gens(gens, mod)
        n = len(gens)
        N = [ prod(r[:j]) for j in range(n) ]
        Z = lambda s: [ (floor(s/N[j]) % r[j]) for j in range(n)]
        return [Z(T.index(elt % mod)) for elt in elts]
    def extend_multiplicatively(an):
        for pp in prime_powers(len(an)-1):
            for k in range(1, (len(an) - 1)//pp + 1):
                if gcd(k, pp) == 1:
                    an[pp*k] = an[pp]*an[k]
    from sage.all import PolynomialRing, NumberField, ZZ
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K([c/ZZ(den) for c in num]) for num, den in basis_data]
    convert_elt_to_field = lambda elt: sum(c*beta for c, beta in zip(elt, betas))
    # convert aps to K elements
    primes = primes_first_n(len(aps_data))
    good_primes = [p for p in primes if not p.divides(level)]
    aps = map(convert_elt_to_field, aps_data)
    if not hecke_ring_character_values:
        # trivial character
        char_values = dict(zip(good_primes, [1]*len(good_primes)))
    else:
        gens = [elt[0] for elt in hecke_ring_character_values]
        gens_values = [convert_elt_to_field(elt[1]) for elt in hecke_ring_character_values]
        char_values = dict([(
            p,prod(g**k for g, k in zip(gens_values, elt)))
            for p, elt in zip(good_primes, discrete_log(good_primes, gens, level))
            ])
    an_list_bound = next_prime(primes[-1])
    an = [0]*an_list_bound
    an[1] = 1
    
    from sage.all import PowerSeriesRing
    PS = PowerSeriesRing(K, "q")
    for p, ap in zip(primes, aps):
        if p.divides(level):
            euler_factor = [1, -ap]
        else:
            euler_factor = [1, -ap, p**(weight - 1) * char_values[p]]
        k = RR(an_list_bound).log(p).floor() + 1
        foo = (1/PS(euler_factor)).padded_list(k)
        for i in range(1, k):
            an[p**i] = foo[i]
    extend_multiplicatively(an)
    return PS(an)
level = 768
weight = 4
poly_data = [-2, 0, 1]

# The entries in the following list give a basis for the
# coefficient ring in terms of a root of the defining polynomial above.
# Each line consists of the coefficients of the numerator, and a denominator.
basis_data  = [[[1, 0], 1], [[0, 2], 1]]

hecke_ring_character_values = None
aps_data = [[0, 0], [3, 0], [0, 1], [0, -5], [-20, 0], [0, 14], [-34, 0], [-52, 0], [0, -22], [0, 71], [0, 39], [0, -96], [-26, 0], [-252, 0], [0, -122], [0, -241], [-364, 0], [0, 260], [-628, 0], [0, 118], [338, 0], [0, 279], [-1036, 0], [234, 0], [-178, 0], [0, 91], [0, -667], [-1404, 0], [0, -14], [1378, 0], [0, 633], [-1572, 0], [2854, 0], [-1964, 0], [0, 533], [0, -801], [0, -1248], [-2932, 0], [0, 1300], [0, -511], [1308, 0], [0, 706], [0, -332], [-2490, 0], [0, 963], [0, -763], [924, 0], [0, 805], [-156, 0], [0, -226], [2826, 0], [0, -872], [-3354, 0], [6396, 0], [6882, 0], [0, 0], [0, 507], [0, 2101], [0, -390], [6266, 0], [8596, 0], [0, -2969], [4940, 0], [0, -1196], [-3106, 0], [0, 2379], [-2908, 0], [4298, 0], [9996, 0], [0, 1412], [6738, 0], [0, -754], [0, -2697], [0, -2964], [12788, 0], [0, -820], [0, 949], [0, 780], [3582, 0], [5126, 0], [-2924, 0], [0, 2586], [0, 5602], [-6274, 0], [0, 1625], [5084, 0], [14190, 0], [-6474, 0], [0, -2235], [0, -4043], [3796, 0], [0, 3710], [0, 5447], [-15452, 0], [-52, 0], [0, -4394], [0, -5785], [-714, 0], [-5980, 0], [0, -4854], [-18500, 0], [0, -3099], [-268, 0], [-13866, 0], [5140, 0], [9386, 0], [-8844, 0], [-9406, 0], [0, 8294], [-1262, 0], [0, -5759], [0, -2524], [16874, 0], [-20748, 0], [0, 5247], [17758, 0], [1148, 0], [0, -9542], [0, 7449], [-18356, 0], [0, 5392], [-12082, 0], [0, 4505], [-33508, 0], [364, 0], [0, -1361], [0, -8346], [0, 5586], [0, -1629], [0, 9270], [-27924, 0], [0, 3160], [0, 4979], [0, -5258], [-15834, 0], [-16666, 0], [0, -10945], [-20228, 0], [0, 3185], [-9242, 0], [-10972, 0], [0, -3301], [0, -1261], [-18876, 0], [0, 2466], [0, 10634], [0, -14552], [-25194, 0], [-9308, 0], [0, 9476], [0, 508], [-42830, 0], [23964, 0], [0, 9984], [31972, 0], [0, -9496], [0, -14261], [-13650, 0], [7098, 0], [0, -14611], [9900, 0], [-46938, 0], [0, -2471], [53052, 0], [-41890, 0], [0, 3840], [0, -117], [0, 14124], [30238, 0], [0, 4065], [-36396, 0], [0, -14360], [0, 17368], [-15782, 0], [0, 21207], [-64934, 0], [41444, 0], [0, 13741], [0, -10439], [0, -20832], [0, 15951], [70356, 0], [0, -8730], [1482, 0], [0, -22516], [0, 9945], [0, -21450], [22828, 0], [19422, 0], [0, 17072], [-2302, 0], [74932, 0], [-16420, 0], [0, -28379], [-31156, 0], [-23894, 0], [8762, 0], [0, 21862], [49394, 0], [0, -26260], [0, -8663], [0, -7455], [0, 6410], [-44134, 0], [13884, 0], [0, -11245], [0, -6239], [39236, 0], [9546, 0], [79412, 0], [51766, 0], [0, 6481], [0, 22809], [-66716, 0], [0, 22554], [-48106, 0], [0, 7059], [-84018, 0], [0, -28548], [0, 29905], [0, -25038], [0, -3619], [57694, 0], [0, -25663], [-93660, 0], [0, -2288], [-15510, 0], [0, 35094], [0, 1677], [-13916, 0], [0, 16770], [-10948, 0], [0, -25363], [-40214, 0], [59684, 0], [0, 20422], [12350, 0], [0, -37315], [-59956, 0], [0, -26214], [-44668, 0], [-34588, 0], [0, 25571], [0, 17016], [-76158, 0], [0, 12770], [0, -8601], [-38740, 0], [-79564, 0], [0, 42172], [0, -2358], [114898, 0], [0, 11578], [-117606, 0], [0, 891], [-50980, 0], [0, 25746], [-107900, 0], [0, 9871], [123942, 0], [0, -19331], [-28068, 0], [0, 26586], [0, 26072], [106366, 0], [-123956, 0], [0, -15679], [6522, 0], [-63180, 0], [0, 3653], [0, -42228], [-104260, 0], [-60470, 0], [0, -16969], [-17134, 0], [0, 20733], [-78468, 0], [0, -6812], [78338, 0], [-34260, 0], [0, -25162], [0, 39057], [0, 5622], [0, 14508], [12564, 0], [0, 37284], [107782, 0], [0, 3821], [0, -27165], [20114, 0], [0, -37583], [10828, 0], [101738, 0], [121700, 0], [0, 9392], [0, -42003], [0, 12213], [0, -24453], [9244, 0], [87276, 0], [25358, 0], [0, 21757], [0, 38679], [11596, 0], [106068, 0], [35702, 0], [-131412, 0], [0, 20670], [0, 51418], [0, -61932], [0, 12044], [0, 43419], [133470, 0], [-112372, 0], [0, -32404], [-33606, 0], [76492, 0], [0, -17446], [-173030, 0], [-78, 0], [132428, 0], [-52130, 0], [0, 59183], [0, 5143], [11206, 0], [11102, 0], [27164, 0], [116532, 0], [0, -11904], [0, -57895], [0, 44642], [0, -12623], [0, 74133], [118476, 0], [67444, 0], [83564, 0], [0, 26728], [-78078, 0], [25458, 0], [0, 3085], [0, -22008], [1158, 0], [0, -49525], [0, -36699], [0, 60943], [-173724, 0], [0, 42510], [-156124, 0], [0, -19534], [0, -12497], [181948, 0], [48054, 0], [0, 48307], [0, -37375], [0, -55800], [-101142, 0], [0, -38576], [57508, 0], [15790, 0], [0, 22996], [0, -20696], [83226, 0], [0, 6948], [67596, 0], [-136916, 0], [-119326, 0], [0, -12329], [0, -26169], [113030, 0], [-54300, 0], [-173724, 0], [0, -3528], [0, -10049], [0, -48997], [0, 80230], [15492, 0], [0, 59852], [211714, 0], [12558, 0], [-241202, 0], [0, -34567], [-108842, 0], [0, 52887], [-230910, 0], [-101940, 0], [0, 40292], [0, 32475], [0, 81098], [16276, 0], [0, -1774], [-71422, 0], [0, 90817], [-272428, 0], [-218308, 0], [0, -31520], [161862, 0], [0, 55797], [14838, 0], [-5356, 0], [0, 42297], [0, -18004], [-48802, 0], [0, -52083], [-130410, 0], [0, 61911], [0, 42523], [0, -27990], [89310, 0], [70012, 0], [-205452, 0], [-110118, 0], [0, -64363], [110460, 0], [-100820, 0], [-31790, 0], [0, -38305], [0, -94132], [0, 53079], [-57570, 0], [0, -43446], [0, -15739], [0, 43680], [0, 2236], [-175332, 0], [127950, 0], [0, -42993], [-288972, 0], [11050, 0], [206804, 0], [0, -25382]]
