
// Make newform 320.6.a.i in Magma, downloaded from the LMFDB on 25 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_i();".
// 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_i();".
// 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], [2], [25], [-62], [144], [654], [-1190], [-556], [2182], [1578], [9660], [3534], [7462], [7114], [-28294], [13046], [37092], [-39570], [56734], [45588], [11842], [94216], [31482], [-94054], [23714], [129674], [136846], [193190], [120046], [-152646], [107906], [233072], [356082], [-312204], [-27498], [-136908], [-406714], [13642], [-203438], [-127242], [94684], [517018], [-412300], [-771654], [190238], [132072], [-928704], [421494], [-991962], [266946], [960314], [-492696], [56078], [-1967920], [-971910], [-154770], [-1023714], [-1147756], [2496758], [1695398], [2123954], [-992722], [-487522], [-444116], [47242], [-694058], [-82168], [-727934], [-2022978], [-4408582], [1069650], [-32968], [3640810], [3173110], [-1604980], [1989254], [5164950], [-937586], [-5636574], [4061374], [976108], [1627062], [-4279004], [-3201950], [5092456], [5435514], [-2990074], [8017594], [-2584622], [6142606], [1592702], [863592], [-8207142], [-8933936], [-1119596], [3681774], [6734826], [441370], [11729970], [-744158], [3248006], [9944462], [-3893742], [-11195138], [844040], [-5133782], [-9761562], [966226], [-7900000], [10312598], [-9707670], [11056750], [8311738], [-11545124], [-8202620], [-5396946], [13389618], [6482538], [-14490714], [-6590804], [3252326], [3866546], [-1238562], [13137642], [12384104], [9789518], [-12225742], [-13505304], [11727122], [11651206], [12680828], [-197370], [-13328196], [3861222], [-8317558], [27635778], [-17884210], [-21569082], [10306022], [372378], [19479456], [469318], [17862182], [-9425602], [14862190], [-4711696], [-16268482], [-29266702], [33106164], [-15805178], [42683414], [-3573970], [16847090], [-8367918], [25723022], [34210828], [2440336], [13436118], [7965290], [-9080254], [32176910], [5338074], [37152170], [10986536], [-26505422], [-47572626], [32214908], [-38707242], [-36045646], [-52106466], [-34313140], [-10987550], [-2313364], [-28986110], [21243824], [-33858486], [-11676792], [48324378], [6925686], [7450846], [50149738], [-1368128], [57241862], [29749026], [-75064746], [17703730], [-34051874], [-83872334], [-53932322], [-7544820], [75283498], [-86169654], [69178136], [22181646], [-67226138], [-21116038], [23589070], [-83880394], [65823714], [-67758050], [-61063958], [-38542684], [-73009978], [57296978], [-6238604], [70066806], [-75916192], [36071330], [-44874150], [58497752], [-79104838], [26127718], [18871054], [-16353818], [-4138960], [94912918], [-39610958], [-131198510], [106550866], [-93365250], [-114894986], [-26786560], [136690770], [39763166], [129665558], [84626150], [-41763294], [106719936], [73258666], [-60444120], [-98680706], [113919940], [44764100], [163729942], [99582786], [134145378], [-54866810], [91926150], [148407020], [-24838628], [34014282], [64099216], [-116736906], [-94908614], [-12956702], [-46822536], [-9114062], [90173112], [-88778700], [-84959794], [60818462], [24198930], [14700730], [64131758], [-49370698], [-21049020], [17920010], [-20493490], [-167696346], [183377306], [208061734], [-143342858], [62773058], [73089982], [-47030518], [37465508], [-56594390], [-160867190], [-133176646], [165061534], [63618034], [-157420962], [-148106342], [-42731216], [-194792982], [-20649786], [52611918], [-100309830], [-40093434], [-130853472], [-29983530], [-220587620], [-100775318], [105592586], [-246538090], [-102363108], [-165614982], [-99039794], [138242800], [114571350], [-265023394], [162161718], [167126994], [-155813344], [180918038], [-245777762], [-193173428], [107594142], [-105435924], [97025038], [-70235246], [-140193626], [30838504], [122745810], [-257897808], [12795362], [231033118], [88419834], [-371986184], [-26103602], [333786806], [84522354], [166121954], [293274962], [180968354], [-206930006], [-292137484], [78058572], [-16328550], [-93235434], [-126963224], [-146996958], [135719694], [-31222818], [-161294462], [-150472482], [-190346620], [293978890], [263011530], [-111046106], [282242366], [225923782], [273672664], [-83294294], [204769376], [-216575066], [-282853890], [210873114], [-141336650], [196419330], [213299918], [15597450], [-474838138], [-376152460], [-62291170], [271424708], [20571862], [-81549874], [-467391332], [-114098082], [-28823456], [151350442], [-167809410], [-420664258], [-131371214], [-390765902], [-378114936], [214456024], [-74740526], [229411126], [-287471834], [-390603798], [207642186], [196348372], [-246985306], [-39508534], [357268974], [41981534], [243959510], [357610752], [-290238740], [349361614], [367452086], [-86987692], [397444766], [-216727356], [-72624756], [311004882], [-153760698], [-459301918], [-223442430], [-206762030], [-642524022], [-598005102], [-508913708], [-416328058], [-228840412], [-547857570], [-545599654], [-387242326], [-45708810], [570320294], [89177876], [199917614], [562578820], [-604676622], [28856968], [98236058], [-96402704], [-124383610], [218237054], [-101193030], [-568121622], [306561074], [177415734], [531972532], [176851478], [510972114], [-341527846], [-298019316], [529127250], [-146784642], [-788841646], [510007760], [467697554], [386812850], [718836384], [-150881470], [338229954], [-141435258], [-424834034], [-217350418], [62348922], [-833930828], [-728040854], [-197150634], [-780407086], [60494238], [752788712], [-194965752]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-2, 1]>],Snew);
    return Vf;
end function;