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