
// Make newform 1300.4.a.k in Magma, downloaded from the LMFDB on 10 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1300_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_1300_4_a_k();".
// 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_1300_4_a_k();".
// 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 := [65, 2, -30, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [5, 49, 1, -1], [-17, -25, -1, 1], [-43, 17, 5, -1]];
    Rf_basisdens := [1, 6, 6, 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_1300_a();"
function MakeCharacter_1300_a()
    N := 1300;
    order := 1;
    char_gens := [651, 677, 301];
    v := [1, 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_1300_a_Hecke(Kf)
    return MakeCharacter_1300_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, 0], [-1, 0, 1, 0], [0, 0, 0, 0], [2, 0, 1, -1], [7, -3, -1, -1], [-13, 0, 0, 0], [-50, -1, 5, 4], [33, 1, -7, 3], [-61, 7, 0, 2], [-2, 4, 16, 6], [73, 2, -6, 9], [-42, 3, -33, 4], [70, -13, 5, -8], [-113, -6, -43, -6], [70, 16, -29, -3], [-146, -17, -39, 0], [-177, 1, -27, -11], [282, 18, -26, -10], [-44, 10, 59, -11], [-257, 6, 2, 23], [-166, 17, -85, -26], [-182, -8, -110, -28], [-138, 14, -25, 23], [-706, 2, 118, -24], [-290, -16, 0, 32], [34, 2, -26, -8], [657, 23, -126, 6], [363, -10, -37, 8], [-314, 58, 34, 8], [-206, -65, -19, 12], [227, -45, 24, 2], [-128, -72, 42, 14], [-238, -10, 234, 72], [-970, 18, 92, 48], [-450, -64, 164, -28], [509, 122, 106, -55], [-1106, 90, 74, 0], [-448, 8, 79, -29], [1482, -134, -297, -65], [-1926, 27, -255, 12], [-32, -6, -348, -22], [1118, 62, -26, -130], [684, -132, 216, 48], [-1406, -92, 288, -44], [122, 238, 10, 8], [-616, -38, 248, -14], [1484, 14, 352, 158], [-2038, -132, 261, -121], [-2328, -54, -203, 3], [614, 117, 411, -48], [434, 274, -202, 44], [-2229, 54, 284, -135], [594, 233, 19, 88], [3166, 88, 308, -138], [-1658, -38, 526, -60], [-1397, -101, -50, 120], [370, 352, 24, 0], [393, -338, 54, 45], [-1990, -51, 75, -280], [-1686, -189, 161, -144], [-1249, 356, -133, 106], [2534, -53, -577, 104], [-2954, -42, 829, -99], [-4602, 150, -528, -60], [-2454, -225, -123, -104], [1918, -127, 921, 136], [5589, 173, -477, 289], [2586, -411, 507, -8], [-3655, 142, 249, 152], [-66, -51, 143, -232], [5538, -93, -195, 150], [-2869, -252, -910, 265], [-1483, -65, -760, 384], [-1970, -206, 114, 208], [3579, -123, 1233, -43], [-1078, 482, -761, -177], [-5410, 72, -80, -200], [2486, 209, 969, -164], [-10970, 170, -758, 28], [4550, 177, 327, 552], [962, -228, 964, 118], [-4238, 266, -1102, 204], [-4971, 112, 724, 349], [-5694, 4, -120, -16], [4788, 566, 398, -104], [1995, -254, -1421, 40], [-1734, -111, -657, -264], [846, -574, 34, -12], [2954, -275, -2069, -112], [-320, 134, 1031, 353], [883, 450, 453, -118], [-5805, 264, 1994, -27], [-2344, -138, 1227, 77], [4854, 490, 462, 346], [6737, 123, 1503, -93], [-703, -5, -204, -376], [4230, 245, 275, -124], [-2974, 424, 1258, -400], [-2513, 94, -2461, 208], [2610, 93, -1265, -424], [2111, 496, -375, -396], [-1370, 279, 1923, 44], [-8433, -166, 821, -550], [9110, -172, 2374, 168], [-3530, -506, 500, -436], [-1182, -515, 431, -82], [-3472, -260, -641, 47], [2454, -306, 1606, -420], [-670, 402, -1116, 496], [6450, 80, 2320, -200], [-1097, -769, -722, -76], [166, 44, 1520, -100], [-7910, 280, -1508, 348], [-4353, 169, 1693, 93], [-6693, 1008, 1884, 443], [-4998, 250, 2710, -392], [6678, 68, -911, -57], [3391, 485, 1262, 286], [2442, -686, 30, -308], [11542, -556, 784, 166], [-5990, 542, -2014, 360], [4302, 253, 291, -712], [-12290, -1145, -91, 108], [6436, 102, -1493, -7], [14169, -1075, -1565, -419], [-13134, 848, 1072, 320], [-242, -643, -2649, 684], [12196, 284, -502, -134], [18781, 457, 616, 958], [8426, 404, -32, -236], [-12831, 927, 819, 695], [3950, 666, 1371, 391], [-6490, 834, -1926, 186], [-17894, 337, 2411, -500], [-15462, -704, 772, -236], [-2130, -140, 1568, 864], [-15306, -963, 1013, -60], [22514, 78, 1913, 797], [4482, 354, -1286, 444], [1442, -402, -4716, 52], [-3995, 343, 2625, 809], [-6462, -28, -3808, -1384], [22169, -115, -2132, -866], [-23274, -278, 115, 727], [6538, -256, -588, -1278], [8377, -1300, -2230, -557], [4230, -2203, -1655, -132], [-29130, -70, 674, -592], [1882, -486, -4142, -1190], [-4738, -2036, -1211, -229], [6118, 912, 624, -768], [1966, -1000, -3606, 28], [607, -2278, -51, -22], [-79, 261, -826, -800], [15627, 22, 1901, -442], [7248, 250, -1172, 766], [-30146, -662, 2024, -472], [21770, 1349, -881, 1644], [-7814, -288, -3576, 492], [-17802, -405, -123, -840], [-7662, -870, 2839, 1047], [-18714, 772, -4888, 520], [7132, 2504, -491, -475], [11720, -846, 1812, 298], [4074, 673, 5059, -338], [-8504, -270, -157, -895], [-484, 750, -426, -1560], [-14194, 741, 1215, 1436], [-15034, -376, -1740, -568], [-28554, 1305, -3465, -456], [-3121, 1687, 3483, 1661], [13162, 477, -3837, 388], [-12826, 360, 820, 394], [-10046, 883, 1717, 358], [-42280, -282, -114, 708], [-18766, 1608, -2168, 16], [-3227, 1891, 1705, -535], [-7402, 1283, -5143, 1104], [-1989, 721, 7274, 206], [-16386, -604, -2572, 1936], [-2786, 1192, 2531, 757], [7598, -720, 2182, 16], [-11730, -429, -4259, -1388], [-9726, -470, -1646, -2228], [-4692, 2388, -1257, 747], [6462, -2026, -2862, 758], [-7322, 1068, -4956, 60], [14562, 2224, 1277, -493], [-874, -1217, 2637, -500], [19421, 428, 1384, 33], [18946, -881, 3321, 592], [-23358, -962, 3703, -485], [-9408, -614, 1648, -210], [10958, -3146, 4826, -568], [10737, -1820, -1171, 1246], [-21166, 1056, 7140, 1504], [-18274, 2201, 3923, -292], [33770, -878, -5870, -852], [-35526, 689, -4929, -10], [-30519, -857, 856, 328], [6366, 1329, -453, -2328], [15520, 708, -506, -38], [4334, 1176, 2612, 2084], [-20606, -118, 4848, -1500], [18581, -2663, -4243, -1417], [-13894, -391, 835, -540], [17111, 1282, -480, -875], [24099, -390, 6699, -1440], [-8530, -162, 2994, 652], [-33702, -2054, 938, 1410], [11154, -676, 2536, -600], [-19878, -2022, 2682, -198], [23369, 1279, 236, -1524], [-29286, 824, 4699, -799], [3721, -376, -5962, 655], [12446, -1463, -7369, -1772], [3201, 445, -1506, -280], [-39410, 2316, -2812, -520], [-15364, -542, -3947, 1031], [37426, 2120, 2192, 2320], [20122, 1934, -834, -990], [-52475, 806, -5220, -429], [-27874, 1462, 1870, 764], [9586, 514, 6449, 961], [1775, 708, -6229, -2594], [43122, 240, 3000, 638], [-9318, 380, -9364, 1592], [2750, -786, -566, -3266], [69301, 993, -2880, 198], [-8383, 2389, -2381, 1073], [-6238, -2532, -1780, -2212], [-19938, -1070, -5662, -3834], [47099, -2062, -2162, -781], [-31338, 2194, 4174, 1672], [687, -4116, 5261, -200], [-73668, 1182, -4345, 429], [69922, -2877, -683, -404], [-27330, -1271, -4707, -932], [61828, 210, 4344, -166], [-33984, -734, -6426, -800], [-14790, 2810, -5395, 1013], [15462, -200, 6290, -1308], [12677, -2871, -6474, -2308], [13366, 1869, 7935, -2348], [43474, -2784, -10264, 344], [54056, -718, 7286, 624], [-6486, -1496, -2073, 341], [-42673, -1177, -5883, 1335], [-3693, -2519, 2589, -147], [4605, -4181, 1054, -398], [-9826, -1099, 5101, 3868], [-36646, 2732, 6480, 900], [-72650, -452, 2329, 135], [55930, -544, -1376, 1728], [-7026, 868, -80, 1156], [89959, -1347, 4289, 725], [-29378, -4412, 1592, 122], [-24936, -60, -2643, 1885], [-43706, 940, -2844, -192], [34498, 575, -3983, -22], [5775, 707, -11360, 1026], [-39763, 284, -2505, 1872], [43098, -601, -1023, -1184], [-6486, 4537, 5031, 2516], [56370, -1731, 9855, 1266], [24974, 720, -618, 1080], [10618, -775, -4921, 1060], [-8954, -3772, -7124, 2188], [-31632, -2218, 6337, 1227], [20890, -839, 6219, -264], [74746, -798, 4358, 328], [60992, -1040, -6393, -1629], [194, 396, 168, -1396], [-12712, -1482, -876, -1710], [-10142, -2713, -4207, -2164], [-74442, -1118, -6061, -1321], [60216, 2370, 4629, -21], [-53774, 1915, -13219, 620], [50114, 789, -7949, -1608], [-34762, 3286, -6668, -940], [87445, -1791, 3222, -988], [-21237, -2430, -2346, -2905], [727, 927, -2542, 1472], [57082, 3313, 4559, -652], [-72750, -1534, -1463, -2775], [-40514, 298, -6146, 582], [26714, -4222, -3242, 28], [11686, 2790, -9338, 3596], [26711, -128, 3322, 817], [33222, -3824, 5794, 616], [-55798, -2274, 6982, -1238], [-37597, 446, -9825, -1764], [57254, -858, -2942, 64], [-71089, 511, -3971, -1201], [8990, 2320, 7404, 5940], [-64474, 1220, 5004, -528], [21796, -542, 15860, 1850], [-15346, 2714, 6502, -2724], [-3550, 2468, 2250, -2556], [70478, 4106, -3769, -5], [-8514, -1686, -4486, -2300], [-57378, 446, -1638, -2152], [-1956, 4358, -11456, 346], [108815, -888, 9977, -152], [1416, 2418, -5618, -868], [53810, -749, 1573, -2934], [-32645, 1774, -7755, -3378], [97754, -1354, -4358, 1064], [-7287, 2782, -8624, 1627], [-27722, -1838, 2534, -440], [-61457, -1343, 6564, -4632], [40850, -4329, -14847, 460], [-9870, 4384, -6122, 268], [15601, -1132, 19023, -1000], [27598, -2466, 5639, -2377], [-80966, -5030, -5564, 4592], [87637, 101, -9207, 1075], [-59469, -26, 9562, 2971], [-56830, 6227, 16557, 3106], [-70762, -52, -4908, 2064], [-26422, 2428, 1992, -3902], [-10334, -7811, -5797, 1090], [-16166, 2722, -10110, 3522], [8420, -4862, 267, 237], [-14134, -627, -673, 5398], [119966, 1602, 2360, 2184], [-48785, -4291, 1493, -567], [-19198, 7038, -3165, 2495], [975, -303, 4198, -2190], [-74750, -4224, 10016, -5764], [-40262, 2848, 19916, 4124], [-6658, -9054, 6238, -2264], [-72918, -1154, -1792, 2160], [-6504, 1874, 13721, -2065], [14799, 2687, -5779, 4003], [-32520, -3430, 4223, 677], [29194, 462, 17578, -3452], [-16170, -2412, 112, -1356], [37458, 313, 14519, 6516], [-45785, 3159, -7764, 1518], [-23782, -10126, 442, -908], [-37998, -6857, -4427, -5300], [-73098, -3712, -9148, -412], [55034, -7300, -1978, -124], [-75270, 1058, -8974, 1844], [-59340, 3388, 13034, 2302], [105738, -2776, -10024, -1976], [39014, 60, 19689, 4943], [-5007, 1466, 14438, 3113], [-71030, 910, 10302, -1920], [8609, 5177, 1859, 4241], [-11646, 664, 3032, 4760], [-36714, -2920, 7416, 1328], [-59219, 537, 4888, 1218], [41206, 168, -20616, 3856], [-88562, 1989, 2183, -208], [1097, -1296, 17446, -893], [-3035, -4103, 4591, -3015], [34626, 6528, 5940, 1812], [-101354, 1916, -8933, -1631], [95862, -5677, 6547, -1548], [33810, 2544, -5706, 3768], [-52923, 3013, -1754, -3476], [88975, 2815, -5661, 477], [-145655, -3928, -523, -2686], [46790, 5973, -4385, 3140], [70910, -7578, -5514, -284], [39788, -2408, -6723, 741], [27858, -3662, -19018, 0], [-51872, 1090, 144, -3666], [15640, -672, 21340, 1912], [-50228, -3292, 7599, 6547], [-13854, -2376, 2940, -1362], [-500, 11840, -4094, 3126], [-42634, 8081, 20203, 664], [-8215, -10569, -4457, -2537], [31474, 4776, 3018, 8588], [10726, -3478, -18806, -7228], [-113450, -1990, -4772, -2408], [45586, 5003, 521, 4076], [42226, -1183, -8989, -260], [-4566, 2915, 5045, -4942], [51318, 5598, -1665, -5897], [57114, 1399, -1571, 5278], [52677, 5745, 3133, 2423], [-34808, -5962, -16781, -299], [-43, -516, -10272, 1269], [-9182, 1083, -7187, 768], [-17794, 6718, -6965, 1275], [-94593, 2325, -13416, -3876], [-132554, 1435, -11995, -28], [-19474, 383, -7429, 900], [-24797, -691, 10105, 2785], [-134625, 494, -6593, 1368], [-31231, 2396, -5512, 141], [798, -2526, -13174, -5384], [-69605, -3968, 14606, 1829], [-96222, 974, -25548, 2696], [64004, -1582, 8494, -256], [73214, 5832, 168, -3464], [42574, -11808, -8280, -4112], [16790, 2713, -21561, 2408], [116534, 80, 15231, 5785], [-151334, -2159, -9857, -3786], [-59446, 11728, 2860, 2708], [75952, -3798, 17106, -332], [30886, -17, 11523, 8920], [39134, -2180, 884, -5008], [50124, -10036, 9547, 2079], [105467, -1391, -5751, -3571], [58998, -2614, -198, -6612], [-113358, -2151, 2015, -252], [42401, 6988, -18077, 524], [-12302, -9780, -6528, 2290], [-39990, -11160, 2768, -3872], [-27690, 244, 12484, -2288], [14391, -184, 15914, 4661], [-24705, -6859, 13148, -2592], [-50694, -5429, 11013, 7486], [-95723, 3779, -7454, -1562], [-26134, 7124, 6508, 1062], [80626, -1076, -12740, -5720], [-24180, 9990, -15345, 1269], [9402, 2166, -15174, 1398], [-66666, -7150, 6226, -660], [94974, -5647, -5899, -3580], [14571, -1366, 9881, 2018], [-5046, 6239, -2651, 7712], [29817, -5025, 27101, 4781], [20846, 7238, -1100, 2880]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1300_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1300_4_a_k();".
// 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_1300_4_a_k(:prec:=4)
    chi := MakeCharacter_1300_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_1300_4_a_k();".
// 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_1300_4_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1300_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![228, -40, -64, 4, 1]>],Snew);
    return Vf;
end function;