
// Make newform 2450.4.a.bn in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2450_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_2450_4_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_2450_4_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_2450_a();"
function MakeCharacter_2450_a()
    N := 2450;
    order := 1;
    char_gens := [1177, 101];
    v := [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_2450_a_Hecke(Kf)
    return MakeCharacter_2450_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 := 4;
    raw_aps := [[2], [7], [0], [0], [-37], [-51], [-41], [108], [-70], [-249], [134], [-334], [-206], [-376], [287], [-6], [2], [940], [106], [456], [-650], [-1239], [-428], [220], [1055], [-1960], [-1825], [-144], [1681], [798], [434], [1290], [192], [-1402], [-302], [-3167], [470], [-2390], [2631], [2243], [52], [-2462], [3159], [2060], [1738], [894], [-4083], [-377], [2551], [-74], [1888], [4997], [3830], [3390], [-7170], [-7672], [54], [-2932], [3254], [3327], [-4627], [4083], [4089], [4008], [-7355], [-1684], [-1460], [7514], [-2862], [6368], [3635], [7116], [319], [-11652], [7748], [-8680], [-1711], [-1589], [-5147], [9100], [-2618], [-3695], [15779], [-7238], [2646], [5688], [-3285], [14834], [9972], [-9096], [-15867], [-242], [-3558], [1473], [603], [-18387], [-9018], [-4624], [5876], [-8537], [-13060], [21372], [12704], [8762], [-24764], [-1811], [-10548], [-17439], [2451], [7792], [1937], [5036], [-27286], [-28538], [25007], [-12130], [-14385], [2208], [22448], [8791], [13180], [-7164], [-12335], [-15436], [19184], [32975], [-31497], [18610], [17508], [4685], [-25925], [25578], [-4291], [-31528], [23154], [-13992], [21681], [16903], [-18905], [-5571], [-10894], [-30731], [1038], [7958], [30666], [5354], [42890], [-22950], [2824], [-4866], [-10676], [29856], [-1944], [14628], [-12858], [-18324], [-14751], [47922], [44987], [20356], [-27786], [-48674], [-11168], [-20094], [49104], [-27751], [37600], [10911], [-6103], [8718], [11748], [-8172], [-22585], [53302], [-2032], [-16128], [-673], [-18783], [-20540], [-28496], [8324], [-8548], [-32348], [-24534], [-61232], [19206], [-50110], [-43885], [16841], [-31480], [41838], [-39160], [37633], [-64014], [22404], [-7107], [52995], [36270], [20091], [40187], [-55986], [-2628], [5754], [32768], [41704], [12267], [21486], [-62884], [21970], [-52768], [-8378], [48210], [30598], [36159], [52916], [-9496], [59758], [88730], [30736], [61982], [-57714], [32816], [-86475], [20284], [-51729], [39186], [-48713], [-14201], [-36001], [-77068], [-50948], [-84304], [49712], [-55491], [33367], [39043], [47334], [-103388], [96201], [-2382], [71940], [-54452], [-45557], [-31970], [35521], [-79476], [-3336], [-24372], [-27259], [69044], [-21852], [-4688], [-116642], [35996], [55238], [61923], [-56162], [-121216], [-38875], [15461], [-63744], [91286], [-2614], [-70279], [2370], [1906], [112209], [-92468], [-49726], [-38328], [11614], [41254], [-43933], [7624], [56710], [67283], [-23540], [11750], [-76663], [37500], [-6981], [-91195], [-22504], [-109114], [-87025], [-131257], [-93984], [130468], [84226], [15730], [-116695], [149781], [-71034], [64374], [7256], [-143778], [28194], [-76491], [131764], [98859], [-151549], [169986], [95795], [-114612], [133373], [-130138], [-71744], [-90140], [115888], [-84750], [-10512], [-61497], [48522], [-118020], [-119116], [-118892], [59036], [-45533], [84619], [7005], [134116], [-62822], [54966], [-68590], [38040], [134578], [97977], [18876], [-28234], [-58654], [17902], [-131830], [148834], [-190087], [133572], [-64173], [6037], [-109458], [-9220], [-216317], [157386], [-145622], [70726], [-94585], [-181042], [-55584], [97218], [-56492], [-3814], [-161529], [-45266], [23424], [56949], [-112533], [37877], [-150726], [-134640], [-35610], [-21904], [-1678], [-159244], [-167310], [-40686], [-125173], [-18708], [-70252], [-34977], [26028], [-82659], [176791], [-43400], [-110638], [-101637], [-244776], [170076], [-200420], [192679], [-72075], [-61062], [-204007], [-112200], [73462], [-152666], [165934], [-4506], [193839], [-115305], [256709], [76932], [233389], [-165235], [-55713], [48045], [-81124], [62215], [-240136], [-136604], [87122], [-200797], [-157278], [-150268], [2150], [173374], [-149145], [269952], [234604], [-219366], [-128925], [-164404], [65700], [-71317], [174300], [-161826], [-159188], [160670], [90232], [297527], [-269256], [-102806], [166479], [-185763], [-7246], [1436], [-243348], [-60847], [301635], [-37646], [1978], [198042], [127144]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2450_4_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_2450_4_a_bn(:prec:=1)
    chi := MakeCharacter_2450_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_2450_4_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_2450_4_a_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-7, 1]>,<11,R![37, 1]>,<19,R![-108, 1]>,<23,R![70, 1]>],Snew);
    return Vf;
end function;