
// Make newform 1080.4.a.p in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1080_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_1080_4_a_p();".
// 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_1080_4_a_p();".
// 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 := [3500, 200, -141, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [250, -617, 3, 7], [550, 131, -9, -1], [-575, -71, 9, 1]];
    Rf_basisdens := [1, 40, 20, 5];
    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_1080_a();"
function MakeCharacter_1080_a()
    N := 1080;
    order := 1;
    char_gens := [271, 541, 1001, 217];
    v := [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_1080_a_Hecke(Kf)
    return MakeCharacter_1080_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, 0, 0, 0], [5, 0, 0, 0], [3, 0, -1, 0], [-1, 1, 0, 0], [7, -1, -1, 1], [-6, 1, 2, 1], [18, 0, -3, -1], [44, 0, -3, -2], [51, -4, 1, 1], [-19, 3, 0, 2], [74, 4, -3, -3], [95, -2, 0, -1], [48, -2, 7, -2], [31, -4, 5, -1], [-59, 8, 10, -5], [-53, 0, -4, 11], [203, 4, 23, 4], [83, 2, 1, 4], [-273, 2, -16, 3], [358, -4, -5, 7], [201, -9, 31, 7], [-193, 2, -2, -9], [-103, -10, -6, -1], [844, 16, 19, -7], [240, 16, -55, -8], [395, 14, -3, -18], [-494, -12, 12, 0], [480, 12, -14, 6], [111, 1, 0, 16], [1154, 18, -44, 8], [15, -13, -54, -8], [796, -18, 10, 24], [494, -10, 3, 7], [756, -48, -1, -8], [1451, 19, -33, 9], [-281, -29, 58, 18], [1337, 16, 82, 18], [19, 36, 68, -29], [1242, 12, -58, -14], [-1361, 56, -42, -47], [725, -36, -21, -24], [-811, -46, 32, 15], [-388, -30, 3, 53], [2891, 10, -10, 9], [1577, 41, 97, -33], [-344, 26, 83, 25], [2232, 14, 10, -14], [343, -26, -44, 43], [-1304, 54, -24, -44], [1586, 10, 88, 0], [-3233, 24, 20, 41], [2637, 20, 72, 24], [-2040, 41, -84, 1], [1825, -11, -6, -76], [-2728, 4, -44, -16], [1425, -32, 81, 49], [948, -42, 163, 27], [2058, -98, -2, 50], [-288, -48, 150, -32], [-2294, 0, 44, -26], [274, -14, -202, -22], [242, 54, -233, -12], [-2745, -30, 238, -59], [2844, 24, -125, -29], [6044, -56, -68, 24], [2390, 4, -167, -71], [-3896, 22, -25, -85], [1049, 6, 112, 73], [3847, -36, -1, -68], [-2255, 47, 226, 62], [-7284, -70, -92, 68], [-51, 130, 205, -40], [-8181, -51, 57, -35], [-5120, 70, -9, -77], [-1676, 124, -81, -72], [851, 120, -185, 67], [-2835, 65, 62, 142], [-1373, -60, 78, -83], [-6197, -4, 74, 30], [-2176, -117, 182, -11], [-97, -124, 191, -34], [-3412, -120, -94, 38], [-2260, -102, 102, -152], [-1226, -152, 240, 46], [-1798, -106, 18, 64], [-1001, -58, -132, -35], [-998, 184, -34, -4], [1787, -28, -26, 19], [-8405, 46, -223, -10], [669, -294, -2, -41], [-5019, -46, -44, 37], [-569, -62, 163, 10], [3712, 32, 330, 46], [-8546, -224, -316, -50], [-9754, 148, -27, 96], [-6950, 180, 213, -200], [1966, 94, -476, 6], [-3081, -48, 226, 86], [-4249, 302, -13, -12], [7017, -220, 206, -10], [12663, 198, 602, 21], [168, 114, 184, 2], [-11167, -100, 156, -3], [-3644, -154, -431, 55], [-2414, -42, -43, -245], [11668, 122, 142, -76], [-7534, -211, -24, 159], [-4397, 370, -22, -269], [-5338, 198, 357, -6], [-14433, 74, 317, 174], [-2297, -117, -187, -33], [-5957, -113, 336, 358], [-1064, 148, -101, 5], [5082, 30, 675, 41], [-21012, -10, 108, 182], [3022, 66, 499, -216], [-3503, 288, 98, -97], [-1522, -246, 6, -208], [-3742, -224, 384, 82], [-8421, 88, 107, -56], [-666, -310, -93, 27], [17727, 52, 260, -1], [-12077, -172, -90, -63], [11418, 194, -692, 228], [15258, -236, 389, 196], [11459, 302, 397, 80], [-11733, -88, -156, -211], [8928, 112, 1044, 32], [-410, -258, 74, -138], [-3930, -370, -318, 244], [2581, -232, 49, 269], [-1477, -253, 875, 41], [8229, -491, 671, 209], [-14912, -170, -958, -152], [6659, 12, 256, 76], [7077, 374, 134, 305], [14819, -216, -480, -490], [10014, 202, 402, -348], [-15458, -328, -448, -26], [5958, 218, 28, -128], [-1377, 208, -1230, -361], [10359, -46, -311, 320], [7975, -352, 370, 211], [20917, 258, 437, -318], [2518, 358, 292, 356], [4299, 95, -3, 43], [6851, 194, -1142, -401], [-2772, 416, 101, -129], [-2797, 16, 245, -345], [18115, 289, 81, 229], [8106, 352, 924, -124], [12865, 210, -9, -480], [18626, -52, -371, 78], [-779, 264, 696, 420], [-3624, -48, 440, -480], [9045, -443, -660, -192], [-27855, 70, -180, 49], [216, 214, -641, -167], [-16656, 100, 117, 150], [40721, -206, -12, -25], [-9792, 95, -1574, -407], [7859, -94, -109, 276], [-1842, -323, 1226, 253], [-23914, 233, -56, 95], [9470, 152, 309, -776], [4809, -7, 429, 15], [4053, 687, 810, 144], [13311, 620, -360, 6], [-21235, -90, 1120, 679], [-6604, 299, -428, -685], [-3978, -34, 642, 438], [12157, -578, 912, 471], [-11290, -358, -221, -367], [2163, -1099, 277, -175], [-46789, -336, -354, -31], [5122, 246, -422, -792], [33368, -304, 188, -310], [30563, -316, -205, 218], [24856, -458, 242, 376], [-113, -270, 257, -548], [-20212, -256, 172, 616], [-10913, 499, 810, -254], [-14194, 145, 1090, -127], [5410, -104, 36, -250], [8143, -384, -396, -739], [-5445, 171, 351, -287], [7617, -4, 662, -98], [17405, -506, 763, 190], [9981, 446, 1388, 15], [-18372, -784, 223, -327], [-5396, 718, -244, 246], [16204, -70, 145, -227], [-27497, -160, 1485, 3], [-10729, -280, -2284, -57], [-23586, -502, -1486, 130], [10767, 422, -147, 178], [-29413, 619, 379, -35], [14876, 98, 894, 208], [-25243, -96, -6, 1063], [-2169, 1036, -163, -273], [-22088, -454, -41, 735], [14442, -176, 883, -613], [1981, 218, -1089, -374], [-27552, -109, -140, -133], [3643, -578, 580, 427], [-32387, 237, 1007, 489], [35756, -416, 852, 326], [-8390, -218, -238, -318], [17928, 1014, -137, 415], [-23184, 234, 753, 805], [26175, 100, -1055, 403], [-18153, 116, 171, 994], [18374, -92, -516, 88], [-21729, -414, 1570, 831], [-189, -428, -1720, -260], [3260, -1120, -242, 728], [-39480, -940, -1640, 54], [-26105, -380, -713, -591], [17871, -936, 468, -63], [-1397, -394, -251, -504], [-217, -201, -836, -172], [-4212, 338, -1490, -338], [-25148, 954, 242, -654], [21400, -762, 1806, 396], [16455, 472, -1909, 412], [-13472, 669, -958, -529], [-17822, -1370, 446, -186], [-14879, 636, -543, -786], [-58204, 153, -278, -521], [-38128, 196, 855, 565], [-31006, 328, 426, -290], [-2827, 565, 780, 112], [-21718, -308, -164, 1144], [-17977, -618, 503, 486], [45957, -420, -420, -627], [33411, 1220, 1506, -326], [25851, 994, -1798, 509], [10181, -52, 794, -377], [14802, -310, -1998, 868], [-19393, 242, 2160, -41], [-33158, -538, -721, -247], [63527, -834, 683, 336], [17767, -790, 2497, 246], [-8661, 914, -8, -315], [7818, -186, 2256, 1146], [-9331, 418, 119, -54], [15977, -697, 1042, 546], [-31516, -346, 972, -878], [-5921, 448, 257, -431], [49205, -169, 690, -180], [34419, 392, -1764, -637], [-74821, 120, -972, -185], [1603, -90, 3623, 612], [34894, -1414, -174, 74], [-11514, -143, 1770, 601], [-24047, 1494, -1771, -1010], [-2710, -86, -1211, 304], [-14389, -8, 476, -479], [-13964, -468, -1744, 126], [-19241, 1114, 1815, -746], [-10738, 684, 1388, -68], [7177, 1156, -1899, 352], [-33497, -1685, -1839, 363], [-28889, -1441, 1026, -536], [-56630, -168, -156, 462], [42786, 544, -2900, 376], [-35707, -284, -1722, -805], [33414, -98, -2409, -660], [31805, 330, -1078, -1133], [-14813, 990, 1227, -1618], [-40567, -448, 1020, 838], [6862, -968, 264, -548], [33021, 97, -137, 473], [12320, 1196, -1656, -602], [29635, -66, -3141, -182], [-39966, -408, 1158, 2088], [3686, -640, 1682, 164], [14270, -1554, 1053, -502], [-89022, -589, 1548, 161], [-24410, -1808, -2533, 492], [25815, -273, -1056, -1732], [3425, 808, 1689, -1609], [-18963, -730, -1293, 1156], [4625, 1452, 506, -2002], [97277, 776, -250, 221], [-30756, 1620, 1437, 69], [-570, -828, 46, 1554], [-12313, -1275, -51, -971], [31560, 316, 1112, -1462], [-19408, -1368, -1117, 1430], [-75315, 2018, -1964, -1283], [17542, 2263, 2252, 741], [-3238, -2068, -108, 162], [-22532, 138, 1238, -92], [42716, 1440, 1154, -620], [23328, -2094, 673, 1261], [67037, -500, 334, 1025], [7816, -19, -1096, -1619], [65851, -1514, 1373, 664], [-49840, -1046, -991, 213], [-49521, 288, -3698, -171], [-17221, -829, 72, -1476], [30552, 988, -1242, 364], [11872, -78, 547, 429], [-26894, -2270, -1342, -878], [-51823, -650, 2488, 387], [42599, 354, 1955, 264], [-69560, 1240, 1642, -504], [29537, 2281, 309, -185], [19867, 396, 2523, -181], [18982, -796, -726, -882], [-60489, 690, -418, -613], [52985, 384, 3086, 122], [-59662, -2308, -3551, 160], [58818, -646, -217, -154], [54762, 923, 1850, -1429], [-60822, -320, 1214, 1208], [-48706, 314, -2532, 526], [48740, -656, -1564, 394], [66818, 724, 4601, 443], [52282, 358, -2719, 543], [53983, -2648, -807, 1205], [51932, -660, 2864, 24], [37868, 1565, -1392, -75], [56247, 1524, 4376, -458], [-30494, 1992, 740, -1862], [57988, -648, -2608, 624], [70606, 296, -2339, 944], [-13834, 230, 3536, -1590], [-9749, -940, -3535, -246], [-44735, 1654, -1254, 321], [31757, 11, -2501, 1259], [15873, -628, -2108, 443], [49700, 1562, -58, -1874], [-109673, -624, -3360, -43], [75959, 2192, 2609, -28], [33278, 1010, -3650, -294], [-11890, -1302, 3, -710], [-39500, 200, 3038, 1660], [111427, 245, -475, -951], [-37121, -839, 5388, 1268], [72301, -732, 1612, 491], [41865, 173, -2945, -2119], [28700, 1844, -1368, -2112], [17084, 1655, 434, 1489], [-26850, 972, 1688, -208], [127888, -100, -212, 40], [38240, -3424, 264, 36], [-158864, -944, -2148, -10], [-35312, 2300, -1587, -2003], [-2376, 120, -2631, 245], [45090, 2064, -2189, 206], [43650, 624, 1010, -838], [-3625, -1188, -3875, -1636], [-30307, 919, -3172, 60], [43203, -1608, 1110, 1629], [57834, 1999, 64, 421], [22974, -789, -3716, -1307], [43405, 984, 3953, 1351], [2934, -2664, 285, 1849], [-52724, -1604, -232, -744], [-63217, -392, 5746, -619], [4338, 1039, 2, 2127], [87043, -1748, 434, 788], [64274, 1840, 4019, 713], [50253, -990, -2630, -1045], [-75295, -2118, -503, 1412], [31133, 276, -1552, 1762], [-51580, -1349, -2698, -995], [40850, -692, 2565, 1465], [9654, 1980, -4547, -290], [88725, -664, 556, -1701], [-51584, 2610, 1469, 657], [40195, 461, -6373, -297], [78163, -2273, 3584, 1698], [171860, -1586, -86, -166], [42440, -1768, 1739, -601], [-35261, -14, -850, 1611], [-3776, 838, -1667, -2593], [-113039, 568, 471, 5], [105426, -1185, 1968, 245], [55997, -554, -1747, -2762], [37648, -3013, 1932, 1215], [-60954, -1168, 467, -1517], [21644, 1496, -1227, -1576], [-14842, 2184, 4368, 198], [112626, -200, 4855, 747], [55751, 2248, -2474, 208], [-139133, 2120, -1355, -669], [37832, -1994, 4385, 64], [-1000, -2780, -602, 340], [42424, -2244, 2250, 1110], [48723, -180, -1508, -1946], [-65958, 374, 112, -762], [-133614, -204, -2707, 235], [12728, 422, -4417, -1613], [33851, 658, 2270, 29], [-13612, -2136, 4298, -536], [38375, -320, -6081, -2335], [-120652, 2188, 254, -594], [-10082, -2177, -1508, 361], [-151196, -1048, -1868, -868], [-18170, 1659, -444, -475], [-162372, 180, 3198, 708], [-48030, 2164, 1008, 2202], [7159, -327, -453, 1083], [-83727, 3072, -840, -285], [-43381, -2522, 2263, -254], [33979, -551, -1196, -752], [83460, -3418, 2918, 2688], [-31670, -658, -3000, 24], [89835, 184, -2462, 2135], [7388, -2302, 3047, 1141], [-140708, 1924, -2205, -1635], [-5460, -52, -1700, -2070], [110119, 2072, 1178, -1673], [142575, 1284, -2361, 634], [-139015, -722, 5570, -2039], [-126465, -1388, 2353, 1209], [24814, 2688, 5029, -1760], [58612, -562, -974, 2020], [114129, 1048, 1543, 801], [7575, 1817, 2554, -730], [22, -1886, -6966, -614], [-57576, -674, -9168, -1826], [9080, 1402, 4564, 76], [-50499, 1734, 5344, -1771], [75448, -1030, 1052, -378], [81669, -884, 3920, -349]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1080_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1080_4_a_p();".
// 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_1080_4_a_p(:prec:=4)
    chi := MakeCharacter_1080_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_1080_4_a_p();".
// 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_1080_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![29484, 9792, -1067, -14, 1]>,<11,R![1807596, -45756, -3749, 4, 1]>],Snew);
    return Vf;
end function;