
// Make newform 784.4.a.bb in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_784_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_784_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_784_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 := [13, -10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-29, 2, 4]];
    Rf_basisdens := [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_784_a();"
function MakeCharacter_784_a()
    N := 784;
    order := 1;
    char_gens := [687, 197, 689];
    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_784_a_Hecke(Kf)
    return MakeCharacter_784_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, 0, 0], [-2, 1, 0], [1, -1, 1], [0, 0, 0], [0, 0, -3], [8, 1, -3], [15, 13, 1], [-28, 2, 3], [64, -7, -2], [60, -7, -3], [-122, -26, -1], [-187, -14, -12], [-8, 23, 11], [-108, -56, 0], [-86, -50, -3], [273, 28, 34], [-590, 29, 0], [-185, 66, 4], [174, -7, 34], [-220, -14, -6], [193, 98, 38], [-44, -7, -46], [-800, 2, -30], [-315, -72, -52], [20, -263, -19], [-223, 23, -19], [-684, 65, -20], [-448, 126, 97], [23, 203, -63], [28, -273, 11], [-188, 126, -42], [-270, -227, 94], [325, 119, 23], [-1216, 54, -26], [-489, 441, 127], [1502, 322, -43], [-953, -278, 88], [-494, -343, -112], [754, 353, 129], [-989, -140, -82], [84, 28, -3], [-798, 340, -36], [-1442, -518, 99], [-1947, 441, 93], [-1700, 413, 129], [2526, 228, 161], [-1608, 434, 98], [556, 2, -294], [-1800, -70, 57], [1773, 21, -233], [561, -147, -139], [1506, 77, 269], [961, -132, 52], [-838, 303, 239], [-17, -615, 197], [-2140, -147, 280], [-961, 554, 224], [-608, 157, 252], [-2743, -224, 118], [1980, -77, -241], [-4896, -316, -177], [2002, 528, -160], [-5836, 320, 72], [24, 97, -106], [7617, 38, -70], [-2699, -420, -166], [4202, 987, -58], [2664, 749, -39], [-8050, 147, 16], [8788, 431, -53], [2827, 207, -469], [-114, 224, 445], [1184, 515, -44], [1489, 252, -170], [-5510, -1309, 3], [-2962, 1776, 271], [-1345, -7, -189], [5417, 53, -77], [-3959, 1351, 115], [1163, 549, 973], [2676, -1200, -472], [1464, -1197, 583], [-5658, 112, 215], [8588, -83, -127], [5106, -860, -481], [4492, -308, -49], [3304, 245, 481], [9367, -518, 350], [-5940, -213, -585], [4384, -1232, 224], [-2362, -1145, 312], [10644, 1197, 94], [8252, 2289, -276], [1242, 2443, 11], [-2182, 441, 936], [7908, 1154, 74], [-15795, -245, -319], [-2787, -2896, -332], [-8712, 526, 331], [9619, -1099, -65], [-4594, 161, 289], [3015, -2541, -311], [-3270, -1737, -410], [-2673, -70, -458], [10208, -308, 1249], [-3519, -960, -672], [-3564, -916, -1324], [-12045, 967, 731], [-312, 2247, -766], [556, -1207, 605], [-2378, -2044, 1027], [3755, 1855, -311], [-504, -1071, -531], [-1914, 1095, 1194], [-8140, 2898, 314], [1415, -420, 1004], [-9644, -3576, 528], [-5264, 1937, 270], [-5883, 168, 350], [-8160, -882, -722], [11083, -2662, 100], [-376, 525, 1193], [-8155, -1591, -325], [-356, -1526, -1025], [-8862, 537, -1774], [-514, 2940, 860], [-5835, -1694, 1332], [2960, -2731, -844], [-15100, -750, -1446], [11011, -192, 34], [11936, 546, 1059], [17468, 2590, 70], [-3282, -490, 1367], [-52, -4907, 457], [1851, -547, -2003], [7520, -1057, -653], [18521, 1379, 505], [-11362, 5, 12], [2412, -2149, 1879], [3983, 1974, 82], [-8668, -3588, -620], [-5037, 2919, -627], [-5960, 1015, 290], [15788, -4564, -1084], [6793, -5247, -1437], [-1464, -240, 96], [14992, -431, 717], [-5159, 3890, -738], [15796, 3236, 97], [-4036, 2345, 2058], [-1517, -2471, 27], [-4338, 3180, -748], [16448, -1498, -1034], [-11682, 790, -1399], [-4658, -4977, -1884], [5952, -4368, 32], [21502, -5012, -1215], [-41307, -2974, -30], [13262, -2644, -1828], [-12653, -1532, -1958], [-8370, -1729, -954], [-5516, -2905, 1171], [-804, -3794, 86], [-27722, -715, 970], [-16531, -455, -2475], [-9862, 1578, 1687], [-17052, 1519, -1762], [-1069, 5074, 1316], [28692, 2387, -449], [25203, 1246, -1004], [9238, -3017, 1044], [-168, -1799, -1435], [24536, -2919, 406], [24027, -6188, -2688], [27958, -1198, -1965], [7072, -1597, 3031], [8230, 2625, -1887], [-30831, -392, 374], [11796, 7882, -1758], [-32307, -3721, 885], [-1172, 5537, 482], [3240, 4310, 390], [-33122, 84, -3252], [13309, 4288, 3420], [-32240, -4963, 1212], [-29893, -4518, -236], [-6353, 91, 2265], [33156, 1604, 2955], [-127, 1253, -1459], [-19670, -8196, -835], [6529, 1280, -2432], [23160, 4718, 1678], [-19276, 4914, -799], [-26095, 37, -789], [740, -2912, 1433], [16407, 4599, -1161], [-1883, 7413, -495], [9183, 4851, 3533], [16096, -10801, -2173], [-36844, -2255, -548], [-35341, -2807, -97], [7276, -6318, 1370], [29319, -1544, -2130], [-37345, -3527, 341], [1288, -1326, -4558], [-18081, 230, 1780], [34956, 3283, 898], [-59496, -2324, -421], [15506, 10500, 756], [3218, 5697, 3980], [-32699, 1477, -4367], [14932, -1261, -657], [-20528, 5908, -2748], [682, -5369, -164], [-30470, 3974, -1621], [26907, 761, 817], [-3490, -3388, -2917], [-16361, -1487, -475], [21282, -2198, 2423], [6934, -2912, 1520], [719, 105, -2681], [5018, -10035, 1325], [-10013, -3766, -4582], [54590, -3962, -1353], [-39192, -6066, -1442], [-18776, -6293, -3441], [17251, 12929, -2607], [-14248, 11389, 1588], [-1650, -4014, -3587], [3690, 3171, 222], [49185, -7602, -920], [36814, -3091, -1036], [-18312, 2772, 3236], [43677, 1323, -3365], [35452, -1344, 3720], [-37788, -12631, -62], [-70301, -5169, 1539], [-18357, -10157, 1145], [-59668, -3444, -3324], [-67618, -161, 1503], [44238, 13405, -1746], [-3296, 3982, -909], [-10324, -10245, -3024], [-48727, -17150, 1096], [30822, -7596, -636], [26040, 4867, 318], [-34964, -8526, 2442], [-12288, -12714, -2107], [-25580, 3262, -317], [48022, 5999, 3055], [48752, -6405, -1809], [-7431, -8868, -3428], [-21558, -3416, -2501], [-33324, -1803, -1143], [20747, -7088, -2938], [30000, -11564, -2869], [42333, 10906, 880], [-15952, 5380, -961], [-32392, 11525, 3665], [18907, -5587, -579], [-2320, 6153, 896], [-22044, 10836, -84], [19317, -7663, -2297], [-20396, 2183, -4333], [-43481, 4621, 4489], [45920, -3960, -1047], [40048, -3213, -4473], [-7992, -9465, 5915], [103996, -1092, -892], [-14729, 12509, 471], [-61227, 1371, 1337], [-3224, 1330, -1269], [16691, 13265, 2601], [-25590, 7084, 2765], [-58652, -2983, 813], [-25748, 8289, 4228], [-47318, 9247, -3166], [9881, -10122, -3160], [82287, 5110, 1978], [-17756, 8770, -29], [19298, 17784, -4487], [34310, 6034, -515], [43152, -7532, -844], [-28044, -14093, -2017], [15824, 682, 4967], [-20110, -11900, -3], [33247, 532, 604], [-57012, -6307, -5695], [15212, 9991, -2700], [4596, -1911, -6339], [-20069, 9205, -5], [-2068, -12572, 1795], [-9165, 3388, -7208], [-33322, 4333, 5581], [400, 11179, 2799], [-61719, -2215, -309], [12482, -19306, -2227], [1976, 13549, 3385], [-23010, 6581, -8366], [55450, -2701, 947], [67305, 1478, 5570], [15587, 24017, 2291], [-6034, -3500, 3579], [39672, -6174, -4014], [90356, 7056, -173], [12832, -8855, 1797], [96858, -791, 1862], [-35876, 5091, 1999], [12258, 19866, 5063], [-1841, 1337, 887], [119868, -6001, -234], [91509, -8050, -972], [-56695, 6027, -817], [-107886, 8295, 392], [-41320, 19992, 5240], [22543, -45, 787], [6192, 2610, 3106], [-56610, 18928, 4447], [73224, -9101, 2119], [21292, 16975, 1819], [-85016, 9862, -1299], [4009, -11459, -963], [26356, 25775, 1131], [38450, 1533, 6909], [-6693, 5908, -6560], [-23419, 6502, 286], [101738, 973, 644], [-8690, -3067, 7474], [136976, 7343, 1448], [-120024, 539, 1231], [120045, -476, -4246], [-132333, 2821, -5869], [19188, 3942, 3742], [15938, -6889, 5022], [-71240, -1988, -967], [-69404, -420, -10172], [73408, 14819, 2167], [27167, 9753, 213], [74526, 1604, -3436], [-26648, -9991, -7256], [21443, 15799, -903], [3660, 2387, 3679], [82008, -7251, -663], [48372, -3486, 9082], [-81719, -3626, -4236], [-14928, -12978, -4146], [26947, -12198, -5876], [98636, 7056, -3189], [10578, 25061, 4421], [142719, -1932, -374], [9742, -10985, -1968], [-4107, 5607, 1207], [43788, 4193, -2891], [36012, 749, -3098], [11617, 12348, -1210], [33894, 8164, -1684], [109884, 2923, -3814], [-132572, -15730, 1961], [107481, -1001, -1453], [-92336, -2548, -4404], [87996, -3003, -5959], [-11193, 2207, -2825], [-55230, 17682, -2175], [56438, -5103, 4300], [-96182, -9965, 4714], [-114755, 2779, 3315], [-18688, -31435, 1793], [86066, 2436, 6247], [22602, -21308, -9252], [10674, 26551, 9432], [-23404, -11856, 5781], [-12178, -30226, -2977], [-96850, -5516, 3628], [54794, -5966, 6271], [11285, -10556, 306], [-67516, -14296, -681], [94480, -3472, -4992], [-31941, 24775, -1341], [29437, 8210, -4886], [-27844, 20593, -7483], [-81603, 3315, -1915], [21912, 12033, 4205], [-2584, 11144, 4840], [90387, -1134, 1602], [-52212, -5276, -3764], [171454, 20108, -1383], [-18496, -23611, 3684], [-23365, 15050, -9276], [-118202, 6153, -8220], [103632, -17232, 2848], [-21926, 19348, -1404], [-63915, 3257, 6651], [111342, -3801, -2676], [-36314, 5719, -12056], [23194, 7014, -3245], [-30905, -17682, 6274], [-22780, 21517, 12142], [-119184, 8723, -1113], [-12548, -10612, -12700], [65715, 5663, 5281], [19931, -9308, 4278], [-26967, 1491, 8615], [-138854, 7112, 2625], [-10275, 25900, -3088], [16021, -11223, 14223], [-108056, 2183, -8758], [-32403, 11620, 1438], [-32648, -30723, 3993], [49048, 6526, 9349], [58242, -21587, 4574], [-125131, 606, -8906], [64041, -18760, 946], [30428, -14588, 11260], [-29584, -5880, -6057], [-19400, 16569, 15029], [14007, -11018, 6272], [-115542, -30436, 3453], [-11674, -24104, -7115], [-59376, -16505, -4501], [93558, 6642, 9253], [-112423, -26586, -5768], [-42885, 30998, -4348], [-72496, 2464, -1920], [-63464, -29534, -3902], [46232, 25823, -5821], [-57549, 1892, -9158], [-24684, -19166, -1487], [-140508, 1407, -5685], [-104730, 14203, 4294], [131098, 3346, 12143]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_784_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_784_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_784_4_a_bb(:prec:=3)
    chi := MakeCharacter_784_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_784_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_784_4_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_784_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-7, -25, 7, 1]>,<5,R![2063, -333, -3, 1]>],Snew);
    return Vf;
end function;