
// Make newform 1150.4.a.p in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1150_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_1150_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_1150_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 := [342, -111, -68, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [18, -50, -3, 1], [-34, -2, 1, 0]];
    Rf_basisdens := [1, 1, 3, 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_1150_a();"
function MakeCharacter_1150_a()
    N := 1150;
    order := 1;
    char_gens := [277, 51];
    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_1150_a_Hecke(Kf)
    return MakeCharacter_1150_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 := [[2, 0, 0, 0], [1, -1, 0, 0], [0, 0, 0, 0], [0, -2, -1, 0], [-10, 1, -1, -1], [5, -8, 0, 1], [6, -13, 1, -1], [14, 2, 3, -2], [23, 0, 0, 0], [41, -14, 3, -3], [97, 16, 0, -5], [-116, 18, 2, -4], [121, -1, 0, -10], [-222, -24, 6, -6], [67, -44, 3, 11], [-146, 40, -8, -8], [-20, 10, 14, 2], [290, 33, 7, -19], [368, -28, 0, 12], [57, 39, 28, 4], [-287, -44, -1, 3], [-232, -72, -20, -16], [256, 26, -24, 6], [-450, 30, -16, -34], [504, 137, -31, -1], [86, 46, -22, 62], [-10, 127, 45, 5], [972, -12, -30, -4], [352, 14, 5, -26], [210, 104, -20, 12], [805, 70, 1, -5], [247, -66, 45, -19], [862, 38, -25, 56], [961, 94, 1, 27], [280, -230, 27, -34], [-191, 83, -64, -32], [-446, -322, -10, -14], [-173, 108, -6, 13], [2120, -48, 36, -48], [-1584, 175, -23, 29], [849, -208, -7, -7], [634, 238, -97, -16], [-1662, -90, 40, -24], [-1031, 212, -65, 3], [-477, -95, 60, 26], [-16, 206, 52, 10], [1344, 266, 116, -62], [-1488, 276, 116, 20], [1006, -52, -12, -82], [1638, -4, 36, -80], [-253, -276, 81, 117], [-2697, -308, 49, -45], [-2218, -266, 88, -130], [-1234, 150, -87, 222], [-1101, -468, 49, 77], [1814, -651, -13, -133], [661, -110, -181, -47], [3554, -156, 151, 200], [-1287, -964, 137, -5], [-330, 334, -46, -54], [3514, -406, 82, 72], [-1280, -88, -218, 26], [1450, 545, -47, 83], [171, 992, -63, -29], [-4830, 206, 49, -112], [-3656, -424, 105, 60], [-555, -202, -263, 15], [1712, 438, 5, 58], [3902, 187, -105, 217], [5249, -452, 141, 95], [1057, -734, -87, -79], [1712, -802, -80, -270], [-2796, -420, -8, 104], [-3314, -36, 150, 32], [-650, -1777, 129, 93], [-1870, 200, -170, -310], [-3942, -1049, 153, -21], [-2667, -851, 74, 64], [-1602, 892, 438, 140], [-3569, 348, -154, -377], [-3954, 268, -10, -6], [-1816, 606, 129, 70], [6366, 200, -116, -142], [-2288, 490, 277, 30], [-5057, -36, 54, 133], [-5067, -604, 26, 275], [11052, -56, 175, 68], [-5128, 440, -90, -78], [4625, -44, 99, 195], [-1444, 238, 228, -202], [-4086, 1338, 168, 84], [-6740, 790, 268, 22], [-4935, 666, -83, 275], [1661, -1876, -27, 113], [4007, -612, -67, 359], [-4800, -802, -441, -240], [3761, 910, -249, 385], [-3364, 1624, -398, -198], [-2838, -574, 14, -320], [6161, -82, 109, 61], [-3237, -24, 28, -107], [-4342, 1566, 120, -186], [3072, 200, -192, 224], [-2062, 560, 404, -200], [-5038, 173, 267, 7], [4101, -1612, -443, -429], [-10379, 483, 68, -400], [3546, 64, 250, -120], [1974, 1985, 461, -109], [-13425, 228, 150, -321], [2280, -840, 48, 32], [4300, 920, -554, 102], [4002, 511, -435, 399], [-17474, 282, -279, -62], [-21790, -138, -120, 8], [874, 694, -660, 34], [-12546, 1304, -512, -470], [-7733, 678, 485, 69], [4089, -412, -572, -199], [-8996, -1136, 120, 500], [-12340, 2365, 77, 547], [2439, 2912, -305, -111], [3830, 2048, -736, 72], [7975, -656, 574, 221], [-4508, -76, -234, 440], [2212, 1346, 11, 474], [-3396, 287, -93, -139], [10406, -2044, 457, 496], [-10776, 3511, 535, 559], [22780, -836, 26, 266], [10369, -3600, 11, 125], [8898, -150, 441, 790], [-12118, -490, -412, 384], [-3900, -1410, 34, -560], [2615, -1764, 74, 487], [-3266, -3120, 48, 684], [-8446, -878, -596, -582], [23764, 1694, -246, 58], [-264, -3856, 416, 574], [3764, 885, 151, -169], [14487, 1964, -45, -141], [3530, -1704, 544, -388], [-7309, -3202, -39, 301], [7280, 1450, -662, 674], [20022, 1152, -320, -376], [2614, -340, 80, 302], [13296, 152, 123, 648], [-4205, -1312, -621, -59], [-3509, 4852, -661, -465], [-12919, 718, -379, 1135], [-17472, -3755, -297, 835], [-3944, 4742, -470, 400], [-11314, -796, -431, 484], [-1261, 2636, 649, 439], [24988, 860, 202, -500], [7576, -752, -686, -284], [12666, -116, 562, -538], [8699, 1356, 47, -875], [19866, -3426, 447, 140], [-5762, -1803, -1013, 941], [-5731, 1432, -526, -1345], [17900, -639, -367, -581], [16717, 746, -467, -329], [20808, 2263, -497, 431], [-10470, 62, 469, -872], [27860, -913, 583, -101], [15566, -4899, -243, -313], [6910, 2384, -232, -580], [-36, 3508, 140, 138], [29169, 465, -534, -8], [-21840, 4536, -604, -760], [3257, -370, -1217, -231], [10032, -3336, -618, 76], [9550, 1045, -745, -911], [-18465, 2719, 1402, 274], [16414, 2774, 930, -998], [-16031, -5630, -705, 715], [34947, 1014, 363, 87], [5162, 2243, -327, -315], [18986, 2118, -439, 380], [9441, -206, 225, 635], [1340, 5651, 91, -329], [2015, 5464, -226, -149], [-5434, -4058, 422, -186], [8520, -3057, 527, 15], [-15446, -426, 181, -892], [-704, 4484, -767, 704], [2044, 4320, -520, 348], [-20337, -6489, -286, 980], [11114, -649, -173, -1355], [-13921, -2516, -1479, -191], [24176, 68, 684, 648], [-2614, 5556, -250, -210], [-10702, 1202, 1712, -622], [16154, -6918, -186, -624], [34880, 4506, 305, -346], [2240, -2234, 60, 1596], [-6544, 424, -98, 2242], [12476, -5440, -870, 574], [-187, 1640, 789, -2319], [10306, 6389, 1495, 265], [-32970, -3388, 47, 404], [-20489, 6997, 348, 1250], [7072, 8086, -354, -144], [11192, -6816, 344, 168], [-38319, -4816, -919, 1063], [1240, -8774, 648, 22], [37937, 1361, -698, -542], [21325, 272, -850, 701], [7721, 3784, -1263, -463], [-19717, -6910, -811, 1351], [35379, 700, -1717, 33], [-41276, -2518, 1675, 64], [56846, -1744, 840, 58], [-9860, -2880, -1224, 2420], [-36806, -2902, -1042, 282], [30255, -1790, 647, 321], [7509, 936, 333, -29], [-10868, 462, -1807, -768], [-7529, 1964, -1105, -1023], [-12233, -1382, -739, 1251], [1860, 442, 576, -470], [10267, 4761, 64, 1658], [30564, -4118, 601, -300], [-69153, -2876, -719, 919], [3955, 5062, -1463, -845], [18710, -2762, -543, -4], [14523, 308, 1350, 201], [-28920, -5954, 957, -1396], [47220, 7152, -72, -672], [348, -6344, 967, 996], [-3036, -427, -1419, 1321], [-7678, -808, -1262, -798], [-17624, 3059, 1285, -431], [-35208, 8356, -382, 72], [10622, -4216, 390, -698], [-10296, -6806, -128, 560], [-37096, 1874, 1300, 940], [-53077, 3596, -629, -1697], [-1061, 6193, -1648, 616], [51996, 3724, -30, -284], [44787, 1366, -155, 2041], [25775, 8542, -2387, -39], [44451, -108, -167, -2019], [-36662, 490, 1226, 286], [-58155, -6164, -966, 871], [7831, -588, 1011, 295], [-27800, -5646, 1733, 0], [-41564, -2681, -337, 1347], [18368, 1421, -2375, 309], [-27812, -2836, 1604, 230], [-9950, 260, 1258, -320], [-30376, -782, 1013, -504], [19114, 1662, 728, 994], [86690, 1584, 844, -992], [-18627, -5418, -867, 1135], [41878, -3193, 737, -1089], [46298, -4826, -80, -592], [-14849, -4632, 642, -29], [-57195, -6820, -1923, 2435], [-41210, -4523, -1177, 699], [41150, -4506, 1174, 3280], [-14258, -6058, -992, -222], [-26594, -5526, 1326, -1294], [-17306, 5420, 1700, -1260], [21186, 141, 139, 919], [-9350, 13693, -2309, -1263], [-4374, -14180, 1432, 2068], [-7332, 1570, -2294, 630], [-4981, -3816, 972, -949], [-51511, 12534, 539, 169], [-48886, 1452, 650, 2110], [-72336, 1102, 767, -626], [-8258, 5988, -1470, 1194], [-3855, 5628, 2377, -1737], [-42917, 1546, -1241, -2339], [46978, 5233, 201, 1563], [6282, 482, 2310, 1926], [-34442, 7384, 1852, -236], [-28402, 5906, -341, 6], [47729, -6520, 1035, 1497], [-25390, 1684, 1798, -394], [92686, -2057, -927, -1259], [-53766, -1672, 2940, -1024], [47346, -1224, 1957, 932], [82178, 467, 1611, 1193], [-50794, -12928, -988, 3128], [-39860, -6320, -1076, 2282], [-36174, -4663, 2997, -1529], [-24316, 11649, 2483, 2299], [-6590, 500, 440, 2308], [-31180, -13214, -626, 2502], [-36550, 3080, -886, -1112], [-70234, 11758, 21, 94], [-45953, -6709, -3434, -208], [61484, -5155, 1789, -1085], [-14936, -2600, -2182, 444], [73917, 10007, -984, -398], [19265, 15934, 883, -2793], [-2485, 9931, -782, -962], [-7884, 8962, 271, 2302], [-62492, 7438, -768, -2396], [100204, 1254, -1382, 1098], [-3595, -16, -1589, 2985], [73694, -5770, 341, 166], [-74045, -6092, -203, -819], [50282, 13337, -2219, -901], [50382, 4162, -1627, -1140], [24570, 5040, 56, -3098], [-58076, 9103, -1283, -1071], [68499, -14048, 903, -1457], [-26770, 9510, -261, -2092], [-13360, 3712, 1544, -2238], [-49809, -11005, -1686, 3314], [82630, -13750, -1373, -1922], [-66566, -1950, -450, -1894], [47109, 5326, 2431, 1987], [-66255, 1260, -1770, -2477], [21116, -752, 946, -2338], [-5019, -10761, 856, 4202], [-66508, 5215, -2873, -1837], [-16664, 8525, 3201, 2115], [93683, 420, 355, -1135], [-31836, -5576, 3206, -176], [18644, 2143, 4219, 1785], [20200, 11782, -2, 1088], [-107856, 714, 1597, -1016], [60851, -9352, 230, -3495], [130966, 9570, -771, -646], [26620, 1854, 4740, 2268], [20693, -8332, -1969, -4121], [131685, 175, -1072, 1082], [33729, -2028, 763, 5029], [12799, -13552, -158, -2091], [-376, 4556, 1696, -340], [116311, 10240, 722, -2387], [10276, 5921, -3475, 599], [42446, 6868, -2560, 1484], [-45815, -4699, 5038, -276], [-4676, -1795, -83, -4735], [-1801, -2952, 2699, 933], [43932, 1491, 2879, 1749], [-942, -6538, 2496, 1494], [15666, 56, -644, -122], [49406, 7740, -2708, -1940], [49372, 3812, 1700, 52], [17759, -6288, 3307, 3089], [-137610, -1984, 1123, -2108], [16954, -8434, -1282, -924], [16814, 1806, -1550, -938], [70067, 2124, 2039, -2209], [-47799, 1468, -1011, 2303], [-68270, -3304, 1834, 2008], [71464, -13855, -375, -1647], [-18980, -16532, 3062, -394], [-102170, 11778, -138, 570], [-12032, 1250, 1666, -830], [-28348, -10802, -2435, -112], [981, 10096, -1347, -2617], [31544, -3222, 876, -282], [-7534, -8420, -850, -5804], [-11879, 19452, -171, -397], [8317, 25158, 789, -453], [11560, 12403, -857, -1885], [40639, 3805, 1556, 4124], [-99611, -11080, 2745, 671], [31101, 7773, 3174, -3184], [-53188, 14920, 3084, 1156], [11822, -26798, 594, 3046], [7141, -6022, 1295, -4489], [-7320, 15970, -2994, -4218], [-5381, -4954, -219, 2005], [109590, 15763, 3293, -1509], [-20464, 14500, 1388, 3820], [45325, 15032, 5746, -883], [-35463, 3520, -1743, 6393], [-16948, -14530, 1114, -62], [-5260, 933, -2339, -5449], [33688, -16938, -3124, -2228], [65051, -1006, -1365, -357], [37428, -173, -761, 4689], [-41778, -16193, 1193, -493], [48260, 4734, -2866, 714], [21315, -3016, -773, 6085], [99774, 1632, 2326, -2474], [19805, 3604, 2127, -1071], [68811, -7452, -510, 273], [-31544, 24300, -1215, 1632], [26454, 10250, 2318, -3380], [-25066, 19390, -2611, 3318], [37500, -956, 6706, 3182], [36260, -1872, 2271, -1604], [149051, -10408, -1319, 127], [-115260, 17616, 548, -320], [14494, 802, -2398, 3452], [-130576, 13146, 2181, 2390], [54278, 20382, -4774, 856], [58046, -7294, 132, -3094], [-48206, 12670, 1573, -766], [133786, -10976, 1772, 60], [-126669, 3028, -2807, -419], [-122939, 2744, -2409, 259], [1298, 2572, -426, -2962], [-65646, -11346, 4525, -5240], [39079, 11350, -3777, -2069], [-25439, -19191, -2778, 3430], [-13892, -12042, -812, 1884], [-11669, -14768, -7858, -2385], [-19750, -8100, 3932, -3502], [-32268, -2304, 5184, 472], [105315, 13920, -3991, -343], [-60783, -12427, 4246, 1340], [-34304, 17904, -4272, -4888], [-61312, -771, 1629, -2899], [9130, -10366, 1755, -4736], [-34239, 780, 873, -3289], [-40662, 16032, -3859, 832], [60244, -1996, -3938, 1644], [44684, 10003, 5019, 3317], [25848, -3962, -4941, -4696], [105820, 787, -1065, -1255], [3546, 870, -3394, 314], [15836, 9596, 2298, -6836], [-41784, 5212, -2738, -3580], [56533, 1818, -3853, 6881], [29195, -8580, 1323, 7237], [-94956, -5328, -2604, -2900], [-7416, 15204, -1359, 2008], [-7817, 8222, -4565, -4255], [-18943, -17387, -2246, -3638]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1150_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1150_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_1150_4_a_p(:prec:=4)
    chi := MakeCharacter_1150_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_1150_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_1150_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![164, 243, -62, -4, 1]>,<7,R![453664, -2618, -1507, -1, 1]>],Snew);
    return Vf;
end function;