
// Make newform 119.4.a.e in Magma, downloaded from the LMFDB on 08 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_119_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_119_4_a_e();".
// 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_119_4_a_e();".
// 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 := [36, 1814, 2515, -4674, -1087, 880, 90, -53, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0], [-12, 0, 1, 0, 0, 0, 0, 0, 0], [2882012, 6476646, -21032277, -17876225, 2133388, 1728180, -35990, -40561, -725], [22936788, 48031426, 19278413, -13086287, -5557212, 843788, 358366, -15479, -6667], [-31983300, -14331138, 83597339, 13150919, -14101860, -1229500, 785794, 28847, -14061], [-38173324, -49932190, 146349677, 32413121, -29732012, -2952436, 1904318, 68585, -37659], [-33613820, -184262226, 178532379, 59074311, -35178740, -4509364, 2163922, 96807, -41373], [78172932, 252728866, -379731379, -101674127, 75914692, 8174940, -4686210, -178135, 89413]];
    Rf_basisdens := [1, 1, 1, 3388208, 3388208, 3388208, 3388208, 1694104, 3388208];
    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_119_a();"
function MakeCharacter_119_a()
    N := 119;
    order := 1;
    char_gens := [52, 71];
    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_119_a_Hecke(Kf)
    return MakeCharacter_119_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, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1, 0, 0, 0], [-1, 1, 0, 0, 0, 0, 1, 0, 0], [7, 0, 0, 0, 0, 0, 0, 0, 0], [-2, -1, -1, 1, -2, 3, 0, 1, -1], [18, 4, -1, 2, 2, -1, 0, 0, 1], [17, 0, 0, 0, 0, 0, 0, 0, 0], [30, -10, 7, -2, 2, -5, 0, 4, 1], [2, -16, -4, -4, -4, 4, 0, 2, 0], [-28, 9, 3, -3, 10, -3, 6, 1, -1], [69, -20, 6, -7, -4, 2, -5, -1, 8], [-38, -11, 3, -11, 14, 5, 12, 15, 7], [1, 1, -18, -7, -16, -15, -6, -3, -8], [-13, 5, 14, 5, 0, -9, -8, 3, 8], [-12, -2, -8, 0, 4, 6, -12, 0, 0], [15, 6, 6, 11, -4, -38, 5, -7, 16], [10, 34, 21, 18, -18, 35, -20, -2, -9], [97, -46, 16, -20, 16, -75, 16, 20, 8], [17, -14, 2, 1, 16, -22, -13, 9, -16], [-176, -12, -14, 0, -16, -20, 0, -22, -14], [103, 15, -32, 11, -4, 25, 18, -13, -2], [256, 42, -28, -16, -12, 6, 12, -4, 40], [270, 36, 7, 6, 14, 29, -20, 20, -15], [326, -18, 30, -54, 28, -66, 30, 22, 10], [305, 136, -60, 37, -16, 48, -17, 1, -38], [-20, 200, -37, -18, -30, -155, -6, 8, 9], [256, 58, -52, -8, -12, 96, -40, -26, -40], [310, 99, -37, -35, -6, 93, 24, -17, 15], [366, -161, -55, -7, -18, -101, 34, -31, -15], [-182, 220, 50, 32, 4, 110, -58, 4, -18], [-305, 124, -30, -27, -28, 134, 1, -39, -88], [-238, 263, -118, 85, -104, 190, -38, -115, -72], [-419, 197, 24, -21, 60, -1, -32, -47, -22], [123, -255, 14, -56, -16, 74, -15, 58, 26], [133, -121, 12, 129, 8, 159, -36, -97, -90], [423, -29, -8, 7, 20, -79, -40, 89, 70], [642, -210, -39, 30, -10, -55, 50, -78, -17], [-954, 277, -71, 141, -2, 205, 22, -77, -119], [-761, -199, -94, 51, -24, 31, -110, -53, 56], [-799, -32, 168, -150, 92, -63, 132, 106, 136], [-1115, -275, 170, 121, -24, -75, 24, -5, -56], [196, 249, 106, -61, 64, -198, 58, 91, 16], [-923, 128, -84, -49, 32, -68, 63, 51, -10], [-628, 176, -84, 14, -28, -78, -12, -116, -16], [0, -709, -69, -15, -10, 149, 68, -101, -9], [27, -199, 226, 7, 52, -225, 134, 35, 32], [1010, 141, 95, 79, 122, -221, 26, 3, -41], [572, 572, 28, 80, -64, -246, -136, -82, -80], [-233, -611, -200, 68, 8, 188, -87, -66, -8], [678, 72, -243, 62, -90, -217, -52, -38, -53], [-82, 218, 188, -82, -108, -170, 48, -28, 24], [-445, -433, 34, -145, 52, -433, 16, 1, 64], [1801, -34, 26, 139, -124, 474, -73, -77, -176], [-710, -104, 55, 60, -30, -249, -248, -2, -75], [428, -4, 130, 20, 44, -114, 52, 46, -226], [-564, -816, -166, 160, -48, -22, -268, -72, -142], [-1344, -813, 36, 89, 28, 160, 38, 53, 46], [890, -502, -296, 42, -56, -124, 120, -156, 48], [-440, 193, -349, -267, -42, -257, 148, 63, 87], [1213, -278, -96, -231, 108, -136, 119, 195, 246], [57, -85, -362, -8, -184, 186, -61, -226, -202], [1682, 126, 257, 150, -42, -313, 4, -60, 155], [-490, -192, 285, 92, -14, 469, -78, -158, -145], [1207, 354, -70, 33, 244, -62, -203, 175, 52], [-107, 228, -120, -171, 308, -136, 83, -31, 118], [1068, 469, 173, -65, 170, -405, -106, -39, 65], [651, 446, 300, 3, 128, -400, 61, -5, 270], [1718, 172, 404, -94, 136, 102, 238, 114, 128], [-1148, 399, 47, -93, -318, -241, -160, -33, -33], [244, 1450, 23, -64, 50, 113, 124, -122, 29], [1088, -430, -88, 188, -240, -144, -288, -40, -188], [-617, -12, -16, 77, -184, 12, -275, -7, -190], [1971, 667, -198, 129, -196, 487, 30, -331, -116], [-3077, -549, 70, -67, 292, 23, 312, 203, -120], [2826, 171, 59, 25, -274, -581, 288, 13, 35], [-750, -204, 172, 284, -36, 542, -26, -84, -28], [135, -768, -94, -327, 64, -406, 321, 243, 176], [223, 579, 468, 334, 84, 52, -323, 62, -128], [386, 534, -638, -446, -64, -308, -152, 164, 162], [1628, -236, 676, -54, 392, -508, 126, 258, -24], [709, 777, -582, 18, -36, -634, -33, -4, 10], [2975, -481, -134, -295, -96, -469, -168, -89, 120], [100, 72, 238, 296, -180, -432, -374, -94, -86], [446, -432, 28, -334, -192, -390, 120, 406, 332], [845, -683, 442, 455, 76, 133, -362, -117, -268], [-3452, 466, 78, -222, 300, 462, 180, 50, 222], [4364, 236, 504, 392, 60, 380, -130, 6, -64], [2817, -1380, 122, -97, 240, -222, 207, -135, -92], [5432, 476, 551, 242, 402, 395, 84, 62, 257], [-2993, -125, -256, -109, -88, -475, 168, 113, 238], [2874, 122, -223, -38, -318, -333, -250, -462, 19], [1353, 179, 210, -207, -24, 933, 206, -119, 208], [-2296, 512, 30, -496, 292, -340, 326, 218, 242], [2057, 344, -640, 567, -228, -80, 115, -9, -334], [-2256, -769, -303, 25, -370, 693, 148, -285, -247], [3345, -570, 558, -321, 360, -1226, -25, -107, 236], [-4650, -344, -491, -172, 174, -361, 222, 202, -305], [-1701, 1429, -248, -515, 192, 353, -154, 393, 414], [2060, -1346, 393, 162, 278, 695, 496, -112, -153], [-1920, 59, 233, -145, -438, -319, -60, -267, 301], [1218, 907, -571, -377, -46, -97, -142, -121, -171], [-10886, 498, 174, -194, 392, 754, 588, 70, 190], [3792, -1114, 493, 230, 514, 1089, -394, -118, -17], [5325, -1193, -294, 445, -80, 729, -72, -205, -420], [3092, 699, 599, -31, -58, 59, 470, 83, 511], [4076, -1614, 700, -318, 440, -1128, 366, 240, 292], [4434, -990, -393, -314, -218, 1385, 178, -62, -27], [-6918, 2720, 620, 22, 168, -72, -126, 92, -48], [-2951, -1039, 108, -39, -692, -725, 40, -221, -66], [3850, -804, 770, -212, -392, 78, 432, 84, 74], [1251, 998, 146, 241, -392, 810, -167, 459, 160], [-1577, -192, -794, 245, -804, 1314, -1127, -317, -164], [-5388, -1872, 846, -462, 412, -302, 404, 670, 854], [3786, 1723, 74, -411, 332, -58, 306, 557, 236], [-4203, 2588, -60, 959, 336, 1708, -605, -361, -430], [86, 1466, -664, 88, 668, -1140, 488, -446, 272], [1399, -1654, -552, -10, 128, -125, -384, -10, -228], [-6906, 642, -296, 758, -604, 770, -590, 174, 292], [598, 2367, -719, 669, -810, 915, -874, -735, -31], [709, -1948, 974, 215, -620, -434, 127, -229, -236], [-1236, 898, 667, 602, 290, -1637, -528, -624, 105], [1238, -2094, -292, -4, 48, 2194, 136, -168, -700], [-11992, 825, -410, -545, -432, -1094, 594, 531, 176], [3718, -1057, 1653, -853, 902, -1539, 950, 697, 497], [8141, 3788, 130, -456, -84, -2053, 552, 504, 326], [-8730, -1806, 640, 98, 212, 724, -464, 90, 24], [4568, -2033, 1371, -621, 334, -713, -138, 897, 731], [-1597, 529, 418, 47, 768, 1303, 150, -409, 364], [3968, -1222, -616, 234, 332, 418, -2, 44, 88], [772, -160, -971, 346, 542, 945, 432, -162, 131], [3521, 2197, 324, 661, -200, 479, -1004, -389, -558], [6074, 1430, -386, 224, -652, 1234, -1282, -576, -294], [-3224, -5218, 688, 358, 60, 318, 228, 432, 112], [-4893, 65, -30, -553, 296, -93, -268, 349, -504], [13060, 494, 76, -194, 56, 1254, -24, -50, 136], [2228, 8, -958, -216, 500, -488, -498, 72, 394], [-11084, -3488, 259, -216, 298, 805, 466, 748, 745], [-982, -1373, -490, -647, -160, -866, 266, -747, 212], [-2896, -3016, -761, 584, -582, 2691, -30, -502, -755], [-13900, 2038, -456, -774, -252, 1576, 142, 492, 60], [947, -894, -318, -398, -256, -1007, -72, -430, -478], [-8698, -2239, 729, -543, 650, -1853, 600, 559, 937], [-3142, -2358, 102, 204, -28, -2602, -114, 288, 290], [2236, -593, -799, -439, -754, -1107, 56, 319, 81], [14426, -3566, -2397, 0, -1030, 227, -632, 14, -55], [5048, -254, -168, 634, 628, 264, -240, -1074, -308], [11172, 767, 720, 209, 1288, -1924, 798, 129, -254], [-6517, 228, 1436, 1275, -804, 1116, -431, -309, -10], [14590, -4514, -171, 44, -758, 73, 880, 220, -581], [12955, -2668, 118, -239, 28, -1370, 829, -639, -100], [376, -3515, 883, -93, 910, -371, -280, -547, 443], [-3989, -1010, 136, -655, 252, -2116, 1053, 825, 970], [-8121, -1614, 1374, 195, 540, 1398, -1567, 1047, -452], [-651, 3732, 34, -1439, -64, 398, -41, 379, -272], [8884, -963, 295, 1193, -182, -361, 444, -1243, -261], [1136, -1882, -678, 104, 272, 2386, 522, -262, 58], [-4575, -419, -454, 509, -1324, 1753, -540, -789, -352], [2599, 54, -290, -363, 1388, 930, 433, 313, 148], [-3162, 3258, -934, -496, -644, 2216, 510, -636, 446], [-2955, -222, -680, -216, -516, 881, -964, 256, -120], [1138, 2293, -995, -1073, -270, 1201, -784, -325, 349], [14111, 1932, -1548, -1303, 764, -480, -327, 167, -66], [1683, -3837, -270, 563, -720, 1271, 108, -879, -1444], [-5600, 3538, -1185, 294, -1890, -1317, -962, -890, -219], [4621, -2004, -968, -453, -1128, 3088, -1217, -1199, -910], [8473, -3404, 806, -2275, -220, -3926, 611, 859, 1916], [2952, -228, 206, 422, -484, 420, 702, 666, 414], [-1283, 4610, -608, 1412, 264, 413, -528, -232, -1116]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_119_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_119_4_a_e();".
// 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_119_4_a_e(:prec:=9)
    chi := MakeCharacter_119_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(997) - 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_119_4_a_e();".
// 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_119_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_119_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![36, 1814, 2515, -4674, -1087, 880, 90, -53, -2, 1]>],Snew);
    return Vf;
end function;