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