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