
# q-expansion of newform 2166.4.a.f, downloaded from the LMFDB on 24 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 = 2166
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], [-3], [2], [-21], [-40], [-17], [36], [0], [74], [-100], [-103], [-187], [128], [121], [410], [-230], [744], [-277], [231], [-578], [609], [-1259], [-696], [612], [1550], [-418], [1701], [1690], [-42], [1828], [2124], [1206], [310], [1335], [-1116], [-1328], [-2537], [101], [-240], [1428], [2046], [-1510], [2290], [-627], [-748], [2171], [3177], [-4751], [4706], [-4807], [546], [3966], [5051], [4370], [670], [-7002], [-2484], [3736], [574], [9278], [5244], [666], [-2388], [9460], [10682], [4542], [-1313], [-6649], [-10706], [3799], [-10926], [204], [-9119], [13102], [-2841], [14024], [-9438], [8267], [-6664], [-2038], [8832], [9826], [8850], [-10643], [10387], [6652], [16976], [-6367], [-14008], [14161], [-12356], [-10094], [7580], [-19462], [14383], [1716], [-3954], [11356], [-14627], [-6355], [-8077], [-10346], [6126], [-1444], [20951], [8678], [-11700], [-6968], [10248], [1505], [-22187], [9682], [2844], [-27809], [-28477], [-10926], [-5465], [-25876], [-21594], [-6392], [-346], [-20603], [14342], [15530], [-24108], [-2854], [18033], [11878], [17323], [-5082], [1673], [-31172], [2941], [6061], [26004], [-20837], [-33162], [497], [-26466], [27090], [29376], [5916], [40784], [-5768], [30735], [19234], [-22293], [-29226], [-8315], [-45930], [-26815], [-37662], [14881], [14684], [51484], [38568], [-37591], [8138], [35543], [14696], [47286], [-20816], [-7839], [-38390], [41686], [-34692], [32375], [29131], [-25642], [-18480], [-15840], [37753], [28422], [16361], [-49035], [17598], [61361], [-45246], [-44947], [45899], [-41132], [-65128], [32075], [23858], [-21006], [-38970], [-43382], [52007], [-11642], [-8508], [28127], [-69676], [-17437], [10506], [20830], [-35472], [-1978], [73629], [-31480], [55050], [-32532], [17432], [27839], [8959], [-61834], [-37804], [36164], [-50412], [-16404], [51037], [89483], [49058], [66753], [34740], [62442], [49209], [46272], [41574], [22400], [59628], [-41253], [82159], [-8258], [-67021], [-47768], [-837], [51778], [22656], [75736], [-27180], [-27003], [22351], [35880], [104816], [55076], [-49404], [62409], [29576], [32600], [-15522], [-27946], [70696], [-8537], [88405], [15180], [-89040], [-21704], [85624], [36481], [-19800], [10009], [22370], [63416], [-28850], [55652], [22144], [-1047], [23305], [56880], [103555], [-57715], [-110364], [-44475], [-34155], [-88596], [79259], [-78768], [-17400], [45445], [74004], [-1899], [33368], [-134094], [-76960], [-64169], [-3093], [65634], [-122443], [82553], [-58386], [43962], [101752], [-38286], [11949], [67744], [12240], [-32595], [49842], [-16595], [59218], [-4014], [125610], [-89418], [-62342], [-15155], [77600], [29176], [-142084], [-59128], [2289], [-87866], [159598], [164881], [60250], [87963], [-70481], [106554], [123115], [4638], [-32209], [-4958], [173616], [106562], [-89919], [55134], [-100758], [140724], [-137494], [71225], [118120], [-7675], [-94509], [-31872], [101833], [132342], [7383], [105485], [103145], [87128], [-21340], [150709], [-125028], [139580], [139594], [-21012], [71438], [83649], [163914], [-29815], [101179], [2150], [109086], [40728], [74572], [-96236], [-38722], [185838], [76044], [-87806], [5682], [-141931], [-26921], [21032], [-88872], [147862], [8906], [31100], [-63474], [-212096], [-184548], [-150530], [-57850], [-149136], [39592], [-139636], [7510], [-79968], [114693], [-63679], [75246], [-180363], [-35128], [-64534], [-69019], [222221], [53710], [-90748], [213758], [176454], [98679], [-68250], [-66070], [-20096], [61326], [157239], [-116834], [201049], [-145322], [-70772], [-49342], [231475], [48646], [-245670], [130891], [12546], [20830], [8897], [36694], [-81319], [-89868], [-244931], [99934], [-130320], [125738], [-135750], [-196447], [-179075], [210454], [56420], [125540], [-57943], [32514], [199598], [-287983], [-251606], [-135480], [-144390], [-44204], [-305664], [192638], [93462], [128449], [274100], [4544], [-130123], [-232944], [-130724], [19966], [-72421], [-1114]]
