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