
# q-expansion of newform 7728.2.a.f, downloaded from the LMFDB on 23 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 = 7728
weight = 2
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], [-1], [0], [1], [-1], [-6], [0], [-7], [-1], [-10], [10], [6], [-5], [-4], [1], [-3], [3], [9], [4], [12], [-4], [2], [-2], [18], [-6], [-1], [19], [20], [-16], [6], [-7], [1], [17], [12], [-9], [5], [5], [1], [5], [6], [-20], [6], [-15], [-19], [-10], [5], [25], [-10], [-6], [-7], [-16], [4], [7], [-10], [15], [-9], [10], [-24], [11], [-22], [28], [12], [28], [15], [-23], [-6], [25], [22], [-30], [18], [14], [-24], [13], [6], [38], [-18], [6], [-6], [3], [26], [14], [20], [11], [11], [-20], [-24], [-26], [22], [-2], [5], [-18], [0], [28], [-2], [4], [12], [-1], [-30], [9], [7], [-16], [-10], [-12], [-1], [-8], [6], [13], [18], [30], [-8], [-20], [42], [34], [20], [-18], [-1], [3], [28], [-24], [32], [25], [33], [28], [-36], [20], [-3], [-38], [-48], [23], [6], [20], [-49], [24], [-20], [-27], [2], [52], [-5], [6], [34], [6], [-8], [-21], [-33], [-38], [-46], [-24], [-9], [-36], [54], [-29], [-2], [8], [-48], [4], [-24], [10], [54], [3], [-8], [-4], [41], [-4], [-54], [-35], [-6], [45], [-28], [2], [3], [15], [50], [-1], [36], [-10], [26], [31], [-54], [-19], [2], [55], [54], [-19], [-49], [-37], [6], [-59], [12], [-31], [-48], [26], [-24], [28], [-57], [31], [52], [50], [58], [44], [53], [-55], [28], [50], [-63], [-54], [41], [-56], [-30], [-64], [-50], [37], [21], [22], [30], [-32], [-6], [39], [62], [48], [18], [-17], [41], [-60], [-32], [57], [21], [46], [-24], [-40], [28], [-71], [-4], [-36], [-36], [-1], [0], [-49], [-66], [48], [0], [-35], [44], [4], [-49], [71], [75], [42], [66], [-10], [-15], [-28], [-32], [-7], [49], [66], [34], [-4], [27], [-75], [-22], [56], [63], [38], [-43], [45], [-47], [-39], [78], [-24], [32], [-16], [-18], [38], [6], [-56], [46], [72], [-33], [-36], [0], [33], [-80], [10], [58], [22], [-42], [-10], [-43], [76], [-50], [43], [-62], [-54], [72], [-78], [-52], [60], [-15], [51], [14], [-18], [50], [10], [24], [86], [-37], [52], [-33], [-37], [-6], [15], [2], [-75], [16], [59], [75], [-57], [-60], [7], [-32], [31], [-14], [-9], [39], [-15], [-17], [48], [-52], [15], [51], [10], [-72], [-44], [9], [-28], [-9], [2], [42], [-10], [-16], [66], [-85], [-35], [-58], [21], [66], [76], [-53], [82], [-2], [22], [43], [40], [-25], [50], [55], [82], [-14], [78], [42], [8], [-27], [-12], [5], [52], [-1], [-3], [-74], [-22], [88], [-92], [14], [-61], [31], [14], [4], [65], [-41], [-68], [4], [-80], [74], [3], [-84], [28], [-53], [35], [64], [68], [-72], [8], [-9], [10], [8], [-43], [70], [-95], [78], [-82], [-58], [-72], [96], [-58], [74], [-11], [-66], [8], [2], [56], [36], [-50], [-42], [-61], [48], [74], [78], [46], [100], [-20], [56], [34], [27], [-18], [12], [-20], [7], [21], [42], [-42], [-69], [-59], [19], [87], [-46], [-80], [-60], [-15], [25], [1]]
