
// Make newform 462.6.a.m in Magma, downloaded from the LMFDB on 01 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_462_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_462_6_a_m();".
// 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_462_6_a_m();".
// 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 := [2202, -320, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-216, 10, 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_462_a();"
function MakeCharacter_462_a()
    N := 462;
    order := 1;
    char_gens := [155, 199, 211];
    v := [1, 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_462_a_Hecke(Kf)
    return MakeCharacter_462_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 := 6;
    raw_aps := [[-4, 0, 0], [9, 0, 0], [-15, -2, 1], [-49, 0, 0], [-121, 0, 0], [465, -8, -47], [-301, 1, 48], [-84, 21, -15], [-1561, 19, -26], [-1065, -238, 161], [1873, -141, 330], [-665, 72, -297], [6538, -298, 144], [2089, -115, 390], [7688, -151, 765], [10381, 93, -1376], [-7686, 903, -2121], [23404, 1458, -336], [-11016, -365, 1257], [-26234, 1146, -288], [21917, -66, 3025], [5018, 38, -352], [1975, -1067, -1334], [14398, -136, -2732], [56413, -971, -5268], [15287, -3459, -2326], [81092, -1734, 4256], [4750, -149, 167], [40041, 1315, -6502], [20236, 1994, 1520], [157385, -1725, 3000], [25296, 7936, 4566], [-80777, 6013, 13102], [165034, 4934, -1786], [162897, -7736, 12877], [178411, -5467, 5428], [109598, -10386, 5644], [393244, 8015, -63], [250391, 4311, 634], [-77266, -8826, -15782], [-151324, 15620, -9020], [257687, -6645, 5910], [45875, 3425, -23196], [-59089, 8435, 14820], [464262, 10224, -14688], [56505, -17039, 16640], [531116, 25810, -1838], [-211314, -740, 18824], [503342, -15708, -11996], [-1881, -29113, 41962], [-2772, 5294, 17292], [274476, -17361, 4109], [239691, -11122, -6069], [-189008, 3491, -72659], [-545145, 14828, 52971], [-391252, 27361, 51899], [-189092, 1214, -21110], [-104798, -10193, -56445], [-567038, 1274, -39554], [498485, -31152, 57453], [-434710, -32597, 20729], [-686920, 30188, -76726], [1968158, 6614, -19278], [-414228, -81176, 31054], [-100021, -23919, 73726], [-939113, 23891, -55472], [-1093902, 36786, 70640], [31903, 52159, -56516], [162382, -34882, -41260], [842079, 54626, -153011], [-653343, 70056, -87507], [-2878, -43314, 120096], [1974942, 61732, -36952], [1368021, 43715, -140606], [2036458, 142191, -23925], [-1820714, 62506, 116570], [-1547096, -75604, 5614], [453261, 3487, -248256], [-1926321, 47595, -103776], [1584804, 42190, 116162], [-3312982, -43483, -40187], [-859465, -28466, 219109], [-3025850, 87243, -133689], [2719138, -2666, 33554], [-370148, -113271, -17721], [-3987390, 90874, -262656], [1539168, 21988, -283230], [239061, 167457, -127064], [-2366400, -16028, 311766], [-404702, -91191, 54765], [4396234, -82829, 213103], [4510427, 30941, -200652], [-1866006, -100702, 204400], [1154256, 139293, 268359], [3070146, 22063, -243677], [-2768225, 52655, -92390], [-425734, 135132, -404514], [-918343, 48118, 271039], [2804600, -207361, 398103], [-4194716, 113976, -123286], [-1725712, -163220, -59728], [-605085, 63930, 60373], [-5451887, 131293, 501284], [3588578, 148336, -279556], [-4524330, 256314, -277348], [4286721, -166825, 629458], [-1630738, -14819, -138859], [-3460696, 341132, -600868], [5274054, 29514, -398688], [-1732271, 98510, 341417], [-9071512, -122683, -24861], [-5676807, 110863, 370274], [1806500, 142558, -516472], [-96855, -203937, -368216], [-1580154, 301586, -204396], [-3448551, -63653, -163254], [4893459, -182521, -815302], [3375776, 129515, 21887], [2796416, -7788, 467158], [13213188, 177349, 37319], [472417, -440551, 853790], [9393831, -43013, -409192], [3505320, -100718, -197756], [-7578721, 131965, 378980], [-18857194, 22684, -67858], [4848888, -202238, 727200], [2315207, -234766, 1047389], [-16155120, -264161, 239675], [-6265707, -309615, 233488], [7435626, -64928, -770108], [2578939, -488685, 159250], [1028204, 181521, 542243], [-7890824, 90423, 896661], [6275437, -23650, 852059], [-4678040, 633732, 104080], [-599651, 624072, 201075], [4295137, 74322, -471239], [4132904, 4303, -990117], [-691225, -220658, -16857], [5301691, 68426, 307153], [-2685644, 470475, 875111], [21151831, -244496, -468809], [-10251554, -19051, -606871], [5876638, 697227, -325573], [-1423108, 404652, 519916], [-11697834, 487455, -178395], [-12709922, 122928, 401456], [6415002, 85384, 487570], [-22477556, -84872, 616116], [2722055, -239493, 1478446], [14290018, -207818, -428070], [-9821903, -426266, 689515], [1746612, 397593, -371497], [2704415, 1124793, -1065020], [24688432, -397220, -390328], [-2749372, 350278, -1340134], [-21048923, -62795, -910406], [-9702111, -348928, 597525], [909854, -219188, -1030162], [-1487686, -127602, 730222], [15839216, -784150, 1606386], [34519627, -251526, -445183], [-14474260, -341026, 228030], [-30419964, 115259, -545843], [23135535, 847811, -797396], [-21074638, -1386642, -26530], [-3294260, 972699, -1714263], [20021932, 59286, -1186280], [-2350866, 189972, 1583000], [-17721679, 611414, 111849], [12799536, 956933, 698091], [6208500, -246282, 1116070], [33676400, 486120, -1464944], [-5195881, -213967, 2560738], [-31705390, 630320, 793188], [5578100, -828182, 670000], [8602155, -288745, -818978], [31687804, 721106, -717484], [-10232660, -30501, 3325], [-5854201, 728156, 661507], [-31859296, -363241, -567943], [25248679, 591083, -1174024], [44506598, 78580, -1059584], [38442054, -305530, 1212008], [-7001504, -258116, 2352900], [8011947, 945784, -1690851], [13112914, 537426, 946554], [-18244025, 1427445, -2050124], [16789655, -480387, 1237998], [26283221, -726201, 2611396], [14891134, 251252, -1582452], [-5061074, -1335319, 2435001], [45191970, 868981, 363397], [-6976789, 646730, -1194569], [-4060146, 1340227, -2365141], [21439579, 948218, 781417], [9677913, 598331, -3715298], [-33095206, -405904, 2268480], [40037973, -1309155, 3362322], [29298715, 1042027, -771734], [41985616, -1140218, -435804], [-56977522, -559427, 548257], [44900369, 671593, 76258], [-26383689, 842372, -1974263], [29825378, -1779194, -1093732], [58538084, -516026, -2072542], [-28239526, 739138, -782358], [30187900, 1608323, -3338123], [45527670, 2982692, -512712], [745109, 2296617, 1967850], [-39291550, 1058320, -1232796], [31259765, -683376, -3164633], [12974300, 670953, -593853], [-17446386, -1916498, 772372], [-71634528, -955706, 1516614], [25609548, -1274234, 3964916], [833708, -671828, 4799184], [-58062723, 1626915, 1200000], [24277937, 978603, -3002320], [2934373, -1988933, 876494], [-32958005, -2466651, 1226170], [-1335340, 1139827, 3554365], [8544935, 3706795, -3440560], [55083920, -7803, -2572157], [30171602, -1027118, 6398498], [9490354, -1013560, -2864160], [7698241, 2982328, -1930959], [-25089408, 2478650, 2429718], [3435410, 2159169, 3367153], [-42453512, -1265953, 2951993], [-36347548, -1600642, 4834632], [17408004, -820057, -1068569], [28825582, 87596, -3088290], [31064427, -1040006, -3641655], [-72503249, -113041, 2661706], [-70754032, -335546, 288302], [77496973, 3711551, -1786238], [51343295, 870658, 1621229], [-28515363, 394711, 4100868], [-35408468, 623241, 3086897], [12773355, 3875555, -1197750], [36159912, 1317264, -5129446], [-56162963, -1883541, 602818], [23150946, 1730400, 4665892], [76640012, -192728, -2727208], [-63018826, -1502986, -2537584], [-38423258, 2297374, 3056370], [-78822808, -3673427, 3043579], [-48217946, 629442, -3542708], [34614012, -2006583, -4205949], [73823638, 1265232, 3517384], [-21714327, 4275901, -8399450], [99550590, -827884, -3663850], [-65311956, -1230686, -715900], [-149141156, 1021698, 884360], [12315336, -2714652, -2064156], [-13479843, -238014, 1849231], [-41842692, -3836173, 2133287], [-59410583, 1921908, 3602243], [78750975, -1784008, 6680341], [-38696816, -6442966, 974310], [-54225188, 2085592, 3955176], [7628898, 1232716, 1095336], [-2533537, -3556068, -606333], [-85788279, -3925884, 1363749], [-107544531, -2462029, 2544132], [-55638576, 3377302, 3227232], [3029615, -3208876, -1904777], [29739346, 3744090, 3981216], [31585554, 1780016, -4178396], [37642376, 6627864, -1518680], [7345686, -163567, -2172355], [95591847, 232507, -6131616], [22048721, -223265, -1418436], [77209433, -672834, -6056195], [-34063757, -4221355, -321754], [-22308216, -263412, -454992], [-155562508, 888026, -3734616], [91160187, 1270761, 1910138], [-153527089, 802299, 2907884], [-40836883, 261977, 6642686], [31888648, 2898128, -1767208], [-27463269, -3085351, 3039864], [117860919, -336288, 4379135], [237273098, 879263, 1241737], [-1307355, 2453685, 5548710], [-77771995, 5408852, -987863], [-62588526, -3682896, 1094624], [37482939, -3360427, -3105006], [4073517, 3950363, -825792], [-129198465, -1920195, -3830130], [121610298, -3002718, -10730384], [47285203, -1716286, -11958347], [105803373, 2432229, -7007612], [126880214, -2539234, -7602818], [-120770033, -5086221, -2116660], [-34585432, -4417138, 12491792], [197336660, -2912890, 8412946], [-236172033, -2676769, 2261164], [36954016, 5397297, 6219589], [244731997, 678328, -1309933], [83823221, 7839042, -3406169], [-3389327, -1125375, -5989414], [-12383565, -3540629, 5086482], [143897776, -26041, -2471419], [119488287, -1395642, 8113981], [-17039419, -6580095, 5362066], [-3438843, -7137747, -5542282], [-36033543, -2825123, 13295502], [78788583, 3185295, 4711344], [1323944, 6774878, -42358], [-32510034, 5537942, 4275286], [70803101, -3308820, 401577], [30952468, 763936, 3350224], [120358260, 3938964, -3287088], [-133413316, -1272290, 4818038], [103622242, -6004274, 4842624], [-68915856, 1960152, 11062968], [59844925, 1406157, 1035328], [49985070, -3905916, -7151004], [81235006, -218745, 11549597], [184453409, -1092956, 5096049], [-65037116, -1708738, 6972876], [-76090546, 2004566, 3687760], [-99103767, 2355154, -11569677], [64255642, -5645398, -12702710], [102396400, -2342860, -4719136], [32103281, 5136777, 9085646], [92814578, -3598687, -4134499], [90253077, -3815636, -3143883], [-67264248, 4255820, 9669522], [-20624282, 7613882, 3659186], [5296086, -3751137, -538217], [-47590067, 8130399, -10713466], [-124539329, 6842079, -11087478], [243233568, -2093567, -2979717], [-138636133, 3097970, 10690009], [-24041277, 293599, 9462462], [310710737, -2849193, 4518734], [-70435022, -4383318, -4571372], [-128739274, -2452660, -9230892], [30198257, 4108851, 920162], [-97951611, -2207149, 3510226], [-106684614, -14821937, 2880323], [-23334303, 5506895, -7754658], [-27038800, -4567291, -15480169], [94383816, 6991690, -4701302], [137521390, -12538, -12946608], [130626074, 2224350, -8387344], [176464708, 1300578, -11384870], [-118870690, 5230934, -2812414], [-200173193, -1221656, -2604421], [-76526062, -2484010, 4215790], [104526946, -6554581, 1551563], [138431645, -10765117, 16361318], [147582671, -10597935, 22610648], [-309696754, -3246181, -4527251], [-75991724, -11014880, 268530], [7661873, -10165968, 1095517], [199737791, 6798023, 6494510], [-135581372, -741076, -17741398], [55283394, -9543134, -3019792], [98548226, 2736878, 6492088], [-42463602, 2548675, 20040747], [98091412, -3178616, -7217728], [-25284141, 11485574, 10925085], [19737501, 10579259, 6601682], [-288094860, -7435198, 9589874], [-260824694, 9256076, -15621556], [393584817, -785373, -14083020], [-322976421, -8910195, -2611904], [226994084, -8947413, -2714039], [-360477643, 2410106, 17356515], [-157267150, -1641734, -3453564], [451254919, -986786, -6821939], [-8120874, 4759949, -17120103], [175904490, -6909915, 9396985], [175506507, -2533580, -21066767], [153327274, 9044236, 8848298], [-239180926, 2978616, 10863734], [148636129, -6632712, 13877531], [405604963, 2984455, -1972020], [-116476572, 7868642, -2859566], [-101842251, -4020116, -22803275], [283154360, -2539840, 7884910], [-108796078, 6880851, 21058189], [160493656, 6010175, -5731747], [60297264, 6521462, 17580846], [215389767, 3914197, 8344424], [214168470, 12013857, -13376081], [5362179, 2578684, -5779153], [31313006, -8682804, -23754314], [55641653, 4539233, -16575974], [-137626585, -3339621, 2140626], [469766892, 4146126, -1877754], [565061, 99451, -25954198], [-262425910, -5734653, -566469], [217592717, 11465184, -3719475], [23587106, -4910174, -7030608], [170498173, 15428700, -11045491], [214329047, 1439178, 10617353], [270905421, -10013637, -10598802], [55629961, -8748149, 218608], [424759788, -1914998, 12105264], [-317948949, -7339777, -144912], [302625430, -12525699, 32061705], [81262907, 15002482, -1627667], [76105912, -6272522, 18969796], [288160692, 9187722, -4501130], [-54695210, 4276126, 6807720], [-123505178, 13658716, -435434], [-121184726, 395600, -12857516], [252416630, 8195646, 18707336], [-384458617, 8814007, 17810986], [-237722248, -3640666, 16233136], [161329213, -6629474, -4380647], [-419998040, 7403241, -19038385], [-359525973, -1057919, 3689242], [-153134402, 4545856, 7219320], [330090255, 4084813, 3498544], [-56013065, -17340255, 1261638], [75089333, 17450332, -26639335], [-201117793, -6022587, -25375976], [329484017, -5744853, 11705074], [-176960270, 9198960, 32658740], [-562813265, -9500492, 3219361], [-269724929, -13801051, 18632692], [110415531, -12250178, 22473513], [-45746398, -1274756, -26482698], [-117385032, 13143564, -41761900]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_462_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_462_6_a_m();".
// 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_462_6_a_m(:prec:=3)
    chi := MakeCharacter_462_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_462_6_a_m();".
// 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_462_6_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_462_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-174636, -4207, 42, 1]>],Snew);
    return Vf;
end function;