
// Make newform 9240.2.a.j in Magma, downloaded from the LMFDB on 02 November 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_9240_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_9240_2_a_j();".
// 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_9240_2_a_j();".
// 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_9240_a();"
function MakeCharacter_9240_a()
    N := 9240;
    order := 1;
    char_gens := [2311, 4621, 6161, 3697, 5281, 2521];
    v := [1, 1, 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_9240_a_Hecke( : Kf := Kf)
    return MakeCharacter_9240_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], [1], [-1], [1], [-4], [4], [4], [-6], [10], [0], [-8], [6], [0], [8], [10], [-8], [-10], [-14], [-12], [-10], [16], [0], [-8], [6], [6], [8], [-4], [16], [16], [-8], [20], [8], [16], [6], [8], [-14], [10], [-18], [-10], [12], [8], [-16], [-2], [-22], [-16], [-18], [0], [0], [-4], [18], [-18], [18], [24], [22], [12], [18], [8], [18], [8], [-22], [26], [10], [18], [10], [10], [-20], [26], [28], [-2], [22], [-6], [32], [6], [-36], [-16], [6], [14], [34], [22], [-12], [22], [-34], [-2], [0], [-24], [-30], [22], [2], [32], [12], [0], [-16], [-36], [-24], [6], [-6], [40], [-2], [20], [28], [-38], [12], [-20], [26], [-14], [4], [-24], [24], [-10], [16], [10], [48], [42], [16], [18], [28], [16], [-34], [20], [8], [10], [-2], [16], [50], [-6], [-34], [6], [-16], [-4], [18], [8], [48], [-8], [-34], [46], [-38], [-54], [26], [12], [-4], [-38], [-12], [-36], [56], [-6], [-12], [-24], [22], [-6], [-22], [40], [34], [10], [-2], [-4], [12], [28], [58], [14], [-44], [-2], [24], [-28], [28], [16], [48], [-16], [-30], [26], [-24], [-32], [-62], [38], [4], [24], [2], [-42], [20], [-26], [-32], [4], [-64], [-36], [-14], [62], [14], [4], [-38], [48], [66], [4], [48], [38], [-68], [66], [18], [-8], [0], [-22], [-50], [-40], [-14], [-34], [-24], [2], [-40], [36], [-16], [14], [-2], [-18], [-4], [-36], [-44], [-58], [16], [-34], [-62], [54], [48], [32], [-54], [20], [12], [-56], [-38], [-36], [-64], [60], [-4], [24], [32], [32], [-24], [30], [-14], [-10], [20], [-54], [64], [28], [32], [-2], [0], [48], [-32], [-36], [70], [52], [-62], [-50], [-34], [46], [-14], [-56], [-18], [-50], [-38], [14], [64], [-36], [-26], [-12], [2], [-10], [30], [44], [-20], [-26], [56], [-22], [6], [28], [-34], [-8], [-68], [20], [-46], [20], [-42], [-24], [-14], [70], [18], [36], [-70], [-58], [-76], [66], [-54], [-36], [-62], [44], [-46], [-30], [-28], [-74], [28], [-58], [-10], [18], [40], [16], [-64], [34], [-60], [-68], [-36], [-58], [34], [42], [48], [-2], [-76], [26], [-68], [-42], [-66], [0], [-20], [22], [-30], [8], [-50], [34], [-16], [-76], [48], [-42], [-60], [-10], [64], [-12], [22], [-36], [-74], [80], [-50], [52], [4], [64], [-26], [-8], [2], [48], [12], [62], [-20], [-54], [52], [34], [-90], [28], [-68], [0], [14], [84], [54], [54], [-38], [34], [14], [-16], [-20], [10], [18], [72], [-42], [-68], [30], [-24], [-94], [48], [36], [92], [30], [34], [2], [-14], [14], [48], [-24], [-30], [-64], [80], [40], [34], [-88], [92], [46], [-42], [60], [56], [-4], [-18], [80], [0], [20], [38], [-70], [12], [-56], [-82], [-54], [-80], [-52], [4], [20], [-24], [-70], [86], [-80], [-102], [-62], [-102], [-74], [-8], [66], [78], [30], [68], [-82], [36], [-6], [50], [80], [44], [2], [-20], [82], [4], [48], [56], [-22], [0], [22], [-30], [-42], [96], [108], [-90], [8], [42], [-6], [30], [-74], [42], [54], [70], [-48], [62], [44], [90], [86], [-30], [-48], [-44], [-32], [-24], [40], [96], [-32], [-2], [-66], [26], [-44], [-52], [-60], [46], [32], [-84], [38], [30], [-60], [108], [74], [92], [54], [-26], [-66], [-62], [70], [-70], [96], [12], [-74], [-32], [-86], [36], [44], [66], [-2], [66], [112], [10], [-44], [34], [-96], [-14], [66], [-68], [-14], [72], [68], [-10], [6], [20], [-38], [46], [84], [84], [2], [18], [46], [22], [-46], [-54], [-24], [48], [28], [-18], [60], [54], [90], [-76], [66], [10], [92], [50], [-88], [-4], [32], [-20], [70], [66], [50], [-64], [-114], [24], [-100], [-54], [-44], [-56], [-120], [120], [-8], [68], [-120], [42], [-40], [-42], [-60], [-6], [84], [-70], [-42], [48], [90], [2], [-114], [-22], [108], [-46], [86], [-68], [0], [-34], [6], [-20], [58], [-18], [-72], [-34], [-58], [68], [62], [44], [30], [88], [-82], [-64], [74], [-28], [-120], [-72], [-14], [36], [-90], [-30], [72], [-52], [-6], [-58], [-14], [24], [74], [-78], [-30], [68], [22], [-40], [-90], [-28], [-124], [4], [124], [-110], [-90], [86], [-122], [-14], [-122], [88], [28], [-92], [-18], [-82], [-48], [-6], [-64], [-100], [86]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9240_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9240_2_a_j();".
// 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_9240_2_a_j(:prec:=1)
    chi := MakeCharacter_9240_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(4603) - 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_9240_2_a_j();".
// 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_9240_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9240_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<13,R![4, 1]>,<17,R![-4, 1]>,<19,R![-4, 1]>,<23,R![6, 1]>,<37,R![8, 1]>],Snew);
    return Vf;
end function;