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