
// Make newform 320.6.a.z in Magma, downloaded from the LMFDB on 19 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_z();".
// 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_z();".
// 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 := [-367, -376, -100, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-364, -190, -4, 2], [-3932, -2406, -68, 26], [5824, 3104, 64, -32]];
    Rf_basisdens := [1, 1, 3, 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 := 6;
    raw_aps := [[0, 0, 0, 0], [0, -1, 0, 0], [-25, 0, 0, 0], [0, 6, -1, 0], [0, -15, -1, 0], [146, 0, 0, 3], [-190, 0, 0, -3], [0, -57, -9, 0], [0, -6, 1, 0], [42, 0, 0, 18], [0, -312, -10, 0], [-4934, 0, 0, 6], [11906, 0, 0, -21], [0, -99, -54, 0], [0, -408, -79, 0], [-4374, 0, 0, -15], [0, -411, 185, 0], [15506, 0, 0, 84], [0, 471, -170, 0], [0, 162, -112, 0], [29850, 0, 0, 9], [0, 1020, 88, 0], [0, -2997, -52, 0], [52330, 0, 0, -90], [-14782, 0, 0, -165], [117842, 0, 0, -90], [0, 414, -607, 0], [0, 4821, 32, 0], [45666, 0, 0, -222], [-122878, 0, 0, 54], [0, -4284, -691, 0], [0, 3411, -347, 0], [85722, 0, 0, 456], [0, 2697, -1699, 0], [-166982, 0, 0, 438], [0, 12606, 180, 0], [5730, 0, 0, 198], [0, 1239, 1948, 0], [0, -12954, -413, 0], [3602, 0, 0, 1854], [0, 8007, -709, 0], [333442, 0, 0, 456], [0, 30504, 1650, 0], [-683886, 0, 0, 657], [-529686, 0, 0, -1287], [0, -150, -1646, 0], [0, 29727, -3159, 0], [0, 1236, -4497, 0], [0, -1617, -490, 0], [-408062, 0, 0, 3132], [-94742, 0, 0, 4083], [0, 39636, -3016, 0], [41018, 0, 0, 4527], [0, -50139, 4211, 0], [-717902, 0, 0, -2406], [0, 43086, 1181, 0], [-1772958, 0, 0, 984], [0, -55308, 8766, 0], [1264954, 0, 0, -2466], [452130, 0, 0, 1065], [0, -71871, -1938, 0], [-78278, 0, 0, 372], [0, 47835, 9658, 0], [0, -15930, -7840, 0], [-1632294, 0, 0, 3090], [-163086, 0, 0, 3639], [0, 58569, -3941, 0], [-13230, 0, 0, 5958], [0, 79353, -7668, 0], [307242, 0, 0, 2328], [-832158, 0, 0, 10302], [0, 111258, 5042, 0], [0, 93984, 9957, 0], [2256794, 0, 0, 6282], [0, -121923, -3835, 0], [0, 135948, 10135, 0], [-1197846, 0, 0, -11760], [627634, 0, 0, -8757], [5050562, 0, 0, 2160], [2664578, 0, 0, -9999], [0, 176859, -2489, 0], [3016906, 0, 0, -6666], [0, -165828, 9550, 0], [-821006, 0, 0, -9225], [0, 30318, -26938, 0], [0, 84441, 1034, 0], [1762106, 0, 0, 3315], [4158602, 0, 0, 1860], [-1774422, 0, 0, 12414], [0, -266088, -1485, 0], [0, 35907, -17986, 0], [0, 328440, -3804, 0], [0, -165330, -10117, 0], [0, -48591, 39055, 0], [0, -125865, -25785, 0], [0, -247998, -915, 0], [-2793142, 0, 0, -22788], [3054634, 0, 0, -27216], [0, 450213, 3570, 0], [5717626, 0, 0, 8586], [0, -108081, 30078, 0], [-5950142, 0, 0, -426], [0, -373821, -24356, 0], [-5332190, 0, 0, 6861], [0, 352293, -55489, 0], [-1355342, 0, 0, 20364], [0, 491229, 8580, 0], [-2781102, 0, 0, 6156], [0, -501570, -43142, 0], [7187906, 0, 0, 16989], [0, -488460, 39197, 0], [-3821686, 0, 0, 8235], [-4847894, 0, 0, 10131], [0, -304695, 21577, 0], [0, 201606, -53700, 0], [1367530, 0, 0, 42375], [0, 20319, -71884, 0], [0, -472554, -6413, 0], [-17493950, 0, 0, -6879], [0, 81183, 195, 0], [-3585766, 0, 0, -12444], [-4422334, 0, 0, -29067], [-5977910, 0, 0, -813], [0, 89325, 39010, 0], [0, -254457, 88141, 0], [-2818414, 0, 0, 22794], [-2971262, 0, 0, -17718], [0, 206220, 66032, 0], [0, -738918, -58053, 0], [6524066, 0, 0, 14820], [0, -499797, 90199, 0], [0, 853446, -32023, 0], [0, -103164, -32070, 0], [-1766726, 0, 0, -39096], [-9408646, 0, 0, -45312], [13157394, 0, 0, 12846], [-7975830, 0, 0, -16071], [0, -627021, 66774, 0], [-9576846, 0, 0, -56871], [3628746, 0, 0, 43584], [0, 346809, 127367, 0], [3171130, 0, 0, 4470], [0, -428574, 155169, 0], [0, 675441, 51724, 0], [15291794, 0, 0, -36588], [0, -378606, -123314, 0], [10643738, 0, 0, 14001], [-23904534, 0, 0, 14622], [0, -1185891, 6009, 0], [0, 190620, 40515, 0], [3889298, 0, 0, -69420], [-4354614, 0, 0, -14631], [0, 370659, 41540, 0], [0, 1083522, -6949, 0], [0, 136749, 19380, 0], [0, 596196, -3694, 0], [0, 691662, 116418, 0], [-8784070, 0, 0, 83379], [-28287254, 0, 0, 15201], [35957770, 0, 0, 27468], [0, 623307, -24966, 0], [-7426854, 0, 0, 117540], [0, 66174, 59463, 0], [0, -1724055, -26365, 0], [14209170, 0, 0, 4353], [0, 1168434, -86759, 0], [0, 576768, -121866, 0], [20787514, 0, 0, -78261], [44839106, 0, 0, 9954], [32363514, 0, 0, 28695], [0, 615213, 58885, 0], [736410, 0, 0, 71508], [0, 895770, -249100, 0], [5750266, 0, 0, 37323], [0, 1349412, 12380, 0], [22745898, 0, 0, 31842], [0, 1458093, -47985, 0], [-7837870, 0, 0, -35532], [0, -352146, -172827, 0], [-15246014, 0, 0, -60240], [0, 1703028, -87015, 0], [0, -1980189, -206987, 0], [-2452966, 0, 0, 56967], [-57486438, 0, 0, -17379], [0, 1027608, 152031, 0], [-27539790, 0, 0, 118110], [8054930, 0, 0, 71262], [0, -753465, -145668, 0], [9741106, 0, 0, -167955], [0, 77592, 177214, 0], [-21678862, 0, 0, -57672], [0, 615477, -136954, 0], [0, 1692831, -178747, 0], [-11418510, 0, 0, -11100], [0, -1278657, 331706, 0], [-24984438, 0, 0, -92931], [58417034, 0, 0, 19581], [-12361198, 0, 0, -166041], [-47732030, 0, 0, -114252], [0, -575754, 311145, 0], [22521850, 0, 0, -96810], [0, 515148, 297390, 0], [23972938, 0, 0, -30885], [-53177438, 0, 0, 133488], [0, 204153, -269899, 0], [-25205790, 0, 0, 152028], [0, 19560, -154200, 0], [0, 2197119, -380252, 0], [7027482, 0, 0, 31278], [0, 183561, 192451, 0], [16522146, 0, 0, -162189], [-7847334, 0, 0, -225186], [0, 358290, 93433, 0], [0, 3452217, -1480, 0], [0, -3003582, 2494, 0], [21550050, 0, 0, 232635], [0, -799392, -108591, 0], [-44039646, 0, 0, 186144], [0, 661074, 124919, 0], [18652354, 0, 0, 192465], [-79085302, 0, 0, -13668], [0, -2901570, -460742, 0], [-75351598, 0, 0, -90282], [0, 4126224, 343863, 0], [0, -4398669, 19022, 0], [-11195078, 0, 0, -381048], [49967274, 0, 0, -278985], [0, -3744672, 90280, 0], [0, -2250282, 338271, 0], [0, 1285329, 64947, 0], [19328786, 0, 0, -66807], [0, -3934089, -496585, 0], [0, 2571096, 10066, 0], [22350354, 0, 0, 38961], [0, -2522283, -339514, 0], [0, 843576, 143417, 0], [-19882262, 0, 0, 298983], [-58796694, 0, 0, -71625], [0, 3418893, -148899, 0], [0, 4642482, -268220, 0], [0, 5543379, 152388, 0], [0, -1562427, -124413, 0], [0, -5560242, -175487, 0], [76880890, 0, 0, -26760], [87420498, 0, 0, -222954], [0, 2878134, 383846, 0], [0, -207684, -538307, 0], [0, 4031379, -164383, 0], [0, -3448935, -68451, 0], [0, -666720, 173827, 0], [12390146, 0, 0, 345111], [-88649406, 0, 0, -350712], [0, -2734938, -265933, 0], [1131874, 0, 0, 198585], [-92806094, 0, 0, 4980], [0, 3850119, 296767, 0], [-54494430, 0, 0, -217098], [0, -427095, -91524, 0], [-104439318, 0, 0, -289854], [-100255718, 0, 0, 347880], [0, 2475684, -430741, 0], [0, -1391865, -715938, 0], [1238210, 0, 0, -122220], [-33335342, 0, 0, 460836], [-38815502, 0, 0, 28539], [0, -1210773, 10779, 0], [-52471846, 0, 0, -210204], [116593962, 0, 0, -287004], [0, -5391927, -334614, 0], [-8169606, 0, 0, 332610], [-58748822, 0, 0, -181320], [0, -6798141, -255410, 0], [-116158150, 0, 0, 196791], [0, 2234496, -221680, 0], [11883202, 0, 0, -274020], [0, -2812614, -244347, 0], [0, -87663, 239184, 0], [163997258, 0, 0, 260082], [30160498, 0, 0, 39837], [0, 5380551, -556967, 0], [0, -7722468, 532835, 0], [0, 2552106, 55060, 0], [0, -7204662, 904507, 0], [-109802894, 0, 0, 572532], [0, 9807405, 514724, 0], [0, -6219156, -417110, 0], [-165938878, 0, 0, 415689], [10371930, 0, 0, 183807], [0, 1387950, -996294, 0], [-9105878, 0, 0, 402987], [29333282, 0, 0, -394842], [0, -4350117, 840702, 0], [73096490, 0, 0, -511761], [0, -8188887, -490769, 0], [89303538, 0, 0, 685908], [125026354, 0, 0, 306210], [0, 2935824, -1249970, 0], [-192434518, 0, 0, 113352], [0, 3384117, -976083, 0], [0, -4208361, 819282, 0], [-256976998, 0, 0, -70008], [-145451694, 0, 0, 516642], [0, -6928044, 1163384, 0], [0, 359403, 60152, 0], [0, 5675613, -364941, 0], [-94466078, 0, 0, 238221], [0, -2707323, -1172996, 0], [-179171142, 0, 0, 127842], [0, 2255598, 1195934, 0], [-187586214, 0, 0, -125862], [0, 10130352, -61293, 0], [-93734126, 0, 0, 29496], [123777810, 0, 0, 99132], [0, 4204647, -465032, 0], [0, 9166950, -1110637, 0], [-205669702, 0, 0, -316638], [0, -5472753, 769431, 0], [0, -6871584, 1182814, 0], [-101440398, 0, 0, 418554], [351494458, 0, 0, 169011], [0, -8321841, -11571, 0], [54624362, 0, 0, 356076], [117660498, 0, 0, -244668], [0, -30612, 78159, 0], [-5795206, 0, 0, -185610], [160655450, 0, 0, -732765], [0, 5227923, 969579, 0], [0, 2300577, -866182, 0], [0, -3953100, 1687517, 0], [28507770, 0, 0, -878409], [-152734142, 0, 0, 519222], [-162243582, 0, 0, -707580], [0, -10618080, 223116, 0], [0, 13341951, 255040, 0], [0, 2068953, 879335, 0], [0, -2413911, -875148, 0], [183560562, 0, 0, -467778], [-125100110, 0, 0, -675624], [194954098, 0, 0, 138777], [0, -8366424, 704781, 0], [-184274806, 0, 0, 389640], [-19831942, 0, 0, 386784], [-126594102, 0, 0, 310998], [0, 12945018, -124232, 0], [160495314, 0, 0, 604710], [0, 612219, -1932117, 0], [-70546390, 0, 0, 211860], [0, -11588907, 449352, 0], [0, -21037452, -1202534, 0], [265226970, 0, 0, -638343], [0, 1331451, 102789, 0], [-348513206, 0, 0, 495378], [215011554, 0, 0, -463944], [0, 488784, -407681, 0], [-375308142, 0, 0, -99348], [175512234, 0, 0, 404145], [0, -8799360, 178420, 0], [0, 13209441, 429099, 0], [86363954, 0, 0, -570591], [0, 1306122, -514699, 0], [-114441926, 0, 0, -927981], [-162267718, 0, 0, -40704], [0, 8108232, -2532011, 0], [0, -17442267, -1088759, 0], [0, -17070561, 307010, 0], [-155171670, 0, 0, -944559], [-296854062, 0, 0, 149349], [0, 918270, 802421, 0], [-389361550, 0, 0, -594345], [0, 10747587, 669261, 0], [0, -10786239, -223023, 0], [0, -7946208, 2113819, 0], [19571290, 0, 0, 285126], [0, -16872138, -336468, 0], [359571330, 0, 0, 476127], [0, 14544663, 2044551, 0], [0, -780000, 1221302, 0], [-265988286, 0, 0, -969960], [-395867766, 0, 0, -837033], [-195805974, 0, 0, -369438], [299453850, 0, 0, 430068], [-90759046, 0, 0, 100410], [0, 8455746, 1529067, 0], [1693506, 0, 0, 1710192], [0, 10712427, -3135141, 0], [0, 9726750, 444205, 0], [0, -3004716, -240986, 0], [-278982998, 0, 0, 926790], [0, -13902711, 2063106, 0], [0, -8821428, 311997, 0], [-181577526, 0, 0, -1192413], [-91898230, 0, 0, 45546], [0, 10316985, -2710059, 0], [0, 23841123, -321634, 0], [0, -11386266, -1393596, 0], [233605450, 0, 0, -306576], [0, 9224856, 715740, 0], [-54224694, 0, 0, -302856], [0, -2393751, -1663809, 0], [256218618, 0, 0, 57792], [71076274, 0, 0, 176790], [286819570, 0, 0, -1034289], [0, -15783720, 753725, 0], [-106188342, 0, 0, 229440], [148890474, 0, 0, -1614540], [0, 25941738, 554952, 0], [367967522, 0, 0, 574461], [-339630910, 0, 0, 279228], [0, -20961597, 1604772, 0], [0, -14566389, 2409823, 0], [237908914, 0, 0, 112050], [-248434614, 0, 0, 923826], [0, 10152513, 694142, 0], [0, -1094181, -1423459, 0], [-186233958, 0, 0, -876159], [-307248342, 0, 0, -840786], [0, 29363832, 886472, 0], [0, -228594, 1251235, 0], [-590162222, 0, 0, -247845], [0, 9261042, -1199643, 0], [153689234, 0, 0, -1291188], [550715754, 0, 0, 939663], [0, -18246648, 2703209, 0], [0, 11501349, -1551231, 0], [262866026, 0, 0, 2140740], [-127566158, 0, 0, -419274], [0, -13997205, -2829336, 0], [-81546702, 0, 0, -2330979], [0, 10286733, -2624089, 0], [0, 191334, 582014, 0]];
    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_z();".
// 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_z(:prec:=4)
    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_z();".
// 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_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![83520, 0, -848, 0, 1]>],Snew);
    return Vf;
end function;