
// Make newform 320.8.a.c in Magma, downloaded from the LMFDB on 07 March 2026.
// 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_c();".
// 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_c();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-28], [-125], [104], [5148], [8602], [20274], [-45500], [-72072], [-231510], [-80128], [-104654], [584922], [795532], [425664], [-1500798], [-246420], [-893942], [2336836], [-203688], [-3805702], [5053040], [45492], [980010], [-5247646], [15380658], [3256808], [14832876], [7032250], [14607378], [-15166096], [24598548], [35172474], [44713660], [-17334750], [59238152], [-27394454], [88538692], [-28530936], [104350842], [-100761180], [-35684222], [52789152], [-32089342], [-167463534], [161770040], [-178418972], [126952688], [157656036], [338259250], [-35638182], [216044880], [384299282], [236430348], [-23783166], [-79896312], [-233546790], [-279281968], [-163824734], [128061162], [269378812], [155781042], [487125556], [288891432], [-409452982], [269274186], [-405515492], [-383012686], [-1175743524], [-288404630], [765131298], [-525903720], [893570624], [813328642], [1020946540], [-914342832], [-223943790], [-1807571174], [-1635687438], [2273809130], [-404353260], [-8372942], [-277412688], [878768018], [896006600], [38306652], [755714370], [2224068794], [-1195043622], [-3834314752], [1645542036], [-780830880], [4798034504], [1416435708], [4181281060], [2852218968], [-851998710], [2864773242], [-2868162068], [-271353302], [-3765956444], [1237886586], [3721923732], [3891176010], [7436845708], [-5382237886], [4921340556], [-7302052302], [-256041240], [-3575071318], [6273242384], [8708051122], [392214234], [63917020], [5265471272], [-2370744318], [-9352459868], [9025975464], [-6742029798], [5500263300], [3208435618], [6248209058], [8324687346], [-9993225588], [-1549019132], [-12771150582], [13441075090], [8537082480], [-10716519016], [14446458922], [-4705320620], [-17088288792], [20883551792], [5699588866], [-3006097398], [-11166855550], [-16721606958], [-4201025324], [-8804919894], [7270571610], [-3533837252], [27687484098], [11683062488], [-2455259844], [-4712943350], [-27705776520], [9593177122], [20052412074], [1403204620], [-35051758032], [-18788111174], [7290399762], [-38399432108], [-11725568136], [-5311833524], [18458521872], [-2590353880], [1644374370], [-41285786086], [22263123258], [-5661379404], [4126399818], [16895090984], [2006382108], [-3752330766], [-28279628232], [-14382818368], [17453883826], [16646765330], [7161110082], [38608063980], [38568494218], [19602353112], [11782334138], [-105629200], [-24491550870], [44964972268], [-4437722382], [36589114088], [71719330810], [54010391024], [-70562737452], [-24763605998], [-77862624006], [-47379085632], [8038831650], [-12453082454], [43325309572], [32024951450], [3658117152], [-6221082622], [20998693932], [103642524388], [867391338], [-44825520924], [-559486182], [-12573967918], [-74064932918], [25612466754], [-101465041272], [28372124250], [25738604432], [-21244234334], [65246772770], [-55703340900], [61452197706], [76766063360], [-131301268188], [-126912194310], [50022688348], [93599685554], [-74907965022], [94766661368], [104483165916], [-20980566120], [23474448602], [65656051904], [-111185147598], [81148714584], [68169176682], [61745661298], [-123833218360], [94820735490], [-17756818432], [-172830864684], [-47807658590], [133816300458], [123807782880], [-203219093176], [-193346845572], [229676052922], [-125302005020], [-152985878368], [-205562713158], [106769989612], [-184288187616], [-203471141710], [-3527020638], [-219686811060], [-66368801928], [174992794452], [-160816262132], [119827250888], [157690352410], [-46442987022], [-262669030680], [78104868944], [-88658803212], [164928232540], [-262308502752], [67625201866], [77337496002], [7858564584], [-128512554310], [-278611670118], [31390309380], [-33476893022], [-10957856804], [214386064626], [-367784360566], [312569427728], [-233365115004], [-251504990510], [77964312682], [-29671480926], [55739983060], [-318332533830], [-4265572278], [270160624732], [-145966840878], [206773439578], [-120916188524], [-239776235542], [193385207840], [-157703256046], [406862803928], [-95083897284], [-157727199350], [-100594275718], [-243022554972], [353518612848], [-77107380808], [133928752824], [49368090898], [-173812501364], [-321816044208], [108534284018], [226012790946], [254904018920], [-99751022430], [-216872318022], [124510947636], [244717896138], [-143483564772], [248510818522], [-12935372310], [45581370752], [-622433908158], [-102288304980], [-32884604], [443678890298], [-316820178534], [-256688759440], [665732594292], [-25528397972], [331913834594], [82659217836], [218784543610], [453548595720], [434434246162], [99340164288], [-605815574430], [744528824802], [-313980148988], [128509987464], [526673525210], [-363394921500], [399015017952], [-506189957182], [-747840423630], [714674213668], [-454627660246], [415458057258], [-438985965712], [852920415258], [-782621570158], [-346335973580], [-866547287108], [235120296144], [-51455964558], [-402226823942], [-645922338294], [-223887610240], [96794224932], [326094878428], [-220766007204], [716273429290], [-125017522782], [699030800282], [-272940508096], [644016410242], [1083568008714], [190511578770], [-690410288488], [61290603882], [-502149360300], [-404911094222], [393676357036], [-269913804048], [293454244866], [388519043668], [-49643352646], [442693933338], [-235642814272], [-802713684830], [-199428698262], [1111878365280], [-44301781572], [-384571118766], [-718261937832], [-265694900654], [-1070675342598], [-16897566816], [1240134387660], [553508261476], [148453251098], [-751941269574], [-336475325752], [1344178743722], [242590268148], [-32991864740], [1285086529248], [162050700930], [-93046398808], [-134185259894], [-256875891900], [278622728832], [989791044578], [-1423601819310], [-1594514305846], [-527836808502], [1123179541818], [626011600664], [1169251882914], [443043539860], [-777463770072], [1896553817072], [1771018753666], [1043156229532], [1816019032944], [896566497410], [-876986340078], [186347431740], [-789063519404], [1081995455112], [244235151338], [-539515210720], [1090278234330], [1288498140988], [-382755381822], [-482373818870], [1008466984578], [-1161741473056], [-2163087892566], [-1660801494030], [-1382563304008], [-290681022854], [1233216568722], [764389739092], [1492464348660], [325181485298], [1915513306146], [-701366246148], [-1120224948812], [-105875734246], [2157265740858], [810002320320], [699439056104], [-513501425166], [-1634861542152], [-457282432470], [-1164346939214], [766811111424], [1829355613740], [-560300962822], [1879977267546], [-1544338969548], [1702654035690], [-1857090488852], [-106615427640]];
    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_c();".
// 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_c(:prec:=1)
    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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![28, 1]>],Snew);
    return Vf;
end function;