
// Make newform 8624.2.a.d in Magma, downloaded from the LMFDB on 08 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8624_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_8624_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_8624_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_8624_a();"
function MakeCharacter_8624_a()
    N := 8624;
    order := 1;
    char_gens := [5391, 6469, 7745, 3137];
    v := [1, 1, 1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_8624_a_Hecke( : Kf := Kf)
    return MakeCharacter_8624_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..prec]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[0], [-3], [4], [0], [1], [1], [-2], [6], [2], [1], [4], [-2], [2], [-4], [2], [-12], [9], [5], [9], [-4], [2], [15], [-6], [-6], [5], [15], [12], [-8], [10], [17], [-5], [-18], [-9], [8], [-10], [-9], [-4], [-13], [-17], [5], [-13], [22], [-14], [-22], [-3], [10], [14], [-26], [10], [16], [6], [-19], [-30], [12], [21], [-3], [-12], [25], [-3], [-10], [-6], [6], [32], [-28], [-1], [-12], [-7], [-30], [28], [-2], [18], [31], [-14], [-7], [29], [8], [0], [30], [15], [32], [-20], [-20], [-1], [10], [-5], [12], [30], [2], [3], [14], [-12], [-37], [4], [-18], [16], [-21], [-2], [26], [20], [-25], [0], [38], [26], [36], [20], [7], [-3], [0], [24], [-26], [-16], [22], [-27], [20], [0], [9], [1], [24], [22], [32], [10], [16], [-38], [33], [15], [39], [6], [-26], [-34], [1], [-18], [-36], [44], [26], [-54], [38], [24], [-22], [-38], [-48], [-28], [-15], [-38], [22], [-16], [54], [-50], [4], [-17], [-10], [25], [-9], [-1], [-17], [-44], [54], [24], [33], [12], [-55], [16], [56], [-56], [-13], [14], [18], [20], [42], [-20], [46], [-6], [10], [23], [10], [-10], [-49], [-44], [38], [-24], [14], [-36], [-10], [64], [-4], [-4], [18], [13], [21], [-52], [31], [14], [-4], [25], [8], [32], [57], [8], [50], [-30], [-57], [1], [-41], [32], [70], [21], [0], [32], [30], [0], [11], [-22], [14], [16], [20], [3], [-25], [-5], [36], [-36], [-10], [57], [13], [-33], [38], [-66], [-71], [-1], [0], [37], [10], [-64], [26], [29], [30], [9], [39], [30], [21], [-21], [-16], [-24], [-32], [-36], [-46], [-66], [-48], [-26], [-35], [-18], [-45], [-75], [-20], [-22], [26], [-47], [6], [14], [4], [46], [40], [8], [20], [-42], [31], [-45], [15], [-24], [-49], [-10], [2], [-10], [44], [51], [28], [-28], [20], [-63], [-73], [82], [6], [-69], [58], [-15], [23], [46], [54], [-53], [-14], [-30], [-12], [-42], [-43], [24], [62], [1], [-17], [18], [-4], [-10], [42], [-56], [-23], [1], [-69], [67], [-19], [-73], [32], [-66], [54], [-27], [-10], [8], [-84], [-9], [-84], [43], [12], [30], [-60], [20], [23], [-43], [20], [48], [-21], [-56], [-24], [-81], [-33], [18], [-46], [-85], [38], [-22], [-15], [40], [0], [21], [24], [26], [-30], [37], [38], [-18], [-30], [16], [83], [0], [84], [-12], [-70], [-62], [35], [-6], [-18], [40], [34], [10], [12], [23], [26], [-40], [-60], [-67], [21], [62], [-4], [86], [-75], [-16], [41], [-34], [-79], [0], [15], [16], [-74], [70], [12], [-32], [10], [13], [-46], [40], [-38], [10], [18], [8], [-10], [37], [-16], [-25], [41], [60], [-12], [-49], [-65], [55], [35], [-75], [-57], [75], [51], [45], [40], [-2], [-84], [20], [-65], [-72], [42], [-39], [-94], [4], [-42], [1], [80], [-85], [-37], [-86], [-63], [62], [-44], [-41], [-12], [-9], [-18], [101], [85]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8624_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8624_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_8624_2_a_d(:prec:=1)
    chi := MakeCharacter_8624_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_8624_2_a_d();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_8624_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8624_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![3, 1]>,<5,R![-4, 1]>,<13,R![-1, 1]>,<17,R![2, 1]>],Snew);
    return Vf;
end function;