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