
// Make newform 162.6.a.i in Magma, downloaded from the LMFDB on 06 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_162_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_162_6_a_i();".
// 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_162_6_a_i();".
// 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 := [159, -63, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-135, 24, 3], [639, -12, -15]];
    Rf_basisdens := [1, 2, 2];
    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_162_a();"
function MakeCharacter_162_a()
    N := 162;
    order := 1;
    char_gens := [83];
    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_162_a_Hecke( : Kf := Kf)
    return MakeCharacter_162_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], [0, 0, 0], [-18, 1, 0], [44, 0, -1], [-105, 5, -1], [248, 11, 2], [-483, -9, -4], [377, -5, 6], [-1056, -14, 1], [-1716, -59, 6], [2870, 44, -17], [6656, 40, 10], [1683, 80, -70], [10463, -117, 39], [4308, -40, 49], [16008, -116, -54], [20985, -255, 71], [25322, 37, -82], [10997, 519, 15], [21612, -354, -130], [-1411, -901, -68], [-29734, 724, -15], [10878, 476, 211], [-11022, -294, 98], [-15415, -16, 386], [-34074, 45, -88], [-67492, -1376, -655], [45555, 1501, 54], [6932, -824, -586], [31908, -155, -142], [-106954, -294, 1188], [141894, -260, -987], [-13785, -576, -938], [-83419, 2357, -87], [-93792, 1613, 1662], [-59440, -3770, -235], [-156178, 2755, 392], [238388, 1312, -176], [149034, -3382, -269], [62016, -957, 1212], [269916, -1580, 828], [-14746, 6770, -450], [-224784, -6384, 149], [262889, -2464, 1042], [-335184, 298, 436], [311498, -4248, -854], [-175450, 310, -1443], [775724, 508, 491], [82599, 4645, -1177], [610532, -6835, -1124], [38139, -3457, -5182], [192684, 10602, 4917], [-526555, -10950, -2236], [-147315, -11149, 2978], [-632499, -2344, -2924], [816516, 5706, 1871], [-1589628, 180, 214], [55100, -8328, 4740], [332780, -16343, 3548], [13476, -23241, -3896], [245870, 14440, 4715], [405420, -30665, -1664], [-961513, 27337, -2626], [427212, 21330, -6947], [-344071, -4774, -1344], [811404, -287, 9562], [-895822, 18938, 5399], [-106945, 1948, -5324], [3504207, 4989, -3087], [-1543294, -14849, 9532], [-3379011, 10342, 1926], [434142, -32098, -1904], [906242, -31272, -6315], [1063004, -48513, 12514], [-1171543, -17359, 2880], [448326, -23902, 11447], [27288, 36499, 19276], [3496664, 9620, -7202], [2897559, 24276, 5482], [836597, 12966, 200], [-2464278, -10586, 15095], [1074518, -20555, 15538], [32178, 39290, 15936], [-252457, -46719, -7776], [1352966, -34352, 22121], [4536789, 39413, 12109], [1242873, 64271, 23440], [1794389, 21568, 518], [-4255872, -31687, -20218], [-402250, -15240, 16675], [4543665, 36955, 6918], [2879160, -58718, 17459], [-2319274, 52110, -1688], [1189167, 87571, -19757], [-1884961, -44253, -15363], [5123808, -18082, -11390], [3580470, -112773, -1154], [-3384843, -44531, 54646], [3213020, -85978, -2558], [-4922896, -13234, -16356], [-1026697, -68295, 2337], [1120422, 63414, -48226], [-2171841, 21037, 33185], [-11347785, 15550, -8552], [-4676353, -78991, 19383], [-618379, -151361, 25928], [556569, -25979, 2785], [-7919070, -39506, 22150], [-6569166, -52006, -31029], [-524245, -20530, -55850], [-4108066, -98146, -31203], [2731772, 72104, -71066], [4614597, 100134, 13198], [-4994581, -127367, 18077], [-859648, 82732, -25700], [-3357537, -74966, 14460], [4025195, 35169, -34125], [600498, 75562, -35416], [-1513848, -158397, 800], [-5758722, 137858, -25851], [4889654, -120785, -3724], [2822168, -19947, -14240], [6814242, 83537, 61680], [-5662089, 115169, -20666], [8311190, -33060, -19239], [-1535718, -26962, 19850], [6313286, -78445, -12220], [2577924, -33356, -8944], [-5891188, 165942, -35343], [10852532, -15029, -61954], [-3759847, -148859, -91132], [7253796, 77432, 63127], [14064770, 214110, 47249], [1408826, -42484, 39640], [5427912, -212821, -47456], [3521840, 115275, -47150], [-2533986, -60854, 35978], [-4857490, -144512, 24995], [8291010, -86489, -20818], [8984649, 146319, -54136], [6737951, -81147, 59826], [3741012, -229895, 67282], [10263578, -296860, -21829], [-5892108, -250508, 18940], [774422, 126654, -31862], [4155342, -94022, -55591], [8029832, -406933, 22486], [6136548, 318811, -32524], [-5614297, -371323, 51723], [4837872, 280204, 124132], [2724194, 232293, -56806], [-10538526, 248114, -37294], [16805123, -178551, -22790], [-5882490, 63936, 102145], [-1057003, 139589, -2965], [4703298, -57164, -4045], [-23987806, -19742, -45088], [23864136, 196803, -12984], [-9637546, 421298, 2010], [2474250, -85031, 189796], [21688125, 378079, 119675], [19670337, -484409, 15320], [-17721064, 67178, 107707], [22723020, 58182, -100278], [18440079, -568042, -35952], [-2838438, 169256, -176865], [-6169984, -335604, -152076], [-19079842, -339881, -97240], [-32405758, -185498, -25990], [5504598, 424515, -114602], [-33880137, -309553, -1171], [3653162, 500845, 45818], [21305394, -62748, -185927], [27284363, 98274, 137090], [-353812, 158520, -44615], [-31157652, 21737, -81786], [-5482849, 36131, -125729], [-9110358, 210178, 200318], [33972740, 287932, 161040], [4042706, 590343, 23124], [23262344, -260624, 18979], [-48175263, 194849, 104709], [50861672, -34727, 42308], [-32299245, 445097, -102464], [-38243484, -611008, -169729], [20188062, -276885, -20782], [9368228, -328750, -214004], [4585382, 276180, 217697], [-32035495, 445270, -109860], [-16767276, -547404, 54896], [64111985, 323647, 47460], [10903803, -672983, -144817], [-18837571, 245483, 171210], [7339842, 28357, -1964], [-36891807, -359733, -151210], [8961117, 580020, 192248], [11477759, -386358, 243814], [-1232026, 237891, -253076], [-12982311, 990052, -186140], [21214830, -238582, -224844], [33117312, 302887, 43076], [2811584, -618916, -19009], [61744370, -20773, -72748], [-39633061, -191696, 320684], [-37934499, 902503, -53778], [1956090, 211318, -39422], [3226904, 629244, 276508], [12469131, 261791, 215171], [43109397, -327728, -47876], [-355471, -381367, 59217], [-21379837, 248921, -95916], [-8060556, -7219, -180174], [34453616, 416536, 121547], [-46370538, -193962, 402545], [34471974, -336306, 135003], [35405933, 495546, 306660], [-24094018, 76484, -195425], [-32814345, -244188, 83658], [34045674, -194798, 126888], [-11195994, 917415, -311566], [-12532324, 691299, 61582], [13006178, -468818, 121457], [-17950185, -96572, 75450], [-24518518, -1248070, -40712], [-83815935, -3299, 257027], [-22784416, 569229, -306596], [-16603320, 628465, 388226], [45290004, 1385520, 396532], [13657472, -671146, 453], [24700602, 1044230, -414139], [-27026872, 1030145, 326076], [-56473900, -801288, 59784], [-23948632, 363922, 19091], [-13892607, 721844, 431228], [84642542, 478402, 51259], [55460604, -907324, -151315], [25233656, -523679, -299292], [18713250, 601502, -356486], [-1441059, 241733, -281897], [25870542, 282242, -553924], [22308813, -125299, -772155], [88298156, 444788, -2564], [62601326, -1564734, 20697], [17199038, 1611422, -326942], [-32326527, -1838422, -342378], [99074658, 34850, -91483], [58345388, -305084, 461400], [37120707, -909571, -251035], [-28305082, 640830, 8229], [114531426, -280174, -183944], [50161688, -193277, 353162], [22539195, 834021, 638484], [21631434, 2256592, 238789], [57631640, 732959, 266398], [3211908, 371887, 103364], [51199401, -1266763, 301116], [37316324, 417704, 482302], [-32176246, -940110, 37671], [-3231900, 805230, 2676], [40754243, 679001, 743788], [-59265250, 1930600, -405567], [-63779997, 2681627, -312155], [-121403314, 110999, 210148], [53246462, 822234, -226522], [35237196, 1381679, -208144], [43259909, -1715781, -296811], [-56755536, -1073344, -298458], [-21733995, -556124, -255640], [104684201, 1832207, 534811], [-136930272, -840091, 467974], [97443686, 595073, -711534], [-157983412, 165796, 51412], [-2135245, 1448168, -242300], [-98953696, 2351960, -93443], [-101224153, 585666, -130026], [201735884, -77596, -254240], [37168794, 191704, 9981], [-100042060, -1336789, -690422], [-65563567, 293919, 394908], [-60071049, -416939, -705641], [-172549476, -333132, -399485], [-36834940, 1781684, -554843], [39623268, -2077842, 625723], [-43428280, -1384415, 839600], [87028091, 872591, -317363], [44993718, 1834036, 132338], [-27807238, -320886, 769246], [-93430866, 3005373, 42836], [-90515398, 1181434, 644267], [-41636817, 262323, -2454], [-16314834, 2064379, 725978], [9297663, 3615439, 440064], [3942357, 942472, -593972], [-87077175, -2043445, -588395], [49935290, -357861, 728472], [73133160, 43151, 83460], [43415156, -3028854, 618781], [-77200020, -130683, 1186094], [13280508, 2132752, 743048], [-109872646, 233160, 11665], [-67044163, 2108674, 251460], [-122940630, -507922, 72874], [25205096, -251608, 980080], [-172220958, -933700, 618545], [50338370, -1453980, -901261], [40385954, -2996510, -184546], [-175420194, -2195290, -263815], [194237450, 440227, 523076], [88880712, -423892, -21609], [-79335460, -1590652, 493466], [-21104718, -157450, -634183], [-27307188, -3277428, -180114], [86876016, 129453, -51114], [-75886006, -1768414, 1241957], [-56678964, -1619920, -43788], [-82017619, -362641, 492040], [139147635, 87573, 527491], [148850322, 1426884, -545335], [-1108381, 14784, -532380], [-22023852, 1189591, 616208], [116741651, 3883697, 614437], [139055513, 1204002, -643040], [76001064, -2518412, 823338], [1849934, 1700486, -1443824], [-151195104, -767553, -1134580], [204306791, 1456511, -429390], [5560625, -1384367, 76160], [184627895, -2753763, -301467], [30973254, -2546950, -337271], [-102699390, 3258990, 692026], [-207559750, -307861, -134072], [61418058, -1588827, 274280], [233565686, -2030834, -386501], [-3592425, -2432357, -358807], [-4134607, -95573, 1309814], [75356052, 1078992, 740032], [212690882, 7500, -96888], [173612097, 1218654, 149746], [-74059489, 350922, 1096038], [-62611180, -2136138, 993174], [-150643222, -3440983, 151730], [105489156, -3988783, 102206], [47970786, -3225583, -125756], [-58224214, 4191306, 70235], [-57039012, -4120691, 912910], [-36067881, 167743, -664680], [111608984, 2453344, -1572310], [30253973, -4524831, -828369], [88683282, 2934796, -77141], [124106334, -827796, -1264664], [293022326, 218894, 163797], [-242439841, -1322051, -149628], [179934576, -165275, 137974], [-218200054, -401384, -294979], [-30821698, -2573303, -473086], [-165258318, 2177436, 1274320], [-120620886, -2396424, -1756275], [146389260, 464840, -756528], [269780280, 687221, -461610], [-73391856, 2270454, -522353], [-124088560, -1113389, -1433946], [283354473, 1831636, 1012284], [-62314848, -5454450, 152394], [-60699609, -5751531, 266927], [-89992981, -241451, -2032698], [-180635185, 1656750, -1173142], [139884750, 2701407, 279974], [-285912514, 2031000, -764402], [-63379621, -4644555, 483256], [-279797010, 618458, -899731], [180401333, 102027, 259658], [-158907006, 3716294, -162721], [-285344262, -1110805, 436014], [-443961508, -1416524, 859677], [-21959110, 2321558, 863414], [303634101, -2429697, 222093], [-150229062, 5530532, -520394], [-338698594, 1679178, -21326], [-307087467, 420251, 396096], [81326984, -5511679, 310444], [351316776, 794219, 757484], [-419537829, 2832930, -746464], [149696384, -1636452, -301684], [-31303179, -773978, 1195294], [153382793, -1847711, -578175], [11237772, -8463468, -960784], [53792312, 5966344, 636203], [124846850, -3696633, 2004008], [-48115216, 7534328, 758828], [63031674, 2713894, -1313449], [535162415, 1778378, -433514], [-540128574, -946193, -64142], [364008585, 3907145, 333264], [280990439, 4430923, 825415], [-148382724, 1072504, -1152703], [-334909540, 918405, -1009452], [117124592, 1524918, 1834850], [147076503, 5574868, 1038530], [-123501511, 3491345, 392977], [301142214, -552985, -1597582], [226737116, 727041, 138192], [16899321, 3503239, 393976], [13546646, -246500, 2075615], [-121989768, 841759, 1927052], [-64323234, -2321332, 676792], [-97888804, -4512166, -204398], [125826608, -4411755, 2003740], [-331266201, 1648682, -738028], [225003671, -325735, -326921], [-314274186, 6683240, -239601], [-130057177, 3913086, -86502], [12435312, 3339195, 1357420], [-133611393, -3847285, 2395100], [-369632227, 3735067, 503213], [91943300, -977655, 517736], [461151714, 1368826, 284038], [-426442494, -1410150, 141568], [380886824, 2056126, -659739], [428779221, 3000119, 994100], [73459206, -798794, -1210989], [526748610, 3530249, 1285664], [-92112640, 6489564, -805722], [51996006, -7624162, 640821], [-338794791, 5615049, -891777], [109676378, 8587714, 1617518], [303988938, -28761, 166838], [-234779253, 4103311, 457545], [-181066554, -5934314, 1290314], [258505940, 2886888, 396816], [-265109814, -4036320, -1078345]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_162_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_162_6_a_i();".
// 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_162_6_a_i(:prec:=3)
    chi := MakeCharacter_162_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_162_6_a_i();".
// 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_162_6_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-215784, -4671, 54, 1]>],Snew);
    return Vf;
end function;