
// Make newform 507.4.a.p in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_507_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_507_4_a_p();".
// 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_507_4_a_p();".
// 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 := [27, 63, -2478, -4139, 763, 945, -27, -56, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0], [-1151901, -15644592, -13739936, 4377940, 3665268, -177378, -231050, 993, 4276], [-40902156, -794287746, -296579777, 197174581, 68463819, -11363973, -3890801, 190713, 64999], [3317895, -45679772, -105271205, 13299657, 23628597, -297443, -1397001, -7166, 24987], [6113457, -219614865, -422915233, 86430869, 94118139, -3836655, -5333239, 32184, 90230], [-154170810, -246575877, -485797741, 76680635, 120654441, -2116755, -7390255, -25263, 135002], [313226181, -96613761, -1250692846, 57886724, 265872168, 2115444, -15606016, -175299, 279719], [15335469, -1087356531, -1808976728, 314702644, 417633228, -9175896, -24966176, -76689, 450169], [129805956, -1105342458, -3109582931, 411567511, 695505123, -11744913, -41110133, -134067, 735613]];
    Rf_basisdens := [1, 1169766, 15206958, 5068986, 15206958, 15206958, 15206958, 15206958, 15206958];
    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_507_a();"
function MakeCharacter_507_a()
    N := 507;
    order := 1;
    char_gens := [170, 340];
    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_507_a_Hecke(Kf)
    return MakeCharacter_507_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 := [[1, 0, 0, 1, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0, 0], [3, 0, 0, -1, 0, 0, 0, 0, 1], [9, -1, 1, 1, 0, 1, 0, 0, -1], [8, 0, -1, -6, 1, -1, -1, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0], [16, -8, 2, 4, 4, 1, -1, 3, 5], [34, 6, -2, -8, -4, 1, 3, 5, 1], [16, 4, -5, 5, -11, -6, -1, 3, 2], [9, 17, -4, 11, 11, -8, 2, -12, 11], [69, -25, -6, -5, -11, 4, -4, -2, -13], [145, 33, 15, -1, 30, -4, -2, 3, 8], [32, -8, 11, 1, -7, -15, 12, -6, -5], [1, -41, -3, -39, -6, -7, -3, 2, -17], [-30, -32, -16, -20, -26, -27, -5, -15, -15], [13, 38, 26, 21, 18, -21, -15, 9, 6], [85, 19, -10, 2, 13, -25, 3, -3, -7], [-184, -92, -30, -14, -14, 29, 15, -19, -39], [301, 69, -20, 4, -33, 9, 12, -49, -21], [-11, -21, 8, 18, 21, -8, 23, 42, 4], [323, 14, -14, -3, 10, 2, -10, -60, -7], [-132, 112, -24, -30, 10, 16, -9, 14, -6], [276, 158, 27, 119, -3, -29, -33, 30, 5], [-93, -115, 14, 86, 61, -31, -26, 63, 49], [130, -95, -86, -73, 13, -1, -10, -11, -8], [-245, 71, -37, -189, -42, -17, -2, -48, 7], [-39, -26, 35, -208, 69, 32, 23, 9, 5], [275, -65, -49, -93, -6, 26, 55, 27, -66], [612, -132, 25, 15, 15, -25, 4, 56, 29], [-557, 115, -15, -9, 60, -34, -6, 9, 48], [-308, 41, -66, -9, 113, 47, -8, -65, -46], [204, 47, -17, -82, -40, -92, -102, 39, -35], [275, 133, -69, 111, -66, 21, -5, -186, -37], [-404, -218, 39, -41, 57, -51, -68, -16, -69], [435, 253, 62, -123, -13, 61, -95, 3, 46], [240, -48, 43, -330, 1, -56, 18, -43, 53], [67, -37, 127, -309, 32, -11, 89, -66, 13], [291, 53, -84, 106, -125, 19, 30, 85, -89], [-19, -251, 41, 95, 212, 239, 89, 12, -55], [-1415, 33, -66, -45, -27, -180, -6, 54, 133], [-133, -50, 78, 121, -38, 86, 68, -228, -97], [517, 73, -108, 118, -111, -249, -84, -85, 49], [-491, 157, 106, 366, 219, -13, 74, 339, -11], [137, -99, -63, -205, -168, 77, 93, -288, -141], [338, 224, 41, 561, -3, -11, -17, 216, 35], [-745, -195, -46, -95, -369, 5, -43, 25, -224], [1511, 343, 212, 552, 153, 132, -5, 36, -60], [760, 234, 9, 203, 275, 9, -194, -18, 141], [102, 497, 148, 117, 59, 63, -88, 33, 116], [105, -671, -46, -382, -57, 230, 41, 18, -34], [676, 200, 4, -416, -290, -19, 5, -183, 23], [-927, -43, -51, 391, -74, 136, -136, 225, -142], [-138, 173, 181, -324, 254, 253, -31, 72, 112], [327, -165, 18, 506, 91, 322, 0, 24, -332], [-1459, -745, -248, -570, -423, 157, 200, -159, -221], [1123, -445, 104, -606, -113, 63, 170, 129, -49], [-643, -120, 19, -76, 313, 95, -216, 180, 110], [1894, -255, 112, 745, 167, 160, 313, 92, -147], [-1336, 72, -57, 319, -151, -31, -280, -180, 101], [-2354, 6, 63, 95, 89, -32, 125, -171, -26], [154, 208, 234, 276, -66, -115, 149, 77, 29], [-1964, -340, 19, -620, -275, -152, -92, -39, 157], [441, -201, -152, -532, -167, -318, -255, -118, 158], [659, 457, 82, 224, -57, -81, 108, -45, -137], [-707, -176, 9, 210, -475, 159, 232, 152, 100], [1530, 536, 456, -80, 442, 300, 199, 204, 106], [2210, -438, -431, 553, -289, -167, -112, -118, -109], [3309, -23, -336, 483, 51, 50, -228, -280, 79], [-2710, -148, 193, -91, 17, 585, 185, 138, 23], [4368, 62, 212, 1274, -198, 154, 52, -22, 124], [-2159, -513, -412, -1118, -215, 127, 106, -57, -331], [469, 367, -620, -270, -541, 289, 194, -249, -155], [1728, -784, -678, -180, -264, 142, 15, -350, -172], [3116, 284, 49, 287, -265, 51, 198, 72, 21], [1843, -587, -423, -223, -92, 528, 420, -349, -876], [601, -69, 146, 232, 709, -227, 4, -3, 425], [3399, -517, -267, -342, 312, 491, 64, -366, -136], [3440, 44, -548, 388, -60, -173, 139, 405, -545], [1549, 697, -92, 132, 405, 6, 165, 306, -16], [-529, -801, 273, -1183, -454, -99, -62, -252, 219], [3561, 125, 169, 1060, -90, -169, 258, -204, -184], [5048, 480, -146, 146, 338, -283, -309, 173, 373], [2199, -941, 310, -1260, -415, -347, 80, -327, -39], [-478, -780, 106, 637, 172, -589, -34, -133, 432], [-300, 720, -512, 796, -546, -327, -54, -715, -81], [466, -38, 150, 249, 80, 113, -380, 51, 334], [756, 646, 180, 954, 316, -715, -559, 477, 469], [3538, -36, 161, -148, -23, 8, -384, -41, 809], [1460, -924, -575, 371, -257, -454, 24, -231, 116], [940, -220, 232, 920, -76, -240, -68, -276, -376], [1184, 263, 698, 291, -129, 507, 600, 843, -140], [1097, 677, 531, 1053, 192, 14, 22, 849, 52], [3964, -251, 266, -1305, 533, 451, 176, 135, 138], [-4018, -758, 733, 1036, -335, -547, -467, -96, 432], [250, -754, 526, 730, 296, 212, -380, -258, -220], [-3528, -746, -853, 957, -589, 4, 145, -471, -572], [2976, 1098, -500, 2168, 62, -644, -458, -384, 460], [-3147, -547, -809, 1679, -342, 9, 211, -738, -301], [1184, 288, -449, 953, -761, -360, -291, -607, 386], [3114, 50, -911, -63, -795, -561, 76, -60, -53], [7643, 1557, -41, 2135, 1458, 562, -296, 347, -214], [4227, -245, 378, -2126, -327, -334, -405, -240, -236], [3406, -2361, -376, 1581, -497, 70, -41, 180, -705], [-2870, 702, 115, 1303, 1647, 727, 522, 1848, 347], [-3958, 682, -679, 1629, -1057, 106, -15, -915, -910], [-2264, -750, 271, 315, 379, -221, -73, -466, -951], [-4608, -942, -128, 605, -432, -278, -141, 102, -147], [2650, 832, 578, 82, 626, -1282, -472, 1284, 758], [1313, -1023, 340, 652, -1031, -1049, -172, -1407, -235], [-1033, 459, 1011, 694, -230, 27, 344, 744, -108], [156, 496, 718, -2374, 828, -141, -214, 1789, 677], [-421, 985, -237, -533, 526, -484, 18, -421, 12], [3880, 1672, 982, 250, -138, -356, 208, -822, 596], [-9484, -1074, 474, 2058, 1364, -197, 65, 807, 653], [1722, -760, 127, -2393, -1207, -445, 601, -444, 401], [2578, 3608, 807, 175, -37, -850, -583, 459, 492], [-2058, -808, 594, -1828, -1074, 849, -333, 1381, -1123], [-7436, -1256, -313, -3947, -193, 265, -62, 810, 553], [-5818, 1644, 920, 1636, 358, 1020, -63, -672, -286], [2493, 1445, 549, -2527, -306, -228, -307, -1053, -200], [2087, 263, 766, -1404, -1519, -101, 710, -915, -431], [6363, 679, -81, -2037, 376, -518, 125, 509, -212], [-9892, -3162, -491, -4263, -665, 83, 1005, -558, -551], [-8487, 1008, 434, 645, 1260, -332, 44, -546, 1089], [-5788, 120, 381, 1259, 1761, -139, -372, 606, 525], [2820, -1454, -137, -1489, -501, 777, 684, -738, -1843], [-1409, 1391, -320, 3594, 459, 1350, -327, 60, 524], [1992, 2498, 450, 794, 508, -150, -674, -168, 1386], [-4844, 1390, 883, -4765, -461, -79, -513, -1178, -21], [3837, -1787, -764, -616, -2687, 1151, 538, -1193, -1477], [-10441, 713, 43, 1585, -146, -696, -392, 1569, 990], [160, 2490, 1758, 900, 646, 29, -179, -225, 863], [1740, -688, -1065, -910, 161, 1216, 182, -2231, -551], [-3116, 320, 81, -5397, -917, -171, -270, 178, -857], [-1391, 1177, 802, -84, 1077, -371, 34, 1707, 3], [3192, 2758, -14, 1150, 1592, 2040, -316, -338, 12], [-2039, -2275, -1047, -1847, -1298, 855, 838, 366, -1189], [-10848, -2950, -471, 1717, -405, 2069, 784, -1730, -1109], [-1392, -1026, -174, 1143, -74, 506, -575, -60, -1043], [-14585, 513, 213, 179, -508, -1673, -31, 1098, 1735], [1200, 1256, 998, -276, -998, -995, -1167, -1219, 937], [845, -1158, 606, -731, 310, 297, -265, -957, -1728], [-8477, 145, -133, 1431, 104, -347, 640, -654, 1135], [-17069, 721, -1330, -709, 683, -412, 62, -216, 361], [264, 3872, 621, 1413, 1279, -960, -661, 847, 1940], [-9695, 4553, 155, 249, -174, -133, -19, 30, 389], [9934, -1110, -119, -3387, -291, -250, -1715, 101, -70], [-2258, -1370, -590, -5570, -104, 700, 906, 1002, -524], [4744, -54, -241, 2183, 269, -122, 705, 1555, -26], [-9192, -1434, 1006, -1296, -258, 1115, -341, -579, 369], [3747, 2693, -273, 731, 62, 79, 123, -656, 1815], [2876, 1652, 1414, -2536, -508, 271, 1305, 2709, 231], [-15842, -1540, -868, 522, -196, 1383, -409, 1937, -41], [13023, 4963, 6, -84, -213, 250, 1037, -126, 766], [13578, -1866, 929, -981, -845, -591, -858, 214, -523], [-3351, 1099, 718, -4526, -273, -1348, -613, 984, 302], [-15105, -1506, -138, 2753, -944, -95, 937, -855, -734], [-10453, -4605, 659, -5543, -676, 2765, 1483, -2430, -1719], [-7517, 1875, -84, -2087, 1645, 1215, -769, -2109, 546], [-2772, -4222, -585, -2756, -2603, -1049, 689, 360, -1522], [-19073, -712, 1106, 953, -70, -877, -543, 2529, -1184], [3601, -27, -1230, 1562, -1003, -717, 892, 1857, -585], [-759, 2489, 1917, -5690, -1694, -1958, -385, -275, 1025], [2277, -2275, 1191, 1944, 664, 1177, 356, -96, 204], [2653, -1929, -643, 3995, -1772, -770, 868, -2343, 1576], [-13443, 225, 1274, -1922, -169, -1147, -164, -711, -17], [8303, 368, -1084, 2625, -2032, 141, 1049, -1801, -1148], [7043, 2335, -1516, -1658, -53, 1443, 782, -1665, -347], [19672, -2402, -418, 2771, 374, -1422, -1145, -576, -1019], [3661, 4163, 1067, 8461, 1118, -574, -1044, 3351, 1184], [-23092, -3538, -876, 2260, -1428, 515, -353, 375, -1269], [13159, 871, -1074, 3286, 3433, 1988, -283, 728, -176], [6564, -4200, 227, 2653, 87, -703, -462, 1326, -507], [16351, -801, 643, 1621, 1796, 1642, 2156, -343, -904], [73, 387, 1463, -2129, -1468, -774, 734, -2045, -694], [-15951, -5557, -1883, 2479, -3194, 189, -297, -2100, -1351], [862, -2028, -403, 3351, 257, -1228, -1463, -1193, 66], [15744, 2700, 1700, -674, -332, 925, -752, -159, -65], [-1839, 643, -435, -559, -2958, -2258, -704, -931, -870], [5276, 2402, -209, -1897, -1441, -522, -1195, -2109, 442], [-8346, 2597, -372, 4031, -973, -1745, 678, 1393, -840], [-2872, -86, 1888, -3249, 3612, 1176, -1137, -588, 153], [-19354, -2596, 451, -171, 2653, 263, 1776, 1650, 1189], [3312, 1462, -2799, 2533, 123, -620, -109, 183, -606], [-6496, -2712, -268, -138, 2022, 3573, 529, 873, -1289], [8060, 2986, 1476, -2244, 2692, -3024, -1725, 2700, 1438], [-16060, -2478, 2244, -964, 2746, -431, 1035, 5043, 281], [-1579, 4077, -662, -4674, -867, -2071, -8, -2551, 83], [4097, 2213, 236, -2486, -1955, -646, -1440, -520, 1378], [-20847, 81, 29, -1129, -1070, -1182, 1134, -1893, -1216], [-1495, -2671, 354, -5511, 517, -1362, 2038, -2606, 3435], [-7770, -5226, 1113, -1659, -7, -422, -1528, 4275, -532], [-7272, -4350, 1648, 1538, -1466, 1797, -1449, 1067, -1279], [-8540, -1689, 598, 4481, -815, -1746, -581, 636, 1949], [21679, 4746, -311, 1084, 2891, 506, 1205, -1431, 1873], [4985, 927, -458, 4094, -1571, 288, 37, 414, -1158], [-3636, -1250, 973, -4428, -281, 2046, 1848, 2365, -669], [-10766, 1928, -500, -1026, -3528, 270, 1394, -2502, -2676], [-6659, 1767, 553, -5995, -302, 115, 2111, 1194, 57], [6144, 5198, -1059, 9065, 1997, -110, -2087, 4089, 1788], [3939, 3117, 215, 1929, -4372, 1058, -230, -213, -2656], [8895, 6015, 1899, 6170, 2862, -526, 1029, 3819, -561], [-5460, 1000, 1281, 443, 91, -1284, -1613, 5147, 14], [-10165, -1018, -1668, -11137, -2804, -1546, 1044, -1682, 2305], [-33454, 3512, 1799, -389, -989, 731, 1369, 3030, 2905], [-3687, -6605, -2376, 717, 1307, 2207, 133, 447, -1506], [597, -348, 1500, -3875, -1120, -1894, -72, 1878, -137], [-14655, -1247, -539, 2525, 1982, -3384, -1457, 2211, 4236], [-1242, 214, 793, -9055, -87, 271, 694, -3534, -1173], [-17011, 1245, -1287, 5621, 1280, 591, 495, -3564, -875], [-20236, -4443, -1580, -5465, -749, 1985, -1790, 281, -92], [7188, 2232, 3639, 2398, 2509, 2262, 1400, -717, -527], [342, -4164, 611, -643, 3223, 2525, -1962, 544, 1805], [-26005, -2517, -975, 2117, -1764, 1182, 2172, -3369, 66], [-24046, 3500, 2153, -2679, -3897, 1632, 369, 1899, -1826], [10103, 5935, 234, 3120, -1455, -2287, 263, 1499, 461], [19638, -1932, -2416, 4045, 1242, -1597, -636, -887, 876], [3570, 3794, 1596, -5124, 910, 2820, -2534, -2448, 344], [-8411, -2765, 1446, -180, -675, 1061, -240, -327, -2355], [26895, -2226, -2353, 3548, 445, -122, 7, 591, 687], [-25968, 4930, 2196, 2852, 646, -2952, -2798, 2624, 2192], [-5814, -4891, 1225, 5144, 6584, 3306, 1052, 1125, 2185], [-17657, -6603, -106, 1570, 4249, 4873, 1804, 531, -187], [22622, 810, -1447, 3038, 485, -3815, -1655, -1514, 210], [-3215, -1113, -1164, -3912, -5453, -3451, -686, -21, 1547], [18223, 3253, -2726, -810, -537, 1063, 2076, -1991, 1519], [-9753, -487, 1455, 3417, -2520, 568, 1236, 777, -2078], [-4867, 1969, 416, 15142, -99, 1461, -856, 4059, 621], [-18786, -3701, -487, -4816, 818, 3555, 2133, 288, -2128], [-28174, -4505, 318, -87, -381, 1011, -320, 1239, 2918], [-6402, -10942, 653, -1523, 1229, -806, 369, -1747, 1482], [-6888, -1860, -1621, -2093, 2135, -2616, 2739, 1981, 1636], [40285, 5037, 2072, 9310, 2313, 482, -3176, 3628, 1724], [7717, -1565, 2865, 3889, -2552, 904, 952, -1593, 180], [4766, 2018, -1707, 1531, 2971, -1004, 451, -773, 1326], [-13962, 2220, -1473, -1231, -1393, -2507, -2596, 2034, 849], [-12744, 1966, 3635, 1895, -4805, 1273, -603, 2112, -45], [43645, 287, -3452, 5994, -1069, 1253, 1015, -1887, 2525], [8699, -4321, 3006, 2346, -969, -1850, -2301, -1878, -12], [24191, 1275, -4320, 8682, 793, -404, -555, -1446, -1840], [606, -826, 1185, 2650, 1597, 2467, -487, 1266, -568], [22057, 2783, -815, 611, 894, -4102, -736, -4083, 1128], [15897, 4991, 907, 3941, 4212, -1603, -2333, 8760, 1237], [12778, -1386, -2095, 1023, 341, -2029, -1518, -3728, 3565], [16962, 4838, -591, -5299, -5891, -5765, -1804, -1686, 3367], [23597, -5477, -452, 714, -2609, 2409, 968, -1629, -4591], [21553, -7053, 2588, -2741, 159, 1322, -3986, -1178, -217], [-15415, 5399, -1120, 4969, 3275, 2040, 382, -4242, -131], [-15960, 6386, -144, 7416, 2370, 2827, -1591, -1163, -3243], [-21033, -5315, -83, 6527, -3640, -3499, 825, -3534, 1175], [-902, -1444, -1812, 318, 764, 809, 1997, -5201, -221], [-1371, -5243, 3211, -3213, 1602, -659, -1751, -762, 4043], [-20444, -574, 3148, -7418, -2888, -585, 3603, -1545, 525], [-20602, -5728, 975, -4957, 4901, 3943, 215, 4102, 613], [12631, 1169, 4380, -1074, 5113, -335, -637, 957, 4453], [-24488, 10376, 925, 1837, 1631, -1484, -1104, 2709, 1398], [5757, -7297, -1265, 8091, -5976, 2400, 2234, -2037, 2136], [-12644, -28, 4634, -10990, -922, 833, 2679, 2237, 75], [37030, 6574, 649, 1323, -551, 778, -1860, -2163, 2156], [-15073, -7565, -3869, -13416, -2218, -982, 2471, -1607, -435], [18577, 657, 41, -4864, -8270, -4450, -63, 757, -157], [14780, 1063, 1460, -3779, 5449, 1483, -1546, 3273, 5784], [14283, -1313, -1012, 2968, 7875, 2092, 199, 3918, 4416], [14457, -191, -1902, 2690, -3257, -4089, -3770, -3703, -4945], [9452, 3678, -4222, -11976, -4782, 263, -117, -4611, -705], [-9882, -3704, -263, -7193, 325, 6181, 1024, -1826, 437], [12564, -4927, -3185, -1824, -588, 1520, -1608, -3831, 2283], [4539, 2889, -1359, 3251, -1222, 1746, 4396, -519, -1264], [-6486, -5720, 1074, 6858, 1002, -4201, 1551, -2449, 25], [-27115, 7308, 134, 12723, -2244, -1089, 3487, 225, -3536], [9794, -8070, 375, -6475, -3709, -39, -2566, -192, -2845], [-4791, 5559, -2331, 1157, -482, -2261, -4279, -4224, -1383], [-744, 2545, -410, -4971, -511, -2533, 778, -275, 3370], [19477, 8774, 3876, -7231, -582, 3225, -1085, 1531, -2600], [-10447, 2285, 3187, -10669, 5386, 436, 229, 2295, -1098], [31416, -2218, -6000, 4681, -1460, 202, 2461, -230, -3651], [-750, -9047, -1697, -4096, 2828, 7051, 1553, -2190, -3650], [-20420, 5346, -2979, -3689, -799, -5701, 1258, 444, 4389], [31406, 8000, 1626, 7896, 310, -3162, 307, 4060, 1266], [-19082, -1912, -1453, -11757, -2905, -533, 29, -4398, 3809], [15263, 2187, 2344, 888, 1969, 950, -1485, 480, -4100], [-6124, -10231, -1597, 10348, -730, 136, 1688, 4433, -647], [-40337, 6423, -2041, -45, -1234, 0, -1492, 2715, -1232], [-10756, -3014, -1765, 1633, 4623, 1423, -1000, 1434, -43], [-31726, -5792, -2114, 1998, -1998, 1168, -2122, 2110, -4912], [16458, 4014, 4082, 978, 9088, -756, -960, 1110, 1408], [5544, 4323, -1622, 18335, 2891, 3170, -5007, 434, -3137], [64834, -791, -1214, -1819, -773, -7382, -1347, -1260, -99], [35129, 4865, -2881, -1722, -3220, 2469, -2182, -3916, -4616], [-19657, 4287, -794, -9482, 4843, -3017, -4036, 7641, 1787], [-1393, 5269, -4905, -7935, -6890, 3644, 1565, -1671, -5016], [-25655, -3989, -6180, -5155, -10969, 2394, 3032, -3852, -6813], [57407, 193, 3150, -3474, 5991, 2568, -167, 3186, 4526], [11195, -2808, -323, -11058, 4465, 6066, 2875, 3309, -1369], [43103, 8595, 1269, 7565, 8790, 1244, -664, -651, 820], [-11467, -2539, 4, -15340, -1177, -3818, -3420, 3942, -2034], [14419, -9964, 1108, -6785, 1412, 2330, -4152, 198, 3849], [51421, -9921, -623, -1181, 2634, 3492, 3167, 2463, 1120], [24214, 2718, -4504, 6783, -5606, 3625, -2666, -4575, -3774], [23931, 2717, 3270, 4970, 3725, 3676, 455, 1042, -800], [-23652, 2678, 93, 2834, -5605, 874, -1954, 4825, 2353], [54112, 1937, 4763, 2972, 2840, -2862, -3518, 4047, 3737], [467, 3789, -97, -2855, -3272, 1810, -2749, 1033, 4704], [-21788, 8547, 1723, 7276, 5142, 1673, 2161, 4824, 5124], [5940, -860, 7161, 3243, 313, -6809, 402, 6488, 2655], [-19015, -1586, -8530, -13021, -4254, 4865, 3259, -9003, -4026], [-52179, -15001, 1107, -11013, -4332, 573, 47, 2952, 3705], [-33867, 4129, -5420, -8716, -4211, -4258, -83, -4292, -1594], [-22905, -1745, -3992, 10146, 1197, 1130, -1687, 456, -3246], [-9626, -560, 2514, 14750, 5690, 1706, -3280, 1484, 1854], [20659, -10425, 5483, 59, 7488, -2801, 3269, -822, 2291], [49426, -4642, -2736, -4122, -5738, 507, 4390, 6567, -987], [-36422, 1804, -6512, -25584, -2206, -3385, 1575, -4953, -1147], [27752, 3462, 890, 14446, -564, 3641, 1797, 13, 3231], [46376, -3400, 593, 1513, -2071, 647, 4410, 2106, 1065], [-84530, -1896, 1092, -8061, -5738, 1088, 3207, -6600, -5707], [-12985, -1314, -3202, -1823, -5458, 1808, 5326, -5130, 993], [4541, 1875, -125, 3823, 4008, -7109, -2613, 3750, 2019], [-56511, -5619, -854, -5378, -105, -3096, -1631, -4576, -3124], [-38246, -972, -2211, -435, 7667, -3883, -3462, 7572, 5149], [-62890, -8574, -4709, 3001, -2151, -1419, 118, 752, 1073], [-62921, 2751, 1128, 2371, 4653, -1658, 2230, 6504, 3383], [39245, -131, -7150, -12306, -2231, -2544, -3134, 4794, 1932], [27136, -102, 3280, -13175, 4360, -8107, -692, 4883, 2446], [29605, 2441, -6752, -9012, 2049, -4654, 153, 4146, 1072], [45698, 12600, -286, 4427, -3544, 1444, 1747, -4178, 459], [1572, -3762, 1922, -19706, -9564, 2138, 912, -2912, -7614], [-17768, 17074, -2944, -11402, -2026, -1123, -995, 1059, 5305], [18891, 9363, 4644, -162, 5257, -4346, -285, -2340, 6006], [-23318, 10598, 3558, 1776, 9530, -3487, -5557, -45, 8929], [-85602, -6012, -4170, -7424, -3610, -520, 2428, -5826, -3102], [45629, -14044, 505, 8338, 7377, 5190, -65, 1449, 251], [2816, -2084, -674, -6564, 5718, 7243, 1423, -5765, 3507], [-15993, -16772, -3536, 2681, 1058, 6238, 3860, 5682, -5063], [24756, -12676, 3681, 10723, 105, 143, 2450, -5240, -7161], [-1551, -10448, 4969, -18896, 2041, 1146, 479, -6675, -6379], [17058, -2374, -4168, -2770, 994, 8211, 5485, -5743, -8067], [-18628, -13152, 335, -15635, -9039, -5637, 1270, -516, 681], [-88194, 13180, -2190, -4867, 1948, 4875, -754, -5857, 1588], [-546, 1092, 2070, -3763, 4316, -5478, -3609, 4008, 9067], [25462, 4932, -4893, -9147, -5683, 5740, -1113, -3147, -1850], [23484, 2054, 6133, 15607, 1497, -1597, -8418, -642, 905], [26362, 16552, -687, 5744, -1603, -1875, -667, 7296, 3858], [22644, 14934, -466, 30057, 7282, -1365, -5870, -737, 4678], [37633, 10143, -170, -14401, -3259, -2335, 797, 1743, -4200], [35221, -1087, 929, -1191, -3174, 3706, 9859, 2541, -1070], [-44267, -10611, -1550, 12882, 555, -1111, -254, 11819, 809], [-42578, 7458, -860, -11598, -1866, 6764, 3180, 1064, -4482], [-21601, -7955, 3248, -22266, -5789, -982, 3147, -11280, -4498], [-18894, -5185, 7876, -5347, 475, -4008, 3327, -5820, 1909], [-54261, -18701, -164, 2646, -3679, -3157, -2310, 4813, 5843], [-9289, 17643, 7771, 11239, 5468, -1085, -1158, 5660, 9697], [11738, 328, 3287, -5890, 335, 3829, -2441, 6042, -6254], [35144, -5530, -9493, 11129, -4971, 4789, -3008, -3760, -395], [-99756, -6486, -2402, -14918, 1212, -288, 5400, -118, 444], [-1611, 345, 624, 3264, -49, 3077, 4812, -4287, 357], [-9826, -2390, 5209, 16571, 7869, 3452, -2545, 6915, 1404], [4824, 2708, -7270, -7006, -7394, 3616, 1389, 2952, -3648], [-30696, -5870, 306, 2174, 1184, -1774, 1000, -9564, -11102], [62141, 2437, 2780, 11294, -6265, -996, 2379, 12918, -3192], [-495, -3237, 5837, 1717, -4250, 247, -1721, 17374, 1459], [-38444, -3808, -2535, 5049, 2915, -9183, 468, 6336, 7037], [-33310, 504, 5545, 14411, -2359, -7643, -2192, 9324, 7617], [-25299, 2159, 3563, 9251, -1792, 1503, -3758, -1008, 3895], [30925, 26443, 618, 15584, 2359, -2979, 1506, 6413, -1527], [-18301, -13580, -4269, 10874, -6625, -3439, 60, 7904, -11596], [24864, 7984, 8305, -441, -1461, -896, 5332, -8829, 86], [51972, -3003, -2772, 18161, 407, -4875, -1560, -4029, 3700], [-19233, -27357, 1793, -8574, 1088, 12941, 4634, -3872, -9064], [48369, -2174, -4273, -5930, -1501, -5351, 1624, 3270, 4140], [-5874, 10660, 1841, 8423, 7401, -2827, -2176, 6486, 3185], [7449, 16231, 4640, -24416, 1729, 5946, -2309, -5148, -1704], [63860, -4682, -5340, 16595, 11208, 5774, 1401, -1626, 719], [21142, -8609, 8129, 10018, 3658, 13944, 1864, 7443, -1447], [23480, -9436, 93, 2753, 1803, 10482, 4187, 5125, -3858], [7057, 15762, -1311, -3006, 4071, 4164, 2751, -5361, 7009], [20470, -1774, -6661, -4455, -699, 653, -1432, -14694, -2359], [-17684, -4190, -930, 9280, 5596, -358, -3475, 7712, 3514], [-58461, 7979, -3159, -3711, -862, -1217, 1519, 3678, 4673], [12566, -9392, -954, 11144, 6990, 9829, -6244, 2489, -2515], [-5397, -7293, 1749, -5710, 5300, 695, -1536, 6186, -3428], [34854, -9768, -6564, 6482, 434, 5553, 241, -12087, -2299], [32841, -9521, -11406, 1101, 485, -6957, -1307, 5975, 2566], [42562, -13400, 1571, -8711, -11219, 2707, -190, -804, -6055], [2277, 4329, -10238, -1548, -3059, 403, -3642, 1523, -1837], [-26934, 6816, 4273, -21773, -10855, 53, -1276, -7032, -1935], [23123, -873, -1966, -7418, 6289, -1811, 1831, -1313, -7649], [-10107, 17713, -4678, -6616, -321, -7729, -1534, -9843, -4459], [6183, 4557, -4554, -14970, 3381, -6375, 3564, -7731, 39], [76534, 8476, -3797, 2331, 1821, 2638, -1487, -1569, 1020], [-21322, 15800, 6533, -5554, -4359, -2561, -3929, 8660, 3214], [33759, -2028, -1735, 1372, 3479, 9457, 4308, 17664, 4650], [41108, 14410, 6486, 18474, -4166, -1489, 1628, 7287, 303], [-75202, -3142, 4974, -7054, -10760, -7414, 5208, -8420, -8102], [248, -302, 1112, -6234, 10746, 11320, 7374, 13032, -982], [5628, -1002, -1368, 31949, -1252, 1944, -5817, 1116, -7757], [38277, -2703, 1858, -11908, -4925, -6132, 5898, -5440, -5470], [15515, 10389, 6726, 10256, 4667, -5294, -9259, 3300, 16694], [-43867, -12927, -10991, -5841, -4264, 6024, 5988, -2917, -13886], [51082, -11320, 2540, 12277, 4650, 4430, 4349, -1398, -3467], [-3039, 2153, -3247, -4947, 2280, 4304, -1332, -2215, 800], [-16571, 2095, -3722, -20166, -9671, -5536, -479, -4302, -3978], [29010, 16793, 3303, 30738, -8698, -7054, 4278, 1639, -5019], [-15830, 10448, -2609, 23003, -4277, 6614, -781, 7767, 3592], [9375, -23213, -3643, -23348, -2980, -1895, 532, -5328, 6636], [-49973, -22776, -3884, -11269, -10452, 1702, 3636, -5566, -579], [-6789, 10751, -1899, -483, 9170, 2444, 244, -1079, 1988], [-14926, 24536, 2895, 17427, 4365, -11351, -3534, 14550, 5853], [53550, 990, -1926, 24432, 4620, -7374, -1264, -2004, 4192], [-36567, -3691, 102, -16534, 13341, 7206, -4663, -7014, 2284], [-45826, -10336, 403, -10473, 1065, 9099, 7053, 9390, -4243], [-12317, 4765, 941, 18920, 5432, -3580, 833, -5853, 13957], [19368, 5954, 11472, 25627, 5368, -3600, 3919, -4596, 2077], [-40038, 10154, 8201, -4735, 13783, -285, -4028, -5956, 9681], [-18870, 15011, -939, 1890, -1312, 3746, -598, 4687, 1951], [32090, -4508, -3235, 11317, -985, 4379, -4186, 11814, 3063], [6141, 6631, 3954, 23556, 13219, 7566, 5997, -5262, 3614], [-3445, 5759, -385, 13182, -554, 7243, 3958, -418, 7494], [31293, 19251, 3231, -3855, 8016, 11385, 2373, 13734, 2577], [6881, 5151, -80, 9444, 12227, -7229, -1160, -3555, 9197], [96376, -5960, 1330, -5072, -14110, -431, 50, -8637, -2277], [-39431, -14943, 8040, 19142, -1759, -8073, -6514, 1995, 5633], [10026, -540, -7445, -13199, -12675, -4950, -6793, -12873, -2178], [10027, 7063, 3206, -1266, -2449, 10974, -1641, -606, -4388], [-81799, -4067, 9882, -4987, 1633, -6009, 5621, -2323, 10780], [103470, 18502, 4237, 14051, 16143, -6728, -6785, 20907, 3780], [-50951, -562, 8384, 4847, 1958, 2951, 2649, 20991, 436], [9876, 11632, 6471, -22131, 20899, 1060, -3281, -4479, 8856], [4987, -3975, 10472, -22844, -4649, -9521, 1296, 10645, 2597], [21996, -11300, -8560, 13890, -4182, -6097, 1429, -2133, -3503]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_507_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_507_4_a_p();".
// 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_507_4_a_p(:prec:=9)
    chi := MakeCharacter_507_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_507_4_a_p();".
// 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_507_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_507_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-1016, -2288, 11386, -1401, -3075, 452, 251, -40, -6, 1]>,<5,R![48900601, -29476244, -2833568, 3228609, -239411, -66645, 8831, -8, -33, 1]>],Snew);
    return Vf;
end function;