
// Make newform 2116.4.a.a in Magma, downloaded from the LMFDB on 11 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2116_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_2116_4_a_a();".
// 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_2116_4_a_a();".
// 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, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-5, 1, 1], [5, 1, -1]];
    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_2116_a();"
function MakeCharacter_2116_a()
    N := 2116;
    order := 1;
    char_gens := [1059, 5];
    v := [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_2116_a_Hecke(Kf)
    return MakeCharacter_2116_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]];
    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], [-1, 0, -1], [4, 1, -3], [18, -5, -3], [16, 5, 11], [-9, -11, -6], [42, -33, -5], [18, 24, 16], [0, 0, 0], [105, -1, -6], [-69, 8, 59], [12, -65, 3], [203, 27, -52], [184, -62, -12], [-1, -72, 47], [-126, 64, -42], [4, 94, 38], [378, 14, -96], [632, 51, 61], [155, -58, -47], [-91, 89, -68], [254, 134, -176], [374, 97, 185], [-104, 16, -238], [-194, 23, -177], [314, -362, -278], [730, -15, -1], [-158, -82, -10], [-432, -160, 56], [482, 11, 227], [-387, -150, -73], [-561, 460, 319], [-1276, 26, -20], [-863, -68, 81], [522, -42, 188], [635, 374, 201], [1436, 146, 538], [1073, -232, -447], [812, 62, 258], [-3566, 216, 40], [1045, -66, 443], [2564, 107, 67], [456, 827, -101], [-1399, 655, 538], [917, -259, -20], [756, -33, 899], [1440, 666, -226], [-2516, -648, -220], [2986, -781, -285], [-2516, 468, 192], [659, 463, -348], [255, 100, 67], [-2496, 469, 695], [1366, 909, 597], [3055, -109, 200], [-3254, 814, -224], [3689, -817, 90], [-1880, -320, -1008], [-295, 221, 144], [-1714, -79, 1285], [2628, -355, 807], [-628, -438, -774], [-5956, 366, -390], [-3289, 178, 697], [4900, -716, 78], [378, -754, -1338], [573, 212, 1509], [1968, 1600, -1366], [2400, 1012, 1700], [5869, 313, -1224], [-1967, -331, 424], [-1278, -562, 572], [3578, 669, -1297], [-2312, -953, -2441], [-4732, 612, 1158], [5172, 1256, 1220], [812, -78, -1666], [3267, 1703, 0], [4012, -107, -133], [4141, 1649, 2816], [-2436, 976, -1358], [-190, 1345, 1219], [-8788, -582, 1298], [-4660, 1245, 2043], [2473, 2872, -879], [1347, 818, 693], [-2618, 1948, 1188], [-9898, 3403, 1019], [-6211, 2433, 2264], [-5788, 3144, 1684], [2290, -3220, -2732], [4618, -727, -2489], [7517, -524, -319], [-2511, -1700, 421], [-2649, 342, -2059], [5054, -1378, -2240], [-5215, -2595, -1624], [9864, -2988, -958], [10974, -63, 497], [4065, -2623, 212], [-14595, 100, 1957], [1176, -702, 490], [-508, 994, 712], [6916, -147, 2955], [-5290, -1725, -1037], [-2567, 1375, -874], [-3861, 2338, 3569], [5242, -4204, 1176], [5912, -2192, -2824], [-2919, -2597, 2346], [-10176, -3314, 1478], [2706, 477, 1619], [-1582, 3358, 4938], [1172, -2916, -150], [-11752, 450, 106], [5568, -6072, -1882], [9380, 3951, 2217], [12371, 212, -1369], [-1169, 3999, -1892], [-7698, -751, -559], [-614, -266, 3608], [5439, 313, -450], [12902, -654, -2404], [6765, -182, -989], [-7196, 4764, -1780], [-8506, 5955, 1829], [-6626, -811, -1429], [-17176, -1684, 292], [-11228, 2761, 1205], [-11006, 765, 1703], [-9759, -1082, -3009], [1862, -2349, 1013], [-4716, -1698, -1782], [920, -2909, -2505], [-27047, -19, 2712], [11792, 3749, -73], [-25008, 2074, 2466], [17680, 484, -1714], [-18186, 3284, -1766], [-14786, -3496, -1404], [-25481, 2620, 1503], [12942, 80, 1160], [-3773, 4102, -2335], [-5588, -5648, 2426], [16698, -4374, -4974], [20346, -3995, -4733], [-21818, -1530, 3726], [22987, -7929, -1436], [-24677, 2118, 3921], [29069, 2544, -2195], [-9178, -1878, 7502], [-9346, 5493, 4481], [16268, 2816, 1864], [-7737, -2906, 5413], [-7222, -334, 518], [-22846, -84, -2654], [26310, 5047, -4323], [-14009, -4047, 3886], [448, -7353, -8155], [8678, -10687, -2897], [-865, -8522, -5331], [10470, 854, 594], [27305, -9078, -2061], [4010, 2022, 90], [9316, 6921, 1423], [2534, 2328, 842], [-584, 5672, 5096], [-9854, 3016, -632], [-7230, -7362, -842], [2759, 5777, -1330], [6244, -3157, 2041], [-1003, -2437, 1986], [1650, 8521, 11775], [-35096, 3330, 764], [11341, -1830, -625], [10234, 5097, 11401], [9545, -10068, -747], [15575, -1683, 2666], [-15402, 7690, 4776], [-638, 4687, -4031], [-2327, -4440, 10889], [1060, 982, 8872], [-8519, -5063, 2812], [8678, 9100, 9912], [36860, -661, -5577], [48694, -581, 965], [-27674, -2958, -6238], [-14262, 1146, 8838], [-38287, -4541, -8150], [-5992, -2480, -7504], [20207, -8041, -10276], [11192, 2150, -406], [-33876, -7511, 555], [19726, -1308, -5940], [1496, -2877, -2595], [-15152, 6488, -7254], [-42396, -2055, -5437], [21900, -462, -11086], [-27092, -280, -8338], [26737, 7676, -3067], [14300, 6036, 14336], [11888, 9404, 7780], [-26811, 14301, 6844], [372, 3457, -525], [34984, -300, 1486], [46085, -4765, -654], [-28116, 6599, -1877], [15579, 1984, 2679], [24819, -10521, 1416], [15533, 3638, 4835], [32879, 5283, -9472], [4907, -7477, -12660], [-38404, -578, -3206], [-14758, -6994, -5742], [-19268, 11856, 5748], [-2720, -10174, 3912], [-46309, 2602, 2429], [-43619, -4953, 1798], [-1476, 1655, -577], [-23113, 9299, 4960], [-41741, -789, 5956], [23944, -3759, 1493], [10837, 9113, -1896], [-7018, 8141, 14407], [-47637, -1942, -907], [-14809, 22731, 4832], [2480, -2755, -1581], [53569, -15450, -1601], [27150, 10570, 6552], [-9176, 21308, 6628], [442, -19776, -13552], [23930, -13467, 3709], [30056, -14433, -2397], [-62498, -1184, -24], [-7716, 3210, 14368], [-61450, -6285, 7217], [-49980, 7564, 2222], [42316, 10145, 6553], [60443, 8018, -8247], [10057, -12282, -10465], [20224, 11630, -14000], [33599, 1804, 13651], [-31337, -3244, -4669], [183, -19927, 382], [40562, -16104, -11272], [40391, -2664, 11567], [-16841, 22238, 6133], [21170, -12086, 2314], [20318, 6064, 8248], [19756, 7741, 22589], [15898, -1655, 6743], [16620, -8341, 4677], [20446, 13152, -986], [-9654, 3509, 4869], [-16598, 2668, -736], [30281, 11206, 13247], [36312, -3087, -1651], [16856, 6153, 8475], [70713, 7397, 6816], [15965, -13899, -780], [22496, 658, 10874], [51516, -1270, 1676], [-24702, -7200, -3008], [67738, 6561, -6273], [-12494, 17448, 13048], [-32178, -2998, 22922], [11948, -5997, -15197], [11604, -20430, 9920], [44578, 5584, -6348], [26469, 1077, 9748], [1317, -14557, 2314], [11814, 10970, 16906], [-13160, -4474, 1560], [-13630, -1329, -14371], [-18559, -2393, 1506], [15111, -2930, -12515], [13736, 8454, -4174], [-15218, -12692, -6348], [66248, 3103, -7971], [31300, -12008, -20314], [-29711, 4484, -13395], [27800, -873, -11189], [54756, 87, 14139], [20814, -1264, 11982], [3492, -11458, -6310], [35180, -3410, -23166], [34758, -760, -116], [-9790, -5942, -24100], [15156, -14390, -10114], [-5938, 13010, 19642], [41542, -34786, -13048], [22018, 15577, 5261], [-5694, -1708, -9808], [-20282, 12658, 7178], [-80327, 6709, -4128], [-71654, -13524, 14266], [-47314, 32033, 14903], [87711, -21139, -70], [64073, 8846, -8921], [55753, 748, 12137], [18366, -7689, -11457], [-56394, -10326, 23808], [12014, 4189, 3307], [63397, 7856, -19439], [-13080, -26484, -7030], [9707, 11903, 20580], [-80364, -6084, 2592], [-68536, -4462, 21354], [-71316, 8961, -12375], [13346, -21880, 13644], [50399, -32048, -15073], [-70710, -7926, -4136], [79014, 7915, 13411], [-39603, -11014, -10605], [-67522, 20152, 2882], [49546, -4293, -26781], [-3051, 4066, 26391], [13367, 3994, -8671], [-144304, 4670, 4904], [22827, 14141, 2902], [23004, -7212, 17962], [52962, -25575, 9733], [34107, 18195, 24308], [-6460, -2674, 4242], [-19992, 40117, 10399], [-98756, 17320, 11570], [13056, 8873, -21321], [-43231, 32288, 5421], [25364, 8071, 11551], [78970, -2253, 20433], [-58343, -8887, -18668], [21215, -17397, -33424], [20069, -2920, -15715], [-38319, 33696, -3603], [6758, 12714, 8578], [-17783, 2796, 16733], [2048, 7441, -22423], [170886, 3997, 5841], [100955, 20967, 13860], [12640, -4538, -16610], [69243, -12617, -7944], [102416, 3482, 18488], [-40338, 29878, -4090], [18554, -16310, -1112], [-4376, -11133, -39889], [-56632, 3982, -23210], [-40629, 8749, 254], [-7524, -24380, 1600], [110130, 6158, -8860], [111028, -3633, 11763], [29291, -39276, -9793], [-82967, -4767, 13704], [-72934, -6504, 2552], [-19638, -28428, -25958], [11450, -43837, -5223], [-71866, -5436, -4480], [-42666, -33571, 11199], [88552, -741, 17869], [87005, 7649, -16392], [49272, -28066, 8254], [-3200, 21467, -11081], [65, 39307, -6094], [-108711, -23292, 31141], [-91144, -3849, 16709], [-4351, 20672, -21123], [55665, -12099, -12852], [30903, -21613, -27864], [53956, -3691, -6735], [-177402, 2440, -4836], [87665, 24008, -999], [-37892, 10084, 38024], [147355, 3824, -23069], [22558, 6731, -40083], [4676, 40510, -20606], [-167701, 12445, 1398], [71385, 2240, -23963], [21956, -32063, -42003], [81790, -42350, -5390], [60924, 18998, 6464], [38363, 4737, -40666], [-24840, 42281, 17189], [-5338, -8594, 2154], [-87296, 35532, -7884], [-26829, 31581, 17502], [99142, -5485, 23459], [-3003, -12022, -38001], [147297, 14684, 22717], [-66006, 27856, -5992], [13924, 24079, 61], [-19818, -21565, -15791], [67914, -4353, -16633], [-56658, 10724, 5592], [-48961, 58568, 24187], [67220, -48672, 4240], [-62406, -25987, -38185], [-18836, 37479, -4723], [-66120, 59478, 9590], [-96298, 10833, 1841], [111990, -5569, 13915], [-4506, -15602, 9006], [-4481, 13267, 10456], [-60303, -25527, -25072], [34858, 3309, -49769], [99330, 2951, 2851], [-97693, 1019, 17868], [-32873, 31516, 36491], [-84386, -9260, -3038], [-20199, 46337, 45520], [-78262, 7365, -20867], [-50032, -9148, 32308], [97367, -16311, -626], [65259, 22733, -26794], [56196, 3617, -38065], [29466, 11880, -35392], [-334, 26890, 44646], [-100863, -9699, 27432], [-99564, -4672, 22364], [-219760, 3710, 10622], [-84780, -30744, -14694], [74456, 13138, -29938], [-91326, -15969, -22715], [23456, 6036, -39160], [-93292, 68476, 15552], [228836, -3012, 14516], [100037, -12637, 20898], [-10377, -13679, -10402], [-160514, 26228, 20268], [-96394, 26766, 28866], [-17097, -48602, -57311], [-143229, -15270, -8291]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2116_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2116_4_a_a();".
// 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_2116_4_a_a(:prec:=3)
    chi := MakeCharacter_2116_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_2116_4_a_a();".
// 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_2116_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2116_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-24, -17, 4, 1]>,<5,R![2096, -228, -10, 1]>],Snew);
    return Vf;
end function;