
# q-expansion of newform 57.6.a.f, downloaded from the LMFDB on 23 December 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 = 57
weight = 6
poly_data = [1412, 118, -90, -1, 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], [[-10, -58, 1, 1], 6], [[-286, -52, 7, 1], 6]]

hecke_ring_character_values = None
aps_data = [[0, 1, 0, 0], [-9, 0, 0, 0], [-3, -2, 2, -3], [-29, -16, 0, 5], [-183, -8, -16, -13], [2, -2, -6, 40], [-945, 64, 0, -13], [-361, 0, 0, 0], [156, 334, -14, 48], [174, 184, -224, -56], [-1734, -586, -198, -70], [4656, 510, 226, 10], [-1824, 244, 332, -630], [-4681, 356, 284, 133], [-8577, 126, -198, 621], [-5046, -112, 768, -20], [-18648, -312, 112, 1020], [2399, 2220, -644, 127], [-27400, 716, 1100, 580], [-16380, -5576, -2336, 44], [-35195, -344, 976, -1147], [-15440, 570, 4030, -860], [-48084, -1312, -1632, -1024], [41370, -10016, 1376, -1728], [10598, 964, -988, -2052], [24642, -3814, 2838, 2832], [-56258, 1498, 4662, -1082], [-810, 15592, 2888, -4938], [86212, -14758, 2494, 2478], [40050, 5196, -7540, 3912], [38734, -5450, -4238, 3710], [69903, 10924, 1564, -467], [97863, 31024, 4144, -5005], [-9973, -12756, 13252, -4391], [175323, -16686, -9474, 1431], [-37056, 31218, 3830, -1252], [30846, 44580, -10852, 2312], [-152064, -19448, -11128, 15636], [-48918, 8172, 3820, -20370], [-256506, 1428, 3164, 2816], [215406, -42176, -14856, 2518], [466882, -29942, 966, 8608], [-423951, 6330, -11154, 5187], [405940, -40500, -1956, 2862], [-261186, -3274, -18758, 28604], [-195549, -44200, 24904, -25083], [318588, -3592, -31440, -5560], [91068, -102122, 4410, -19736], [-121806, 149824, -13640, 4034], [267145, -113276, 24068, -7731], [18009, -3916, -9732, -26551], [61557, 31742, 31226, 1015], [-901324, 20052, -8116, 25094], [-1073457, -23996, -15484, 8645], [-194952, 126456, 35400, -646], [327039, 11678, -69350, 32197], [-481038, -118548, -5900, -23196], [-164100, 125564, 64244, 1804], [734965, -167196, -4668, 17169], [-432726, -25116, 37068, -54880], [-205717, -61612, -21924, 21305], [481668, 556, 51508, 53034], [-851388, -72732, -6348, -60264], [-1630221, -11762, 39098, -49359], [-803042, 83196, -55564, 59852], [-143412, 101420, -48116, -83486], [-402388, 252804, 20324, -59800], [1913986, 315024, 35192, -17848], [464415, -41704, 10816, -136979], [-1015431, -58056, -32080, 20333], [1539198, -43480, -57640, 56052], [775917, -320326, 46606, -28177], [-1912664, -10780, -83156, 35328], [515584, -40450, -62126, -77286], [192850, -416260, 18228, 10058], [-841074, -97008, -20480, 22754], [92901, -134058, 80058, 116949], [133849, -310976, 83784, -114467], [-2094636, -63916, -45500, 58182], [1776082, -256268, 5788, -154288], [-353028, 259524, -39492, -49480], [2530922, 123550, 50818, 49328], [1234878, -95004, -29452, 146850], [255030, -55532, -1308, 147052], [-1326166, 635622, -51806, 107434], [1363347, 392424, 123616, 90921], [-2781348, -30120, 98584, -11930], [-154973, -521676, -211628, 12055], [-252021, -348518, 39094, 164303], [-3057703, 199776, 44496, -179241], [2036595, -84548, -69156, -145767], [2659440, 46790, 96090, 134820], [-616432, -310606, 21590, -26084], [4033824, -201544, -117528, -153868], [3449165, 491796, 1708, -94073], [-949296, -726462, -223970, 73572], [2291382, -304436, -340692, -1880], [-2073036, 85936, -204024, 198526], [-2045554, -159716, 21028, 184670], [-1462077, 179352, -170624, -142493], [-2052986, 182204, -65716, -149882], [-6031785, 141242, 134502, 137971], [5937012, 586184, 36616, -56064], [-1355202, 1148384, 113096, -367724], [699072, -1279352, 149096, 141348], [-1433973, 661628, -79348, 456631], [-2308305, 146336, 152168, 206733], [-8159910, 59048, -104632, 145048], [2037264, -265660, -410572, 220600], [-2685264, -167208, -227152, 96098], [-3862966, -1078822, -147602, 149898], [-1755423, -164752, -157576, -25475], [1859643, 680500, 447516, 88711], [3428548, -1801264, 280912, 101280], [-7048185, 723212, -135836, 109881], [-657630, 276600, 135152, 172136], [3951191, -417428, 47908, -266203], [5350497, -313542, -27426, 226203], [1283235, 961906, 479022, 140599], [5932290, -1858168, 164296, 136154], [-6003972, 993310, 55042, 274670], [-741672, -997444, -710820, 489626], [2851794, 1067048, -728656, 69324], [6864858, 823264, -202664, -177886], [-350503, 1202716, 486868, -710053], [-16719702, 163746, -316738, -243456], [10806150, 287536, -331552, 367632], [-8565975, 127582, 820202, -468285], [-438047, 2149148, 155188, -254385], [-4281950, -2024540, -850436, 10292], [-2109725, -657444, 364372, -456119], [836232, 674260, -404428, 634736], [-4551576, -519190, -631322, 189444], [-8172257, -740776, -42656, 376575], [-1106817, -53928, 480920, 684731], [9756155, 4824, -344704, -281833], [945924, -1553012, 518364, -710254], [-4138520, 585456, 257312, -236428], [-1715484, 3320940, -217748, 490026], [4675113, -423408, -936416, 907841], [8837914, 637412, -776348, 249306], [4656963, 749166, 643506, -133977], [-3213341, -1426820, 411316, -132979], [2109564, -902264, 700608, -91520], [-1746812, 797018, 468886, -1134618], [-13149210, 690412, -237068, 1126970], [3978562, 374048, 1027568, -164636], [-10361400, 1982528, 256488, -807254], [771699, 1408572, -406076, 905209], [-11108652, -681948, -176340, -575260], [17806122, -861922, 403554, -1098952], [20240475, -1028084, -355436, -630273], [-1784437, -2536028, 1030956, 115081], [11336196, 2165948, -320036, -146940], [-13770314, -744868, -269116, -111194], [11618154, -708708, 20612, 531806], [7651352, -2276680, 226088, -92816], [-31372002, 113812, -340884, 386988], [-2447979, 2286176, -270456, 557957], [-17417238, 2185412, 10396, -642756], [22272516, 2462752, -614384, 570168], [-746448, -3757036, 370868, -209262], [-29721776, -3055884, -673428, 89184], [-15723444, -2627624, -282872, 342104], [-8603562, -229188, -1339788, 952380], [-14807340, 2250744, 520712, -1190444], [16920704, 954262, 601946, 497220], [-5583407, 2363560, 963696, -470339]]
