
// Make newform 9360.2.a.p in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_9360_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_9360_2_a_p();".
// 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_9360_2_a_p();".
// 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_9360_a();"
function MakeCharacter_9360_a()
    N := 9360;
    order := 1;
    char_gens := [8191, 2341, 2081, 5617, 5761];
    v := [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_9360_a_Hecke( : Kf := Kf)
    return MakeCharacter_9360_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], [0], [-1], [0], [4], [1], [6], [-4], [8], [-6], [8], [-10], [6], [-4], [0], [10], [4], [-2], [12], [16], [2], [16], [-12], [-10], [-6], [2], [0], [-12], [-10], [-10], [-8], [12], [-10], [-12], [-6], [0], [-2], [-4], [8], [18], [12], [6], [0], [10], [-6], [8], [12], [-8], [4], [14], [14], [-8], [18], [-28], [6], [24], [26], [-24], [-10], [-10], [-20], [26], [12], [-24], [-22], [2], [20], [2], [20], [6], [30], [16], [24], [22], [4], [32], [34], [30], [-34], [-22], [-4], [-34], [-24], [34], [40], [36], [-18], [34], [18], [-8], [12], [-8], [16], [4], [-20], [8], [-30], [6], [-36], [22], [20], [18], [12], [-10], [-28], [42], [12], [-34], [-24], [-6], [8], [-10], [-42], [4], [16], [30], [-4], [24], [34], [-20], [14], [34], [-22], [28], [12], [-22], [-50], [0], [16], [-50], [-20], [-24], [-32], [-42], [-42], [34], [-38], [-4], [2], [-42], [-12], [-6], [-16], [-36], [-2], [0], [-26], [-18], [20], [0], [14], [-2], [36], [8], [12], [0], [56], [14], [-22], [-30], [52], [-34], [-16], [36], [30], [8], [16], [-58], [-14], [42], [4], [38], [8], [50], [-32], [22], [-44], [42], [-48], [-34], [-24], [-4], [6], [6], [0], [34], [62], [-36], [-6], [40], [-62], [-36], [-20], [-14], [-20], [30], [2], [-34], [14], [24], [18], [-16], [22], [34], [20], [-14], [24], [12], [6], [68], [-62], [-30], [-48], [-4], [-48], [10], [8], [62], [-24], [66], [22], [32], [-18], [24], [-4], [38], [-66], [32], [-32], [-60], [-50], [-4], [72], [6], [44], [32], [-62], [10], [-12], [-8], [-12], [-76], [-32], [-58], [-2], [24], [-40], [-52], [-60], [48], [46], [-50], [24], [-54], [18], [-20], [-74], [4], [58], [-14], [56], [-20], [46], [-2], [-18], [-68], [18], [-10], [20], [10], [-66], [-52], [2], [-32], [-46], [-48], [60], [22], [-38], [60], [48], [-32], [-40], [46], [20], [48], [34], [-22], [-32], [-66], [10], [28], [-10], [-12], [46], [-86], [-16], [58], [20], [-20], [58], [-46], [0], [-4], [-28], [-22], [68], [30], [-48], [6], [-16], [-54], [-18], [36], [-40], [-22], [44], [72], [-6], [-50], [12], [-78], [-22], [8], [70], [-78], [76], [4], [-80], [-38], [-26], [50], [-16], [-60], [-44], [-36], [-74], [62], [58], [40], [-74], [-18], [42], [88], [-30], [-52], [38], [-44], [72], [58], [-20], [18], [-62], [-24], [-58], [-2], [-40], [-12], [6], [8], [-26], [54], [-48], [-92], [52], [-6], [18], [-64], [-38], [76], [68], [-32], [66], [-72], [-2], [-100], [48], [10], [62], [-22], [18], [-42], [-32], [78], [-52], [8], [40], [54], [-92], [96], [34], [-6], [-44], [-28], [48], [10], [56], [-74], [-12], [-54], [86], [70], [-24], [54], [-6], [-8], [-2], [-2], [-52], [-68], [66], [10], [36], [-68], [-86], [42], [-24], [64], [-2], [-40], [26], [38], [48], [36], [34], [18], [60], [-10], [36], [40], [42], [108], [20], [-96], [14], [-2], [-38], [-66], [60], [0], [60], [-34], [-34], [-80], [-14], [-26], [92], [48], [-94], [-18], [76], [-32], [-60], [6], [-86], [-94], [-26], [12], [-74], [-10], [-28], [96], [-36], [-42], [-76], [74], [88], [-4], [30], [60], [-72], [-28], [-40], [50], [-12], [30], [58], [24], [32], [10], [-70], [-90], [-30], [-94], [16], [-12], [-42], [-52], [-76], [104], [-18], [24], [-38], [66], [60], [-98], [100], [-6], [88], [28], [-62], [-24], [-90], [-80], [-34], [-74], [-88], [-32], [54], [92], [84], [-32], [-14], [-62], [20], [-70], [-14], [94], [-24], [104], [6], [68], [-98], [72], [90], [-68], [98], [-54], [60], [74], [72], [-42], [16], [-28], [62], [-72], [6], [102], [-62], [12], [96], [98], [-24], [-84], [102], [4], [-16], [-20], [-40], [-70], [94], [36], [8], [66], [60], [-10], [-68]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9360_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9360_2_a_p();".
// 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_9360_2_a_p(:prec:=1)
    chi := MakeCharacter_9360_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(4027) - 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_9360_2_a_p();".
// 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_9360_2_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9360_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![0, 1]>,<11,R![-4, 1]>,<17,R![-6, 1]>,<19,R![4, 1]>,<31,R![-8, 1]>],Snew);
    return Vf;
end function;