
// Make newform 1560.4.a.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1560_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_1560_4_a_m();".
// 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_1560_4_a_m();".
// 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 := [1156, 50, -76, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-438, 122, 11, -1], [1210, -54, -33, 3], [-518, -264, 12, 6]];
    Rf_basisdens := [1, 26, 26, 13];
    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_1560_a();"
function MakeCharacter_1560_a()
    N := 1560;
    order := 1;
    char_gens := [391, 781, 521, 937, 1081];
    v := [1, 1, 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_1560_a_Hecke(Kf)
    return MakeCharacter_1560_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], [3, 0, 0, 0], [-5, 0, 0, 0], [4, 1, 0, 0], [-2, 1, 0, -1], [13, 0, 0, 0], [-18, 2, -1, 0], [18, 1, 1, 1], [-12, 2, -1, 0], [-16, 2, 2, -1], [56, -3, -3, 0], [76, 0, 3, -1], [36, -2, 1, -5], [84, -4, 4, 0], [44, -5, 3, 0], [88, 8, -7, 1], [-88, 5, -13, 8], [56, 12, -13, 1], [144, -17, -7, 6], [-18, -13, 14, 5], [200, 22, 14, 5], [214, -26, 23, -5], [-268, -15, -1, -6], [252, -4, -27, 11], [342, -2, -29, 16], [400, -2, -24, -1], [-104, 24, -32, -16], [154, -32, 9, 7], [540, 10, -12, 9], [84, -18, 46, -21], [908, -36, 10, -14], [-186, 14, -24, 7], [834, -20, -20, -18], [730, 68, -41, 7], [468, 4, 45, 25], [1244, 3, -23, -26], [690, -46, -14, -18], [290, 37, 32, -25], [108, 35, -11, -8], [1146, -12, 0, 34], [538, 64, 34, 9], [372, 56, 43, -17], [32, 34, -54, 32], [38, 18, -3, 8], [2, -50, 8, -40], [1368, 76, 0, -8], [1300, -4, 28, 64], [1314, -121, 57, -5], [-256, 87, -121, 48], [448, -2, 6, -89], [-1142, -18, -151, 22], [1126, -79, 8, -15], [-22, 148, -104, 8], [2558, 16, 96, 11], [-500, 90, 114, -25], [-686, 4, 84, 51], [-2584, 110, -40, 31], [3464, -125, -73, 44], [1026, 46, -118, -46], [-1778, -4, 56, -64], [1228, 32, -76, 40], [1354, 130, 0, 48], [2518, -203, 72, -23], [2032, -68, -36, -56], [-2946, -144, 168, -66], [1494, 40, -30, 118], [5358, -195, 43, -49], [-486, 48, -30, 144], [1078, 228, 97, -51], [-428, -298, 28, 9], [-3510, -4, 48, 38], [368, 1, -173, 70], [1864, -270, -174, 84], [-1522, 242, -72, -72], [-858, 249, -179, 19], [2024, -303, 113, -114], [296, -378, 240, -65], [4116, -52, 223, 63], [-2062, 114, -46, -70], [-1146, -460, -160, 86], [-6018, 250, -48, -13], [3424, 290, 144, 11], [5848, -335, 67, 46], [-1078, 124, -82, 56], [-254, 2, -67, -75], [-3090, -352, -207, 21], [-2680, 300, 115, 45], [-3930, -102, 75, -148], [-988, -236, -101, 189], [8536, -143, 0, 98], [1794, 354, -249, -201], [1250, -185, 228, 219], [5792, 263, 156, -14], [2370, -44, 64, -127], [1582, -27, 153, -249], [-4662, 164, 24, 79], [-3704, -344, -115, 191], [-8474, -276, 104, -66], [-3380, 20, 208, -24], [-2652, 102, -50, -103], [-972, -584, -136, 160], [-2222, -292, 164, -152], [-3970, -278, -149, -147], [-16958, -164, -182, -60], [2670, 922, -125, -11], [-702, -346, -89, -26], [-12432, 3, 151, 192], [1330, -88, 218, 18], [-17272, -362, -70, -20], [-5652, -514, 91, -119], [6952, 670, -338, -260], [2024, -272, -231, -363], [-6358, 296, 92, -142], [-2170, -173, 367, -105], [1752, 3, -87, 8], [-10098, 80, -154, 238], [-1786, 63, -214, -143], [-7828, 754, -263, 228], [-4370, -16, 416, -240], [-8726, -926, 218, 109], [-8648, 770, -88, 347], [-950, -748, 276, 12], [-15292, -660, 373, 195], [-11276, -425, 201, -162], [7386, 5, 121, -31], [-6200, -674, -48, 187], [-14364, 102, 96, -71], [-10748, -116, -72, 162], [10848, -120, 622, -212], [8524, 176, 135, -361], [-11514, 67, -705, 19], [-1648, 541, -635, 370], [10610, 418, 361, -39], [-3646, -196, -546, -182], [-16438, 498, 358, -122], [-14074, -104, 194, 218], [11954, 818, -172, -148], [-196, -483, -61, 320], [-7772, -732, -509, 307], [-5950, 548, 508, -376], [6814, 245, -381, -197], [-16248, 200, 179, -101], [12216, 720, 432, 224], [7472, -1057, 79, 340], [-1338, -360, 328, 416], [-25866, 515, -250, -7], [24088, -200, 41, 349], [-5490, -358, 477, -364], [-20026, -48, 431, -299], [3456, 729, 393, -142], [10038, 940, -148, 196], [-4770, 332, -236, 358], [16316, -498, -290, 384], [-14912, 1112, 375, -486], [632, -1024, -226, 182], [-17508, 414, -250, -22], [6, -472, 93, -789], [7892, 1884, -211, -321], [-1638, -472, 416, 600], [15236, 1080, 233, -51], [-2428, -165, 349, 494], [3262, -1290, -213, 144], [14990, -1569, -183, 97], [15294, -878, -538, 311], [906, -688, -138, -410], [16596, -809, 281, 8], [4250, -1162, 17, 73], [8734, -14, 1060, -360], [-846, 1048, -248, 44], [35232, 112, -507, 321], [-9476, 55, -787, -338], [2656, -1398, -194, -121], [3828, -380, 1076, -10], [22442, -1078, -205, 186], [1570, 456, 131, 741], [-20774, 1220, 82, 308], [-1446, -1457, 855, 53], [12436, -308, -203, -215], [260, 472, -628, 258], [-10950, 148, -1060, 342], [24604, -743, -732, 160], [12202, -176, 740, 5], [19166, 1508, 320, -336], [5430, -1836, -204, 352], [-6384, 607, -681, -386], [-7388, -838, 676, 145], [15146, -568, -146, -846], [12946, -737, 128, -413], [-11054, -236, 114, -652], [-9542, 191, -656, 715], [-2554, -240, -474, -30], [5128, 543, -173, 356], [21994, -108, 333, 207], [15456, -84, -297, -237], [-16720, -598, 294, -642], [40706, -1230, 203, -234], [-15378, 1376, -408, -110], [20018, -1406, -854, 230], [-358, -612, 142, 278], [-7208, -1172, 1149, -1022], [874, -1520, 28, -832], [9198, -1680, 201, -505], [20580, 2620, -263, -173], [-32992, 546, -543, -289], [-15142, 9, 758, 465], [456, -1488, 227, -223], [4608, -735, 841, 468], [28840, -392, 1128, 342], [16824, -1614, -505, 681], [21902, 1006, -759, -47], [21498, -832, 294, -224], [7840, -534, 230, 303], [-8628, -1806, 762, 18], [-7480, -625, 679, 64], [-15912, 205, -277, 962], [-9514, -236, 1374, -874], [-17340, 1850, 234, 114], [-12586, -752, 120, -154], [26496, 1553, 81, -270], [61058, -116, -332, 288], [-28472, -16, 965, 489], [-7780, -421, -881, 198], [24178, 222, 634, 1066], [11102, 1667, -407, -115], [-1090, -1138, -1369, -767], [-15684, -480, 1095, 683], [5186, 150, -1663, 734], [23416, -1394, -12, -236], [-2344, 1644, -598, -248], [15278, 1149, -880, -1293], [27870, -94, -836, -284], [5182, -1900, -281, 57], [28612, -1491, -789, 490], [8794, 464, -1574, 516], [-6648, 1418, -1408, 1130], [23288, -283, 845, 1394], [-66486, 128, -98, 556], [69986, -432, 824, -68], [-43742, -3544, 750, 457], [-1732, -122, -278, -698], [17436, 297, -153, -266], [66726, -662, 929, 85], [-76, -1250, 270, -314], [10568, -702, 344, 767], [43818, 20, 1010, -466], [-27168, -1708, -848, 696], [6026, 225, 1815, 563], [34066, -991, -708, 933], [2278, 1069, 1603, 679], [12722, -1190, -586, 871], [50410, -140, 240, -154], [14886, -2208, 600, -1088], [-14228, -2137, 675, -584], [-47100, -960, -513, 205], [40716, 1892, -1401, -693], [-2058, 829, -1534, 235], [-32698, -2472, -72, 884], [44090, -933, 318, -1233], [43402, -52, 192, -678], [-7594, 378, -657, 1360], [-55640, -1692, 42, -348], [-26138, 2492, 359, 285], [-36772, -1030, -1464, -715], [-8046, -2100, -178, -850], [-36058, 960, -584, -556], [-1346, 1280, -379, 913], [32320, 2368, -1351, -1125], [17540, 2396, 909, 747], [-44614, 1077, -954, 207], [1902, 576, 928, 916], [-10158, -568, 1408, -174], [85942, -1285, -80, 669], [21402, -654, 211, 1186], [5320, -2230, -834, 612], [-15838, -3720, 96, -112], [3624, -1529, -96, 498], [-16516, 1163, 325, 530], [-45400, 166, 1412, -961], [-52942, -3244, 450, 336], [10650, 2512, -1814, -619], [-24624, -1648, 953, 1066], [-19752, -109, -1759, -524], [-34782, 1064, -1376, -145], [-6856, 218, -1330, 1183], [39664, -1563, 279, -1302], [40140, -3024, -620, 1386], [16042, 1508, -490, -1288], [25050, -3406, -352, 840], [-3100, 4131, -29, -90], [-29802, 1420, -2910, 782], [9444, 642, 1200, 941], [74964, 2464, 544, -356], [30498, 456, 806, 1238], [-25252, -2511, 187, 278], [-226, -1792, 1536, 916], [69572, 1270, -134, 673], [-76784, 1254, 666, -876], [44168, 3652, 923, -675], [-9422, 3338, 766, -163], [31226, 1477, -404, 287], [-8658, -576, -336, 2158], [12026, 1170, -268, 1872], [39638, 1380, -903, -1617], [6434, -2192, 387, 1463], [68684, 1624, 3772, 140], [55814, -750, 837, 372], [-60138, -470, -575, -1303], [-38664, 284, -179, -1651], [100016, 1455, 61, 270], [32634, -928, -1654, -578], [-15108, 1928, -1935, 128], [4218, -1968, -260, 2220], [25598, -2448, 64, 86], [-90812, -1068, -2056, 588], [-16584, 2583, -2183, 1354], [-64292, 1712, -325, 289], [-19750, -697, 416, -1555], [34574, 3871, -1746, 93], [-103400, 1978, 310, 673], [63270, 332, -82, 1402], [25792, 1310, 1090, -1226], [-81808, -4414, 938, 741], [-9204, -1882, 1454, -11], [-44056, 3069, 2032, -1746], [25798, -5048, 424, -416], [-12980, 3402, -325, 341], [3774, 1395, 1491, 355], [-67138, 2311, -434, 673], [63088, -3922, 23, -1950], [-53334, 1576, -868, -1002], [75268, 106, -230, -151], [-24736, -6228, 1983, -391], [-79912, -1280, 1952, -1264], [-31428, 313, 1379, -86], [24446, -4403, 1471, 99], [39776, 1743, 343, -2168], [-89796, 850, -698, -15], [-20642, 704, -3622, -16], [-76082, -2888, -2068, 106], [-21716, -244, -1630, 2014], [-19660, -1224, -983, 871], [-45146, 1334, 1921, -1576], [31420, -3096, -1055, -611], [65624, 6028, -1608, 12], [43046, 1854, -170, 1974], [-35142, 792, 668, -595], [55176, -1424, 2179, 1253], [51270, -2991, -1244, -207], [32616, -1431, 2995, -2282], [-35048, -6032, 1967, 1045], [44102, -663, -2019, 1571], [-4354, 2150, 1137, -1044], [-26400, 744, -2669, -2381], [-84592, -1544, 1478, 312], [-448, -5900, 1609, -635], [-29432, -5422, -1002, 277], [26382, 4027, 3598, -867], [-46648, -5881, 677, 808], [-90360, 4158, 678, -15], [-33748, 1325, 1341, -2112], [26838, -6312, 2180, -776], [15438, 1716, -1142, 3234], [-31830, -4912, 892, 2227], [4780, -4889, -3331, 902], [109520, -3276, -242, -326], [-42598, 2348, 2254, -1340], [-76782, 3866, 644, 1220], [-79912, 4165, -216, -254], [-90644, 3488, 2667, -2895], [115846, -1602, -1408, 799], [-18768, -3666, 2986, 3258], [17452, 1615, -1211, 556], [24680, -4598, -826, 2907], [-119534, 1422, -223, 85], [60266, 2836, -3770, 2674], [121494, -2657, 2060, -1509], [6292, 6752, 622, -358], [-13646, -434, -329, -2498], [39234, 2396, 3182, -788], [-73842, 3232, -2544, 430], [31966, 1148, 1252, -702], [-177022, 1156, 1084, 198], [28002, -5715, 2283, 931], [-113706, -2016, -3620, 388], [-84870, -861, 2121, -1247], [59464, 1675, 237, -1394], [-109404, 2665, 3745, -4242], [-72302, -3148, -3902, -806], [50728, 291, 5737, -1294], [132384, -72, -527, -818], [84206, 6972, -3746, -1238], [13698, 5220, 784, -2996], [-11546, 4865, -2380, 2235], [8132, -2876, 2664, -2988], [81270, 4061, 940, -887], [-72074, 2796, 1068, 3154], [-12048, -83, -4659, 0], [18170, 3256, -3604, -336], [-107162, 864, -3081, 1933], [35698, -5008, 3496, -536], [30036, -10, 522, 2005], [45918, -10306, -199, -1172], [86588, -1223, -1382, -972], [21754, 3764, 3862, 218], [-76820, 3300, -813, 1101], [50282, 1708, -4653, 1981], [83586, 3640, 2088, -1790], [-95986, -4084, -844, 840], [-18226, 1741, -5182, -1519], [130270, -3055, -3382, 3591], [-15970, -2724, -900, 3370], [-17612, -5204, -401, 3367], [98542, -2316, -1235, -2943], [124642, 1506, -795, -1961], [-31262, -3244, 4060, -164], [-88216, 2354, -3318, -305], [139938, 369, 1594, -1705], [-4308, -1410, 288, -2946], [18738, 252, 2414, 602], [65268, 3606, 1077, -2468], [110672, -2878, 586, 775], [99496, -7604, 1347, -2559], [49440, -1287, 2707, 3762], [-32858, -3138, 6926, -2465], [53920, 2786, -1430, -1227], [-22738, 3116, -4922, -1314], [38770, 6154, 547, -777], [17512, 1860, -5137, -1695], [6494, 1383, -4093, 2591], [152308, -3998, 1656, -2178]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1560_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1560_4_a_m();".
// 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_1560_4_a_m(:prec:=4)
    chi := MakeCharacter_1560_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_1560_4_a_m();".
// 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_1560_4_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![101088, 6048, -762, -15, 1]>],Snew);
    return Vf;
end function;