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