
// Make newform 9450.2.a.u in Magma, downloaded from the LMFDB on 25 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_u();".
// 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_u();".
// 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], [0], [-7], [-6], [-6], [-4], [-2], [-3], [1], [-3], [-9], [6], [8], [13], [0], [7], [8], [-3], [9], [10], [3], [4], [0], [11], [-15], [7], [-12], [15], [-4], [6], [-10], [22], [16], [12], [6], [9], [2], [3], [22], [-27], [-25], [14], [-26], [-3], [-22], [-27], [24], [8], [-18], [12], [24], [-18], [29], [-26], [-6], [22], [30], [16], [-30], [1], [15], [-10], [4], [30], [-10], [-12], [9], [10], [4], [-16], [-24], [30], [-38], [24], [14], [-30], [35], [-9], [-11], [-19], [24], [0], [28], [3], [13], [36], [-24], [7], [-12], [14], [-9], [-30], [-27], [-38], [29], [-8], [18], [21], [-6], [32], [-11], [-12], [-36], [-39], [44], [22], [-20], [-6], [-1], [-34], [-24], [4], [-27], [-42], [48], [14], [-8], [-30], [18], [17], [0], [-19], [36], [28], [-5], [-16], [-6], [14], [52], [6], [32], [-18], [-32], [12], [18], [-7], [30], [49], [-36], [-52], [-42], [10], [6], [41], [-18], [40], [-18], [-20], [-15], [1], [57], [56], [3], [7], [-3], [-12], [-54], [-23], [36], [-15], [24], [20], [-26], [38], [-6], [21], [50], [-12], [46], [-49], [15], [-10], [-18], [52], [26], [-17], [48], [-14], [0], [48], [21], [-38], [-26], [23], [18], [34], [24], [38], [57], [-18], [-24], [-58], [-8], [42], [63], [60], [-55], [-59], [62], [36], [-18], [11], [30], [-42], [59], [16], [15], [19], [60], [-48], [-28], [40], [-6], [-18], [-51], [5], [23], [42], [61], [39], [-10], [24], [-45], [-26], [3], [4], [-25], [50], [-48], [10], [-57], [-40], [-27], [-21], [36], [6], [20], [-32], [65], [-78], [12], [52], [60], [-22], [0], [22], [-18], [-6], [44], [24], [-36], [2], [-62], [18], [-38], [64], [78], [-4], [-47], [-6], [-1], [-18], [-78], [4], [21], [-40], [-65], [-26], [32], [13], [-2], [-24], [53], [-43], [48], [-24], [-58], [-48], [-28], [-32], [-36], [-56], [-78], [-37], [-45], [-24], [45], [57], [78], [64], [-21], [8], [6], [0], [28], [-5], [81], [-16], [12], [-22], [52], [-66], [-22], [33], [70], [-39], [36], [66], [-5], [-18], [-34], [30], [24], [1], [-30], [-28], [58], [-27], [-29], [-21], [20], [74], [-44], [-12], [-54], [-73], [21], [8], [33], [-70], [-72], [-79], [-6], [50], [-20], [-26], [-3], [-75], [44], [-30], [81], [20], [73], [30], [18], [-31], [-92], [-12], [-8], [14], [-54], [42], [72], [93], [6], [-62], [3], [54], [48], [-74], [-44], [-66], [52], [29], [21], [29], [12], [-6], [23], [34], [24], [-45], [61], [-18], [-53], [-33], [-51], [-47], [51], [23], [27], [80], [31], [-101], [48], [35], [6], [36], [-98], [93], [40], [56], [39], [68], [-84], [-58], [45], [103], [-78], [9], [11], [-44], [66], [58], [-6], [-17], [51], [-36], [44], [58], [-99], [-45], [28], [-72], [57], [48], [43], [24], [-48], [70], [-24], [-12], [36], [-52], [-6], [86], [-84], [50], [-9], [85], [9], [53], [-70], [-44], [56], [39], [-78], [5], [51], [98], [-78], [40], [-81], [-70], [-4], [-83], [-12], [54], [-3], [-86], [-90], [71], [66], [94], [-27], [38], [-40], [15], [35], [-14], [-38], [26], [-57], [54], [83], [4], [-36], [84], [-85], [87], [1], [-30], [35], [-96], [-21], [-5], [57], [79], [87], [10], [24], [-67], [90], [-37], [2], [-62], [-72], [-115], [-78], [84], [86], [16], [69], [-85], [62], [36], [52], [42], [37], [40], [0], [84], [-13], [-2], [-80], [6], [108], [25], [93], [56], [-62], [-78], [110], [-105], [-38], [-62], [-40], [18], [-42], [-64], [72], [31], [-72], [84], [123], [64], [-63], [67], [117], [115], [87], [-53], [-114], [29], [61], [-66], [-30], [-112], [-36], [6], [8], [61], [93], [-26], [3], [78], [46], [-39], [-9], [-75], [-10], [-23], [63], [92], [46], [12], [12], [42], [37], [-4], [8], [-24], [8], [-66], [-117], [22], [36], [92], [7], [-109], [-63], [-6], [71], [-36], [-43], [-69], [4], [66], [-114], [32], [33], [-98], [9], [-21], [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_u();".
// 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_u(: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_u();".
// 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_u( : 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![0, 1]>,<19,R![7, 1]>],Snew);
    return Vf;
end function;