
// Make newform 6.28.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6_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_6_28_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_6_28_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_6_a();"
function MakeCharacter_6_a()
    N := 6;
    order := 1;
    char_gens := [5];
    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_6_a_Hecke(Kf)
    return MakeCharacter_6_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 := 28;
    raw_aps := [[-8192], [1594323], [1992850350], [-321751224088], [-25382713790940], [-618784763833834], [42768440409795282], [42070253342628764], [-3028321281867281400], [-100366681142476985514], [55016279561029110608], [-2821694106703256608066], [-3427515768510486304806], [20535927846768765196868], [-8141280020337107297040], [-116044242102163951943778], [-1158685835874911959210860], [-1947671858682488283713530], [-1975718741948908545255028], [2230407467653040108533080], [14212344156312963793333466], [-4298873468785234776056608], [-97472194121103881757652644], [-92903297497219352080554678], [1265152186081280981741120354], [-1370308124396003451155732562], [2209738832229207235317722408], [2667398674446922494024132516], [4255277788054706330151033590], [239965208615208521188906386], [7673311692303547464403248080], [67345199626823911259040404940], [-13861452044459006603260333638], [34657919111896761884021339204], [323843729457362543179332534366], [-372157988485963730400444127912], [-206553375195605779789083587866], [890184804084666915582740941388], [-960738795363599540290819914600], [544926003500151892345387926054], [-1067918899689153162878841407844], [326612544120086355977892915854], [3790259810022440383001339848896], [-1602832093219176013052179564606], [11349796639182936918951722191758], [17075685513595209245449530541832], [-31770777313157271590658275872900], [-36943805073391445040377035950160], [-51712927892486419579371041665524], [-35856621654908355972473460690850], [-24559822807256605516094211477894], [240319417120124588052958458670416], [-135755473804557208352434015230958], [115310143216951165558655263005876], [-416768732819269820648284452608766], [-537651334061218059000014377736520], [-476359152171110264616365246315994], [772511030601498006454712576152064], [-43073949772722611776725194717266], [-51226962854134485642110077832502], [1927759855043645869863295135312436], [-3739606617052084836237153991524498], [-237639586406873766274150506015460], [-1179509485863209337225610224632760], [-22751946720946242993308241870934], [7166563851191113995621022226246646], [-2804214878837746153274206737492028], [20830096596888867867412545402522482], [504564917731568291361284308871124], [-10468359849327895691260612295675290], [-5465969489303154532299030274301982], [-18368175156162475113572232851604936], [-32957201535758142145440552345337216], [103684663954326323492721797165376878], [-62607046165733885670506825398848076], [-67353119724666649374277953443575680], [87400723451479016245800388653520686], [-69397552746579622224139846554401674], [-155159107193557391970793384070534766], [90767052573906765085344463065635594], [125664890632014305295722964312182220], [-151552602779467940238758847533202850], [-385318895828440953846844308808466640], [416262254002530084695556512742465938], [11511906537479724991645899335613272], [-744063888232207508494571936273649804], [-684230372163198899644947387869002014], [-581402634223231174055817945569357158], [-850698766150796837626159572339038970], [1066161078738410537661218427101532608], [-912847494030178469237860022772106212], [1954561855526664541830536625453333504], [1675529734347040370962609566319967624], [1933472848311726526724698199786961444], [-2896233632323570290508374816572323876], [2040998683343539403298918742351768872], [-2372023164100520078593057389483781194], [-8173749007503381223970165808722032902], [-885047434016660585573594097617685340], [408869115823247998692763224897252230], [13224216105214745951986785101648442764], [1384131344305785177451911573618743526], [-4692604847388300684333186589750723716], [-3717081328173417988251526326568317558], [10837297915008514248815143602099220820], [802377833419028437053470137466972354], [-31304418864081014796310333118473190844], [1867882574162399948778656751265961010], [-21317275947616496205254145813258642936], [14340480389819747144406199064377013258], [-58837564651168466032157428479792319888], [73216461047652768751485512921085466046], [-12981416905899634363740015014281890630], [-33253043186600630170952966220754196764], [-57035237560959771117941449510332828808], [87129386703130142048032315701201647010], [17857132181713630615355774314406085548], [55348789037492567963044394483953643928], [-121420675450567488008139341162590000506], [122876644312883875922651248754471777532], [83931525522900276749533107100595304974], [154387838507027082644427273773869797218], [-92943470891101718686008265449653896242], [-146931000062927122719010308308781265596], [-2286705266442546331215890784209881156], [-256701520456346319488115830860490504586], [-302399817230039956820495306028702761218], [164757567233647398929063188987452044880], [335708054571043752754617877512668817944], [-300777479778420428948356077745470994426], [-134953597615824042087662004497672049748], [883345898816092490735528609995776132888], [-58782164203039942135535504527939405120], [1116946237789324710600083264539613777294], [-1033672477682459736722294087772460381302], [968618067051923111639906864676615902978], [-1756114806225283249805305646536797078834], [2333249760592159135157326366307502397532], [1725031699577132506171128745613542703670], [-2331743442365990869307386674899247642726], [-3045520167197829281046670957814549563324], [-1192098397611885945804742578148913003682], [-3931707429400698218757756289390854353800], [-2099609537823779660424951305926359319596], [-2200808843740970460651278074367066129818], [-4537911740686982852964629370845347026024], [-4879226640143981686732200436973947390258], [5221577295693702794018057868577918560234], [-4443821276696996371414271316134631400876], [-391807687694425521545353923358332650208], [-887168673447253688989099994357618363626], [-10727745360580606281133911218516683173294], [-850245871613052441575662649549050355332], [12002827034006854535864115789369530523720], [2966191262686625015193070498877566399268], [8057202670114750341327597445117599439152], [-619826834813527993916402018410308913384], [-1535074829411260753720978194467157148734], [13388233681802069489394977317636586835962], [-4367175238730785549290961461588710850522], [26170184551309470887351590160114576760732], [8797870571330291688087323638591796236938], [-12829190461926044438185630852937485638328], [-12429965708952922593673876374249967155036], [29760723647943645837376940069755425478866], [-31858988697433418822080521527575463073432], [-6120278521555425053961227802474670797616], [-40292039716073902085826834654855744197698], [13638252258700314689098926860358466749458], [40508197284312929995883857137613994797758], [30508038680081542491905602909202746381332], [2449784079959176271926919016297774451334], [-33827599448116132524776691842380999203336], [18252788322475645052322911693839869137690], [-31033578285962028898988984417390087339296], [64365688048510435239295483741825514551242], [54108370850961945519167897602099109215028], [-61817904641590120748022984361975831192818], [-17527471699677203808011306200777137280024], [-7164450085107963021313206298044840910954], [21565953555016908585923822502176877476336], [-124326231028735720685521243441658222169492], [-32798450822594775536946003750654460602370], [177494333367699406693391800276491983920602], [191364089871917830061153734166239533247920], [164252579592354678510078203872876922089566], [-250758413094947896884044366906465798563066], [-14910522453894459497584420468058720890516], [-5918001989310958633761689741918881815046], [-156319099797722587449918735803062144028544], [95023905324600431763918178977867055656194], [21778449838630698110902237060871435220036], [456206704037484585620379240535991403429692], [64708785367665285208611825573517271611830], [75340257763737806672922860392713917620908], [-26958836136267680427208490654071756035462], [505038635063715788410360873967942649928850], [-767025061949084721308204046282220677520858], [-818793442353416704247284964181833092258110], [517588609241665273301496404234497048602168], [-290486535756978814081090025034622525467258], [-370254820049153512665134069031394542920512], [-79573931724874793735090105699948049377554], [458554971213580624380023567094786184488866], [714256518235919215294619269078266777053700], [578025999620599752134713230387820495814070], [363576034120775745069338193880573331614160], [-1039298767872971930324492474161664788661076], [1722267446587498178780668810486546830159450], [-68052856969992597408046895488497610923868], [-1482555202410078910730248844910465524571214], [-107910570709091802678445563364835010186978], [-379604549543777652550569872024197009554568], [-939700303220410563848967458897102726432460], [490867213027303701603727768743733635440568], [2140657609378000635591096042913854285752186], [-1137737446875863568525496477935923492179840], [53842840945077539383603804541514043929234], [-730066397870325221833728449432012429641752], [-1229929760733054684384164358350585857806282], [-816790875427389702877438439325641792043490], [-3351067887017955137710231149738759894037480], [-5879938210281152162004919108439278137260190], [-966350190684093699837350701373727076107136], [3854006130495003491431656318765738924467484], [4436524331795519252685618461147131868050958], [2016315419858735544536086256698909244448138], [3622275975730921679285428279384273063625280], [6007984899876190328841871585611889421593640], [-6417145143779771968052244937479262671580572], [-1933881581103341574537062577055806829929034], [3770998143995570115509645391420368328956540], [7751014663162317294498603385035255861990224], [-6135200803511441992482574810364208750248742], [-12020908396774815511375242337224439600133404], [3234282007387556559074774986917703766074512], [-5491671719600260501702794191639038251676750], [-9016283108657087170500722820661612989242082], [5280638880192697539555981937294475596571412], [-4412130366908785922670794809934098214614728], [-1830115420664906738650137645668333964707652], [-8835755112032919379262188765985874506255980], [2356433851206648185090733208662175267092584], [-4852073400888107868550094987163165696848458], [-10692160702896685284700125347835979813284942], [13552250693693891550779159959872964379967048], [-9048243874397459257221121690774018516143664], [22598167811779620904922790399576293663187564], [18377496668872095881610179180541469413282788], [-12641472255898994860636072382646596951433072], [-8445840292612894308212326940814520252124314], [-29897132527223388169676882470488778414438014], [12147575649591921077104814484289827512354904], [-35759777120331545867516029662185050617319846], [17839919659692444279756344954831977440967398], [-32686547019516021272153248555926480847600452], [17125245972283563060221416381560729086190446], [-468582239235539686549644412411678978892236], [34424788529936713390672986695923910998659054], [-3938540633982374158703662597164903859686166], [-30590430320896600104558419487829895527232560], [-57089558362861059010364781106775622873533364], [23100214533946286750783867642172246559419518], [41095726055891478740594235770525465420005478], [-4717926342370875000224232788923146778939326], [43566438828897263040087288417443834933957996], [-53519354235156261516443703854483760600385050], [-30427173653366473700548096483302248542528278], [-65234241342514356215943569831417208016181068], [16447264332719186919164550752351272411230702], [1637848106566585006477269279373414614693686], [78910316885110972269099823381413070018839740], [53480234320791417058990037353148337674275082], [13300874181275512048481359272149824974752720], [-90519678028575096566978564704945281980694958], [-84205200668966428523350842041806781483307496], [21268777919605009578440313501894792505873908], [-46969365012255880424390053045251563951510458], [-151574361232105772325669983085444943051340902], [-20616873136225360950903308321596720862905860], [-201026125292685755396317435407981120469310784], [-70864461532902532033394276602731498942881560], [36318941726034860434017176354761838384456616], [-227839956967573846055120688349396670867010850], [22316086653261839222181351788549550694612772], [-140994955753930561109564700643697063359696656], [214891649654738915292051158100573772402614962], [-225572012046462061489280240714188610294828706], [168808067739683834982870807166522939507505432], [300363048032643364259886400201471382068760034], [76490527913568010703640761472232821784068390], [-345466210736398116819179623856987630173647780], [-183680535318422666912484712694054311656775638], [136907756545111584489115276082862436587603780], [-142749555637271181307641480552574306880450122], [-137855484624805529812243230269596876843587978], [-176776092381090564819854261833224588423651664], [-246879473059798546930703177807477179481468514], [224414837129725386810316825395394477820033460], [-342441169467968672084082961147493373616636756], [124967909433031220645232717080740678395196250], [250167299915266798974210509641596990655030854], [-111250130343154448238896857896394842166434400], [-436758636705990730342808813653166037414293124], [-356670207386615630891546745808797556924672492], [776448635921220893282722452188364045534958178], [294935656744403831974149447761260400238308676], [45159721478343544721487676654190670370566326], [-451777126961754025771886805080470524827771928], [103802496102055348413188443054837473750814622], [431869499352209617392568473162994783834594416], [-177294505977766415340589104568135476673209666], [-1579641322585230232889814478880619247552254], [428417035617656524657410205406096618722920716], [1013482954500099201551080894598346751662568536], [-121791551428446090050419318940767412909789446], [-276806757150897094064243652534353643487844388], [-645363513760179068094259638666759337852637856], [-994269168429193500191777091925381192722925630], [389603410801262319011176104245935274945676210], [-213746244711214766871850199905409213092626436], [-224941075357062037755767460552747202752285046], [-370023208014260190703613282442406268827453674], [-432683154450651547785346269932877800794043632], [-905401227607225607849162405726478200638792038], [848964144137040054582767291223453108892795922], [75430260192952776169553693256005204300912300], [-1511786984690441268172558546539565296285085228], [1358158494352842718998635630221559640894796896], [1007471884970426781652929597679570964086388622], [1189253128315924910020851571052210181302574902], [507624197781653962713085019809416788379869142], [397260113909802909541671982231340720329703888], [-2022310694214265413918643002392220941632316340], [-1478436335943529824625752335881154624187437692], [-1390217684907006886605282883066396870067892588], [1909148057666273937212590066630062531506816294], [-2847435492387217477098231965451368785805600286], [-3176554647157721043773365472175202786338669766], [1499868696282603026311022381306667812938884320], [3224346155424175165769944653505625789382756782], [1754760864187548526080296914513987057581446346], [1900928024906252670227337782963270252323412238], [-2194139469625035400004433694270760475239362360], [4336537505211321131832941489387972961542740374], [-2812793930381512948693752885782130869431871604], [1425804975157628321828993426282183532991862558], [5173690345986403117675414518133758101749620452], [3290337704904657271160062888615848832164738288], [-6249563611227323385908017277281025909053402146], [-6360608388265726551573061764804599552166653140], [-4992195190133981624141421781347453069357436390], [6791767051571736418384218294908026948897978662], [-4791079112627369274454143354292261391846103424], [2495104251394189627847086998251163959996025806], [6806654175676588585371438395664128116122582282], [1777050303531088587795755426342861012770221408], [-932267049260858683979466286344557763132217308], [1268894029656070527247405424314862453041784178], [1919696841329420032082102987955402043814785416], [-5454451628675137214388322080067968882405296290], [-534312981124893506996269136196525891946422438], [-2574713702812869632062711085139833562857022480], [-9700057184748783802023596183934565808038794540], [-6862571126596173129478117014210056714065174036], [5749218918204413375057235756258539466544618874], [3702984128953971586336009611529773908351190150], [-1552056653138826537387617861649451933822373656], [-8719967373757602143645541797399627175066303094], [11516966580205502690345811833681907603144042636], [7772658702053688830708862883360778146191174596], [8818319516575898158216958110753774520247282576], [16373455465539140563375622284897398151786463838], [7849549833974519229968681894686444654706130680], [1103066091387036734302081587042378415156189286], [-12738426602193487684917025953668891198499862884], [23366953396003551007490250458532313429751538528], [-4241895156900465984788668229415905165688711838], [19299254889681040557599262927550181336422065138], [7790797634535709706698129424006761227688938602], [647774312268416685146315566802291592669087318], [11265244169933759616767740564800802726882120698], [-1865989508445352817369731154744809555004245096], [-9092979499843884499158167538075366635030188254], [8620507393169591831418258366342745187595448652], [12063155134170666382638892482141068972354271576], [1590062098986316712873461776531587291887427648], [26958962245836803613760492766498916467813692622], [30483625446154561282271709298623127206615969236], [27112755177897022735296088286439028835377572192], [4439314674039160468248328084221061716724713218], [-24790126521258578388001186997441821519265552658], [-5406097104766591931828524122159799203853087932], [28469892248222264710637190264527912420723751836], [8275730523201939291067982325885820415592248424], [-368613389959822033125680077176814573569220726], [31426306522699642423695446284934842808479351088], [10761214407177538158891364162699738549229699418], [-28122379715390568678278298024981208722779907580], [-30989612571782850107913172582481537686757200194], [-40191102395578789115023662899257779708030845434], [-5281800269824684979322370000616511979978367070], [-31243314946086281153263290601214053625806312576], [14799409263913113228881081949223066497225648618], [20401808647772119595193934481505281786764970670], [-59407253151508366526587833761764308961714753336], [-3162599838649197820600336543459317177241018762], [38669539308759175827536845993372083901151231154], [14928670902920270598625441764719806769396329148], [-1269558472823168591570638297304877989173494612], [19014254155168671609681342894558053651593608626], [-63334710039623659201761442298360650848652679778], [34843141396308396684055292415722719792569034260], [-18957448240440574947351296600748751154194575796], [-7118587276006044402936526335410635143373411846], [-29122984517788834932210373054975416518137552506], [-6661231719529922907503160908275886925777265344], [19766682583949611622506802020173183100052653544], [-22517694484734209015923163577902872196794302894], [-3036936689543298269434143605288530277638248312], [13336571536936864079045090656628813257359260598], [56757446225194192482033292295713627911002710142], [94800331709544307605656005290248482319872841424], [-12785353096904986243481020854231474793214117388], [-38260944104756194094328428614847754817054012774], [131886675662713906699227946529399597876099687334], [-118754420891425128587540081883469955930887906212], [47208142739319280800122986958416320846085164426], [26491687661999163006909800016632184615955032980], [-20084089154887187016709063333019621439160547736]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6_28_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_6_28_a_a(:prec:=1)
    chi := MakeCharacter_6_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 28));
    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_6_28_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_6_28_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,28,sign)));
    Vf := Kernel([<5,R![-1992850350, 1]>],Snew);
    return Vf;
end function;