
# q-expansion of newform 525.4.d.m, 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, ZZ
    R = PolynomialRing(QQ, "x")
    f = R(poly_data)
    K = NumberField(f, "a")
    betas = [K([c/ZZ(den) for c in num]) for num, den in basis_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 = 525
weight = 4
poly_data = [16, 0, 9, 0, 1]

# The entries in the following list give a basis for the
# coefficient ring in terms of a root of the defining polynomial above.
# Each line consists of the coefficients of the numerator, and a denominator.
basis_data  = [[[1, 0, 0, 0], 1], [[0, 1, 0, 0], 1], [[0, 5, 0, 1], 4], [[5, 0, 1, 0], 1]]

hecke_ring_character_values = [[176, [1, 0, 0, 0]], [127, [-1, 0, 0, 0]], [451, [1, 0, 0, 0]]]
aps_data = [[0, 1, -1, 0], [0, 0, -3, 0], [0, 0, 0, 0], [0, 0, 7, 0], [-13, 0, 0, -5], [0, -17, 11, 0], [0, 27, 53, 0], [0, 0, 0, 56], [0, -24, 115, 0], [-11, 0, 0, 84], [-74, 0, 0, 13], [0, -19, -66, 0], [140, 0, 0, -45], [0, -58, 373, 0], [0, -88, -120, 0], [0, 89, 119, 0], [116, 0, 0, 209], [-248, 0, 0, 273], [0, -123, -640, 0], [427, 0, 0, -235], [0, -88, 90, 0], [265, 0, 0, -103], [0, 431, 821, 0], [28, 0, 0, -522], [0, 704, 266, 0], [-550, 0, 0, 666], [0, 21, -111, 0], [0, 310, -390, 0], [599, 0, 0, 597], [0, -601, 342, 0], [0, -109, -1918, 0], [-214, 0, 0, 246], [0, -394, -4, 0], [1266, 0, 0, -390], [-313, 0, 0, -874], [-43, 0, 0, 453], [0, -242, 834, 0], [0, -341, 427, 0], [0, 90, 2342, 0], [0, 44, 448, 0], [-2900, 0, 0, -370], [-2094, 0, 0, -364], [664, 0, 0, 237], [0, 429, -2566, 0], [0, -2224, -595, 0], [-3152, 0, 0, 1200], [-2520, 0, 0, 479], [0, -1757, 957, 0], [0, 1097, 2529, 0], [-3014, 0, 0, -152], [0, -2349, -236, 0], [-3512, 0, 0, -1232], [-4964, 0, 0, -406], [1146, 0, 0, -163], [0, 1403, -711, 0], [0, -1126, -4609, 0], [-5650, 0, 0, 1508], [260, 0, 0, 1424], [0, -1760, -1230, 0], [-681, 0, 0, -2267], [0, 1278, -2160, 0], [0, -868, 6360, 0], [0, -1232, 2114, 0], [-3406, 0, 0, 868], [0, 714, -5774, 0], [0, 2852, -759, 0], [1055, 0, 0, -3782], [0, 3121, 3263, 0], [0, 279, -9082, 0], [-5068, 0, 0, 4889], [0, 3740, -390, 0], [-4535, 0, 0, -94], [0, -4627, -2411, 0], [0, 3735, 6348, 0], [8065, 0, 0, -3808], [0, -924, 2956, 0], [-2219, 0, 0, -3883], [0, -3735, -1521, 0], [7643, 0, 0, -63], [2068, 0, 0, -4418], [8986, 0, 0, -2195], [-2417, 0, 0, -477], [14212, 0, 0, -1159], [0, -2594, 4238, 0], [-460, 0, 0, 4661], [0, -4428, -2576, 0], [175, 0, 0, 2097], [0, -1916, 1215, 0], [-9900, 0, 0, 328], [0, 6344, 4972, 0], [0, 157, -14521, 0], [8728, 0, 0, 2596], [0, -631, -18698, 0], [18727, 0, 0, 335], [-1808, 0, 0, 3395], [0, 7344, 3410, 0], [-4712, 0, 0, 1084], [-8150, 0, 0, 491], [0, 1420, -3292, 0], [-1025, 0, 0, 3781], [0, 1658, 12757, 0], [0, -4751, -8126, 0], [0, -8341, -5487, 0], [-8031, 0, 0, 2293], [16871, 0, 0, -336], [0, -2258, 5690, 0], [0, -3819, -21653, 0], [0, -1078, -8522, 0], [9279, 0, 0, -7952], [-17756, 0, 0, -3428], [0, 6864, 516, 0], [0, -3233, -5574, 0], [0, -10589, -3898, 0], [4444, 0, 0, 1374], [-5981, 0, 0, -3405], [10723, 0, 0, -2877], [0, 4598, 24682, 0], [0, -220, 8862, 0], [0, 336, -29034, 0], [17668, 0, 0, 3890], [-20900, 0, 0, -2402], [0, 3615, -7215, 0], [0, -4466, -6880, 0], [0, -107, -28170, 0], [-11092, 0, 0, 10942], [-8834, 0, 0, -8163], [-8142, 0, 0, -10198], [26960, 0, 0, -582], [0, -2403, 28047, 0], [0, -5415, -26415, 0], [-5497, 0, 0, -598], [0, -2847, 3077, 0], [-8800, 0, 0, 17936], [0, -115, 12222, 0], [9612, 0, 0, -1366], [-22312, 0, 0, 9084], [0, -730, -31728, 0], [0, 4484, 8318, 0], [0, 17692, 16002, 0], [-10397, 0, 0, 4009], [9342, 0, 0, 2688], [9730, 0, 0, 9572], [0, -8659, 20146, 0], [0, -15877, -8994, 0], [13626, 0, 0, 6503], [6658, 0, 0, -9162], [0, -3871, -8831, 0], [0, -4038, 2318, 0], [9750, 0, 0, -19166], [0, 13883, -6052, 0], [0, -12510, 5016, 0], [-6666, 0, 0, 12041], [0, -10858, 6615, 0], [0, 9234, -17642, 0], [0, -20719, 661, 0], [16005, 0, 0, -5310], [-10091, 0, 0, -3721], [24706, 0, 0, -4597], [0, -15338, 5234, 0], [24966, 0, 0, -13710], [0, -8776, -2132, 0], [0, 12093, -14036, 0], [0, -13936, 4608, 0], [40188, 0, 0, 3968], [0, -4785, 5962, 0], [0, -3150, -392, 0], [45003, 0, 0, -3575], [0, -8538, 31190, 0]]
