
// Make newform 9450.2.a.l in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9450_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_9450_2_a_l();".
// 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_9450_2_a_l();".
// 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_9450_a();"
function MakeCharacter_9450_a()
    N := 9450;
    order := 1;
    char_gens := [9101, 6427, 6751];
    v := [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_9450_a_Hecke(Kf)
    return MakeCharacter_9450_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 := [[-1], [0], [0], [-1], [0], [-5], [-3], [2], [9], [-3], [5], [-2], [-6], [1], [6], [-3], [-3], [-10], [13], [9], [-2], [-10], [12], [15], [-8], [18], [13], [12], [-16], [-12], [-20], [-9], [-18], [14], [9], [-10], [-23], [-11], [-12], [24], [-24], [-7], [12], [-5], [-18], [11], [-13], [-8], [-9], [14], [12], [12], [-10], [0], [-18], [-9], [-24], [-7], [-8], [6], [4], [6], [-2], [24], [10], [-30], [-19], [13], [30], [-1], [27], [-3], [19], [-14], [-16], [0], [18], [-2], [-18], [14], [-15], [-10], [-24], [16], [35], [6], [0], [-35], [-30], [22], [-24], [36], [-38], [12], [-4], [-36], [-18], [3], [-20], [-16], [-44], [-21], [3], [-24], [5], [34], [-33], [-42], [-3], [8], [-5], [-38], [42], [-10], [-16], [36], [40], [-30], [9], [-12], [14], [1], [-12], [-12], [-28], [-18], [-28], [24], [-17], [-23], [20], [-3], [14], [16], [9], [-40], [24], [-14], [6], [-24], [2], [39], [22], [18], [2], [42], [37], [-9], [14], [-33], [-32], [-27], [7], [-36], [28], [24], [2], [30], [-56], [-30], [6], [36], [4], [-57], [-42], [0], [2], [19], [11], [-36], [-54], [23], [-27], [1], [32], [-15], [53], [3], [-56], [-55], [-8], [-3], [-32], [39], [3], [-54], [52], [-8], [5], [-42], [-56], [-6], [-7], [48], [42], [39], [-67], [10], [-51], [48], [-39], [35], [22], [62], [9], [60], [-43], [-36], [-48], [50], [-47], [30], [10], [-57], [6], [-28], [22], [18], [-15], [-3], [14], [-40], [0], [52], [-12], [-10], [-39], [-24], [37], [-6], [4], [-16], [50], [60], [-8], [36], [-58], [-69], [-42], [-18], [54], [2], [-59], [-52], [69], [30], [61], [-12], [-13], [-9], [4], [-3], [57], [-10], [54], [42], [-16], [28], [-36], [-20], [46], [12], [50], [-2], [-51], [80], [18], [-30], [31], [-6], [59], [52], [-44], [-4], [-50], [61], [54], [26], [38], [39], [-42], [50], [-24], [-55], [76], [-48], [-38], [15], [35], [-9], [-18], [15], [36], [-15], [46], [-30], [80], [-42], [-75], [-62], [22], [-51], [38], [6], [41], [7], [-72], [-49], [0], [16], [-12], [-15], [-42], [-77], [45], [-52], [-3], [24], [-44], [12], [-10], [58], [-72], [34], [72], [20], [-7], [-62], [69], [54], [8], [30], [-28], [36], [11], [27], [38], [9], [-58], [88], [46], [-6], [48], [-10], [15], [54], [-7], [1], [-12], [48], [-40], [25], [39], [-53], [-76], [54], [-36], [-60], [-18], [48], [28], [39], [33], [-6], [-38], [-98], [12], [-20], [29], [18], [20], [-45], [51], [-13], [-74], [69], [27], [52], [6], [82], [-90], [60], [52], [18], [32], [6], [62], [49], [7], [96], [-1], [60], [30], [-98], [57], [-77], [29], [-21], [59], [51], [41], [12], [-86], [-9], [-24], [56], [-80], [-12], [4], [-33], [82], [-75], [-36], [-55], [-59], [-30], [-57], [64], [-63], [-54], [-81], [7], [48], [3], [-92], [-24], [-84], [72], [38], [-36], [50], [-60], [-67], [54], [67], [30], [-37], [-52], [37], [65], [84], [-6], [-22], [-21], [62], [-84], [-32], [-12], [74], [-13], [-92], [48], [-66], [-21], [103], [81], [-28], [45], [13], [66], [29], [-22], [18], [-82], [22], [61], [26], [-12], [-24], [-34], [94], [72], [-30], [50], [-12], [82], [-6], [44], [18], [-81], [22], [-51], [-2], [-66], [-8], [78], [32], [60], [-28], [38], [19], [54], [-61], [0], [36], [95], [88], [21], [-49], [44], [-15], [-101], [114], [-62], [-50], [-78], [-24], [-4], [-2], [-62], [63], [-60], [-56], [-63], [20], [-17], [-96], [65], [57], [7], [46], [23], [-102], [87], [80], [27], [-32], [78], [18], [48], [-44], [78], [94], [18], [-11], [30], [-98], [54], [-25], [-101], [-18], [-63], [-76], [51], [54], [-100], [16], [87], [-80], [60], [78], [-116], [18], [66], [-114], [17], [4], [93], [-16], [-17], [42], [-78], [69], [-71], [-4], [-64], [-87], [-28], [-18], [-84], [-41], [-90], [-34], [-20], [-37], [-96], [-33], [-100], [45], [29], [51], [4], [21], [-36], [23], [-15], [-98], [117], [90], [-86]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9450_2_a_l();".
// 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_9450_2_a_l(:prec:=1)
    chi := MakeCharacter_9450_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(4297) - 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_9450_2_a_l();".
// 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_9450_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![0, 1]>,<13,R![5, 1]>,<17,R![3, 1]>,<19,R![-2, 1]>],Snew);
    return Vf;
end function;