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