
// Make newform 147.8.a.g in Magma, downloaded from the LMFDB on 16 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_147_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_147_8_a_g();".
// 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_147_8_a_g();".
// 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 := [1890, -1110, -299, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [882, 764, 17, -3], [9728, 2728, -65, -1], [9906, -262, -82, 2]];
    Rf_basisdens := [1, 106, 106, 53];
    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_147_a();"
function MakeCharacter_147_a()
    N := 147;
    order := 1;
    char_gens := [50, 52];
    v := [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_147_a_Hecke(Kf)
    return MakeCharacter_147_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 := 8;
    raw_aps := [[-4, -1, 0, 0], [27, 0, 0, 0], [127, 5, 1, 1], [0, 0, 0, 0], [-511, -109, 15, 7], [4552, 44, -20, 28], [-4865, 209, 85, 13], [7610, -902, -22, 146], [24907, -1643, -111, -47], [49168, 2170, 330, -110], [16222, -13750, 202, 34], [35964, 15414, 198, -34], [93537, 9711, 603, -2349], [113724, 6096, 720, 1840], [-403024, -34904, 1400, 392], [-358304, 16990, 2046, -6298], [806108, -58088, -2200, -10120], [172826, 81490, -2854, 6602], [858226, -69894, -9918, -846], [-21223, -77281, 8595, -5037], [2763874, 70286, -3770, -17258], [1217474, 206982, -8370, -11826], [2056796, 114088, 13400, -9784], [-2752727, 235343, -26069, -33773], [1646702, 19930, 5570, -40270], [4151801, -525653, -18817, -27889], [2964850, 572102, 36070, 21934], [-11132371, -745153, 16731, -93], [4015566, -103284, 53100, 6492], [8566282, 16456, -6792, 62696], [-9665318, 998550, -52578, -88866], [16543248, -446028, 1860, 52260], [3758710, 43984, -30096, 133008], [-10325368, 2019604, -129484, 13892], [-21725728, 763358, -40770, 106086], [808488, -1987968, -59040, -107776], [-19140102, -1772262, -152190, 72306], [39964462, 552150, 106542, -57186], [-36505020, 2326404, 81060, 34548], [49636305, 5717259, 25695, -133137], [-68771329, 3427301, -10455, -32623], [-50429768, 4361708, 146380, 143260], [-4030907, 3822139, -18225, 605343], [14953752, 1074186, 251658, 194466], [12973316, 5145770, 645306, -58238], [3569736, 256992, -353472, -330144], [-49189536, -6138708, 117180, 774364], [18271812, -5138292, -368340, -313764], [154075120, -1326988, 141460, 124324], [100192788, -1368576, 566352, 571104], [-180730942, -2430844, 5844, 608948], [-8460829, 6400661, -597135, -668783], [117144858, -8215122, 3846, -719178], [-76941164, 3926312, 681928, -1032824], [-22402643, -19771477, 428215, -473729], [-101175185, -11383415, -971835, 834965], [313260227, -7304999, -307387, -239419], [48922382, -11837294, 223058, 632906], [-91248796, -14206374, 484650, -414990], [293870318, -6968440, -1099080, -286680], [368517230, 4652230, 449270, -133330], [-22820987, -21607345, -557885, 167875], [-13133338, -11364578, -352690, 1879334], [107097504, 1526880, -174576, -3114912], [397646600, 6823888, -380560, 515216], [-530901548, -9754622, -300990, -130310], [-73010952, 29552580, 1637460, -1247340], [482504382, 8951280, -2725488, 2535344], [534925739, 36641561, 860445, -1210155], [-543416998, -34905494, 1302098, 1073666], [7660867, 29888021, -2970455, 1030657], [201131293, -4333709, 287175, 1758647], [401527392, 2774640, -2272080, 4513200], [164353990, 37287576, -3742344, 1229112], [95025600, -26453652, 92700, -843044], [473096204, -44982932, 3559580, -674884], [-248669992, 28090106, -1970070, -7563118], [590824130, -60944366, -136390, -1872502], [-63201194, -20012936, 1739640, -222952], [-158270110, -24069914, 2188766, 3258062], [-411439600, -22117892, -7112692, 469196], [281180548, -14421366, -992070, -10102302], [1018478869, -33001949, 442455, -5106713], [994226796, 28082412, -1085220, 5816124], [-399347260, -33430724, 189596, 2235212], [987428375, -98096923, -2227623, -6976591], [-475260866, 63463012, -3020940, 2882964], [-1365891894, 79364112, 7834608, 823376], [39884009, 11009923, 4860167, -8984281], [541841918, -21036294, -245646, 12866418], [-239533916, 140227904, 1626880, -272192], [1267935764, 68616628, -2880508, 604004], [-249348276, -49245924, 4171500, 4556780], [-1166237789, 25391065, 906765, 11760565], [1189439352, -13788540, -11751660, 12769620], [-73592584, 16313752, 5961800, -6792136], [-777500321, 105010013, 4095337, -2076071], [-1077368353, 65742769, 2777141, -16836883], [-2054620156, 98323504, -10703920, -6080272], [-396660076, -31082814, -4698990, -92358], [-1106172766, -189828990, 11714634, -13908582], [-137028856, -185853634, -5232450, -11642810], [529561860, -142470168, -3317160, -4778616], [526196414, 62476856, 5117640, -1400168], [-303605042, -117335394, -1027530, -6543738], [-1316102204, -4799188, 13218460, 17987644], [2373574776, 311197044, -11145900, 11098788], [-1503391445, -292617427, -14651855, -6226919], [150358381, -74086277, 8419455, -17097729], [-775391804, -1235524, -2279348, -23827316], [-4620251876, 21370052, 7471300, -11219276], [-2798919182, 10597824, -21981888, -4643136], [-2522001118, 2761988, 3054180, -12343180], [-4198357360, 17396212, -11275948, 7749284], [2543218234, 21671622, 5151150, 12513294], [2065595018, 225189620, 5060340, -18786780], [-5511465238, -226734590, -1709230, -14725510], [-371573596, -86261756, 11387780, 51432308], [-2754667748, 144858334, -36669474, -2023578], [-1796247995, 355320199, 16572195, 7338123], [-5495146846, -30798710, -9788686, 4939298], [-48670920, 282412230, 32987430, 11973230], [-329556095, 83985611, -13617665, -40427153], [118592659, -94352375, -625491, 27442053], [-3610113372, -238450752, -41480064, -8301888], [1659862108, -28222706, 677070, 727638], [2657245734, -486114420, -12477780, -37515940], [-5309465972, -330919684, 3719884, 22738828], [-437886630, -220646178, -39950370, 8270694], [5848729336, 228815060, 24548500, 35325220], [-4972825978, -267955938, 7321590, -14163066], [-2575482743, -615874793, 14218299, 14535243], [5228066520, 38748936, -19648440, -10290008], [5860781118, 648407556, -3242556, -11673612], [2121063001, 134019719, -23286845, 6688555], [4455656820, -949191660, -4036860, -15954300], [2049715905, 389522883, -9093225, -20861049], [-1577531872, -724339004, 1751300, -62007628], [5672721469, 283633391, 1749235, -95215613], [4512361274, -263748832, 48746160, 94010976], [-817296908, 306271568, 58821520, 29055760], [-20426034256, -41860594, -18010290, -36826538], [-11757242434, 377919090, -4144374, -30415158], [-12189376787, 242069983, -37159989, -23917213], [6687995040, 438218748, 60439068, 45540396], [-10016543656, -398365952, 17182592, -45571456], [9498276706, -746751166, 25400650, -25442822], [-422013519, -775337121, 22982715, -15085917], [-12348387582, -1084551798, -25406790, 68979810], [-9672411929, -997163543, 7187493, 110726261], [1440948362, -528685200, -44917488, -92348496], [17989224223, -227215159, -75889571, 44102533], [-3600736200, 498210420, -16862940, 59685700], [6433904764, 986726876, -59326820, 83119852], [222535116, 865523064, -49203720, -59236040], [-8133560875, -770975533, -34562265, -77228521], [3711650076, -1060043820, 9080100, -3027260], [16920794241, -349954209, 38195307, 62575299], [12213303936, 2189995680, 23599680, -51523680], [6275837439, -113494059, -94861215, 65751345], [-12940550803, 794723903, 17140395, -7983805], [-9698049646, 1165359800, -36449736, -99597352], [13919907074, 1083019878, 102182382, -14113746], [-3547033488, 958229316, -1906812, -179230284], [8496997610, -55958908, 41793492, -84088396], [2916064604, -531043748, -26812420, -81729556], [-14368126644, 9653100, -94669380, -7884100], [-12231694830, -313682982, 112884450, 11342706], [5435576732, -745146666, -38299050, 26678718], [34332699069, -841201713, -64626525, -139131261], [5656612177, -1392575237, -70580505, -69444689], [14271306594, -603212766, -102245142, 88103706], [-4858733587, 1062263867, -6792225, -229820161], [-2504114956, 96151410, 117256914, -126199062], [-2454829584, -1212148776, -88817640, 21669240], [10883253743, -541133591, 111393917, 97176869], [17458453034, -1271847654, 33333570, 18935442], [13978925684, -3015614050, -82970370, -129884250], [-23476828882, 1038786370, -38913790, 137254970], [28454492546, 744576538, 56267234, 137933618], [2734557814, 742143978, -19457118, 305966754], [-21932237220, 2079228768, 70375008, 134384736], [1255269244, 1435256118, -29428218, -207788706], [37593599059, 586342373, 14104585, 34982641], [50170809463, 708351889, -116351523, 71382429], [-22429390027, 1099436695, 401963, 27498731], [-36244821150, 2488331316, -84743244, 1719652], [35076261812, -1160396480, 41348480, -9787840], [-112864532, 1361155482, 86169690, -49718286], [65060346368, -339126920, -20585752, 152206616], [55461873770, -2175805418, -95424850, -58035586], [-29163658615, -1112629357, -4282257, -10494329], [5987359260, -2560365504, -190193760, -103500768], [31013258485, 1655166215, 223048795, 95974555], [15091346153, -2719060405, 178871943, 2007071], [23727046867, -546205339, 88907785, -140926223], [-13254136920, -1223512890, 95942790, 403852270], [-40015542212, -177647922, -50072994, 7111062], [44935941345, -326797161, 86848035, -74037477], [-13435265040, -46393680, -64862880, 34011120], [-24467131480, 1163936318, -71341170, -383919034], [-21680684108, -1224032764, -48249692, -101464844], [18034536332, 1036468864, -235583440, -176083552], [-36987001242, 2242732362, -215510190, -264095070], [-421010004, -3009878232, -119311896, -22995192], [-12413367987, 1937995431, 185906235, -66841413], [-50127700820, 1857407852, 93898732, 422130364], [30600615257, 2505301907, -189220881, 387340423], [-49926177106, -1123557364, -18033780, -204760868], [33841888330, 606397538, 143939218, -303146534], [45328196054, 4553562168, -47670408, 79728984], [54138106963, -1501140703, -11213315, 162892045], [75013137324, -3852470916, -121658292, -78091764], [-26676650140, -395395856, 15192560, 167817008], [13934317300, 3397864364, 25547164, 229820668], [16684628704, -3024995896, -61922072, -167003864], [-24998439348, -1409372148, -161988516, 150827228], [-40291988525, 3404584445, -59684255, -145117655], [25836541763, -2049216235, 263141313, 155401201], [7959227032, 1938088498, 142763970, -116631190], [24228520326, 783998412, -130634100, 6956444], [-69246792590, 1239617774, 143859694, -154205642], [-44035410514, 1267448180, 172778340, 25498340], [85594006008, -1353343992, 95246856, -411013208], [-34256610172, 5453304880, -124323040, 90332720], [19960103412, 1464204942, 181404990, -263126826], [64019790789, -370870413, 283439535, -49184121], [-28446175289, 2149951201, 100362525, 592883917], [-67428815514, -1192498518, 315830730, -239913726], [-47514438389, 940490281, 258420045, -340137883], [-35291897874, 883833228, -49554036, -509306532], [-39803341698, 2137655358, 24098670, 607479750], [-50022611316, -8529666516, -131383620, 68247228], [-15570195506, 8372846092, -258932580, 218229404], [-80106953298, -2515098090, -517732890, 124140990], [-37688734896, -4729538352, -700792080, -32679024], [-92740231554, -1254502470, 165549666, 196797522], [-6632556388, 7198286402, -291316686, 482928698], [-36293439265, -1808260915, -436643775, -440424135], [-90142330984, 1475735896, -31252408, 219630584], [33007520647, 2146230325, -379268823, 503731009], [36226580988, 3760527192, -380504040, 421799160], [33943046028, 6412218564, 474342180, 238541748], [17336201796, 382007298, 372066930, 3703546], [15771101417, 8425438447, -9424405, -28739341], [-100065672936, 9811871568, -345343248, -1981296], [-5640369970, -6012353198, 267274130, 419417354], [-42754002008, -2947360084, -32066132, -295909124], [33915012070, -8155381338, -296709570, -729056466], [-3204303365, -473407067, -346263807, -1080961439], [-31031832006, -7359513636, -589720932, 369479276], [319034303, -126301415, 170157293, -444328939], [-142568014099, -1930890613, -458296737, -233486929], [136084533506, 1946690158, 573475814, -20595082], [45369603925, -3165455665, -171754445, -417583325], [11544708337, -5124772397, -329785185, 231850471], [-14254905364, -1470603690, 6301350, 1211474430], [105500480578, -3510973846, 17578330, 330589378], [51239751841, -9610544317, 132518215, -296389529], [13059345416, 6019103536, -461510320, -356807248], [202426884802, -663692562, -175526730, -574854570], [-66730006769, -6420193235, 267036561, -503841543], [-19211707028, -3268886032, 133090720, 895119760], [33736045866, 2670593682, -454176390, -479238006], [44431281159, 2613275769, -708126195, -170214987], [-198686095896, 4122761700, 103063524, 630476628], [149860475428, 4945602850, 592721490, 310368410], [132892762563, 12889783557, 15361785, -298433295], [40001911330, -1944413550, -573253830, 741911850], [111208474412, 1765196294, 398782086, 793373422], [819613462, -801953746, -538143674, -619392458], [-88543298268, -4181069760, -220138848, 738065824], [-27525571982, -9402539890, 223091110, -1306213610], [178033105836, 2624799828, -673197660, 429989956], [112144509038, 2861983234, -500873110, 1267908218], [104206204930, -4539668434, 878770030, 559866742], [-1613734175, 272815267, 1295661807, 158642679], [232432508772, -3782855310, -515319390, -320039510], [51751048968, 7115172882, -800648910, -463728886], [181922410760, -7817853908, 305835692, 629739644], [21185232028, -12176341228, 621207700, -395430716], [-150498822910, -13148187570, 575712630, 17361270], [-7729579548, 4251936564, 528678900, 312933348], [-189713797646, -2569634998, 537962386, -494517278], [-54042599460, -9327985944, 866832360, -625347768], [239274869261, 7846910507, 395935935, -187674161], [-281207901078, 5132115144, -345504024, -189008088], [66280665760, -4008567650, -539472690, -318593370], [33221467886, -1469028854, -149658358, 1840596194], [-111041048199, 11414474319, -286408245, -529541805], [220519799960, -3911523634, -491790690, 14255382], [-12883435992, 8770161708, 683018460, -322790724], [290536725458, -8886861724, -685258236, -3311532], [3866544716, -12919673432, 564611864, 1029773768], [-112506685930, -2694238416, -32846256, -2393837712], [134778613965, 10189550847, -1199354493, 973567059], [399870734200, 10628214920, 54592360, -597431960], [-69252496365, 3234612585, 449867445, 2903058645], [72436147136, 2732603116, -1075590388, 1016851004], [-200684500856, -23842063372, -757764620, 866214436], [359892782132, -14018466332, -979019500, -656599084], [199078211788, 5856381358, 19638366, -2071356938], [-167953524266, 24027523938, 553075290, 1736002746], [-7685195011, 27405343679, -391494357, 410666691], [-304419286714, 2357355222, -374615730, -55338786], [-208361288034, 19549105152, -618240672, -233294464], [-147740638201, 5514920189, 723703713, 598676041], [90679745516, -8357191328, -1105899952, 671482496], [231675325501, -4002274445, 91992615, -1215199625], [231960429324, -13530058686, 1054733778, 414292026], [259202257084, -18057101548, -244845260, -1873104956], [320739248872, 9469482586, -709339590, -886705038], [35178202702, -29683267280, 141066240, -1433431760], [106773527016, 12501416028, -68315796, 1688198668], [26870627843, -12232413115, 1310045553, -689291679], [-109235205414, 6589747350, 233902926, 1002917502], [65901590128, 11378907932, 1850844700, -697093460], [-244930802437, -21819634555, 1301906625, -1421185535], [-277393933158, 4421900886, -1432074930, -1310699778], [145208530066, 12702017020, -404302980, 123534220], [249227741934, 21623029902, -526815234, 486541782], [-232635620664, -28701404946, -897193170, 261397110], [-31678777455, 20751261603, -424846617, -442670649], [-86443520292, 4538871612, 1141875180, 2478169740], [-104589527266, -2278835524, 860122380, -1180404340], [-195277620514, 3773568490, 2282125586, -218309758], [-121082393518, -23379949278, 649216170, 517217274], [246027055178, -23484667094, -915297190, -2362834558], [75920369441, -12376295209, -1946936853, -72619221], [-29265388648, -27352327462, -60933030, 313769330], [122848096050, 10941448980, 701621460, 3010382020], [-6861981188, -38398010162, 585764910, 512603670], [572627131382, 10793716354, -215888254, -1860898438], [289273914264, -25202394156, -1131586620, -2006526012], [44728515794, 8076577554, 608984730, 1417126698], [326570116880, 14812877476, 1582221620, 1279795412], [-305995353406, -3231935064, -1392468120, 468607752], [254695414905, 11672733231, -2281630005, 1713498867], [-182254184610, 14163962082, -244103478, 2115862554], [326774750006, -21141278558, -454548670, 463304474], [70720478198, 7227799848, 643938696, -3349863288], [694877995798, -17758702880, 276396528, -79591264], [231766876947, 17380626441, 548783733, -2237925579], [722497491324, -2259183612, 919900980, 497443316], [-102168015124, -13389027490, 2048635566, -384082458], [47704358369, -29120821765, -1747212585, 904342415], [782240987612, 17852577976, -574022392, 139640696], [-195948274932, -445679856, 1037755152, 2758976304], [505245804568, 21390476696, -2188769096, 2671636408], [-167682037723, 22199106655, -317325085, 798128435], [-324487277662, -6395652182, -616355014, -3377370238], [-243675681892, 24038061822, -2888747010, -1203758010], [470684474176, 36016442086, 613493430, -1089161138], [-254426014724, -15818035588, -1535962820, -803239796], [384015121582, -21409081776, -848265840, -2891511792], [-457272356985, -15636347631, -1174171995, 385823853], [64190076092, 41227674988, 2275322300, 706574780], [274307216392, 11479535132, -2107653956, 2898619948], [-577489110446, -3664020704, -373391280, 128160480], [-148291572035, -26898413597, -2163031737, 2304462791], [190239156190, 7074147312, -1018983888, -1706444496], [51689416325, 25153937683, -1016185297, -1249246489], [-537358772515, 11495344331, 1253501151, 2919600367], [92987153389, -21039083153, -1046041365, 2055372499], [-202467253676, 644883680, 2367123520, 630066400], [-188274088008, 1941959502, -1214258706, 1437903318], [-518920884485, 32411050097, 1070019325, -1051115651], [409702780402, -5856435018, -2726151426, 1167703038], [-471969009864, 25263865458, -1038068910, 2224830186], [-315647732113, 31916838581, -2285897655, -48634943], [146085106814, -16370321954, -3990014290, -1786481050], [-69965622635, 15233779723, 834889983, 1207795951], [-141020544260, -23729429726, 378216210, -1083474022], [-484234258018, -12720212318, -2103535966, 2632691738], [-103265435788, -2008356318, -2603588526, -3124083942], [-835648900536, -21571925172, -267532068, 1605926364], [-770325336145, 22253923145, -507846555, -3280717035], [-143993561756, 14883729788, 3075447820, 3176339596], [-345601227821, -13045862419, -188833775, 5692015705], [-312466522806, 39652548894, -724235850, 158237478], [-10083976787, -13245794353, -2267786765, 843816355], [330548971754, 83528528, 1022922432, 958292304], [-23677965108, 28185281556, -2464689852, -392764], [131156611522, -28606613408, 1436597184, 3647937248], [-10359421844, -4649724592, -4320718736, -3174254192], [-400436860456, -20353279352, 708941240, -4283420824], [-198591163200, -89181403752, 1294893720, -1861011784], [-5082831880, 4454720884, 1526065940, 778431428], [1163134922402, 7269612498, 894129210, -661889430], [808358231660, 17137229164, -492038500, 1239429308], [1006996053716, 6764309802, -1957268790, 1071005634], [-638504825133, 14694670785, -614199315, -1031201715], [-582937163711, -9901006229, -307639305, -4583722593], [-603972132322, 22016315230, -1407959410, -2505924250], [488355669425, 6007100975, -719279805, 4639008355], [-413699807754, -24432889440, -579903264, 2412130592], [-343781792408, 49746198176, -1798553792, 1965334816], [-519991691113, 28967631961, 2810765933, -499671019], [76434305386, -13151848950, 2591730450, -557711550], [401796203752, 26384107162, 1263110250, 1275771314], [-589031594034, 22930935918, 3093692934, 3929450358], [-572430397126, -15348684184, -4107883080, -3025454840], [-573775851974, -27605479266, -648849690, -1499366970], [-306815994167, 10993939463, 785489395, -2656306229], [762126241183, 37798148141, -2559238391, -1717279607], [352105092232, -49795782256, 1110827536, 824390992], [-183788535068, 47862034722, 1837958994, -1949856102], [660415186558, -13002012332, -1071334380, 1304762116], [-89414009136, -37232429220, -2477575620, -1379132820], [157431054896, 7414551868, -5102762356, 2503458188], [-102228549828, 60368093124, 5231280180, -2099686092], [-413626306672, -16671524590, 287769378, -859200694], [-320003721049, 29865873341, 2609083617, 4773863689], [-187679115972, 9299569824, -903067200, -4855112832], [169104361388, -6966017766, -493321158, 2138690034], [-1471437463945, -5912897771, -201292591, 1947362513], [-182462263081, -45644835031, 3445739445, -1392076267], [-19018302814, -22664608682, -5057890570, -6443570434], [420965479935, -27157801599, -2410254315, 3814479837], [-60423675388, 677302156, -790877860, 5098325852], [1749505968844, -19659203522, -2741073810, 1025332166], [-637625104522, -67703600906, -2109817330, 2831957918], [-958160030447, -24963130817, -172492269, 4460128307], [721972155952, -35398460884, -4277435012, 4552433596], [-1702001282860, -44310606620, 966387860, 407245460], [1541896851753, -54280848213, 1358348175, -792818001], [-442829667401, -2006581643, 303159561, -9712622783], [-780929270302, 9356833748, 1445972100, 938659396], [-145623685508, 106274475104, 3952589536, 1210281952], [36507698508, 1373680860, 2941542588, 4065437676]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_147_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_147_8_a_g();".
// 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_147_8_a_g(:prec:=4)
    chi := MakeCharacter_147_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_147_8_a_g();".
// 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_147_8_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_147_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![3376, -4560, -362, 15, 1]>,<5,R![-2561414400, 35944560, -66636, -504, 1]>],Snew);
    return Vf;
end function;