
// Make newform 162.6.a.h in Magma, downloaded from the LMFDB on 23 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_h();".
// 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_h();".
// 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 := [-230, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-3, 6]];
    Rf_basisdens := [1, 1];
    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], [-6, -1], [-7, -1], [135, 5], [344, -5], [1569, 4], [-67, 19], [-1107, 31], [2232, -19], [-1684, 0], [-10468, -49], [4224, -154], [13253, -105], [21270, 54], [4866, -136], [23382, 274], [8456, 459], [-29539, 435], [-4173, 133], [-32371, 606], [-16507, -857], [5502, 798], [15069, 304], [-60292, 262], [34368, -182], [61514, 1146], [61548, 272], [90380, -357], [-144723, 324], [46415, 597], [-149091, 347], [-41967, 848], [-226102, -574], [-125694, -2501], [-42826, -918], [28862, -255], [-277282, 1010], [424977, -1785], [224328, -183], [366540, 176], [-306550, 1100], [-285681, -3071], [114569, 7074], [66072, 6385], [46256, 6220], [480017, -5237], [220793, -6885], [-1040559, -489], [353672, 3003], [563091, 530], [525498, -9318], [1243163, 2672], [-372063, 5867], [-196293, -2346], [-271074, -10682], [-1402590, 2423], [-408067, 14943], [-1396714, 2352], [-429813, -16342], [-93124, 1200], [698346, -701], [625700, -480], [-1265280, -7048], [-473173, 8948], [1948992, 7177], [-2478403, 11899], [-730228, -18730], [-688449, -1767], [1153496, -2266], [980982, -21160], [-1329831, -10557], [-1187572, -26580], [2138258, 17236], [400328, -38788], [1351191, -559], [2978070, -20828], [-514114, 17997], [-1093749, -7942], [1421177, -22906], [-3964404, -180], [1939430, -31999], [2453178, -2270], [558695, 828], [2308154, -21006], [1461342, 66558], [-1604808, 59430], [928013, -34182], [1969254, 41852], [-672874, -57974], [1761990, -29302], [5073429, -37653], [-2211088, 58252], [4780809, 52363], [-6058189, -15903], [1663200, -78240], [-1112514, 31892], [-5587332, -12806], [-2397175, 12507], [7504946, 1649], [-6507274, -72546], [5340684, 41269], [-1025598, -85470], [-2005149, 102262], [12825122, -24634], [-3092623, -93546], [-11118153, 30637], [551037, -72572], [-174384, 63244], [-3264367, -83454], [-7693213, -2971], [9329366, 16176], [324399, 93614], [9458240, -35256], [306278, 31130], [-1651851, -32032], [12226526, 73350], [-3593547, 49899], [4850370, 46384], [-2595477, -63443], [-4826116, -159753], [-7574671, -31694], [-5842830, 84472], [-1416618, 103542], [4049663, -177903], [2941944, -42775], [9460592, -4805], [-13972689, -58203], [-1014637, -22923], [5615414, -205800], [851960, -420], [11098644, -63096], [4279379, 217493], [-12810922, -193680], [4835049, -101712], [-17884411, 140782], [18646038, -99765], [6875873, -10653], [9843774, 84195], [-6127881, -91094], [23697344, 124560], [7829844, -113327], [9933284, -125000], [8886963, -254423], [-10891822, 246748], [7191381, 168639], [-5726830, -184620], [-28364721, 62706], [-3171586, -249418], [-3409935, 183427], [-8121802, 100661], [-967980, 259610], [14207522, 101842], [-45555, -73273], [9091988, 14188], [21724455, 49797], [-3561451, -83865], [-7238931, -340536], [-4471975, 261074], [5827032, 158593], [9225273, -445185], [28106559, 10530], [-7368697, 112569], [-8063919, -269601], [-7984368, -33170], [31992108, 11380], [-9509299, -224709], [-7166002, 97425], [1822439, -212244], [32983986, -129112], [-49655520, -52732], [23982002, -192327], [-9749886, -231718], [-30158881, -133276], [-39371749, -115919], [5522040, 75502], [349277, 507183], [51015096, -225879], [20057342, -181190], [43050110, 11637], [-14447698, -681430], [12853329, 357919], [25288244, 122979], [17252244, 334050], [47993646, -166342], [-45764580, -284003], [-21015772, 652923], [46455977, 328979], [-45251134, -184520], [-53016639, 255367], [-4225567, -357290], [40287252, 475476], [-50554189, -349279], [-6143718, -379553], [10388721, 505831], [13752990, -173768], [35925383, 285208], [-18656974, 190060], [31581825, -361760], [37632999, -220691], [30747840, -352515], [-203005, -970223], [-38689360, -156170], [23710163, 522108], [9053781, 617267], [-53366766, -260672], [5049977, -174113], [-18953790, 807662], [-29521524, 923146], [36634775, 406985], [31699628, -671962], [58922172, 84721], [-91139467, 45387], [42922707, -460727], [1703328, -47736], [-68584108, -341658], [68206157, 191775], [-35206449, 83238], [-73096734, -183982], [-46954332, 676273], [81817580, -53285], [-128573857, 19569], [-132148833, 88550], [-80087722, 676818], [-8871996, 557532], [40764860, -573917], [60573288, 994494], [-83893575, -508129], [-78724402, -82678], [-44996562, 659294], [40560134, -742399], [27782219, -1000083], [-98158645, -184095], [18497019, 848114], [-1985524, 245576], [-8325162, 943610], [-154215961, 59668], [-2641248, 587322], [-67765620, -821172], [-30055251, -1430821], [1617801, -946925], [55541045, 137223], [74240882, 463854], [-114949150, 463068], [-11416176, -464786], [21809097, -938965], [-87478447, 5215], [62921973, -43873], [-58382542, -392034], [113666112, -353856], [-92241460, 1138959], [-28649871, -26520], [56776590, 520834], [94342433, -232230], [68839896, 453405], [82771005, -185165], [-121942636, -958017], [53044439, -336735], [-47950884, -759927], [32157272, 463506], [-46981072, -194912], [134583960, 160536], [5387030, -142983], [93691592, 251750], [-36702258, -1384144], [-36256684, -869952], [24569040, 1483897], [163335243, 716562], [55519640, -50400], [94701624, 387561], [-27535702, -1169947], [-107950357, -489679], [115038032, 1297722], [-47972044, 1287480], [41666975, -1053336], [120406574, -160962], [-101889024, 460688], [34628702, -1071951], [72481313, 1766154], [-86020626, 996202], [-3760566, 2265110], [16068068, 1267692], [-53930844, -37336], [-96230200, 707643], [24425774, 1524978], [-223960284, -458640], [117030713, -109838], [-27842346, -2055644], [-44344111, -729201], [-173902149, 280014], [-11632290, 793380], [44752839, 48209], [-36869301, -1655102], [-19715232, -1759692], [-44120776, -2031309], [-94934016, 886033], [-180135496, 569080], [-101482374, -702161], [-101241351, -2345421], [-24597802, -861662], [-60871003, 3152890], [-71975376, -2008398], [-240654103, -535857], [8420799, -1316131], [93378164, 147956], [25999292, 3327510], [-98532639, -2608813], [-137949958, -461244], [-44810100, 1475848], [-161793526, 608161], [69325461, 1556795], [86064174, 563916], [29433999, -231042], [179731505, -1739369], [-181427730, 2075134], [-182431384, -441246], [207483678, 517730], [-71314920, -721376], [41227817, 942726], [213683568, -173154], [94356086, -1651998], [-80494792, -1772846], [-68274786, -570469], [141016556, -1602180], [-66775260, 289954], [72276227, -647896], [29134127, 2984037], [342537395, -778887], [-40508781, -982683], [88316682, 2570816], [24503342, 1118928], [-202480560, -1950311], [32348432, 3590984], [-10792113, -2746275], [-339901, -1065747], [53307942, -1239982], [236828180, -732825], [-89501973, 3000542], [-161465716, 853662], [-45202390, -898074], [260799236, 602419], [-63231516, -2064430], [153432348, 2392389], [-134302048, 3704252], [-24117798, 438823], [-346166373, 53669], [-184287994, 2300397], [-107264380, 3377844], [227564088, -284132], [295436832, 1688765], [-253861177, 420293], [-231416617, 708544], [92113560, -2424695], [177648107, -1156767], [202050170, -2548419], [85753113, -1013476], [368091330, -1555398], [-115779543, 1956715], [30635460, -1303334], [-223338825, -1124527], [-334443538, -1437635], [-264466107, 2811680], [-279242559, -1398453], [43272654, -1753718], [-1430554, -652862], [-54388051, 2231894], [119129442, -94640], [550635620, -433088], [141204506, 687856], [-74693817, 4627517], [363728627, 1098137], [-332148336, 1024520], [-25061934, -5627693], [-1585150, 2201590], [-241579534, -1458011], [-162418359, 1563555], [-263517282, -832590], [165723899, 1576276], [281905086, 2501296], [36491099, 4256244], [-320219712, -1850827], [37628721, -5860472], [385689410, 16106], [-118164927, -2514464], [428291273, 954091], [-156528375, -5268509], [-171721948, -1634640], [-12560134, -1195807], [-171170545, -4313927], [222355104, -1146744], [-456865267, 1436394], [-243144372, 3850789], [-299829705, -206483], [261426719, 2105789], [406555554, -1284426], [300342095, -1561512], [-400695193, -1457959], [290047359, 4632066], [352399787, 554385], [77580084, 2759777], [160193798, 2500353], [198491808, -392642], [-161252677, -1566675], [647729511, -810798], [181424574, 50091], [199286507, -92679], [-399222802, -3484955], [-85457025, 6036014], [-377391277, 3105393], [530137428, -1542032], [660787907, -1117980], [-114951600, 7037621], [144614589, -1634725], [291046334, 644562], [-201195589, 4022504], [-211475778, -2193377], [-75175824, -5337868], [-110004616, -1419056], [379997079, 3103550], [30095238, 737282], [216913608, 1212890], [276637232, -1398042], [-260283990, 5107102], [58479144, 988416], [-111773941, -5840652], [394212474, 5626531], [-579821148, 145712], [145038933, -4026744], [-417470488, -4856688], [280985910, 3623338]];
    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_h();".
// 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_h(:prec:=2)
    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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-8253, 12, 1]>],Snew);
    return Vf;
end function;