
// Make newform 2070.4.a.bh in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2070_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_2070_4_a_bh();".
// 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_2070_4_a_bh();".
// 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 := [1508, 1520, -273, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [59, 395, -15, -2], [-3084, 569, 1, -3], [-3178, 945, 1, -3]];
    Rf_basisdens := [1, 47, 94, 94];
    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_2070_a();"
function MakeCharacter_2070_a()
    N := 2070;
    order := 1;
    char_gens := [461, 1657, 1891];
    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_2070_a_Hecke(Kf)
    return MakeCharacter_2070_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], [0, 0, 0, 0], [-5, 0, 0, 0], [6, -1, 0, 0], [-12, 0, 0, -1], [13, 0, 1, 0], [-16, -1, 0, 1], [18, 2, -2, -1], [-23, 0, 0, 0], [-18, -1, 2, 5], [31, 3, -1, 3], [38, 11, 2, -6], [-41, -9, 1, 0], [39, 6, -3, 3], [-24, 2, -8, 5], [-35, 17, -13, -2], [-31, 3, 9, -10], [43, 18, 11, 4], [62, 17, -4, 8], [-42, -13, 20, -3], [-4, -4, -6, -21], [-53, -36, 17, -5], [-42, 29, 20, -1], [36, -14, -14, 12], [13, 10, -23, -7], [-12, -3, 0, 5], [-67, -58, 31, -1], [122, 31, -12, 13], [-125, 28, -25, 6], [-156, -11, -24, -27], [-149, -64, 5, 34], [26, 32, -42, -22], [195, -86, 31, -1], [-423, -33, -23, 31], [210, -140, 20, 13], [-482, 70, -34, -42], [-226, 23, 58, -36], [-90, 110, 18, 14], [532, 6, -12, 15], [-138, 82, 44, -36], [554, 134, -46, -26], [-679, -18, 9, 53], [118, 70, 50, 47], [-376, -110, -18, -12], [952, 164, -2, -28], [-1301, -66, -51, 61], [-1323, -47, 65, -57], [-465, 122, -7, 63], [1463, -72, 29, 99], [-2231, 2, -71, -55], [-572, -114, -30, 78], [566, -39, 16, 19], [-1078, 140, -20, 87], [-676, -18, 96, -24], [1174, -96, 40, -145], [-1019, 125, -127, -90], [1158, 149, -42, -95], [-1799, 123, 29, -35], [-2253, -16, 31, -99], [-1584, -74, 18, -21], [-1006, -83, -48, -90], [-1163, 89, -21, 106], [-3728, -10, -84, 109], [-2033, 212, -191, -97], [284, -103, -48, 136], [2790, -40, -4, 107], [-2625, -37, -117, -63], [-2445, 408, -1, 37], [3172, 120, 88, -18], [-5573, -107, -43, 7], [-1788, -52, 34, 77], [-706, -34, 114, 69], [-6800, -141, 214, -52], [1597, -110, 105, -137], [-5598, -68, 22, 118], [-2913, 47, -21, 40], [-1388, -304, 62, 128], [-4373, -218, -69, 221], [-7120, 136, 2, 100], [-5743, 327, -113, 77], [-3726, -8, -6, -81], [241, -272, 129, 160], [-6266, 4, 186, -4], [4062, -231, 110, -76], [-5844, 274, 96, 58], [-1988, -98, -176, -1], [-4041, -49, 169, 150], [-5572, 257, -208, 44], [-9225, -76, -73, 263], [2441, -22, 139, 116], [4110, 231, 96, -135], [-5770, 490, -110, 59], [-9017, 132, -23, -226], [-9079, -165, -167, -138], [-6517, -383, 163, 165], [-683, -193, 149, -262], [-7663, -426, 137, -51], [-14054, 162, -152, -89], [3819, -76, 37, -381], [8536, -18, -6, -80], [-11760, -8, 4, 264], [-1649, -255, -423, -36], [-114, -279, 308, -117], [-11596, 268, 14, -264], [7956, -40, -416, -49], [-1458, 442, -24, -456], [2234, 902, -250, -258], [2254, 60, -304, 29], [-11281, 524, -151, 37], [11745, -609, -57, -93], [-8863, 172, -129, -170], [13439, -8, 27, -3], [-7942, -167, -86, -89], [-1284, 172, 36, -224], [13497, -508, 255, 248], [-12020, 42, -178, -255], [1360, 597, 18, 416], [3408, -344, -196, 371], [1436, 110, 378, 121], [-13968, -68, -28, 367], [14965, 344, -87, 169], [9774, 82, 12, 9], [-6723, 399, 223, 112], [17558, 322, -370, 39], [12892, 198, 340, 468], [-7558, 348, 164, 227], [8127, 102, 487, -108], [-5000, -357, 570, -137], [-5818, -295, 596, 154], [8932, -657, 180, 106], [7849, 67, -191, -417], [16432, -28, -336, 272], [17607, -90, -115, -100], [7152, -533, -224, 480], [-7839, 177, 403, -220], [11260, 882, -210, -135], [13184, -1200, 26, -304], [-2120, -1127, 194, 184], [-16311, 107, -5, 120], [-1055, 729, -325, -608], [9623, -695, 391, -623], [5983, -462, -205, 115], [-8943, -212, 35, -503], [9298, 853, 104, -51], [13859, 429, -211, -545], [-102, 398, -142, -362], [6841, 428, 89, -799], [-6470, 112, -304, 1144], [-4205, 325, -165, 165], [30926, -686, 198, 140], [9123, 12, -353, 951], [2790, -720, 552, 313], [-7258, -348, -30, 149], [5696, -774, 12, -802], [-7992, 789, -438, -562], [18608, -1268, 280, -28], [-3327, -1552, -197, 153], [-1221, -1785, -131, 236], [13769, 190, 213, -287], [7710, 144, 32, 403], [10338, -1440, 594, -80], [10551, 984, 23, -839], [-2253, 660, -99, 314], [18324, 128, 196, 534], [-9056, 1965, -180, -49], [22301, 861, 393, 134], [2163, -571, 351, 749], [-14931, -902, 73, -607], [3516, 886, 426, -546], [-6740, -748, -738, 113], [8118, -1124, 58, -198], [-27469, -229, -471, -183], [10532, 562, -816, 364], [5526, 1405, -186, 50], [-25652, -968, 268, 104], [4190, 1484, -200, 365], [-16460, 750, -532, 78], [5256, -1449, -552, -543], [11060, 1115, -22, 782], [-3505, 556, -1085, -528], [-14963, -1594, -689, 542], [-5228, 138, -516, -713], [299, 544, -33, -709], [4954, -826, 600, 393], [16531, 685, -757, -52], [-5322, 690, 1028, -131], [-7595, 512, 729, 196], [-4668, -797, 770, 566], [-4809, 181, -779, 459], [-7106, -753, 996, 85], [37642, -1908, 340, -447], [3692, 1442, -76, 620], [-1190, -838, -122, 697], [4858, 2519, -970, -947], [17671, -570, 57, 1047], [-19088, 527, 344, 1107], [-15720, -2332, -202, -7], [32403, 2330, -229, -785], [-23571, 328, -295, -449], [30128, -1330, -340, 332], [-13524, 228, 186, 1183], [5510, 1706, 518, 790], [-40215, -1060, 109, 626], [16268, 1316, 98, 179], [-12164, 926, -1364, -515], [-22092, -2092, 1354, -336], [8665, 72, -625, -822], [8984, 2184, 936, -553], [-48747, -241, 443, -578], [22816, -1538, -136, -716], [-3332, 224, 742, 72], [-18957, -1388, 1035, 363], [40035, -990, 153, 425], [-16107, -1250, 299, 1621], [9230, -2485, 60, -223], [-15832, 462, -94, -2083], [-15747, -406, 1587, -525], [-18517, 1675, -1155, -1388], [9003, 1345, -781, 20], [-1724, -2298, 778, -617], [-17201, 157, -303, 279], [-6477, -3282, -547, 357], [-22569, -1101, -679, -464], [43744, 2847, 302, -550], [-54352, 1112, -496, -221], [42635, -1115, 85, -49], [-32965, -772, -773, -481], [4148, -2495, -1262, 505], [2653, -1780, -173, -1291], [-23019, 2595, 333, 198], [-9563, 2256, -1015, -952], [24940, 1370, -1220, 1187], [-6625, -2038, 1713, -1059], [13473, 1887, 735, 772], [31926, -799, 564, 858], [-53430, -1442, 146, 106], [38514, 794, -296, -999], [25526, -396, 828, -712], [-1337, 2199, 1323, 214], [26796, 1493, -222, -575], [12042, -1875, 1384, 1245], [18487, -2693, 1915, 431], [-1297, -3006, -919, 53], [1054, -3602, 644, -226], [-6000, 1954, -2058, -406], [6087, 204, 857, -939], [53523, -1000, 477, 518], [-9834, -220, 598, -341], [43486, 1162, -114, 108], [68887, 25, 399, -474], [-65625, -1274, 1399, -157], [55668, 912, 750, -698], [-1055, 1223, 681, -2022], [25658, 720, -272, -238], [-28028, 4282, -1646, -477], [6335, -545, 75, 712], [-51451, 702, 137, -358], [39055, -896, -151, 1527], [-12036, -1870, -1110, -385], [10350, -804, 524, -552], [5282, -3001, -1620, -486], [-28460, -2003, -314, 99], [-55913, -1705, 717, 1035], [-22922, -1781, 1386, 478], [29536, -2082, -338, 784], [15126, -1744, -154, 1269], [5832, -2220, 22, 1717], [29356, -3320, 718, -1978], [-34868, 9, 350, -1132], [56748, -1250, 390, 490], [-75099, 2301, -581, 935], [1236, -435, -730, 2284], [30544, 2971, 1512, 488], [-36215, 2994, 375, -807], [-47962, 2978, -1748, -1757], [-713, -478, 485, -1256], [-11546, 670, 190, 1645], [-14611, -935, 259, -665], [4034, -3398, 1432, 2093], [-39736, -1114, 1656, -57], [21884, 530, -784, -784], [-44539, -1456, 139, -78], [-42826, 12, -1070, -2724], [-77433, 858, -485, -687], [1678, 54, 622, 653], [61268, 621, 1210, -933], [-40606, -4979, -518, 1226], [3254, -536, -460, 240], [-6944, -550, 1996, -838], [-26202, -1176, 1768, -1402], [-46394, -3752, -1012, 1758], [-262, 1071, -2116, -163], [-8258, -3274, 1624, 570], [-81802, -1566, -310, 465], [17239, -4318, 1227, -608], [-8288, 30, 102, 2782], [-24371, 946, -393, -1728], [-40798, 1330, -316, 907], [-72521, 2781, -161, -296], [19848, -4426, -208, -140], [17558, 1103, -334, -1826], [13061, 3819, 247, -594], [-50221, 4408, -1591, 1001], [23914, 2878, 66, -1497], [38072, -2096, 1280, 1296], [-5670, -1974, -2536, 893], [-85950, -2476, 366, 1525], [11007, -1544, -1473, 2781], [-36350, -2034, 1750, -1543], [2265, -6234, 593, 938], [7800, 2280, -368, -1152], [-28398, 6482, -1968, 53], [-37168, -1160, 1854, -549], [-47658, -660, 1790, 150], [33723, -1245, 399, 746], [-23674, -1714, -804, -2473], [-63665, 1867, -1085, 374], [14948, -1715, -1470, 1165], [56026, 1441, -1126, -816], [61220, 2634, 950, -3128], [85994, -160, -1358, -1053], [-2640, 3761, 44, 992], [-5711, 2004, -2539, 799], [-19835, 3214, 1683, 749], [-16018, -4203, 2294, 1175], [30568, 5786, -3614, -813], [83682, 1964, -838, 1311], [74676, -618, 1144, 2041], [-41096, -6356, -600, 1960], [71147, 1305, -3771, 1596], [-20779, 5857, -661, 2097], [-2944, -894, 1422, -731], [-657, 3005, 923, -261], [1238, -2672, 330, 225], [57396, 1876, -276, -1504], [-25968, 5068, 708, 1832], [43347, -1972, 1427, 775], [103581, -228, -1287, -359], [70960, 62, -3042, 996], [-30458, -1759, 3756, 1282], [-21541, -2684, 1727, -2029], [10345, 3568, 701, -181], [46055, -2252, 655, -689], [-36787, 1272, -1629, 4048], [-33137, -5465, -2675, -336], [14989, 2143, 1469, 576], [33991, 765, -1111, -1985], [96814, -2418, -1962, -673], [12710, 6366, -2818, -610], [16129, -263, -1385, 552], [47711, -5027, 1279, 1503], [-26360, 590, -2246, -1573], [29772, 45, 624, 1171], [-38430, -2413, -3892, -1444], [-32677, 162, -1437, 2852], [-51388, -3288, 2334, 30], [100020, 4812, 1680, -725], [6230, -1402, 1342, -690], [82402, -190, -2192, 1037], [143446, -354, 78, -1116], [-35098, -6545, 1626, 3644], [-16735, 5063, 2127, 1586], [79148, -5178, 624, -1650], [51388, 5984, 148, -42], [59320, 4170, -456, -1442], [51620, -2484, -3082, 600], [-131614, 1684, -3048, -2831], [-113666, -3471, -308, -1242], [-50572, 2970, 2906, 1038], [-150405, 3413, -853, 1732], [5143, 1079, -877, -115], [57628, 8878, -2200, -1556], [58056, -3002, -2394, 708], [20611, 656, -1551, -2477], [44143, -4984, 2607, 796], [-27527, -2269, -2647, -472], [-18986, 6594, -714, -2060], [79706, 321, -1046, 4892], [45170, -2562, -1100, 4022], [28652, 2396, 1406, -1588], [-110572, 2148, -1010, -2924], [-1243, 732, 2289, 2509], [-49051, 1396, -1417, -2647], [-16808, -4890, -2862, -1573], [67434, -1960, -586, 1620], [-8820, -2318, 592, 1240], [109581, 5157, -1371, -1215], [-14395, -2790, 1149, 156], [43560, -3085, 2158, 2748], [-1127, 1889, 2589, 384], [-53058, 356, 952, -153], [-14746, 764, 1536, -4630], [27259, 4503, -2001, -2126], [38240, -6372, 2744, -1253], [30242, 420, -846, -2911], [-41910, -2543, 3258, -4928], [-33861, -7182, -731, -751], [-113524, -7782, 1666, 2928], [221452, -2092, 100, -624], [-120830, 427, 822, -681], [-8021, -2483, 709, 5], [-106424, -2744, -742, -266], [52316, 2465, 2350, -970], [44328, -155, -836, -1425], [-90896, -807, 4484, -2313], [-2523, 481, -3435, -491], [-62150, 341, 634, -524], [20860, 1420, -78, 636], [90703, -9958, 1061, -1197], [21668, -8804, 4428, 1696], [56784, -2386, 122, 2979], [17126, -2938, 1152, 6337], [75493, 6616, -4185, 1117], [93486, 1364, 474, -1924], [-82538, 3595, -1654, -2804], [57133, -2200, -375, 947], [-1859, -2244, -2309, 5855], [-32239, 6268, 855, 1758], [27980, -10261, 2596, 1403], [86488, -3628, -3080, 638], [-51642, 6694, -3292, -3083], [-53235, 6782, -4231, -3219], [-34308, 3352, -1912, -5231], [-36834, -4864, -3854, -1218], [-30964, -7402, -946, 2571], [-51082, 3530, -2556, -4600], [77779, 1364, -519, -4915], [172067, 2077, 1857, -1100], [170330, 2038, 918, -256], [7860, -2483, 970, -1177]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2070_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2070_4_a_bh();".
// 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_2070_4_a_bh(:prec:=4)
    chi := MakeCharacter_2070_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_2070_4_a_bh();".
// 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_2070_4_a_bh( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-42320, 10580, -415, -26, 1]>,<11,R![421376, -50368, -1186, 48, 1]>,<17,R![-982972, -95440, -957, 62, 1]>],Snew);
    return Vf;
end function;