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