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