
// Make newform 1600.4.a.cs in Magma, downloaded from the LMFDB on 05 February 2025.
// 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_cs();".
// 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_cs();".
// 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 := [6, -11, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-30, -2, 4]];
    Rf_basisdens := [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]];
    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], [2, 1, 0], [0, 0, 0], [1, 1, 1], [-11, -2, -1], [-3, -1, -3], [-34, -13, 1], [-32, -9, -2], [42, 4, -2], [-37, -27, -1], [94, -12, -6], [49, 53, -1], [-127, -36, 4], [-133, 13, -9], [-287, -37, 5], [-14, 32, 16], [-375, -85, 5], [-161, -1, -19], [213, -96, -13], [663, -59, 3], [10, 45, 15], [313, -59, 33], [-359, 144, 31], [396, -1, 37], [-260, 230, 50], [-479, -39, 43], [899, 57, 31], [939, -24, -3], [977, 145, 19], [-297, 136, 8], [-996, -74, 32], [-1249, 177, 11], [-1129, 142, -54], [-911, 18, 59], [533, -101, -31], [1325, -195, -35], [-2020, -150, -50], [-213, 154, 33], [-469, 233, -25], [-648, -56, 72], [390, 205, -140], [-522, 272, -64], [1376, 422, -84], [-1366, 103, 29], [-2564, 302, 26], [1796, 352, -4], [881, 492, -129], [-1174, -70, -102], [-957, -195, -97], [610, -422, 14], [194, 308, 124], [-557, 421, -137], [-2562, -593, 5], [2150, -205, 0], [-4492, -214, -2], [-1918, -364, 150], [1938, -474, 98], [-392, 1026, 108], [-3419, 67, 41], [-3676, -438, 62], [3962, -217, 164], [-5511, -607, 19], [-4922, -379, 116], [-6257, -329, 143], [3108, 646, -142], [-3296, -532, 84], [3161, -538, 11], [-2297, 596, -212], [-2217, -204, -359], [1793, -711, -293], [-4500, 410, -210], [-3911, 53, 49], [4548, -1064, -4], [-5080, -930, 90], [-3816, -827, -46], [-1385, 999, 199], [-1850, 124, -172], [-488, -716, 252], [4068, 245, -265], [1883, -662, 302], [4860, -65, 210], [1982, 286, 506], [-4595, 225, -395], [-1744, 1017, 131], [1811, -1683, 231], [-1488, 181, 42], [-3542, 1291, 393], [4467, -226, -278], [-3816, -1036, -468], [-950, 2050, 154], [-75, -565, 553], [-3234, -248, -334], [5120, -126, 276], [305, -665, -555], [-11165, -715, -145], [5446, 1270, -234], [-438, 276, 188], [-1911, -1076, -188], [3653, 802, -361], [4540, 2476, -12], [-1210, -635, -428], [9343, 1021, -137], [-3285, 1449, 207], [4077, 2348, -540], [-7969, 1777, 571], [2251, -1648, -384], [6590, -913, 176], [-10179, 362, -34], [-6921, -1497, -41], [-1934, -331, -425], [-3416, -624, -472], [-5186, 228, -116], [8070, -1560, -200], [-17267, 1331, 113], [18546, 952, 126], [18504, -350, 358], [-7431, -1369, 509], [-12726, 906, -742], [5805, -1395, -585], [8329, 2008, 159], [6047, -3479, -69], [-7010, -1060, 500], [-3278, -1586, 42], [-8225, 208, -183], [-20262, -119, -712], [-1053, -2751, 947], [-410, 4182, 66], [635, 1975, 915], [6313, -1513, 117], [19257, -2221, -423], [-17539, 1867, -319], [15414, -2296, 282], [18319, -487, 259], [14180, -380, 60], [6685, 3136, -432], [-7470, 1543, -291], [-19969, 1257, 171], [-15949, -827, -225], [10170, -1860, 500], [-12984, -4950, 350], [-5905, 3425, -245], [23312, -1642, -350], [8178, 5242, -414], [4570, 1283, 1724], [8323, 3337, 235], [2346, 6302, 386], [-4900, 410, 430], [1809, -2652, -1556], [-21491, 1718, 199], [1157, -2101, -687], [13220, 320, -400], [15068, -5310, -634], [19598, -2891, -212], [-12368, -6996, 424], [-12893, -3235, 367], [-16108, -2416, -228], [10604, -6822, -1256], [-29454, -676, 20], [11212, -1181, 1137], [6547, 3625, 1275], [18515, 3849, -249], [-6659, -5148, 1676], [27952, 488, 528], [20469, 1238, -641], [-22944, -5243, -249], [-6217, 6775, 455], [-8729, -433, 311], [-20454, 1242, -1474], [-15400, -5703, 611], [-31187, -69, -447], [21864, -1387, 594], [-11569, 2991, -67], [-23463, 3789, 1297], [12662, -5191, -413], [27315, -2315, 1255], [11574, 4701, -337], [14278, 1131, 368], [-3595, -4291, 1767], [-24338, 3738, 966], [14852, -8190, -1226], [43794, -670, -494], [18700, -3425, 1170], [-3181, 7863, -91], [-18174, -1063, -269], [-18507, -921, -1575], [-16678, 7562, 1006], [14505, 3205, 1215], [32400, 2407, -1282], [15259, -3522, 234], [-20709, 1037, 191], [-6521, 1368, -856], [7000, 4729, -6], [649, -2612, 439], [3726, 2364, -1340], [-18882, -4439, 500], [-20738, -2996, -348], [1595, 6296, 552], [33512, 1934, 2282], [-20955, 6150, -430], [19081, 2365, -559], [14340, 3778, -1386], [-18788, -3776, -588], [-14572, -5484, 1068], [491, -3296, -848], [16897, -2801, -1163], [-30280, -3010, -1190], [45214, 6068, 154], [19751, -6271, -701], [4310, -8168, -984], [-6483, -41, 857], [-15546, 5228, -956], [30881, -2955, -1073], [-22465, 2441, -1229], [28691, -1964, 1101], [13666, 9072, 846], [-50285, -2490, -1550], [44768, 1242, -588], [21394, 6967, -579], [-3363, 233, 517], [3267, 11779, -23], [-28978, 4764, 1252], [14309, -5337, 2409], [-10870, 563, 1169], [3615, -1945, -1761], [-11412, 4119, -1454], [-627, 4253, -1913], [-34332, 1151, -3707], [-3161, 7073, -2501], [4131, 13657, 879], [-38166, -5877, -1556], [11591, 767, -19], [-40809, 7802, 1381], [37675, 4895, 1315], [10420, -689, -443], [7277, -10361, 281], [-13401, -6025, 455], [53434, 7519, 261], [-41097, -3519, -2477], [24096, 617, -574], [10590, -3810, 190], [-70180, 1359, 1474], [-47138, -641, 272], [4196, -14778, -488], [6474, -10990, 630], [-54113, 2204, -508], [-2018, -9086, -1658], [185, 5317, -1279], [-1335, 12855, 685], [-3856, 6893, 3754], [-10875, -2709, 1361], [39882, 12174, -358], [-117, -8688, -144], [-70831, 1109, -2391], [10218, 2301, -3217], [-59769, 937, 91], [-16423, 4664, 47], [14975, 6681, 1003], [-42552, 6277, 1058], [-47757, 7971, 1193], [29307, 6554, 702], [21349, 2001, -2899], [62483, 7378, 9], [66827, -1523, -1449], [-995, -9305, 485], [-15608, -2231, 67], [-25806, 5153, -1376], [-12408, -78, -3514], [5752, -4090, 530], [-40289, 6752, 1417], [-55371, 2553, -1621], [3803, 5105, -1085], [68573, 1228, -1245], [4666, -3463, 3091], [38415, 5745, 1715], [20798, 8036, 1388], [-52918, -4550, -2950], [-21771, 194, 1479], [16196, 5180, -1660], [4462, -3056, -208], [-16186, 12293, 2324], [16638, 3718, -1202], [15522, -3836, 1462], [-36160, 12864, 1456], [-52320, 9036, 68], [-18576, -1119, -1358], [19294, -5662, 54], [44850, 2620, -1740], [74619, -7987, 839], [17810, -17370, -3030], [-41530, 1180, 1300], [52521, 3269, -465], [1179, -12411, -2537], [-17706, 16473, -1661], [-15990, -22025, -140], [36844, 8048, -736], [-73152, 4994, -986], [-26471, -2167, -4391], [-36883, -15741, 1737], [-9189, -5523, 2071], [-26401, 674, 4429], [26999, 7738, -306], [-56541, -8097, 1389], [-51688, 1024, 3832], [52290, 1773, 2520], [-20026, -21357, 1904], [58864, 1293, 3199], [-69993, -3215, 1027], [-56471, -2895, 3715], [-24586, -18412, 1714], [20687, -16501, -1663], [13227, 12883, -3189], [-72122, 3544, 2472], [73310, 519, 3197], [74099, 2553, -2617], [31848, -7476, 416], [-19048, -8274, -4662], [24500, -965, 1250], [-106424, -728, -2024], [84961, 7822, -374], [-85379, 710, -1038], [56011, 6957, -2089], [45351, -1738, -14], [139447, 1893, 2415], [57862, -11324, 1650], [-88188, -4666, 402], [-71576, -10006, 3166], [4375, -8410, -275], [52561, -889, -1835], [-20601, 1203, -513], [5639, 8293, -4961], [-20935, -637, -2759], [29891, 5747, -5559], [-85527, 1901, 2353], [-12102, -14259, 784], [64163, -12764, 1293], [-35247, 1779, -2419], [-25429, 10285, 4087], [22358, 11596, 6628], [65192, -3821, -1503], [79197, -3531, -691], [112150, -2310, -3010], [-39477, -16874, 3378], [-43458, -17508, -892], [-94631, -5837, 829], [-58126, 3168, 2864], [52801, 12047, 3301], [-22229, 809, -5285], [59618, 15975, 3004], [-32199, -4473, 741], [182363, 5551, -787], [63671, 6242, 8581], [26644, -9602, 6554], [40905, -17247, 451], [-125813, -2335, 263], [-2694, -14580, 2260], [-137670, 7965, -785], [52861, 9727, -639], [39239, 20528, 769], [76882, -1076, 292], [69822, -930, -2210], [-30127, 10461, 2663], [114472, -1025, 3925], [-39453, 17675, 4307], [-86199, -1953, 1581], [-25447, 9560, 1743], [56444, 10883, -1151], [-103773, 2589, -2153], [43528, 15736, 3832], [-15297, -10402, -8038], [-10725, 11925, 855], [106985, 17090, -45], [-59688, -29628, 2672], [-100980, 15424, -1232], [2810, 19270, 4530], [56101, -20923, -1729], [-86466, 17513, 1844], [3405, -7595, 1005], [46989, -8362, -686], [15426, 17051, -1751], [7898, 7336, -4712], [11304, -18618, -3134], [-169089, -14238, 726], [-149371, 16819, 689], [44799, 12048, -1056], [117755, 8345, 1855], [-39435, 12037, -5435], [-17372, 1076, -6092], [111644, -3452, 524], [70625, -7477, 3597], [72238, 15508, 1210], [78121, -30950, -2658], [-31638, -11726, -138], [-24250, -11485, -4080], [157845, -316, 5291], [151518, -4044, -2102], [-75299, 2832, 2496], [37212, -2416, -7148], [-65333, 19022, 3786], [30289, 16658, -3781], [151644, -13526, -434], [-10503, 22295, -6491], [101616, 13497, -509], [8657, 22515, -5323], [-75431, 15928, -3096], [121456, -1832, -5192], [11133, -709, -6327], [-101926, -8172, 3804], [17672, 15970, -8090], [3831, -14903, 4387], [-145647, 4396, 1743], [87661, 3522, 326], [105636, -22388, -3164], [-185034, 439, 1144], [-57585, -5175, 3275], [-26212, -1489, -2107], [-60295, 12401, -7037], [62448, -19834, 1628], [-45722, -25620, 6338], [-34820, -7775, 9035], [-105279, 8589, 841], [-105737, -10487, -213], [-103199, 23657, 3931], [23466, 14656, -4138], [-2470, 795, 9820], [-111003, 5584, -3328], [-118557, 36901, 4623], [18535, -283, -6037], [-5566, -28171, -6969], [-113213, 11244, -2163], [206544, 1238, 2204]];
    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_cs();".
// 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_cs(:prec:=3)
    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_cs();".
// 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_cs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![89, -37, -5, 1]>,<7,R![5736, -692, -2, 1]>,<11,R![-8475, -485, 31, 1]>,<13,R![-192000, -6000, 8, 1]>],Snew);
    return Vf;
end function;