
// Make newform 320.10.a.p in Magma, downloaded from the LMFDB on 01 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_320_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_320_10_a_p();".
// 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_320_10_a_p();".
// 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 := [-1512, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_320_a();"
function MakeCharacter_320_a()
    N := 320;
    order := 1;
    char_gens := [191, 261, 257];
    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_320_a_Hecke(Kf)
    return MakeCharacter_320_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], [46, -1], [-625, 0], [-3454, -37], [4040, 166], [-55974, 252], [-163766, -956], [578340, -3484], [-528626, 9517], [2106130, 5912], [-5680564, -24134], [3625930, 51896], [6515218, 182956], [23967038, -8701], [15457146, -135245], [-50461054, -32140], [23681268, -699384], [-101817214, 342256], [29436426, 145537], [-174950396, 387506], [35580194, 2649812], [-226043672, 862932], [122432718, 2988231], [-128036630, -2272296], [-92475286, 9414300], [1386972074, -1005880], [-165212554, -4131775], [-140953190, -9371835], [-425306014, 9682280], [-120569022, 10549464], [5118831834, -2313877], [784569000, 17021338], [2395929226, -15738016], [-4707449468, -7500904], [226602266, -63383336], [-6534885532, 760426], [-10115253038, -7246184], [2020392534, 11851387], [-8165637030, -62232097], [7059852866, 39800728], [-5585120948, 74359648], [13603737994, 56494896], [-26700598876, -14829826], [21098091290, -6719756], [-6585013070, -37023468], [-2896183800, -155979552], [-22055419320, 82581474], [7173295054, -202711855], [-10789122358, 31076689], [-364294, 126955360], [-46915638030, -17033924], [2814042552, -182091012], [42417923130, 30991772], [-14023709544, -141469754], [-95183403790, 109861000], [-56955189954, 490443021], [143569819026, 172365120], [-7553118956, -286466450], [-46038530086, 744000696], [-61243175406, -401820764], [-63165690114, -255388693], [117347488986, -463361552], [76538453850, 968208737], [71025457868, 287801574], [-28250748182, 828225096], [-51641783478, -185367700], [-245622617808, -962469070], [234403104930, 443679064], [306787876458, -1008077979], [-46933437726, 2955004496], [-104083476686, -1722715816], [-123645827896, -40556848], [-382098722270, -202493985], [-232549850214, -1693808984], [-47664536740, -894686700], [134936439950, 1678753601], [320707505562, 926654112], [10041307546, 2538746652], [-389036988718, -3353794784], [82505978322, 3472211908], [-281201782004, 5521632328], [25914147338, -1575934184], [826022544068, -530623578], [418642409114, -1283275156], [561226612024, 2380746048], [139369145894, -7028385305], [-47352570838, 6196250636], [450007188522, 2416550128], [1078404792258, 3367672040], [85673513742, 8315176681], [-791530154750, -1056386787], [1184393036024, -143465708], [56023364714, -5700299849], [-280562751416, -238933130], [1874272759236, 1817320612], [1696373324278, -2922014071], [-1761233239646, -4713087712], [104735242570, -4613502080], [2682704615246, 2296251211], [181940682002, -19599020200], [458474779162, -18665953079], [2000096474498, -3850653064], [644108136142, -2132785321], [781971077650, -14724224012], [-556966360592, 14972878618], [1003250714658, -6076001840], [-2130787182910, 18021211297], [3933167187634, 2596870288], [614883116928, -6121294772], [2674755586994, -19211740044], [49502070986, 7978749091], [-936375448446, -17019696356], [-2675423580238, -17959291236], [4017160207900, 11685415164], [3502310622948, 5972782618], [502756685706, 12118869372], [1270066582150, 1013536307], [549444638538, -32027819625], [3171322596266, -16132322540], [-2122920943636, -37445202912], [-1897700793686, 7017840208], [-236017344486, -22132396252], [4261638873410, 21486261532], [3306765028078, 23088537131], [-2891291894080, -10074467754], [-1795417755694, 26593901768], [-1201486867350, -25099596808], [-4357194527208, 19047263676], [-6146686772286, 21050884067], [-7271749947102, 21609169552], [-701511263124, 10944919928], [-4656625045178, -3438385063], [-11699536454420, -20422757614], [-7065384237974, -21164656576], [-7776739029702, 51848205376], [12420335864466, 2955781368], [-7079622984526, -14948435596], [-3543121874462, -30243183475], [2964166062042, -40648955660], [-7929766746390, 6777058752], [-9150917142328, -76920565994], [5518883434938, -11824684360], [6839380056094, -4387151243], [8267173129178, -78817558915], [6817333199106, -51294989264], [-7958437698128, 118805530668], [-3867439690782, -51574649740], [13304024172522, -102083778536], [6840459959524, -148084611520], [4665551477270, -61752802227], [5601987332690, 19818220656], [-21314619659670, 71364256900], [-10488108956098, 44364428607], [-19262200589454, -51612300261], [-35968198030, 115851894633], [-12722843532836, -34554453974], [11141721398832, 127598607316], [4311583542282, -190629546996], [-2080242023486, 58751412724], [16519736320050, -132325147136], [-7943572773094, 25584293441], [3722076522650, -35669648144], [669205259218, 105669885523], [-9527224459552, 102643887962], [11467993702698, 37019482100], [30004120526974, -114197061355], [4905947741724, -208161132814], [-20076443979582, 44027974140], [-30738248140446, -120178300600], [-2474114207214, 395294301132], [12324376947708, -49778681852], [-11234645941854, 91371546976], [-13267299597220, 79505452934], [-11313923888238, -2281380548], [1402851152704, -395445705560], [6231574440394, 246149710280], [-21546434960768, -163031939806], [-14942852487110, -291908698528], [49509206607550, 110302722269], [59866349740530, -144007031936], [-21515848404942, -303226800065], [-24970359664440, 50225578538], [-49288227424894, -28166999316], [-33768551680446, -116421226812], [-2909510731066, 211772330605], [-35557215506630, -336552957560], [48369599783634, 132511143928], [-39986472694010, 165531248259], [-87287483136318, -789757196], [58016763960316, 120124347986], [13407085107778, -292330043040], [30093112945686, -357462854265], [-100614447710336, 173159266438], [22787946179170, -433395209776], [1761382728802, 169929204805], [-18026718288542, 22564978596], [20214776929290, -104325855020], [37514285024394, -295606641652], [13984554130786, -150838429648], [45041939093014, 318160303009], [4047107880770, 458798253288], [-36413217235996, -25097968602], [32826360607442, 206941864380], [5039315000674, -50794115264], [-74800258381868, 364597705216], [38809093500674, 564715781008], [-152629592928864, -230911715152], [78743083084838, 717872036003], [109086569932506, -136230236424], [-49533475186624, 732272776074], [-110531901451686, 293611835132], [-29425695706406, -408034812104], [95310649899006, -480467515403], [-34028733426814, -553122407271], [-22708159704784, 537952268636], [41995530900626, -1096589501332], [-110249177493126, -18326593613], [-30166903248238, -522885799008], [-4212127051814, 351849584695], [-36327497702502, 1068363416628], [-46009489337702, -168288057936], [-78366571122048, 501417066332], [44885983016402, 1087086967192], [29440639112406, 932750890565], [-173951146545998, 155436636069], [-151259211645686, 44046133024], [7819733390274, 1063128427308], [5877557995056, -1479396093960], [-13828218162350, -524514418941], [76786596639600, 1142970629730], [-87641170639094, 98545443732], [17070572303812, -1541694724668], [-149043875759836, 141113245374], [-173275857715710, 163427552708], [-238029184136506, 18692532943], [-109785071238054, -453551391597], [-262993312340070, 436641854620], [183645355381298, -145597766132], [-1881856680020, -21816734340], [-77596786938900, -973227564562], [339907532815214, 132814668967], [-21861008266248, -1416808141034], [161684541001030, -608925865879], [192793848086578, -642163312368], [-118776762556126, -1094192599944], [99525992054280, 1360598306376], [-244695083001782, 1030181692995], [-379685915628192, 170631947406], [4596091526980, 1884670102760], [-44113894970466, 1199394089233], [-47507013465398, -2931184243220], [-321204963707646, 55746520224], [-74205153444566, -625194582521], [-21005070867966, 398752057796], [-49428761207822, -1391050484304], [39632042198772, -2059848545508], [-30445760570310, 2451722789960], [26200580490954, -1374675485131], [92390015732650, -978490518424], [232220338159866, 324358182560], [188638328321302, 145577255133], [312678810319210, 1922508532273], [185174041420826, -114963526272], [-394594332336286, 115421350352], [-7284541127254, 1292316406364], [323511145224116, 745393002708], [54943375985842, -1487064558848], [-137759969352038, 133008205552], [191851168103334, -1789919112025], [330294715281034, -1315429575800], [-203817398090830, 812795541296], [402254585112226, 1634203988813], [124264716853378, 620569471020], [-370253371818752, 981652311024], [382814304198674, -1637764859024], [-124000873785338, -288404408767], [213018907475826, -1443290666127], [-123504289039438, 3187308885592], [-84051661812382, 2493506244532], [340966971229752, 2275097892234], [-205088411933706, -1947675613251], [-522836290059684, 1390698530326], [365534014099954, -1031045135813], [25980008252058, 379688465312], [-106526973368542, -318474022287], [146376379957436, 382961548954], [-490414170771222, 80772559380], [-312318593197454, -1477218558740], [56151912197888, 3105346973708], [-229672340712374, 3366192895436], [-66957303529982, 1537488198552], [-611338015852478, 29529131309], [534000185025954, -3309086971860], [-299423604407560, -4536256369906], [-700971246762126, 3019136411216], [-574661159094158, 3161913969544], [-138186975170516, -1695489109878], [-476126675225622, 364944963936], [-114573760292292, 4444499500932], [-719771181138702, -2184508123475], [-122214321985526, -1475972905920], [-396933059032382, -3193325554616], [-773185721105992, -3304425489556], [659166784986918, 2074974293883], [68350298750632, -7134296505970], [-631291897368870, -1131402706972], [101708594134770, -981890457223], [289780227272642, -4651991490152], [-498769612470680, 2666580820744], [593572047772618, 5972573781960], [-638425272220210, 64642242089], [379123722079978, -5421612397936], [-683622201208958, -5620571134512], [-816302327144530, -2921448769617], [154956246146298, -1385575996721], [-281963183277478, 1879072662728], [126282705119636, -5595351088420], [-38975097503252, 1429633993466], [57032558425778, 6043525321288], [395342324771450, 1695842012524], [-208190646787984, 6969373993070], [-743002697289222, -3352285627824], [136965216149602, -5526255639952], [-897068373158930, -4586141564287], [1111743633967354, -2228889445544], [490271159567642, -4644829821716], [-84683971790268, -4783079567908], [-1552731781423530, -3089794423265], [847954638936778, 7215957452483], [-869031662781854, 1224135739852], [-395054154324414, -8110818796840], [1394683889622850, -2255809763312], [569655553423032, 7038842029348], [-526364672497058, -8675043183929], [-615149270028184, -8075672407050], [859653308595466, -6486254298923], [-1060026508791406, 7249309506904], [-821285307397278, 1663988917248], [-298945289820574, 2428424370596], [-51256308449454, -2818959040569], [987895705380714, -3315445777024], [-130834307133382, 10733841492928], [607955218628714, 10887087743672], [1342001761287748, -4360829920142], [-1250393308902766, 8139142539704], [2031874176742516, 4084043004468], [1178679133969114, -2201739776208], [-1116161083781990, 4436103504229], [1152239454042892, 821336242594], [1208097127934722, 2225966988404], [-471553374073768, 4401376067618], [-562812618705030, 8937448978888], [1557832883254930, -4207431197920], [-539900385583162, 12322934168301], [989320544610570, 5948684919904], [638473589290034, 8162993652756], [347601885366216, 3548182857132], [1142167090385536, 4379001116602], [-900653127284470, 2192780117076], [-1887856458691002, -2566841430943], [-1893451032352542, -4579344861668], [-1180363152836214, -13673438941536], [31599314988978, -6670575552153], [164464512318164, 11342159233512], [1417441091887314, -6969025260595], [69320250211522, -18936524116364], [-965920500147926, 17446040123780], [-1026309105061458, 7784279722613], [-7293917910686, -5460622124516], [1712240663699320, 8353036159298], [-1045806768678308, -19657920436068], [1270220794244270, -10537363527639], [1138783416184954, -10303416920712], [-2239917516433020, -5356314637558], [-634558066501878, -8780716362004], [820226077360452, -9982263735852], [495170352744252, -4669125004542], [-3221190777085982, -2269260850144], [680939543773434, -6531582027108], [1066006145773418, -2582337662904], [2624631586090594, -8202726243616], [1828776873845178, -7927288094872], [-3482039443414334, 4939174800803], [1863490385689634, -7189172309984], [97421050358164, 21367933351812], [-2435597137836530, 10722521743893], [1190108621594468, 2558564009910], [-1847488341906886, 1674968784664], [-2240490432862218, -8406976422049], [308389794904186, -9772622766693], [2028804897220906, 7625818992236], [-2177095604461878, -17142297257912], [-1245499688126540, -4180320741696], [-494299508689726, 5522337247965], [1673641390723220, 6068762800530], [-2323327050616294, 2407862774368], [433062926032456, -6607972581492], [-4956044802616150, -1853909074528], [4750952149595864, 5747078283278], [-751517536832662, 32977579239008], [138129618690482, 21175057794648], [-479853164932694, -19102169805844], [-3065511758495902, 10921522760815], [2004130600911962, -2016841838752], [-1270226001112038, 17503480917168], [-1574278035189756, 24778890546562], [-1390927767953302, 2440825650180], [3196242775813458, 19247539175184], [1183002299877870, 1871704275431], [435632961278684, 2398131583600], [4732139770619522, 3854605169992], [-1008379950352454, -19111199842552], [301163917797886, 25221949404267], [-1541578502384920, -9327162045270], [1453126630861186, -15309417837548], [1604325937636066, 20359290523176], [2233416877285824, 3478601417280], [-4136870458399158, -17183611588873], [-4050547226215078, -7331693102372], [638458945070294, 32620541789257], [-1478036965445662, 11671394081712], [932432471168482, 43267885464940], [-618245473222678, -4605032176805], [1173942675213892, -24725518716800], [-6980461505436950, -1698102037776], [-1026509764202526, 3559692041688], [2619760501295142, 33937261805083], [-2622600286775758, -25776276073196], [3615776280772560, 27366545312378], [-6361671878620328, 14711213701424]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_320_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_320_10_a_p();".
// 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_320_10_a_p(:prec:=2)
    chi := MakeCharacter_320_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_320_10_a_p();".
// 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_320_10_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-22080, -92, 1]>],Snew);
    return Vf;
end function;