
// Make newform 400.10.a.e in Magma, downloaded from the LMFDB on 01 October 2025.
// 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_e();".
// 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_e();".
// 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 := 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]];
    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], [-48], [0], [-532], [33180], [99682], [443454], [357244], [-142956], [1527966], [-7323416], [2666842], [-7939014], [-21174520], [16059636], [87822234], [-120625212], [93576542], [193621688], [-417763488], [450372742], [91425472], [-652637376], [-170059206], [10947022], [1099628646], [-1358777644], [1559878896], [155615342], [-2299456146], [-5392040092], [2666434260], [2055884598], [6761768884], [1300092054], [9202347760], [6773449378], [11544980000], [3998967612], [-10431143406], [-3862564308], [-20099356330], [6092623512], [17436969166], [17618292618], [27211845112], [-44038251164], [-24752350900], [52233132696], [48518735174], [15597760134], [78774848064], [91232959874], [1227792300], [56445682974], [-140882893692], [46218406638], [48888305800], [-16073433494], [-14626681014], [92449119896], [-148755577350], [245184085928], [92959784448], [-244767736922], [280185289074], [44320793452], [412784396302], [27096157920], [-188319351490], [-101309430402], [71999204376], [343665128132], [142006871626], [79043454868], [291619740204], [847185014694], [85608130402], [605160826770], [-209246967094], [540287820444], [-358322867674], [-583728991416], [1257535351102], [214988321032], [-1509978116376], [1066387221906], [389933706166], [549112375950], [199371487196], [-793834531080], [-1771751773776], [1621317414044], [907687391100], [268633343644], [1302596692548], [345797738526], [-1026113077686], [1972888695176], [-3198568677346], [-295149549256], [766146556050], [1827708894048], [-1825834826070], [-2725624570148], [-4119380054402], [-5277128507904], [-3368363412882], [-2927134785960], [-1006363924150], [3319106638052], [-969366007478], [3769238433414], [-3724538390780], [1862290364368], [4041047003922], [-4437517192864], [-6018349990212], [7431348250242], [-3402886154676], [4852829388278], [3907400195374], [-4282341171702], [3059775688872], [-11439909466508], [7768615827390], [-6472445866234], [-6995610895776], [-2680442663524], [8185301494018], [3295135577500], [-1286349366156], [14100921071224], [4942220825578], [-6658606615878], [-12079714013278], [-18484707522870], [12737195859704], [22689480778482], [16884104208234], [3726956315836], [-6879505123914], [16251447693332], [10115993934240], [-452458295458], [2434860423528], [-6227367394310], [13776820391238], [5052475594564], [8533235879964], [25454154906226], [9535577993442], [-25929755139904], [-17674373160228], [13309723172576], [15864729139128], [29544650579896], [29711277798258], [-8007239676122], [3120327627342], [1954977886632], [13018974067014], [36662141775692], [-33668576766516], [13224071645118], [7765230634548], [-7588534751096], [-15907735689014], [39257864987090], [37040669414778], [33808107133524], [-15136836259426], [38184325923888], [15429777424102], [2366895784336], [-66553885532358], [-16848969990308], [30704702370054], [41678439719780], [-14484515800306], [-15349050780268], [-16904709566508], [-40693558788182], [-7498872321210], [85580635541772], [45141262376790], [9930684815074], [-29955777625984], [-6969864963238], [28938132396648], [-77717407178882], [-62789154258504], [59204901832660], [-113890828888770], [85352140030056], [58171806897894], [23692264369634], [-52534007698574], [-87546812270850], [105517162045620], [-75920939783154], [74458184913448], [-36115016206502], [-9941300214046], [-117985665417420], [-154127239485726], [-51469571427392], [-96736685585760], [-151875559222806], [-121432861176116], [-96632556251234], [107220109854102], [-1168972053004], [13857191545776], [132862215703368], [-65264080487110], [-208825284775180], [-58329130768302], [228556644297612], [205313414902578], [45228715424966], [-11908161992072], [-24919431177822], [175446186484844], [-1318366322856], [227001063137078], [-36361255633770], [3244713393600], [-126837430491028], [-260177385029556], [-103300840726046], [-182946873510308], [274426605801112], [-347149430304006], [185882401099928], [-253302141543660], [-133436801233438], [-140551928873958], [108733386776340], [182766586143600], [-169857364419744], [120039262921324], [274350395208020], [313472645387630], [15195802595790], [253694201616456], [3034316451620], [419067596011812], [-343190240151596], [375925610038812], [122608312713970], [335869087969218], [119216426722236], [423497612618234], [151483003840914], [349228219663068], [-426323669698858], [231795981371936], [-193660781712678], [293529540003910], [-475823113791748], [183130710539448], [-628842621749146], [87415445924290], [300217668475662], [238908125347756], [451111433190606], [33923558190522], [-618657946663192], [204714031575162], [405198758369582], [381898176527288], [313998283925206], [-664162196869664], [-7845769731122], [-125743650161692], [87882759568752], [-437891680216450], [-39725004908422], [297588095523588], [377994740259612], [759387637689424], [-113941210190052], [-623321597243098], [-221389466094784], [923709333623736], [-475536223150274], [681242350820250], [11923660242520], [-310047366209742], [715589984529198], [-841424052653352], [-905997372629322], [1124645431626492], [-470879410889774], [331056578898078], [-366589698753368], [-70223933452758], [-1101143450476140], [-247682388600664], [-937699982922890], [658043332569906], [598533499091488], [1077315438683088], [-489800974997972], [381160817835502], [-475378931174016], [544243344205550], [656933405335656], [1374554503582522], [125777873520156], [-1406043038680650], [-1167292641864990], [896740471366832], [-998938360948740], [176329356343754], [-525500518434564], [-1027644319419192], [1068438716552926], [516948185575458], [-459633514904588], [-1015536079175258], [355387256753790], [-1347722685856756], [1197414880665270], [1063124863164866], [-1323371859530708], [1152247968344360], [-1529298626339676], [1598617854216906], [-785362337782930], [-943647690391518], [1110313956482320], [1525931848763952], [-751001414731364], [-2403839147376864], [-2371098820122850], [227063064140190], [-773438455816294], [-2154435648656092], [356918981250922], [-1011392598216378], [1425725130512646], [713604825039520], [-823902556830942], [2176743836708268], [-47391145430650], [-2241359294336464], [144847570550136], [-1154802677013222], [2671584773510260], [-554956735561706], [-395112381226578], [-372399662658292], [-124608248650954], [169256727457782], [-1858876556670192], [1872989602469292], [1034842350659742], [2495991284314596], [-471519231740246], [1493455612717386], [752175027118404], [282860545848036], [-92702386180600], [777209239575334], [2222043166647330], [-2111315773195996], [-3320684815994710], [1192289822888532], [-178512656788988], [64986830511612], [-2708932949943690], [-3894798375187184], [921708617611570], [-1075406770349892], [-3421843549274232], [-2586172177651106], [2838650628192066], [-2324568604650458], [1446989458041822], [4091508712094742], [3761479535235356], [719849982417438], [-192427267962836], [-2534319165542076], [-3873540044941112], [4038619485177610], [-518228510090488], [4070232642433188], [-1099729749337390], [1160561509620282], [4973105173096596], [803259671228600], [2787439208676624], [-2526971979866], [-277348345074608], [-3091314010569366], [-1015738205351972], [3088106906394966], [2237596433266430], [2033284439358510], [-337522475957788], [-2083340194055322], [-1786782785639610], [-2335256123502080], [2566836385955170], [4875166363875378], [4839296615964512], [3521764094431260], [-3315274731765746], [-3384134567938902], [4541554017458328], [-1833720163865612], [2337661430827174], [1344161577219054], [1078505535601344], [-2435582981146372], [-5807282798711970], [1037910413309604], [-3745846917132930], [2068041369372682], [5326042023844116], [3996435670366500], [-2338066775306], [4616259671772978], [2410380789704208], [-7868563974299766], [221170874408188], [-5071621585957176]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_10_a_e();".
// 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_e(: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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![48, 1]>],Snew);
    return Vf;
end function;