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