
// Make newform 784.4.a.bf in Magma, downloaded from the LMFDB on 25 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_bf();".
// 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_bf();".
// 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 := [194, 36, -35, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-101, 200, 6, -4], [182, -12, -11, 1], [-392, -265, 12, 11]];
    Rf_basisdens := [1, 57, 19, 57];
    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, 0], [0, 0, -1, 0], [0, 0, 0, 1], [0, 0, 0, 0], [-25, 3, 0, 0], [0, 0, 6, -1], [0, 0, -1, -9], [0, 0, 11, -4], [-88, -4, 0, 0], [65, -7, 0, 0], [0, 0, 38, 4], [53, -3, 0, 0], [0, 0, -31, -3], [-135, -35, 0, 0], [0, 0, 26, 32], [4, 18, 0, 0], [0, 0, -49, -20], [0, 0, 68, 27], [486, 38, 0, 0], [-562, 14, 0, 0], [0, 0, -37, 25], [262, 94, 0, 0], [0, 0, -1, -8], [0, 0, -157, 75], [0, 0, -189, -91], [0, 0, 8, 7], [0, 0, -14, 132], [-942, 10, 0, 0], [-129, -185, 0, 0], [-579, 119, 0, 0], [-394, -70, 0, 0], [0, 0, -111, 56], [438, -10, 0, 0], [0, 0, -305, -284], [-654, 256, 0, 0], [-1530, -102, 0, 0], [0, 0, -350, -183], [-543, 157, 0, 0], [0, 0, 362, 152], [0, 0, 358, 233], [-1138, 206, 0, 0], [0, 0, 498, -83], [-1782, -102, 0, 0], [-1557, 277, 0, 0], [716, -546, 0, 0], [0, 0, 118, -28], [1006, -42, 0, 0], [0, 0, -152, 156], [0, 0, 129, 340], [0, 0, -50, -315], [-1228, -332, 0, 0], [-1136, -532, 0, 0], [0, 0, -75, 99], [0, 0, -521, 144], [0, 0, 593, -183], [-2538, 206, 0, 0], [0, 0, 334, 543], [0, 0, -456, -380], [-3118, -220, 0, 0], [5560, 168, 0, 0], [0, 0, -633, 96], [0, 0, -532, -385], [0, 0, 673, -496], [0, 0, 232, -544], [0, 0, -655, -395], [-3356, -66, 0, 0], [3853, 129, 0, 0], [1269, -371, 0, 0], [101, 17, 0, 0], [0, 0, -214, 689], [0, 0, -77, 237], [-6906, 682, 0, 0], [0, 0, -1860, 332], [6962, 256, 0, 0], [7831, -245, 0, 0], [0, 0, -1138, -880], [725, -563, 0, 0], [0, 0, -42, 743], [6899, 571, 0, 0], [0, 0, 615, -79], [0, 0, -775, -712], [-2406, 476, 0, 0], [-13304, -228, 0, 0], [0, 0, 515, 543], [0, 0, 572, 284], [-4722, 990, 0, 0], [3558, -1288, 0, 0], [-5757, 1173, 0, 0], [0, 0, -1538, 289], [-3068, -1540, 0, 0], [0, 0, -393, -268], [0, 0, -822, -44], [-3364, -872, 0, 0], [-58, -1554, 0, 0], [-4162, -802, 0, 0], [0, 0, 1380, -132], [0, 0, -1082, -577], [0, 0, 739, 1361], [0, 0, 1065, 1036], [438, -2516, 0, 0], [13487, 1155, 0, 0], [-14080, -486, 0, 0], [0, 0, 2039, 556], [-18959, -87, 0, 0], [1067, 1823, 0, 0], [0, 0, 941, -1405], [0, 0, -77, -1204], [0, 0, 651, 407], [-11428, -1740, 0, 0], [0, 0, -1555, -827], [0, 0, 1460, 416], [6913, -1879, 0, 0], [-19801, -945, 0, 0], [0, 0, -2475, -1872], [-11622, 938, 0, 0], [-12911, 809, 0, 0], [0, 0, -353, -1452], [0, 0, 3430, 1156], [-1361, 711, 0, 0], [-12637, 791, 0, 0], [0, 0, -2788, 361], [9522, -14, 0, 0], [0, 0, 1054, 61], [2894, -1138, 0, 0], [0, 0, -959, 2176], [-15377, 1687, 0, 0], [-3755, 1565, 0, 0], [0, 0, -3254, 1176], [0, 0, 2474, 2544], [0, 0, 380, 1893], [-9139, -2279, 0, 0], [-13106, 882, 0, 0], [-12800, 1396, 0, 0], [-17743, 1561, 0, 0], [0, 0, -4101, -845], [0, 0, 3585, 1779], [0, 0, 2992, 1969], [0, 0, 335, -1036], [0, 0, 5046, -841], [-14255, -801, 0, 0], [0, 0, -2525, 1360], [-32686, -332, 0, 0], [26288, 360, 0, 0], [22314, -1862, 0, 0], [0, 0, -2868, -1077], [0, 0, -962, -3188], [0, 0, 3922, -1307], [0, 0, 4065, 991], [0, 0, 2365, 2784], [-1698, -2650, 0, 0], [-1095, 4337, 0, 0], [0, 0, -2695, 2499], [13018, 3458, 0, 0], [0, 0, 5390, -1912], [-21074, -522, 0, 0], [7446, 4242, 0, 0], [33820, -956, 0, 0], [0, 0, 1143, -2097], [0, 0, -221, -2503], [0, 0, 2492, 699], [-11421, 2215, 0, 0], [24824, 2814, 0, 0], [-1948, -728, 0, 0], [0, 0, -5737, -1412], [-8970, 5254, 0, 0], [0, 0, 2050, 140], [6380, 4980, 0, 0], [0, 0, 6264, 817], [5357, 2835, 0, 0], [0, 0, -5202, -3605], [-5702, 738, 0, 0], [0, 0, 130, 2951], [-19646, -2678, 0, 0], [3924, 4036, 0, 0], [0, 0, -2366, 2024], [0, 0, 5273, -3043], [-7002, 1918, 0, 0], [-12463, -3335, 0, 0], [0, 0, 5424, -120], [0, 0, -1676, -3355], [25196, 752, 0, 0], [0, 0, 4117, 2556], [31607, -161, 0, 0], [0, 0, 479, -1711], [29578, -3826, 0, 0], [0, 0, -598, 4581], [4092, 130, 0, 0], [0, 0, -1493, -148], [47758, 942, 0, 0], [0, 0, 2130, 5988], [0, 0, 3557, 4755], [-23242, 3934, 0, 0], [14542, -3938, 0, 0], [0, 0, -966, 799], [-20850, -3378, 0, 0], [0, 0, 7727, 6347], [40149, -1907, 0, 0], [39365, 2909, 0, 0], [0, 0, -1879, 2363], [0, 0, -5840, 2300], [48780, -1102, 0, 0], [0, 0, -4602, -3300], [0, 0, -9928, -2521], [0, 0, -3999, -4917], [0, 0, 9337, 5900], [0, 0, -9540, -1603], [0, 0, 6930, 1196], [-43327, -1019, 0, 0], [-16315, -553, 0, 0], [0, 0, -3877, -6760], [22761, 7137, 0, 0], [0, 0, -6092, -177], [49054, -3710, 0, 0], [0, 0, -9169, -4200], [0, 0, 1328, -316], [0, 0, -1013, -5429], [6800, -10000, 0, 0], [0, 0, 2551, -971], [-2356, 2908, 0, 0], [12007, 8575, 0, 0], [1355, -2061, 0, 0], [0, 0, -3960, -4828], [-51040, -178, 0, 0], [36480, 1396, 0, 0], [0, 0, 627, 7564], [-45533, 315, 0, 0], [0, 0, 10099, -2437], [-17532, 5400, 0, 0], [0, 0, 2008, 4044], [9355, -5009, 0, 0], [58755, 1131, 0, 0], [0, 0, -1333, -4328], [-29724, 4956, 0, 0], [-26764, 8446, 0, 0], [0, 0, -5333, -2288], [0, 0, 2024, -4436], [0, 0, 8543, 2727], [-30418, -5428, 0, 0], [-13218, -1666, 0, 0], [0, 0, -9580, 584], [-41773, 5071, 0, 0], [0, 0, 3257, -2484], [0, 0, -4268, 5764], [-28136, -2754, 0, 0], [0, 0, 4719, -5907], [0, 0, 8802, -348], [0, 0, 6356, 672], [0, 0, -1317, -2296], [-20703, 4413, 0, 0], [-68308, 3052, 0, 0], [-9126, -3136, 0, 0], [0, 0, 1651, 4669], [31426, 1354, 0, 0], [0, 0, 1691, 5443], [0, 0, 8276, -2477], [-13850, 3566, 0, 0], [-35857, -633, 0, 0], [0, 0, 5803, 540], [0, 0, 4048, -1377], [0, 0, 8593, -1073], [10720, 12316, 0, 0], [-38719, -7091, 0, 0], [0, 0, -12536, 2751], [0, 0, -4664, -2179], [0, 0, -10923, -9125], [0, 0, -12879, 4732], [30438, -5348, 0, 0], [0, 0, -5261, -1957], [-49394, 8190, 0, 0], [40303, 4967, 0, 0], [0, 0, -11626, -2343], [-13213, 2551, 0, 0], [0, 0, -9769, -1629], [22018, -9090, 0, 0], [0, 0, 4199, 4927], [0, 0, -9236, -5184], [-13731, -12359, 0, 0], [70284, 1670, 0, 0], [-137539, -689, 0, 0], [0, 0, -9851, -4504], [0, 0, 8540, -2652], [30292, -4988, 0, 0], [0, 0, 314, -10032], [0, 0, 17780, -2065], [0, 0, 8435, 11864], [-7634, 13786, 0, 0], [-12624, 942, 0, 0], [1444, -1722, 0, 0], [0, 0, 9794, -3624], [0, 0, -10523, -2109], [-80, -10538, 0, 0], [0, 0, -17075, 2008], [-96057, 3343, 0, 0], [0, 0, -807, 8048], [78766, -504, 0, 0], [0, 0, 4686, -6529], [0, 0, 2040, -9364], [0, 0, -12818, -12531], [0, 0, -7283, -5632], [0, 0, -3715, 5560], [0, 0, -15905, -4263], [31791, 8551, 0, 0], [39840, -2440, 0, 0], [147005, -3647, 0, 0], [-61135, -1579, 0, 0], [16858, -3094, 0, 0], [95889, -795, 0, 0], [0, 0, 4468, 7667], [-5324, 13128, 0, 0], [-77402, 1768, 0, 0], [0, 0, -10024, 2372], [-108447, 361, 0, 0], [130022, -2810, 0, 0], [87069, 9817, 0, 0], [-56254, -1638, 0, 0], [0, 0, 3973, 8221], [0, 0, 3671, 4476], [-55864, 4000, 0, 0], [0, 0, -13409, -1579], [-67940, -5012, 0, 0], [0, 0, -15069, -872], [-50830, -14206, 0, 0], [0, 0, 22072, 12181], [106454, 1302, 0, 0], [7781, 9139, 0, 0], [0, 0, 1029, 3137], [82939, -585, 0, 0], [0, 0, 14145, 4400], [25434, -17770, 0, 0], [-47997, 13867, 0, 0], [50768, 8810, 0, 0], [65671, 2783, 0, 0], [0, 0, 11766, 3576], [0, 0, 14081, 10596], [-28074, 1214, 0, 0], [0, 0, -8343, -6572], [-83193, -15169, 0, 0], [0, 0, -67, 1859], [0, 0, -11055, 2847], [0, 0, -19830, -13244], [46792, -10790, 0, 0], [42667, 3955, 0, 0], [0, 0, 682, -2923], [15650, -11942, 0, 0], [10707, -5029, 0, 0], [114399, 10059, 0, 0], [0, 0, 10818, -3533], [-55969, 2579, 0, 0], [0, 0, -2912, 9828], [0, 0, 4900, -11759], [0, 0, 23839, -3616], [39246, 7592, 0, 0], [100060, 2226, 0, 0], [0, 0, -10994, 6612], [77564, 1726, 0, 0], [0, 0, -22599, -6499], [0, 0, 27270, -4084], [0, 0, 26957, -7020], [50040, -14038, 0, 0], [85132, -1736, 0, 0], [2522, -1400, 0, 0], [0, 0, -3965, -695], [-72678, -11890, 0, 0], [105906, 5442, 0, 0], [0, 0, 9227, 15164], [-73167, -2103, 0, 0], [0, 0, 13662, 15657], [-46456, -14620, 0, 0], [-68997, -6083, 0, 0], [104702, 990, 0, 0], [0, 0, -19401, 8052], [108272, 3328, 0, 0], [112226, -7280, 0, 0], [0, 0, -11572, -2016], [9202, -1144, 0, 0], [0, 0, -8677, -6212], [-136768, -12292, 0, 0], [0, 0, -10729, 5125], [0, 0, 30973, 7363], [0, 0, -4233, 4993], [0, 0, -21646, -15263], [625, -18529, 0, 0], [3036, 1372, 0, 0], [-53140, 46, 0, 0], [0, 0, -811, -2372], [0, 0, -17548, -7740], [-27094, -28662, 0, 0], [0, 0, 16188, 21857], [106718, -1418, 0, 0], [0, 0, -16202, -2804], [-94267, 14301, 0, 0], [0, 0, -15776, 927], [29326, 5806, 0, 0], [0, 0, -12045, 11320], [-122182, 6422, 0, 0], [219622, 550, 0, 0], [0, 0, 3978, -5884], [0, 0, 35995, -4031], [-139274, -9394, 0, 0], [55549, -24363, 0, 0], [0, 0, 23884, -5907], [13766, 12072, 0, 0], [-29712, 10832, 0, 0], [0, 0, -17193, -847], [0, 0, -25422, 477], [0, 0, -8318, -21836], [-167898, 2720, 0, 0], [11251, 525, 0, 0], [0, 0, 15841, 8128], [0, 0, 9239, 2308], [0, 0, -19799, 11891], [93951, -16313, 0, 0], [256611, -5145, 0, 0], [65418, 11546, 0, 0], [-48144, -15344, 0, 0], [0, 0, 20674, 12751], [-40282, -28074, 0, 0], [0, 0, 12598, -14624], [0, 0, 3013, 7395], [0, 0, 30900, 17172], [-45, 25099, 0, 0], [0, 0, -9792, 18993], [-182660, 7308, 0, 0], [0, 0, 6489, -1400], [0, 0, 7559, -15821], [0, 0, -2108, -11181], [233271, -10189, 0, 0], [-53268, 3612, 0, 0], [0, 0, -19975, 5128], [0, 0, 25326, -12816]];
    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_bf();".
// 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_bf(:prec:=4)
    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_bf();".
// 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_bf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_784_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![784, 0, -74, 0, 1]>,<5,R![784, 0, -186, 0, 1]>],Snew);
    return Vf;
end function;