
# q-expansion of newform 256.4.a.f, downloaded from the LMFDB on 13 June 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 = 256
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], [8], [-12], [-32], [-8], [20], [-98], [-88], [32], [-172], [256], [-92], [102], [-296], [320], [-76], [408], [-636], [552], [-416], [138], [64], [392], [-582], [238], [-1468], [992], [-584], [740], [-302], [1664], [-2328], [1734], [3032], [-1788], [-480], [-2300], [-1592], [-2208], [-3948], [-2104], [1412], [-3712], [1614], [-684], [4064], [2120], [-2816], [3848], [-652], [3050], [6336], [-4610], [792], [-5374], [-3488], [-4764], [-1344], [8596], [2874], [-2888], [-6540], [-10584], [-6368], [8758], [-716], [4408], [1202], [-5160], [-4876], [4834], [-4128], [4416], [4180], [-13736], [-512], [1732], [10436], [-12130], [5014], [-8024], [-2348], [1728], [62], [14112], [-4488], [-2482], [5894], [-7068], [-7616], [-13080], [13568], [-1696], [3096], [19208], [-16224], [-11292], [-5178], [-6856], [13732], [-10968], [-25612], [9768], [22838], [9208], [-10878], [18040], [26994], [18336], [-9286], [17536], [-5868], [-19286], [5240], [15520], [654], [8232], [24672], [22052], [-12024], [-19100], [9902], [19684], [19864], [-3256], [-2876], [7300], [2880], [-8800], [21076], [19336], [13664], [-19520], [20004], [31478], [7054], [9604], [3144], [22084], [14950], [-23432], [1044], [18208], [-12488], [-30172], [-32544], [-26156], [18646], [-5800], [25088], [-3004], [43282], [27880], [-7392], [29080], [-26688], [-19680], [-48466], [13610], [30692], [-4824], [-22986], [-17184], [-2920], [-27042], [44192], [-29824], [-11612], [22014], [-16572], [-20744], [-58476], [-40608], [-19958], [-44096], [20794], [25880], [45380], [3680], [21844], [-27392], [23048], [5364], [-16182], [27072], [-61244], [1860], [-16952], [-6106], [-58368], [-41662], [32600], [32744], [660], [-12216], [27498], [4754], [49892], [-12990], [-77728], [11028], [-12992], [7028], [7842], [-71496], [27156], [6656], [67528], [-37430], [-52360], [-60514], [18084], [-46944], [3576], [-59808], [-69786], [-67904], [30558], [53664], [31828], [-70988], [-15456], [-15218], [97600], [-60632], [11252], [45690], [39040], [63200], [-91048], [64516], [75880], [70912], [44874], [-29672], [48704], [-39970], [104228], [-88136], [43104], [101512], [87480], [-62112], [68276], [85490], [-96], [-41728], [-102936], [-20200], [22208], [38676], [52354], [79200], [75402], [47748], [-60728], [-62460], [3992], [-118812], [-67594], [-80896], [-83064], [48612], [-98828], [-68562], [-39128], [-98652], [-104358], [-104936], [-12572], [63956], [39272], [86650], [128640], [-136558], [-7776], [11448], [1636], [31690], [-136152], [-89088], [-36896], [1440], [70068], [39384], [52672], [119006], [-54636], [-2016], [-21534], [-17020], [10664], [44954], [-15624], [108708], [55204], [-156928], [-132444], [39480], [106472], [51334], [-132012], [33728], [123528], [48824], [-22546], [121592], [-97900], [159264], [-106492], [-38208], [-4060], [-164562], [64744], [-166304], [-122198], [-25080], [-156160], [-142142], [-60046], [-15864], [-137770], [-64908], [40064], [38054], [-141058], [77064], [49272], [183808], [-20364], [7668], [-96780], [-77824], [-78680], [-34920], [-135144], [-97004], [40290], [-200662], [68416], [-5692], [-139530], [-220988], [-76448], [60516], [-55992], [29076], [-149000], [64192], [150308], [84680], [95494], [148052], [-73920], [130884], [99834], [-11648], [25560], [80510], [176928], [58660], [6986], [27840], [-139176], [-231416], [57706], [40116], [84832], [146518], [-83928], [9208], [-38336], [-103020], [-164960], [-166156], [13640], [-257280], [4450], [-54850], [-176970], [-236620], [-119162], [41504], [-110046], [129416], [105696], [127296], [31732], [-76136], [119040], [214594], [178052], [203448], [-130936], [-23136], [168342], [-59776], [71782], [179864], [186068], [-118124], [52302], [58688], [-222762], [-25004], [138208], [-98572], [-217730], [-89208], [272872], [-5390], [-57228], [139288], [225672], [204266], [-4492], [52992], [290912], [-95394], [164768], [92836], [-56380], [-228032], [300760], [17222], [-171468], [-18584], [-160134], [-222536], [26912]]
