
// Make newform 240.12.a.m in Magma, downloaded from the LMFDB on 22 May 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_12_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_12_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 := [-450, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-128, 256]];
    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 := 12;
    raw_aps := [[0, 0], [243, 0], [-3125, 0], [-3892, -14], [-147784, -121], [328746, -281], [4289974, -305], [-8813988, -514], [14920536, -6138], [-100940974, -16492], [35528504, -25157], [352929242, -50121], [-163827574, 71822], [-1596276060, -13846], [-1026532360, 30932], [-1152149726, -437282], [739385288, -938311], [-4132445730, 456274], [-12106088764, 832090], [10109444128, 3216340], [12939791634, 3552418], [-11162497720, 2502535], [-24007254492, 2197008], [39604841538, -6473406], [-18537613726, -351180], [-104485799526, -9473544], [25014053980, 4789764], [77285556540, -16191198], [19600117598, -9361296], [83915815102, -22744553], [-72078678204, 8418980], [-120185371320, 62609931], [-567237674874, 2429481], [-38653808372, 120799494], [-390745960606, -51176728], [-814087982232, -104627455], [-688489186774, -19361199], [-1095307755788, 287680680], [-597061516632, -419315544], [-289618441398, 335132592], [913017917120, 184155725], [446237636006, -396611028], [-437320756664, -501258566], [2944629402602, -31602378], [3773012466498, 16941102], [1610719670136, -109042477], [4406488768084, -1189813182], [-9947208050636, -9692964], [670969338988, 1123005466], [6183459629422, 738168926], [-6534273524850, 2444498361], [8307769584872, 1719843746], [-79045499166, -2519687384], [-3711445646352, -4880957055], [6506701133790, 69205263], [32766616025752, 42013180], [3474594774418, -6115959056], [12152467868016, 5686307219], [-7816868384102, 4139754977], [45593972842338, -691478202], [-8986495489636, -2657857034], [20634070303458, -5144734950], [60284690887020, -1207783228], [-63392411673984, 1703185914], [29248274666258, -6175430970], [-35103111057430, 1272133778], [-18393559381132, 21711805660], [4446215148378, -17481985058], [-7979451927484, 13193581490], [23767946854206, 8669194618], [-2858602438314, 12729529329], [-39145690451352, -5315828826], [-161443599995308, -10737550742], [-18529854464430, -27374688779], [110229875863020, 8753244380], [-80617726377048, 4729722690], [-153586679832318, -14608212504], [-98082896103630, 9290995003], [-195585607702470, -19051268796], [-144116235195958, -20574608544], [-30035213897768, -35306897399], [-8283542124402, 19546523458], [-106233092345616, -953883222], [-110103402679302, -42698386550], [-203341482355560, 15168157475], [-177590956312716, 56130795006], [262568456827834, -78129285788], [-281954528408598, -12372815456], [-385873067364678, -11735139720], [-65116220099380, 4235286334], [-153805242511580, 42882405172], [775220258246040, 34442968080], [-417127845659804, -7361655360], [-201492317240960, -43929649769], [-454084989087108, -33504565804], [-652112864688896, 120934935076], [422753178683602, -183462088844], [-410324687134, 94828150052], [-1178206734878100, -4280184676], [-1490090156657954, -73817751028], [-536895810577572, 73543596746], [-767208059594166, -77137347180], [851546377809948, 318575732238], [-38278235887902, 19683728664], [1742180302158436, -47306727756], [-94333847683006, -3193554540], [-959175822468900, -13457645478], [719185759498670, -39255641989], [-488274307675544, 124208816038], [-1634915914425766, 183336039336], [-1615451129411844, -268580330350], [-86163831831078, 284309818867], [3035492006314686, -94827563199], [-980618264571332, -327784790526], [125401480960848, 85367645555], [2189790402353346, -108966698658], [-1532719097640460, -536023763036], [2685648837175376, -337145078500], [-3770303729276182, 166791597980], [-1167189120987160, -665334815485], [-780451185231258, 42005288590], [-85324935360806, -593957235922], [2457291792681378, 779537112612], [5974694701107372, 227058644340], [-5118351261360324, -492686787406], [5312176062133490, 257860151564], [-5813845263500322, 315109361434], [-251176986973344, 657087415818], [1905158246619364, -966090198516], [-1458785083879630, -863549558019], [5598689077850028, -265400531176], [1567972912737200, 614066444954], [4487974766796936, -456947367841], [-4113865114964454, 1282016181301], [4849767357966978, 701361197028], [-6281053827423166, -223895009988], [-3621298435790862, 1049314958610], [3712034855247780, 2233033766792], [4328965460629850, -1640925296212], [-2224895703324550, 91450469870], [-6583879822301092, 1133862629440], [-8329636781437542, -2084293579932], [-6896983951449212, 1160011212888], [11088049668776996, 554022628400], [-8559349385422610, 126559211240], [-2709361625063720, -628083559970], [3579738626205898, -137960535745], [11930153250495790, -2285188584677], [-13533290637340020, 210723852500], [-2081360341598000, 4552057865464], [2207369332632202, -2044073247511], [-18612616585572182, 62709936238], [-2828407635144140, -1091508822516], [6592634356521960, -2782397447868], [-6949919540696860, -2596629640898], [-26194624814100832, -782999085400], [4084325630156400, 72278384495], [27457394015072378, -207365720296], [15531730411394698, -682205376508], [-9732714467926294, 3072989127752], [26569435702702524, 1340308558224], [29889263153804326, 2782887282649], [10464414288482476, 804751821000], [-19819480736998656, 1542325979493], [-22469777978049146, -731560864145], [-7101954369626064, -5387183340438], [-29390235252414512, -3960999032835], [-24497796980311694, -3374633070799], [-9105915488544670, -6783849399840], [-5005233363690478, -7318401506308], [5846044466191992, -7862747606199], [-28526848362867690, 1114003569604], [-13665120040651128, -3595738373568], [22671568444228738, -5767519751830], [726451542971064, -8761271815993], [32855958505274178, 3254857375974], [-36981224221991956, 7709669113618], [-34432005461324526, 3397134281256], [-32372141521479500, -1323235237446], [8047538631776790, 9112265061280], [-2589416662546772, 8267996756616], [31445911581561976, 1352416993669], [7026069464234922, -1180643491883], [51941849219658950, 323433894323], [-19143657929792280, -15801391673466], [378290907068290, -11974692679040], [11013079643246794, 3752388668915], [-853466120546556, 10220999178266], [55893615147221546, -1803965968392], [-75290744169334168, 3216742809722], [6381318846693450, -4458192054854], [76493075471205428, -500628754492], [8230339439917220, -3974687393114], [716924554671994, 4124696769376], [-10666094688915804, -2416092438690], [25558609603824902, -11854498218613], [-18722949533198766, -23817483704984], [-2686480475503718, 17315967796127], [-32608332310313010, -3994367034237], [73085453404669552, -13459982548070], [121339846033442154, 7315338699912], [64784896628778200, -7102888352459], [-48730871696844542, 5507184424547], [91753320382758738, -2430434518076], [87621002935419336, 2540119879383], [-73458417388465638, 8511751851534], [118465134488205592, -269210441739], [118061677285218332, 14985031290770], [-41559109837648206, 6253294078962], [-100320538546269548, -22254908080518], [103516330543509386, -7377967537614], [-52516090577143918, 9740583042920], [55055191606460396, 33076800780532], [98189159105545556, -24051582338080], [-70770811720198752, 11896564829424], [102314751602834090, -13250207532396], [60736109653383684, 1660210287914], [-113967253972849350, -16698578299656], [7774652920440592, 14958142418218], [9128378094864570, -11055682436064], [-69614971213458162, -20523570021062], [96081200545664104, 14466772485807], [43895808793062690, 13395416176170], [85502501101387548, -30761584337782], [-120660897623346380, 8945668822372], [50036146421177630, 69605430094140], [31179450685470438, 44342336778795], [10213137136084192, -32515498833974], [237999461513680500, -3271422271258], [-193966022176484088, 16465813543017], [318075940925656234, -3958700615077], [12886113166607172, 41600744233256], [-206856391713861104, -25570303702281], [-109901654196444350, -3961471480526], [246832228747572028, 33244370273208], [-41659651164839184, 51383205463890], [71104600213792786, 18538167620168], [91302298241534738, 67238053696040], [56727924233931672, 39723513305511], [194405903218496880, -38854656832464], [-210192627473250132, 68150702306178], [25223236017827972, 44754779091412], [-309226327479094188, -4351752380500], [-301926642731248946, 24142527910862], [139624199047534518, 3558792772785], [318529384049243168, -2555203245796], [415695267671573812, 13414396379118], [-175139294005667056, 12020601869513], [-61694226639942812, 73975231107864], [517087140439876352, 806232604820], [-469902433354887438, -36266244129671], [-239753879792387198, -59669161713500], [-411699969086090952, -33823158060534], [-36911054274179798, -30807972031384], [490877312026538138, -28221887655730], [361150714502866344, -68201472006573], [155985726533960502, 4796596797760], [232146415571855596, -83380859597850], [148361061201328338, -105146869716318], [269657205057689618, 104253047634762], [-191749240092202860, -85684652563456], [-267543363217360052, -28228566578864], [536155257484537406, -21337148620602], [-477164532501616958, -12735649829353], [208396282027140894, -44219013353895], [209180304778832556, 29580213512168], [-510240686870357702, -95688093977096], [-62947413394099270, 99283964973224], [-146915610730330484, -129771507565308], [-156433751793728318, 78682387321192], [-106025544612311482, -162171812084832], [-534120220631228340, 19814410302152], [520950841914043778, -16369009986330], [-262262252358308296, -60958403452673], [-290048669610196070, 67691170639418], [357307551882135532, 179333627582460], [-674830563790991148, 72107358039618], [959332967965487470, 11383014867350], [-425633485789250246, 72781999969736], [-465458764779767256, -82865832732597], [368054581609254016, 89964166672162], [858435179386385592, 58077402785087], [439965366131393008, -2192283275684], [-237827376399099506, -109634595984904], [1503444556751085140, -41096135942498], [1034405891509343064, -75323242380162], [-748406545206000942, 186494251318720], [700305308640703986, -144535128190164], [58902875574124504, 91149170702157], [1134357486799650, -1461906128460], [-59034637154515366, 131586019824296], [-698001743457466460, -42174035261438], [483968251878293118, -21207744590295], [-1516988012480549928, 28283717911137], [1282293254848888418, 83697613003035], [-107438601072925590, 148666487284680], [523015002889234408, -125452787419695], [-477404472965524494, 200414387832354], [571862728409713800, 165516037618155], [-215603082364560836, 433130231436174], [-1464763459760492318, 105155729115542], [-704659401069208214, -271747597838204], [1082094499184808384, -130533592158703], [-15212652958785372, -228205993776102], [-982907999909882700, 81116974483226], [488792353387158194, -220872518675340], [655415267202294780, 382578287243532], [397831139783817878, 407684244395514], [171755153178737472, 115074246175116], [-911314291474458590, 98271064787021], [-2003576622795871200, 95491662623544], [1247818715208460458, -93181682268396], [-2150743370242769814, -105087929801928], [83745146732731852, 264043091522910], [-1801835997019604720, 77016017439202], [266915235309361578, -572860990615436], [-37309119048172416, -51671444210343], [577254665666079768, 99639705436740], [559894447099905754, 396432990040298], [259395434683894626, 503046470878848], [-1891269341049347876, 231461829614748], [-378902390010301678, -420872319620346], [1446507606209309314, 184148744268916], [-439725187642089780, -428818752444196], [2473083452642131230, -196538741948229], [-965287328825728926, -212727638056904], [1086930404626389220, -387061773593100], [-2265062923701248268, -142948997752870], [-2261497633000275576, 394646324325714], [-456842864726546078, -568908458525528], [-2303069639723235098, -139659609745510], [-310768607058414566, 373283405704000], [4658355327856360, 381664351797885], [835958777372626804, -334653704680514], [-199102248161788820, 2493644515926], [-1145340809616474356, 403102603558024], [-1823697948572040826, 606389324855712], [2018345585275011302, 575445417950717], [-682496159822176870, 480364194195684], [-2942432735676238204, 471146556688000], [-97296570757332030, 800252730159421], [-3340838570754117298, 66774362317019], [1773397574856186522, 92547181015776], [1202183521442130968, 442600106178355], [-609481231164175478, 169520932613002], [495227069286940320, -390494900351865], [1629529820019704510, -556463859301326], [3097661812719791892, 172675794438728], [-3822224760263853096, 4864124347368], [83316331808972498, -291408336811378], [-1873094021382201964, -706201989592676], [560619725214686218, -773910479080168], [1895478122951377346, 478712746938332], [1148356257421075044, 419141703765176], [-3542835881633427002, 118147059277934], [-1113197004908996418, -987263919257283], [-3067012486388935088, -619183041669584], [3155096260518153192, 94067476069977], [-3046479730701582642, -247112626136043], [1359383066639580488, -74547270338512], [3228099535915626834, -219546606013715], [1852972087501735258, -987790292730572], [2963525358361279992, 255386695005258], [-3349282661895822232, -458948587775701], [-7529589124303559420, -179939503955178], [-493133739152314086, 663504813589228], [3475043002414372314, -236542533133770], [-4801971607563672052, 160972405145278], [1553646780739488074, 1153028947669716], [-6213723640270397568, -42024199197453], [6616956085947588572, -15885083578964], [1439703971662366136, 1037988062533922], [-2152504735325658822, -642962141771856], [5383948716057227672, 18993691902757], [6093232851906632562, 668567518088029], [-1051710115606531648, 1217128808304851], [4279678441234459680, -492199506568824], [-592182162248595694, -172094754792636], [3276554091454643274, -502043860210968], [2142756469125896010, -445071611313032], [2866717868524567562, 1376878915416920], [-5778911817566722170, 653236607900721], [2133546426645306252, 30440683020038], [6731119882122765734, -700242887307055], [-6740037071548233676, 1129768082098312], [2781211371958728200, 443303741683304], [1561428082769324152, -934725128322213], [-341248275054493510, 1172085741347433], [3072570197816356580, -981325182562436], [-8536495683094698480, -453935057574978], [3935905003459525762, -1133122125426424], [9376886514801056962, -338684020550348], [2379187611999991064, -445222646763103], [3474230024301378388, -571977600961704], [1129016537437105160, 714845022294356], [11598538503587606618, -468396840943200], [-5089552642516526480, -1142958069169245], [7163121992094111642, 73649111505546], [-3100179926472263676, 1013218877119118], [-124296125427643662, 2321574155189328], [-663430059180883146, -766680044799248], [5174119291265575566, 571512610125789], [8746294404957755508, 452756571982196], [-9883498391932185898, 593755411004669], [657893486105240138, -1238040472843696], [5864278980323815584, -372273975714217], [5087791048554322034, 348387379318125], [-88202006246038726, -1485597468896404], [-5666419649343043468, -2280021664180760], [5589128957407158408, 727584518913849], [-7205762898875180894, 313027783874744], [-16084174208091985230, 409775613292188], [2490405233428497596, -1273720674087448], [-4223457966490237444, -597873497530586], [-2645687425823190190, 2178218989287738], [-9436338340846452302, 1029673539057328], [-9346091099934433568, 630436971389056], [528766903496700300, 1398816001277942], [-1389323342690365218, 2390419467287589], [-8014051118422400936, 297722784650746], [-1272610575609843766, -67215150508888], [3667630005400520178, 1259590470196357], [6606975489825059592, 468459776661858], [-8577835733909823952, -561957552894691], [-4631194899375248014, 873665524386594], [-1386158242798107830, -1198109457054302], [-7770045128008304924, -1085238365712428], [3034543029313342890, 377348140951860], [3085827162571090756, 2166446804102634], [-10875807940119295672, 347449377451274]];
    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_12_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_12_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, 12));
    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_12_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_12_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_240_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<7,R![-5768338800, 7784, 1]>],Snew);
    return Vf;
end function;