
// Make newform 5.24.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_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_5_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_5_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 := [18660756, -215756, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-2, 6, 0], [-431642, 387, 3]];
    Rf_basisdens := [1, 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_5_a();"
function MakeCharacter_5_a()
    N := 5;
    order := 1;
    char_gens := [2];
    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_5_a_Hecke(Kf)
    return MakeCharacter_5_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 := [[222, 1, 0], [-46476, 64, -1], [48828125, 0, 0], [-810894448, 134848, 24969], [-55095343468, -369424000, -3176250], [-1184990244666, -1088653568, 7666020], [-138701923089838, 52011875072, 392947092], [-325234681022820, -238564061696, -76236972], [-1659888970777456, 735154573120, -6575183169], [31842287955802070, -18079820219904, 221499175272], [67999176240265392, -3265191408000, -283700003250], [-161010059061744818, 330639588451840, -1507517641272], [-1452708290578190278, -749931865824000, -10025979826500], [-1774717895615178836, 1786831882165056, 9151901654523], [4086087513107791592, 10139748041326784, 7451007190041], [23880327980920028574, -18891364110000896, 139294979645004], [-140281138812701502060, 16358437670616832, -335630712239976], [-193908445941406671818, -23901724378752000, -247406271654000], [-466556181056373557788, -61496051260486208, -2014946101493343], [-136383891668990165688, 688917794172944000, -1048180970768250], [1084986169325580653594, 603928614175727360, -96940008304764], [-3387849515951436370480, 1292856678944563456, -3130025058096708], [-4788450003009155216796, -4314776175415261632, 4363465832004087], [18421036999708339733610, -4061331204010132992, -7512492359115144], [-77174992601432766599358, -3252233106127280896, 24921572003036556], [-53424953866081905467698, -59566367934728000000, 304535371599051000], [5014058246278037062624, 36694437424113454144, -238826743654938741], [-290635281958130809685348, 30168015520971293888, -276448449396914451], [213183785096449504008390, -25171890251637073408, -263907662985487656], [251412018125899493940434, -40669242149298124288, 1838580487682650680], [-967458919644885367055528, -396840549390505621824, -3629542389253529775], [-623832480288276093034308, 298338435920766480000, 4793803556862734250], [1528515157032898055468282, 1653895867870251950080, 3183858369194042208], [-2321228403283582856442940, 644142690874363623168, 15165637207385471976], [-6072873347318840690111650, 1696883729688815162880, -28735321277370474840], [-7465327517901696491759048, -4517718120798119088000, 25275366430913508750], [-6349595024943847842280298, 7764436661373747793408, 20754280605833767464], [-27957158078086094402085516, 450968256257725228352, 30290038106594932635], [20219940599506774689239312, -11063078974405089224768, -71569425310374033963], [12515458136222191397794694, -9392096166961950364160, -92541266923877263704], [39490933062687655506219420, -10076153778110126445824, 137057050713047546832], [-22485598927519257391726658, 15669808005329340160000, -221694538844773350000], [-2470138244146330394213328, -48273577205371633744000, -270716233352108235750], [699379638451658436337314, -63465446945463881146624, 105192927709389061188], [2916427676230809628249742, 112082126867864767744, 206562223194404905836], [97432263376101857521967800, 97427956472014446435840, -503186632395498069120], [-42646173108976711534406868, -31415215075913786800000, -830435602444529112750], [-987592884051199382392215256, 13708807070925755734080, -612417512070540975549], [325554033701222667646085572, -147421083851517411857984, -3858668836066139242095], [-748270784050202445028118130, -74795842525634548798464, -595250028844318863648], [-801080237327856992308536646, 94564090969470450373888, 3970482434869168376652], [-1772976299048646494751441040, 27556523661909628191488, -7801689719793303886284], [1270960693668988587957182322, -655951091130685912160000, -10645384502309605312500], [-1957014611339222822898566748, 71043639716755780464000, 14717925739550679591750], [3293232150061322946340916802, 1058391193272756822056448, -10629796399202828970456], [-6808542694533332671515000416, -847344615989421406386368, -4246627545462902250705], [615296290620317623272499430, 85615093787963922735104, 12780922341318082312128], [3135691034876265004287762912, -302840582253803301968000, 2157940518661490834250], [10065621661926504631769318622, 3335991824326763049831936, 16711051302219626322120], [8775468254626414351892773642, 3133035166853338085984000, -12548520006672074875500], [13954876732816519995240657404, 730863079339535899793728, -15326829677716784708493], [1073779612579413141027110414, -3996158273109654120479744, 75752214267415033020048], [-23597054058421604030656427148, -4369516937358112276116032, 35554468560556971508209], [-8702029519691553280132818568, 16545785416567304060080000, -151661918501292115134750], [15696492738487671792509018634, 7201340938274785394550272, -55813870175257288647000], [19453978457075300838299405462, 21167880670626454658587392, 155156792192999851431732], [-85717757012322653601631853708, 8885914190074244536976000, -284157265003524219444750], [69154012056289777447936698482, -23588631924448588208381440, 90125167555062363066168], [33785905949489698306951854892, -31269341497702307566783296, 831401303019734088840381], [-73782997213290485737176903850, -96507690129714731838945280, -64620456075496184418960], [33329014536849625216487899874, -7817255526150038645382656, 450410555812215680633784], [77369730781353405232777695640, -24114945544128659945348608, -484053199649537616955056], [36334831669327781150864533512, 52661926772466709440818112, 1200425784583803021544797], [-129610266555351029267398319106, 39445917599462552211212800, -1974238863470591217868584], [-338779119885312128209142480780, -17704205317826532387600384, 535938333669688920209412], [-372480042801597642239124693496, 94189427308564580738233408, 941306046580461482164467], [471594756831722068751689659310, 239002763923401545337939968, -844193444735114586635424], [-173845163645058943194252400058, 260862918003976322202849024, -812275653399694832828604], [641047503613323552387522889202, -264378957110533156213760000, 1385796008646917482068000], [790515646551473573609964366090, -274667028955130483068526848, -101709988169494467820236], [-605123678714449717502003331220, 620180450091902657332886784, 2819830188506765044320888], [542912902765694253303021846862, -191415165010418380736064000, -2416456139543554186719000], [-579459376350695857886781713408, 977874530757642058862960000, 4650458482319434692419250], [-908740991463392134202995058446, 47290137324995550240981248, -4023779957824067802331428], [873697344373608653245451442760, -845873449736950700190991872, -5645698638186528366998304], [-1100492767086290017474160338436, -1083574505796274829233023424, -684933071919888227043537], [-930347251254253392762203209950, -440316098275965940314479360, 11971184218322501533033980], [3665861460910564470824346723002, 30097556107584278759318528, 5355890129795751991174704], [234821388589279001067622201382, -682776445186884394410560000, -17808603056550788373729000], [1391239717616935941999349313784, 1333036761488677820577648192, 12006261123859421425961115], [5572749347550719356178951594612, 145928653336217037778383552, -4419271503593872428022323], [-953400212853358139221483170880, 897442142352967009421614336, -11718653354046147631180548], [2896699152390501973847788767632, 2252026034561015458060393920, -8090741493386135709117987], [8001521328436512035433345035572, -3170996109594348986694800000, -17656482656626918198334250], [3198940103894038213185035949500, -5386725813084395548845222400, 10767491325357997792919700], [3748012482099216350748132795024, -2393664955714455518858969536, 1283000921210817298753299], [7560040137395350235773671271990, 161400203483335523411868672, 11560312138675340901647904], [-1486262016645651687822922328838, 5441142546924824503482368000, 29710935261289236721200000], [-1615132351022074579551954211956, 5129483603178333045126963520, 59059133639698530250468131], [-21071752703971514408649226468778, -5672822028668640592527040000, 10397171856327581035833000], [-7205916503168559800885992142908, -159852363230573358422142016, -36921664635436045973717559], [12272075858138699935981385716102, 153245555205641096639917568, 19720683397807476700115784], [13034873355495900304836470042884, -4379992016675050035639598528, 67162500806053406004116775], [5157531229533418037859246513130, -14660415008216090421176417536, 127073364816719490701306148], [-23760049457903387085732592544188, 6771094485622285821871824000, -22141771919976964894023750], [13026743736276326326293143625922, 15664180005605662936571155456, 61640353147374255047702160], [-872136959711537615791523343268, -25751859316244094932868875840, 258039753690884829649953993], [29256355246483926106328259873714, -23528910393678022335280559104, -306022754185660043900557872], [-74687062278607215733490939236600, 26217208481926470599170571520, 178219551444790362918031140], [-13343009383423001769642704886198, 43312099427611392812015072000, 63629135006501518796926500], [13015826394417646675185052484152, -6357337228968753652253358912, 98672914846049364938575449], [92618295766470796969207084517934, -3403717340730929839159877888, 86252200957016423769322980], [42056280525051616251190522696762, 2366707611660475602424339712, -144391619362358481405116628], [-26024328893885389658119042815420, -4296749672861081120450622976, -30350785211922869998990932], [-74241030177733848370037748992808, -43192709882214614014780976000, -339127956740532846662057250], [-43155891853006392869394028632478, 38710758511134482271314080000, -594788694013629187873276500], [15149231451715499168051120631764, -79117574222535452181659881664, -63572597593872990948514317], [-168488198423241129362662665633808, 28785629035831036137639986624, 290519277732974190062824221], [110931959426302655692790459383174, 89603777028705423282861155584, 158490897190930087105191564], [85805560415566797683329491473340, 23728395044678795026413789952, -662928874544697232662257136], [-40904787269421373750499288482018, -141424754892342707261613952000, -58365180498658465047090000], [168183299884852043071904376448194, 2836914312274772888384490240, -1033391630624737521865363404], [110193503533246609320463264055022, 72583708458289894133915287296, 62649423748232202025754340], [-129646845868794969356347905362196, 66003781358496160841787824448, 944006065379337989967445347], [-270314741869668831480620777391828, -2697821892956744376234320000, 68915038753901564914959750], [447438993205475922118006707146102, -25623334445754576257759424000, 361191156519534560823051000], [-435820401429274978467983032536210, 80709432438243620993902899712, 1165673574566019747524186184], [-66616919458891958032133508977520, -278793264112356664666405913856, 1321709679716546634151009908], [114468102117523588294150843139072, 69245224469516546841870465216, 176114081030898883171720305], [-378072312140824913318583835847146, -531001359046893350578409075712, 260756943397482239586755952], [-736539177249083238474703358451540, 213036679115134307236678521088, 131647935536987646048565416], [-513874834889318791027045912103136, 236809693226961547212793201216, -151171278200250358188366957], [-980125896184920502259425537665248, -196135691852167367249395632000, 925715871499801687959333750], [-823631381714525516019253917045698, 228010740612316829279428251648, -3708704487864983926372501056], [-182406908589296555534906669593718, 158079337318568621684258816000, 5439119494874242478505768000], [-1018257513945052216605227099611070, 317626202070126966231117320704, -4822311281511926803779573672], [-1236395159244775756845925523574706, 254874685111802852319249982720, -6353503560622321610579129844], [-201387063266899322585526633173068, -963767220198751207313067223360, 4584107677788316657089363453], [-256019878207502526325500683931658, -279822886509045895683735196416, -1055399637153044627285822484], [41367045643248531398180480169690, -441470961892713036385579552768, -10842197094136785398524858176], [596266010814869178075661202642932, 1016280760190332062064192112000, -1257070458008755043873930250], [1832876540906561528652178815344062, 191255273517971550286885568000, 7296764247904930568349837000], [-875731438523536241427499981848656, 463292003576803204074929008960, -9418318426425697768489903689], [2094350592446715547541986503276172, -576499456640913235384011802944, 3382536633628302938880778485], [-688681614429609171330903752918730, 2167812046925736649059283577856, 7021470635318483405082368592], [2823217379805745601950170004190360, 244489506817383648431015217408, -10644168348288398776609718844], [4454547074597490281429115237669374, -136148424703394419572017728256, -11440082318557338678533588916], [5664200530479772063620331766247402, 1011794576493956189186051250688, -4722251665250771474947739976], [-2498722758860425981614415054134860, -1749517568982992744367080587008, 6463660150675818413265264144], [-4182848158742755534602736666461816, -182764992208870313657296746688, 8209361768246348574142011255], [-591547706334218289618425171142778, -1194268083642341879290609409024, 701241136245472037262349200], [1283259295218541307708709365675442, -791503141180646557104498848000, 3230397273658689468543460500], [-3147111193808970895257659457103996, 3006723072988394511632941727808, 6068618903981170314208546767], [3185836935387128142014639401696032, -3929454964815093034572797901120, 687634471381705411029869433], [-13865673104277985645237879522432548, -1111326187693106267227679817792, 9416638425771848042947324689], [13593714784531914142390159072551232, 825281972353876657546134288000, -11710236029500836238768277250], [-740806964932568165046873859721720, -3490818050794116267673370255616, -21694648031745150495581537412], [4385901538660987747596412780431170, 648862638473521520122716984576, -13349066704925400149362196868], [-2255286808629164281098340421758918, -2462230040083401479838134432000, 60450082074519083822187712548], [14176283892060356176985309944956422, -2899740241466265495847943808000, -44729233414369997164876488000], [-10227383107069461368995265833450508, -2401986518603438735453706619456, 24066179015627974239949332561], [-694080940652391058153649646361526, 7074043722133122225633680077824, 24328653847555046592096631344], [-7844291844584794548641518232107888, 3918206026371276412611018562752, -70536695915789888449967217423], [-5922166814480148397098979919686988, 5382689922903964406129485136000, -28123384719148587751950963750], [-4379173192335907223603206067245678, 3385679185275705069726748034816, 20915881500519038785228981380], [7953254131410487281755460792697104, -5387706005036891776616684152512, 80299844875060890144308468727], [-23741155001979857985401669709262928, 1711756533513574298179935952000, 52181090328439846930250613750], [21569366862160406276179729704266542, 3820678453636727408698168196864, 56045440544082445250000243076]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5_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_5_24_a_a(:prec:=3)
    chi := MakeCharacter_5_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_5_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_5_24_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,24,sign)));
    Vf := Kernel([<2,R![5728572416, -7619376, -666, 1]>],Snew);
    return Vf;
end function;