
// Make newform 48.24.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_48_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_48_24_a_b();".
// 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_48_24_a_b();".
// 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_48_a();"
function MakeCharacter_48_a()
    N := 48;
    order := 1;
    char_gens := [31, 37, 17];
    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_48_a_Hecke(Kf)
    return MakeCharacter_48_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], [-177147], [-35483250], [2385847912], [-427835351460], [4303510800614], [-211566679094862], [303299666491876], [4084826356392600], [-76724512266210954], [95662499637633472], [1916787087325361486], [-3821928337631245926], [5028833488465187068], [20587597004644658160], [-17205347518114927842], [-109297555349407820340], [475260275455205930870], [-472131632539902962348], [3017521662759223717320], [4697126809344265031354], [-9688757824459562759312], [-9020535128755560906204], [-7813973672159946207318], [-57431905133561269660894], [-115979920114430361490962], [175356915235293312318088], [-142393710912902051521284], [-42978645388494387682810], [613546266289012654632594], [1959552767479273317270880], [-709683176762506909208940], [-401532828062468535429702], [-4992157278934946828180324], [-7072811045321461732479234], [-862065265283118854580488], [-20949584070949921772099434], [-10224693106256781637850252], [-65047667023613195622936600], [14365044717595139368223526], [-146619728000950028170198716], [-85808824193079108786089986], [257595150545847512979854784], [-271961961190857797339407294], [-222519362433292511046378738], [-309110945344480945751451032], [-830826685221331560261119900], [-582216344591656589718100160], [-537591197864962778369620044], [488639918299316354055529550], [-2898722282042266650607743846], [763733388064297857152475504], [-1875703073420365199154881518], [-1478255100001307488830669876], [6128540297547952587363998466], [1397507784762644851896215880], [649584616739180217732935046], [16101863359744996808064125296], [3218290878078382870496786846], [4955401583162236646360851818], [-28596275789524293071149456724], [31524341373312764873214129198], [22645395589315374541176217540], [50812371830715044635697927160], [-33454537678826459626994108086], [31886748816395950236709299414], [166919737489119861360685129948], [198063153560642736426155459378], [-23590328568890097348289287636], [-45797334891168341937315557290], [-202926162819222038782529381598], [14855032524472352166231502056], [-87225138051330016880327292656], [118888092401153599377545843582], [-343992733294045035618622659764], [-235072029041697722122893655680], [-49993009739026072900039336434], [-383153512440258036926134400986], [-885838334716455622260351583566], [-1136558478340187702727493432726], [-1228024293532482116566098542220], [208954900103086182801376532750], [-2187089486356332583444681017360], [648538220927879753621855858642], [2395462524158894630934539172568], [-1128383180330191240320313766004], [-716916343583292009032453522814], [2083163453264935409094472124858], [-5585012458877360825124726878970], [806785487013669721565870705968], [6092371499733209376358407228708], [6954612800762081817323712711456], [-8035713353649967810654601370296], [-16098707409848823823822631745924], [20034494922672691686557336268676], [10526037717735315526400256463992], [-11131955576791755531820486026474], [-15121718013130629403350843057222], [10133581333660151481886565850460], [-3927903222433608930122764985770], [-50802153610662304767566414701196], [-53270341148367973195395820120026], [-63501907213618322059134244829436], [-28164805168929788679956829023478], [-1675828023689867601065617284020], [107229022261845883252284581682626], [-123743667188108248493771195436324], [-130127528358551485363187489797710], [-85824367528250093628984594852264], [-35479455395015827603310861027542], [-108336103239862723807828479601088], [-91700073148630811110491441521266], [240716714984468124397762727192730], [150898659685160001148610135462524], [164482282646284439803763696077528], [-111001103251883412340274957379390], [332441648197786448523675366331348], [-167496272733020017373378310406392], [73257283882001846279086851821766], [-60385828736615778355857089351772], [376424958759166697435125477916894], [392456386419547891464701575782242], [-122862406444962103043166556567698], [586595711507523171040531126346364], [-125068727866596303728510448726524], [-869124333303741045193459276450986], [-734080237392300694595322642175378], [1152506069923181524218205874367120], [395292653263382623347045195147064], [-803668252862438187985320513069034], [-184582028760034744722102970947212], [-2054533451806650675855645369223512], [996860881687334736683521757339920], [-1144074942559529450836462449401794], [1028523093994624536181203094574538], [-1159659332343324064364819953960702], [-2377170841302628840672685194487346], [-422154304470845837261560731241628], [-1849056784894158546709118521300170], [3424970673565959526669841824649754], [-2275836981712262871394511677092356], [-5019215730072857519925963772386402], [3434018378635561254577108633048600], [6155119819532404256237649416795724], [-4407164240608802214899125332324298], [3660891901376169605281918392118344], [676756728546629483491509489713438], [3945696369531969462019973525125866], [-6909773430736543862920518901858004], [-2536568012715566099122250008318368], [-6497749323578350170661366690647994], [5941050691508198312211307163190546], [4540826890174240127479002615067588], [5732538882451642140528900573115320], [14271418519201279021931783272079068], [14638854223993994883054634873801488], [-2696023233968075563816490931262856], [14910767837600180661565302183176226], [10044080001893261943129166985796698], [-9168421107562135529373571231500762], [9715919859408309584845119773584452], [24320843909783780228110396859334282], [-6143324598146665014979977735751448], [-14866325318131773374074418576981604], [-32858568556942959106814908336124046], [-12528876025032793671242091627899112], [-2950004606974896368722949624094464], [-47857032830234739252562933097569522], [-13511043997588157069412393606879982], [13513978185917509415486364509309982], [-42947156220526890190945783058337012], [-19592244058821760137769850960404426], [35329738480282302170717872258437576], [-36477650206924935717195916529853190], [-56911895786891082216326955114668624], [-87402741350004789817874158762775958], [-12633973221064184263608016311571028], [43159155766822635096338403820133742], [57805489589835983088132819165370696], [120355961726396681416947739469626886], [105792637630965486714643611786473056], [-1054935893047461320658306836847468], [17713437841602119567793112963993070], [109058604713814444199596395164641978], [-92190547729544638532295539821717680], [154768716988837533885517470006980286], [206172058273810217712984983157107606], [86011491043163951826861004160742004], [-179555752909446338328720495100952806], [73883923258724457945641789306108544], [-205494106228822642934824214102603134], [-149510489915416942485206927809843044], [259969221199879965368770989201425188], [107535620657970329947121526623688630], [-347872545339874274469653278614381132], [95558896591143346707825824978883162], [-122165755620396754413863305121935150], [-234084314751497454923141001874606282], [-260216514905040744089926770575801790], [300823715467001123902337687078377608], [126546612750133176687034296171545862], [393763553630864746061695503780127792], [478916665178095545684436577005997534], [24199602483108573460870013666540066], [136609288220321995006870350793818300], [-277346509012105800428655561994004970], [-155274508904668902909545166781916960], [796520725229580832277999776423123284], [-198988182287200630817208823859881350], [-374406753448210458155006263782398372], [-452562850179252580549664146886383246], [678982672095720376305747426760058622], [981733257838436747489643515754941752], [-941630821602329279937669677958802260], [-1288881183333122411701245132498761688], [-1343316211782684271664303960661391654], [-266237797600129579291132303092593840], [1631594162239923543123861641561879154], [2084067539432957033154004575256431768], [804483655862180810363623977641556342], [679775445185681182296636165605100110], [844186305352810280264992220338742680], [55345848005117228204044142247615810], [-906423940359239310224225695427123216], [806852422590346843769088706514933604], [-1163852172837528141459032258863331362], [2210462639043437266523233543932820842], [91408304984107671106539237633143520], [-1998076367920844755565000614088459960], [-795144649906044011066954636870489028], [-1152430033586687412743929846293005626], [-3416487196545265537463129338043554940], [2754434714348370827794852475262581536], [1636398533073110934525808178143608378], [-893859155011376580795867593796187364], [2988477269299522584630315783736084752], [3115697434433766477874226536255603250], [-3570919288332011331856396168535089218], [3189150372740468761316467327004402988], [-4565152770931629207805247671425691032], [3321999853414751018059996378222587588], [-94922237261181858828658685067448820], [159551889609442689233025410714420584], [7101073331679857913852861397888053542], [1933323833782587124629129123777166962], [50984343512995127204691871832314392], [-8042817564907461504716993815656828224], [5113703652696694723465450463773564596], [-5239729049147908037628583666978963268], [-11785319180482306048172467884977807952], [593787364423872469328229530605625654], [1810664761607389511815790792206129986], [5734549656263591999460412962726940104], [-52661683099086838801949874384093766], [-6695296634475848486512943315124464058], [-7122236598695566920300700384897965468], [-14691293271436895573803957773292556194], [-1917698497679920437955400353097056916], [5455768913406826334599945799327289966], [882900072420265624297803262811865866], [15585026928261572160851824107370035040], [-6383190202744763212186742723604642924], [-1717426159892351570853409105951217362], [15602692096138977831980244099199062422], [-15896467273885270338317306547409435614], [9415174944292596596015380707974449204], [-5445336018684607877377486408238357850], [-7844977484413666895548389941387723958], [-11372946505371457266320091561937387508], [-2080490187437482045116813446313855282], [13527300696330547308353558420791935206], [-17383659067412855438544052659200184860], [16068496714270095393224045728165955498], [-4971734199422850625905041225968209920], [13626761453190885191177311216458980498], [17711933511994491700120926756494679064], [-30740056740540773513603706673798282932], [-42326626483948166473049335366083732298], [-18255247619428356834456337324799754502], [22223151868336139696208670019321044260], [-14074926196963660527487782254917324704], [48294758806088765696563824770305881160], [-52468244057310882412129315848019143624], [65426304701632626924656356637940728750], [-55558209162887329639406072574171730148], [-26355474731968824941728277045185038384], [-25629896841599042458980577955103084622], [50997385814807423325355024001640625086], [-60858598643227778829165011003085121352], [-8586704719269914774830429249950196446], [24315166004391595667608658908442863590], [92414591386432457517554805931345961220], [30530548795317674579998116667483445898], [-56605252198319655902159481416053575780], [82862520024199407225878592962239361702], [31684044878803271100814050620298951222], [12880779679509455421654678452560987264], [89767426388761043430507919841951090334], [143427475112066976586405324200683843340], [-62726121532330219010763545009809204076], [18004638884140206244877242434224680250], [-86541384943552107889452794849632694394], [117658351148263729269322989801212479600], [-29152381643791045843045965393574276764], [29728048822537503544436882981213758252], [-106793722131821725820357348720760578398], [160942179382359437083838636313543511356], [64202141476428643719695184206198746886], [87528970382224435501564784037517918968], [58510933179144710354246284637089074158], [-81153774698989390117796478508824839664], [120500567745495095562393186901067871294], [100959638970013143344951694854605521186], [-219390628162242247115910097730618613644], [-25658934619089328326980406087223768344], [131587561902754464706762336753067322074], [76026168399367730172844958294047755588], [-78817257977631256482826774577494769664], [68473641865113345472036481704371860930], [-251155224434780080486878710055412269390], [11355606216331189470962039045841096676], [-60938374565151352688509030211624651734], [193510650290969419019509233347658139446], [70758987961998522513498965667428858368], [-198216769693622352359730365962599689382], [-264338307345205231015475804586429751918], [27619895289932325943156502281951724500], [-157550476221081355380449408819883372308], [-247599925031671477605543423491597591904], [114362742324584120951996686089328525038], [-455024903875893677205436651381881112378], [-606381738906570068319528727982219893482], [-81009668850647494837545248240806140128], [306802840587308053814658797810880773460], [92901799521509398442162007214857008092], [526906921373432002258316007860724398892], [337827951877956535987656651096630528854], [-443564976581708639503233442453003024734], [265462706517362987273636614156943635994], [379789380626616539593133172931442349520], [-410819152609674838092076991666191268482], [170014589873250471870703373024200529994], [-490630631507486721564266227847327930802], [9815418118567469777235137662432072360], [-936362090498538989548206813878084321034], [-364362603569959450937534910991091796876], [419051904387453580238565451034084911118], [-218063562285181672275624503899439247428], [246452145790597982258107744848339113712], [565467752293948474309901568542915481246], [873516497241449923362155087861328581140], [412753650005778218926273385639347628090], [-544811203879880186482378032525980825658], [291554184471963678713018056690344084016], [-990075424326273290657368508485720601314], [-330081912901352277350905367301916199382], [-858460552941468932464976024659148325408], [-1479560962172972713684490427500428475652], [843807637926990399579136962242834232402], [-648420642684897961427337252825405167304], [385596327462201148414363053564698532590], [-710845329972091153135766875035315662598], [-939104439266343574941862446393459220080], [427849504550761677231956649146876533740], [-802442968615499408667144733938209123276], [-1513696717693834727023734805142502755494], [665144753685106948781135259282895755750], [815606820143488041826962656020899068584], [1439524931459125425145797088706345585066], [1887962287667871280555410204556813427124], [-2568570514105932660865003122830674420676], [-2331937681482346700080062583373097425424], [574091793959319315316501998135022214238], [-1364117799706963288357458951240926419880], [-1141699077415598642853313814485159762186], [1307187122648880929213813305856358756324], [1183262002740072947993638478531262810912], [-560058832012229044854886384025666904862], [24617804284072436942731038417628462098], [-3187173838783766133039473848392777814582], [3521059670033450040415697725860295035798], [491801423156568230024785323016818674682], [3127567558074984727365610202391710837944], [-589247184118928186520278171582457182046], [-4184154748680935300306435292880332015692], [213741006071529711849901123783733603496], [-112269960676257897865307650047098972528], [204872201658010602976673060046299437118], [-1699855534520616665060292576723245563124], [-1658448323457004618141584588706603157568], [1211585563801744482382300370515912496258], [1444586338864192844008671547086613078158], [3211050759966664368767283062732489189532], [5417473049085748887646762400084034414436], [1246021915394024360569062375334029421656], [-1743616826791873102622051628496661749654], [-589713268358956384120363301474490689408], [-680919636154262048523571121869275292902], [-2164366225641320417661925211415189481220], [-150131291806059314259576372013088579874], [-1766146240780106492872289918223794778634], [6870475184525861514832434337080210458370], [-2502894129720984018511760667523043425616], [-287815491639884848664651036826210839958], [5770264474075561866904755940554255746670], [-2130431115597918654726018863729019122744], [-1481236616122706029556170370035060407418], [-5285932280306328259963778303002737545646], [3520446648243225475788700989800986636228], [-2389134613046082555589713727658442638508], [-1924499684617733166373635215002508788366], [3100547068794242474849905835182887011838], [-4036888202700202477904696730528525176340], [-7892906727193219714952083002910598197004], [-7000059446062895900093741164325548514854], [-7533243005614795405917917004461619180186], [-11445594281442368017647743501788121044416], [9583043032156559731651607115000750269224], [-5468866137551590704023994942465153828366], [8521640962154172799574729111916874465368], [-9842066085845720195512096224811981212042], [3527149916627769516749248960142199550478], [-7503270860032056993618616882226476144656], [-10764256991722357733326877522150800459572], [7085083642653585652351871866650930561914], [-6620399078575120024340776288394720759034], [-537908057183167957217114402432343521052], [8096753089092192497785863927049832917866], [3240774090714019808475411894503824832620], [12358287678963396894074512442664681441336]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_48_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_48_24_a_b();".
// 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_48_24_a_b(:prec:=1)
    chi := MakeCharacter_48_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(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_48_24_a_b();".
// 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_48_24_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_48_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,24,sign)));
    Vf := Kernel([<5,R![35483250, 1]>],Snew);
    return Vf;
end function;