
// Make newform 320.4.a.r 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_4_a_r();".
// 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_4_a_r();".
// 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
        poly := [-3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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 := 4;
    raw_aps := [[0, 0], [0, -1], [5, 0], [0, 1], [0, -6], [-34, 0], [114, 0], [0, 0], [0, -29], [26, 0], [0, 14], [150, 0], [342, 0], [0, 63], [0, 81], [262, 0], [0, 68], [262, 0], [0, 69], [0, -146], [682, 0], [0, -28], [0, -21], [-630, 0], [-966, 0], [-1638, 0], [0, 95], [0, 85], [342, 0], [2106, 0], [0, 61], [0, 246], [1618, 0], [0, 348], [-1010, 0], [0, -2], [-1794, 0], [0, 275], [0, 105], [-2834, 0], [0, -132], [1466, 0], [0, 482], [-46, 0], [-1122, 0], [0, 416], [0, -58], [0, -353], [0, -703], [6194, 0], [4290, 0], [0, -732], [-3074, 0], [0, -286], [-3718, 0], [0, -977], [-6058, 0], [0, 722], [2990, 0], [2710, 0], [0, -637], [3750, 0], [0, -611], [0, 410], [5642, 0], [-4650, 0], [0, 766], [9266, 0], [0, 113], [-7494, 0], [-6270, 0], [0, -96], [0, 297], [2574, 0], [0, 1904], [0, 583], [-5314, 0], [8638, 0], [2802, 0], [-82, 0], [0, -148], [5742, 0], [0, -1974], [7098, 0], [0, 64], [0, -841], [-11706, 0], [5066, 0], [594, 0], [0, 67], [0, -315], [0, 564], [0, 1549], [0, -638], [0, -40], [0, -2553], [8714, 0], [-11830, 0], [0, 1243], [15490, 0], [0, 1585], [23862, 0], [0, 1007], [-9074, 0], [0, -1090], [4762, 0], [0, -2979], [11954, 0], [0, 1492], [17862, 0], [0, 1041], [-11522, 0], [8290, 0], [0, -3352], [0, 1718], [6750, 0], [0, -3249], [0, 1205], [-22282, 0], [0, 2196], [11758, 0], [11866, 0], [26574, 0], [0, -1905], [0, 3130], [7062, 0], [1554, 0], [0, 4308], [0, -3391], [-15058, 0], [0, 1652], [0, 2395], [0, 2478], [-35410, 0], [3386, 0], [11522, 0], [14382, 0], [0, 113], [14550, 0], [-37622, 0], [0, -46], [-18690, 0], [0, 2339], [0, 5441], [3718, 0], [0, -1988], [-26786, 0], [19682, 0], [0, 4604], [0, 1415], [-41986, 0], [38142, 0], [0, -5441], [0, -5759], [0, -599], [0, 6894], [0, -724], [-17546, 0], [-11390, 0], [-41838, 0], [0, 4885], [28522, 0], [0, -635], [0, -3090], [-2214, 0], [0, -3449], [0, -6442], [-57930, 0], [28658, 0], [31278, 0], [0, -7824], [-19598, 0], [0, -8110], [-10534, 0], [0, 7184], [23194, 0], [0, -5906], [44922, 0], [0, 6515], [-15626, 0], [0, 1937], [0, -3714], [3014, 0], [68298, 0], [0, -1145], [5970, 0], [55494, 0], [0, 2239], [43374, 0], [0, -8850], [-31590, 0], [0, -601], [0, 1586], [-21690, 0], [0, 3945], [-494, 0], [-24002, 0], [31606, 0], [-21534, 0], [0, 3431], [11290, 0], [0, -6286], [-49786, 0], [7826, 0], [0, 1060], [40926, 0], [0, -1560], [0, -7465], [-13654, 0], [0, 3574], [31330, 0], [-48258, 0], [0, 7911], [0, -11067], [0, 12052], [-54490, 0], [0, -3891], [-44670, 0], [0, -5727], [-35042, 0], [-56994, 0], [0, -6308], [55506, 0], [0, 9515], [0, -5095], [-42770, 0], [26778, 0], [0, 1256], [0, 9445], [0, 9294], [-82274, 0], [0, 3392], [0, 1354], [39718, 0], [0, 4059], [0, -9195], [-410, 0], [71142, 0], [0, -14520], [0, 7706], [0, 7395], [0, -14], [0, -13981], [107610, 0], [-34446, 0], [0, -6968], [0, 8613], [0, -4046], [0, -6284], [0, 2259], [-16530, 0], [-6894, 0], [0, -5891], [-93714, 0], [-26338, 0], [0, -11944], [40378, 0], [0, 473], [98238, 0], [-88534, 0], [0, 567], [0, 6761], [-100910, 0], [91414, 0], [49042, 0], [0, -760], [26602, 0], [-11254, 0], [0, -7225], [-96122, 0], [126178, 0], [0, 15861], [-13982, 0], [0, -15728], [-43654, 0], [0, -14173], [0, -10575], [126314, 0], [-48874, 0], [0, 7006], [0, 16047], [0, -11422], [0, 10653], [14634, 0], [0, -5323], [0, -1938], [-24494, 0], [143134, 0], [0, 10684], [-5850, 0], [-21946, 0], [0, 8553], [16202, 0], [0, -2870], [-6370, 0], [23046, 0], [0, -16258], [-63690, 0], [0, 11432], [0, 4997], [-15470, 0], [132542, 0], [0, -11412], [0, 11927], [0, 6898], [14538, 0], [0, 3105], [-79766, 0], [0, -8328], [-84874, 0], [0, 6151], [-15518, 0], [-147342, 0], [0, 15543], [0, -19631], [-42406, 0], [0, 16688], [0, -12058], [-15334, 0], [-157082, 0], [0, -24694], [-25822, 0], [47686, 0], [0, -13949], [-54542, 0], [-6450, 0], [0, -17048], [0, -3697], [0, 20241], [41158, 0], [87366, 0], [62894, 0], [0, -16036], [0, -24709], [0, 5354], [0, -13923], [150950, 0], [-163702, 0], [-23994, 0], [0, 8357], [57638, 0], [-78598, 0], [-194370, 0], [0, 22102], [-208602, 0], [0, -27560], [62270, 0], [0, -12447], [0, 1310], [-51906, 0], [0, -8698], [-188182, 0], [-34922, 0], [0, 6107], [64194, 0], [-223782, 0], [0, -8820], [0, 15622], [-10790, 0], [0, 939], [154150, 0], [154346, 0], [0, 15225], [0, -21180], [0, -18919], [59618, 0], [34222, 0], [0, -6793], [88390, 0], [0, -14778], [0, -22040], [0, 12595], [-218034, 0], [0, -1442], [-42226, 0], [0, -10840], [0, -258], [-82702, 0], [-70042, 0], [-25678, 0], [58962, 0], [22978, 0], [0, -37395], [220562, 0], [0, -21520], [0, 16395], [0, -5854], [-24154, 0], [0, 7031], [0, -12431], [-122362, 0], [-131842, 0], [0, 11644], [0, -21955], [0, -34434], [167282, 0], [0, 21892], [-41142, 0], [0, 23418], [-82674, 0], [227366, 0], [145538, 0], [0, -25975], [149234, 0], [9886, 0], [0, 16526], [134598, 0], [-153118, 0], [0, -6773], [0, 37524], [32578, 0], [117990, 0], [0, -21773], [0, -1482], [-59462, 0], [-12846, 0], [0, 17352], [0, -21471], [79514, 0], [0, -509], [9958, 0], [313278, 0], [0, 17185], [0, -21796], [133402, 0], [-99602, 0], [0, 31463], [144478, 0], [0, -6850], [0, -5736]];
    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_4_a_r();".
// 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_4_a_r(:prec:=2)
    chi := MakeCharacter_320_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_r();".
// 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_4_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-52, 0, 1]>,<7,R![-52, 0, 1]>],Snew);
    return Vf;
end function;