
// Make newform 9360.2.a.bx in Magma, downloaded from the LMFDB on 29 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_bx();".
// 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_bx();".
// 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], [3], [-3], [1], [-3], [-4], [3], [-10], [6], [-5], [5], [-2], [-2], [-11], [-4], [1], [4], [-3], [6], [-3], [-16], [7], [-19], [4], [14], [3], [-18], [2], [-8], [-8], [-12], [23], [-5], [-8], [-16], [11], [10], [-18], [6], [-3], [-6], [-13], [-12], [-8], [20], [-8], [20], [8], [3], [-3], [10], [-4], [2], [0], [22], [20], [-26], [-22], [24], [18], [-33], [-10], [20], [-10], [12], [-2], [-9], [24], [6], [4], [4], [30], [22], [16], [2], [7], [-18], [-20], [-30], [-20], [-24], [0], [7], [-41], [13], [25], [25], [-5], [-25], [-29], [33], [22], [10], [16], [-29], [-30], [32], [20], [-18], [-34], [-17], [30], [-19], [1], [-4], [-22], [-14], [-13], [4], [-3], [-6], [-44], [-10], [36], [23], [21], [-6], [-34], [-22], [-30], [-31], [-12], [28], [48], [-36], [-40], [2], [11], [-42], [24], [-49], [22], [-54], [-30], [48], [28], [-5], [24], [-2], [21], [12], [-14], [2], [33], [29], [23], [19], [-42], [10], [14], [-34], [21], [26], [4], [-55], [-21], [40], [27], [-54], [-31], [-8], [28], [-18], [-44], [-53], [-14], [48], [13], [36], [-56], [30], [1], [-5], [10], [18], [-9], [-8], [22], [-33], [-24], [24], [-20], [-14], [-10], [-16], [-35], [-40], [59], [24], [34], [45], [29], [32], [17], [10], [-14], [-52], [11], [42], [49], [41], [-3], [-25], [63], [-64], [20], [-1], [63], [-2], [-2], [-28], [56], [24], [58], [30], [18], [16], [60], [-57], [-6], [30], [16], [-17], [-43], [3], [30], [70], [-35], [52], [-41], [-4], [-24], [20], [70], [10], [-24], [-48], [-68], [56], [-45], [14], [-38], [54], [60], [0], [-23], [-14], [-8], [14], [54], [76], [-35], [39], [-69], [50], [27], [-74], [-51], [4], [53], [48], [66], [24], [-43], [39], [-21], [21], [-30], [-30], [9], [-3], [24], [24], [29], [72], [-58], [68], [-72], [51], [-30], [0], [-62], [-84], [-26], [-46], [14], [-6], [-20], [40], [4], [-78], [28], [-36], [26], [-32], [-33], [4], [-33], [-16], [-28], [25], [-55], [-4], [-17], [-47], [-65], [72], [68], [-21], [42], [80], [-44], [-62], [29], [-9], [69], [-34], [-20], [-32], [58], [-4], [-25], [-12], [63], [-40], [-29], [43], [-26], [48], [-53], [28], [-48], [44], [-54], [-32], [78], [-70], [-2], [5], [95], [39], [-32], [-6], [-2], [-79], [-1], [88], [51], [88], [-53], [13], [72], [-33], [42], [57], [-28], [-50], [94], [-50], [-42], [36], [96], [48], [66], [28], [75], [33], [30], [44], [30], [-96], [-5], [76], [31], [24], [13], [58], [-8], [18], [6], [-4], [26], [94], [2], [-40], [-32], [56], [31], [-44], [12], [-19], [-6], [61], [-28], [-30], [16], [-53], [-46], [-10], [71], [-67], [-36], [-15], [-97], [18], [90], [1], [87], [-44], [67], [-77], [87], [-40], [-80], [-33], [42], [44], [-91], [-6], [-73], [-48], [14], [-46], [48], [39], [-27], [30], [-64], [32], [57], [-51], [54], [-59], [-92], [-36], [32], [-44], [26], [-26], [19], [20], [16], [66], [-30], [66], [54], [58], [30], [19], [12], [94], [-18], [-1], [-22], [98], [-72], [-88], [36], [-79], [-64], [44], [73], [-69], [-45], [-81], [12], [-56], [-52], [104], [-20], [-63], [-70], [-42], [-33], [-90], [68], [-27], [-36], [56], [0], [52], [2], [-12], [-77], [-40], [-1], [46], [-11], [-7], [-96], [-90], [-14], [30], [-50], [-77], [44], [44], [-53], [81], [-44], [50], [-43], [74], [66], [-83], [-85], [102], [58], [72], [59], [11], [86], [100], [-46], [-90], [-93], [42], [-52], [82], [-44], [-86], [9], [-43], [-16], [70], [-73], [-56], [4], [4], [68], [68], [26], [34], [70], [-66], [35], [-62], [-83], [-8], [65], [76], [84], [-78], [26], [-62], [-78], [71], [-31], [-106], [-42], [-109], [-87], [15], [67], [-80]];
    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_bx();".
// 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_bx(: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_bx();".
// 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_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9360_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 1]>,<11,R![3, 1]>,<17,R![3, 1]>,<19,R![4, 1]>,<31,R![-6, 1]>],Snew);
    return Vf;
end function;