
// Make newform 320.6.a.f 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_f();".
// 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_f();".
// 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], [-6], [25], [-118], [-192], [-1106], [762], [2740], [1566], [-5910], [-6868], [5518], [-378], [2434], [13122], [9174], [34980], [9838], [-33722], [70212], [21986], [4520], [109074], [38490], [-1918], [-77622], [-46714], [1038], [-206930], [139386], [299882], [-7872], [-164238], [282100], [388950], [-97948], [3718], [43234], [186522], [374454], [-272100], [75418], [-356988], [-438694], [156798], [-162520], [181648], [-288274], [-1125522], [415810], [770586], [-595320], [273902], [-850752], [825402], [1364646], [113310], [-849628], [-438602], [-1456698], [120394], [2642094], [1447558], [-928068], [2295626], [-2736522], [-3818792], [-2210878], [2327238], [311290], [-3086574], [-3530760], [35762], [1715254], [3101740], [5319486], [-1161450], [-628562], [-2724318], [1780190], [-650580], [3540598], [-548748], [-1492414], [4862120], [1861554], [3737190], [-6482758], [-1509102], [8684006], [-6964122], [-5510520], [5518082], [1512768], [1930420], [6731046], [556650], [10111002], [7037194], [4231138], [-4440242], [9014478], [9812874], [13315230], [-9958952], [4503722], [-625842], [-2503854], [-756480], [-13856458], [11377202], [7001614], [7903002], [-4023620], [-10022668], [6373902], [-5004566], [-8719278], [1584774], [-12640980], [3615718], [11131346], [235518], [-20583006], [9548248], [-1293042], [21272050], [8317320], [-4367398], [4056454], [-768260], [6187806], [18169772], [-19349402], [-30199158], [21585410], [-3908946], [26508238], [-10794042], [-11144550], [11486608], [-30434682], [4097726], [17065158], [24761710], [31652880], [-28267106], [26086962], [33811060], [22281726], [34674838], [14260302], [37517674], [40765722], [35711638], [-21138948], [18599600], [44511030], [-21941878], [7777218], [-31719882], [-5602854], [-20353198], [23430648], [-43041198], [-47500314], [20923052], [-29633162], [33762290], [52045374], [-4833300], [25518178], [12907452], [47092706], [-33795280], [-33788790], [46590808], [-49505382], [-17971954], [-42585890], [35301362], [54443088], [-41526746], [15509442], [-19362354], [-7206030], [62773918], [-48502166], [-22644610], [-8918148], [51496106], [10319874], [47238088], [18784398], [-16954962], [-53922534], [-82445458], [49484374], [-9381918], [-18177834], [-33983190], [19241012], [-34901402], [66999890], [7232820], [-42271242], [59488160], [-114511206], [106004250], [7626088], [-97407718], [8569638], [35123846], [75097998], [-119447280], [-87537418], [28429082], [10674642], [-3074598], [-103772706], [26137078], [98917280], [-43338990], [-42033994], [73752798], [44057830], [-114037374], [-26305920], [-40565038], [111360888], [-4185506], [-36880220], [143290772], [-2848458], [-28983206], [-10830198], [-28413850], [48856614], [-129700020], [83924652], [147524514], [-88378112], [-52580914], [97773370], [-169894494], [114384120], [35630042], [4355688], [-54549260], [132732966], [46804798], [186730002], [118885602], [-95747890], [-76020426], [-39356700], [11696458], [-45045482], [-3559962], [-164816998], [20800286], [142661118], [111723970], [-96579266], [-174425238], [162426820], [-202741590], [21016842], [218346994], [94741854], [-233150222], [10570438], [-13959814], [-12863440], [-53488918], [65455646], [-180826602], [-155118470], [10399142], [5904048], [-59155314], [-219673108], [-149307438], [15570058], [-227238722], [73530252], [-154360294], [122996718], [-262708720], [224509110], [18283038], [-154097922], [86432946], [-283210032], [-107693546], [4017630], [115697852], [-71198946], [147377100], [-297782282], [-202502254], [-112341402], [31374920], [-14543286], [3372448], [-58584958], [-36752922], [-155948870], [85280760], [-129268466], [-267668754], [240758130], [-39973278], [345974794], [-67077078], [3558890], [53106900], [-166767108], [328200026], [124147830], [139161688], [285989282], [-123716082], [317436086], [158430786], [328377662], [160036900], [-251461886], [110653842], [179156934], [338611198], [250537158], [-185893960], [254352834], [-164896112], [302634318], [-72827330], [340794906], [-97194538], [-123252118], [-272153906], [340944522], [471712710], [244166372], [-12013986], [-499909020], [-153351722], [-100551722], [-73877748], [-325758402], [132378928], [-207367318], [-88681602], [373844246], [-151358030], [-331828014], [459427560], [120463848], [-123635598], [79629006], [-362516282], [466768362], [439421202], [98677140], [-53442962], [-253819414], [88777038], [-7733674], [-217174858], [-16583472], [337060300], [-519876954], [526174710], [480919172], [354960958], [71260260], [-567810948], [558089426], [348239910], [12648482], [242674818], [-136684014], [535179122], [285775122], [-414832460], [-472561314], [-100271308], [354775198], [-92875886], [349897842], [188181590], [-654524826], [-188560620], [-143095082], [-439934028], [-692791054], [-9153880], [-169813350], [-524406752], [548777478], [-165444290], [-234523494], [515304242], [364356402], [-734333130], [-623235868], [780364918], [-697765038], [-712860686], [-581521140], [-82711534], [130656318], [169010154], [405201568], [-663984718], [-29390862], [-490175520], [-611985718], [55741602], [-8762274], [640537230], [-702267122], [656474562], [71959860], [321952106], [234260118], [-219015606], [382102590], [-414421832], [-880978680]];
    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_f();".
// 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_f(: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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![6, 1]>],Snew);
    return Vf;
end function;