
# q-expansion of newform 315.4.a.f, downloaded from the LMFDB on 16 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 = 315
weight = 4
poly_data = [-2, 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 = [[-4, 1], [0, 0], [5, 0], [-7, 0], [7, -32], [25, -4], [25, 44], [18, -44], [-122, -68], [13, 24], [-60, 180], [282, 60], [164, 124], [-130, -68], [175, -132], [28, 128], [616, 0], [168, 108], [-76, 64], [952, 0], [338, 344], [507, -248], [188, 600], [108, 44], [1371, -220], [338, -68], [-667, -716], [-862, -456], [241, -1056], [242, -1140], [1304, -64], [110, 1324], [-644, -1108], [166, 256], [-226, 392], [-645, 1184], [774, -176], [-174, 832], [795, -308], [-403, -2044], [-2300, -480], [2028, -400], [1099, -512], [-404, 804], [696, 988], [3080, -152], [4863, 552], [-2811, -2516], [-325, 948], [-1260, 3796], [-88, -368], [-263, 3760], [-3146, 2228], [118, 304], [4818, -2152], [-2014, 2272], [-2266, -696], [1904, -1980], [4286, -3304], [1853, 1048], [-205, 3972], [-3863, 2532], [579, 948], [-4466, 2300], [3561, -3532], [642, -5048], [-7308, -1680], [-3546, 2528], [-846, 6148], [-4494, -4084], [-4299, 1060], [448, 1920], [-2095, 3732], [1916, -3204], [-2460, 1264], [2756, -2776], [3747, -1856], [1131, -2204], [6503, -1648], [-6010, -4024], [5028, -5488], [3401, 7176], [5807, 440], [1890, 4336], [-5502, -48], [8490, -2124], [12041, -3400], [6224, -6452], [-10056, 2816], [-13792, -3628], [-119, 4876], [-10266, 5564], [11062, -3872], [-379, -112], [3269, -1888], [3589, -5668], [-7930, -6928], [-7390, -900], [-12228, 3152], [15475, 4360], [9192, -1204], [-8712, -11728], [-18716, 2160], [11182, -848], [-8676, -2056], [2069, -1884], [12096, 2584], [-9261, 6844], [-1329, 15080], [-15970, -16], [-5917, 14196], [-1982, -1872], [2382, 14696], [610, 8316], [9681, 3040], [17758, -1200], [-9599, 3604], [-8360, -14888], [-314, -8980], [-10701, -9032], [-4096, -3656], [564, -18124], [13319, 6428], [-9384, 12828], [-12428, 14776], [8633, -17416], [16803, 2192], [9574, 1060], [13992, 12488], [989, 11292], [-2543, -6416], [-20940, 3544], [5739, 14024], [1824, 3096], [13490, 11108], [-314, 15664], [7935, 12452], [-29083, -5756], [8429, 22596], [10079, -5744], [-18406, -11240], [-2117, 11160], [-3740, -12572], [-25174, -7104], [26676, 3316], [15282, 9196], [11374, -1392], [4638, 16496], [12300, -4256], [-16688, 15164], [-24974, -3724], [-15392, -20848], [4004, 628], [-20248, 13072], [21466, 1572], [-10368, 17144], [20079, -4064], [-18060, 984], [32427, -1444], [-6480, 5428], [18152, -14100], [-6808, -1252], [-21982, -23672], [-22200, 108], [-14374, -20], [-21139, 9420], [-5344, 21104], [-50713, 12], [-4355, -28952], [-6050, -13320], [41240, -5728], [12650, 20968], [-10069, -15992], [-2070, 19032], [-9534, -14596], [-38804, -144], [-18331, 14936], [-33781, 16800], [28076, -5592], [22712, 17236], [-29532, -25188], [500, 4708], [670, -6212], [-19462, -6944], [39332, -2804], [30102, 15564], [-5864, 4488], [-3143, 21508], [21249, -14832], [-25152, 14652], [61970, 10032], [35418, 24220], [45531, 8840], [66472, -4676], [-17268, 6008], [-40221, 3276], [16599, -8376], [-7324, 15076], [-2919, -21540], [-25445, -28628], [-15062, 4144], [-23590, -23600], [34522, 15848], [77402, 1580], [17418, 1756], [-29287, -25332], [12170, 15552], [-35108, 9724], [-42630, -23856], [-54896, 8484], [-41916, -2644], [-1442, -22656], [11516, -33476], [14435, 48484], [17758, -21400], [-41244, -700], [-44222, -10220], [31628, -47516], [-11922, -9140], [-18910, -29056], [-15870, 53800], [44138, 3888], [-9973, -42920], [2506, 18264], [-23181, 8020], [26910, 4568], [18037, 22788], [70911, 1288], [19469, -26220], [31852, -13784], [48388, -10580], [-8986, -15736], [-14032, -4888], [10799, 19336], [-75771, -15972], [17435, 19972], [-5032, -23692], [17312, 8408], [17509, 39096], [-34562, 31300], [-46104, -10576], [43624, -24024], [-17127, 12620], [-14226, -31568], [-41773, -7556], [15770, -33732], [11944, -4568], [-4850, 79032], [32639, -56336], [-8790, -22452], [-32062, 1196], [81886, 17528], [4140, -22664], [-80680, 11208], [-16318, 8408], [-8549, 70944], [66654, 13576], [-34980, 21744], [-64977, -7356], [-84475, 17932], [88910, -24292], [81230, -31656], [47844, 43224], [-32387, 63668], [-61298, 1976], [98298, -14412], [-38365, 15072], [48414, 46688], [-58684, -16816], [77550, -4660], [49072, -65644], [-1372, 7564], [-105541, 4252], [16596, 45696], [-58298, -53752], [-73383, 17420], [-72524, -31344], [874, 61472], [-83607, 19200], [-72594, 10328], [127731, 12716], [-72013, 7736], [7888, 80976], [81942, 31576], [41501, 76108], [-40169, -16776], [-26970, 49876], [44342, -5636], [59900, 45120], [-42052, -14192], [32363, 21736], [-51927, 1644], [-38688, -68548], [-95628, -11180], [84122, 28732], [66216, -63468], [-5102, -43240], [-39409, -38572], [-36108, -30136], [-87415, 43396], [-1201, 49628], [-26534, 68352], [-78531, 7320], [77392, -1360], [1883, 20224], [-79062, 30588], [19250, -40004], [-16192, -43728], [18408, 64744], [-25544, 26552], [82136, 9000], [-53111, -26768], [-45038, -94400], [75902, 47600], [61938, 57044], [-34876, -76372], [66190, 27520], [105879, -3488], [-12529, -72924], [-95741, -34112], [-126402, 27864], [8600, -72820], [-20026, 19896], [6076, 73316], [-41230, 17888], [-16948, 59128], [50251, -17064], [-42044, 112584], [-30192, 15492], [-64148, 79116], [-49826, -9392], [21732, 21460], [44230, -53352], [22325, -6276], [-71388, -58440], [101615, 10844], [-15183, 19464], [-106786, -64512], [-76698, 5220], [104553, 26892], [69474, -97440], [43416, -3824], [-73514, 32844], [65853, -32552], [-19046, -67340], [-83252, -35280], [92486, -25592], [45564, -42092], [-9482, -124908], [126109, 13932], [46648, -114480], [-9264, -133108], [19195, 256], [5601, -85988], [-18619, -121096], [36418, 23784], [109642, 49656], [58578, -76836], [-177594, -3916], [10694, 6624], [74688, 90036], [142008, -65392], [31448, -18844], [13859, -75696], [51092, -18496], [-160062, -12628], [-8763, -107220], [-124126, 12716], [-96419, -93488], [-7197, 127040], [6928, -14492], [9928, -48944], [-101591, 46976], [806, 48352], [4306, 38912], [43432, -71368], [-112725, 11232], [39893, 131308], [-59750, 48432], [-60583, -56516], [7810, 57592], [2858, -26312], [53844, -44176], [-81414, -91304], [-44320, 24404], [-133125, -75420], [61769, -68656], [117897, -64252], [-28828, 110040], [25297, -54428], [-63511, 129040], [25977, 19036], [-162631, -30280], [157412, -84112], [136783, -59664], [66952, -10072], [104532, -53964], [-38240, 83516], [52705, -114448], [57302, -14480], [157948, 66572], [20204, 187680], [204306, -28972], [-180531, 31916], [-52188, -92144], [-106518, 99776], [106162, -72368], [154033, -29456], [-107444, -22224], [-158796, -43248], [41323, -29716], [36578, 145064], [82386, -123996], [-16204, 125984], [-73826, -25644], [102456, -56416], [51679, 2544], [36500, 63752], [-34522, 76104], [144963, 50252], [-77841, 76472], [-4706, 174656], [26694, 9264], [79884, 30664], [154745, -59028], [-115491, -45436], [-170704, 69688], [91446, -135912], [-47480, 80388], [-110672, -108796]]
