
# q-expansion of newform 72.6.a.f, downloaded from the LMFDB on 14 May 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 = 72
weight = 6
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], [0], [74], [-24], [-124], [478], [1198], [3044], [-184], [3282], [-5728], [10326], [8886], [-9188], [-23664], [-11686], [-16876], [-18482], [-15532], [31960], [-4886], [44560], [-67364], [-71994], [48866], [-51606], [180424], [65700], [-112706], [23502], [-94592], [-70292], [-277290], [-130308], [401530], [-75976], [-394322], [-11724], [551928], [-432894], [-559620], [604710], [409152], [540866], [629898], [283048], [142756], [889696], [-1143156], [-695786], [347126], [1642960], [-1167438], [790612], [129790], [-70888], [-1790174], [-1773616], [-275450], [-594170], [1092428], [-333654], [1059972], [1336488], [1644186], [1723698], [2749628], [-3414894], [-730764], [-2297490], [1170718], [-3886536], [933040], [-392218], [-4729300], [-1897344], [3722954], [3338078], [-4274898], [-2573190], [-5268276], [-973354], [-3557360], [-1954958], [-3296808], [5058196], [-2127298], [289130], [-2668702], [7586192], [1419612], [1884064], [-6013880], [-4292316], [1345092], [-202008], [-9783438], [10483030], [6210172], [5080878], [3346868], [-7003774], [12981884], [-1899418], [-1662996], [8773442], [-5183932], [-8498578], [-11247096], [-3464390], [-999712], [9813398], [5347446], [-6827684], [-3609704], [13385342], [-9911148], [17835928], [4323234], [-19785828], [15777158], [6787618], [14994218], [-11558044], [-220156], [-4789326], [4268918], [16195952], [6534264], [13161710], [-14234764], [21583544], [18659376], [-2566810], [25958566], [5532674], [-8329398], [-13652252], [8546258], [-7584842], [6184732], [2781018], [16389464], [-22951148], [-3501362], [-5296680], [-20294842], [4827846], [-13021044], [39238688], [13462206], [917710], [24548804], [16146280], [-20336132], [-10772560], [41856568], [-29984546], [14240202], [41454594], [15407868], [20632806], [11872424], [-1532220], [-17432082], [-2232696], [22250080], [53266198]]
