
// Make newform 1080.4.a.f in Magma, downloaded from the LMFDB on 19 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_f();".
// 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_f();".
// 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 := [16, -11, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [22, 3, -3], [48, -6, -6]];
    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_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], [-5, 0, 0], [0, -1, 0], [9, 1, -2], [-1, 2, -1], [5, -3, 5], [-26, 3, 3], [35, -1, 6], [39, 1, -5], [-69, 1, 8], [-40, 19, -19], [100, -16, -3], [-161, -3, -10], [101, 17, -19], [-164, 8, -11], [80, 30, -3], [-148, -37, 20], [-174, -1, -36], [-56, -52, 17], [-292, -11, 27], [-701, -10, -3], [-14, -26, 53], [-756, 30, 13], [-464, -3, 29], [-515, -1, 12], [-404, -21, 66], [122, 40, -16], [-1032, 2, -2], [-39, -15, -50], [-538, -14, -20], [403, 41, -30], [-34, 68, 44], [-372, 51, 39], [-697, 9, 20], [-1893, 62, 15], [-1117, 11, 104], [-667, -10, -6], [1528, -22, 85], [-882, 98, -82], [1228, 16, 39], [-2498, -113, 64], [990, -124, 117], [196, -45, -59], [-504, -14, -77], [-367, 6, -103], [1980, -61, -167], [-2308, 48, -106], [3196, 92, -127], [764, -166, 24], [-1850, 98, 220], [-998, 98, -161], [-1827, 68, 8], [3433, 11, -75], [797, 19, -270], [-100, 16, -40], [-5367, -235, 67], [-418, 19, 183], [-2438, 100, -154], [-2018, 234, -328], [3648, 200, -82], [-4402, -184, -6], [3, -47, -132], [-576, 362, -73], [-1666, -87, 279], [-520, -308, 280], [-1476, -417, 85], [7134, 127, 91], [1820, -300, 339], [24, -309, -4], [-1497, -559, 180], [1980, 30, -344], [-2676, 395, -380], [6165, -74, -113], [-3282, -257, 371], [151, -475, -52], [-6049, 403, -231], [3081, 265, 104], [1916, 316, 299], [9715, 90, 118], [-4265, -469, 317], [-1994, 551, -690], [5676, -262, 146], [1926, 92, -420], [-1536, -428, 286], [3856, -412, 60], [-6722, 80, -249], [-2600, -786, 204], [-5446, -8, 269], [9456, -417, 298], [9028, -290, -19], [-7696, 68, 511], [5390, -379, 174], [1512, -54, -622], [10756, -320, 198], [3195, 375, 316], [-6961, 23, -380], [-3532, 302, -266], [1567, 702, -762], [1452, -419, -328], [6725, 486, -210], [-5156, -446, 111], [-14070, 166, -214], [3156, -106, -581], [10828, -255, 663], [-4158, -115, 659], [12374, -380, 584], [-10831, -329, 655], [-11818, -158, 617], [-9837, 331, 842], [2688, 927, -430], [1307, -296, 653], [21291, 195, 92], [-9992, 937, -1511], [8302, 759, -323], [-1138, -914, -146], [20239, -199, -64], [7436, 928, -135], [2416, -572, 516], [-7880, -52, -338], [1540, -349, 752], [-14320, 775, -1461], [13112, 1298, -431], [-152, -724, -137], [1322, -1086, 168], [-7685, -593, -376], [7690, -161, -724], [-5246, 1002, -1541], [-4340, 4, 1640], [-7098, 504, -230], [-14344, -1172, 408], [-11407, 373, 7], [-3617, -214, 463], [-2643, -724, -125], [24754, -316, 76], [5927, 572, -452], [-11946, 78, -1293], [-4411, 564, -818], [20080, -928, 160], [-12192, 1020, 634], [-10438, 114, -1212], [-11642, 1104, 817], [2706, -377, -1548], [22970, -8, 981], [9658, 1383, -282], [-11566, -1206, 736], [-6325, 84, -479], [41650, -22, 245], [-15784, -549, 75], [1673, -1499, 93], [4733, -1174, 1495], [27158, 460, 228], [-42, 701, 1240], [-2627, -981, -770], [-9031, 520, -908], [-41424, 232, -624], [-20735, 1159, -718], [11320, -24, 1003], [-8832, 1315, -287], [-3585, 907, -2170], [18350, 512, 677], [3631, -397, -479], [-12168, 441, -200], [20021, 1545, -943], [36653, 147, 279], [-13733, -1333, 204], [4981, 1522, -231], [-6917, -757, 1054], [2521, -2216, 2542], [-13490, 1816, 373], [-13233, 1841, -2913], [-22962, 400, -1806], [3838, -1472, -507], [1042, -1517, 1097], [-39571, -462, 643], [14024, -224, -65], [-3864, -2444, 1484], [-8938, 1344, 1798], [26618, -589, -1182], [31542, -1412, 468], [21958, -185, -1976], [-23256, 660, 184], [-32453, 283, -976], [2161, 237, -139], [-26112, 392, 1018], [-11650, -2046, 755], [-1357, 1014, -3161], [17933, 1206, 302], [-12136, 1017, -1898], [19570, 1284, 13], [-5948, -1079, 1069], [7182, 2118, -514], [13574, -2583, 3341], [-35687, -1163, -959], [-4136, 438, -1879], [36006, 1412, -1766], [3036, -2013, 1362], [-10821, 138, 1267], [65498, -396, 140], [-7016, -680, 1473], [-14523, 2121, -803], [14314, 2235, 123], [-9964, 1785, -429], [44264, 913, -254], [14043, -2151, 3047], [-54872, 1060, 1585], [-7011, -620, 1819], [-8458, -640, -846], [32426, -128, 2130], [5562, 1367, -2873], [-17150, 1497, 2797], [12805, 2437, -3239], [69630, -517, 586], [54526, -1336, 200], [6766, -2190, 1485], [34351, 2012, -2484], [-41506, -130, -144], [-31730, 736, 1818], [7201, 3203, -1997], [-6590, -750, 2951], [-59950, -81, 1700], [2335, -435, 3218], [43088, 1976, -2602], [28288, 620, -1506], [-27462, 1968, -4344], [77068, -549, -1140], [23589, -2035, 1999], [-29214, 332, -2442], [39742, -1871, 1526], [-3183, -4399, 4127], [-23948, 621, 1933], [-20598, 2814, -2266], [20113, 583, -2806], [9290, -1696, 3384], [33422, 229, -1082], [-11808, 342, 4491], [-5721, -1518, 3578], [-18768, 2142, -2705], [-1592, 1044, 1465], [64988, -896, -224], [27132, -2252, 2189], [24994, -2397, 1537], [-3544, -1507, 2980], [32508, 3091, -78], [1950, 896, -2193], [18296, 1554, -566], [5616, -839, 3486], [-27597, -3631, 816], [-29170, 74, -274], [315, -619, 1347], [18775, -2989, 58], [50272, -2490, -1123], [26228, -3482, 3385], [77332, -1439, 1284], [-38258, 1348, 3626], [10841, 2101, 973], [-13350, 1883, 1282], [66857, -1181, 1800], [-85186, -1478, -377], [6574, -208, -3482], [48254, -2935, 1490], [43386, -40, -3564], [5800, -3535, -888], [25811, -3012, 2881], [-27901, 3261, -1110], [-55328, -456, -570], [-12014, 1188, 3624], [-38008, 3784, -5027], [36767, 1273, 516], [-46564, -5110, 329], [-15362, 3385, -4046], [24943, 2424, -498], [-40726, 1384, 1060], [-28075, 1752, -5773], [15962, 3192, -66], [-17838, 5105, 398], [-24012, 562, 2312], [68552, 3498, 28], [48499, -149, 3194], [-55553, -427, 145], [48101, 3877, -640], [23507, -4007, 4562], [48927, 1241, -1139], [-55982, 501, 2312], [-68967, 2890, -4018], [60602, -2440, -1005], [-36670, 843, 2793], [-75622, 514, -3186], [-64731, -5790, 3183], [29746, 2720, -506], [-101579, 1905, 2566], [-78032, 212, -937], [38383, -2671, 101], [36948, 4452, -1450], [-18838, 3188, -6080], [-26142, -3066, -2460], [19962, 3353, 945], [20374, 1964, -5065], [33553, -741, -7215], [43850, -785, -5944], [-62078, 185, -1707], [-95400, 936, 1547], [-88385, -2771, -94], [-30974, -5858, 2692], [-16112, -4285, 6549], [-23810, -1164, 254], [84766, 1496, 449], [-26376, -95, -3020], [128466, 2526, -1168], [-74851, -4230, 1353], [-34269, 835, 41], [-12046, -3890, 5458], [-74658, 990, 3329], [-11007, -7022, 1546], [-92725, -2349, -84], [-64103, 321, 4374], [115007, -1813, 3431], [35700, 3906, 176], [-47652, 1486, 274], [18818, 2936, -1330], [-80194, -93, 3543], [-59750, -6719, 3095], [51687, 5565, -3409], [-2636, 660, -912], [42637, 2883, -4295], [-34815, 7728, -9314], [-35044, -496, -598], [-62076, 3080, -7656], [-32341, -7197, -764], [37884, 4626, -2870], [-61124, -959, 58], [-67442, -5286, -1501], [-89641, 566, -1319], [49794, -4334, -6123], [-7744, 1448, 858], [-81878, -8506, 1827], [-5194, 2889, 3860], [-32902, 1264, 5602], [23829, 2101, -3606], [-18446, -2482, 5780], [-21563, 946, 3363], [-8407, 4261, -806], [-11698, 3314, 781], [-37095, -748, -2789], [18316, -2292, 248], [-69309, 2035, -1767], [-37946, 1308, -5480], [-80308, 3968, 960], [-91668, -1056, -3540], [-36838, -3512, 3578], [13582, 6291, 129], [-97134, -3021, -95], [29963, 2489, 5854], [-51850, 3222, 4546], [26130, -6967, 1524], [-44893, -4813, 7862], [118068, -4152, 5059], [53311, -3003, 2549], [-76169, -4443, 4269], [23259, -2959, 8349], [24664, 5767, 361], [-74220, -6332, 1600], [-202084, 828, 851], [93859, -2401, 5771], [-40955, 1118, 7052], [-3994, -7459, 701], [92708, -1550, 1905], [-11464, 4887, 3000], [20547, 2192, 5242], [-39509, 4763, -7707], [-63940, -1917, 3589], [75033, -3397, 110], [70518, 5238, -4859], [27098, 2077, -2091], [39601, -20, 3649], [-35825, 7883, -11088], [-46368, -976, 3730], [-81778, 297, 1379], [67394, 4510, -7775], [-118412, -4931, 343], [13499, -1041, -2121], [32775, 1333, -9355], [-3434, 1091, -6206], [-62201, -3151, -3469], [122312, 1441, 3207], [-25987, 5915, -8324], [-110408, -3276, -3682], [66936, 6453, -7261], [7609, 9086, -9480], [24117, -9131, -3343], [9307, -7293, 3136], [71354, -6842, -2020], [64664, 2806, 2818], [85529, -5812, 4038], [-101132, 2458, -9042], [49930, 439, 2703], [70302, 10223, -2065], [75556, -3046, -1673], [42042, 5138, -7520], [-10583, 3239, -4885], [80680, -7714, 14406], [76459, -6511, 9841], [-30140, -828, -940], [-42857, 2285, 8397], [105982, -2050, 5116], [-17456, -3760, 106], [21185, -3208, -6275], [-112402, -3758, 6421], [90278, -5155, -5414], [46641, -2955, 11758], [-60426, -3968, 372], [70550, 10918, -1076], [-16726, -10968, -1743], [-42576, 6679, 821], [137132, -5551, 6137], [148610, -932, 2334], [-114682, -9472, 6025], [-75118, 2759, -4150], [12390, 6282, 4291], [171779, -2279, 5939], [224131, 467, -236], [35670, 14284, -2936], [-101257, 1415, 3371], [-116223, 3331, 3336], [13234, 11372, 294], [-124690, 1714, 726], [-36968, 11390, -9992], [-24172, 10204, 1975], [-17986, 5790, 1914], [-5566, -8010, -2435]];
    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_f();".
// 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_f(:prec:=3)
    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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-2666, -507, 0, 1]>,<11,R![-8044, -1272, -27, 1]>],Snew);
    return Vf;
end function;