
// Make newform 17.12.a.a in Magma, downloaded from the LMFDB on 28 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_17_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_17_12_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_17_12_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
        poly := [-12354600960, 24205632, 19034528, -21100, -8440, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-1377136394880, -3188346096, 1314400972, 4129848, -211643, -223], [-663710838720, -11713342032, 636174244, 5321856, -106061, -241], [-1857468055680, -41170505328, 1352281196, 39209424, -116599, -5939], [45942107520, 1877653968, -41978116, -1602504, 4409, 229]];
    Rf_basisdens := [1, 1, 437669760, 218834880, 437669760, 8257920];
    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_17_a();"
function MakeCharacter_17_a()
    N := 17;
    order := 1;
    char_gens := [3];
    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_17_a_Hecke(Kf)
    return MakeCharacter_17_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 := [[-2, 1, 0, 0, 0, 0], [-79, 0, 1, 0, 0, 0], [-2129, -40, -11, -1, -9, -2], [-3670, -480, -46, -3, -7, 30], [-158999, -2968, 605, -394, 490, -140], [-74971, 4496, 209, 463, -357, -1564], [1419857, 0, 0, 0, 0, 0], [-4469434, 126080, -7522, -404, 11420, -596], [-16465644, -121160, 100, -9397, 4451, 21462], [27110697, 863256, -105577, -4611, 85021, -19798], [-33134498, -80904, -93986, -125485, -173909, 87446], [-130512327, -466072, 549983, -417991, -295423, 225818], [26569792, 2990224, 102914, 639786, 493658, 723456], [-185404386, 1273432, -222526, 694056, -386052, 313348], [-972919876, 4060648, 143844, 815776, -244788, 232900], [-1645411100, -1302112, 1060058, 1537322, -1822382, 2343088], [53178402, -44489400, -88450, -4158300, 1882000, -3117700], [-2637316551, -18326840, -2480597, -4304343, -818847, -1200346], [2905967676, -72043296, 16253860, -635600, 8343008, 4242716], [1534027324, -136158928, 14368156, 10466237, -10895375, -13713130], [-2269488346, -23629696, 8768992, -96656, 6845264, 6341804], [-15172954252, 357998152, 15317204, -8166913, 1898879, -25424722], [-4360713310, 82137320, 31146126, 28791240, 11252500, 13434508], [9058719761, -468845784, -51199163, -9135241, 35275927, -66288772], [-17638597514, -59025952, 93479440, 59465436, 10593436, -10424388], [10080864749, 334085392, 14126737, 16188583, 90278995, 98649652], [-1053928020, 1166942112, 44928692, -25435508, -78328692, -42330232], [18429171431, -374557232, -71457609, 35476726, -169448458, -19411428], [-2806406797, 2447571960, -225275779, 46891587, -74365893, -35782934], [50258991924, 1061179632, 77729322, -119657814, 60806986, 130173508], [-204265791772, -3087968976, -534873236, -289683522, -257523922, -3877868], [20275010015, -6884533152, 170926247, -67487206, 345789186, -67532532], [59871510593, 12497013384, -106171135, 77229767, -106942825, -166218496], [-104731271693, -402713912, -10760089, 798698470, 513882026, 550022428], [246676783362, 4217812320, 1366198964, -348583860, -693368724, 375804328], [-145895314208, 1897366064, 269520528, -113354346, 818726, 469498532], [285593563254, -10126150192, 372013164, 833466872, 746165776, 240158460], [-68756681373, -10788255800, 243920679, 98847144, 967754916, -524970720], [-559295063662, 18555195024, -673424438, -954994429, -1421019409, 742637418], [226205063905, -2962316456, 376911571, -127810011, -434164379, 98614326], [892171155914, 9216663936, 1171947618, 2172948572, 950047948, -1784216100], [-1885819457203, 21437752872, -665173873, -1555733055, -665516503, 1963142334], [-917940114340, -24407058008, -907418068, -1260960344, -529700844, -3927762532], [-2883687744476, -11824380784, 3651998558, 2565453402, -262814646, 1149887920], [-385140654373, 6602309064, -6552739119, 2969639807, -2200873025, 775765350], [-1910507784020, -53964682952, -7709873924, 1401613945, 3255054489, 394870698], [-4418115552611, 14416880256, -2185301195, 2483373674, -693241662, 411594628], [-2159065286840, -37075309912, -4944886816, -2691299154, -14936272318, -527491848], [-4893478150653, 34975776696, 7288740159, -4336617876, 126062304, 3598566792], [1922551394541, -49627634416, -5062343395, 538660595, 6982055439, 543931392], [-880586986796, -79469578448, 6780643142, -4325791554, -1131392050, 3934109832], [-3340675774624, -133109301576, -519690968, 8105374736, -7850114476, -9470927028], [4383730246016, 100823632336, 9553757486, 14444831678, 7045929182, -2223663580], [-856577629176, -18966156320, 26636288736, 3350387384, 11306113928, 5734590148], [10498768480695, 123015732648, -19198312389, -4515620571, -5890999731, -3379275072], [-7955583403500, 125382757312, -21468976092, 8617683422, 8652608326, -23178465012], [14165874141887, 52637730296, -30717840287, -3794772045, -25311364693, -3429458174], [316857615812, -119143621128, 15424831780, -7775557188, -12322320784, 5188809772], [29418833117097, 76782895416, 10356052391, -6429296399, -25319104143, -5931507526], [17905501641082, 369530317984, 3623797412, -4048006632, -17526612664, -10847021412], [12605930835541, -350600512760, 42118905593, -8112624854, 19512637054, -3807121044], [8707006882930, 255936377440, -55154875444, -18216945108, -39379678324, -15643211664], [-27918176340404, -544596122488, -10570042960, 4402130736, -27688461172, -22207664916], [-15224012009038, 778008321984, -42798140742, 4547023991, 3769264955, 41138373610], [-29156275717368, -705439025776, -56999704578, -7570728502, 686629338, 10089824396], [6368227231131, 345102839144, -25590654351, 30717157171, 23978265363, 11644303270], [-49683163860318, -84016304824, -24277565210, 56054272532, 40809508992, 46118684836], [10432389357722, -361424211872, 118166328516, -50611123264, 19790299440, 49630337924], [-62518985524309, -435424957512, -86145389529, 21220689284, 21716496984, -37845503728], [80038989118068, -389060402592, 4862265458, -48607599086, -20337978310, -2051512736], [-551731809218, -50672526176, 126691419136, -82626690804, 624286572, 18529837268], [46310532719604, 414554455416, -96181682444, -72124203558, -27047424106, 7985440744], [-48283246174672, -126416155616, -1069798144, -60959818633, -10126758581, -63478888622], [-19450149648519, 896040552672, -66912687371, -6092423405, 62123510823, 179325577884], [3053358256709, 19900605024, -215285875771, -101940705612, -109983697420, -31957706688], [26867530676140, 391637145824, 157062969596, 22260528830, 175459026262, -119201259404], [67415901812461, -1032713556928, -253376005563, -179379249733, -73740268257, -95612748304], [-64114242033531, -1768873825944, 93440110995, -61049640155, 101180160445, -178405760494], [-35564290886872, -2319422605488, -32029141042, 12032272790, -147029685546, -126098686692], [-11748685954006, 2706539263008, 386116463616, -12351557952, 126035071536, -2881733808], [24991853433227, 1366720777232, -71503732333, -1699687668, -308771304556, 241119957984], [-186945104759935, 2159928202880, -302249986147, -91503769709, -240339599145, 44450171132], [87747872911372, -2224525331432, 83645763612, 137414390271, 229981439191, 401760867670], [-107633122364933, 2587489211400, -81865667453, 121875469625, 35337146433, -158216876], [59328622675056, 3523718996304, 73824531392, 30718857313, -295080100619, -22367397138], [30363809573832, 1703269725760, 244373004232, -291767339860, 116529200828, -161870539740], [291782467594338, 3370935771232, -85734462168, -168343025848, 180787798584, 144447350360], [-58425128280941, -43130395544, -401709685061, -51517600079, 383302609129, -9657523796], [77563587188564, 2160771074592, -627040138006, -91353880486, 19665961794, 131759245800], [-58993083070716, -3421798269712, 302668282748, -13454154904, 441942707920, -423752754848], [247126343454302, -6529360352320, -144717693762, -21702863112, -463431766504, 170463505580], [97189253044180, 7892129879304, 443694683988, -113590457495, 141946659041, -125425003062], [-241162323261800, -6814639026592, 294095604120, 23315239215, 600016702787, 603411083018], [-26676130407794, 6869510831280, -612457729890, 279576562924, -496747891388, -478334509036], [145234167384221, 2492586409984, -1305026989163, 390561379574, -589849388450, 132680420780], [-84997353915448, 1694563565760, 251833618248, -282245373757, -394705623977, -313863367422], [-53410845918074, 5265590949152, -251040943768, 38958708224, -739629874768, -375005197528], [-460599920983452, -1218982988592, 248122201926, -375567594258, 626143424366, -332428879864], [-102266991195920, -9888468680512, 960655605424, 650012801184, 246880126752, 171984926828], [-21785490187559, 8563719516840, 1221296577779, 344633231117, 1503591516421, -580181129594], [-627946381169613, 9954109460544, 1239380396683, -670549422038, -1020145728670, 1107868030268], [-492668662922807, -5992020551968, 346089840573, 722899412867, 374852045271, 82042066748], [-451223501557838, 5158391261304, -557434047826, -420632350688, 2011356792452, -55088043548], [254765189760810, -21096139080000, 920100069508, -727363641096, -505281199464, 307892394044], [414729319160643, -5156759615024, -807242522341, -108831210924, 295766915868, -39696772808], [-373622211318351, 16174763339032, 1720531039217, 40507008159, 1267675805511, -797401483808], [571236285020226, 2722497346064, 2710154269482, 883198503220, 1787158688252, -558801354324], [-341163625130082, -31674254433792, 626763908984, 970383700812, -50817696452, -555374417764], [306432671226288, -33637608643632, 1085325385912, -316246712292, -146765292028, -1018450101200], [-1074064127624934, 19643642546240, 532133631424, -787423126492, -1833172402188, 472552715560], [393857121488114, 14385301859768, 521259705506, -2228224872197, -887017462189, -140187650906], [819352789178270, -33424878773536, 1949732550880, 289129000960, 457463289616, -1735233872432], [-536390896890712, 19558689002576, 1256358407210, 725415152706, 2091758868786, 544554617296], [1504968644402387, 23358594211592, -2125437465225, -982056286988, 92440055904, -1742046475088], [-147523039696348, 10772064401768, 1389941967076, 270314544154, 716335888798, 33903766720], [14755238520562, 14053953567840, -6154298269508, 125893665400, -3235006583672, 318072089092], [83443178515269, 26755794814768, -1556979290083, 375412707180, -1040572329820, 320098703448], [-443148255814364, -19035033358392, -1956387980532, -1965485481380, -3765614638616, -1248784374028], [1552417282428061, -14669145805096, 2628339509775, -1277605825795, -784178178915, 602821021814], [1054234215731980, -8886109925640, -2241593167720, 1867220300476, 3003722638000, 602940338484], [-693477121081352, -4918482095792, 1787392380626, 241946180830, -3756823288322, -816847865556], [-823388903084194, -10683382887712, -5403555882628, -85647189548, 1946890627604, 1984146316024], [193810735081787, 37144136666888, -1264896851331, 466660662555, -1435364648725, -2871876529006], [-719416278958783, -15238769739824, 2125421551049, -822643828436, -4385126472492, 1592889964784], [197010052297877, 25581326292200, 99028167017, 128750395846, 2710395306618, -1638051246772], [-955166333992591, -15777084385936, 5209894156269, 2303621308011, 1505498846423, -2399906481172], [-1189236396532459, 13806084154648, 3329882135815, 628584612149, -1195835490155, -4002158141986], [-2888055861742552, -22459193438832, -3495910994648, -3476673521383, -2783142460691, 1129086061190], [-1186863629833580, 70659587238472, 2939563995028, 1418846120992, 1018512460572, -2657509154172], [395559156062884, -18289618524656, 3793523598582, -3738452436758, 531018058618, 882729733652], [-2899191025764678, -48671184521536, -3267109375302, -1759236366988, -3517385606876, 1345245533556], [-688271692402990, -84738985345768, 5252897113346, 2568297172935, 7361512213503, 5827708565446], [-954596941383340, 33881824149120, -978222387948, 1371381965025, 2582915071197, -4661073183378], [569241775230085, -79079808624096, -2804934149547, 2315132853275, -297819322801, -3490782642440], [5559377151702549, 8500072541576, 3440660583661, -3986756089733, -295693467589, 3468104403008], [-347667971882447, -87707769477944, 4103352273665, 481844552239, 5436066549119, -1864983290024], [3865493528564093, -3722488641840, -7780589386131, 4854692779187, -2194340318737, -537131388608], [53280013659915, -27367150977960, -5016485230825, 5043503617030, 736175726530, -6407182238748], [-238329611543676, -57679684820304, 988986900118, -1037074849062, -5023967137062, 8220240566756], [-7416097597218694, 28230001138144, -3989453695260, -3765072032156, -3085310306236, 3875227783860], [-6041314349655, 7200077849272, -10250773924651, 8051589152904, 9129504463884, 6423311022352], [5689915706666279, -12069322372760, 16548364545225, -2310199827689, -3467447994297, 6481890128170], [-10180692457619780, 62331824051240, 6772982025308, -2654559954369, 3918875207823, -7798262306330], [-5323720141382703, -94509555227568, -6407873271231, -218908037370, -10812852913722, -299928631836], [-3862950657116578, -48213173927696, -5549669357532, -2201154657712, -50615486344, -2070294288980], [-4271540294455958, 61042671083280, -20221345012878, 3335734444033, -1749749282891, -4689478381378], [9346238670895039, -113795689078120, 5851455455109, -3396514243569, -1240244934169, 566945226830], [413581400509496, -103258329697584, 20419310021862, 5192431019162, 15993208607498, 1816909567828], [1941781963875822, 175791254424904, -910242360910, -2952446091000, -3081636686172, 6815476274524], [8196945585396532, -33116413381696, -15669368463716, 6252792572384, 5848987805376, 13874586967912], [6170875807024647, -121091240134920, -42521024775, -2759352271385, -6117625779185, -4853888695030], [8694823985395114, -2569351827328, 8859355743012, -9338762567104, -9047575592032, -12421364705852], [-2155080162394176, -171221755668832, -32984426743264, -13989739351420, -17545288469436, 4677396787548], [662624377923288, 81611079776296, -5985824948808, -10985710043935, -13788867536215, -13660255636334], [-4283409466993399, -60053789894312, -20036021877339, -5758068333154, 12324209043194, 12631770390436], [-8829114155510634, 163327717796512, -26485410946194, 15358427798069, 2486070046801, -395954486346], [-1000851712868264, -232016044977528, 3577205588384, 15221305668368, 2800772039020, -2017324338356], [-7077025195961144, 53779041886064, -10208405192634, -2637935997298, 24443197195038, -1072714951564], [9189564219639774, -257090394961216, -8346986233092, 14725344412124, -17042298223412, 3981054196128], [3136750549842971, 172285933939784, 5691316469277, -505151172357, 14181308401643, -22185969370918], [-8136914726036173, 344794058625400, 5448492943935, -16307275008458, 1424730170402, 4263772105716], [-8039828105971015, 237519594343672, 13218589809901, 10243715312671, 24820617824887, 2243119944580], [-11235822215967544, 197048819112888, -13178802685984, 20591312165670, 9249820423506, -7033817734136], [19882981055788978, 144247801324088, 25225313629182, -2133746145088, 6125513849604, 18663050996204], [-5456746990540782, -36503564658816, 1596230160244, -19022642417424, -11124931052848, 21568155583324], [-16224885123628948, -48135058137520, 6271098887548, 18965404019565, 9807726959569, 28953475024710], [-5946781230725552, 137802321578736, 533453570432, -25812554395399, -3152005962467, 19438975772758], [-11782087523328397, -78598654014776, -41600334104751, 5934391094639, -21752658019281, -2810957633410]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_17_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_17_12_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_17_12_a_a(:prec:=6)
    chi := MakeCharacter_17_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(997) - 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_17_12_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_17_12_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_17_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![-12230355456, 99820416, 18705368, -88580, -8410, 9, 1]>],Snew);
    return Vf;
end function;