
// Make newform 182.6.a.e in Magma, downloaded from the LMFDB on 14 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_182_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_182_6_a_e();".
// 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_182_6_a_e();".
// 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 := [-1701, -479, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-318, -5, 1]];
    Rf_basisdens := [1, 1, 3];
    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_182_a();"
function MakeCharacter_182_a()
    N := 182;
    order := 1;
    char_gens := [157, 15];
    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_182_a_Hecke(Kf)
    return MakeCharacter_182_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]];
    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 := 6;
    raw_aps := [[-4, 0, 0], [-5, 1, 0], [-9, 0, -1], [-49, 0, 0], [220, 16, 1], [-169, 0, 0], [-45, -55, 10], [611, -56, 7], [-283, -46, -4], [-453, -92, 10], [1350, -9, -16], [-5716, 310, -11], [1686, -560, 122], [-9730, -113, -9], [-8391, -240, 193], [-27388, 93, -217], [-7647, 1337, -39], [-6938, 504, 168], [4546, -2228, -118], [-1260, -1458, 415], [-33974, 361, 214], [-35234, -329, -623], [53776, -2081, 12], [-5016, 3115, 938], [-34698, -2527, 1202], [40505, -1047, 1764], [-87660, -2052, -184], [79977, 1757, 231], [7132, 1372, -1027], [58428, -1141, 267], [-150105, -2689, 447], [144416, 4288, -1314], [-34302, 2124, 1497], [108489, -8327, -2726], [77378, 15278, -1071], [-69806, -16832, 2781], [-179093, 3097, 328], [106354, 11414, 5772], [-35835, 1098, -6027], [-248733, 14789, -2334], [12108, -12427, 4093], [154465, 3981, -4988], [-391837, -17949, -699], [-177158, 26648, 1266], [-38244, 17526, -8730], [-144625, 5861, 5998], [230467, 17532, 584], [-42018, 38777, -920], [-108096, 41984, 358], [-473445, 6177, -13401], [576199, 26064, 380], [860240, -1356, -7978], [-222701, 44374, 1803], [917227, 17391, 4432], [-175529, 147, -13514], [177142, 38661, -7799], [-116914, -3018, -5632], [-68338, -70970, 2814], [-1287263, -10692, 2686], [479482, -96742, -7023], [515888, 88704, -18998], [109930, 24823, -8360], [428628, -20381, -3408], [1892199, 73379, -9188], [-824941, 25715, 2002], [-366554, -120606, 12022], [364868, -55546, -19826], [755598, -68911, 35777], [-2718096, -52096, -2684], [1773026, 31901, -11752], [686349, 13491, 2785], [485762, -143004, 1223], [39171, -146205, -224], [-902629, 139205, -15245], [-680640, 70272, -23113], [2515322, -23294, 36280], [922897, 172815, -2453], [112616, 6463, -44044], [-1802980, -59448, -8608], [1080598, 77609, -29204], [-2730877, -105725, -21602], [-1068048, 38614, -49253], [-62194, 118708, -35060], [-4627684, -141956, 30468], [-1606918, -47512, -84974], [-621289, 149328, 18200], [59802, 83030, -33208], [-2916196, -256658, 45735], [2675410, -333436, -23650], [-3899602, 169030, -28023], [3347893, 126665, 37024], [1191780, -76023, 73692], [-1639432, -183462, 25536], [-4163533, 249059, 3091], [-1069666, 64648, 53931], [-2087156, -135662, 39610], [-6457314, -45633, -2198], [-3234400, 273468, 19868], [-137892, 235278, -19338], [-2191996, 315006, 77931], [-6700937, 165654, 21816], [-4146266, -152154, -28550], [-2776494, -11590, -77550], [4279917, -128686, 162380], [-2853789, 5076, -113814], [-827726, 198992, -135604], [4276434, -639339, -14392], [-956479, 557014, -36321], [2534662, -280441, -139587], [4293680, -545966, 6], [201519, 321027, 133188], [5603226, 10662, 161602], [1579920, -98878, -118774], [9540734, 289450, 22806], [7359050, -98236, 48812], [-2487969, -140498, -172566], [3687720, 177732, -41990], [-1285339, -238279, 127570], [4465240, 410646, -41882], [-7262327, 322380, -106376], [5563319, -100642, 204025], [-1780254, 776869, 29149], [-4811723, -50223, -97568], [6373968, -254552, 15342], [-5896899, 695340, 37187], [-1071085, 979090, 22084], [2322382, -147750, -192457], [16330703, 211547, 6056], [4265056, 834542, -185462], [14308423, -387054, 32717], [-4904010, -61574, 53423], [-13501194, 65818, -175098], [-888748, -1036431, 165923], [-1241537, -49894, 260504], [-16287857, 416136, -41111], [6347067, -541772, 194807], [-12109242, -931652, 223330], [-11892362, 592079, -186540], [-3351390, -160288, 46132], [10905219, 342526, -237220], [-2841088, 962244, 306924], [12737528, 690266, 146960], [-7648949, 506763, -154763], [-7737874, -1095758, -23024], [-5309343, -1166447, 52018], [149684, 812912, -114082], [9657793, -1013930, -74689], [-7456028, -770582, 374284], [-3288308, -1653954, 155810], [6389618, -346642, 506566], [5680092, 377146, -332161], [-3081906, 210136, -363874], [-17085073, -855417, -124313], [-4759830, 424298, -343636], [-6365299, -336854, -168626], [-26007940, 989027, 208695], [18774780, -275420, -270580], [28663149, 86390, -134063], [12703409, 39091, 270118], [-22445383, 977980, -75487], [2064100, 550154, 227444], [14646513, -410172, -124378], [-2492908, -19284, 356835], [-11950904, 1133614, -103596], [-2601706, -685834, 419583], [3401851, -190992, 137961], [11659275, 59787, 560919], [-2814016, -1336996, 342790], [1470366, -1934494, -53683], [17061711, 134993, 345444], [-390008, -428576, -252195], [6325138, 1792512, -173006], [-31720823, 1925388, 99380], [28123002, -174152, 11869], [2858126, -876902, -31664], [15851844, -2488804, -387256], [-6139612, 955124, -692234], [33682658, -2354504, -162262], [-132373, -3080213, 175404], [40882825, -4827, 217118], [-504334, -72954, -201688], [502361, -1221407, 276884], [-31698875, -1135593, 207357], [-5168494, 1570875, -742100], [1293052, -1417040, 142267], [3068811, -440077, -639796], [25838918, 1885067, -396529], [-6642948, -446907, -55182], [49150540, 841558, -273272], [-22744957, 2150256, 344705], [19211325, 553303, 343420], [9322582, -1090480, 55046], [-5507199, -309858, 673394], [-7426215, 2859330, 718865], [10906399, -198086, -597740], [1813359, -1009663, -639254], [15340478, -1654730, -557503], [-21506319, 2077788, 254252], [5130633, 777896, -509979], [-40552960, -683450, -438844], [-19838888, 1191134, -104935], [-38024349, 1352937, -96032], [-30843696, -2522341, 362204], [71988580, 906844, -73828], [-18034771, -257864, -557941], [-28392432, -310980, -145518], [-39003632, -420771, -702342], [-28012662, -2310645, -419517], [-42537722, 4738652, 515093], [676408, -3849754, 149330], [21434715, -1553016, 826120], [-14361809, 895705, -801702], [24746672, 2903976, -794664], [6928942, -1591946, 881464], [8506854, 3442185, -959568], [-38920447, 574786, 822171], [-7063744, 1549441, -79413], [-8065656, 5319620, -172854], [-19176970, -2647538, -262300], [-21387122, -2285060, 686847], [839278, -626295, 400215], [1767933, 4547357, -28459], [-16612190, 1497486, 727180], [-50271002, 1602176, 259672], [-12040170, -1229096, -402742], [-37912090, 944907, -739845], [-15238982, -3159354, 624282], [-11308158, 4876221, 407193], [-16410103, 764805, -737804], [-74378710, 597298, 5647], [-68626257, 1371817, 445021], [-8463585, 4506925, 280528], [-25627932, 2597388, -352824], [34099043, -2636319, 732429], [77967836, -747866, 429044], [-14192969, -1325954, 1288595], [2981074, 2832224, -455618], [37241608, 1876780, -285188], [-14075777, -3609622, -1025266], [-49214498, 2693328, 253770], [-30602260, 1651588, -577220], [102717808, 402966, 25740], [20916414, 2459834, 1779874], [55869604, -3655058, -537740], [-94874035, 561808, -79875], [-11719747, 4765615, -572384], [93482845, 2693300, -659523], [97049586, 70639, -210132], [-98938520, -4025622, 1003547], [65456589, 1288864, 315722], [104029630, -2064046, -88266], [17537942, -1981532, 1238694], [17819706, 2332184, 1363934], [96271372, -37210, -734088], [-78647022, 2489056, -102732], [31172108, -2823960, 1664994], [-38115177, -86328, -537732], [18261956, -14592, 10872], [-49341068, 2635876, 1103874], [44685629, -2211608, 422727], [-52772143, -3062714, 1206300], [-158216, 5370211, 1206723], [29557406, -1497871, 13660], [-60794159, 314693, -1434794], [-4416712, -2255654, -2167250], [-5182438, 63068, 1724528], [-32703922, -3374772, -456750], [-112897014, -845555, -361502], [-71389510, 536482, -1062485], [30436481, -8754681, -1079347], [-110974419, 2680809, -400384], [-66167402, 3116348, -605291], [2850784, -6455410, 955454], [-41067021, 8619910, 5676], [9152947, -1887387, 1130228], [-186620078, -860974, 134858], [-98144898, 116372, -341007], [-69247412, 3112078, 181161], [-73178520, 7399464, -996496], [-139526282, 5849014, 62154], [16266268, 7384718, -1263212], [-65096734, -9142096, 1385748], [-18657314, -3057074, 457826], [-98305882, -6480691, 1278058], [-121111495, 8915957, 1237449], [-75043678, -146781, -899157], [4333557, 6483602, 282434], [-4368972, -8920288, 1400964], [-67328730, -6730534, -443380], [36042819, 3404273, 918018], [97934436, -8270391, -105285], [57009998, -10389330, -1301048], [-69314126, 59700, -1511924], [-826851, -9524922, -1869889], [-117625040, -2617181, 1619213], [-125453520, 275560, 718508], [13785286, 4750376, 185162], [45100184, -783940, -1511044], [43517803, 400633, -2000564], [235677276, 1849405, 1116996], [37473247, -4961605, 2581116], [33595968, -2353686, 2087993], [-50426523, 2090818, 1986614], [169845351, 6320608, -501554], [-61627371, -2242528, 1032192], [-179756360, 1356656, -25695], [43408747, -10942793, -893567], [101925071, -2242499, 295966], [193293000, -3311710, -954370], [-208203756, -1629703, -886127], [109418203, -4457235, -894866], [3310290, -9260254, 1113477], [-27723317, 9665953, -1912287], [-170033250, -7483439, -436049], [88866588, 9780982, -2255651], [-40104726, -1521654, -2261306], [268635904, -1129431, -853460], [86254262, -2725242, -2855375], [-18035321, 10480880, 986505], [-66636005, 8209626, -936708], [-200569558, -1776390, 1668396], [-62211206, -1591850, -3914068], [-11051607, -12308487, 1335072], [-52569004, -12840900, -813258], [136721308, 6329740, 2276924], [83555621, -3316377, -1477022], [86704958, 1390350, 2561050], [171715230, -1096655, -1582018], [88476457, -4851783, 167297], [180128041, -2408425, 2292403], [-199916736, -1269544, 2022933], [32859030, 11463251, 411315], [-55652007, -18329427, 1104184], [171206377, -1348108, 944051], [79860004, -2040936, -268507], [98589941, -10374254, -2290893], [-155017784, -7091238, 1274825], [-168850380, 859310, -4620756], [-197092145, 4918281, -3826301], [4061908, -7121426, -3221300], [-24590642, 10956568, -1909155], [150066605, -17773889, -1629419], [-174331775, -1060149, -918187], [72359053, 5116017, -2368419], [-47492262, 14626484, 2343669], [131553479, -6671765, 2630075], [-56889929, 11301555, 1598976], [36879082, -3321124, 4583721], [-80006167, -14967202, 2727107], [393131549, -1437999, -490858], [-80763871, -16335478, 3432053], [115955448, 530612, 621387], [-167175262, -9365744, 414697], [150493512, -2803726, 3272570], [-202618319, -4324125, -1385291], [-31942597, 17162539, -2026736], [-286553998, -846171, -253336], [225070116, 567051, -1644492], [-75566823, 797511, -422091], [12226662, -8806470, -2888223], [49826652, 1544882, -3195840], [185451212, -6932422, -786252], [22706624, 6280157, 1574639], [-273120960, 17588906, 1893681], [-378083091, 3868981, -2727912], [40776937, 1801434, -5282082], [-301573307, 10083614, 1500551], [202397824, 6879200, -902405], [-122859250, 984723, -909613], [-123020747, 6528777, -965537], [-83758169, 13706319, 711918], [198510478, 3990216, -3800307], [-324140597, -554992, -940252], [-44669989, 17687489, 387552], [267622681, -10603586, 1593702], [-149858994, 6790286, -145088], [97162535, -18443577, 3617], [-34568703, 1093919, -4408531], [247970670, -4390990, -2612124], [23302946, -7806336, 2979232], [28681113, 20389434, 3662187], [-175504052, -3505210, -4134992], [-344269806, 5494924, -645565], [359851308, 10293730, -2423601], [226557247, 16743202, -5459731], [148110528, 6911167, -5843404], [-186671512, -9761546, -4176077], [-350917218, 4068394, -1280574], [-20083774, -5058172, -4654349], [-297481147, -22585901, 2848398], [-70453664, -2358606, 3307156], [-137819419, -10925888, -3967129], [354574364, 11952068, -2423646], [-236456602, 11798382, 3885204], [-366497656, 2022348, 427040], [-365751582, -1101291, -3553015], [102800394, -24909350, 2009366], [-153568056, 9943126, -6501242], [-70498214, -3368075, 3422949], [254526804, 4258444, -2360002], [195841190, -10579757, -5118768], [51571070, -20809085, 1444977], [-178856368, 13183032, 1463635], [240579205, 18442372, -1865219], [-164463094, 9273575, -4690422], [-89344225, 11200529, 508726], [390273710, -13318134, -1183628], [-96226868, 10672138, -502287], [-36879601, 12302946, -5300231], [-167262327, -12869092, -1665935], [404900680, 1615336, -1403476], [50422612, -19129353, 8098615], [33189419, 4910878, 5392326], [171231553, 22680357, -1496445], [-78811648, -14979319, 4340287], [-401852581, -13798099, -202800], [46035070, 24671098, 1711584], [-387408138, -10900522, 751356], [-81225266, 8248716, -2261936], [-27094763, -10993953, 3514420], [-255185662, 472071, 189631], [298572573, -2511021, -3398035], [-132702180, 8339170, -4812301], [-210802125, 10085113, -1163878], [306568260, -12999430, 4034270], [253416286, 8618047, -1296224], [-303899194, -372685, -2618845], [423411654, 22670394, -2153796], [-300144895, 6661356, -787865], [165463852, 22384070, 3614418]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_182_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_182_6_a_e();".
// 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_182_6_a_e(:prec:=3)
    chi := MakeCharacter_182_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_182_6_a_e();".
// 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_182_6_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_182_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-3996, -414, 14, 1]>],Snew);
    return Vf;
end function;