
// Make newform 9450.2.a.p 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_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_9450_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_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], [7], [3], [-1], [-6], [3], [-4], [-2], [-6], [-2], [-3], [-9], [-6], [-7], [4], [-12], [-2], [-1], [6], [-15], [4], [6], [4], [12], [14], [6], [7], [-18], [6], [-4], [-9], [-7], [1], [-14], [0], [24], [-9], [5], [12], [19], [3], [-10], [2], [-8], [12], [5], [-12], [-30], [20], [-30], [-21], [-18], [6], [-16], [10], [-30], [-23], [-30], [28], [12], [-20], [15], [8], [1], [-3], [35], [-30], [30], [-26], [-2], [14], [-24], [-27], [-11], [-24], [8], [0], [-10], [0], [-32], [-22], [-21], [12], [37], [6], [31], [12], [-9], [-8], [39], [2], [-12], [-6], [-15], [-5], [38], [-8], [21], [24], [-24], [-22], [-32], [12], [21], [-30], [-16], [4], [16], [18], [20], [-13], [12], [-23], [45], [-33], [-3], [-22], [10], [30], [12], [44], [-6], [-4], [21], [-14], [-23], [2], [42], [-40], [4], [51], [-16], [36], [-44], [0], [-6], [20], [-27], [-20], [33], [-25], [27], [-26], [-27], [-40], [-36], [-32], [-45], [-8], [0], [-44], [-12], [8], [-9], [16], [0], [-36], [-24], [-59], [24], [-42], [57], [-49], [10], [50], [-36], [24], [-34], [-30], [37], [56], [15], [62], [-42], [10], [29], [-65], [18], [-38], [45], [24], [36], [34], [-29], [-43], [-27], [-62], [-51], [20], [36], [33], [21], [5], [28], [-57], [27], [-21], [44], [13], [44], [-12], [12], [-64], [-24], [24], [53], [49], [18], [1], [12], [0], [-64], [-44], [33], [-12], [-6], [-52], [-52], [48], [-47], [-24], [68], [27], [-36], [-38], [-45], [-14], [11], [53], [-18], [-17], [24], [32], [21], [-36], [9], [63], [-25], [10], [-34], [27], [-27], [-26], [30], [32], [24], [-32], [15], [-60], [-64], [36], [51], [-4], [28], [54], [16], [49], [-9], [23], [7], [30], [35], [63], [-9], [4], [63], [-13], [-38], [10], [23], [-50], [58], [-63], [44], [-34], [-48], [24], [41], [-33], [-55], [76], [-60], [37], [-54], [-10], [9], [39], [18], [-84], [-6], [58], [-18], [-4], [-6], [30], [-44], [58], [-33], [-40], [-60], [-76], [22], [57], [62], [48], [-2], [27], [54], [6], [-74], [-60], [14], [90], [24], [-44], [78], [-73], [61], [-30], [79], [-54], [-70], [-28], [4], [66], [39], [-28], [42], [56], [12], [-82], [-30], [86], [75], [26], [-2], [76], [0], [-30], [-1], [-90], [33], [17], [-38], [-9], [-48], [59], [25], [-39], [-14], [-22], [-51], [21], [66], [48], [78], [-86], [-15], [54], [27], [-47], [55], [-18], [-56], [-55], [63], [-88], [36], [-75], [14], [64], [24], [-18], [-26], [-27], [-38], [90], [-60], [52], [12], [-49], [27], [-31], [58], [16], [33], [71], [6], [-15], [61], [12], [46], [-76], [69], [62], [54], [77], [-60], [40], [54], [-42], [56], [-104], [6], [-32], [-48], [46], [-81], [39], [-10], [85], [-78], [-6], [58], [54], [99], [30], [-14], [48], [-30], [-74], [-48], [-48], [-60], [35], [-27], [-4], [-36], [26], [-96], [94], [-9], [-73], [56], [-20], [-70], [42], [54], [-94], [-90], [68], [-12], [-44], [24], [110], [-70], [-92], [-87], [-21], [-6], [-5], [-93], [-28], [66], [13], [-36], [-52], [89], [60], [-58], [61], [46], [8], [24], [-48], [20], [-11], [-57], [93], [17], [-108], [58], [78], [62], [-3], [90], [40], [-69], [-2], [-42], [52], [84], [38], [30], [17], [56], [-29], [51], [-13], [0], [84], [23], [-92], [39], [50], [-46], [18], [34], [-84], [-68], [-104], [6], [-60], [20], [112], [31], [0], [-27], [-26], [75], [-52], [-17], [-108], [62], [36], [-68], [-44], [86], [-78], [108], [-40], [-120], [94], [48], [-33], [0], [-44], [30], [-44], [51], [61], [0], [25], [51], [62], [-32], [81], [15], [-40], [-66], [-66], [-46], [25], [54], [-98], [78], [-96], [100], [87], [-51], [57], [125], [4], [-9], [-31], [-5], [-105], [-57], [-12], [37], [-118], [107], [60], [-70], [84], [123], [-17], [-84], [-16], [-8], [-34], [-117], [6], [11], [63], [98], [-51], [88], [42], [-108], [-46], [-54], [46], [36], [63], [-104]];
    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_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_9450_2_a_p(: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_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_9450_2_a_p( : 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![-7, 1]>,<17,R![-3, 1]>,<19,R![1, 1]>],Snew);
    return Vf;
end function;