
// Make newform 49.26.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_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_49_26_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_49_26_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_49_a();"
function MakeCharacter_49_a()
    N := 49;
    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_49_a_Hecke(Kf)
    return MakeCharacter_49_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 := 26;
    raw_aps := [[-48], [195804], [741989850], [0], [8419515299052], [81651045335314], [2519900028948078], [6082056370308940], [-94995280296320424], [-271246959476737410], [-4291666067521509152], [20301484446109126982], [183744249574071224598], [300901824185586335756], [924361048064704868688], [-990292205554990470954], [-13052569416454201837980], [-9015451224701414617502], [-26689067808908579702428], [-192390516186217637440248], [-42404584838092453858826], [-271681055025772277197360], [931454457307013524361484], [1763635518049807316502630], [-2829240869926872086187362], [-1863424798129100831412102], [-4858120128770696114246696], [35830422465487817813321292], [-47779523949713376857525170], [-74647597801541940896262414], [335904534129377492483226752], [174970523892428305728249948], [618313109745960536292087882], [484462128637274579929861780], [905568683500101980256093750], [1161895714542448974565531352], [341504962101535821001216258], [4632019330305293463671472836], [8264701881776285676276280728], [6026024708562761758610453874], [24102261500967183004825491540], [8191932538465314965518627498], [5506016890624536539668892352], [20871590887477398937670272706], [-59936987790338741946487251738], [-2240424832787305697791685000], [-75247451459088716712603051148], [316695888921276124166441057824], [-385093867204018424441344878852], [568261440252719522161661910010], [495586486330457297693292119466], [-144023448037426492352746292880], [319455938984031179088910841998], [-621677267284418547255343836252], [2294462267947666633683914581758], [773315946921138089280627617736], [-3622588130389834818682741628910], [3627673250121222001463568596848], [-2548076683459664313429095585098], [3598172883135056042267481549402], [-3822646294747995463726006273916], [-130006531958494180627027636806], [-14360214302848177647169534817492], [22463033920144429698250146067848], [1379559471136367894001031739014], [-10278651623433080957734662503778], [-5753563965996971662984355822548], [66926793150558778433244186524882], [941781150816541824227585338812], [33908112195800308067402386538050], [-13031284751559498352132220789346], [-130336088347675288184755640431320], [206294354762653692506037305805328], [246050779873833737919701517205526], [71274301600760314844951680645340], [-133051294483218319113126298310016], [240508530175723242636509861314470], [412136723690212764833398877672338], [-71664659505624898201929474345198], [-134430221475968122996297608755930], [171876160097459082884173044372540], [-827663831782889538482847281783098], [-78383621915046495210172752362448], [-633272755307763050690739692591666], [1482986970040060831209497321814280], [-1209012635333170464590901871190244], [-948861362336468714243755796389950], [1906438015454539953482023226664842], [45626967057782744498214751298898], [2135214165360682091948455931456336], [2672252931140078368886189852908428], [-1972399217793483382246331331836640], [-396365691342605028028934306158168], [-7226256779485390805843060698858548], [8198301737483581650490339755358100], [-4725620603026848328690830213571896], [-1969545084859124374313398077691230], [-7397816591525737266577846621011402], [-17033203938239706662701704149092076], [-12868103727506073374588427568589698], [20662449349768742309415960538527812], [-3287507202857319236737451756367858], [18080449355994165352055799784337964], [-3059669485707949000126966308019590], [-12988412934313322304448992252392548], [73149007283437031184593659377598], [-51622576954284315296250641988959532], [-24070451022895515429903274463421906], [-8306715731833092425485008028093800], [30040465694002976026741088820368998], [100962655278660281875479010258127008], [-1024526308514073350808056160507514], [45327063639607885238749699016129322], [-124784313486059742429996939685034060], [48333817152455235297360818912551352], [83049407119340498575305771673129602], [-52572397212807570140220263990030756], [203021212934182245316840438243695288], [167656843695783841975546906745288046], [-292520764764077767547034646185916620], [-83022703976977790010627770051790902], [-323598217246990900160837490152839774], [-77633340760409856063176405173288902], [-249908521900610788265417549767360884], [85696370131854075386336488795551148], [453463801782936369543916065342799902], [-493253946459830644676925328436697370], [-213498713808545388991042502994273360], [-512190003491531639219969928363945752], [-177366164610548743964253082296616766], [-1135347530077011177037769659346019580], [40374926372477701905735782397977256], [772404884393222923195887199165623152], [331584959148585596040577353957416342], [-2022303291728039968865129534892172602], [-771193056134021862301167237188337410], [-1960602395367194653286888268993426726], [892654495293574111495131320041147468], [2354935536386796280810376630649963138], [-1296165763533323698864614991794011670], [-2636056416477357054221085357358365452], [-592270505992680220429366303959161898], [476928247666321407950184339078265976], [4177942458006529804074897026301674652], [3180226070217526507313196970402771810], [3572695920570651737167056756666687480], [1754663901382733612982072450161497354], [-7103238657301854777597975384261375642], [7566948942139016552745489201846935620], [5721949004294555145046114270754672736], [3219258509708242534801954541687009102], [10463253416859950223551856430386179598], [4117448435898373812184041586239319316], [2529037303097500118008581763261629768], [-4931287778030781014582333390707925908], [-7105476587378448225139854652518494448], [2641548413132821047693879218876582360], [-5019344365605312552357640636603350690], [17018932488743426852986073699646170518], [15125431526392966776353989505223811698], [1653293258295818493141829726879888212], [27778351805167089272093426013001009146], [3824414748277568577907801195770305672], [16708665614867499515267004314724420948], [-35437572556504850467887446821661773998], [-22675898811191401775988244653815457816], [-1827055282544037157264700582600143648], [-23459931419013195552931575066153510662], [19957196712468199740416348057027580530], [-51277568126624367621215983341085902486], [-42704158543825397461674056047528523940], [-16013969873345001824942773791470526302], [-11616065083494194636378420518362817848], [-60687271062326742733921784692147655734], [24249541908783048684962182476570989680], [-30713598245682878642224028926577276250], [42276760442590471748928458306114134652], [-12864136695895341145709630382111693498], [97555761491634346008773928406995043864], [78613287869975495763727497451617775090], [-57997086865803169474228907588681272768], [79675107027532607242411327449853973148], [62794413247736508864612737146468373606], [165384770153330073633783413308872744438], [53172384036389513799168016978152774096], [-54201346589539680040246282878994570230], [-26198166345599373836970869028103482178], [16951378498797220533287681980731744124], [271163694815428279185743618185815765290], [50080772430974656197613709895905509248], [269988260503631759816492598689580253054], [42623980007446030882497172524822582636], [146673754583108367075525222284036819252], [-32931482492296936204788593483741199102], [4365646652846274478866497417564366532], [-148687620547785630603322813446808544106], [-475823668066144196113282876478607253198], [-16534455597129949330039102540397714914], [167722811990901260236745750416374466878], [-379819380197007015530244379093307536776], [-640194603822719460736808891498159088210], [-762938977601448348504013246992017167952], [283294008563125545439564107463384027018], [-408927436990830511225599536723559918050], [-476331476185689221103753900502510450380], [1042629403056488017266408209181456443298], [-368298379095278824217167874252729949440], [229186252396870843027187538292809031716], [1119511164346384064413671725512007226570], [816684031063038974185393558116890889748], [-953666214222174762916566477192483869038], [-442090263900015470275481129208340395702], [535444321256092744989688400366587633496], [1673168060302918489433619416538229503108], [-521275422269393182054884372207758832360], [-637127061892430516538932280733726209002], [1608207936163131126172895224964036856752], [-1078943603324240570669551268357866632402], [2479300311251735380508707701428999691672], [-460059576785722655831668274476448107074], [-1680236100688891414788200425553381931898], [-1356307379651170122792918039139216854200], [-2056049383831833373523828414694221996670], [-1570451028334316612209302126300732727024], [-933026293530522170067175997131581555252], [2972953146185899093591005236701223303990], [519906257335938294888306048808645309734], [-2091827493578530669723777297900238294880], [5901665403036859284754651336111976001688], [883982159708678184196213616383765703052], [2552037890343029673494706740654131036046], [4069180804199539313436549814783622773420], [-1331004947757572816438957670900690499648], [2365672767545074222957981127577657272202], [-774681033820224854952823022361429075116], [-3694388386689731901088677136817911697232], [-5041128815853183285074388316243172524370], [-7746768706831024392767800634194249760394], [2780279689291807584317577686636324605500], [-8116301018955458785288905463479023357352], [-4327848400242193459553051263424044655724], [-449644070609959888214561952625236629852], [9506145976842687311653668964209248645944], [-4419166450547918633795648894119219493650], [3312716319918359968990187532483816991854], [-6749404244184556968324156372677561096280], [-4943893967699880397778217015796395306272], [1196265157040983080272321793071959049148], [-12504050421020589313182875396725051689460], [-3215690033030386008475967192031720258384], [-9403565539703552328272679182394008637538], [-19768884175598075295371482046039818792002], [21118338397408104578558293338882846141192], [4275684177890237424604759629398504545270], [21427556476275546278833231192136874415314], [-14449652141443815118497361443148880272140], [-1097118879871057101804705822423808332298], [-15213386071182467004127292909634217265852], [23060952639247457696018942486442474973818], [28811759181769293945627546538274139833158], [31217822717867102753485969400790767006336], [10342561724970473076281343984427308721572], [-12329807819551900947206542331890422713510], [3489873149035309279832275408176282190594], [28500316471913086132937843850187494086238], [-6608567030725226789912501445814375573700], [32109005165265894500585677725711670028430], [-703688487891497406706538659664989118202], [-16257567528200382462042835138849968714724], [-18180003600374961480820957416748528100634], [-19634870592100024191487735300729298448302], [6023059789925091218043726640937377341812], [-58458917910244181003474615877473421765146], [-2049132084657815388610740187273932965920], [2192645818853125245032413476645623993998], [2496519236990515831095575745706315414984], [17460239519915908592621714854089613488732], [-21958526664435232346830636609825726221730], [-60794391052955922370696836728891036940598], [-49567390650184838518077172428129392355252], [64852656033998630608357472718186939193824], [12116360446242317516710417714654982456552], [-55486934386837469280244463902843891925112], [95818539483769140516017826015925857951898], [-86872536790014671057706781239879953238572], [-111437248521603723075832639854126389164848], [21356535009462301509013880851719420233426], [-105506475650134356377477266260163187986698], [-14800257625983480781710617927816634118040], [-136814415847859931819020550129135681206370], [54034782857639864494474971949914269332302], [140510107078185652844073251421227859676908], [28896424479310015842789514550584281964986], [114796657343663977053336923834557671468948], [23909935666223316106665614540007036473966], [-111254882995239985871710767311331542461950], [32905717649858774766850719906796961873248], [-122202814667536338972882071308321362365526], [292496941649443943687398510166459107257060], [-199261745039256807670443817149477361685732], [229421839594247588506799329031675284824694], [-171710743744353128002618050658834738009938], [-75917712675255006533995420917377958977200], [53811166482272117797204835709890343201396], [279720038765160443468397440626744641339452], [-1238009654648202441981455686407058478878], [104662044973255070390812532399072428040652], [156150524143722063170146898492391381493810], [-216958669016956506348166318321298406139080], [-82233765152085024216884968574131102920154], [49026127075469933874872362766476459569264], [97144841284106942203659307911629479453110], [-414566080966901841596810270151472107442398], [-104077995290841484755378321270170705367484], [187675025144087245286850577242283657453032], [-342967699263114834616479406208481832987370], [-265812239486753742144902402997300283372500], [90091308201567984894779816250689274418752], [-179070551707917450274789995271382061125186], [330857076184082086653592129668223441140690], [398671710931502973728343866106704010823948], [-584559069526631801971211271908764316732518], [109048935197039022736370311824707533631298], [-558953040716719996305520802498382590390944], [567836641026221133370863196851201296872746], [-787209537266965343937877450806371395330802], [101489613537899319691699089569369403922340], [-67831349729337497501524539165332060947196], [-495785130905616135012426453905061154931808], [-11150991500239949097715646005422504813114], [-1177975686594098348808691575031825456586098], [-631598353176139219053107717303867906216418], [800861250325399233291088620041090643676480], [-767068135395790225101802064559727053213156], [-522515906496193291370696228346201170366548], [-1317803379964407075665449713233515067795772], [-1140584868893764156658364795362074435191490], [1485217890402448207634253643058606252204574], [-1416301181943436697779679564832643738828202], [-1032367827506301182483595931668312071922032], [1146494322261206102284019305885296876659606], [271937772073890736657856992010441786587962], [-839519242407969250976229261610812375477030], [-1899447651641819137725348113306758419925048], [370147185157533520400611206554415280669566], [628064341737775167650161388162714295031620], [-1747353178223785934380487565096426045778502], [-817319284078061160009219912156982689836788], [927092984040435248851669617743626869280848], [1622435352015895694284471693302317614358058], [1749566009696079674537146951745811206747548], [-617291834940261877800433259904774748183798], [2090464127784015472738085178344595807673902], [-1189628169262203901160475364476044113336016], [2502794418781098015817853167116217719732470], [-612277544357534451591832814155690465790106], [-832754800280032571356835275211394057045600], [-1941978094730767908823470075221411062904652], [-968945482372307769198714704487560001086478], [-1185436156377053010812799283413983307870024], [-1870005373827020485577903571378460951472218], [-2184647131188518084317823100127393923229002], [2837971887604370308542774943292856989885712], [-3201691047644519650570279870792076443145220], [2690155870081654400988351913033726298733628], [4493443458467418234366922377729263354552426], [-4042833837605878387862960194959598980873102], [-2705142199541610313400278180338714954083704], [1668610079458872344504714219417178390149402], [5074467193961696805277204361504198008437252], [-4741366089202713094073925117558399793615820], [-3834871732141157392910789104671007960147344], [4159865410231427748696384892532694402892950], [4231708295627222288764139201384642493813448], [2807261289408440960031915966777446654395742], [-1700254699452781401912673382481018799465140], [216508891708658099917474235860583717720352], [716070971530676511635878325068331274998494], [-4273089225649785682320970393997311393214130], [5603039763942770133015613702346953546790278], [5057407635193769569077763006145809995136098], [-7521149772627931888852573545266463264646134], [-3615444317840811397730289784537602065917288], [343267073921874510779877607520932334105442], [-6390593960643319253759689397913642127758980], [851828640501238656038170101599335024751064], [-7355938262697921043907862564519660658559248], [-7288584948033908826566490032790310878081302], [-4094816604587387106058535580515407465973284], [3815030491455273196017515378256258564778368], [6232363866723096582092607458579801512138370], [-2352807040861971665607592114899192610365606], [12999886043945777287258207405642125073742700], [12053678390136243950089816064236856904085708], [8118171330476915591128069860601006780840152], [4310578553434222274416490274122783099444186], [15222640576365822924736648685075691645612640], [15805303644035426957820644721914956065538710], [-6540885356826550223407803937201825382988148], [-3052664191451920046995606468561358272073898], [-10966330111488851055467733499231983401553950], [5431298223215359458457021315892769815806146], [14715615809703643647277254282462311076129872], [-5586288497443033622619626348795458511090202], [1081581855004685806989868722554819976270330], [-14396354912046051300808893627986839729539752], [16374429470658672367702378984210316471456462], [-15210216957834284006972840639780716823584398], [2872501977839760895028725379809725206423404], [-2555272408526705546833640127870257659405860], [-654949356260092039432518838520259917598866], [-10763366693266443344168434258388945489791818], [23836867392663942592539264553589424500248956], [-19406125474675568976980590776663333801858748], [-5566527445096675001289167967462739121281558], [-15324820285904442641511432336630856008978702], [-2947337836998688528060666358019618934292160], [13976491666011678177927701793578735839819768], [-1690378921968934834387570593656838974065362], [-9407805809741924575250065327800480817279896], [-23274410818188031096378841360883539728763970], [937332776939347257734297498873790334336378], [-38986907141881472411511490393660759443525648], [-5734487964799494275074562375777649960973020], [-11024179881983301289058365709564089167612746], [-37690806816331739732316074453162865073004142], [21353589010306519671643725097343326944426036], [-37910030444387910461769243500448343142801190], [16573600265334256387494756810833955657798148], [-26409888302889229933154371499347262118756600]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_49_26_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_49_26_a_a(:prec:=1)
    chi := MakeCharacter_49_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 26));
    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_49_26_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_49_26_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_49_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,26,sign)));
    Vf := Kernel([<2,R![48, 1]>,<3,R![-195804, 1]>],Snew);
    return Vf;
end function;