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