
// Make newform 841.4.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_841_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_841_4_a_b();".
// 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_841_4_a_b();".
// 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, 20, 18, -14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [-2, -8, 1, 1, 0], [2, 12, -1, -1, 0], [-6, 0, 1, 0, 0], [14, 6, -13, 0, 1]];
    Rf_basisdens := [1, 2, 2, 1, 2];
    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_841_a();"
function MakeCharacter_841_a()
    N := 841;
    order := 1;
    char_gens := [2];
    v := [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_841_a_Hecke(Kf)
    return MakeCharacter_841_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, 1, 0, 0, 0], [-1, 1, 0, 1, 1], [3, 1, -1, -1, 2], [8, 2, -2, 0, -2], [-3, -7, -10, -5, -9], [5, -3, -9, 5, -6], [-10, 0, -10, -4, 0], [-44, -8, 0, 2, -4], [46, 0, -2, 14, 24], [0, 0, 0, 0, 0], [-93, 19, 14, -7, -5], [-48, -22, -30, 22, 28], [216, -18, -16, -22, -44], [49, 29, -22, -25, 11], [-45, -75, 16, 41, 7], [-109, 75, 17, 23, 10], [90, 52, -6, 30, -16], [-114, 20, -66, -60, -12], [280, -88, -140, -44, 0], [-122, -58, -96, -122, 6], [384, 106, 66, 38, 32], [-27, 139, 140, 63, 177], [146, -96, -42, 14, 60], [-196, -66, -100, -10, -152], [-296, -34, -48, -78, 32], [228, 126, -58, -30, 40], [70, 314, 132, 50, 2], [492, 158, -38, 80, 2], [-101, -35, -237, 71, 22], [62, 220, 256, 184, 340], [616, -48, -92, -242, 108], [-468, 252, 32, 262, 220], [124, -62, -394, 122, -64], [1090, 60, -50, -74, -88], [225, 121, 51, -111, -210], [-392, -462, -126, 180, 166], [780, -254, -48, 222, 244], [389, 203, -480, 147, 39], [-1262, -290, 96, -174, 254], [662, -580, -664, -100, -128], [546, 318, -32, 302, 214], [1233, 43, 305, 481, 46], [1368, -128, 104, 414, -48], [720, -710, 28, -38, -160], [-654, -148, -316, -436, -456], [1096, 650, 578, 88, -158], [-1039, 303, 172, 295, -161], [486, -690, -516, -662, -426], [-706, -954, 32, 86, -322], [-1540, -2, 460, 550, -276], [-85, 63, -133, 291, 238], [830, -256, 498, -666, 24], [813, -183, -39, 49, 862], [539, 289, 88, 149, 769], [2713, -161, 707, 405, -34], [143, 359, 898, -75, 59], [-166, -356, 482, 40, 516], [-791, 273, -594, -453, 497], [-1058, 268, -124, 4, 824], [875, -37, 183, 667, 562], [2294, 444, -14, 654, 1424], [-2450, 1404, 164, 400, -84], [1485, -1683, 230, -541, -409], [1464, -896, -88, 110, 768], [-2587, -561, 415, 177, 418], [4302, -96, -198, 372, -408], [-3247, -453, 0, -161, -341], [7078, -364, 82, -460, 8], [-2582, 110, 980, 494, -774], [1211, -69, -79, -601, -778], [2542, 1776, 628, 768, 1692], [369, 543, 1812, 59, 89], [716, -656, -956, 106, -1128], [-3963, -365, -1451, -67, -182], [-3240, -484, -1728, -1474, -1152], [-4268, -282, 538, -976, -1166], [-1652, 562, -246, 1050, 664], [-2747, 223, -1663, 61, -530], [2591, 1699, -1485, 751, -278], [-2366, -260, -1152, 28, -804], [7506, -910, -476, 6, 470], [6510, 460, -662, -284, 1048], [1742, -412, -982, 302, -292], [2860, 1678, 750, 322, 616], [-2142, -396, 2390, 14, 696], [-4676, -596, -692, 1710, 704], [-2518, 2036, 484, 868, -224], [-6914, -1264, 20, -136, -1020], [-2774, -1464, 936, 60, -1740], [-2550, -672, -346, -2, -2356], [-5359, -1379, -1214, -57, 795], [1637, -1247, -1874, -721, -411], [-28, 1278, -1114, 956, -206], [6787, 119, 342, -443, -503], [-1594, -1584, -1546, -2514, -576], [-587, -639, 1702, -2369, -115], [1095, -2069, 629, 635, 62], [-2925, 2201, 2821, 1051, 350], [-1676, 4060, 1984, 788, 3112], [2672, -1106, 302, 1542, 2876], [-1404, 42, -2838, -1936, -10], [-710, -1412, -1412, 1012, -28], [11501, -441, 488, -813, -873], [-4678, -204, -1756, -836, 388], [8464, -780, 2352, 1400, 984], [3918, 1120, -502, 2708, 756], [2046, -1756, 422, -1310, -1164], [-1433, 201, 2213, 1719, 2310], [5797, -333, -1304, 695, -1999], [-10164, 1446, 1100, 310, 1636], [8405, 2377, -794, -961, 2141], [-4669, -1915, 1727, 655, -1850], [-8908, 3530, 2846, 578, -104], [-9923, 3067, -20, 875, -833], [2794, 2766, 2744, 162, -454], [-6538, 1368, 1778, 1004, 2580], [10908, -118, -178, -588, -2098], [626, 2912, -522, 1414, 672], [-9860, -1630, 1996, -706, 212], [10019, 889, 2052, -2675, -1439], [-2054, -1656, 1248, -1640, 1956], [-9891, 2069, 3177, 449, 3826], [-850, -484, -2840, -1816, 312], [896, -3260, 112, -976, 2060], [2928, 604, -1044, -264, -4508], [11101, -2359, -1317, -555, 1662], [-979, -2935, -2293, -1587, -5510], [15974, -1682, -1104, -478, -1566], [-3736, 1168, -416, -3242, -5512], [-304, 554, -194, 862, -640], [10267, -7227, 488, -1235, -1523], [15944, 2396, -1124, 1466, 1900], [-10812, 8, -3444, -402, -1712], [10546, -1944, 938, 2176, 200], [-4966, 340, 1704, 3588, 252], [1506, -5280, 2622, -2632, -1344], [10460, 3830, 992, -658, 1356], [-1014, -710, 1064, 4798, -674], [-14378, 1364, -450, 2220, -956], [1180, 3166, 5378, 962, 1036], [7476, 4150, 2110, -1956, 1526], [-11315, 5069, 7659, 2109, 734], [-10816, -312, 1012, 598, 1908], [2009, 195, 800, 1215, 2023], [2786, 5588, 5590, 3456, 2136], [-5805, 153, 2448, -1471, -3405], [3506, 4108, 2628, 5596, 6768], [18205, -1, -2873, 249, -1074], [-389, 1811, 1098, 5893, 5065], [17158, 2342, 2780, 2150, -2662], [-4621, 8467, 3745, 1599, 3842], [12338, -1308, 2692, 1772, 4828], [-884, -726, -1730, 3076, 5450], [-14549, 2315, -78, -383, -2397], [-3212, -988, -716, -1682, 2928], [-8063, -2135, 2670, -4501, 433], [12846, 1782, -312, -430, 690], [-11014, 3084, 2468, 1380, 2168], [1202, 5156, 308, 3692, 1588], [-22037, -3483, -2973, -5801, -8418], [-1215, -6079, -6034, -3745, -5041], [15863, -921, 87, -5561, -2346], [-11133, 4085, 2400, 2449, -1025], [-3564, 5548, -316, 522, 3360], [-12123, 6031, -925, -943, 1042], [13415, -1307, -148, 4165, -2293], [14342, -2138, 4828, 1910, 2566], [4472, 3974, -5278, -1026, 856], [-11575, -1101, 1455, -2467, -38], [4596, -982, -1098, -822, -4976], [-5472, -4058, -5250, 560, -4998], [4035, 2729, 71, 3527, 670], [-11698, -7362, 1412, -894, -7958], [-40034, -1656, 1996, -3424, 1440], [13402, -1808, -1398, -1814, 3892], [-20922, 7416, 3972, 8144, 3652], [11644, -420, -1232, 4, 4240], [8178, -3672, 386, 3856, 3844], [-17427, 4355, 7148, 4687, -487], [1230, -8200, -4468, -2560, -5288], [17089, -1049, -3108, -1397, 3069], [-2087, 911, -11480, -961, -557], [-23794, -2472, -3240, -3968, 3484], [8225, 1111, 5283, 7589, 1298], [-11260, 4148, 2140, 408, -1204], [-11823, -7221, -6103, -3823, 3354], [1070, -9576, -3662, -3780, -1328], [8168, 3772, 1480, 4990, 3152], [-18110, -3740, 6186, 736, -28], [39044, -974, 6094, 2828, 4610], [-447, -1467, 733, -2307, -1914], [-10573, -8423, -12288, 1581, -4231], [-24975, 129, 4758, 1871, 11211], [11924, -86, 570, -4542, 1616], [-16960, -8084, -1344, 3202, -1096], [12786, 3040, -4116, -4176, 2564], [8596, 946, 5958, 6746, 9196], [18478, -5272, 7156, 6992, 5968], [-15, -2095, -4667, -483, 2862], [-28228, 8448, 4616, 1308, -3064], [17952, -1250, -9900, -2318, -6288], [-12934, -9260, -10374, -2226, -5924], [-27160, -6534, -164, -3646, -8120], [12956, 1926, -988, 3398, 2856], [-19216, -3404, 2664, 3906, -1624], [30937, -2645, -12623, -1647, 1634], [40261, 6055, 3812, 295, 5073], [-12194, -10734, 5088, 3614, -6966], [20259, 7049, -399, -1597, 4906], [-19885, -2617, -8702, -11939, -2107], [-9536, -5758, 7400, -4998, 660], [-734, 2264, 3128, -832, 5744], [22505, -3187, -6706, -1605, 473], [13, 9997, 11770, 3691, -4081], [31928, 4328, 2464, 1558, 4728], [11449, 1559, -9037, -2771, 5374], [-21232, -2072, 292, 9024, 10428], [-1772, -2406, 858, -9926, -3468], [30612, -2220, -452, -2188, -9540], [5870, -8188, 4224, 3904, -2572], [-25398, 1636, -2306, 8088, -2248], [-38992, 6910, 5942, 1384, 6186], [28458, -2996, -3992, -2940, -652], [54209, 5163, -2604, 2107, 1289], [31908, -300, -432, 120, -248], [10286, -15596, 6660, -1216, 3816], [12644, -4314, -7974, -8470, 2420], [-15072, -4792, 4464, 1602, 11424], [12739, -2323, 10440, 8673, 2975], [18700, 1850, 2242, 4904, 13014], [-3624, -9350, -11634, -8362, -18440], [48956, -936, -1456, 1184, -1156], [7576, -20196, -9596, -2946, -9556], [-9204, 7686, -9766, -5230, -4492], [-12434, 4562, 1892, -6054, 4610], [-5608, 3512, -12948, 3402, -4940], [16942, -4248, -7550, -10436, 1940], [-31264, -4458, -524, -7862, -2232], [15668, 6334, -3702, -6728, -11302], [10983, 16427, 7942, -2507, 5367], [-25477, -13393, 6046, -5803, -1395], [32058, -22546, -12128, -7510, -10350], [-20062, -4574, 13812, -1790, 854], [10208, 7370, -5742, -5146, 3832], [12318, 9292, 3868, -2044, -7460], [33598, -11498, -7296, 1766, -10454], [-24590, 2524, 1726, -8966, 4832], [-18210, -10796, -770, -5954, 4052], [40866, -7266, 1220, -42, 910], [25033, 6115, 936, 11275, -9751], [-33530, 2768, 12630, 2860, 2132], [-10701, -10943, -4907, -16061, -9022], [-37539, -1463, 10938, -2033, -5075], [-15788, -5450, 9086, -11294, -1144], [-50804, -526, 4500, -1882, -684], [-40004, -1200, 13668, -236, 13636], [-15252, -11382, -10968, -13978, -17848], [-12621, 49, 248, 365, 2677], [-32998, 5124, 4272, 5028, 3704], [6805, 11281, 7605, 8681, 8514], [76048, 1936, 6032, 4554, 3824], [6637, 5101, 2094, 3291, -2381], [-17794, 1888, -1012, -10360, -1888], [49666, -5640, -10746, -1576, -3312], [55634, 3924, -6718, 648, 10388], [-52103, -9895, -4198, -12385, -12045], [-7648, -5850, -8498, 9726, -1740], [21246, -16900, -5554, -3364, 7640], [-4852, 1484, -7308, -12322, -1040], [-4957, 17253, 5571, 10727, 15686], [-28221, -1825, -4351, 4159, 2322], [7090, 4682, -8612, -3318, -15822], [-27431, -9347, 16697, 1205, 1034], [-8576, 20240, 10148, 5694, 5700], [-11908, -5814, -11626, -7102, -9556], [50639, -4333, -10410, -179, -12461], [-21760, -9156, 9792, 650, -4808], [-26699, -4589, 769, -3523, -5526], [30676, -2486, -6310, 9170, 4548], [60494, 20776, -9330, 110, 13632], [-38346, -7402, -25844, -8966, -4314], [-16474, 1542, -14860, -11266, -894], [21520, 14272, -4372, -1460, 1084], [-1954, -18284, 12636, -5372, 2100], [-62372, -6356, 3928, -9326, -14660], [-41408, -6020, -9972, -15366, -13500], [-9362, 8204, 16046, 8356, 14504], [-6612, 7754, -1680, 14326, 1312], [38028, -6150, -11734, -6268, 4386], [2397, 14901, -6355, 1497, 5526], [27033, -10189, -10123, -9831, -14506], [17538, 8296, 16202, 1930, 9632], [33841, -12623, -1327, -11219, -6882], [12707, -12247, -7004, -12403, -1395], [-24950, -7152, 7072, -4820, 1420], [-39483, -4095, 16519, -5867, 7302], [33535, -29479, -15452, -6595, -3321], [41647, 17091, -3851, -2277, 6130], [-2248, 3098, 1582, 1908, -1262], [35884, 6908, 10644, 17862, 23792], [-46390, 4776, 14114, -1288, -9300], [-31478, -3080, 5136, 464, 2716], [52944, 13392, 10528, 1434, 6840], [28741, -11927, -14842, -11565, 7447], [-23132, 6860, 29764, -2538, -4264], [28765, 17875, 22987, 14233, 18522], [80753, -5645, -3432, -729, 2959], [3433, 23085, 23095, -1831, -6606], [28928, 3926, -506, 5412, 16534], [17649, 16843, -2719, 929, 15458], [15838, -26848, -6326, -7270, -17552], [-21360, 466, 11660, -7974, 12072], [-68010, -5580, -17460, -3044, -740], [-17982, -1236, 16698, 7774, 15820], [4572, -17786, -8370, -5256, -15694], [11843, -549, -817, -1869, -5974], [36284, 19092, 15324, -9022, 12320], [26438, 1350, 1384, -18158, -11190], [50313, -23333, -9241, -6051, 946], [-8558, 12196, 6490, 1144, -20732], [-1377, -13187, 19252, 11841, -1463], [-33075, -23645, -2977, -16999, -25162], [3974, 29816, -11040, -6240, -4168], [33701, 12141, -1298, 16943, 21209], [27627, -4981, 1175, -7877, 2338], [-45760, 9602, 21280, -2798, 6844], [64426, 10614, 19792, -1106, 1466], [-4772, 33244, 24504, 7928, 25676], [-53379, -37, -12876, -3329, 4349], [-7961, 26625, 5851, 7691, 17310], [-48052, -7598, -5446, -16446, -8268], [-93799, 11449, 8487, 11657, 15714], [-35012, 14104, -2836, 19156, -2460], [39036, 5884, -15664, -1082, 20268], [-7609, 20295, -1614, 5153, 15409], [-78172, 11252, 4172, 14112, 15524], [-5346, -24704, -11232, -10008, -24040], [40646, 9692, 5292, 1984, 13328], [-73374, -6672, -20276, -3916, -7968], [40448, -9300, -9200, -11692, 9128], [-77654, -7032, 6702, -17024, -23056], [-24166, -16784, -14828, -23112, -18572], [-17294, 26976, 26, 12616, 1920], [120596, 4076, 21648, 6912, 8752], [83926, 27620, 16296, -14900, 5240], [17605, 26629, 7410, 12819, 19883], [-62362, -15956, -17474, 15700, 8284], [2068, 11908, 17984, 16510, 2708], [39489, 13971, -1952, 13907, 2669], [55314, 1012, -3432, -13324, -3064], [20078, 600, 4022, -12370, -15028], [-35330, -6248, -17540, -19336, -22548], [-64314, -19604, 15584, -15016, -16352], [-8022, 5328, -16226, 7494, -4820], [-20878, -27600, 18790, -15192, -8620], [100970, 3136, 11478, 14432, 16404], [-32193, 20523, 8782, 14101, 21819], [-67848, 13370, 6306, -1248, -1018], [-84698, 5160, 11722, -1020, -5756], [10478, -82, 2032, 9306, 28178], [59949, -4717, -4423, -8387, 9266], [77933, -1363, 12937, -7943, -766], [-102023, -18849, -6484, 3795, -11355], [-54006, -7510, -3524, 28602, 19314], [-12479, 16229, -29362, 1855, -7797], [31368, -24802, -21676, -2374, -11212], [77604, 13602, -1814, 10754, 6480], [-80546, 23842, 9024, 20254, 10914], [85966, 1320, -24092, -760, -11564], [93113, 21455, 17500, -2113, 5595], [16338, 16642, 33244, 14170, 16174], [-14780, -13834, -35010, -17188, 3294], [-78846, 30972, 18564, 7756, -2680], [21522, 18988, -31302, 1206, -2544], [-27265, -1455, 7615, -10733, 7946], [-106636, 620, 180, -17530, 6424], [-81463, 22253, 18978, -421, 14313], [59550, 3484, 18942, -3140, -600], [-23293, -13967, -3239, -31157, -5274], [-3535, -12453, -9133, 18261, 1306], [103580, 1090, -2250, -630, -1780], [29069, 13083, 9715, 19169, -22358], [-20001, -3847, 17084, 18389, 14367], [16502, -576, -29434, -9868, 5088], [22628, -11102, -7454, -7384, 410], [80168, 14798, 1510, -9240, -16830], [-16416, 2104, -25800, -418, -7672], [-55083, 37673, 44115, 24133, -8834], [105433, -10805, -14452, 4711, 6355], [76104, -11916, -5684, -27810, -10492], [-87254, -36600, 172, -5548, -28100], [83079, 17023, -6907, 11779, -946], [44863, -14135, 16984, 8657, -1071], [-123041, 10659, -4942, 5617, -9379], [20515, 2499, -13586, -3015, 9959], [-72731, 26179, 9967, 2065, 4410], [59180, -3840, -12384, 1412, 5112], [-98248, 21390, 11482, 2086, 20844], [4290, 282, -35856, 2174, 8086], [29394, -5020, -8444, -28092, 9464], [-124014, -25256, -5004, 464, -8568], [-7010, -14676, -20404, -13592, -19624], [-47064, 15532, 6020, 12346, -556], [-62863, 20985, -29707, -15451, -6502], [69433, -33847, -24997, -30583, -26874], [170362, 6072, -7382, 2794, 8820], [-71757, 13665, 9879, -16297, 8910], [15206, -9544, 1162, -21860, -31056], [78253, 4145, 16606, 11851, -7793], [102712, -14596, -24308, -12812, -8388], [40026, -13516, -4012, -4860, 23516], [36715, 15971, 20165, 28087, 36598], [-20692, -5354, 14374, -896, -13726], [171058, 3308, -3406, 8122, -10124], [-103280, -37486, -20840, 6066, -24148], [142018, -1960, -22000, 1652, 11760], [-57147, 17013, -32538, 1479, -8383], [30362, -6834, -10224, 1102, -37306], [-28344, -21362, -27902, 10190, 18468], [-97619, 91, 34876, -7377, 1729], [77218, -6156, -39388, 3036, -17792], [-21902, -1392, -11620, 26636, 15688], [23041, -13187, 12970, 28163, 8885], [36127, -10065, 26206, 21897, 12721], [78859, -36681, -18977, -29557, -7286], [-35629, -12555, 751, -10809, 21478], [102806, -22248, 4086, -1162, -18276], [133508, -8270, -23354, -12806, -1908], [76254, 15120, -9018, 5374, -18300], [4273, -36295, -2238, -27621, -15855]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_841_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_841_4_a_b();".
// 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_841_4_a_b(:prec:=5)
    chi := MakeCharacter_841_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_841_4_a_b();".
// 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_841_4_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_841_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![256, 192, -28, -33, 0, 1]>],Snew);
    return Vf;
end function;