
// Make newform 400.10.a.j in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_400_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_400_10_a_j();".
// 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_400_10_a_j();".
// 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_400_a();"
function MakeCharacter_400_a()
    N := 400;
    order := 1;
    char_gens := [351, 101, 177];
    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_400_a_Hecke(Kf)
    return MakeCharacter_400_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 := 10;
    raw_aps := [[0], [174], [0], [4658], [-28992], [164446], [594822], [295780], [2544534], [-3722970], [-2335772], [-10840418], [21593862], [10832294], [5172138], [-98179674], [-16162860], [-43928158], [-81557422], [-161307732], [247147966], [583345720], [-14571786], [470133690], [117838462], [-86092698], [1928721374], [1396845258], [-604327390], [1685802246], [3707158898], [-2540801472], [1153895982], [5627209060], [-2136877350], [9675148], [688487542], [-14308161946], [9987347778], [-3513956634], [-1195024980], [-9120526378], [9374306988], [-24000039194], [556123662], [25125494200], [16391501008], [46525684934], [-1914147702], [-14582465170], [-41278998714], [-36550217640], [-86606962738], [72076909248], [112729124742], [55522504254], [27972555570], [-33288431732], [-54624034298], [-83781811578], [-83608582786], [228547011006], [195063631058], [-215637432492], [-191755248554], [338885704422], [178426590328], [-264693465218], [-81191170062], [-226688041450], [-32873293074], [312096166440], [628209236378], [98477013766], [-289023741380], [201349539414], [393769497690], [515624890462], [-843309264798], [564548742110], [-692474998020], [408125314682], [-441054560772], [71538962686], [-474967117640], [-197071772106], [-620156168250], [-788005952858], [15349559742], [194493818654], [106502691378], [831146028120], [-1385664440182], [-392804354112], [752029324900], [-1834291570626], [-619863696090], [525682625082], [168425748734], [2206122543662], [-3516393618262], [-629995603458], [402618993054], [2554817360670], [-1162432881032], [-4663321787498], [3884215231818], [2013411671406], [-2105782224000], [4740576995702], [-4014761597542], [-1303985206754], [-5101642171578], [450629987980], [-79710463172], [-3126484893138], [-5949816067906], [3561873037338], [137882921526], [4166544473340], [-3290827458358], [-5747316151634], [-9312452352498], [9199671873414], [-10312547234312], [-9525655030398], [-8385367901890], [-6940126686120], [7749838653698], [-4125549925514], [-3339308538740], [-12647132076906], [-1565515642652], [-954781325258], [5273296939242], [-6969226252030], [3793827157566], [-20593920260182], [-1455066513738], [13174886289210], [-9978331382192], [-18091349708118], [1398011991734], [22620105562098], [17264635520930], [1766066867760], [23784418812526], [-7619409330258], [12769504611940], [26303811434454], [-476832010298], [17483879355822], [-6483207992386], [-9924500053182], [1407680213858], [-6913431077292], [8501894648080], [8906389927830], [-7400640565418], [-8138673844338], [-11697501263262], [25040957651526], [26890425202778], [-32878001398632], [813505336302], [-41323989342786], [36122726805988], [30716569824262], [18079150700210], [-19156718903154], [63276684649980], [24036803623982], [58468516575828], [-61731447995714], [-16898554544240], [-17185564041750], [18831309968248], [49624172942742], [9347882891654], [-48494222863630], [-22568085604582], [-60539572544112], [-24693495419594], [-21575447458338], [-51516780596826], [28858463386110], [-102843712292978], [-101679228889666], [-36176675624770], [18430709624148], [54125221855126], [90518709226854], [27657624371368], [-38733292964478], [23387473764618], [-17780009687994], [-123607085070898], [70055952514246], [-6651142622178], [102656382433134], [1462339825830], [-71861358463172], [57292825990582], [15457821348050], [36204896488740], [59122666598502], [116562506890720], [-10742423268786], [90545081292090], [-173926802393912], [-2970131094938], [-11600119076598], [83180920151774], [-153435414233142], [-70281427392720], [-209756263684618], [-41500000420702], [-203450670197358], [40774277392578], [113866946901966], [265856169369722], [-225125378084000], [-170220466506990], [88280387581934], [-115907243716902], [65244268285130], [171796354203486], [-9814240419840], [59935184162138], [-179587783579752], [-221147775100274], [127437344510740], [44897278165468], [101443693556022], [-111174223135186], [-103949318049582], [-45113997193210], [-87802186553994], [-233848223220900], [113586742246308], [-368225547691866], [36284299088128], [-181767953850106], [-408776701791850], [-123379991359074], [-126489787782360], [263039409574178], [-184926588146232], [183586172536420], [244676920152414], [92304966546862], [139521764496402], [-137697138715542], [254276714829710], [287847067427046], [-490793747128620], [314878756623782], [-355110374515102], [-156981514971018], [-159738310600058], [-36329447502346], [-476835519316422], [292583342492270], [-78457748374994], [471337170491862], [-290848714964300], [332697344735910], [375999656840682], [-303694780678666], [18949473429486], [-432081782594338], [284087171366738], [326293103285926], [-33257551925360], [275630009537302], [-433469297388586], [478161155274018], [812850430547990], [-520412332801498], [403226015578608], [890674886826534], [398162958649828], [799631912614938], [-333367852432858], [-723710741422822], [-574933715412732], [-904583837371034], [-790596935480898], [-40130174995280], [-441242288501610], [122435108714802], [948782387225658], [791761006496046], [-95476404901872], [-100648194701114], [-1227462542403150], [504800972236948], [-251489152838034], [89216940464220], [716226134742818], [435765061064206], [305103662551062], [-858440611447400], [244116923084574], [109303367259808], [-1462464063144578], [-455293363965102], [-889753249457770], [-195027723086040], [485730171316126], [-1067014622324346], [-888551837302530], [97966454775522], [-1679000214884386], [-812565064348782], [95247216023690], [-769506118463100], [-921479959838892], [-526889492876954], [898867953387030], [694888011668728], [748549060968382], [500429120440962], [1531459664659694], [-747294163994274], [-1367781193084258], [960348249824020], [865803878315174], [-1146277936907142], [-148377261078954], [353868386924882], [1020519260195382], [-646017504002840], [1076337609981894], [-778732504267952], [-867396907671222], [-2981050339630], [1931246101865766], [-1713028238206378], [2105874202786418], [942034955839006], [-1989083481852138], [1381768556180010], [-1657697816242292], [1508781593265486], [2097550298837460], [192283221985562], [-2550308862111262], [792722120121348], [-2017566259705458], [1111302818528368], [81376372330102], [749530443002322], [-1298463774052786], [-1753542344614210], [1924986792337806], [-965636233614600], [1375206423227208], [-1988446218944178], [-2480109676203066], [2540061015917782], [-634074226805238], [1201709788105338], [-2640576391656060], [-2241255862010422], [1798132561707766], [-192155779866498], [-3381965388774226], [-182720631124618], [3379892199254928], [401809701565660], [1848313120985694], [-362650813758150], [-3336758206616852], [1547287405504942], [3447031523108820], [3657894699573588], [-2699598210262994], [-1549448520367290], [-3139082325350978], [2726488583277582], [-4399981381132914], [-2449280979518662], [1421841328719342], [-4484316537711260], [-355753790426346], [-2002145266241732], [-5244844343886098], [-1475848742710186], [-194434564562982], [1937960356790], [3959017116025206], [4452107720832900], [4112279013805058], [5021732202810108], [3035453732241646], [-3318465805298120], [1239732221257530], [2320855496506528], [-1924010082794838], [-268536698075950], [-2268367934275674], [4032413591463578], [1180113369366702], [-1706449898570310], [-6249999953853812], [1866657048305062], [-2299826888543598], [2513528327133974], [-4348750168819620], [2829412462439086], [1940529322067982], [6402648165440094], [2676567361961248], [3588279328284142], [5601808053352542], [57213714786720], [1774483291133618], [6131849156447262], [834332845309974], [7319143721550210], [-6233652382903778], [1726754242889898], [-5218060055832540], [-1239898591195274], [-3375396169520058], [6953620296570654], [-3037916951249730], [3261969122935768], [4522736117712600]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_10_a_j();".
// 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_400_10_a_j(:prec:=1)
    chi := MakeCharacter_400_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_400_10_a_j();".
// 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_400_10_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-174, 1]>],Snew);
    return Vf;
end function;