
// Make newform 4.24.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4_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_4_24_a_a();".
// 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_4_24_a_a();".
// 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
        poly := [-618312, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-192, 384]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4_a();"
function MakeCharacter_4_a()
    N := 4;
    order := 1;
    char_gens := [3];
    v := [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_4_a_Hecke(Kf)
    return MakeCharacter_4_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 := 24;
    raw_aps := [[0, 0], [85260, -1], [-46133010, 540], [96041720, -2106], [-623587347900, 2983365], [-3730149990490, -22978404], [-187448673951630, -148205592], [-420180139606276, -153252405], [3216678961536360, 11230584498], [-34027749623717226, 111255541740], [-72792257273422624, -638955815400], [605947071775578830, -1437407022996], [2518389183567344346, -6392398005360], [467590472959967780, 13445936110845], [-4215584448138798000, -59591327627772], [1881568598685102270, -42305364395028], [174280803256450693908, 418202976769065], [-291483296360355677578, -440318419808580], [105807634422707327180, 1905529275465039], [1920023878566772005048, 1924700485055670], [-340333125956797048390, 8794324601147016], [-321495697653361820368, 16664050979942940], [-9399751316254358885700, 4712530604907483], [2500699389441625069866, 67926459439942920], [61011397130279910307490, 119382738980386824], [-4986939593945732839794, -154130628322463220], [-133203066698168860507240, 85417398805629582], [-265557670925160132357660, 174008366896455693], [110039738532074182882118, -460840567125303540], [-55102757224703219566830, 456701352187211712], [-21858548737070907640960, 5417763281415473184], [-841380279032706028528500, -9960109380744628545], [-2245031957034746457596550, -2911864243734162864], [4275668938405210107451844, 10784976070691608965], [-11459512979273758569829794, 6092704704647701980], [572277782008822415116520, -56340410674799132910], [7120490060454615662038550, 60906946456922573916], [11800156441616757208766060, -7274555517182973705], [-18937220238045106574126760, 103511286054599356926], [-29819939619322652316354810, -55849257368697282948], [-47867319717418176770339748, -232199899282307841885], [-74360501635551224255235010, 136232141925250977660], [227150400853976099320358208, 9225018290772703440], [55112756074212211074861890, -471359641482836665272], [126441322210342305699513390, -381251093905732167684], [185803652768307718844507192, -474571453929022224810], [-833665708312734832840654276, 756327318471324129915], [414102254974399624368112160, -77335156092071182680], [431315385326400468987859500, -4429959252478539191577], [376406175337163769388104206, -2160728371902871026180], [556241469989044633210422810, 6102871739585523918792], [954020092027652244514494864, 3622825968586424751060], [-1294407879750468389476150126, -7116506261702488292760], [412232990095505984249596500, -6984781989038091051975], [-1678654459076379198666828030, 12733877664962876832768], [7384177717681221464687272440, -11993526466002575920314], [-8604827595789583855795469658, -17273803824496683577620], [5968609865942486199835191920, -23525330380664363912340], [-369895930248109325732768290, 4480223283144063811692], [-4861531061808894222029048214, -44235244626954828877080], [3750943951329495195691191860, -36682246988013894028623], [746741318541542069299105230, 103318492276397334720060], [-46331032115683726318497117220, 47274413452192620213219], [-43495815102430988928732099768, 149883886447777302392970], [34481047208505185364370212170, -131132229436130861347056], [-7021217063588572030854400650, -72979663808587509734292], [-28995197380569187555695654652, 160373090854373591098485], [-141042393739539876737732302030, 230345352029793203519904], [110048541976115142476294641140, -573775941061978486155135], [-108355721917999587447707256490, -188774479857171897495540], [215108395211450006523391581090, 570638228624210419140384], [82244876096610153586467633816, 382453358716574679102030], [-281626519786123452157134922480, -476924429803907580456204], [405387964614643844325206307710, -528569577169674082754292], [-100131742779852868776137082412, -1387262545449747889508775], [51111590298303836163454945920, -971230931826539660570592], [-310669572285828798281715033234, 1878492689839981675576620], [-247696477714326747376685680090, 3978573325476906787158924], [-365126630221072118589079772430, -4151538307577297958413400], [-66073041138052248453844522006, 1823137865419337252047440], [-304086031212593641014080250516, 281237353484527753197975], [-1673608430614289121323520754354, -89620279464663606772260], [-2617750208021011934316476487984, 1087695589484133827198820], [2309051800078716766190493421010, -816882677643307083378264], [906102108869055228937963034312, -3521256598195699953060630], [3257341209652922546772148720020, -1245424129028701683093207], [-425445048836982437201616502206, 1672962838632353701830600], [1397306096773799022988322954810, -12428361335294479145431728], [-3800216479695217003629816108570, -6259065832215724816911060], [-462840202047045071518739179600, 6408270486735376353434172], [-2709315582096586883735701374660, -11691503905435025205995685], [7012022921136994737527741270304, -6632931006104397617145240], [4271717678671890593776428525080, -25221839363157806187943698], [3568539683010390268710270924900, 27664334848914090127786125], [-8414245072328648019104689082596, 18506175902021606284627155], [14922142782723521539720517786760, 24852340186264916456530266], [-7809615086635673510293475913546, 2506219742623217108221980], [-612007654964966872427564267526, -63562710377575033656879600], [-13756514404964378754794811629500, 51307670783761386496056837], [28316232033056063406001194189974, -22205792146067955385676100], [-11537724162983591998620835162900, -44256152805584204541832713], [-30562833366392829011670490935930, -16403159045530931019407460], [-50848387347076812019595018052900, 35980451946036280795413411], [-27341642238914216935958351688630, 55959623052624780342512400], [-655014970933344696873860189932, 158470582270657907815209225], [60672118235285038618989182528450, 36877908886623792161330976], [36162775914443609648661289342980, -69121181187302329278290187], [-125722178585718478316247283750350, 25993214557505525963191104], [-1610894850301335827190988906200, -334214605592268902746578270], [-4835442089352295140191091972310, -63907650351034854565292280], [-30586705854531402661887646253920, 162425796407199931302039816], [-115833214728115387597268241569650, -241645767693806714411357604], [-7852605179036607636318143801190, -415120247381224767537778392], [87968748338826622389493521604580, -313228434980721403283142195], [42745729153975281580040253057032, 422807879061240395224284090], [74870286686053169271721549452162, 99413315742887162900319240], [-258309999409694993128262442186100, 35627001624863098228240767], [33370325675071388844279337374840, -157860784250434972883681946], [33779729952004741196995333226790, -715739937231368594267762004], [154416657354936721259885487488124, 974765597739000124264779915], [-43685314263243075200237003534242, 534576509678877403832558460], [118953947078307945528239150234210, 563660432743357576787823432], [250082677961948605158800574246990, 593787213850859526903594156], [150750976524938144236261040586660, 533906041095227632620711069], [308172283634866174798229531060828, -1268875522364870914596235485], [108470993877977176961530512762870, -1256432111023173449380307460], [-68069506140547724442388116234706, -302414308700464526419504980], [516431516501619800348841105530544, -1093159331739190409802256260], [-313104400255057408541967106044760, 3249094972479683513426089218], [954442221938768038076132329398230, 1496375169576570843367433004], [-345744440491216119467382000881620, 1092905309525274200427475815], [1168096123004837709107618585861400, -196228365103929587412262482], [380149579200115005117721133303696, 4100588513733664822637717460], [214376164248107084437310651633150, -582297911669482836487674084], [-1411344949694454967427306614546038, 3446978999429687420499382800], [-1058642565787572808879849576337662, -338289003161112127754437560], [-359617666885537965198239316598290, 4268091410656593051726202860], [-625970244962390886768503220857860, -4693244691058894027814165973], [-656682457001322974833759297332330, -555128688816832456066512996], [-405391762397420557992194222012454, -14193988778236624409799759600], [-4636729787428637134445906625018076, -1705652375223091197346825635], [-578089080363812180165733722823234, -300565882654379123563080180], [616442129836189592190658655353160, -8880888441061666125448281846], [936969583965269498450488698634260, 4939228123587979255788973065], [-3939335269194999487112072393519242, 4778415089423921890081066140], [-1976541669771396937383223175385672, -4985968925052425690679245130], [-4993409090265288957785465744371810, 9073224273640008778129147500], [595500873383144213786512247973930, 12134315178799654215899434896], [1864138779064253201326915883365364, 26960472331765742615022030465], [2464715265774616742208594080879520, 1479948753138700112898964488], [371349397996773634920872117893190, 24746265302684450728199074092], [796254226314606236705095880193042, -18408533504874423686048849760], [420612054761668984782313545653660, 14754499525648507640251347027], [-7684213284407752675430847107141880, -2378044087965979979165059014], [6217516599052226382409739242653380, 27688053363505058247399563013], [-3212771790421439597438704719229968, 10712543979264193398004698060], [6849371428598470206114169135377896, -27996072487505042096059645230], [-2306904050129451858625586441244318, 75189153737413210474650388680], [-18959029430420141453527398104354470, -33807032391541430820274626744], [1932325554749459484919491402848262, -32741301766032390711974164020], [3734191950112285405692872639803740, -80096088906498076804620184509], [-20121552631724179200599409389680950, -38098513683936931429333927728], [23844756471961475805675780319521080, -7166863768854833199657342954], [12261297165617781083879690505752196, 13949309796631901130455944245], [20804457611110343053958143244590770, -5627001547489920926099416344], [-7570934378083917089791547318008920, -42530255407639716463457955774], [13306045635593964118557577688565536, -125651695333478612647711423320], [-5152749978504648866732280481676530, 27206950250899115282265223212]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4_24_a_a();".
// 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_4_24_a_a(:prec:=2)
    chi := MakeCharacter_4_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 24));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_4_24_a_a();".
// 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_4_24_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,24,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;