
// Make newform 48.22.a.f in Magma, downloaded from the LMFDB on 17 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_22_a_f();".
// 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_22_a_f();".
// 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 := 22;
    raw_aps := [[0], [59049], [12954174], [479513104], [-115657781700], [295658246702], [6626983431906], [-28576184164796], [-335385196791000], [-699224214482106], [3484957262657992], [-35181531093012298], [6132056240639994], [-233260850096910596], [580205712121346400], [-1394471665941750306], [-2352476807159705700], [9920628300330384590], [-26068981808996843996], [13336955952504341400], [9037529597968684202], [77283864571811027992], [155698418876868248388], [253837312813381912218], [-1030722092535365121598], [-765512937290535332082], [897523743732066414304], [-1717739980735440755988], [2998475215252850465390], [-5117109968957302667118], [-4051025628579033462920], [19286740168000300193700], [-29353605098731251876294], [-42406781134264755350996], [50449188236194467441294], [-83078909500562698128608], [-166284912959038859757298], [113920763652858463071604], [-352378464819560720079000], [-54370917211349474040282], [-557843266009054775730924], [-529020623061951632686186], [81926212869210079146624], [660173809644950548680578], [-879420276631515864067506], [-882376051258445135770208], [2862603888296932263299380], [1048922279959895989620280], [4225614488021020663223412], [-9400000044853291279966810], [-5595279014471894733687318], [4796607628778362547725776], [1302395449469646017926802], [12548931193766945489812524], [31247778284915427471470082], [20434497719364343192705800], [-6026506414107250970122506], [11301102664423726320437416], [75173087620117599385619702], [-22465876783827781470053382], [60245993932778778689018428], [4650329370859849085610894], [68909774995400835049064980], [27525409738059325338010200], [-151255283266104985946197798], [-54595777259104615230348282], [-457957823548632141595889972], [177476691565518411934227026], [331317257435621945247024588], [-182866387650109005371973010], [-558760567313975539341116094], [865985621863362703253968824], [131813415096197568135344728], [-480047662826678413671242074], [-361040795878149739922688596], [445742697334730425298227200], [2636157352065095529260568894], [-1912764909696852395927354722], [2316213832094513219270497794], [1775001379158091807407753626], [2225802770490730625183910900], [2262739155442248760253605190], [1807507854061144300362844800], [7124674062886662639592795826], [-1588746425863639052821643408], [-352671881915152889798992212], [7747243893273538039427237394], [-14197730335024872696065336374], [-2103210149810778352670670330], [-16634777210529449722133300696], [19255182564457474743453465636], [-19841658132709746717394199376], [191035714941054591846033328], [-8060028185385412999388379924], [-31263065909788889136875679596], [41471744113244580459758138376], [25426316637938758122125071494], [-32474228640042200990259857382], [-14560469846857808119446750020], [15981981439759860982462789790], [-103424910679138818032566782572], [-98134951843772964034664503482], [-71014215660303120540770816988], [147836614248845593304912959818], [130988178011621522814453377980], [-113007310705585626568650777598], [105611914346383316417762121612], [122381033366206524823288185330], [-137213271105827569801914565176], [189597933643873572981927243578], [107831718570969991912447694104], [44989958893070551722310746902], [283972573364715438827944637130], [-117452482538980094657149787444], [-111858109311016855877381311232], [502292138837093267543378170770], [-427106397633716070914542414796], [432869371376299933545060356376], [-273969463308167944821768854682], [-30774292497768829505538267948], [-306325493303110629021885253786], [509843014407425385278138613026], [-738046875917502110730592021506], [468059179903946354258470489212], [477474753886969351995997997956], [-976925940014301879769869530106], [-806956375219866570406831610362], [-220302610113502876128256310400], [-1521283370019011830129836963872], [336650773106104010116787073278], [259622479515250382975372574052], [1317173997682701985648189153224], [-146729952611463169624658420360], [-316010259106827275514315890698], [-2026388602487662636896022895382], [1555099251267480721872700550402], [-3905272564662792578376330923058], [691303328804076932427064514404], [3057148757751151739687234745270], [5623019003460037800152197443546], [3357516641278651801212377105404], [1664941294983426468791189443518], [4793926285690142404224018294880], [-6927370987349351261609952142212], [-2557450599821838368593823615362], [416859922163997371415247769976], [7407710354977321227034376385254], [-3644477359242619983454505616918], [3704158592698023076184293859404], [-686611927923057961132395491424], [14188600188599117744055088655102], [9830897872982398083175252108146], [-1060307527387328856596881017596], [8968940243707312627497904855800], [-3045990468445518850013279544644], [-9547961095613954803992792287952], [-15636980862752453105548981409984], [-4040442560812209382984703380206], [-20983816638064628733787838869174], [21774437693871719273183311271718], [-12146790671920069836878840665836], [6952123322837741329356621389706], [8857946323324955690257851205504], [30538219808047969188760674707676], [-23801887002071050191622646178942], [34076116212649810464794109552024], [35354604499683225631671603591016], [-42357710256097418841286021071274], [48529682165878504916351201758802], [7810342341806890923686599013646], [21977339429585071558787882165052], [65610639544962958104268030394414], [-19573567954871021834086938124824], [32741240204573630304857372916650], [-51573850972761617348126440222856], [21470536184593323587879703373818], [-56494366823135789108769637380548], [-47090253873390607585171184858658], [88896146506870327663253020959328], [13946012964530835649779964030814], [-81244326200457853820813090323448], [-65954581088526302014145132948748], [22041511249925700445626732311750], [-91908775799101013224948111167894], [-77879937472523040685626202858800], [156944007793424993735492541141294], [17033230138153029550097013200702], [75167547323594013358598638717252], [31047726617001021464719716968426], [107520144038205927125720049863424], [-177789578123483262179906638175422], [-91021674758642383385512646713812], [-117368142383897496315172016567372], [-166692431286462031201620301824330], [-42256107250026552767464501269564], [190901814474863288931502752749706], [-350374474697571180319220053391950], [165560732803855120442264936532254], [-40045610169072630173838298412670], [77379274347544490054204577594024], [-346701371446538112675230396762682], [30741251358029130402584483684392], [-104173949363729705245428520408522], [309073048482623325665103559419554], [-75757498549272505306655807314500], [-255264741981603862230832121348730], [-75436978553170868488789470303560], [-135644178016762662550462834368588], [-486695984588911909051958899781430], [-240680847452845260288349872559172], [775031867326021547652461721335378], [-231401085419345905593088617195858], [-86446382085750711511042563548144], [60425912129733714033841703143740], [422442374957399787481402294703448], [-94610446316591931012159995254774], [-513933079145766228191129082203720], [821111270546205889734484771237794], [-485351543439648103798905957022824], [-1011793946169944945478942052608234], [-762857365778525039074783666551610], [-726320004004387711340722989209360], [-1930686220783645839023699959167630], [1672368669229447780990791589552552], [67117115200074411831866580137988], [-965873210533922310103118771868058], [726676228452485330142347128391706], [-1142975906815837949344792235264400], [-2185812322558725228032314374907520], [536270699599343122244230339335852], [94968200488596923506157534342702], [-2742532727791498401896122192489820], [-117207602040432348185142607903784], [18293340794442002088158009707818], [-3152696392734482297656126434035972], [2172437296511551115038460321488224], [835850976867224250313917487776050], [-1325671101373447753986716842923954], [2567822980813950773159014456124652], [984021026717909666648823233094648], [2331877364551366176759894051908964], [2488716236694923863368810608681980], [-1836563986787880135368302953153968], [988159108142714437006518879149438], [1603115217817681923176007373735506], [325089115278267406220857025751048], [-1414576547776688321931803856770168], [-6850659919482436023124979003439324], [5016751427491794511840803015661228], [5856592152976633395033751691916624], [3068510454389843693985945713370878], [3691099462753442662646162739554466], [7640047547844781870872468163434648], [-6250315117971203947136223618255574], [7532636333900314380041838359430966], [3899766058135535346919444087966548], [-1130776718533416382358913372095434], [363577217282906402815388779646428], [-6773812861878935393757365043051858], [2349954322663768871523425077570202], [-9550546125262231324891888051715720], [-2849989834686267609358341522172188], [9100338093764467723141084692592742], [6936161163882404882247221360142926], [5396446784345616755380508806630482], [8722925524933140642696744807094756], [-12865523326274119625104186479687930], [-15156260134017481913785212580748358], [-10345977592411174607849176708079924], [1120277558088277791389760290304894], [-4081150862672028066197476956489634], [-9055645385496398739493811686647020], [-11959067568208749483581877916440646], [-9576525309061527742810683483038360], [9562305534179088178072521533544626], [-7181427049896590290839114563156048], [-25396611004216518774168501740376564], [1888451482145851695264485422631438], [12353270012610975853828737944078378], [-12365449346043267511871093730264300], [12885931934980887836723469883174128], [18152590316910347332928795043833440], [-19463461345040595607126198148095128], [4349730820663062403589102722795190], [-4814459612282111219488064576768996], [-4873024360028976425646639642233424], [-5441516672475691758413007916634446], [22873126327458300620931335254474542], [15727107377491628901572897039365792], [6657415614118318385052432502944066], [-12445458643450635801705363315683130], [-16293292669273202512230055141470060], [13198194591266885975911925831533434], [-16678730624310255926926570451846100], [-29684933991358448214586019906507074], [-55548702278954648526896197416450282], [-23853249068568888924639641610327656], [4193848739029109400265865371091742], [-76978830869124692908051533327261300], [-40974398813338757297720689449923372], [-66397500212961621724474130971868950], [-44618589560281726487885665082479578], [4213655642807422977228218300790520], [-23582817443865388977159929605502412], [-63240525136071466668512860256278868], [16917057580264176223930929055301954], [50528212585385820934462729042832412], [20565669044454487848899163246595214], [60702807359762370269990122530701352], [-48268367303123017196680272006330826], [92053926490533269991000604428226128], [55562531637643611975178088868109566], [58452639038681748605619717062936946], [50500268841308441530673086086406228], [24232611100607433740888028945849672], [30907504525009974534018546330572426], [-99244558759970726535051553220375628], [101042344936642813250688821328006576], [78223868857307826010437065389456130], [52769719621711742883041005489688370], [-13064587374202760778235789607306444], [-20127808257286650963482383651542598], [91010273802935738424057720291383046], [-37552701886264676285582010483695096], [-7607546966028328423059131616634566], [-50437315440999457475858557142223598], [-70299738943681368116829063106812620], [23409348221940660939053075790643756], [-62777952166589102608119569581671648], [50325283511417094414613344404585694], [55465290402556895044236302836378862], [81135878193783103116365344753533366], [-249987230490969937883491125870887912], [90744561392563026468856324060852740], [250140397056045824605997175557959852], [-120703851204412756898596069266951636], [-312888919239023253824422688680645234], [-16335978659422598882200154763455742], [130681465536922480072106282469787274], [-155404237784640093432090894588927320], [384398066590623668107776507076381574], [260938922961861582145719971837005578], [342171508420365656227805499591546222], [-250437417444818604270471353598486560], [-186709242259180159577107553644579482], [-176111884845728934524671935461870124], [337892376731919036613572124133582438], [124359336802205150935131307486252204], [-165787380431711657332099557211252128], [-407412162921723280362231186504633858], [113338915156157596697072730792868180], [-215432628987052165261192748729334070], [189356994165596019099053900773977942], [-190091545263399618351462022479527672], [-422617490705650059725699426932943386], [-569570550733923595432934433738533766], [-126428641381397747928288895042762752], [171885792755416218183405345613112748], [-140378327139171513338771505822215166], [440861948474025592106009302767493848], [378484925906638918979544389954953430], [609553368343813590437149670162978442], [-578042693766671075893860953782849200], [-272116818842018014184718834101169300], [560433336442681214710319669588908708], [-609558371636812174825800577960519222], [181691390939434081023695871311258070], [941940757237254312947441243253162352], [-701633018198917878342832175610674374], [307999800314031933291226189367382324], [-589417868786686534589842104236326244], [107058000243570131351667506821574448], [64204307349654284029693326508080222], [-270295002789486462105998111145551360], [-161425813263263725555892457259121122], [838247207428300480299278106163638276], [731630001800525066490346457620976352], [1071016622871173307730786540585083554], [-616552889351562170569119097713222558], [667036526357812350304753764721399226], [-1217156303046003848100714600891793482], [-296391513046213532088209744014437894], [262643134758312247405166797317891808], [945182755841874595606615553747253858], [428221859550602274350486945127269332], [-1558539714989369075603918805775158552], [-1409579577468145018105916506952188808], [342199401954423393995196086073189206], [-1114805157096962304140367311821240292], [1503213944804723835616953268563977424], [-697786014890381223373849272651998398], [-138536224409918551934909939869489506], [-541911161655004889725878608477732052], [1216460596948239977877731141048562052], [472834188584897243913011872747577976], [-86335841134743512160445406917741222], [-2067733329247277860521192542509230632], [-261652031183264541396694019021809158], [-119716907728890460892867061842538020], [-1107018056932101768363138987289542354], [-1223873156297128810564114414018089586], [470344698825928312042990500441062130], [1504240366488978050486706568569312328], [1747460178211538215275832545272646954], [-136534153397740231185083253486081330], [1439961107180119748738509440535718416], [-40341804255432914081667584651790226], [2196284384916048063447542582540980194], [-2504322485284841791604828377710280796], [1137764780795675650540068416827431348], [82025529790566888846954881513859602], [-1623184547257579540238260968334609554], [-784270173148605072293726814500439540], [2829630794496879585831736171405336756], [-93829213806139696230986070854316598], [1174509806503242983229348550570873494], [-373504460932655421297960335147800704], [1816927881317607367194035149550047408], [-805840446104298520471076028268029822], [1032901632003113151292312023459450504], [-1074059626590689849830037228419863978], [-3656749909405771808454440032927476874], [-4347136126780538278099034890579221552], [-147013771081146844749133971305816628], [3726215318416078553184213113595954602], [-504332067854448651046637095712576778], [-2472679028488528612634265448915109916], [118969889514990035816902833649197594], [1557430738021860890168899522419544780], [1231472976555805773001964753705434824]];
    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_22_a_f();".
// 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_22_a_f(:prec:=1)
    chi := MakeCharacter_48_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 22));
    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_22_a_f();".
// 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_22_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_48_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,22,sign)));
    Vf := Kernel([<5,R![-12954174, 1]>],Snew);
    return Vf;
end function;