
# q-expansion of newform 882.4.a.f, 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
    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 = 882
weight = 4
poly_data = [0, 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 = [[-2], [0], [9], [0], [57], [-70], [-51], [5], [-69], [-114], [23], [-253], [42], [-124], [-201], [393], [-219], [-709], [419], [96], [-313], [461], [588], [1017], [-1834], [285], [-499], [1107], [923], [-1542], [-2056], [-2049], [141], [1484], [57], [839], [-2833], [-2311], [-1260], [-3267], [-1287], [-2674], [-4185], [-85], [390], [-2833], [-124], [56], [3057], [-961], [2829], [3540], [5231], [-5040], [1437], [2325], [2385], [-331], [4871], [7026], [-5353], [-4158], [-9604], [-10131], [10799], [-531], [-7015], [8990], [8709], [6482], [2133], [-3849], [6491], [923], [6344], [5007], [-12291], [887], [-11955], [-3421], [5460], [7730], [11313], [4214], [16553], [16395], [15090], [-14785], [-2898], [464], [-4233], [-2739], [17051], [4296], [3401], [-16800], [-1839], [-303], [-21667], [5039], [-2392], [22149], [8349], [15345], [-11593], [-14593], [15372], [14373], [-2547], [-7042], [-22591], [-8485], [18282], [2291], [-6928], [-24975], [9548], [-10131], [-16659], [-29556], [191], [2606], [4209], [-24303], [15041], [-24726], [-4957], [-27669], [-13888], [14243], [36959], [12528], [-17767], [-28726], [26469], [5054], [35565], [-8629], [-20706], [16185], [-11788], [29793], [30323], [-21156], [-5269], [39816], [14546], [31449], [-24523], [8163], [4367], [50190], [12308], [-31617], [-13525], [19248], [-8695], [-19479], [-12502], [15993], [-44001], [4002], [10544], [6183], [-3723], [45897], [6467], [23039], [-38218], [27981], [17781], [19082], [21771], [22175], [13799], [-30198], [-19696], [-16743], [-27664], [54479], [64637], [61068], [-3106], [43017], [20133], [67233], [-66949], [16487], [-3949], [27585], [32639], [-47196], [-24235], [56121], [27945], [-41211], [923], [-17305], [-40446], [5427], [-27411], [-67480], [40619], [34211], [-33852], [-64479], [4205], [-33837], [83382], [37739], [-53173], [-43050], [2648], [8031], [-32391], [-84037], [39647], [36573], [13119], [31386], [15959], [41804], [-48999], [-22471], [-50820], [16130], [34869], [-83355], [9665], [44199], [7055], [104267], [-4912], [110685], [-70588], [11709], [8699], [-73359], [-40644], [-64260], [29037], [2189], [-61045], [21755], [-2562], [103371], [-20104], [-85983], [102143], [-39300], [33434], [-120783], [59361], [11102], [-105975], [-128925], [-58801], [-30217], [79086], [61787], [46283], [22692], [-2245], [21266], [-12819], [34781], [4086], [43386], [88580], [-92595], [-6337], [57791], [-44077], [-106303], [47558], [-139939], [40839], [114575], [107183], [-77061], [-11727], [-142969], [-85176], [-20902], [2189], [24879], [-84337], [726], [-44581], [-1302], [23997], [-31047], [-146103], [57288], [-112726], [72693], [-147751], [-63714], [60279], [-54376], [-53377], [79185], [-145825], [103164], [138725], [132638], [-49587], [83090], [-7041], [118103], [-124269], [-122751], [-55635], [102395], [-32664], [31691], [183372], [-88815], [-67858], [-164166], [78815], [-146749], [-122514], [189884], [-24639], [98999], [-49015], [83753], [-179829], [100014], [-112477], [-114435], [173096], [198525], [-138601], [92316], [18650], [-114819], [95690], [-139771], [-133477], [-10446], [97230], [22976], [12069], [-99108], [-200737], [16085], [-59220], [-14523], [-36871], [76691], [-128130], [176339], [-9157], [10038], [76659], [-40623], [3501], [114504], [77114], [-94659], [16521], [119967], [13043], [139691], [67158], [-217393], [-58966], [27525], [222101], [252519], [-81006], [155255], [40403], [191721], [102912], [55883], [103161], [108542], [59421], [191658], [-208024], [-47655], [122780], [31281], [-122725], [64703], [-126463], [-159264], [13106], [179601], [123285], [130121], [-176721], [-106009], [-49453], [234906], [82868], [97413], [-105037], [-7251], [-236671], [-10071], [-144027], [96437], [41159], [79266], [-173857], [123615], [1559], [-60171], [-26532], [-95299], [-129610], [-173115], [-279873], [178943], [123858], [-210033], [110097], [-202813], [165744], [96852], [-225610], [83865], [-81045], [-120990], [-82717], [-261207]]
