
// Make newform 8624.2.a.w in Magma, downloaded from the LMFDB on 31 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_w();".
// 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_w();".
// 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], [1], [3], [0], [1], [4], [-6], [8], [3], [0], [5], [-1], [0], [10], [0], [-6], [3], [4], [1], [-15], [4], [-2], [6], [9], [7], [-18], [8], [-6], [2], [-15], [16], [-6], [9], [14], [6], [10], [-5], [4], [-12], [-18], [9], [13], [21], [20], [6], [8], [-20], [17], [6], [13], [-24], [-6], [-8], [-9], [18], [-18], [6], [20], [-10], [-18], [-4], [0], [-16], [12], [1], [33], [7], [2], [-12], [-14], [21], [36], [-19], [-10], [-29], [-27], [-27], [34], [18], [-2], [12], [-10], [-18], [-29], [8], [21], [3], [-28], [-12], [-23], [3], [-12], [-29], [-24], [4], [-30], [21], [27], [8], [-16], [-8], [-18], [-36], [0], [-44], [-17], [-12], [36], [0], [-26], [14], [32], [18], [17], [43], [39], [-13], [3], [3], [42], [-17], [-34], [42], [-48], [-1], [18], [-37], [45], [17], [4], [34], [-12], [-35], [-22], [-36], [-44], [-42], [32], [-9], [-24], [38], [30], [43], [36], [19], [-39], [-38], [-24], [-25], [-48], [-52], [27], [4], [30], [4], [-12], [34], [-18], [-32], [30], [-27], [42], [16], [-15], [45], [45], [16], [10], [38], [-51], [6], [58], [24], [8], [23], [-33], [10], [-33], [20], [-44], [-32], [-6], [41], [42], [9], [30], [8], [-40], [-22], [6], [-41], [-6], [-35], [-30], [-36], [21], [-22], [11], [42], [66], [-12], [-22], [-2], [-56], [9], [3], [-37], [12], [0], [8], [-64], [33], [67], [-60], [-18], [1], [-68], [-60], [-48], [-21], [-28], [-4], [-39], [25], [36], [-46], [42], [24], [44], [-36], [5], [-52], [-50], [0], [-25], [-66], [7], [36], [-9], [15], [15], [-16], [-52], [53], [-24], [12], [-52], [12], [-14], [-6], [32], [6], [-3], [-38], [6], [-36], [38], [26], [-45], [-38], [-44], [-72], [46], [-26], [-6], [8], [-9], [-45], [-14], [-78], [-5], [-17], [46], [-32], [-32], [-31], [63], [-46], [-52], [-36], [-48], [-23], [12], [10], [-28], [57], [26], [-78], [-25], [-78], [-15], [-60], [-36], [42], [-10], [48], [83], [-27], [42], [38], [-38], [48], [-20], [84], [67], [47], [-57], [79], [36], [44], [-24], [-42], [-66], [49], [48], [34], [-51], [18], [-26], [12], [-52], [17], [42], [-47], [6], [13], [-29], [89], [72], [84], [-34], [-18], [38], [72], [16], [-21], [5], [-36], [49], [-70], [-55], [-9], [-36], [79], [-33], [42], [25], [-53], [24], [-51], [68], [-37], [78], [-28], [-82], [-54], [15], [-78], [-6], [21], [-58], [30], [15], [-90], [53], [-19], [24], [70], [-64], [9], [80], [-78], [-12], [-22], [41], [-36], [54], [-14], [30], [22], [42], [15], [22], [30], [-88], [-27], [-80], [-77], [88], [93], [-19], [45], [-63], [41], [-69], [32], [-10], [18], [76], [-18], [-50], [-39], [-32], [-6], [-60], [38], [-58], [-84], [68], [-15], [-26], [66], [-60], [-38], [-58], [-69], [24], [77], [-6], [66], [51], [-56], [48], [90], [-74], [-63], [39], [-66], [29], [48]];
    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_w();".
// 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_w(: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_w();".
// 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_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8624_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<5,R![-3, 1]>,<13,R![-4, 1]>,<17,R![6, 1]>],Snew);
    return Vf;
end function;