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