
# q-expansion of newform 49.6.a.f, downloaded from the LMFDB on 19 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
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K.gens()[0]**i for i in range(len(poly_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 = 49
weight = 6
poly_data = [-14, -1, 1]

# The basis for the coefficient ring is just the power basis
# in the root of the defining polynomial above.
hecke_ring_character_values = None
aps_data = [[5, -1], [6, -6], [4, 10], [0, 0], [136, 124], [112, 126], [-862, -76], [1642, -18], [1328, -568], [3474, -252], [-260, 540], [3386, -540], [3570, -1092], [-3904, 4788], [-7724, 3748], [4630, 208], [22994, -2050], [34780, -4806], [11420, 1944], [46608, 4200], [-6098, -5256], [33080, -14904], [-66654, 15750], [-31034, -22208], [-14798, 8820], [64196, 27434], [-19988, -10476], [-54532, -21904], [-96982, -3348], [59166, -23940], [-96976, -8064], [249946, 23278], [166498, 51448], [-214970, 46242], [31022, -33496], [41576, -2592], [-176240, -81234], [-463192, 5508], [-72156, -48468], [-10328, -20906], [24580, 71440], [61432, 103950], [-279736, 50504], [-207946, 158436], [-90354, 83832], [98692, 118476], [570236, -54936], [-747320, -65016], [451226, 12398], [-97856, 284742], [266810, 117872], [-218328, 10920], [-633326, 237924], [1629894, -13902], [-754610, -8432], [73552, 91432], [-1889560, -25738], [270736, -440640], [360230, -571104], [520410, -351456], [829954, 132462], [-585060, -462462], [-654038, 359982], [519224, -542800], [1526914, -579492], [2986310, 13208], [-405568, -418860], [-970282, -337932], [-270848, -191228], [-1132040, -388458], [-3069298, 125840], [1465448, -87760], [920296, -259272], [-3134770, 313704], [1906424, 393372], [3813604, -91004], [2620138, -610892], [-3418040, 505494], [-219466, 385076], [3896794, -194508], [44814, 47586], [1787270, 976752], [-1531352, -796280], [-1626758, -591444], [-3115304, 782064], [1437812, -800584], [-2811534, 1268400], [-761602, -780732], [2334528, 67662], [-1144288, -734832], [1602850, -606554], [249500, -661828], [-1546528, 1113768], [-358188, -1755096], [-2453572, 257256], [4357584, -1921752], [6153592, 1041526], [1167410, 1874300], [-5296070, -879498], [5549990, 1550520], [418448, -2204244], [-1871258, 799048], [6376838, 1286090], [-7086130, 1296644], [-3522040, -817812], [3598846, 415584], [-5965554, 1878954], [-2158250, 1784296], [13030216, -476240], [-1977626, -3251808], [5221024, -2468736], [-2537350, -1492668], [9635502, 84], [-2528366, -2256498], [-9411904, -859320], [7992022, -1972700], [10577686, -1494486], [-17583196, -280468], [-8214502, 1566620], [5747856, 2978556], [-1606340, 2807442], [1389866, -2907576], [11259448, -707522], [1432084, 4306888], [-3003206, 1256958], [-12474054, -750708], [-3409366, 1659636], [3059116, 2943580], [-18731972, 33012], [-9245204, -3672918], [-24635608, 79812], [-379272, 1063104], [-6446680, -4022712], [18842714, -896364], [13288762, -3792044], [1412362, -3671892], [-12573604, 5491298], [12299986, 3121686], [35784, -1816794], [3000238, -5095148], [-906374, 2319030], [-4796458, -1048720], [-5467816, -1254528], [-3198900, -4052496], [9362380, 1136682], [10621884, -309372], [-14815472, 4184838], [-9363334, -5899564], [1383526, -4137102], [32942264, -1695016], [19641410, 3126276], [-1608474, -154056], [13146212, 1551312], [8503660, -1980668], [9376412, 1603152], [11539152, -8821008], [14135672, -2356992], [-7652606, 925732], [30900142, -2751336], [-5996068, -1426774], [-24146656, 1064300], [925962, 9684528], [2260400, -203112], [-20742158, -5484434], [-20071958, -8415080], [11531372, 9011780], [28009712, -2830032], [-46077620, 813618]]
