
# q-expansion of newform 350.4.a.f, downloaded from the LMFDB on 20 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 = 350
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], [2], [0], [-7], [48], [-56], [114], [2], [120], [-54], [236], [-146], [126], [376], [12], [-174], [138], [380], [484], [576], [1150], [776], [-378], [-390], [1330], [-1500], [-380], [-636], [146], [-198], [376], [2130], [78], [-2338], [-1002], [-2752], [520], [-1280], [-1764], [768], [1812], [-448], [-2136], [-4430], [-198], [-2284], [4412], [-2072], [366], [-376], [2262], [2592], [110], [-1890], [-2130], [4992], [6816], [8192], [-2414], [1962], [-5402], [4788], [574], [-8808], [2770], [-7566], [-11320], [4786], [-12648], [9632], [3390], [-10704], [8584], [2122], [-4912], [-9060], [8994], [12976], [-3522], [12710], [1638], [-12850], [-8016], [-2198], [-376], [-7188], [-14670], [5146], [-1512], [-7184], [16518], [10092], [-7832], [-6732], [18668], [6048], [11328], [-4146], [1006], [-14722], [13480], [-6222], [-4926], [22182], [3296], [24334], [-1638], [7446], [-6504], [16058], [-10208], [14974], [-7254], [12458], [28352], [27390], [21490], [-17652], [4782], [-27144], [-11860], [-5546], [14880], [-20964], [13106], [-4590], [-862], [-3540], [4228], [-5420], [1280], [35712], [24464], [-30242], [-2154], [10262], [-9084], [19798], [-30240], [-2346], [-29806], [-1506], [20392], [-36108], [-13876], [23436], [-8120], [50010], [34526], [17256], [-8714], [-22806], [-40196], [-40812], [13588], [-47304], [1784], [-35922], [26782], [4044], [2136], [15174], [-25832], [-37686], [54006], [-33276], [-3760], [-36524], [-54178], [-57192], [29028], [-23128], [-7680], [-34922], [17372], [-57582], [14492], [-15198], [-56000], [37676], [-19424], [4158], [-7562], [-63114], [-17688], [33024], [-52310], [46510], [-60334], [-11580], [15118], [12780], [-49372], [-64776], [9276], [-15762], [74990], [59830], [-32634], [51672], [-12426], [30548], [-2396], [35642], [64386], [-17148], [-24316], [35904], [42030], [33878], [52018], [-76860], [60352], [-82266], [60744], [1766], [-32528], [86070], [13224], [-95202], [68186], [-54376], [-20910], [-79904], [-20034], [15626], [-20778], [-2976], [34144], [-54048], [-62642], [20774], [33392], [26634], [97342], [6288], [-20914], [-12102], [29556], [-21168], [-51960], [55442], [-31232], [-68650], [-27594], [-84684], [-73136], [-110238], [-89944], [63936], [-38558], [-1902], [115872], [-82726], [-12], [-7932], [11738], [-65126], [41580], [67786], [21904], [34704], [54164], [-85484], [2130], [43094], [-101106], [60858], [16756], [52998], [-74464], [-42104], [95902], [62264], [37870], [22048], [45480], [80030], [-41938], [85290], [-59736], [3800], [-84924], [-111076], [-56450], [-89832], [-35426], [-20358], [-139876], [112770], [-86010], [-52554], [-100806], [109746], [-122726], [-145392], [142256], [159264], [-110514], [-686], [-138854], [-56706], [1280], [50832], [145928], [-7562], [-144696], [130340], [-9192], [161890], [83928], [1938], [71322], [-71840], [-102384], [146522], [-114786], [-138048], [-32186], [-110430], [-185866], [-145298], [84924], [-188120], [186810], [59222], [68312], [106846], [-137976], [85734], [-127618], [-26130], [11396], [51018], [56972], [2142], [-45358], [57342], [-80710], [119068], [31354], [166122], [-102816], [200720], [40062], [113976], [-170368], [48112], [50904], [146676], [49646], [-180074], [7254], [18412], [172262], [-114786], [-114420], [-51270], [-11346], [-85752], [78874], [-83550], [136536], [-118308], [-25058], [27322], [-24192], [-171128], [218486], [-111084], [-63250], [-97152], [201798], [167816], [89314], [-189870], [-18576], [99430], [42702], [226618], [105600], [-63702], [-75224], [-14034], [-29554], [-150456], [-102040], [52684], [-185492], [205884], [-209410], [-146148], [91020], [108106], [158640], [89566], [41564], [-96642], [-28852], [125922], [26588], [121710], [167056], [220890], [-243672], [183836], [-45254], [-43650], [-56054], [-208290], [-22682], [13350], [53856], [102332], [-8570], [-117192], [-96888], [75364], [-247086], [33024], [287202], [-183836], [-576], [-164682], [-48062], [-89220], [118056], [59418], [-127402], [-24684]]
