
// Make newform 240.10.a.m in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_240_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_240_10_a_m();".
// 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_240_10_a_m();".
// 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
        poly := [-1182, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-4, 8]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_240_a();"
function MakeCharacter_240_a()
    N := 240;
    order := 1;
    char_gens := [31, 181, 161, 97];
    v := [1, 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_240_a_Hecke(Kf)
    return MakeCharacter_240_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 := 10;
    raw_aps := [[0, 0], [-81, 0], [-625, 0], [5936, -7], [-17744, -244], [71838, 173], [192578, -275], [201648, 121], [-111852, -8121], [-37286, -1552], [2513564, 9467], [2686814, 21837], [7105666, -58762], [-13874460, 19048], [-47983220, 53921], [-32152798, -116234], [-93931568, -201676], [77040030, 282086], [-16796188, -930520], [114135488, 882640], [-16561158, 810026], [466203380, -224755], [-103520076, 395136], [112259082, 1163274], [193567298, -5504880], [174536994, 1293924], [882623440, -2987967], [-362351100, 4982826], [-1473309418, -1094016], [-138155014, 3939529], [3073949832, 7720285], [1751045640, -8286786], [5268159162, -910857], [229518232, -13626441], [1031387866, 11985152], [7054949628, -5222765], [4419911462, -10411437], [-1141921724, 46169760], [10984473396, 14774703], [12792802866, 34619904], [14298730720, 11108450], [-4826789074, -31181712], [-5614739224, 42272236], [-6464521294, -1650186], [2353054626, 51844086], [18390290844, 44646043], [-885267776, -136962873], [18074391712, 47483487], [19422353516, -28950392], [11615621278, -152946794], [37711864050, -126787533], [22627494208, 145267106], [56523133314, 57724544], [-22163786112, 286313430], [49967429370, -1449111], [9958952156, -166897955], [-88069901158, 62183584], [-46391315484, -366484769], [67897345126, -351294509], [-7859240502, 216548922], [-69346082068, 263824412], [-42840665886, -257207610], [-68356412460, 332317006], [629155896, -282836214], [-86556147526, 144228090], [61734964330, 573251594], [-40631784592, 133569335], [12774870546, -585428134], [-123819777908, 1045240610], [184064560974, -413925622], [-4938844422, -38658537], [-326208828888, 1066475484], [240049187984, 857891039], [-386335564050, 1050860327], [-39012718320, -1476559055], [-220735391124, 4803705], [-547499079462, 638175456], [233687758230, -1354100551], [683818858170, 41110896], [440276043578, 1710556296], [-74606951752, -859940654], [-21303043362, 2854695782], [-460057817616, 1434520932], [17224756434, -2925278710], [-79297962900, 3339170455], [752552762772, 1926654552], [684532855946, -2196996788], [502364660154, -1364301688], [-535511366958, -742968900], [243686280560, -2961822967], [151724337980, -4880475374], [-1252854332520, -755758080], [1886368400272, -1516181745], [1149665946680, 2223846724], [1322938216488, 1116885811], [62930358212, -3673801283], [-889511823142, 2176904656], [-1523325635774, -1907804332], [757402257540, -3062236622], [-389597835434, -3277002512], [-439441411284, 3525138988], [1592869203618, -2819211180], [1892210954484, -1709535714], [-410230920318, -2311805436], [-589844913104, -5472168309], [2455819001618, 842608140], [-3610551129420, 7239241806], [4305017170330, 5532228317], [2629032638504, 4587298588], [3436112329514, -4746407136], [4137844243992, -5854898825], [2444208607086, -1986144871], [2433470840322, -13953753957], [2742447518152, 254668959], [-404776385892, 8475292285], [-4844300635014, -8211978222], [565659399380, -14443513972], [813747304972, 12722974595], [-4461442772366, 7015482320], [4331842167520, 366416660], [-1399446481818, 8649674330], [5225849739202, 8974014046], [22722883866, 8828240496], [-1171252869804, -7123418730], [2692633391736, 22668756931], [-2556466450550, 4048093556], [-360884773698, -25610174326], [8104246564584, -15273714162], [4715208650368, -22001410173], [-5619922884610, 18253691847], [9158375065032, 17854805959], [-4273563406820, 24719471003], [-9161760162804, 19539413131], [-1099550165898, 16926594143], [1139867618658, 56604066252], [-2429107376014, -18489819948], [-6440748115806, -7580058030], [8496953605980, -42550403294], [-10188198112670, -29502792376], [11778246950050, -8685229870], [-11220333059272, -33353323585], [-13976203493502, -4543251348], [-2119964177336, 17548247181], [-282924531068, 822348860], [-16543456392890, 8080900960], [7341042374120, 50998665520], [-1221001766066, -38503869755], [17882951348810, 32947853269], [-14779955872320, 18588914005], [4642715516060, -27093151217], [4217591638054, 107197488307], [-3912977588302, -29607320978], [6872995621300, 44666589108], [14394326091300, 29464236771], [18340880446940, 20472868406], [-1282211661752, 28454156930], [2075891713620, -17120556845], [16294184574202, 47743589984], [10195071889306, -99508711664], [-28032859925534, 12136727588], [9525859356708, -30288849738], [11767717692218, 10912437943], [-10129333596248, 69382738035], [5523381556224, 60112872282], [22238546600978, 48927965485], [12447405950748, -161412492261], [-29468071436852, 50095497645], [29767673877982, -84509943557], [35543035749890, 35012604960], [-5288213531414, 194109201104], [-29162339889552, -55556165904], [-29474267096850, 15482644496], [-24556987084008, 28914831108], [-11337829754966, -9902445110], [-11012541924204, 94070483017], [8916190651002, -76078134306], [-13751495949616, 41908753517], [37387830316314, 7222179084], [-28591890919760, -93223928457], [6225343111470, -174682720000], [-46015220015024, -83391659907], [22258279840256, 13841835196], [-20274473746074, -187883076721], [23727744047890, -130902441031], [41020721555580, 14078084613], [16448285725610, 136637069500], [8092164855598, -2684264135], [-15357335909028, -62003710418], [-55639827232966, -186307797912], [-45960975562568, -230529689752], [-16579360080750, 211801969022], [-4698022958276, -88556910634], [40227906473360, -1460239201], [29006351269634, -252579919136], [1906895065332, -188470683300], [-501202394894, -145111754911], [-19539271453806, -406594231576], [-50535498880754, 186445079749], [32647478409210, 48172868229], [-27964155480964, 333741927715], [19439118043266, -122930004708], [-53476535762140, -64801014271], [-7993823437514, 113024226721], [-18751951316478, 484091814884], [-69985143830376, 333830909898], [-16201542478566, 276898957842], [-55988985991652, -326163637209], [-59185792915964, 159269671850], [-50533843868934, -111883086078], [-106619521467128, -17063123127], [-59201355143998, -104898251742], [66660738126442, 206526852680], [70759557557408, 33684968129], [32061056148772, -34725276040], [-25529239308888, -557061631446], [-53730444235030, -266154996564], [-166388310242352, -168727890413], [-53737201581270, 216881479236], [-6217845754636, -238921924751], [13157755180530, 7652272812], [-41440508756802, 229393094222], [80448006157756, 117856137807], [-144302614830150, -129093627870], [30946337006784, -2477350079], [-109637920102900, 517298903506], [-183232396545610, -429155968980], [-68880209889006, -113820135015], [-118861195618072, -256965400754], [32474467853640, 176083447741], [139301404592472, -502877402322], [213736704932782, 252858987001], [33378441743808, -326626008329], [-49314945919964, 569146441071], [-204676251276070, 262334914726], [159099002382964, 481852231266], [132562335810972, 653328030555], [75747611739154, 355875329608], [-69810645167846, -325353727180], [112272404281608, -435897066174], [9401519304720, 912264101064], [-116780410763916, 214528915746], [199649487775232, -533708505337], [47323258543656, -187834751975], [137027624504686, 650739109342], [-311576576026086, 191030000655], [-56534018758088, 283998978134], [-173354666145056, -444016208541], [317634951490744, 431336420372], [106618086281752, 514711616229], [-126906969673124, 733491319355], [163304173511694, 370230695507], [700594878482, -213618768740], [122166548034636, -110196151107], [-7167815539622, -85096363904], [113660200461754, 304200644450], [90458876030256, 877185367272], [234281620269582, -542181381700], [146502460147252, 745895474850], [187801689355506, -139289844114], [-60718204577494, 1052409107406], [-72831928105920, 855656290423], [-176723199831484, 117211876618], [264654486053774, -271843306962], [167394514804246, -629095290731], [15218095884978, 726112245555], [160220073562584, -741001625477], [-120533615720878, 582725171164], [54849128059930, 1223083500356], [542506388923588, 498605646234], [-347142481332934, 312972947944], [198130911211118, 148851678132], [364893077986740, 1196925164566], [200379522233594, -2002581917010], [-64339450380124, 1403875470317], [98462786253730, 2123419853254], [255375930840496, 214910825445], [-210252089876916, -1057167583506], [-145280357453810, -258689554250], [241216566919114, 1590936156664], [-258121887375816, -1388199351678], [-159173322839692, 1048755687349], [77716761259812, -2072645358227], [-197884197891124, -526288544117], [462276632370214, 692282393884], [-206015414125300, -149289556234], [191552381999304, 1192253844792], [83935673302914, 2951833483460], [-189139975750998, 1846065099288], [-480018864026684, 1441807680537], [25994203030530, 2260912967280], [414966453872674, 1086720301784], [-485521926854380, 685032410716], [350218685124834, -1588612662165], [-31817872187688, 1766214159498], [562719793766054, -947121121695], [-514517962023150, 776356345800], [-542543204948252, 1544043724725], [-431799080483982, 223437940398], [296577559203240, -1595194623210], [-374660830393652, 765238912452], [661267431932266, 1426305927034], [-356139334555678, -680192761652], [-593710990761084, -1127280951473], [-484200201247476, -1239422420094], [12071011892040, -3877444543871], [-644076049830382, 416681507280], [-167893559356740, 251249671476], [132334791208262, 3609946249554], [1142147448754968, 27394480326], [-85633254613730, -1396569443513], [-315937833300, -2403835468737], [-1291423329811998, 460641152304], [-62066425041894, -1034508731652], [82966721460916, 3363199326210], [-613365738853180, -1760153914139], [322855707107562, 283680479084], [-427871316189504, -297722625438], [-65353329470352, -3489502016970], [-90007243059518, -1676233855034], [-765229925191086, 2906385588948], [-577531263192416, 716511765057], [-684313773718246, 714830251842], [847840038540314, -2024568207356], [-651262154698440, 1664418032863], [-368129300865030, 4969557836637], [774860602532514, -305244792616], [-1110850366654400, 1382530234935], [1114981197137076, 515620273000], [-22640712323772, 3830672765967], [-651125925365974, 1241072732284], [-156053371605338, 295745349910], [1500834847695938, 1314985327240], [-232165181337860, -4703008088565], [-710517975935668, -3117588340778], [441083289507040, -5832098049351], [188933968500668, -5359649323688], [-944194107199714, -1990113106248], [-188084778295814, -2744829243781], [61054899471290, -5293133029404], [187850183740952, -729955855735], [-430277507431170, 3510404250767], [1083760012927594, 3247917257957], [958902003472818, -3925302783624], [22494040183748, -753987729595], [1362035821838906, 2503521991174], [-93879052507800, 216598893480], [-77505749110930, -8632520345874], [1851894096915684, -1719074411816], [986225180172144, 4975784342862], [-479717929846094, 227565164606], [-1402919869407784, 5504064600281], [-397084429521734, 5920890180496], [599202532184986, 6038549843708], [475416684606912, 7596924841747], [-552765819096938, 4818188355934], [-230680051772334, -9417350757441], [-468925390833472, -4064872853684], [1009942237600632, 5873009271678], [363035035233426, -9173451481569], [1240380728410684, 2840037190721], [-1876299999746802, 251165132135], [214640033079338, -5233257838928], [677710676084724, -8258862689361], [-517384253767208, 6037346919194], [-1108475152855580, -6283407189744], [614931257426922, 9732028349936], [1491802586294058, -3345723864930], [-1500595542613576, -4798723370869], [-2326202521948246, -1753226647716], [338958411980352, -10401520922922], [3599929942885808, 219313929581], [-2237529211613492, -5841972214531], [726657491278002, 6637962520344], [-2465116903803748, 3282064265063], [-1148376841209666, 1871577801047], [-1825879550416952, -7611995998384], [-727579151933160, -5376059075706], [-1126160050125502, -6738567708012], [1227744042436266, 484751478432], [993075950515290, 4421468466464], [-2329005737018558, 5882202180620], [-2834752957983270, -656767178673], [-1562444523368016, 4212337329409], [1444545284365258, 3311512004375], [-2811242039003104, -1740595453693], [-1149137493066500, 14374166508113], [-3241185759135428, 2529004264563], [3451944129059270, -1739609259741], [4309635760333580, 3312107131118], [-209478020919300, 14069206426371], [935420780463778, 13922456410936], [-231686979566134, 8964699928084], [830635392275536, -2679706970608], [1438172770580716, -27242739222], [-1046867742210680, -1224815589736], [-375696620463286, -16864280380680], [-3745859714302580, -644574410895], [2708440784234418, -6449511137514], [-2042463076705416, -326790104543], [1589477711244618, -7317093151368], [-1981525668251634, -11603861437048], [-3909324576987822, -3898282226937], [907309770949656, -3276983475227], [-247085003934086, 19688604799427], [-1399146846375998, 13859191468064], [2163648042619404, 12136324193677], [1927454252486078, 11440455543855], [-154340863440326, 2789192099984], [-1257796379817244, -648626208040], [-276901729666488, 6097724969754], [23459203411618, 14424806188888], [4250928675385050, -7685401079196], [-513003039120092, 6188255371694], [877163782007336, -12971221200889], [-1505181021870310, -11915045392446], [-3522727904462902, -9823196472668], [565228660205408, 11744076991936], [4201342495283280, -5067449144519], [552963998699394, -15373526072793], [-2298034736734828, 6390441355087], [-461222544885614, -25047803680528], [1923227272927566, 18055820304911], [4691163643123764, -9060229994661], [97308127124872, -18323333708536], [453428752982378, -11344842206562], [116303463277850, 1750063949974], [-3227256472429132, 34740621784], [4815793259389290, 135853838340], [18306729777736, -6941807078979], [1558647796812232, 3441764167604]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_240_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_240_10_a_m();".
// 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_240_10_a_m(:prec:=2)
    chi := MakeCharacter_240_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_240_10_a_m();".
// 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_240_10_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_240_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<7,R![31528560, -11872, 1]>],Snew);
    return Vf;
end function;