
# q-expansion of newform 147.6.a.f, downloaded from the LMFDB on 19 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 = 147
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 = [[5], [-9], [-94], [0], [52], [770], [2022], [-1732], [-576], [5518], [-6336], [-7338], [3262], [5420], [-864], [4182], [11220], [45602], [1396], [18720], [-46362], [97424], [81228], [3182], [-4914], [166354], [-157160], [-6764], [178398], [-45134], [-205056], [-72964], [-94182], [47796], [-124266], [-446296], [159746], [247252], [684488], [610474], [662252], [-154630], [486904], [620546], [-236570], [-82104], [99892], [186704], [-336372], [926314], [1257114], [-347016], [-99170], [-344428], [-295130], [-1272464], [-276774], [1289936], [1716550], [-1472182], [-1028812], [1186066], [-1518916], [-212808], [1894], [-1578978], [-3394708], [2027314], [3488852], [-965566], [-1153930], [1611104], [-3677472], [649766], [320700], [2361888], [-3533898], [-4048110], [2076450], [-2574314], [-848148], [1436822], [2354376], [3788078], [3643224], [2483892], [-2631774], [-1161302], [-2813846], [6842992], [-3343140], [4282480], [-8931752], [2753060], [4804084], [6024648], [8429866], [-9250578], [-5844940], [9225326], [-6443372], [3742126], [14638364], [14180458], [-1251604], [-5943778], [6461924], [2346054], [-13495920], [-3878490], [533488], [5146102], [-2378598], [-16002316], [12345944], [-3437550], [16219084], [-11992856], [1580094], [6983580], [-3696022], [1846882], [7685010], [7121796], [3237868], [-7391634], [-5333610], [11456400], [24953992], [14339826], [922932], [-9389952], [-408032], [25960454], [-18355410], [747166], [-20269166], [4699820], [-584710], [-16401270], [304948], [34342838], [15668376], [-29688636], [23070802], [-23264248], [-19151510], [5346830], [-39585836], [-25028376], [-5025890], [26049030], [-6824620], [-23383496], [39595916], [-4675704], [-4925944], [32368774], [33233718], [26642650], [31466300], [-13451590], [-28496312], [-18185772], [32094114], [-15615384], [48449936], [45433562], [27942322], [22964386], [-56749116], [16277730], [-16590240], [54820874], [14327200], [47349022], [-61224980], [-20059946], [45433752], [48632882], [73161632], [-595812], [20690294], [4219534], [-14686536], [-71002142], [-78847346], [-28774852], [-9723926], [43221632], [-10921522], [13709460], [-51536620], [-5115750], [-14039540], [83906766], [16504946], [-67741746], [-89342778], [-84698232], [55297742], [-104890016], [-81895110], [-98525554], [-43325324], [73931962], [-55327632], [69484140], [-75952182], [67789028], [67691538], [49409010], [-26260568], [-3352828], [-105784568], [23146358], [-78353440], [103746950], [-61017728], [-87769554], [-21715402], [-70593208], [-113379646], [113958752], [-96150740], [1464710], [-19097746], [64260584], [116110264], [102073956], [21915358], [-113415268], [-123568240], [-87146966], [-8072316], [65382288], [-13681762], [-80708938], [148757940], [82240984], [59339724], [-165847356], [84213576], [109099198], [46816182], [-146636584], [25035584], [-101745428], [68764], [181562712], [-47022610], [-123563562], [-85654496], [86753702], [-117695446], [89179676], [77995718], [102047028], [71165682], [-143574938], [-19304800], [-124950628], [138778954], [133983682], [-72769418], [58924156], [-127326162], [96444446], [56454316], [292918], [18261170], [12908948], [68738774], [209197616], [57274238], [-108044408], [101707492], [-7482066], [6469930], [86004412], [11928832], [-238567704], [-29165528], [6740090], [-139803212], [79793544], [34497298], [252171222], [244940968], [-238780794], [117687790], [109876556], [162885546], [215178852], [246781726], [-10296070], [258430064], [-215158286], [35371060], [-7670180], [-139650570], [-310024962], [-170154800], [-208434308], [-259443732], [-122312958], [-319681884], [197703618], [34712368], [-329829866], [291424368], [186498854], [-352112238], [56473476], [-11572720], [98238790], [5949804], [105628008], [47499662], [-28947966], [-63345668], [197054842], [-366704646], [43847120], [-285246966], [45542270], [200754580], [-59785484], [-145393768], [-98780106], [-258658850], [284942766], [357475552], [5737836], [47339260], [-39210892], [-23479090], [172274694], [-257474714], [225813872], [306389926], [-446806582], [162030498], [-225473288], [-272491858], [3104236], [340255082], [-500712116], [31237584], [181558402], [-397108372], [68987754], [161377582], [-253450464], [-56846330], [-253190882], [409561632], [-292466028], [37741394], [472286544], [419981046], [208942430], [-485735352], [236894852], [-258780068], [48516298], [207739546], [-247341560], [-331913286], [-317148612], [-371001564], [-69516792], [117288054], [-64297976], [63930382], [-146129908], [252015304], [136308094], [-644736186], [331918902], [171154234], [335738538], [320900008], [32422274], [-266441700], [-507816296], [484798016], [69143738], [-419376820], [-416134320], [179734690], [532998498], [615980340], [114827836], [-505581232], [-468483110], [87762800], [-563346], [-178129572], [-326846202], [-348578366], [317897186], [73082896], [-370356402], [449860578], [-709090840], [448542846], [-771276238], [-71188244], [538299276], [93454], [-105168058], [-409778668], [251140132], [-599939478], [-420339174], [833880360], [237879928], [-680356026], [-280393704], [721978638], [329637242], [-154174648], [-359289308], [771383158], [510198954], [-243807188], [-505199574], [-693230364], [131655768]]
