
# q-expansion of newform 1840.4.a.f, downloaded from the LMFDB on 26 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 = 1840
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 = [[0], [3], [5], [2], [16], [-47], [-24], [56], [23], [85], [-67], [104], [-53], [234], [-285], [2], [-80], [-764], [-236], [289], [-225], [-24], [-684], [-1370], [-110], [-2006], [-484], [1464], [-250], [114], [-1715], [1617], [-60], [859], [106], [-759], [2882], [-3135], [-1776], [1686], [1539], [2668], [-1434], [-3953], [-5237], [3124], [-5016], [-2912], [5054], [374], [-4571], [3185], [4986], [-3928], [2365], [6500], [-1983], [-5116], [-3165], [3366], [1342], [3288], [-4324], [-4867], [6252], [-3222], [2743], [-6302], [7524], [1361], [-4637], [-5712], [-9776], [5210], [14184], [-3686], [-7136], [-3455], [-5050], [-6395], [-6798], [-13430], [-5530], [10742], [14479], [4271], [17814], [10324], [-12059], [-4244], [11670], [-5400], [-4463], [6519], [-12391], [-7698], [933], [18876], [-1034], [8161], [-7539], [-6106], [-5296], [16350], [-15284], [6479], [-5753], [25298], [-17352], [16365], [14128], [8392], [8632], [22716], [-15718], [-28846], [-1978], [5399], [-22323], [33504], [-22466], [10837], [-20862], [-15923], [18560], [-11046], [-1818], [22276], [31934], [34112], [5767], [29204], [-26966], [16384], [-5475], [28058], [-7594], [31792], [-3316], [-6630], [-32019], [-16598], [-11633], [3044], [10542], [22410], [25942], [-7607], [33473], [23169], [-2822], [52060], [22028], [6359], [1960], [24388], [7426], [21387], [14036], [-9804], [50047], [-42046], [40789], [33006], [26400], [23406], [19360], [-21934], [14080], [-43011], [-53084], [13781], [-33600], [16048], [58899], [9662], [15399], [-44133], [35572], [-32728], [-45047], [7274], [-65417], [35278], [57702], [-70352], [16874], [44932], [39337], [47240], [38577], [25768], [-54166], [-5766], [-4290], [44426], [-71072], [-47480], [16540], [11493], [71668], [-5344], [-9793], [53060], [-76256], [-22501], [-49020], [-88681], [-44193], [56939], [69301], [-51501], [40994], [-62046], [-58580], [1230], [9071], [-28043], [-2886], [36557], [-82877], [-44184], [-92111], [-92982], [102171], [-24185], [5860], [-17301], [92898], [-180], [-30102], [-39958], [-53206], [-35806], [-98148], [-66534], [-53308], [-72312], [44937], [-92733], [-100312], [-89435], [-7517], [9511], [-65486], [-44275], [-56169], [-110946], [-23774], [-92942], [92796], [-51950], [104106], [42222], [15526], [69039], [41848], [107818], [78303], [-30001], [126924], [-21786], [67222], [1842], [20666], [45552], [-60696], [81690], [60920], [-83025], [91189], [18154], [-28410], [89126], [-49069], [125659], [-116], [-89962], [-38638], [-42872], [69013], [114994], [-16764], [-38134], [-74296], [-153888], [97914], [-146064], [-116068], [43098], [-12574], [-32388], [8010], [-126332], [127883], [12406], [-37248], [100173], [113031], [65805], [-74986], [-78984], [-42516], [-76551], [-64188], [132581], [19812], [161784], [34142], [-127918], [-75357], [32316], [-149552], [26753], [-119128], [76498], [58387], [-21567], [147684], [-35169], [76610], [110506], [-160309], [-9464], [86690], [182880], [-79158], [-15311], [2600], [142332], [-194487], [-151563], [72295], [25821], [66632], [-23739], [99938], [-24306], [44767], [-109918], [-15243], [6726], [-179238], [-47190], [-118290], [3524], [-153825], [135472], [-75610], [13914], [218281], [-132893], [202406], [-57482], [152504], [181230], [73296], [-119274], [79911], [-54736], [232206], [-111183], [48437], [-80886], [-75179], [57791], [-187855], [111472], [112226], [33203], [52076], [99983], [33360], [-224704], [183293], [40763], [-29604], [-194542], [-213852], [-249127], [119694], [68028], [193048], [10337], [-123466], [-106183], [222435], [-43486], [235618], [2232], [82648], [166402], [-128699], [116596], [184422], [-100338], [-139446], [12930], [-111284], [-23854], [-246881], [-223045], [-79154], [-86744], [226575], [198477], [23216], [-63151], [110730], [241068], [118349], [154797], [-213076], [125418], [-25744], [102417], [30448], [213416], [-168410], [65710], [49302], [-104846], [-126992], [-46228], [21019], [140609], [216732], [113742], [205565], [94861]]
