
// Make newform 320.8.a.l in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_320_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_320_8_a_l();".
// 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_320_8_a_l();".
// 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 := [-19, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 16]];
    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_320_a();"
function MakeCharacter_320_a()
    N := 320;
    order := 1;
    char_gens := [191, 261, 257];
    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_320_a_Hecke( : Kf := Kf)
    return MakeCharacter_320_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], [-10, 1], [125, 0], [-50, 7], [-2272, -50], [-1770, 76], [-13670, -148], [-19380, 40], [-62070, -51], [36130, -2440], [153412, -350], [61510, -3192], [132182, -7100], [-211650, -5399], [-52730, 5687], [1195790, 6676], [560060, 28420], [-1128522, -20000], [-2258230, 9923], [310892, -8750], [2284530, -28276], [2166520, -59060], [4896510, -61299], [3012810, 39720], [2304770, 70212], [-385902, 47400], [6314210, -33951], [-5695950, 136443], [5215510, 51720], [-2534630, 340424], [-22384290, -45853], [-21882912, 126450], [-5141310, 380592], [-30411860, -138420], [15076750, 638600], [20394252, -367150], [-4140050, 217368], [-23401970, 2301], [-18266370, -575673], [47521470, -698424], [-106656220, -315140], [-21897662, -1698000], [-92322868, 776350], [-110621350, -362676], [-103208970, 596388], [-85845000, -1412800], [-38220272, -1906350], [19229930, 3552849], [150104290, -2157697], [164885930, 853760], [241184490, -1233276], [-8286440, 702620], [-11107218, -4235500], [78649248, 741750], [-2617350, 4676232], [104789570, -1158551], [-48631930, 3186640], [369610092, 1991150], [229495790, 5327528], [-375787338, -3734100], [-136349290, 1171901], [-144951450, 3834576], [-358084950, -2869157], [-39856428, 1854150], [-399005830, 1765224], [-16415330, 6550748], [-40245112, -1832950], [267265890, 8192792], [422963930, 10586263], [680449650, 2251600], [173798610, 8427624], [35480040, 4075680], [792129430, -9559673], [-1172085330, -7785224], [10915380, 1381960], [-716903910, 565449], [-1688366610, -3727920], [642334230, 6813388], [1966830402, -5071200], [-405724210, 6007980], [-382321580, 6332540], [1572761358, 19510600], [273858012, -6741450], [-1351994910, 8369924], [-1352981640, 26720], [-1634706450, -8242599], [729958150, 34880900], [-1583493750, 31269632], [-786404022, 40211400], [-56692430, 2709349], [2012583370, 23050523], [702170520, -49914660], [2558865590, -9922533], [-845774432, -60499450], [-1596453300, 30871600], [-1936269790, 16585849], [-122556190, 17866720], [-2558843158, 27462400], [-1644345930, -66878699], [236657018, 49842200], [-4224918270, 466063], [1565392950, -58685832], [-124310970, 60950001], [1099652430, -8210340], [1270515208, 27391050], [4877164010, 88272], [728657010, -22875717], [1416849650, -40921376], [5502017600, 28657900], [4021505702, 14809500], [-4156802250, 45341207], [3372580230, -71053124], [-5617672470, -39188748], [575819620, -24322560], [1846974012, 26899850], [-2106835218, 14618100], [-5892033850, -48906199], [-327765530, -49160413], [-3718767410, -39486124], [-306092140, -114800780], [-5817663522, 103915600], [10104690130, -44054276], [1878414390, -18684372], [-3668776290, -57381399], [411967368, -57934850], [9525667798, 109142600], [-7396260390, -86163080], [1714880280, -110617140], [-10712518690, -110673753], [-2080182290, 130349376], [1691841540, -75601820], [-1480932950, -39467251], [-6568173948, 150681650], [-6496030050, 104631568], [6644776122, -150434400], [-4755070, 63240360], [8016221670, 106519476], [23520003810, 7356583], [-19357501970, 80225588], [-3987079510, 128884480], [6169525328, -205315450], [-2553211842, -150966600], [-12826122070, -264842451], [3784942490, 230556103], [3333051830, -200040640], [-339700240, 65040820], [-4253222410, -301214524], [-1897469150, 180984632], [2926762860, 391979020], [-17154536230, 46411249], [27855983390, -138879472], [-10425017138, -301254100], [-6670356890, 399220401], [27072778590, 146314167], [726243050, -154068457], [23919731572, 110250050], [-21453756720, 317915060], [192331670, -237843260], [4847276890, -210003908], [16149044218, -473216800], [-27439755270, 38961363], [-11529494390, 102693824], [-8847546970, -17697573], [30115391208, -261086550], [10692373810, 132881372], [8174085090, -579180351], [-15594654268, 19205850], [1823927630, 365757788], [20155787090, 316575480], [-31738790570, -20470324], [24711925620, 502244040], [5751180858, -175956800], [-24448788588, -163454850], [10456475890, -71328476], [8790518160, -647673280], [-2653215750, 373651800], [-45881180152, 94159850], [42841458978, -285144000], [-30782799430, 215937549], [-26595111930, 367243840], [-12258499210, 464696367], [-19103312432, -199337350], [-10070942850, 442495276], [-12535344430, -362122388], [-46338570390, 423885249], [-305469190, -1477880], [-67305125530, -128681752], [-50831079930, -46541399], [56341371470, 33725340], [61170240052, 487447250], [-81740375190, 49287824], [11075079230, -969690599], [22299968408, 696461750], [-55397840362, -635999600], [19400605410, -640364817], [20091363050, -876171476], [-18266244498, 31922300], [74227570430, -49908724], [15866271330, -244818048], [-53465759470, -427019351], [-83491921470, -24808440], [-95207567588, -51546050], [84227089310, -438225892], [-43470106350, -453428800], [-60873733140, 165265620], [-88208101410, -288525072], [-56735666080, 289176840], [67692229910, 275208001], [-72977053590, -630068280], [-37488762632, 536651250], [7873357370, -1921169388], [39715187998, -384050200], [23190713410, -1771277951], [72147266450, 255513043], [-6533496720, 948956460], [-17695372858, 1923922500], [-2510967090, 707931347], [-40887384078, 1264322400], [-11500009570, -1488148673], [-6331928730, -614730924], [27476372238, 608748400], [1048541600, 267863700], [41654585490, 584515080], [7669244130, 1039477349], [108191409490, -163851697], [2776926430, 695410560], [106299792690, 540488724], [165962802560, 356267320], [-166850178330, -589583413], [-5747401752, 422535450], [80025089990, -604676524], [-58543192740, -2505391880], [25405984892, 890545350], [-74266401338, 403438700], [29667203110, 1240390701], [-6476043810, 2859606267], [-18290417690, 2240417620], [-48198111650, 2258866076], [88887844500, 1637772000], [83952150372, -731068650], [141565437870, -1611682299], [-149176561312, 404234150], [70601667450, 1098896549], [-113608269550, 1093218800], [139983471810, -1360904376], [159188260840, -1800547720], [-55863549970, -720766773], [1983404408, -1253695850], [-117686971220, 2609621460], [131827015090, 1045789349], [-97953202170, 2019784588], [-89207858798, 1264820000], [29630486550, -978529893], [3013860190, 896486380], [-251231395970, 582105776], [-44811591780, -2758511760], [44736879858, -2386758200], [-65521797110, 17259903], [6009682110, 556736808], [63182453450, -1258719168], [-16233537030, 3046242449], [-137737614830, 1370290823], [64031441770, 2320119840], [27500726150, 1606298576], [-228721731030, -1761689388], [44850651900, 53836000], [-144008721790, 3145762720], [-48610409158, -3805338800], [-102297096530, -989103399], [-38381078890, -3732706424], [-173085607382, -1937422800], [-3218584470, -5530711637], [70367495210, 3606962724], [-231691483760, 1785437680], [95565033610, 4369828672], [-227428085110, -2196781851], [61900160010, -3475634817], [-513202510, 3280523480], [219990878902, 827851900], [-377972704272, 656498250], [-189002122870, -1125257351], [-387377140188, -414742450], [150090347270, 2223083587], [-225232339822, 609562400], [-31179868030, 5054369123], [254973056292, -3122848350], [99060572730, -1131741076], [164498707590, 3614795628], [-98073243280, 216164340], [-136136115690, 1453162020], [159396294598, -658499800], [-272952135950, 2888486543], [-61015281630, -262240476], [-389887222512, 821701950], [236102870110, -509101824], [248831274150, -1752045000], [-416983438348, -2186244750], [-154533883530, -3648603024], [-366709821420, -3813041040], [-310769377190, 528555483], [-101174069150, -4163866976], [182793410030, -694179512], [245060477400, -2273374300], [263210150790, 2242780401], [238707140928, -1898261450], [-63720991870, 8822718252], [-335387692710, 4921959903], [-98263162670, -6605808840], [53499753960, -5080961880], [-210093462010, -3805745224], [-13193971830, -1619846151], [-294722529030, -2658306960], [-456517151838, -786620400], [269015785510, -2818415799], [233479874990, -2396000033], [263224578810, 3799949720], [641442163500, -373452600], [-160755287628, 2110124250], [-150233021030, -8884110776], [-312025752330, 2200391940], [-331925537912, -5093674050], [248343875090, -4858148208], [396780186518, 539672800], [424643947650, 3720511349], [310446374610, -631798776], [202318389822, -3849972700], [-369101451620, 6765050160], [-346620181410, 2600162401], [-93080759850, -2866766793], [-157171758370, 5754310876], [-341565233242, 32630600], [-351206323090, -6739594592], [-78332881240, 7807937220], [-465618170450, -5443675699], [-21730863152, 13049117550], [62490170770, 5120514323], [390279739270, 7531305240], [408706101530, -2033461376], [-364342891738, -8150253300], [-44192519810, 9902073667], [408736203750, -5246505824], [-61084834630, -538649888], [-532424301090, 600093720], [27387156172, 11145643450], [591042924710, -3213858824], [-500164209060, 300839280], [91154225518, 3799836000], [458808636330, 1565793463], [283342137252, 11337331650], [-552570555050, -228034732], [209229018608, -13245629950], [-711482129990, -6147082328], [234257585638, 12112973600], [-483064358910, -6519313051], [235274376890, 6789258080], [150198456450, -12009807876], [23122287800, 13044355300], [-587725819272, 129038850], [1071723146130, -3526474548], [427627935130, 7962892349], [630185402910, -4209966692], [-937832453318, 4830212000], [559614993270, 8667430887], [112209923660, 6720852820], [984657707170, 2167065423], [-267788576070, -6795826276], [-137720739210, -16199740572], [17609334610, 1714524049], [214794626342, 1505238900], [-654160904112, 3538181250], [-428680159660, -1966072720], [-1101673119950, 3216775349], [450879351150, -6182370600], [-143087382548, 806816050], [500236412550, -1477966532], [-146029202020, 4561952560], [-142427797068, 4271534850], [-489250288750, -15846168576], [576734556390, -19327020], [-112426413870, -7167225448], [-1049295429542, 2378105600], [622118478690, -9703166376], [-168833629530, 2233473587], [-250426207150, -22812381968], [1207152866060, 5699121320], [-806963545430, -3160724251], [728663304092, -1083383250], [1405824204790, -2379645672], [-1229631227890, 2342315801], [-409324712010, -5748208233], [-1364999159690, 5086926820], [-191442338050, -6824564024], [761630021900, -11038482500], [139692799450, -4080668157], [703083013372, -18983108350], [1029997299170, -904142976], [752112508280, -6309511140], [-63732051030, 963277440], [539025636288, 2999833150], [157670947518, -19419495600], [-1293865361850, 6981848200], [-1031851874790, 4929674724], [-132834851370, -727684873], [-139181162590, 13040515072], [-672258044210, 2052382880], [1313591325132, -3023992750], [-1231007938370, 10323044388], [-1087566373198, 2396323600], [-815710095010, 9839629901], [-539942256780, -3007418460], [-4011160910, 7165853224], [837773213910, 11808913608], [49207714550, 19566983101], [-478578381952, 9225535250], [-31531373950, 5843076732], [948190703978, -10177242200], [-869948070880, 14688444040], [1115609248590, -10006304833], [-323454626430, 7865787012], [-572999647990, -1435873451], [421220373910, 31173203120], [39069646470, 29915482348], [630272747910, 21069820647], [199058973740, 12601965580], [-394024926790, -8534465376], [-584004940450, 1764739768], [-1730716299770, 6571574801], [550744083630, 17154213660], [2347387277608, -1224031350], [277764299800, 12589945400]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_320_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_320_8_a_l();".
// 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_320_8_a_l(:prec:=2)
    chi := MakeCharacter_320_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_320_8_a_l();".
// 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_320_8_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-4764, 20, 1]>],Snew);
    return Vf;
end function;