
// Make newform 9240.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_c();".
// 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_c();".
// 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)
    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+1)]];
    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], [2], [-6], [-4], [-8], [-6], [4], [2], [-6], [12], [0], [2], [4], [-2], [-8], [-8], [2], [12], [-8], [18], [-10], [-10], [16], [20], [2], [-6], [0], [-12], [18], [12], [10], [4], [2], [-16], [8], [-6], [-12], [-6], [24], [-26], [-6], [-20], [12], [-8], [8], [10], [30], [-28], [-14], [12], [-2], [16], [-14], [-16], [10], [18], [32], [10], [24], [4], [-2], [26], [12], [14], [20], [-2], [-18], [-4], [0], [-22], [28], [16], [-26], [34], [-30], [-38], [12], [6], [36], [-2], [40], [8], [34], [22], [22], [8], [20], [-24], [-32], [36], [20], [-32], [18], [-30], [16], [10], [20], [18], [-16], [18], [-4], [-34], [20], [-6], [-24], [-22], [-32], [26], [-6], [20], [8], [18], [-44], [32], [-30], [36], [-38], [-18], [-22], [8], [12], [-30], [6], [20], [40], [-22], [-28], [-8], [-8], [18], [-22], [-46], [42], [8], [18], [-6], [-12], [-22], [0], [52], [2], [12], [2], [42], [44], [24], [50], [26], [56], [32], [-8], [32], [20], [-54], [2], [38], [-16], [6], [48], [-36], [-38], [-48], [-16], [26], [34], [-22], [-20], [-6], [-12], [-34], [52], [-14], [-60], [30], [-40], [14], [16], [-36], [34], [26], [48], [42], [2], [52], [-30], [16], [-58], [-36], [-12], [-22], [-36], [-2], [-22], [66], [10], [-64], [18], [-16], [10], [34], [12], [2], [-28], [52], [-30], [-12], [-10], [-62], [-40], [4], [-24], [-70], [-16], [18], [-32], [66], [-14], [-16], [18], [-8], [48], [-14], [46], [24], [16], [28], [34], [-4], [20], [18], [20], [-48], [-22], [74], [-44], [-68], [-56], [-12], [56], [-34], [-30], [64], [56], [-76], [-20], [72], [34], [-30], [-24], [26], [-6], [-20], [-58], [-56], [-38], [18], [24], [-60], [22], [42], [22], [-4], [-10], [10], [60], [-70], [-22], [16], [-34], [-4], [42], [72], [48], [-38], [66], [36], [-24], [-80], [-48], [-42], [-40], [24], [66], [74], [4], [-30], [-18], [-60], [-34], [44], [-14], [70], [-44], [42], [-60], [8], [-86], [18], [-4], [-64], [76], [34], [-24], [-62], [56], [-38], [72], [-50], [42], [-24], [32], [74], [-36], [-60], [-10], [82], [20], [2], [-34], [48], [-26], [-14], [20], [-36], [16], [-6], [50], [66], [-24], [-24], [4], [-68], [-66], [-14], [2], [88], [-6], [58], [-74], [-32], [58], [44], [-22], [-32], [-80], [42], [52], [2], [-10], [-32], [34], [-70], [76], [12], [30], [16], [58], [58], [24], [-60], [-44], [10], [-38], [-64], [-38], [84], [12], [0], [58], [88], [-38], [-60], [-100], [34], [-62], [34], [-38], [-94], [32], [54], [52], [0], [64], [42], [-28], [0], [18], [-6], [-20], [-68], [16], [-2], [-40], [-6], [20], [10], [22], [-94], [64], [22], [6], [56], [74], [-22], [-12], [84], [74], [-70], [-48], [4], [-26], [42], [-84], [80], [-26], [48], [-10], [-38], [-24], [12], [-34], [18], [0], [-6], [-28], [0], [34], [108], [-100], [0], [34], [-14], [-14], [-2], [-64], [-80], [-44], [18], [34], [-44], [82], [62], [-16], [-8], [18], [30], [-60], [-12], [-60], [42], [50], [-26], [50], [60], [10], [34], [-44], [0], [12], [54], [-8], [14], [84], [-76], [-30], [-68], [-24], [56], [100], [26], [-52], [26], [-18], [108], [88], [106], [30], [-86], [22], [78], [96], [20], [46], [-60], [44], [-60], [-102], [-72], [-54], [50], [116], [-2], [-92], [42], [112], [28], [82], [16], [-34], [32], [-78], [-82], [-96], [12], [-22], [-24], [36], [56], [-30], [82], [12], [10], [-30], [6], [-40], [-112], [-94], [108], [90], [-8], [-22], [28], [14], [34], [76], [-94], [-80], [18], [-16], [-92], [34], [56], [-6], [50], [-70], [-68], [-88], [-46], [-44], [24], [90], [-28], [-88], [-12], [-8], [30], [18], [-120], [72], [-14], [44], [-18], [-88], [10], [60], [18], [-42], [-60], [-12], [98], [108], [-52], [96], [-38], [-62], [-92], [54], [18], [-56], [34], [-6], [-116], [38], [-20], [-18], [-112], [-110], [-44], [114], [-4], [-70], [24], [54], [-60], [-30], [2], [8], [-102], [-20], [54], [-38], [36], [114], [20], [82], [90], [130], [-32], [-54], [-16], [-20], [42], [-24], [-62], [120], [18], [-96], [14], [58], [24], [-4], [-112], [-10], [-118], [8], [64], [68], [-118], [80]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9240_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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