
// Make newform 2160.4.a.bm in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2160_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_2160_4_a_bm();".
// 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_2160_4_a_bm();".
// 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, -23, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-61, -4, 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_2160_a();"
function MakeCharacter_2160_a()
    N := 2160;
    order := 1;
    char_gens := [271, 1621, 2081, 1297];
    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_2160_a_Hecke(Kf)
    return MakeCharacter_2160_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], [-15, -1, 0], [-12, 1, -1], [8, -5, -1], [-6, -1, -2], [-65, -7, 1], [22, -16, -1], [61, 21, -2], [-70, 15, -2], [16, -32, -2], [-107, 21, 4], [-21, -39, 2], [153, -14, -1], [175, 7, 3], [-34, 41, 3], [207, 30, 4], [-282, 26, -6], [190, -17, 15], [430, 11, 15], [-207, 11, 3], [414, -60, -15], [711, -33, -12], [474, 32, 2], [-268, -104, 16], [-262, -136, 14], [215, 100, -5], [834, -112, -7], [-405, -58, -5], [372, 54, -4], [-1416, 72, -18], [-1861, 1, -17], [952, 144, -36], [1255, -105, -20], [693, 0, -7], [1060, -17, -35], [2466, 88, 28], [-1253, -28, 32], [-946, -17, -20], [2264, -154, -18], [-206, -296, 49], [-1148, 28, 6], [36, 215, 83], [-1981, -77, 1], [708, -138, -34], [3426, 121, 10], [610, -360, 0], [-915, -406, -14], [-3158, -114, 5], [-4, -32, -2], [-180, 94, -40], [494, -554, -55], [-492, 246, 54], [-1971, -345, 63], [1389, 134, 67], [588, 290, 4], [70, 23, -38], [-458, -249, 131], [1063, -145, -46], [663, -385, -36], [4583, 349, 7], [1006, -28, -32], [-2330, -331, -85], [3822, -370, -64], [-7676, 45, -14], [4000, 202, 26], [4522, -685, -39], [4270, -84, 190], [4303, -76, 78], [-1012, 58, 64], [4496, -830, -32], [5735, 279, -50], [-2770, -182, -100], [2022, -411, -58], [55, 578, -58], [-683, -943, -4], [2316, 627, 103], [3290, -560, -80], [7074, -124, 161], [8000, 1245, -145], [-2793, -24, 28], [-6292, 493, -11], [7828, -19, 189], [624, 873, 266], [-9586, -722, -41], [4435, 1069, 60], [5206, 1250, -192], [-3664, 946, -92], [5462, 834, -14], [8807, 90, -148], [-4520, -979, 95], [3931, -195, 258], [-5442, -382, 94], [-5218, 877, 60], [11404, 556, -135], [4904, -1464, -268], [269, -451, 12], [-4061, 1001, -8], [5129, -232, 151], [2051, 769, -222], [1978, 1850, 194], [353, -1076, -11], [4771, -73, 98], [3712, -1275, 138], [11362, -41, -149], [-5828, 260, -175], [-1921, -1549, 369], [3320, 1167, 275], [-12888, 266, -67], [-681, -1167, -178], [-23386, -536, -58], [-539, 83, -91], [312, -2210, -62], [-2921, -601, -371], [1766, 1048, 358], [2595, 845, 0], [10173, 82, 440], [-11892, -221, -328], [-12106, 1385, 207], [-9065, -940, -159], [5944, 1287, 227], [-10263, 1182, -39], [-10731, -816, -456], [2830, -2179, 298], [6352, -996, -194], [-16735, 1468, -73], [11766, 684, 48], [2560, -1794, 450], [-9736, -2088, 432], [-3866, -817, -452], [278, -2572, -366], [3501, -249, 251], [-19314, -1830, -62], [-17747, -349, 44], [-2018, 292, -623], [6146, -2417, -350], [1673, 1939, 354], [-10025, -2115, -101], [26939, 365, 162], [-9047, 3736, 113], [-21350, -2080, -220], [-5455, 893, 20], [6865, 3606, 64], [-7091, 1770, -511], [1508, -2190, -526], [-3762, 3286, 444], [10510, 1393, 216], [-13854, 807, 272], [10222, 2410, 573], [-18648, 1345, 351], [9607, 3859, -474], [14359, -4221, -318], [-7386, 402, -99], [1394, 708, 562], [-26138, -429, 1], [-10818, 1212, -166], [2053, -243, 4], [4368, 2542, -6], [8530, 3708, 220], [-11824, -1988, 607], [13670, -672, -400], [-3830, -4560, -420], [11858, 184, -416], [-1650, 4058, -110], [-28206, -1326, 45], [-16315, -1969, -193], [-17608, -271, -209], [16804, 1930, 163], [-13310, 3327, 172], [9512, -824, 556], [-12035, 3134, 528], [-20298, -351, 171], [21886, -3768, -142], [-33945, 3435, 341], [37835, 1159, 130], [5295, 1337, 93], [-8069, -4045, 218], [7021, -3351, -552], [-26645, -40, -747], [-7349, 3051, -192], [-8408, -3110, -354], [-35978, 2168, -84], [28983, -1214, -361], [-27391, 4192, 124], [7918, 4492, -426], [-5536, 1733, -203], [-23332, -314, -186], [21162, 1802, -205], [3372, -5687, -259], [14236, 3452, 138], [-5029, 764, -780], [-17891, -557, 935], [-26502, 2156, -626], [3394, -3124, -139], [-6028, -1951, 648], [6084, -3114, -515], [22816, 4950, 98], [-27024, -1818, 708], [1045, 2884, -195], [65635, -439, 230], [-2774, 2098, 572], [2628, -2024, -186], [36989, -1772, 326], [-14698, 1435, 1], [-21988, -2744, 706], [12774, -1718, 1144], [-4153, 4754, 864], [33620, -80, -320], [4860, 1024, -656], [6880, -2909, 415], [-32009, -4137, 88], [-34556, -44, 632], [-17933, 2604, 511], [16782, -1068, 1086], [-14241, 8426, 824], [27427, -943, -794], [-57000, -1884, 300], [3323, 1914, 158], [12044, -2999, 394], [-4166, -2596, -1164], [18923, -2089, -205], [72957, -981, 36], [56897, -377, -354], [-1498, -2556, -523], [-28118, -7244, 307], [-64151, -1147, 29], [47920, -1433, 1065], [12580, -442, -140], [23138, 3064, -506], [-27180, -2039, 495], [48731, 5191, 447], [39648, 400, 880], [3838, 1240, 1044], [-28195, -1747, 350], [5029, 1730, 986], [12870, 3238, 51], [-28718, -801, -1016], [41292, 2460, 126], [49788, 1791, 369], [-56283, -3924, -279], [-37175, 4735, -367], [28618, -4006, -986], [9596, -1672, -341], [1470, 5406, -1410], [6760, -906, 760], [1704, 7066, -458], [11630, -325, -1395], [-7874, 2760, 330], [-21977, -7200, -134], [59604, 3954, -728], [-16792, 4182, -436], [-20526, 342, 483], [64363, 1446, 500], [-6664, -2653, 1080], [50596, 8252, -952], [-19369, 8884, -430], [18563, -8419, 464], [33065, 4531, -1331], [30250, 3349, -5], [41823, 5487, -1156], [-613, -2178, -1498], [12862, 6400, 895], [-8924, -7356, 788], [41117, -3833, 1375], [-31116, -5184, 584], [44950, 5188, 1410], [-20674, 2432, -492], [23884, 2940, 1182], [-54628, -4902, -4], [-39421, -3876, 984], [-11966, -7702, 1222], [24260, -6501, -1335], [49448, 6219, -680], [78272, -1237, 481], [5541, 7501, -62], [19052, 2566, 1195], [-36731, 5940, -364], [39480, 676, -657], [-14342, -4471, -871], [-70423, 9072, 581], [-5401, -9269, 15], [-48165, -8446, 1474], [33665, 3188, 1642], [13020, 8408, 720], [3616, -1075, -427], [69760, -22, 2220], [-60340, -1640, 730], [-24350, 1911, -1536], [-48766, -7292, 1102], [87196, -3564, 448], [-20460, 9722, 151], [-7776, -6276, 522], [-39928, -5126, 1216], [-1218, -5683, -79], [-82720, 1402, 490], [70411, -5121, -525], [17820, -3720, 510], [40914, 11028, 222], [6523, -207, 1224], [96344, 2447, -503], [-46596, -12187, 406], [59926, -6160, 526], [-11584, 4156, 1891], [-52891, -8261, -1341], [-3198, -4447, -1279], [111245, 8488, -875], [-30678, 1694, -3283], [-14720, 8699, 545], [17618, -10387, -11], [-53175, 6618, -918], [-36690, -4206, 240], [6124, -2746, 2342], [58529, 9287, 512], [117064, 1132, 63], [56957, -3650, 860], [6058, -16576, -406], [-23790, -1593, -1485], [30710, -2371, 835], [11240, -2480, -1730], [71587, 4869, -537], [136476, 4202, -142], [29388, 2294, 1114], [-6396, -678, 2042], [101261, -647, -989], [90371, 8836, -523], [87827, -3397, -1255], [23498, 3526, -1116], [83584, 1352, -208], [-92479, 519, 1295], [29882, 5924, 2332], [-41296, 5556, 1322], [-27539, 4236, 1581], [44289, 3122, 3007], [72720, 1138, -554], [-62487, -6340, -1451], [112362, 11018, -715], [-20728, -3421, 1224], [-3673, -4542, -2373], [-49701, -9175, 402], [49004, -4178, -1498], [19490, -4435, -756], [-85227, -1899, -486], [-51830, 4477, -598], [-13231, 14682, 1997], [-114868, 10435, 721], [20875, -4964, 1408], [6878, -3218, -1236], [76350, -11022, -1920], [7686, -4187, -1486], [14695, 3076, 539], [-117576, 11590, 1212], [22587, -14627, -1564], [117594, -2226, -508], [-2539, 3866, 1885], [-6524, 15191, 1400], [-28922, -9011, -2001], [-151176, -3561, -1293], [-1564, -10886, 748], [-79038, -6086, -931], [88354, 1457, -573], [48952, -4994, 2556], [-14563, 11182, 811], [108462, 1426, 506], [29848, 9246, -1626], [-126882, -1233, 169], [-96743, -1567, -1813], [9634, 2932, 1112], [-25990, 660, -444], [-26416, -9386, -908], [28202, -12903, -968], [-79316, 4638, 1225], [38517, -12063, 156], [-79576, 6123, 2440], [-73478, 2978, -1224], [67420, -11112, -350], [7710, 16596, 1320], [30496, 9709, -1817], [19472, -3578, 556], [-9498, -3474, -2894], [149298, 9274, -916], [-146739, -10887, 981], [-129151, 205, 162], [168576, -3605, -556], [-75424, 3834, 2410], [-26937, 934, -2431], [-44865, 7189, 487], [8046, -8569, 2513], [-109249, -6975, -482], [-1868, 776, 1916], [20691, 12784, -1539], [-6396, -4861, 1540], [-106590, -20744, 920], [-61258, 13604, -184], [35628, -7130, -16], [-91258, 11661, -519], [50678, -4519, -382], [92421, 1929, -702], [-166771, -9305, 1059], [103966, 3350, 2588], [54322, -10900, -2772], [-39188, -16150, 2876], [141987, -6879, 1556], [4930, -26832, -20], [-58443, -12089, 3116], [-145500, 9867, 632], [11696, -5952, -2622], [74724, 9394, 1052], [-12950, -13958, 260], [-16522, 20647, 2749], [-140556, -5480, -738], [-7044, -8349, 2262], [-16012, 4010, -2973], [2148, 18923, 96], [-40108, -5682, -444], [-94641, -12787, -2228], [127334, -7422, 242], [312, 5928, 416], [61059, 12009, -549], [-104867, -9488, 1812], [16988, 5078, 234], [-95478, 10806, 346], [49617, -780, -4020], [-75174, 21346, 338], [92544, -8086, -88], [-163085, 16993, 2031], [156739, -7262, -1830], [-16726, 26956, -8], [94669, 1461, 105], [42334, 69, -1703]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2160_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2160_4_a_bm();".
// 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_2160_4_a_bm(:prec:=3)
    chi := MakeCharacter_2160_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_2160_4_a_bm();".
// 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_2160_4_a_bm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![1800, 552, 44, 1]>,<11,R![-83280, -2612, 38, 1]>],Snew);
    return Vf;
end function;