
// Make newform 320.6.a.g in Magma, downloaded from the LMFDB on 18 April 2024.
// 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_6_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_6_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)
    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+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 := 6;
    raw_aps := [[0], [-4], [-25], [-192], [-148], [-286], [-1678], [1060], [-2976], [3410], [2448], [-182], [-9398], [-1244], [12088], [-23846], [-20020], [-32302], [60972], [32648], [-38774], [33360], [16716], [101370], [-119038], [89898], [19504], [158292], [-36830], [11186], [-70552], [76452], [-144918], [112220], [-403750], [446648], [262258], [-154564], [-396672], [573474], [-594460], [107098], [-469552], [52706], [-455862], [-865000], [1105652], [-1121576], [-23348], [596010], [-485334], [48880], [-110798], [-1643748], [1306242], [-2128336], [1441090], [93248], [110298], [-192198], [-331884], [-2194806], [-2377508], [2373048], [-1429414], [-2124622], [3099852], [2400082], [1777412], [2148050], [-661854], [259320], [1499928], [2238074], [3159340], [-342216], [-88470], [5456738], [4046802], [-2712070], [3717460], [-3552502], [4062048], [7262866], [5410280], [-6515244], [-509950], [1220842], [4072098], [-2022936], [3250972], [3279360], [8531968], [1512652], [-6491900], [-8617696], [-2673230], [6185002], [-6894524], [-155502], [12654412], [7077858], [846636], [4960410], [8965052], [-2860798], [-6740268], [-1786094], [-4946200], [-4580998], [-7079992], [-5096086], [-13000278], [4844060], [-6227752], [1532802], [-17438244], [4254688], [-3010846], [-8114620], [-2473702], [5770626], [-16719702], [7145316], [-8783948], [16014098], [19135370], [-10293360], [19326448], [-5261966], [28294420], [-20986256], [18966848], [10825658], [19053402], [-15782590], [24404874], [33760732], [-21988462], [-29359670], [31770252], [2714298], [12586624], [-8723548], [10617810], [-16776520], [22018554], [31667642], [15806380], [14428664], [-247902], [41026802], [41801516], [21047568], [7483092], [6631648], [16897640], [-12865310], [10688682], [-28245502], [-17089188], [22225946], [-24155072], [-54831348], [-15661198], [16341984], [-13757552], [12909738], [16092530], [-36698086], [35286060], [-43109902], [31649448], [-1356534], [13485680], [12296250], [-6861348], [-3001302], [39109264], [-32754910], [-36317432], [-58193948], [38344394], [74449162], [-5107896], [79427770], [10241778], [-19462724], [20289290], [-75492752], [3479746], [18315236], [43944852], [-39919502], [-37109268], [-53495894], [47322802], [-84436686], [-49292478], [33663824], [-74165790], [387648], [-16594182], [-68481950], [-40927620], [-15491502], [29186560], [2365916], [-69569430], [-87914548], [81232562], [-64369702], [-13363296], [4441892], [21047640], [17766602], [67531448], [-17058798], [9262928], [84310674], [24095498], [-68214200], [-15524670], [106631624], [-57518948], [11322010], [-108138534], [47230880], [56629088], [77099052], [19937154], [-10991420], [-9019952], [-116813398], [64825316], [-69603432], [83468370], [68566394], [138055500], [103651848], [162317676], [26628252], [120612944], [35623650], [135452946], [-16468280], [57480328], [-136691548], [25244540], [-99509816], [179853938], [-14039998], [97211808], [-29493270], [-29988286], [-36802140], [90600698], [33259652], [-13283382], [209130842], [-152848936], [21268972], [150036490], [-134459406], [-38368638], [-17996300], [50629570], [-242612198], [-47425324], [-170244566], [-107929502], [129696412], [18985946], [-215626080], [-238269198], [-150269216], [-134443068], [-130512270], [-177176598], [-51639948], [-47413576], [-74568952], [-54513712], [-44326902], [156933972], [156553248], [119019826], [-120972102], [101257960], [53390370], [-68894302], [166172092], [69542586], [111601452], [13624834], [-218191950], [-81312752], [131350074], [5816940], [-88838068], [-16340694], [158270338], [-60722800], [-280782804], [83560252], [-232812478], [-41689548], [-339520190], [214495080], [119925354], [-95205336], [66376890], [-238699998], [-277229284], [-10863232], [-175808630], [212362500], [217022448], [-324881214], [330084690], [-80237548], [255874682], [16898098], [-413510056], [-16574454], [-66456398], [-129223660], [241978996], [74780808], [-203198486], [53766498], [40595218], [-202327520], [410092156], [323313452], [89127172], [-248858510], [127713826], [246006602], [389559768], [-43177606], [217929562], [355100970], [459250248], [-371362766], [-491914380], [-209147702], [-12798188], [-516097152], [-343843942], [373094052], [428905002], [199149698], [21571784], [338593530], [-454713894], [442894400], [-216622548], [-157044078], [-6505376], [4523018], [60076202], [134981688], [462356780], [-384934228], [276486826], [-50635902], [-258342096], [349683002], [525395652], [119969820], [-82665656], [276637050], [-219360552], [438734258], [-201920860], [-174069552], [226953506], [-652593870], [259940122], [427064498], [29961066], [49096688], [-485990558], [-354979020], [599768464], [-24736352], [-163052102], [487112916], [-584615832], [433202370], [574404394], [531772700], [-378364708], [-509266952], [301625786], [-232607360], [-38134710], [-310093748], [303832698], [-449603950], [485606946], [-113651272], [213035002], [-732423670], [389315048], [-205368062], [-242040398], [-313043604], [-509824140], [-587357934], [232686618], [-132104044], [-487490748], [582190442], [-446077502], [124228160], [-165742432], [-190009038], [575962304], [642721970], [551903978], [-359950152], [477747020], [-312330454], [841489858], [-292537364], [-93341190], [-189608548], [-468056600]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_320_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_320_6_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_6_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, 6));
    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_6_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_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![4, 1]>],Snew);
    return Vf;
end function;