
// Make newform 2160.4.a.bi in Magma, downloaded from the LMFDB on 23 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_bi();".
// 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_bi();".
// 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 := [8, -12, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [8, 2, -1], [-17, 2, 2]];
    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], [0, 3, 1], [3, -5, 1], [2, 2, -1], [-54, 5, 2], [19, 1, -8], [95, -5, 5], [-28, -25, -6], [47, -17, -9], [-143, 25, 20], [-187, -10, -9], [255, 29, 3], [-36, -5, -32], [149, -30, -17], [121, 0, 17], [-60, 31, -3], [-12, 3, 31], [41, -30, -53], [-323, 3, -14], [-312, -54, -23], [63, 60, 21], [-315, -60, -15], [231, -1, 28], [-1049, -25, 7], [74, -145, 55], [-50, 80, 100], [918, -130, 40], [-333, 155, -31], [1218, 38, 66], [81, 255, -3], [-1478, -40, -56], [-707, 165, 60], [317, 65, 129], [-1122, 14, 123], [-737, 145, 5], [171, -14, -148], [-2143, 100, -91], [-920, 110, -140], [-2609, 30, -43], [430, -53, 89], [-373, -150, -41], [-1017, 89, 178], [1687, -340, -41], [522, -274, -243], [-1749, -167, -154], [-98, -192, -114], [1449, -190, -97], [-464, -226, -222], [2362, -10, -206], [-3423, -80, 199], [-7, -484, 152], [-1554, 75, -108], [-2613, 165, 219], [-3516, -40, 248], [-258, 275, -226], [-3443, 481, 262], [580, 188, 426], [-5374, -230, 2], [-1350, 276, 22], [-5180, -160, 10], [5233, -179, 97], [-2149, -860, -253], [-2529, -529, -98], [464, 500, 108], [-4205, -871, -262], [-1397, 273, -164], [-2173, -490, 189], [-3272, 831, -323], [-1625, -445, -125], [-284, 1010, -158], [-1180, 955, 165], [-2452, -718, 239], [-1869, -103, 564], [797, -395, -331], [-3706, 445, 638], [-3711, -293, -501], [-11297, 290, 241], [2049, 278, 136], [-8636, 415, 228], [7320, -641, -657], [-86, 230, 808], [3010, 264, -152], [4590, 1688, 486], [1840, -1000, 340], [-1195, 1650, 865], [532, 702, 334], [-257, 1490, 91], [4454, -1037, 171], [2893, -1100, 321], [6863, -50, -379], [4204, -1311, -27], [570, -490, -700], [-10, -252, -154], [9125, 855, -305], [-2159, 55, -873], [-3794, 30, -928], [-3323, 418, -164], [-7864, -443, -161], [2915, 498, 236], [5927, -860, 299], [6436, -850, -968], [-7465, -740, -505], [-11411, -597, 246], [-10157, -2009, -118], [-9538, -440, 44], [-6776, 435, 38], [-13901, 400, 393], [-621, 83, -539], [-10614, 203, 831], [-13960, 1124, 503], [-4645, -995, 545], [-849, 1219, -352], [1063, 1705, 760], [14068, -1210, -284], [4893, 1653, 241], [16341, -950, 127], [-912, 400, 916], [-7178, -1560, -586], [8680, 1599, 193], [-2159, 137, 504], [18753, 1620, 501], [5607, 90, -891], [-6302, -674, -338], [18257, -505, -261], [18182, -505, -715], [10989, 2280, 1083], [19720, -492, -144], [-12916, 984, -1542], [22756, 712, -416], [-3710, 1755, 50], [-6510, 746, 1167], [6624, -2264, -963], [-23602, -200, 56], [16543, 1564, -412], [14917, 920, -1301], [-18457, -1944, -598], [6812, 3500, 444], [2938, 840, 26], [13222, -1162, 506], [19991, -1190, -1753], [1094, 479, -1547], [14219, 4130, 663], [-8216, 1907, -21], [-5630, 70, -690], [-7188, -1368, 719], [-4837, -1920, -419], [23889, 1577, 444], [21320, -345, 340], [3192, -186, -937], [14702, 3660, 1324], [-17132, 2049, 1413], [18729, 1455, -567], [-811, -3224, -108], [-2680, -400, -1920], [21723, -3235, 1515], [-17737, 170, 1761], [13863, -1815, 2270], [-8965, 4415, 585], [-7373, -610, 259], [14008, -3065, 1776], [544, -519, -993], [19678, 1745, 226], [-228, -1705, -286], [5901, 1875, 1587], [10358, 4802, 289], [-11587, 613, 2431], [15343, -1820, -3910], [16115, -4690, -165], [1222, 3665, 1204], [-23264, 912, 2254], [-7485, -810, -765], [-14003, -1687, 786], [26592, 398, 1791], [-15137, -1330, 841], [-2280, -3024, -2348], [13676, 460, 2762], [-15716, -4941, -1917], [18826, -552, -224], [-7478, 4887, 2589], [32744, -60, -1892], [-29477, 3009, 1033], [-22290, 1285, -1190], [-17246, -3460, -1802], [5477, 2880, -2081], [-1690, 2470, -605], [-22537, -1062, 656], [28224, -2743, 559], [49191, 2050, 1327], [-2477, 2739, 1168], [20092, -1170, 884], [31657, -1177, -844], [-31404, 1775, 392], [16865, -1280, -2095], [-22808, -900, -2926], [-10044, 3187, -291], [-38702, -2638, -1701], [-34986, 1200, 3528], [21353, -6030, -689], [10172, -605, 824], [-6167, 5609, 998], [1515, 5283, 1016], [30560, -727, 311], [34954, 1385, -1532], [23689, 8210, 2563], [-3936, 3592, -211], [-32708, 1860, 3674], [-18308, 4040, -2186], [-11289, -2711, 668], [28753, 3223, -64], [26096, -4105, 2472], [-37424, 1571, 587], [1154, 3080, 228], [-10809, 6000, 4797], [-53001, 2708, -884], [-23966, -4514, 742], [-26724, 3540, 3762], [8050, -935, -1980], [23305, -4480, -665], [17758, -3081, -3827], [22517, -3001, -2087], [-21486, -4320, 1278], [-46798, -1068, 674], [3370, 7060, 600], [6016, -3233, -991], [-24124, 5665, 5432], [-36148, 60, 1234], [-41804, 3001, -3623], [6184, -2035, 1468], [-20463, -3837, 3686], [11540, 4914, -472], [-37065, -371, -1177], [-25858, -2280, -356], [30002, -2419, -5273], [-24673, 1660, 899], [63957, 7014, 1928], [20507, 5120, 3519], [36573, -5730, -6129], [-29112, -660, -1284], [-32403, -2070, -4221], [-1727, -3319, -778], [39952, 1813, 2731], [41810, 1711, 3727], [-21903, 6930, -5091], [35282, 4130, 684], [60102, -5051, -2647], [-9833, -7845, 1199], [48868, 1746, -2088], [22808, 4835, 2166], [20397, 6037, -2061], [-38099, 880, -3363], [-50775, 3840, 3885], [-3866, -5875, -1515], [-10460, -5340, 830], [-83194, -2195, -718], [-25984, -5905, -2305], [28319, -4561, -1097], [-1403, 320, 1279], [-29876, 7564, 7538], [13980, -6139, 3537], [18010, -9200, 1320], [57784, 2317, 1319], [-52088, -5704, 987], [-35831, -3685, 433], [43986, 3860, 3150], [-10198, -9900, -1916], [-84083, 4530, -1501], [-69035, 7845, -4095], [10273, 4240, 3561], [48788, -843, 249], [13225, 1828, -4394], [8450, -4920, 600], [56528, 1324, -87], [-53080, 3892, -3926], [-44436, 1453, -5779], [-24932, 650, 1606], [-14936, -5998, -6426], [-18165, -6669, -643], [-110368, -2135, 134], [-51401, 4165, 3273], [4013, -2109, 977], [29766, -7045, -2248], [7742, 11269, 2263], [-50109, -1194, 1492], [-74071, 7750, -2407], [44617, 3477, 2854], [34060, 9590, 3100], [71992, -3450, -825], [-26300, -8020, 1150], [5021, -8995, -4233], [6435, -11410, -4735], [-19332, -2475, 5406], [11722, 1400, 5734], [-103050, 5144, -3272], [17458, -8050, 2746], [-18245, -1581, 1398], [-39855, 1050, 1065], [51738, 4875, 6336], [-2072, -4869, -6453], [56597, -8489, -668], [6039, -9730, -3847], [34381, 5743, 2881], [2674, 13910, -302], [-51793, -2079, -58], [-2232, -2284, -9638], [-37985, 6110, -5105], [18000, -11383, -5921], [-11722, -650, -514], [54986, -11438, 1549], [39690, -4155, 1710], [-32640, 3210, -4380], [-4057, 2020, -5599], [65243, -3298, -956], [41717, 195, 1219], [7001, -13591, -3457], [4262, -7805, 5114], [-33504, -990, 6642], [-77746, -1010, 7000], [-137660, 500, 3190], [-53369, 8985, -1980], [-2193, 2867, 6634], [-57984, 8435, 8402], [-10308, 16148, 9036], [-18602, 12035, 1576], [-34801, 15980, -3670], [-30802, 3476, 7822], [-13480, 2904, 3548], [-30907, 5755, 4451], [-62714, 7570, -228], [11018, 14665, -1415], [37093, 9940, 1431], [-19712, 7794, -4707], [-140709, 6740, -283], [-61002, -1208, -3286], [-75183, 4460, 8819], [-43878, 6725, 2875], [48172, 12120, -2746], [-103159, 6645, 5415], [-13038, 6102, -4406], [-37588, -9562, 251], [44287, 8295, 8849], [32391, 7260, 7437], [-74252, 9752, -6091], [21412, 16420, 7164], [-48068, 14135, -2816], [68062, -11972, 476], [13100, -888, -256], [-10056, -10320, -3372], [-40452, -3860, 1126], [65749, 1565, 4310], [-23463, 15045, 710], [-41661, 3685, 463], [-18252, 10874, 5748], [-2578, -2339, 2827], [-12883, -12815, 359], [563, -690, -8279], [-12924, 12825, -5598], [87244, -10255, -5102], [36402, 9235, -1616], [-85223, -7851, -5912], [71852, -9420, 7444], [-4481, 9770, 6553], [-39162, -10745, -6854], [51769, 366, 2982], [-32571, 703, -1164], [-11311, -560, -5767], [93712, -2977, 4961], [120389, -3804, -6138], [-177656, 4655, 2548], [17747, 8149, 2958], [-94675, -5185, -5055], [20271, 10680, -1623], [-14209, -14873, -5946], [25942, 13260, 11755], [99899, -6835, 573], [-738, -7680, -2406], [-76913, 2167, 7094], [-83333, 5900, 4369], [12729, 24751, 1902], [201984, -5195, 628], [100236, -10935, -6558], [-13816, -6633, -6661], [18786, 2665, -11408], [-2623, 11935, -3450], [-48537, -12605, 1051], [14298, -13448, -646], [-183801, 4511, -428], [66629, -13682, 726], [-55240, -6545, -5920], [7617, -8841, 7223], [26394, -10570, 6218], [-14862, 8170, 7456], [57443, 11288, 7066], [258330, 10, -920], [-5497, -1203, -5316], [61973, -3283, 4354], [471, 2220, 11067], [-56770, 9354, 11258], [17594, -8315, 1568], [82222, -7974, -9068], [177908, 15565, 3746], [-97668, -5860, 1380], [8300, -775, -1350], [-33138, 16990, -5966], [-51906, -7564, 11442], [5810, 4992, -6261], [-116361, 13300, 6133], [-141350, -2275, 3575], [38947, 18815, 10309], [38406, 12, -10456], [-65142, 20010, -6834], [-16817, 450, 15251], [-142293, 5109, 2158], [-53281, 13467, -10596], [-17328, -28960, -7306], [-70349, 9610, -14493], [76128, -21529, 4947], [71181, 1860, 6927], [29072, 3855, 1714], [-27827, 7275, 5171], [55290, -24248, -3816], [182280, 16005, 2400], [160437, 12745, 3829], [-13404, 10556, 13402], [127172, -18030, 12304], [-106828, 10770, 13294], [-63953, 20510, -4271], [101920, -4914, -11688], [18287, 27200, -2451]];
    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_bi();".
// 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_bi(: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_bi();".
// 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_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![8298, -795, -4, 1]>,<11,R![31260, -2888, -5, 1]>],Snew);
    return Vf;
end function;