
// Make newform 36.22.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_36_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_36_22_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_36_22_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_36_a();"
function MakeCharacter_36_a()
    N := 36;
    order := 1;
    char_gens := [19, 29];
    v := [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_36_a_Hecke(Kf)
    return MakeCharacter_36_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], [0], [11268090], [281914136], [36172082484], [-449098578370], [-2121858786546], [-4609406233900], [-95095276921656], [2245742383351266], [-3155693201792656], [-18178503074861482], [169649739387485910], [-158968551608988244], [134697468442682736], [15637375269722538], [-2977241337691499484], [3603855625679330702], [21066199531967164004], [-21980089544074358760], [-17054415965500339222], [-115020124425041803552], [96628520442403345644], [-60427571095732966650], [-407820224794143352798], [-1950763261541373757638], [898058258856061843544], [-3220130092497702513228], [-555319129053717347362], [-4007902693948374831858], [-17824881127217941461904], [-5430094428491470688292], [-26403796860148994268618], [-44179514856087684617044], [-119466361938975961689558], [5872566808305981708200], [196847920369600163266862], [-193737777987068012377180], [208785374035455089016792], [248567935142422786933746], [715674219494851686103596], [27419591114061314659910], [1353034362121605285057216], [1274701469649650782539074], [136578540596995340122266], [1109602149088414136707448], [-425779204719363247011340], [-106481772114888365580400], [5785719158585301252434460], [-7954702276414244150235274], [6840671103854647669391670], [-17153869205296040009401008], [-6005907724844420703540622], [-14888321930236418516396988], [-17681451953651374091589378], [-32580059438009614292443656], [-20911729539568130023640526], [15737838137655032415305024], [-12346343097656961201371098], [55178618221004063288717574], [14558515035241183795897148], [28667451808922777869705722], [83139801030997460836746068], [180387693500812513901043336], [233156651534474557734713114], [-85158511715914515603723006], [56851313935391272040110892], [208108526283650845174451858], [550754439432880685575219812], [-20467420045193948064020434], [-592033877075008224911287458], [522516275767893470257274616], [-1156522368481555196366110144], [294327942460496639481234086], [1242792731420423248026862268], [-2183011389906980635638142848], [-1522108050614795847726618246], [-632565646590371982759690082], [376087242591463717983438414], [-3841086429691823988068433094], [2150902629027710278773295068], [-1877387477457730080853889290], [5680163017613583906973044912], [-2557812841468138455337776526], [4049710329205329166604877608], [11578446485901326821751428356], [1096569384276720358936937502], [-1081687827798687006038019670], [-1203046482839093206083457326], [9719851148888516590440825728], [-1016839532918391050175696468], [5800133840767503784972016256], [-7929066617297717580680055688], [19426977375753481024417578036], [-7123644563832560395980199276], [35849915681610894123530941416], [-45385891239495921268103833662], [-41327919831518887996464757002], [-25760456826452439300618303412], [50061806561163811014010352078], [76949887359712657264634240612], [-92706978868862392166970555342], [36220256291992394182180282380], [11080690230964988987552108934], [18971291390860560603977734940], [-105096404165739869901453170878], [107067518222716364517652012884], [226565596690376658298550995374], [158465890753906747939008895944], [-175298607035113912059731542342], [139495728895997496937653264848], [179162962080315432850852897238], [193960316916585233888415867126], [129272374265909578592748899084], [199937570032373590157756943752], [198807636674883243757294320606], [-168096804227631692581754498236], [-8679784586301983448760362408], [-507946800818047728019190289966], [-34280767974936704207081854068], [50353641179079398916963658118], [-422879518469863160771510432350], [2941324589639397538440396954], [209159463895430572584549272916], [-710396460268607053672131380812], [-810616405119465487831311145086], [1318273072957393973391414811094], [-1042042056758221182803189710128], [-1066349555357428230828402628888], [2081217897687683895715304797646], [180813941390769257111306410820], [-487745221262758390137446063784], [-922609673455429483956540575488], [1921844472680792341216189373894], [3517222643049993385478966015238], [178079081902483793267631770882], [4210790519590900840779914936538], [365262887784484763470457797652], [3155401643318068830603062027778], [1776813036724722333649131295254], [3554396691756398160909207609260], [-2535018641158409914880847202326], [-1711742843030240062974806236792], [-6619402210153213107062286084252], [6526289319746462737822658965742], [-3944283924977714878559681811624], [-11514931359114606035907015628858], [-263232418397628181375341761562], [2578940515239412837454074799900], [3338898842238241273257655918368], [-1943553269617031651824318678786], [-3058709624128766061090424612530], [-11208015321524612705484121325068], [-5655857149624052268028278813816], [-12897186912830342171364961589812], [11183031865293819680584897546032], [19904389923179853637832566714088], [-24692379142060356656232917332098], [28047314422159099992605057115338], [-8990046193525427428580113125390], [25417003431648633946888754084652], [9083380384301346287987018113926], [-13270468025982123421313139042760], [39502510630712063790155420804532], [-10481180688708359362568150147442], [43320061921051544105069318314152], [27147552335587418301138805050608], [-51869899905107347695198489750826], [51569511760257432053411597791346], [43760775264239430000906394505994], [-60584619329515300899193224372828], [-26225785355701325806843653159538], [13782520198744220153310743445048], [-67900310435125171073325582897238], [74974928612180871466781405418464], [-90730654383130280696809961746938], [-95993426362341654742895552206276], [12019327741174903730291763786330], [64072507086025570590614545874840], [-52134747257719991995085110394626], [-131195989522917304476479985937456], [14808013836312498263044007271804], [-106943531043090008782081324679722], [16674559610181067319742786290454], [126900566626911665986096731918000], [-49969818153866618650969725892950], [69246804851574864951062987198414], [-150569784699042606037594939711612], [176389946852005897060366603947338], [-3563513006963036219147765384064], [141563876265114220610958206966786], [66007430476288214484438823932756], [169242018920191033605726461000756], [128635919419776414866484968604546], [213301130392255650417364096394172], [164495765980077102124918712277174], [5561971300014817310090474670962], [-439596692908917660504502338083410], [246456837994784176484418971688894], [100803225160193444748838805706360], [-22147621560594754571573949795246], [-272824900315257411373528084905856], [291158028649424469987556431693542], [-410970170847931659902885939062174], [-555922074084023545453835751074796], [-390558893230441223261557217081406], [818914669775662600887587914012784], [-467981192489996089478303843819076], [-54470754641957363692110057980394], [245986825429750280619782183222348], [241709338959486059535097794758738], [170723335611196195543706747746410], [-212192741217315328217994401793784], [-523606082311469661208269285927996], [-401512846306225629922704839191176], [-756391493125517435747792953330870], [-793665858922132648151864025850048], [1021783509275044690348985011737294], [980172632622769766131712331147048], [-196420221431731288512886483238526], [1625963227118831899544417660215862], [811657535822010832992670691404904], [349352562016871038250639210607390], [1332366460460936702815531400709824], [1013161288291799268107763012290220], [-32452431085509569770549489470586], [-1103175357571597092311387355753402], [1840384854349157865186665536782528], [-933761846553937469133240147439528], [266917866813235801347036202883700], [-848672968421820797114818598834914], [-1507458860677205757768830512753420], [-1192909607675305854613944276824080], [626263862393836246766989925200662], [374383257127239976800318001089548], [-309621472084288146933371421721584], [-2186767895663730807788724928583470], [-1728403403954886320628198256888086], [-225460406523354517125740217264732], [-1886422666911682542775940540376072], [-3720843265570992832158206469587124], [-1752401679898686541445455170501412], [3454529427311650131949666227867032], [-4901994632336308193443712688231202], [-4478214297845623990792290823665234], [4996653680783508585750510939771912], [3613432636705168977446499522913520], [-5570636127138321315786032338620036], [-2938469046071706783914409351718900], [-778428276085297248815937990984048], [-870006323902090287476200237287442], [1620695665707795764103209434008318], [7951003505374953416810936620871448], [-2256466848691953443926940346606742], [3964032496964004740488232697894642], [4666139146134921090160696362305868], [-6303841853450369315017178099499418], [5975876912251700177531599543920956], [164287729650536916465630258306810], [-849074352954720731748108094846246], [4717026582057849427210082581832816], [-1247829667221061808893952528766372], [-1195388298891983007575178993884458], [2482522802891443587638937176024750], [-6149628259477122523369256617387266], [986228847004373123533338973012868], [-1231960552722961713380041318441422], [-15918302691145906351496023590655578], [-5459816832583010087191850164614724], [14399672410613967565755296939878458], [-11338653670384936207290482463813154], [-18946116091542687211926393548294476], [12537609444622405785565834462335674], [-20316355005856656930179200329497104], [5101083733867177846813287158970290], [-10152112022994592668572420955712408], [-17353230355210436098945570545374844], [-8817568719625048601644632832177330], [-15328706190885079039520901188091862], [-13856096837301357228708911655667572], [-4278230990119411647501274901141184], [16708576551121087675729260360891032], [-3319102744942724507201395816709784], [16465739402751155395858913494871222], [-33968061561712339451076235481386036], [21331353821994855759423127939387632], [-28922545700095901265748596626507566], [32765164477360004136291811642941354], [40388906578251618029378649190945256], [28180604574682038255237606296437086], [45825748114870535311211979386000754], [-36399184981669972628181808197687828], [26780214065363211861818918207081190], [15945894600956648088700985065044], [43355610585890304507019895544041438], [-64260524573159770845990943199812926], [-9499929299102227040030479465494640], [-58083094387517692999945948392365910], [-38296580760513297242085347029236924], [6499187884612537245203466363714116], [-25519275096601513272821527094298262], [-25454563563737531282922885824668782], [-37866440976629198031326171888212192], [-53271478925170929350965057120554996], [-29589424707338667563155492048962724], [26088224797679128651805586997494818], [28299413732522741577465963023023956], [54142994928594287644102913774311070], [29802083785397756477477220183990696], [-13008646359337414269352541820357898], [109363757794918933329425258329881456], [-60511893076594784911534154614377270], [-26158268178116052798237978762985410], [-118359693807335615647012471463192860], [2748723010941475885049175510406296], [59968718633264309389922281009409738], [-132009884311759226586352899678484116], [148231804608436694361737695248314592], [-101020758418307590737635790240795070], [-55102522178768356835959214756795346], [92877837665656521916816447933119860], [-66031856699005194812524327942687942], [-71753022955361871062437122892152414], [62692745004791810177085069200326064], [186187231428049493638109956383921558], [-41780593722369911672836521785570446], [181657373407064938448874823280418884], [-210883751701088862270073716198348388], [180544109002036449082018089651324000], [70578807175694362549105028442563802], [-221189082549405334431022187483817826], [218870920548148592573226177299091234], [-117478810683951031818097606141898896], [-159720588745294562682294046555960740], [-254654688992152315055927973082904212], [63449963484140049070446691339385124], [209989418892652792082318040873276398], [-201527515967799873690553345367618466], [313630549915952729020215165594320522], [92003431359498165963523700346129248], [-262526203175392370828140969903731226], [-199798111022967721756538289228307770], [-325236933486033503168297070131594598], [-144148782464867519451670313461160008], [84197898754828352475710889018403746], [-288813200992920500801727020277450852], [23303880467645572988066085617088182], [-415851153353605563395872951033907956], [1770473322748109913205815101919600], [217161152475437868653510165453171562], [-239598468512297657335722418928066620], [222668433939414807349344009192710186], [148749683263876462512834463132753074], [-292496942710639738111688960187476032], [-406111058495851014522605661079748410], [-401753610485218117750549316255130042], [299436514639180683727797043034276448], [-4473660136188898851335247620446668], [320143277123665351621747429752900270], [-49268099654598612505973002359271992], [14431310009516589012208077065062838], [415504511913816485655437807562781206], [705813831092169258302480191343224560], [-335347452511625235172834183588002972], [593292938574696877403980410522032900], [504922583727962813541800593070186570], [168301188998641783595550583967253138], [488077980514946804682171956399688728], [-399984489846947858493981540747446470], [-556428079632248729405602646018912100], [-698114614691530202237490058914451924], [351705506847341400446529524440776336], [470723521647562276192798546152941418], [472086107182117557893740997371221512], [149205741057823097436689046555225710], [-244454409575065540362200731125244884], [-108108041348359384677691711734107808], [-24385243705695136618116200466586462], [-189836119070915928441823566560941650], [363372601328636590846683797945736410], [-1049602478486529456789788344927654494], [-1406933887460524133543366670073091466], [199659711107419849339671368591139176], [-994601437090065683426728779710714082], [14854036298785236156778295030707364], [-1576083803801204017106800520810591592], [879393478110468498002867588531009408], [592568523006170540471149961085897734], [-468013359532212708565373873627920228], [1027446230497691352155929995526928352], [232791290893778097948715462063329794], [-720663637417357341108226953583023174], [1309525551756374251520609505342030420], [1644417953644174412810518302492633812], [-349766999691310838974244988496639320], [-44753013859252048309100949614450758], [-2260964637278733931431363881598807280], [1183422948039183153004633528822635606], [-726280500121757899136934667127264788], [-723705832231385621482601781001501302], [257348007142877237054761427391302798], [123331339458715603317133803475444830], [-832936773145653543742917625294695232], [1051628422731673860411118168288645350], [-71604616497139877973292636174964934], [1960678795088265141554062466097604664], [2907554031711274202085362449425931358], [-608168460891913122847260494096208018], [2151627266712559177203542195432381108], [-1694686310321906545169915345691463236], [1450069457535557623061800212583369298], [68645617110350094807358843792027626], [1646187807496630094467751716806395556], [2865814170478497224163084195959928740], [1336770117303299526865294467630531530], [-1460358808033372468694517858827188590], [-2954876372895179547675723902673749184], [1365232420958777181510800614572608792], [1949129533993067685221808570661179918], [-2748864340580829633214321085220685752], [-3505317472563829536731692209022581246], [-2073677364081157197680824670557390186], [1935900853262125557917537951412121296], [289819674172338321902904449481789828], [-4684832962444695746815578187600234966], [4746668581428275153862045777599738802], [-4528750900748844064830489355492307988], [-3156472122120577738041083067253055418], [-2152710756414390238628720664160144420], [-5617569254973274377471101491803677400]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_36_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_36_22_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_36_22_a_a(:prec:=1)
    chi := MakeCharacter_36_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_36_22_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_36_22_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_36_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,22,sign)));
    Vf := Kernel([<5,R![-11268090, 1]>],Snew);
    return Vf;
end function;