
// Make newform 1600.4.a.cu in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1600_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_1600_4_a_cu();".
// 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_1600_4_a_cu();".
// 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, 12, -8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [10, -18, 0, 2], [18, -28, 0, 4], [-36, 8, 8, 0]];
    Rf_basisdens := [1, 1, 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_1600_a();"
function MakeCharacter_1600_a()
    N := 1600;
    order := 1;
    char_gens := [1151, 901, 577];
    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_1600_a_Hecke(Kf)
    return MakeCharacter_1600_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, 0], [0, -1, 0, 0], [0, 0, 0, 0], [0, -1, 0, -1], [0, 0, 0, 2], [-52, 0, 2, 0], [0, 0, -8, 0], [0, -16, 0, 2], [0, -11, 0, -1], [78, 0, 16, 0], [0, 16, 0, 0], [-68, 0, -14, 0], [-24, 0, -13, 0], [0, -49, 0, -6], [0, -37, 0, -9], [-12, 0, 30, 0], [0, -48, 0, -10], [-264, 0, 27, 0], [0, -51, 0, 10], [0, -16, 0, 4], [360, 0, -44, 0], [0, -80, 0, -24], [0, -117, 0, 22], [-10, 0, 80, 0], [1136, 0, 0, 0], [442, 0, 80, 0], [0, -51, 0, 47], [0, 69, 0, 12], [424, 0, 101, 0], [16, 0, 56, 0], [0, -121, 0, 9], [0, 112, 0, -26], [744, 0, 236, 0], [0, 256, 0, 62], [1192, 0, -159, 0], [0, -128, 0, 60], [-700, 0, 78, 0], [0, 119, 0, 52], [0, 299, 0, -43], [236, 0, 186, 0], [0, -224, 0, -78], [2122, 0, 48, 0], [0, -32, 0, 0], [1872, 0, -112, 0], [-2532, 0, -22, 0], [0, 80, 0, -132], [0, 304, 0, 158], [0, 241, 0, -13], [0, -263, 0, -140], [742, 0, -16, 0], [-5176, 0, -28, 0], [0, 368, 0, -72], [-2872, 0, 31, 0], [0, 352, 0, -22], [-864, 0, -176, 0], [0, 441, 0, -91], [7368, 0, -67, 0], [0, -336, 0, 88], [2188, 0, 394, 0], [2440, 0, -325, 0], [0, 739, 0, 148], [1316, 0, 398, 0], [0, -195, 0, 278], [0, -960, 0, -20], [5608, 0, -180, 0], [6468, 0, -346, 0], [0, 208, 0, -158], [-5680, 0, -312, 0], [0, 1097, 0, -58], [878, 0, 176, 0], [576, 0, -432, 0], [0, -576, 0, -36], [0, -209, 0, 177], [-428, 0, -602, 0], [0, 416, 0, -330], [0, -1047, 0, 95], [-1944, 0, 265, 0], [-1612, 0, 1198, 0], [-1518, 0, -560, 0], [-488, 0, -123, 0], [0, 1472, 0, -118], [-6184, 0, 1127, 0], [0, -16, 0, -440], [-3008, 0, -520, 0], [0, -256, 0, 84], [0, -869, 0, -24], [-11016, 0, 25, 0], [904, 0, 1580, 0], [12098, 0, 272, 0], [0, -43, 0, 265], [0, -167, 0, 104], [0, 1280, 0, 112], [0, -265, 0, -197], [0, -1232, 0, 210], [0, 0, 0, -110], [0, 437, 0, -505], [-8178, 0, 784, 0], [634, 0, 1152, 0], [0, 243, 0, -120], [-2414, 0, 2288, 0], [0, 321, 0, -712], [8116, 0, 534, 0], [0, 1039, 0, 436], [6040, 0, -43, 0], [0, -1024, 0, -662], [10976, 0, 1344, 0], [0, 641, 0, 550], [10384, 0, 1784, 0], [0, -880, 0, -204], [-824, 0, -373, 0], [0, 835, 0, 47], [-13468, 0, -330, 0], [2872, 0, -1684, 0], [0, 720, 0, -466], [0, 3392, 0, -340], [-3640, 0, 1815, 0], [0, 699, 0, 234], [0, 879, 0, -153], [9260, 0, -766, 0], [0, -2496, 0, -190], [-7176, 0, -2297, 0], [19088, 0, -1248, 0], [-9540, 0, -278, 0], [0, 1815, 0, 510], [0, 16, 0, 398], [14616, 0, -253, 0], [-15098, 0, -2096, 0], [0, -4240, 0, 104], [0, 2863, 0, 747], [-23012, 0, 850, 0], [0, 1184, 0, 458], [0, -1839, 0, 833], [0, -2528, 0, 280], [-23892, 0, -1046, 0], [17274, 0, -496, 0], [-24754, 0, 512, 0], [-14780, 0, 1686, 0], [0, 2661, 0, 594], [708, 0, -426, 0], [-10586, 0, -512, 0], [0, 3808, 0, -334], [-8520, 0, 2135, 0], [0, 6061, 0, -629], [0, 609, 0, 314], [16136, 0, -1691, 0], [0, 832, 0, 1292], [1524, 0, -2466, 0], [-24168, 0, -28, 0], [0, -3248, 0, 358], [0, 1605, 0, 1165], [-8204, 0, -2010, 0], [-10904, 0, -833, 0], [0, 599, 0, 600], [0, -1497, 0, -809], [0, -2539, 0, -1300], [0, 3472, 0, 1368], [0, -2544, 0, -1004], [-4360, 0, -4887, 0], [14872, 0, 1996, 0], [24130, 0, -976, 0], [0, 3893, 0, -846], [-39672, 0, 940, 0], [0, -2949, 0, 853], [0, 880, 0, 1250], [-28320, 0, -72, 0], [0, 4209, 0, 1509], [0, 6336, 0, -528], [35548, 0, 2394, 0], [9534, 0, 3968, 0], [9652, 0, -1330, 0], [0, 864, 0, -170], [11250, 0, -4336, 0], [0, 5280, 0, -780], [31048, 0, -2668, 0], [0, 4256, 0, 600], [14342, 0, 2944, 0], [0, -5024, 0, 1210], [27450, 0, -176, 0], [0, -5411, 0, 567], [30184, 0, 2565, 0], [0, -4513, 0, 125], [0, -4528, 0, -1946], [-41468, 0, 678, 0], [-31656, 0, 1916, 0], [0, 333, 0, 589], [39670, 0, -2640, 0], [6180, 0, -4898, 0], [0, -805, 0, -782], [30424, 0, -355, 0], [0, -256, 0, -1888], [-14656, 0, 5392, 0], [0, 4627, 0, 2264], [0, 2192, 0, -226], [53720, 0, 915, 0], [0, -3843, 0, -214], [136, 0, -364, 0], [-53336, 0, -1617, 0], [-15844, 0, 7226, 0], [13280, 0, 688, 0], [0, -5739, 0, -1405], [8990, 0, -400, 0], [0, 1216, 0, 1640], [1516, 0, 5010, 0], [58638, 0, -1264, 0], [0, 3664, 0, 1422], [-5340, 0, -722, 0], [0, -3440, 0, 1040], [0, -4541, 0, -18], [-4362, 0, 6656, 0], [0, -7888, 0, 898], [22112, 0, -4424, 0], [16856, 0, 5087, 0], [0, 7905, 0, -3], [0, 713, 0, 630], [0, -7696, 0, -1172], [-3800, 0, 8355, 0], [0, 3287, 0, 669], [51474, 0, 2192, 0], [0, 931, 0, -1931], [2172, 0, -1030, 0], [-15752, 0, -1489, 0], [0, 0, 0, 2036], [28638, 0, -464, 0], [0, 5849, 0, -653], [0, -6411, 0, -2758], [35528, 0, 2969, 0], [-8328, 0, -4740, 0], [0, 4944, 0, -1440], [0, 7067, 0, -419], [0, 1648, 0, -2574], [-49652, 0, -1838, 0], [0, -4352, 0, -1390], [0, 8672, 0, 128], [42184, 0, 4243, 0], [0, 6047, 0, -406], [0, -4641, 0, 657], [8312, 0, -7199, 0], [-27532, 0, 430, 0], [0, -8016, 0, -1178], [0, -7456, 0, -1020], [0, 5219, 0, -2358], [0, 3456, 0, -1174], [0, -2727, 0, 1077], [7710, 0, -8720, 0], [-63856, 0, -5016, 0], [0, 6432, 0, 772], [0, -7321, 0, 833], [0, -10112, 0, 566], [0, -8240, 0, -1522], [0, -755, 0, 853], [2532, 0, -3914, 0], [75794, 0, -336, 0], [0, -1977, 0, 267], [-6984, 0, 9485, 0], [-10772, 0, -8310, 0], [0, -1808, 0, 1634], [52170, 0, 6736, 0], [0, 14225, 0, -694], [-11556, 0, -8734, 0], [-1576, 0, 7780, 0], [0, -1771, 0, -99], [0, -4335, 0, 2152], [-42330, 0, 1200, 0], [-36676, 0, 8034, 0], [26736, 0, -3376, 0], [0, 6656, 0, 1578], [-24354, 0, 3952, 0], [52122, 0, -3072, 0], [0, 7723, 0, 2384], [85572, 0, 110, 0], [-43582, 0, -80, 0], [0, -919, 0, 560], [88760, 0, -3636, 0], [0, -5712, 0, 0], [58864, 0, -1000, 0], [0, 7881, 0, 177], [0, -11187, 0, 1004], [-41938, 0, 3184, 0], [-52792, 0, -7309, 0], [0, 12512, 0, 1534], [0, -4643, 0, 305], [0, -4528, 0, -3020], [0, 6067, 0, -1243], [-59334, 0, -304, 0], [0, 12105, 0, -566], [0, -10912, 0, -1240], [-25984, 0, -7464, 0], [24300, 0, -8078, 0], [0, -3120, 0, -108], [57048, 0, -951, 0], [54712, 0, -8461, 0], [0, -12723, 0, -3538], [35960, 0, 9436, 0], [0, 17616, 0, 98], [115404, 0, -4358, 0], [85896, 0, -1355, 0], [0, -14912, 0, -1680], [-38444, 0, 5398, 0], [0, 16176, 0, -2026], [0, -18559, 0, -848], [13816, 0, 2308, 0], [4052, 0, 11142, 0], [0, -7232, 0, -6312], [0, -17677, 0, -502], [0, 4256, 0, -1318], [1904, 0, -1104, 0], [0, -1107, 0, -4816], [20862, 0, 3824, 0], [0, -3936, 0, -3212], [71588, 0, 7262, 0], [0, -9143, 0, -3717], [4086, 0, 9072, 0], [38930, 0, -4224, 0], [0, -18073, 0, 3372], [0, -13805, 0, -2447], [-39418, 0, -176, 0], [0, -11664, 0, -1198], [0, 6032, 0, 432], [-24544, 0, 4656, 0], [-38568, 0, 5217, 0], [0, 8688, 0, 1502], [8984, 0, 14836, 0], [-19272, 0, -9269, 0], [0, -18907, 0, 1501], [12152, 0, -14540, 0], [103240, 0, -8225, 0], [0, -3616, 0, 378], [0, 6987, 0, 2072], [0, -21165, 0, 2647], [70980, 0, 7014, 0], [-39432, 0, -9869, 0], [44676, 0, 7390, 0], [0, -5440, 0, -3008], [0, -5869, 0, 1990], [0, 5616, 0, 5730], [0, -859, 0, 1712], [-56152, 0, -10611, 0], [20160, 0, 9584, 0], [-60152, 0, 8371, 0], [0, -3501, 0, 4331], [31732, 0, -10970, 0], [-170344, 0, 1444, 0], [5192, 0, 2401, 0], [0, 16576, 0, -3596], [-25348, 0, -12430, 0], [0, 3072, 0, 3626], [-60840, 0, 15655, 0], [0, -19423, 0, 1022], [0, 6816, 0, 568], [56140, 0, -7278, 0], [0, 4832, 0, -4538], [-22552, 0, 16268, 0], [-27496, 0, -6037, 0], [0, -11631, 0, -3849], [-59818, 0, -10416, 0], [-10248, 0, 9900, 0], [0, 17520, 0, -2560], [0, -13968, 0, 2962], [-115872, 0, 7064, 0], [0, 9777, 0, -3011], [69628, 0, 10154, 0], [-50278, 0, 7728, 0], [0, 16823, 0, 2149], [0, 17504, 0, 902], [0, -9739, 0, -7610], [73160, 0, 3284, 0], [-115404, 0, -8066, 0], [0, 12745, 0, -2451], [-69400, 0, 3515, 0], [0, 7904, 0, -362], [0, -8672, 0, -1426], [0, -11483, 0, 5561], [221640, 0, 937, 0], [0, 9664, 0, 7276], [133700, 0, 7462, 0], [0, 20784, 0, -2558], [0, 14400, 0, -1104], [87712, 0, 9840, 0], [177656, 0, 529, 0], [-103848, 0, 7332, 0], [-35310, 0, 15344, 0], [-53608, 0, -2620, 0], [0, -11221, 0, 1377], [84352, 0, 3712, 0], [0, 22016, 0, -3382], [0, 33645, 0, -2945], [0, 17088, 0, 6712], [-48116, 0, -5430, 0], [0, 1939, 0, -4156], [0, -4357, 0, -4133], [34136, 0, -5191, 0], [-142140, 0, -2866, 0], [0, -15360, 0, 542], [0, 1937, 0, -924], [0, -12272, 0, -7668], [-86040, 0, -10964, 0], [0, 15488, 0, 2160], [43814, 0, 3008, 0], [0, 11488, 0, -1102], [97688, 0, 9231, 0], [101576, 0, 9605, 0], [-31280, 0, 10144, 0], [0, -15025, 0, 6265], [176856, 0, 8820, 0], [29096, 0, -23815, 0], [0, -17744, 0, -7724], [13684, 0, -12834, 0], [121330, 0, -3696, 0], [0, 10203, 0, 1318], [0, -272, 0, 6586], [-176848, 0, -6920, 0], [-148308, 0, 11866, 0], [0, -6797, 0, -5252], [0, -24272, 0, 5718], [-13256, 0, -6164, 0], [-102142, 0, -688, 0], [0, -5104, 0, 3184], [0, -8101, 0, -8635], [-54624, 0, -1720, 0], [0, -5183, 0, 7133], [-16664, 0, -10291, 0], [-231332, 0, -7302, 0], [0, -9277, 0, -3021], [0, 432, 0, 7318], [-157832, 0, 9140, 0], [93844, 0, -8954, 0], [0, -25565, 0, -1134], [-29128, 0, 16917, 0], [0, -30464, 0, -4422], [0, -5648, 0, -6652]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1600_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1600_4_a_cu();".
// 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_1600_4_a_cu(:prec:=4)
    chi := MakeCharacter_1600_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_1600_4_a_cu();".
// 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_1600_4_a_cu( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1360, 0, -92, 0, 1]>,<7,R![393040, 0, -1292, 0, 1]>,<11,R![3133440, 0, -4992, 0, 1]>,<13,R![2368, 104, 1]>],Snew);
    return Vf;
end function;