
// Make newform 320.8.a.g in Magma, downloaded from the LMFDB on 26 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_g();".
// 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_g();".
// 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], [36], [-125], [776], [124], [13082], [-15950], [20516], [-29224], [221482], [-109760], [-73422], [12762], [-290548], [1269152], [395778], [-421492], [2122250], [3132868], [-5376552], [4985466], [3867504], [6190196], [1124394], [9968098], [-425166], [7062088], [-18218580], [-22786886], [-700398], [36986832], [48604212], [-24515206], [21494364], [-15623902], [78303752], [65268842], [10784516], [39006504], [33925754], [144957956], [-139247102], [-24294560], [104825218], [205566226], [45632888], [11908996], [-168667888], [105791076], [348457394], [-221827878], [-289900464], [-86383342], [-284765460], [-84553470], [-65727000], [-281942566], [309939984], [325763746], [-296309782], [-500091908], [-107287886], [-806445004], [36096424], [-531349174], [-11841846], [374592252], [166535602], [-331437796], [4294122], [-49000670], [-1144316712], [558046880], [889486850], [-240166900], [-45487248], [-734802030], [-823609702], [384193266], [-1970056214], [-2667545868], [763075122], [-670874384], [-1383620590], [1863026824], [357996252], [-2316966846], [-2215989062], [-2520275622], [1534927008], [1530457364], [3068703968], [-3089467544], [1558511964], [-226641404], [-993457608], [2417729674], [6432949370], [-2455521940], [-3815658838], [-1114394588], [-3644775046], [1316677204], [1150778698], [833459180], [-1449978814], [6304726476], [-5955264462], [-3729318360], [5663257258], [5423760240], [2550526770], [-6541319334], [11708296444], [1853402920], [-9843127806], [-6739349916], [8261802696], [-2558333542], [-8906332956], [5575912866], [3928123938], [12539333746], [-2720468724], [6858869284], [-1761677302], [2497448722], [-8335720336], [19942823864], [-16302000342], [16317774132], [-14975715000], [-8725376016], [-4692606206], [-20282526198], [-19663192958], [12332523090], [8924561236], [-1077366486], [24033882], [24561767836], [-19693639742], [-26245995464], [-26684051844], [-6665857270], [19313143096], [-23835000926], [22801263786], [22733307436], [-1045410864], [20954262458], [8442703890], [-19617368300], [-10697871976], [31709907084], [30020331728], [-11776143256], [18839468642], [-2456665190], [-31076871494], [18216148660], [-39030516918], [12295928520], [-444806404], [15783254386], [-24551605608], [45639266048], [-41803591374], [-55824992494], [20861112002], [20706036620], [-32817658870], [-52286178344], [-1474208710], [23161295216], [46368815466], [-9833512372], [-15964519822], [8150632648], [37193346554], [47118343376], [31218088692], [-64535376494], [36180530042], [-10702795808], [4571526050], [20014867882], [-8581465532], [-47732632678], [20132240480], [-14558592766], [18300285228], [65240620036], [33029981546], [79718062564], [-8601059174], [-27375647790], [-8211961782], [55544691778], [-101891088920], [56202922458], [126171422416], [-22304259806], [67076853282], [58681780284], [-25950062518], [-103693653248], [-111486733340], [-32303195910], [-61561050308], [-42779666126], [-38458161502], [152489469272], [-49480161636], [-19998649000], [131541395418], [71617891744], [121603520050], [-160049340168], [-36074691350], [-17402681486], [8972525320], [71341667330], [-20590843872], [69548332116], [-135531795550], [-102520519382], [-100056236576], [-62224605208], [-106609458340], [49287007802], [-82403996220], [-52294199200], [57357710522], [-174037537812], [21784018176], [18722500530], [-224550970590], [-43928363540], [-66178522248], [10635796756], [-127650493204], [-22704008408], [101946062234], [-30799502606], [79419559336], [-113064747344], [6634449812], [-129931888900], [285447729088], [-12455820726], [183191552450], [87279941640], [164622496442], [213985342106], [-191042293020], [258466073890], [-171453822180], [-29589657102], [-1271145078], [36343805872], [-313799909116], [163639143762], [-27933419414], [285110280994], [115782630452], [-8646233030], [-187492200630], [284679042012], [-147391662638], [-176884482086], [205228751636], [-253801111446], [438924559136], [354977662226], [-54082544968], [431687098876], [-309427864310], [-444113024134], [-196674721212], [258348072720], [234128662200], [-447717051176], [-246169958254], [278138660300], [-222299834608], [-460018566286], [143386289442], [362361639720], [-488440783710], [40426501306], [148251027636], [-165578815158], [-123944731524], [176341906394], [404800401642], [-70214321728], [367741090626], [162178226764], [176755094916], [346622288442], [-684748446822], [360911743856], [424546054580], [163371938892], [-220819744286], [-467972656404], [348276799226], [-679797575736], [-296736172526], [-194774165152], [123596787426], [490006558434], [-248505203644], [-434406095192], [462207396826], [-271580358716], [171721081632], [318388856770], [-300163896526], [-220252410044], [-706265621206], [-87982675926], [-132148928624], [129272421914], [-909409211502], [578669996180], [304502752060], [-279289933520], [885807973362], [244185091066], [-825763074806], [-232206811904], [-484713956252], [-570899163844], [-604411016292], [315587504170], [-564955407198], [-59108419430], [-239376973920], [-413407424126], [-1104098974710], [51991976338], [-164041698280], [-967166171030], [8774551732], [714761651762], [-1115280249748], [-811830975312], [-471391723134], [-957683588236], [758840237754], [391258843930], [140673645536], [-393356378846], [822448398314], [349396352736], [401625972124], [-622002299182], [975375107128], [594270568402], [422245664762], [311318651392], [-334150988052], [1078263154788], [138130639258], [-528103068102], [-46350685528], [-59256821590], [102071180052], [-417156835460], [-1035445221248], [493221342594], [415048189608], [-701867601398], [673270859556], [1034390025664], [1494433373666], [-1573290686382], [-1362312662326], [264720938570], [921364271930], [613300268856], [1629406512546], [698378714868], [-145339698424], [1589279618608], [634580065410], [-1560300720612], [-1355134534192], [-1355193661310], [-997242164718], [473951784924], [5792023508], [1027936748680], [-421452643606], [-516249732448], [1116794620122], [1737957118876], [-339373516350], [811662638346], [-1423949207550], [381846884416], [1746912644778], [-221351326734], [1269400162872], [-212949541894], [-1967066012526], [-2054772722668], [2063015728596], [263524053490], [1161029783586], [-239156818948], [25723227860], [-1546477460582], [1721805187770], [1809420810176], [-2032934818040], [-1601551773582], [-1505417959464], [2372565176874], [-303451781326], [1207852581344], [1956803012428], [410774628858], [-2024454398118], [-826168795788], [2060656539882], [-1439856620468], [190669664392]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-36, 1]>],Snew);
    return Vf;
end function;