
// Make newform 192.8.a.s in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_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_192_8_a_s();".
// 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_192_8_a_s();".
// 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 := [-6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 48]];
    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_192_a();"
function MakeCharacter_192_a()
    N := 192;
    order := 1;
    char_gens := [127, 133, 65];
    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_192_a_Hecke(Kf)
    return MakeCharacter_192_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 := 8;
    raw_aps := [[0, 0], [-27, 0], [14, 3], [-468, 7], [-1692, -46], [8538, -42], [-9334, -102], [22428, -62], [-21744, -626], [9742, 1569], [-166428, 1275], [4538, -2772], [245890, -738], [255492, 5110], [-890712, 1210], [697846, -3339], [767052, -664], [-796094, -3240], [-584748, -31256], [-2858400, -13402], [590442, -23064], [-3269052, 7575], [-8402580, 14378], [-3059462, -22116], [11860434, 32220], [13104614, 32589], [8220132, 21113], [-19113876, 7180], [-7301334, 54138], [-3497150, -134052], [-17881524, -137551], [-8602092, 33936], [-28890766, 148602], [2007036, -101936], [-10241570, -184317], [-24135588, 174935], [-68511694, 109404], [52356924, 123446], [-37366920, 538056], [-13786330, -40521], [35547588, 923192], [11532114, -776286], [-36660672, -620344], [28928146, 1279224], [-15237802, 1204737], [122862132, -587155], [52590564, -242984], [50397084, 226933], [-173300724, -619298], [7697298, -2868402], [-50024374, 1399980], [101333088, 320996], [-11741838, -937236], [37036116, 3589650], [-302590462, 494400], [231297624, -1611776], [-413875042, -1306239], [72890892, 2083549], [191149938, 3559698], [-259894454, 725376], [58555692, 4065536], [-436521434, -1693947], [-276643260, -241912], [-83328264, -3358692], [-188539750, -1689912], [-426573154, -268035], [477015948, -1287412], [-123834654, 7338312], [-21350988, 8514778], [1077227938, 1439064], [-776237870, 1005084], [-285785280, 2815590], [-1288588428, 2180899], [1075512730, -4682160], [938763972, -992670], [-820415520, 9524112], [56689198, -6538941], [-494490350, -497808], [317355386, 1765758], [944796858, -5605116], [-1578967380, 3650422], [49551618, -631038], [-582111432, -8515738], [-652208942, -1570536], [1485341172, 13601985], [857466900, 665450], [1570683514, 13093362], [269669802, 14879148], [353607334, 3245103], [1086783084, 16146197], [-249497892, -24039082], [1234200168, 3138470], [2005768044, -2549137], [2362018572, 5714972], [1782528516, 9595360], [323668368, 10999982], [2363123422, -21356811], [469284962, 15406326], [2388228948, 11230002], [70932954, -2670078], [577957356, -15420726], [-699687530, 9385059], [2502134892, -31252502], [2606950706, 4088958], [2864676636, -13613492], [-174132718, -33580440], [300754188, 9632676], [2025080930, 59913948], [-6415402752, -3869630], [-2341676006, 30281040], [-699625332, 7854649], [-2709679574, -302472], [3252784666, -27450840], [-83695140, 36212232], [-3692527236, 45393543], [-1425962566, 18262794], [-2634009300, 30828018], [7371719136, -4215170], [-8267431690, 14293035], [682048980, -16171180], [-780536182, -9796356], [-6459615550, -25676208], [6002393150, 12427263], [-4061765772, 19320070], [-4297161204, -26764138], [-3521854946, 40923213], [-2066415054, -9085458], [-830909016, -60836886], [-314816292, -28181593], [3089084202, 95099742], [8124354180, 71273980], [-8439204600, -7673948], [-3826021500, -83524641], [6691903650, -494802], [10017455458, 27465162], [-20598311758, 27455328], [-4822432298, -28800087], [2687822028, -67115898], [-248195482, -146313669], [-9567721838, 86204202], [10932827364, 99714966], [7510996358, -17620647], [-17275096692, 114489843], [-4015879524, 207684644], [4784296698, 137179962], [-7432475760, -131713686], [-11561345686, 71775684], [-27404520686, -55955010], [12887784612, 66776058], [753036192, 89744120], [-5774501678, -71425296], [16741141106, -139225176], [3515875308, 164035278], [12825827496, -143896080], [-28300031244, -93758942], [10762894368, 112199660], [-24490625364, -88110589], [-16716930934, 127848534], [10183838362, -242576208], [-5424490010, 72457815], [-8698886460, -306147240], [559889714, -186226026], [31835185956, -138162655], [-172096524, 61077550], [-2750040422, 188402886], [-17376522264, -278036440], [20319177492, 266119343], [-32770696598, 231015744], [19063025058, 189573684], [3380963822, -206037009], [20786885820, 58256100], [11921974898, -74774412], [-13036753368, 81785380], [15406340730, -88397376], [-38279915820, -22976637], [-39227439734, 102182688], [-12560062932, 171912864], [-42497815826, -137908317], [-8704412028, 275693345], [34680204386, -59762772], [7376579028, -286168985], [-15354557892, 294695938], [-16349355534, -64312026], [-8282549030, -276243984], [-71347317552, -19263952], [58314109166, 236891847], [-5959682934, -7567770], [-9143174700, -417768984], [49875412986, 58586364], [-39428226432, -503761648], [-36820001694, -262153608], [22130376444, -5739408], [-21426556572, -526293776], [40390103686, -406970277], [-48260467980, -480723312], [34748091674, -387460872], [-52934551582, 292971960], [-3109944726, -98881722], [12299868994, 337920600], [67847651784, -458872764], [-62162169754, 472135143], [-2150283924, 628159861], [40222111122, 727293474], [-40055797806, -105263688], [31587235668, -141258298], [-95399158306, -97311915], [28918728108, -894789879], [21860352540, -648692510], [-84369577462, -76079628], [-26011218636, 200412018], [-51110041822, -92090016], [64562660462, -296588001], [-31426394508, -176078375], [17550014796, -226078464], [122428542960, -356379798], [-72356900966, 58131720], [44426209284, 622627663], [21006328810, -1133778390], [65800937736, -778930920], [26724817526, 1202698407], [14485210050, 618008010], [-30054925548, -485503591], [65622348362, 527394102], [-121722256692, -484501619], [-123282062100, 343088538], [-133198891894, -535361796], [-62856136870, 87184836], [-97059139992, 773692358], [96257838420, 668606269], [22420144908, 1235835356], [9776847210, 877910250], [102725827452, 343965402], [-64684916388, -498791667], [-3927395974, -830580360], [10466185140, 74475394], [-111507057000, -929627538], [172044171330, -363686748], [136913427166, -317798541], [127388776068, -318850930], [64159560576, 1124609486], [-4708754964, -133187046], [40607266428, -1531205828], [105709871628, -246971057], [-4005648574, 505770516], [133824939218, 646921728], [-137932748064, -778597678], [187512162372, 49958707], [-90245655324, -504506836], [131767861356, 1383749708], [-141487316640, 213527516], [99431369274, -32972502], [103950017522, 381440220], [87838030080, -1458066298], [114836325594, 152720040], [92063639678, -443190063], [145315067796, 622016940], [-225900992046, -413007342], [-220510679364, 276157100], [-28298099306, 636625401], [172214982538, -83401560], [-145822298868, -1716237903], [-238207116780, 148155320], [-135356852382, -1416525654], [-126603522862, 1439185140], [32587508170, -2579999778], [150190931268, -1912519116], [61322985782, 2202241083], [-45628599718, 778779300], [-294056733420, 391276190], [-100656387122, -496367949], [184529890354, -2036825568], [69331461012, -521435692], [-12182504598, -1940714208], [89799497172, 850875583], [257216145810, -1178434464], [-344181407436, 662334257], [66103268292, 2215181934], [-59467575518, 860182056], [-235876495894, -1979288352], [195417401940, -1030301620], [12351546216, 618563494], [-117590029884, -928002591], [-153401030208, 232051978], [98145650602, 2125991088], [104740024644, 257351958], [38257137504, 657290452], [123251337330, -366551340], [-99238218866, -2394721737], [130542687612, -1445490897], [171328072402, 558369372], [-289219384042, -2061340821], [-56240675100, 1580127248], [105085523770, -2053836348], [25993505340, -386303664], [31695176834, -1707264324], [195083101366, 80852799], [28883229804, 4050727137], [-227083480330, 1230674541], [123002748324, 1699983878], [225018668700, -2131358018], [78827316970, 4135353840], [-258284771402, 1604219931], [57086032500, -357084885], [-48587786748, 486282808], [-229903066188, 513516502], [-4636305342, 393292044], [238634930052, -1101628526], [419958061146, -402013674], [20372169312, 4245551882], [187082134090, -1521604296], [36131916528, 2066419768], [53251188566, -70175187], [-243473746694, -1244914782], [-23071569300, -865924606], [-31098559032, 935513276], [80432899578, 4110389928], [-140028870636, -1584224772], [-371406756456, -1857252814], [59168533362, 128871912], [-139600476766, 5339007972], [-483110728380, 2227284072], [207153025114, -5053601520], [-422407886834, -1217999631], [291290226084, -919066533], [417999627074, 1342804158], [93158172930, -1754730660], [327352373964, 2337274450], [79999429140, 3466655214], [-404722426464, 2311076432], [-77810227186, -175774077], [-151514577846, -4614756462], [608755582838, 2920811055], [607610460924, 3398362901], [-742931998236, 820913204], [182828549916, -6035703080], [-140608235772, 5792275254], [-449296282222, -2396071116], [26964038162, 4547902020], [89749885482, 29590560], [-839490445188, -2034783367], [-653439173878, 1689127668], [-71648822702, 7348771134], [-284145002746, 1244495733], [-721299615372, 1537055389], [397879358878, -2390509587], [-462336341508, -324311454], [395622662322, 5722154142], [566744746284, -378086036], [-223323108984, 2041213658], [505676513734, 1730922081], [300600142236, -778125538], [-265441050582, 4453757916], [313814168654, 5707905213], [-534649979556, -208939783], [-212339592598, -5131153692], [-549382324726, 2419159848], [377052251472, -7402322804], [71881784172, -4287588860], [-32720881366, 1360235106], [-65270245032, -10318168780], [-750389838022, -3366966204], [1002402116362, 430396476], [-1150011531216, 1799615240], [420406116228, -4217913466], [-47461052412, -5894335956], [-272192158774, 1387197936], [468655609246, -1244388951], [-434324720772, 7797650515], [-121935193846, -3405555648], [-122614598196, -190058890], [939663027828, 4164609426], [358376218992, 1327580952], [96752291734, -1388748099], [874167983676, 2205720807], [-1266324153270, 1695793902], [-645601207284, 4781707498], [53034044256, 193116968], [-756891546014, 6914415744], [-575153509990, -6028295418], [-764324116854, -6759728940], [-290073644650, -1230739377], [749004940690, 2007948954], [621464545692, -9843402921], [1275068922530, 661751952], [-743035224276, -1274423510], [-323738303976, 5330296016], [-392805535932, -6874178833], [1201628105682, -303380286], [318913049772, -11288016624], [-715513476312, 3423113654], [540134719458, -2464012104], [-1231926478498, 5669386023], [1299845519388, 901428624], [963912263292, 3320367258], [-64759800744, 3231965348], [671307018522, 3170711100], [-15649406964, -6503987159], [1585390099810, 4218437838], [-468212771340, -5274990590], [1176325050206, -5410977069], [-201414842942, -8755203888], [-1409084233430, -1647477666], [-911741344452, 7195762241], [-228675686798, -6352230282], [-1201695068474, -7462650651], [22858303644, -18110435693], [-400574916438, -5489227830], [583389960602, 8636659422], [-1942076756484, 32988626], [678373581852, 888222114], [-1261979496190, -4423431672], [-296577861746, 16781634471], [-260882907372, 2048984138], [166468421340, 9172147054], [990835452714, -6314917728], [600934353022, 3995748129], [-197586532224, 1370688696], [-1653014430756, 2683518875], [-642024225830, -8692124682], [820429065792, -4915464630], [-1085320091882, -7778264769], [-612912144166, 9322610940], [-1501205008320, -2050558988], [-289867650876, -6264752330], [-1423563859478, -2382438672], [701124126046, -12755289615], [-969252284772, 683228374], [-828442397926, 16196391780], [-986370662268, -5002650526], [1346695622064, -9688369746]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_8_a_s();".
// 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_192_8_a_s(:prec:=2)
    chi := MakeCharacter_192_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_192_8_a_s();".
// 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_192_8_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-124220, -28, 1]>,<7,R![-458352, 936, 1]>],Snew);
    return Vf;
end function;