
// Make newform 17.10.a.a in Magma, downloaded from the LMFDB on 25 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_10_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_10_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 := [-2711704, 488987, 5754, -1596, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [-509736, -209023, 6301, 207, -5], [3450824, -323145, -24845, 345, 21], [4604568, -123907, -13679, 115, 7]];
    Rf_basisdens := [1, 1, 8096, 16192, 16192];
    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 := 10;
    raw_aps := [[-7, 1, 0, 0, 0], [-48, 2, 0, 0, 1], [309, -26, 1, -6, -6], [-2625, -44, 13, 12, 13], [-13582, -138, -54, 48, -139], [-31799, -150, -37, 198, -546], [-83521, 0, 0, 0, 0], [-75406, 4968, 234, -1832, 858], [329681, -6084, 167, 4900, -2325], [721211, 24298, -8977, 2494, 5182], [-1493895, 87056, -10641, 11180, 34533], [-6287685, 22746, 15899, -5938, -12574], [-1421988, -387124, -17594, -65172, -41192], [-11492294, 231296, -64242, 13184, 123526], [-3131634, -723308, 2726, 102088, -22048], [-16615966, 152616, 258816, -164784, 55220], [-7188478, -1081736, -101866, 28696, 838738], [-15322337, -601494, 252183, 190702, -679618], [-61385498, 1506284, -104058, -346368, -351296], [-96618793, 3613408, 572997, -81388, -671613], [-58202062, -413264, -551952, 652200, -1040600], [-164909903, -468556, 671111, -1041436, 399047], [41276982, -6790888, 96290, 987152, 1443942], [66779497, 20899250, 460683, 806402, 1206630], [125658398, 33525784, 236504, -1535904, -5543956], [24199301, 14775330, 4475815, 1393006, -2280098], [-66886836, -43001504, 1510916, 1489128, 2424300], [340974358, -1360034, -6307782, 3941696, -609691], [251085329, -58933226, 1549269, 779930, 4791166], [-159350368, -4205076, 36422, -4867708, 11885784], [-687491286, 53372144, 8373982, -7641520, -12251230], [611041034, 94994686, -9294842, 13671832, 4587449], [1546046283, 61959310, 2778641, 519110, 17894582], [-496976190, -8186974, -2135166, -562040, 8141595], [774024966, -126524576, -4070880, 5570000, 4974928], [-1251526706, -174165448, -18318542, -7850624, -10822638], [-3687346724, 147555884, -869922, 21475564, -13503224], [-4147087460, 98577514, -4787016, -9272832, 27372153], [-7917370995, 80325644, -4862257, -22784084, -37734297], [3065728567, -255213654, 22089083, -1747650, -48077038], [-3033993902, -514587192, -4705734, -18916280, -10258262], [867879363, 97289482, 10719139, -41748474, -28044854], [-5471041950, -170194972, -26214934, -15851520, 119087844], [12398782512, -316671540, 16163778, 15678524, 56180836], [15772088041, 280275102, 13082937, -16257038, -39040730], [13446918935, -244735716, 43257929, -83827852, 22032625], [12222941122, 835847402, 22555126, 34960224, 93554871], [-36635950964, -73520076, -25526696, 27103704, 29762638], [-9360786504, 598676490, -61878828, -36902928, 192384693], [50599012997, -167231766, -4140005, -3914306, 74804270], [2743452888, -112636276, 177808438, 57453228, -76392008], [19098848994, 1609955996, -106336606, 61906672, -66642672], [19889682592, 676249892, 16935290, -147378244, 108773552], [-33438306934, 1349758372, 31287914, 160198944, -329767736], [-28559264679, 601072530, -51055785, -131740782, 195706890], [-3940809366, 481244200, 23860590, -37763312, 210292870], [24704473685, -1270108586, -324935, -84607918, -498782302], [-45478409586, -535342828, 261890782, -374398312, 82184864], [-64475340177, -769692374, 70118195, 43600278, 414524418], [-79930073472, 1423320884, 94278682, 201230508, -120790568], [-20810764922, -2397744754, -303166874, -122567248, -513192747], [-45671097750, 2998942568, -52127324, -74694264, -653953904], [4545985714, -1758518364, 216800614, -644438568, -689803928], [16977206277, -407163132, -638241121, 255781644, -125471909], [-9655639060, -4631562076, -553171466, 618835916, 881246140], [42873201053, -5042507842, 187807445, 578864746, -92942926], [1534106726, -616784552, -63843374, 135972792, -1082498346], [-58123828026, -3216134336, 471616660, -482895016, -680337452], [-23136856312, -2271020886, 797937628, -938825656, 1001123797], [-17035182218, 9247066816, -567045180, 818264632, -96943572], [32293584896, -3480894924, -956760870, 86967916, 460275992], [221267919880, -567020260, 228010372, -394554784, 365735006], [-140788249471, 445950272, -838170189, 683777964, -742896379], [-129813044847, -10268718310, 776773067, -1538512114, -1271292770], [73195391604, 2491334266, 70695796, -714188520, 702636193], [139199878694, -394774080, 628977354, 1722002640, -52307818], [190268946081, 287496722, 1106689303, -1406258530, -1772731202], [8183359463, -12891281358, -2136979649, 1715615670, 2153931866], [-4505720080, 3807398308, -643553582, -1013692532, -1166756872], [-438273970834, 14396574384, 1113349848, 273986112, -728643264], [631582494800, 9976051614, -1271971184, 953937936, -8958233], [-320802060023, 18649327530, 655161275, 1131747870, -1283555706], [-109289513051, -10041399860, -580194373, 10988084, 2533299687], [-866841436637, 992710238, 1080804757, 445831926, 1518361770], [443094932051, -11661058376, -1437554855, -538590820, 2627575731], [-49992425374, -4585525644, -1988094046, 1125115456, -3828840312], [-637066344782, -14649720440, -1911336860, -848675464, -2409294656], [-268480639853, 26321022030, -2112815507, 3787415782, 3833906314], [5304471422, -4445732720, 400396204, 3736530184, 1945470284], [-415822646588, 6815640408, 1161593892, 398062416, -981521920], [-617230370446, 21131053928, -194111654, 1035525880, 2284567386], [-275854995637, -43795988748, 2862568773, 1087519748, -5096075407], [255185748721, 37769898944, -31206677, -3173819972, -2722285323], [721343772426, -16520787768, -940827350, 3106596480, -4761080494], [47084407610, 5258594658, 4072802286, 1250250200, 1330476243], [-148465109987, -22337658288, 969299487, 9802804, 5539782481], [573030003634, -39306851832, -2814554572, 2807286920, 8608269728], [-159198282488, 36354985812, 3245834410, -3141426716, 3224334552], [735778743786, -9295087772, -404626206, 1511080936, 1747499600], [309790023891, -3675805622, 594786891, 39895158, 10149375122], [-1130559942974, 22120983686, -4056160194, 5791792296, 5912607157], [-479051765967, 36852166586, -4720013597, 1341996398, 12497145718], [306878912438, -28565886752, 3123423186, -10735049624, 169538418], [203906626548, 8758468388, -1566851982, -8625412148, -792911896], [863021130016, 13126754798, -6420714552, -2173806280, -4342797617], [11682257239, -74690191306, 7073881653, -3636366874, -7261819010], [900216166518, 23516212688, 736828590, -3022806016, -18961167598], [2297757015272, 3744228268, 4246065830, 2537266276, -7423206152], [-137905200740, 60914047784, -7304569100, 4101840128, -10213508104], [1221810944306, 148977536104, -3014746040, 974523720, 1137107556], [525066751865, -4538887608, -2775080097, -3491447036, -10627646151], [124648799418, -46131614552, -139344452, -2783744216, 25243540312], [-516305426180, -21757168476, -3100029606, 8468258900, -26573629808], [-307285873544, -27159302278, 8720041076, 5788824952, -6956313859], [-4353955949700, -116757745988, -4902337904, 999173224, -17887211702], [202237415730, 174964895168, 4522789804, -2373489368, -11922262628], [-895875296140, -132622153894, 4242970852, -861828720, 15102375745], [-2602349573766, -48706642116, 5587268386, -10586989944, -646234888], [3921521822427, 86312169866, 6763714567, -4063580458, 6074706910], [-4838988145650, -55211064068, 6974735842, -1929428920, -8142917376], [737104116652, -68351871844, -11081210558, 4064900180, 8825538972], [1367116312358, -15208620048, -15354643056, -5230047200, 496932216], [1215577802345, -7471425730, -14749071719, -16247531270, 8601815166], [-187059881676, 102407767682, 7356747452, 5694749304, -14193851259], [1461007076050, 160885405086, 8623197890, 8083451880, 12618123417], [-530651133655, 101366829722, 27506431291, -19171982234, -18038187018], [571625239631, -45879405006, 5650175763, 26467034126, 15797881446], [-3590820286469, -106349631256, -8479460871, 7597893644, -10392362157], [-2529068163094, 56437035708, -3633374662, 16207526192, -44675160512], [-1877553157172, 94160367148, -8140304918, 16984599348, -13128659332], [2347359805090, -45150263464, -22383127566, -2737586384, -18427356182], [2672021176573, -106813576392, -15109604589, -33025666084, 21200669677], [-2303713966825, 184051335624, 377806581, 24111376260, -35159380425], [-5250028842583, -121388329038, 17839834343, 6894513198, 9199086238], [-946926322425, 140285483446, 3294529821, 20068063326, 43032887278], [5423898224907, -278706225202, 13328609337, -34571012042, -27506109570], [-3598929171747, -56828146614, 12101484299, 17366161470, -41202892130], [1394817654410, -93726162830, 964521898, -19600804960, 49795774539], [3841343830212, 35073048668, -9325052574, 38422707364, 37469598044], [-4817175649154, -171351936992, -7410325968, 20301247784, 80031698528], [10539723677380, -280077958690, 9956862552, 518513552, 39179985547], [-237145443315, -236783701226, -28023683107, -6458808494, 1157781062], [-1971120351783, 134430667380, 6855004215, -36407803060, 39107760535], [7750892585898, 24481778586, 17972000478, 4013302416, -42758750385], [4364565139624, 93926061604, -20020109998, 11460827988, -22087007648], [2614681872135, -232560298836, -32942638067, 17435627844, 14513300441], [1541239170217, -209908175170, -34912071587, -51353329310, -33043805910], [-16575461474292, 39594787236, -1241455258, 34379434092, -78364620596], [11823074520934, -421084661392, 18329990586, -60398782288, -49175474774], [-7890699870432, -136681503728, 24114849664, -45098880720, -50112124056], [-9892257499651, 158138853198, 35575961329, -24632454270, -62307728482], [-3426240606446, 568486034984, 2882904536, -15628597296, -89552433836], [-3339568046386, 299326514292, 18853997326, 68871228400, 93541871036], [-5462662551037, 159764251420, -45429182971, -25131398220, -10611651203], [2862878623894, 389676820894, 7624973870, 45059256264, -92478978971], [-13878149054049, -45830732228, 484214613, -56420114972, -24787536647], [-9936718468806, -85613024156, 36625608114, 12455809080, 122049604556], [3721174439412, -280698566116, 33601714006, -106750034044, 83155435552], [3650396369734, 968715093392, -12481610544, 15182873824, -41178449480], [9995440626317, -532831442746, 41211295237, 47470054930, -16030337850], [-7697474779622, 1043682286882, 28278675210, 5570867072, -68985223453], [-12070065830959, -902130632718, -92320522709, 60383146570, 32471155102], [2378658656480, -253992980300, 29408134932, -127001264152, 978972778], [16091897184918, -1000197489232, 14443408882, 23298942704, 88984702522], [-7925150952188, -1260196365916, -30776495318, 2509152332, -25665110176], [-7265721289641, 162130987168, -36598780891, 67169312268, 101253588299], [-16016727909429, 665285465128, -11022016215, 35612277132, -6031361437], [566977266357, 495868293862, 147166716037, -17024260294, -35215358018]];
    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_10_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_10_a_a(:prec:=5)
    chi := MakeCharacter_17_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(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_10_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_10_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_17_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![457728, 344192, -24920, -1162, 33, 1]>],Snew);
    return Vf;
end function;