
// Make newform 450.6.a.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_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_450_6_a_d();".
// 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_450_6_a_d();".
// 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_450_a();"
function MakeCharacter_450_a()
    N := 450;
    order := 1;
    char_gens := [101, 127];
    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_450_a_Hecke(Kf)
    return MakeCharacter_450_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 := 6;
    raw_aps := [[-4], [0], [0], [-98], [354], [-404], [-654], [1796], [1080], [-5754], [10196], [-5552], [-12960], [8968], [5400], [-8214], [3954], [962], [17956], [-56148], [85690], [-26044], [93468], [73428], [-128978], [-154794], [-27698], [-221172], [123122], [-220386], [-181298], [-254514], [-415506], [-312340], [300954], [-37576], [378316], [-66980], [83424], [-42318], [-167406], [-483118], [-772572], [670570], [-851922], [-561256], [-578764], [-863114], [712800], [-343666], [-218814], [-1020948], [1371830], [-932058], [1265694], [699936], [-488178], [525968], [-2429312], [2290308], [2091556], [107118], [-1129376], [3061452], [1230250], [-679122], [98516], [1997794], [2650320], [-2033782], [-948630], [494616], [75046], [-533468], [-199780], [869400], [-1051902], [-4192616], [-1902924], [1629098], [-2330274], [612974], [6693840], [-2201942], [1104368], [3822024], [3939852], [1017526], [-6808302], [-6742814], [-3226188], [6212124], [1513258], [-3438354], [5273396], [-8811720], [-10378818], [-4721772], [4243396], [-1306822], [9693880], [-8476662], [-1151016], [-45396], [6436964], [578758], [-960804], [-5702202], [15356904], [12168950], [2946298], [10618048], [-11417430], [-1282420], [7378940], [-1638024], [-20384684], [-21031752], [7855038], [9327270], [15732482], [12656194], [2650614], [5744748], [-14374876], [4261638], [19708766], [-10221096], [13210330], [13058632], [-15376660], [-26253720], [-13615060], [-8412080], [414684], [6715214], [-23723706], [31779772], [7262802], [-32276856], [-10068892], [20867070], [-14068286], [24821016], [-14095414], [6472032], [-17170592], [-2454942], [1131260], [18406896], [-26153948], [19764036], [-34355084], [21125352], [-2613080], [32704560], [20646308], [25431804], [-25280042], [18018042], [51048456], [-45361050], [12470062], [-21378594], [-13182414], [29882328], [-37653448], [-15344276], [-7817818], [-24925254], [16267314], [35468342], [28782696], [46830466], [-39833884], [-21859164], [-40217836], [13655538], [-1476254], [-34928410], [-58831430], [-74575098], [60690880], [-18828066], [-39190224], [58892346], [-16727420], [-19508], [-15182890], [23835660], [30325234], [61723176], [58871156], [-65358750], [4666908], [1132566], [15892322], [-49251764], [-93279210], [-82424976], [-37085022], [6301316], [14906740], [-51500626], [-9928446], [47408502], [-51401164], [-44524344], [89195076], [-103841884], [-87745214], [-52354134], [-111632234], [33938712], [59229324], [-59545870], [-40311242], [-63418380], [-71706600], [97468986], [113217590], [-104658400], [-58439496], [-89355134], [-80021652], [-67862650], [12910710], [-68104728], [59446570], [125790858], [137525884], [65600228], [117656000], [-32508660], [-42000932], [-37035456], [121432802], [-106453866], [29269794], [25889772], [76545888], [-30132340], [1472722], [112943594], [-144352998], [22067340], [-46691402], [163678650], [119323556], [27674088], [-87279848], [99316800], [173654808], [142146194], [-13311198], [-69064986], [194276930], [68151532], [-125390982], [130273738], [23855662], [77729952], [-180234202], [24281752], [30751326], [-161348548], [-100498326], [141567144], [73784836], [188236374], [113843270], [250021936], [44341618], [75577868], [85711474], [19182118], [-72768768], [-7867246], [-205741366], [-138890442], [209303448], [-142879600], [70512312], [-67996498], [208401472], [-129649716], [-110838026], [86318406], [36681752], [139926912], [-133121598], [131473572], [52290138], [-108181806], [-267814832], [-27702678], [26809748], [-35046], [188126250], [-83588528], [2887906], [-223018722], [-177881344], [-308749164], [235576148], [-111488258], [72425196], [-29083210], [-142354836], [-366552188], [321380016], [299099526], [323508228], [100928248], [61819368], [-89007802], [236345466], [-326984460], [-110951438], [75389016], [-147346684], [-16493318], [-215293650], [154719826], [24011346], [56440790], [-429054100], [22355536], [346844256], [-105579126], [96836702], [91300554], [-123544156], [-344552796], [246378548], [-314654532], [26457854], [257545506], [268498538], [-236645138], [114158908], [-144827214], [191133294], [103238576], [-309000270], [362040810], [-124996354], [7397680], [-45036780], [484180794], [305545844], [-293327594], [25108590], [-384937034], [82989170], [128460234], [-157933488], [369585666], [232443222], [322514016], [-274707908], [16121568], [162438768], [-437209566], [-488881196], [-320789618], [483980898], [414741286], [-142091962], [-1495782], [605032124], [-314507880], [333885558], [329216432], [-40099208], [118067466], [329220744], [-89184746], [-76679988], [554909662], [118313346], [480330726], [-364678874], [228693138], [-249008980], [-151137984], [-122520388], [-528389888], [740110888], [115054848], [-135362002], [-722979006], [346465098], [682575124], [202687248], [-550822466], [-611708128], [-687966408], [262236428], [163169970], [278874422], [1302678], [-492001082], [577131438], [341517582], [-124463140], [-618849008], [422616324], [-172376036], [-389930706], [-769644554], [160728054], [-177934716], [116054492], [715829362], [-142270602], [286208616], [-109281698], [-639160626], [12018528], [-548883462], [162628252], [-61249248], [570543534], [-224206814], [568909350], [-174328500], [446891088], [39812060], [-859880880]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_6_a_d();".
// 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_450_6_a_d(:prec:=1)
    chi := MakeCharacter_450_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_450_6_a_d();".
// 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_450_6_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![98, 1]>,<11,R![-354, 1]>,<17,R![654, 1]>],Snew);
    return Vf;
end function;