
// Make newform 17.10.a.b in Magma, downloaded from the LMFDB on 17 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_b();".
// 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_b();".
// 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 := [-675998208, -243559296, -10388768, 2252056, 8252, -2986, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [1595734267008, 249666517824, 9962276152, -962897524, -21966986, 479085, 8711], [1729601433216, 980540221248, -87332865896, -1085670148, 124232878, 292545, -41053], [7069845465216, 961758589248, -93593409896, -1085670148, 124232878, 292545, -41053], [113709524082048, 13251504106944, -1752000948088, -12878937644, 2465651834, 2902635, -843359], [-59384105783424, -8853358980672, 873469755944, 10192644772, -1224135742, -2816505, 419317]];
    Rf_basisdens := [1, 1, 3478080000, 6260544000, 6260544000, 31302720000, 10434240000];
    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 := [[0, -1, 0, 0, 0, 0, 0], [12, 2, 0, 0, -1, 0, 0], [198, -26, -1, -1, -2, 0, 0], [1358, -69, 3, -3, 14, 7, 6], [19292, 206, 2, 2, -59, -36, 28], [23312, 2444, 15, -71, -306, -22, 22], [83521, 0, 0, 0, 0, 0, 0], [110184, 8144, 100, 264, 46, 572, -572], [190922, 26063, -203, -141, 246, 1815, 702], [135550, 40114, 869, 1525, 10978, 1840, 904], [507130, 6735, -3979, 411, 6272, -2957, -5722], [2617230, -45102, 6105, 5441, -4266, -5648, -7352], [1492278, -165676, 14290, -4594, -804, -5456, 7756], [3136628, 42186, 11144, -16112, 26088, 1334, 15140], [8171072, -451462, 1104, 31664, 93354, -12878, -26028], [17409274, -446976, 21210, 74926, -132416, 27436, 4764], [4338396, -1749298, -12644, -21988, -277836, -9518, 36004], [-7146054, 586486, 65505, -60195, 41082, 58500, 11900], [43085328, 1297892, 26640, 3484, 610060, -70028, -2772], [93694086, -1768777, -112733, -19755, 594476, 91999, -102202], [43711854, 444796, 70496, 8708, -149704, -71740, -120844], [136620946, 2802391, -11463, 200759, 449114, -119953, -38250], [-215742436, -1909818, 129096, 177744, 965128, -401926, -259028], [-280993836, -5328572, 228211, 51165, -1024942, 452218, 169898], [289042294, -13616496, 129756, 524064, 834488, 960136, -23180], [-482811624, 6887884, -401249, -3335, -1447098, -847654, 253830], [526081032, 20563184, -122476, -248236, 1763376, 427624, 314720], [100810576, -10432480, -317262, 476294, 2226097, 1024002, 61636], [36987162, -15570734, 995099, -230969, 821858, -1118652, -280484], [320538042, 21729808, -753582, 819018, 6970356, 1164756, -23928], [1884936788, 32512130, -1600846, -1955090, 4659332, -355974, -768292], [988407224, -37095732, -722482, 318386, -9181727, -201474, 1344172], [-451187496, 60535420, -396349, 3746129, 11737602, -5101214, -184050], [1565592764, -21142234, 582514, -1083150, -6778201, 2412688, 452396], [-633352874, 53306736, 961996, 4961804, -5367664, 4897592, 3144384], [615261788, 33803058, 1952970, -2830602, -24344832, -4058622, 819372], [3384772914, 120082652, -2103736, -581268, 15777668, 6154540, 5203884], [8537941144, -74376916, -1433944, 2866420, -11911921, -9254730, -5936784], [-1169031430, 77029317, 6053533, 5492619, 18964758, -7524639, 3984762], [23144802, -162165346, -4251571, -8656655, -35927946, -8811940, -121876], [-3608541224, -264732872, -2341900, -12476152, 39072298, 15881148, 4825652], [-961469926, -258083874, -9165535, 8459557, -6700146, 3520916, -9135916], [347799488, 39530718, 7704616, 22355848, 25364646, -5267338, -12424076], [-280720090, -223329128, -14067694, -4664810, 31044708, 2927564, -9076588], [1341839054, 447320742, 16831, -8341065, 17437978, 10122392, 1772064], [6413983734, 204503933, 1417047, 10785625, 123285346, 2288437, 14025450], [10398919816, -326445692, 21799614, -23653438, -18895577, -18233814, 232188], [-9986709956, 527040264, -11017454, -10699066, -87049894, 35153096, -6473680], [13817536872, 779660364, 4745556, -30786336, 39134619, -24370218, 30303384], [-5944600236, 120393632, 6978811, -46285295, -225343306, 27967422, 21904034], [5006018534, 1144474308, -17964266, -23819998, 135401380, -20001144, -49700452], [18006928120, -652616678, -20398880, 26151720, -7753082, -60044470, -40140380], [-22176251102, 184554400, 14785686, 4846070, 164196500, -37150180, 3740016], [-27314940768, 856324388, -20419480, -67989076, 81247784, 10191788, 2386212], [-26652927156, 473627364, -25804703, 73112987, -39628690, 3158150, 8591122], [24746780252, -426311314, 60291970, -61071042, -72488096, -11785450, 32192100], [-54230943534, 1283918330, 19790315, 78564079, 71742894, -41057500, -31533100], [-23000302224, -646194542, 60287988, -6507372, -356130162, -71238726, -3893236], [-5643064642, -1413525390, 33337633, 11541561, -104874058, 89332624, 9528944], [17671858166, -666066264, -14055064, -61040396, 327671832, 80696312, 78855084], [54838355876, -575528046, -1866722, 42228582, -202132615, -76994648, -47184604], [-25107178946, -1386546536, 12765388, -78506524, -313189912, -153662272, -50190600], [11227773428, 432147134, -56557920, -188870304, 207716834, 24434830, -55884780], [45119776402, 320992685, -47486503, 140089727, -712959398, -34126071, -49426822], [114211705730, 1332444028, -43345470, 83272394, 158882036, -131116552, -11324248], [-31326341842, -1986110162, 102179435, 38624427, -12116042, 3889376, 106185224], [-12019248492, 4366454182, 62633964, -11871340, -35449828, 31391018, 62417836], [57105268630, 2777480128, 17029712, -155952828, 856093888, -113950432, 158158004], [-186045055168, 1340037872, 109699228, -96037992, 10139839, 76541546, 113902632], [36820245714, 4148409816, -19402638, 105695254, 104889080, -44832684, -251206164], [103130937118, 3403178376, 92361324, -69242856, 1279907656, 161876336, 181396508], [-125618340684, 2331002164, -144050698, -274867238, -221701170, -131985460, 148320632], [51327921810, -7042182375, -163978159, -83640753, -1023572, -230980567, 49803138], [333505472184, 5893826908, -18379237, -8789131, -574853482, 316357826, -9075058], [-55062273060, -3865995982, 142549084, -428935180, -507354921, 250647304, -23103720], [-34056581668, -10108067962, -73019118, -355081034, 40908792, 214446254, 67598588], [-28581535548, 2687299232, 173476067, 180835865, -2379693802, -21932770, -104524278], [-74825547866, -5283837470, -37466019, -109746827, 97357814, -127653672, -349157272], [-142551174038, -529352384, 200317998, 687826390, 267927268, 39118828, -168436680], [-102532402630, -4809719064, 206385664, -106609312, 236907320, 280884200, 724078864], [-267982659116, -9612346098, -20434812, 180291564, 528752937, -359541048, -37734304], [397678755880, -7954321572, -232074101, -178853115, 1054376910, -548271918, -217767138], [-144190682446, 6470651947, 31529721, -479857833, -1015010354, -115537549, 396427870], [129838208744, -10487216724, -426869755, 229862043, -2748470762, 13177670, 104272030], [326068300630, 23245717623, 102536367, -239630111, -723085340, 304541431, 75596486], [87095430736, -19312325088, -257723740, 932589992, -1186126632, 271839304, -320208604], [-203594533734, -2493303960, 186475336, -159335232, 1344122304, 390377736, -717739960], [227106024152, -2159969284, -279847995, -291458573, 451147598, -1139358618, -454887482], [329681195690, 2333717136, 429961210, -309905850, 2088968360, -353711924, 439225524], [234034435416, 3204084148, 127973560, -549274016, -142173592, -596015412, -665358688], [-657878360840, 3253159748, -436364472, -307743156, 788188022, 503402848, -483504460], [251249810886, 7139544169, -43597617, 1199789033, -2749997074, -232685599, -862236598], [839072614674, -11576723023, 286234545, 719726775, -1369731820, 881529697, 601323338], [-125489658792, -23095896648, -122263420, -1030691856, -1341348018, 90870276, -93648956], [-134338968232, -2334339564, 747236802, 1876370102, -2551299213, -62885606, 208931708], [-13780244174, -43144593695, -930709619, 723514179, -1883828776, 632723953, -1230964262], [-318391402490, -34511680064, -122681120, -934908600, 4639617504, 555917088, 1847761912], [764373185718, -26926005556, -444356282, 521018306, -4212366820, -466847248, -339086084], [-320749163632, -46676627880, -603340672, 533604820, -2959347988, -428787216, -561924316], [130319839842, 44714505806, -647885243, 618605929, 4754789102, 703564380, -1718297308], [540301023624, 31707308084, -1209163842, -1549996718, 4863325213, 1370521054, -11295156], [-585615887696, 32002358452, -1424248061, -1475762115, -1263066778, -1048004582, -794698994], [-1342318649004, -15778072210, -662052400, -944566272, 8670857968, 1403319554, -227418404], [-1129133151418, -20512981104, -492625976, -969614524, -2594720992, -1906889344, -1233288052], [-380376204084, 19566001946, 1677044764, -833019244, -5772538443, 1062187684, 2553369360], [-344984597184, 15736745900, 1049919891, -562790079, -3372504518, 1052999666, 1532162150], [-972147712800, -29005342984, 537694876, 2036460400, -4555387094, -2636708, 1288900764], [-438394185306, -14343461584, -2769589364, 2632046960, -2053228608, -2559957800, -1290611324], [850482584480, 2818855064, 2225837572, 739462556, 2257139060, 14171816, 1560425936], [-335421672014, 60865016580, -485933804, -2273084900, -15770412144, 803964260, 1351669816], [1685588908898, -26908788717, -918782803, -152531029, -5711639744, -478858065, -1421028738], [-1217644980522, -11904721744, 853096704, -262060496, 6455475136, -1626837392, -3760100544], [-1338951056602, 5005459164, -1528203318, -711898410, -977511868, -35329208, -305342180], [3321279687608, 61217286468, -595224628, -3022780624, 5617162787, -791378386, -836384712], [101345348140, -108318283364, 357779734, -792145134, -5073835810, -3123299660, -745905336], [601280629430, 42369717312, 3151019240, -2868669300, -760464576, 3433537776, 1680598724], [-661142430388, -8921406926, 512989412, -1220724524, -20246636169, -545317144, 1496877656], [3119455745384, 12299603782, -179223724, 755273748, -14095011518, -3058316578, -206394316], [-192451846302, -14738778274, -1619817051, -3339682391, 22152890866, -1593746156, -321566420], [1507106519764, 25945783998, 340136228, -1292338860, 13591645974, 2114364558, 1383801420], [1108321423398, 71279720972, 2101024958, 2737972430, 6971510724, -3492979184, -510706048], [1846912958114, -60592808208, -1530009436, 1529924612, 2072922016, -3393125784, -2171672832], [639435335418, -7520562702, 1257515659, 3920044847, -114030670, 4979815412, 5557327372], [-1359658225596, 107774588006, 2260771876, 5767322644, 9700222439, -601089948, -1588975416], [-384431634732, 16211278690, 674706722, 3949002434, -4045258635, -2406647528, -4066676740], [-128640400256, -36679040692, -3633850821, -5847311547, 12055027862, -560494814, -2069257162], [-1477282093294, 71796396654, 3144537797, -4997228511, 4152728266, -4121139244, 3956020516], [-950146368714, 188732773855, 644920575, -78332999, -27589595940, 1376017439, 174678286], [2207204916240, 81500537222, -2998672848, -370001048, -11006537066, 5109183646, -424237764], [-1989956044674, -65085652620, 1022991034, 8480567610, 22045557596, 9744038560, -91153856], [-4015046875144, 67095174396, -732422436, -133274128, 588764294, -8300248000, -6578022316], [4066934416258, -75664859933, 3873963657, 5233110495, -8512837428, -4705147953, 4309224950], [-2957955344562, 109368448967, 2360680599, 111161721, -7043629360, -4327046225, 6192360014], [-863278575988, 304315906392, 1159633363, 4216426945, -10499502650, -7873349786, -2007671886], [-3366866653968, 20956276204, 2292781303, 8275796365, 20538890490, 4217504666, 1915373382], [-44229308152, 174502650572, 42939587, -3596336023, 40841820226, 6082549266, -39245754], [-1381875199404, 30064930032, -1718405925, -8869725743, -3934817162, 6690255022, 7461116578], [-7084058245092, 76191391246, 4225020514, 5241409290, -33759284369, 4230110600, 1140282844], [645061534558, -24517473332, 451186730, -2519551094, -47981777260, 3475437432, -5844584432], [1308290627518, 7298149868, 228864068, -4409863944, 36834732320, 7828262620, 11817173988], [-4564828502216, 239837848996, -8539051928, 9059955548, -15280283467, 1586379314, -1373865232], [-2322598271558, 102817938834, -8306920233, -8385297397, -15383587334, -14301576564, -11047108004], [2976199482794, -158508581789, -2971900575, 7486096863, -6969884482, 6312465499, -10289860314], [4635412639880, 260417932756, 732200834, -5918510450, 18093608015, 9184512498, 7371344796], [-6411137339246, -198444626500, 3518841568, -16047754460, -12302267308, -1974935268, 11836195036], [6970194215694, 120683295303, -7755315777, 3325095065, 6387800534, -13590721069, -3677852338], [-1077706362250, -167267742930, 2511514527, 9285447519, -10869330570, 18856450152, -5267785440], [3134826639722, -227158110260, -2299401230, 1546832994, -32238162380, -23298612856, -14349204144], [-10866234351852, 104234676734, -928034104, 401300608, 27065821844, -23343917238, -7431471956], [6969433705768, 16166050176, 5756010784, 3883891464, 26951664916, -3608786056, -7567674200], [-959298270126, 260981573402, -987525569, 11353334307, -47049343726, -834124748, -6864546236], [13899020233862, -189032536312, -6647249072, -16108288044, 13781953384, -4257349816, 4169132724], [-1874852802176, -114261734480, -5661255156, 3606147656, 51421171760, -6281959528, 2316235212], [-7051682413626, 32510222513, 6267506207, -3511816255, 104472461330, 2885427665, 2573310882], [-9309184667604, -418322076162, 12953170490, -15146166726, -80893197835, 971768044, 14135198196], [6790719043526, 341068801895, 3429935267, 10593131261, 46212222222, 10917511531, -335793914], [-9140497709456, 292541511034, -3361176288, 8370608072, 32584672046, 4728721226, -2817964884], [14957491216338, 262028598392, -7706608698, -2517030170, 10955979220, -708538460, -20185671008], [-4851635688030, 87698993216, -2780540660, -17156942108, -50437907136, -9661962136, -7240940344], [3297350257354, -291550743502, 7599404563, 26625959135, -27093365510, -101218668, 5115810996], [1857765936252, -463727550282, 5671223090, -13973954214, 78063549183, 12747523680, 21666967660], [-13778478747316, -93299661748, -304662533, 4363326253, 104336041618, -31859645870, -5012622998], [20402476784972, 251155538012, -658099254, 11438174502, -55866169450, -38416610612, 12324119808], [-1529322791284, -420945331446, -21105833904, -17345967536, -42776432236, 21798840846, -16336178740], [-14964715215362, -372484924728, 1088253856, 7963567772, -129230220288, 4778849080, -5724653364], [7876362446574, -569292409709, 26347536003, -15646318083, -24184207096, -17149444517, 7053648990], [3191154905350, 412456236919, 1614692175, -10988220535, -189987438868, -17561055097, -5050811778], [13645544519222, -83980310562, -5626078289, -10910119313, -83202526406, -14866890080, -20375675064]];
    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_b();".
// 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_b(:prec:=7)
    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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_17_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![675998208, -243559296, 10388768, 2252056, -8252, -2986, 1, 1]>],Snew);
    return Vf;
end function;