
// Make newform 1521.4.a.bb in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1521_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_1521_4_a_bb();".
// 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_1521_4_a_bb();".
// 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 := [78, 24, -25, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-13, -1, 1, 0], [15, -19, -2, 1]];
    Rf_basisdens := [1, 1, 1, 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_1521_a();"
function MakeCharacter_1521_a()
    N := 1521;
    order := 1;
    char_gens := [677, 847];
    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_1521_a_Hecke(Kf)
    return MakeCharacter_1521_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, 0, 0, 0], [-1, -1, -1, 0], [4, -1, 0, -1], [8, 4, -1, 1], [0, 0, 0, 0], [-15, -19, 0, 1], [-28, -6, 7, -1], [-28, 4, -1, -3], [-43, -11, -1, 6], [20, -53, 7, 0], [-15, -21, 2, 1], [-285, 43, 0, 3], [84, 57, -14, -1], [-20, -8, -47, 3], [-47, -37, -23, -2], [72, 10, 24, 14], [-245, 26, -31, -3], [348, -129, 14, 1], [304, -76, 49, 11], [-335, 194, 24, 2], [-176, -21, -7, -2], [-32, -138, 1, 5], [478, -146, -50, -28], [-506, -71, 63, 22], [-675, -151, 99, -6], [-236, 41, -34, -45], [-152, 208, -23, 7], [310, 101, -33, 2], [-407, 31, -2, 53], [-416, 219, 89, -26], [-200, -406, 46, -20], [-161, -189, 70, 9], [-220, 149, 21, -4], [-725, -287, -71, 40], [1164, 442, 17, -43], [443, -270, -45, -21], [348, 369, -31, -20], [1652, -60, 26, 42], [-718, -508, 92, -4], [280, -350, -167, -119], [-85, 489, 84, 69], [-384, -38, 144, -78], [-323, 296, -66, 74], [-670, 286, -190, 16], [-3136, 515, 102, -19], [396, -97, -11, -146], [-1328, 0, 336, 0], [-1684, 686, 263, -17], [1030, -44, 0, 100], [-2758, 544, 188, -16], [1420, 446, -29, 31], [-131, 557, 135, -70], [1548, 132, 234, 134], [-15, 401, 186, 183], [-3564, -66, -51, -95], [-3570, -690, -42, 56], [2656, 667, 291, -68], [247, 1129, 170, -97], [-1873, 521, 2, -9], [-1272, 77, 76, 145], [-2473, 335, -115, -2], [1252, 1291, -174, 1], [1256, -34, 287, -57], [-30, 437, -773, -50], [3279, -375, -189, -126], [-3940, 687, -89, -100], [2787, 510, 220, -70], [-2256, -374, 399, 27], [-6650, 19, -519, -50], [-7741, 25, -262, -77], [-2664, 1134, -603, -99], [-552, 1415, -572, 139], [2071, -1430, -751, -19], [-1984, 1625, -161, -74], [5236, -604, -128, -184], [-2143, -41, -265, 188], [4246, -1089, 177, -78], [-1753, 827, -574, 233], [-5223, -422, -10, -52], [-4960, 252, -256, -76], [1229, -992, -521, -171], [3308, 474, 95, -189], [5631, 100, 370, -150], [792, -1795, -164, -311], [-4612, 2308, 290, 110], [-1390, 1244, 308, 184], [9549, 486, 134, 256], [-2289, -251, -147, -316], [-2936, -123, 198, 231], [688, -1492, 1, -113], [-10468, 972, 50, -198], [1580, -1614, -185, 95], [-2268, -784, 363, -279], [9980, -288, 802, 182], [-1636, -648, -403, -165], [-2385, -853, 405, 106], [3733, 1389, -92, -379], [660, -14, -101, -333], [1013, -88, -1121, -59], [-1432, -473, 126, 505], [-2053, 905, 1121, 332], [12640, 2798, -812, 174], [-2810, -820, -1748, 140], [-11396, 310, -1423, -343], [-8927, -1347, -609, -150], [4284, 606, -282, -4], [-7161, 3213, 282, -21], [9748, -2246, 1594, 588], [-10785, -33, 745, -22], [-7204, -2496, 690, 102], [-347, -3814, -45, -61], [-9173, -783, -692, 453], [5520, 1023, 995, 16], [-1396, -243, -155, -148], [4561, -3393, 820, 115], [-6088, -3803, 493, -516], [7256, -538, -694, 52], [-10990, 3990, 626, -136], [6280, -1148, -68, 440], [-3603, 1786, -343, -43], [2479, 3396, 734, 358], [3930, -718, -1290, -208], [4540, 1406, -1754, -124], [2560, 2317, 1356, 193], [8830, 4814, -866, 544], [-9155, -1732, -1149, 461], [13492, -2338, -1676, -414], [-6684, 5605, 670, -465], [-4887, 1260, -277, -11], [5912, -4820, 1108, -96], [21832, -4906, -452, 162], [-2540, 598, -745, -733], [-18258, -1792, 352, -440], [3894, -618, -1602, 4], [-414, -512, -1420, 548], [-7086, -668, 1584, 68], [4380, 2537, 965, -792], [-13234, 1550, -2206, -496], [4405, 4921, -1226, -17], [5348, 547, 1735, -120], [5610, 976, 48, -864], [-604, -1032, -2178, -750], [9596, -4172, 698, 1058], [-18545, 3708, -607, -665], [9168, -7486, 342, -120], [8101, 2362, -147, 889], [-1187, -4797, 1102, 461], [-24892, 1705, -384, -359], [4308, 3820, -333, 13], [20033, -1037, -746, -219], [-7343, 477, -2060, 225], [-7016, -3711, 929, 340], [-1016, 3758, -824, -118], [6016, -3512, 1574, 1034], [7232, 7300, -34, -334], [-22884, 2856, -518, 950], [-6933, 1943, -1422, 237], [-669, -233, -1739, 750], [29970, -5648, -1416, -872], [-27724, -932, -1714, 22], [-18318, -1520, 2520, -384], [32248, 970, 69, 337], [4416, 2912, -492, 256], [-12569, -633, 1042, 637], [22808, 2898, -1144, -86], [-7696, 2630, -1479, -895], [20611, -4662, 659, -125], [-3586, -4711, 1111, 742], [17553, 1201, 2721, -596], [-19924, 7162, 947, -109], [3185, 5259, -866, -691], [-24244, 1634, -1588, -238], [4025, 3570, 172, 470], [-14228, -7672, 86, 786], [1469, -6957, 782, 1149], [11948, 1799, -1466, -695], [1311, -5, 1215, -1220], [-6328, 8241, 729, 828], [-23222, 453, 1619, -122], [-42624, -550, -973, -621], [-12192, -3974, -882, -308], [7643, -1076, 381, -821], [21050, 340, 164, 596], [-47904, -184, -573, -371], [-26215, 4425, -1219, 732], [11690, -2513, 1341, 1366], [5920, -6024, 54, -1278], [-19355, -5354, 2778, -164], [26032, 366, 1399, 579], [-22377, 1650, 2068, -394], [-4992, 1098, 45, -707], [348, 597, -1796, -583], [24402, 4624, -1032, -60], [-7052, -1180, 2395, -663], [8766, -4294, 2550, 612], [-9291, 4928, -4432, -264], [22703, -428, 2871, 1345], [-28445, -4955, 2632, 369], [13532, -7146, 3434, 316], [-833, 14133, -623, -396], [-8900, 10993, 2039, -994], [10565, -2488, 1723, -1463], [-3321, 134, -1904, 670], [7028, -84, -199, 1167], [-7363, -3949, 1949, 190], [17352, -4277, -4720, -565], [7968, 4968, 4752, 692], [13075, 4111, -2918, 893], [2764, -7204, 2654, 1734], [-13529, -5412, 5102, 214], [-10210, -3514, -1198, -108], [22288, 2473, 206, 179], [35800, 9524, -323, 755], [20028, 2192, 4530, -618], [25937, -11371, -155, -140], [-25216, 9049, -2463, 196], [-20755, 6763, 1724, -413], [6204, 650, 6624, -194], [-45622, 5326, -526, 1316], [7607, -5668, -1773, -835], [-31532, -8883, 2229, 780], [17911, -7125, -248, 1463], [32592, -11251, -4177, -102], [-33572, -1150, -2105, 1871], [20219, 5838, -2391, -1287], [16957, -14773, -2996, -505], [4112, 2800, -2680, 1132], [-28372, 4063, 2691, -896], [-57408, 12508, 2568, -8], [19835, -4652, -2895, 607], [-16940, 307, 191, 752], [18132, -1828, 1964, 768], [-10143, 2955, -8256, 75], [38684, -4745, 6357, 598], [-18316, 4986, -6610, -1604], [27638, -15803, 415, 42], [2247, -7133, 603, -3180], [30856, -1876, 466, -1746], [-19256, -6144, -1049, -531], [12880, 2990, -5837, 459], [-50664, 2074, 3763, -453], [-132, -122, -4241, -1005], [-1435, -8646, 3127, -1297], [17987, 3461, 6764, 961], [-8664, 4480, 4320, 892], [-11520, -10721, 569, 458], [924, -2986, -1218, 784], [-68028, -6485, -436, 479], [6056, -4982, -1753, 159], [-6178, -12879, -1085, -2734], [-48722, 524, -260, 240], [-12748, 3290, -5764, -1530], [-5569, 4954, -3864, 658], [-39958, 7904, 2864, -1152], [-9312, -4304, 3975, -991], [20878, 14168, -4720, 1272], [-18908, -17170, -1605, 1079], [-2522, -1218, 2266, -52], [14201, -8691, 997, 716], [1588, -2592, 6968, 1576], [-16552, -892, 1376, 664], [26205, -8844, -3727, -1841], [54739, -1426, 2249, 1113], [-21057, -19845, 2832, -869], [-43352, 1305, 2324, -1115], [8838, -13908, -3636, 112], [-857, 1609, 2320, 3573], [22972, 4330, -453, 2779], [-42531, -3501, -2133, 2204], [43619, 4270, -1371, 349], [-25992, 15887, -847, 498], [17601, 7493, -5623, -1464], [12368, -1152, -2562, 1962], [-15222, 14259, -1019, 1514], [-10380, -3294, -1615, -1907], [22584, -8002, -1788, 186], [16093, 4655, 4626, -1843], [-25063, 6484, -572, -2688], [42924, 74, 993, -239], [-34596, 20072, 4305, 399], [-1656, -8240, -7360, 1304], [41948, 8590, 608, -1846], [27101, 8998, -6791, -855], [-19136, 5834, 3237, 4121], [-20548, 7876, 3269, 959], [19755, 29310, -146, -2032], [15619, -3965, 3583, -864], [89004, 3225, -2644, 1333], [-4035, 727, -9108, -909], [-86402, -6150, 5194, -432], [-4404, -20040, -3081, -703], [-23785, 13319, 1874, 737], [-12176, -9394, -3968, 50], [116698, -5255, -1477, -94], [14193, -709, -1473, 2516], [9648, -6784, 4900, 916], [20421, -13695, 471, -2150], [2044, 2750, -3422, -604], [-54576, 411, 4742, 1693], [62307, 15268, -6098, 846], [-7697, -6001, 7915, -764], [-52728, -12878, 979, 2979], [-50456, 6066, -6620, 230], [76356, -3807, 2998, 1691], [-74103, 2230, 4550, -568], [-35660, -1704, -4463, 695], [-19281, 8553, 12046, 1763], [-48048, -15242, -738, -2700], [-14985, -7515, 2482, 1235], [19940, 4402, -2869, 1711], [18670, 16988, 460, -2700], [-23323, -7931, -2410, 2543], [13592, -16349, -9660, -833], [38316, -21372, 1929, 2275], [-28977, -25358, 8404, -1458], [63016, -8062, -3221, -2737], [-64820, 3184, -7187, 2367], [-47154, 10169, -4561, -210], [73113, 939, 102, 49], [-14368, -7905, -1770, -1311], [24642, -781, -4015, -882], [9721, -3921, 5761, 3490], [44192, 6737, -2072, -503], [72294, 12404, -792, 728], [-26717, 29086, -3826, -112], [88848, 1461, 2576, -3563], [23028, -19302, 1643, 715], [-27420, -18524, 8397, -2557], [-42567, 39189, 2685, -884], [17809, 22611, 7782, -2211], [36681, 9969, -1527, -3996], [-50020, 21431, 3564, 179], [34336, 18810, 133, -351], [-32436, 4121, -5854, 1647], [-35576, -476, -6305, -5211], [-65943, 10294, 1757, -547], [52774, 5804, 3940, -684], [33841, 18285, -3879, 1152], [29640, -9427, 4939, -2810], [-18862, 2732, 1504, 964], [92369, -16519, 11306, 5099], [20931, -13389, 2961, -5682], [-96344, -8655, -6568, 3457], [-13966, 31468, 1388, -2616], [-77660, -2996, 787, 1053], [56899, -40556, -1861, 701], [-25928, 3232, 13764, 1564], [-1968, 3584, 3129, -653], [40842, -20690, -4614, 504], [-47252, 12195, 11070, 885], [29426, -23504, 1276, 4500], [86003, -2167, -7381, -310], [-41132, -1575, -10054, 1111], [101675, 7477, 168, 3373], [97081, -3903, -6086, 791], [68024, -13590, 4055, -3769], [16100, -13616, -1492, -2292], [-1423, -9531, -5368, -3503], [-16444, -3038, 2285, 3509], [54509, 8879, -4184, -2177], [31749, 13801, -2562, 2423], [81948, 9422, 1512, 2742], [50176, -28534, 2848, -366], [-81272, 20897, 9401, 2556], [-32222, -16331, -5101, -4234], [3258, -2706, -8814, 3196], [-30168, 13571, 10571, -1044], [-68749, 22683, -1845, 540], [42896, -18220, -5470, -4414], [-48316, 8851, 16776, -653], [-21596, -5464, 2065, 3871], [47037, -10117, 7689, 242], [-33680, 6866, 12263, 87], [76051, 8865, 3908, -6323], [-112136, 20766, -3323, -2635], [-44800, -8830, 4355, -721], [18642, -34077, -6775, -98], [29801, -1533, 5816, -4857], [-22857, -33030, 2182, 2636], [9098, 16766, 7274, 324], [-99321, 17205, 6090, 4087], [42380, -21298, -5249, -581], [-13418, 5408, -2912, 4180], [-28140, -17925, 7643, -2348], [756, 4890, -2835, 3389], [-34132, -23230, -863, -1475], [-2662, 663, 20277, 318], [-113956, 16901, -1925, 2206], [133500, -18290, -7134, -1356], [-10099, 18113, -7547, 6280], [-26149, -16145, 6827, -440], [135776, -5650, -1117, 243], [36264, 19730, -7289, -4241], [-21068, 43008, -3188, -4656], [-102694, -33025, 57, 266], [-60832, -4030, 1183, -665], [112262, -18200, 10136, 3596], [-4868, -32552, -628, 3596], [-99837, 13253, -11043, -2456], [68738, -26261, 12085, 2298], [90826, -26204, 11656, 2488], [4892, -22349, -6671, 2670], [31611, 31349, 120, -1051], [-62545, -32107, 10811, -2162], [-15520, 24335, 3234, 797], [51322, -23915, 9915, -410], [43271, 13203, 896, 2507], [-53852, 15391, 7704, -1745], [21692, -15964, -8680, -5344], [-12093, 40380, -7532, -2560], [3209, -45993, 3455, 1256], [-29380, 30016, 5381, 1495], [-37652, -18588, -7420, -3200], [65367, -23594, -6620, 3258], [173305, -149, 733, 966], [-104668, -8924, -4522, -3102], [-1892, -6573, -8176, 4363], [125786, 6190, 3650, -2168], [-55932, -39460, 1608, 3508], [-4467, 14609, -13827, 816], [73857, 182, 4475, -2025], [95820, -27402, -4659, -4375], [-11100, 21786, 9417, -495], [-46410, 11043, -3103, 7294], [18751, 17231, -12407, 4190], [-138436, 15806, 3476, 558], [-195221, 12163, -1376, -2073], [27028, -6431, 7194, -1169], [-63736, 21298, 7766, 5848]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1521_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1521_4_a_bb();".
// 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_1521_4_a_bb(:prec:=4)
    chi := MakeCharacter_1521_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_1521_4_a_bb();".
// 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_1521_4_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1521_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![78, 24, -25, -2, 1]>,<5,R![6084, -156, -203, 6, 1]>,<7,R![206212, 12652, -1123, -14, 1]>],Snew);
    return Vf;
end function;