
// Make newform 576.8.a.bn in Magma, downloaded from the LMFDB on 30 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_576_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_576_8_a_bn();".
// 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_576_8_a_bn();".
// 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 := [-46, 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_576_a();"
function MakeCharacter_576_a()
    N := 576;
    order := 1;
    char_gens := [127, 325, 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_576_a_Hecke( : Kf := Kf)
    return MakeCharacter_576_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 := 8;
    raw_aps := [[0, 0], [0, 0], [98, 1], [-252, -3], [-828, -6], [-3078, -2], [-8554, 62], [-252, -138], [25776, 6], [-99902, -341], [-128628, -135], [234362, 108], [53470, 1002], [808668, 690], [323208, -2910], [734746, 3399], [-2270772, -1464], [240706, 7560], [2387628, -4296], [-547200, 11838], [-2865942, 5416], [5201388, 8685], [-1106100, 14322], [1802182, 10484], [-3578094, -10740], [1410986, -23601], [15972588, -11517], [-321876, -25860], [6747786, -37838], [-14725250, 6772], [17623044, -4821], [-4752108, 61776], [1664174, -69602], [-802044, -120144], [27574930, 93313], [-26596908, 50925], [29916914, -149796], [44461476, 108786], [62390520, -124056], [94084490, -78979], [-35165628, -75048], [67777074, 256506], [46660032, -169944], [33949714, 360504], [77953658, 60683], [-96728868, 198975], [-56116836, 65544], [36369396, -175017], [140482476, 299958], [117263538, -196138], [129941366, 314980], [-156427488, -242124], [38342322, -1176004], [255539124, -675270], [167749118, -1060160], [-22027176, -704064], [191192882, 465931], [304936452, 444111], [-209025198, 1345578], [263824054, -352064], [-20493612, 1307136], [301261546, -753673], [671900220, 127128], [278222904, -139572], [498011930, -1113912], [-152837134, -1157345], [97619508, -3140988], [691561314, 1037832], [-244120428, -171678], [314488738, 702216], [132540910, 546996], [408417120, -1869570], [812601468, -315471], [-444868070, 781920], [87694812, 4422870], [-637696800, 3256848], [24365122, 2498049], [133378450, 4093632], [-287621146, -4078262], [-705576582, -923564], [-51730740, -914898], [922280418, -462502], [-1535093928, -2183298], [-278411438, 498744], [-960769188, -4620645], [2285041140, 1329330], [947917606, 7268742], [-1514831382, 1166108], [2654249866, -2326107], [310521636, -4449993], [328513788, -7478898], [384137352, -1683330], [-1569131964, 6053493], [991381068, -9365748], [513080316, -4049760], [2383215408, -3250842], [-1703633102, -3470841], [-1361279362, 4515186], [1032982092, 12472902], [4226423994, -738022], [1501444404, 9201294], [539858650, 17098081], [-1787136948, 9733362], [-3333565906, -16595062], [1588452516, -777468], [-2339624302, 8876520], [-338009652, -11154636], [-1450294690, -3731468], [-45233568, 176010], [1806768154, -2088720], [3101799492, 708099], [-5905484246, 4972968], [-2230685594, -4904200], [1458958500, -10303272], [7682344884, 13290237], [-6747717274, 10475854], [1374897780, 19756998], [-7687442304, 8831670], [-1774741510, -7354695], [-1946437740, -25403100], [-5615782582, 12890556], [-2422350910, 34798032], [-5758904590, 7823637], [-6400652652, -26126850], [-549717804, 12074898], [-14086385294, 6614543], [-5275783854, 10286198], [4067049096, 3364434], [14576368212, -2151843], [-353006262, -8941338], [2605900860, -9691500], [-1164557880, -30582732], [-5606791380, 1653381], [-6370075710, 2229558], [-639122498, -46498738], [12673326002, -6637248], [-10601850758, 18112387], [-12420846828, -25712478], [6260921738, 14260649], [12669144718, -1787218], [9629851644, 13311954], [-3281357878, 31292563], [-2298527388, 11110113], [4732474716, 21182196], [-8211866022, -22033422], [17264588400, -37908846], [-3659376214, 34426404], [6027682894, 20745290], [11257879932, 6485022], [20523274272, -34598760], [9829445458, -73495296], [-3118487026, -51201096], [-15304269708, -57219462], [-26188783704, -13257360], [-11255027796, 55349718], [2209852512, 28500060], [-3600810684, -108117231], [-40787761066, -2093806], [14088862618, -4794768], [23483194570, 47861725], [32973751620, -53621640], [43643452334, -20092334], [26193940524, -1725765], [7439162004, 133458630], [-18885587642, 6196194], [-30655079064, 44689800], [-6364867428, 31785717], [25442931178, 50823504], [-21834701982, -36701884], [-5586225598, 101850789], [-39778503300, -69387660], [34710104498, 29505492], [17940993768, 65397300], [-22926336390, -25783616], [-18358444260, -103348143], [16328572534, -55088352], [33635843028, 101965536], [-30745822334, -132710047], [-18352628532, 25184955], [39366618146, -24860628], [2325518172, -199949475], [-20747679588, 159117738], [-18071051886, -171288626], [47314629670, -110622576], [12134885328, 61812912], [47195773634, -109953683], [-7000700886, -82139890], [49656739500, -66019464], [20767520826, -86750964], [12603076992, 185844432], [-7216164126, -18281768], [-23221294596, 76522608], [50974570908, 145321296], [71355656554, 22206793], [-6699821580, -127023408], [53600041574, 28609512], [6743258978, -102927240], [-18513455094, 72130158], [-76811073986, -124797560], [79286225544, 100864404], [-15898402486, 169078093], [54292262436, -140571561], [21862977138, 77015994], [1176595794, 175039928], [39813078132, -284382978], [-39970423246, -150937305], [-56872608732, 171248499], [-8645115780, 79373130], [-25140032458, 271215612], [-78236526996, 63782982], [12940676642, 72753984], [-79505258302, 50775029], [26390012508, -228621405], [118392569676, -77017536], [145387239120, 52994322], [86115784474, -32871960], [57736726956, -199180587], [-118422435530, 123721390], [-39875818104, 237771000], [6011638586, -224207987], [-44462224350, 332711810], [-35790983748, 283268451], [11303372438, 213909362], [39986443332, 391465311], [42433349580, -41742558], [-46218171574, -185103684], [-109443106330, 165063084], [197296441992, -22522722], [-114591430980, 229245999], [-22677574068, 166814796], [12563956170, -115458590], [61413342372, -65124162], [-5326357068, -22437153], [74798018054, -327863960], [62711056620, 250284534], [-157557172680, -147978522], [-15676573950, -617784332], [-128166599534, 195859281], [-5711710428, 170618790], [65800959264, -231274554], [-235858195764, 25764066], [100508177988, 80848788], [-50885218908, -213243627], [-38352456574, -128171916], [-218636795602, -112198848], [6009493824, -68059878], [136801304748, 32952417], [-72532875996, -354517476], [88798509396, -186357948], [-203973913440, 235063884], [133327596186, -227847262], [-53599738162, -450431500], [20918080800, -372693282], [-241553120166, 264980680], [68625911378, -656814277], [67322359764, 743265180], [-73161873486, -177033878], [-159384259836, -447069660], [-78440022086, 413458739], [-135744169718, 225788040], [10470104388, 332568747], [59848397460, -503569320], [150399019458, -340827166], [224339354642, 101798100], [50574473110, 431796138], [15584508, 529343676], [42258632378, -615522007], [67319398118, 525211660], [86699462220, -55172310], [-13816035422, -565686511], [-15696355406, -963191952], [11810341548, -564210852], [-46410189462, -373049568], [-248076594468, 417148197], [-4277754990, 823665376], [77061863196, -466914453], [-90204064668, 365736006], [75486079522, 520173144], [10669463786, -280767168], [20404447380, 690241980], [2168818056, -952855554], [-373784002164, 196117371], [-120635311968, 1166352882], [-45099691478, 1201701312], [182274973596, 179328978], [193432900896, -402092508], [130776551730, 660355780], [-145455901406, -744000003], [47266826292, 66934197], [207704068078, 114980212], [65450398682, -622759431], [111587074020, -696348528], [38072210950, -1026843092], [-18114489540, -383750064], [-153261011134, -816679044], [-8958627206, -232014251], [-271612037916, 445062843], [-36170307430, 116579759], [25200197316, -975985602], [-294108176700, 487905162], [319547462890, -976944240], [338487736378, 605032329], [-390458771460, 148882185], [118701051012, -251062248], [35605059372, -201259182], [229138541442, -1258907556], [-299085159708, 1144264506], [82541075706, 743421054], [-219853501632, -583130958], [59059176010, -124459416], [-99475043472, 273140952], [351013943354, -158456337], [267693351334, -258656042], [314026462260, 839176374], [-153559888632, 1586632044], [-65426365062, -466638648], [699189672276, 141413868], [123265654776, 677414586], [-217119267342, 42527272], [160345890206, 158315532], [-174710273220, 830180088], [-47718431654, -273738960], [-318162349886, 735523739], [409114451916, -1462703463], [119674732574, 437085642], [209013563970, 1468122380], [-381237260076, -728129370], [523283339340, 755420634], [348383138976, 962160528], [454978024034, 805468737], [-390570252246, 1569811242], [311274785978, 896700005], [147421861524, 2265290679], [-73238677596, 509129796], [795456820836, -16231800], [-273194051292, 323233326], [14369896658, -1040985324], [-61711157458, 360704300], [823117428522, 669282240], [-218087095212, 2399780163], [-55309310902, -270376812], [-210114923762, 227399946], [673265787146, -403434937], [160347052188, -572243889], [-374255006222, -1563759313], [392804832348, 1771366986], [-289045590318, 745710758], [594444328596, 1096827684], [-373163935896, -766041342], [36730850314, -2589607381], [389588015556, -1760559702], [-947902729878, 299149196], [-403062430654, 1997315743], [724970310516, 6848067], [853618394282, 1417316292], [-906265854346, 78007352], [407336811408, -1141723524], [175660793388, 51733140], [264019630454, 2905110294], [-367139533032, 934012740], [339975195002, 2142221796], [367676900278, -73569964], [908570230704, -529249560], [1011014269092, -659965506], [422658245052, 2052010404], [-486220206646, 3013114896], [-678755906894, -743846589], [-160869042828, 446941185], [236707266314, 291022848], [-667314479124, -262540050], [-1425958965972, 518935014], [-240395428368, 3632074488], [-184122146054, 1096271711], [416094175476, 453485853], [312358525290, 3500688182], [1228111837164, 384401778], [-1125904900896, -1349634552], [75263376994, -1554270336], [-396145740730, -3336626718], [-1167525505206, 606463940], [-1577042353510, -439155707], [-543088729970, -48677954], [-109651670892, 3440044269], [-198226901410, -4362198352], [-1226578389516, 1764258990], [-688125500136, 1317285264], [-560494817172, -3604444107], [1022745866418, -195396326], [-375108819372, -3910089744], [315089911368, 2432246286], [-1161804285342, 2481591064], [636275860562, 2942072077], [670888335132, -50978736], [869437982628, -2398914882], [998705660184, -1282653132], [865403486298, 2786411500], [257025140676, -4811558061], [295813907710, 4773304378], [384591915180, 3593821110], [-800896973806, 772496561], [301265523778, -154096992], [405125994550, 3157000746], [-1227125923308, -1684758309], [-511360680338, 2079786802], [1024528079434, -848987561], [-370134358956, -1334820927], [-1378119331062, -585715390], [1098423568838, -1988078998], [767219534244, -1770745434], [45345396348, 964001034], [-700543673470, -4162785912], [-1464303006686, 2285132749], [-652847389452, 1872899922], [982439563140, -3281602854], [203214480426, 3629842112], [451629117778, -2411822741], [-378616916736, -3998983464], [516127785876, 1240350105], [-1871139789050, -1130795278], [147650103072, 1091398770], [-1542750206438, 1229834901], [779449653146, -2705481540], [-458464619520, -2463286332], [879955519716, -1977267090], [284105722858, 2439045648], [1269530136946, 3972488155], [-48021032772, -1863358194], [-446680568794, -3157745140], [-140804010468, -1308428394], [53107722576, 6315202854]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_576_8_a_bn();".
// 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_576_8_a_bn(:prec:=2)
    chi := MakeCharacter_576_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_576_8_a_bn();".
// 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_576_8_a_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-96380, -196, 1]>,<7,R![-890352, 504, 1]>,<11,R![-3129840, 1656, 1]>],Snew);
    return Vf;
end function;