
// Make newform 354.4.a.e in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_354_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_354_4_a_e();".
// 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_354_4_a_e();".
// 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 := [90, -37, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-26, 2, 1]];
    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_354_a();"
function MakeCharacter_354_a()
    N := 354;
    order := 1;
    char_gens := [119, 61];
    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_354_a_Hecke(Kf)
    return MakeCharacter_354_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], [-3, 0, 0], [2, -1, 1], [6, -3, 2], [20, -3, 3], [-14, -7, 3], [32, -4, 3], [-58, 18, 7], [-6, -22, -9], [-52, 37, 8], [-22, 7, -4], [-124, -22, 7], [72, 59, 20], [-136, 39, 31], [418, -23, -16], [154, 65, 31], [-59, 0, 0], [344, 23, -8], [-40, 59, 11], [764, -1, 57], [-224, 103, 8], [324, 171, -21], [-30, 117, -58], [-148, -41, -18], [-1178, 29, -7], [50, -26, 68], [-656, -10, 96], [734, -32, 145], [-1196, 78, 19], [634, -219, -49], [-252, 117, 109], [752, 80, 210], [-1342, 319, 129], [556, -417, -219], [-464, 258, 71], [-674, 241, 4], [-682, 151, -41], [-490, -21, 222], [10, 149, 146], [-1452, -169, -60], [-728, -543, -183], [304, -659, -248], [2252, 109, -155], [258, -210, 370], [-2010, 250, 96], [1514, -103, 84], [-30, 92, 483], [1552, -172, -256], [1270, -434, -449], [1840, 733, 130], [-3194, -202, -192], [1492, 483, 417], [730, -82, 398], [-264, -181, -301], [-406, 70, 430], [3146, 319, -92], [-34, 633, -329], [2672, 277, -185], [646, -467, -333], [1238, 56, 326], [1646, -174, 323], [-2984, -276, 323], [3780, -320, -124], [34, -868, -353], [4992, 526, 29], [282, -1051, 43], [40, 72, 18], [384, 46, -595], [1286, -903, -1028], [2310, 651, -265], [64, 582, 941], [-428, -1028, 192], [6012, 883, -167], [-7632, -100, -735], [-3088, 1869, 597], [1144, -1183, -1039], [-3702, -820, -392], [-5922, 1165, 29], [-7368, 228, -205], [-2478, 436, -148], [7996, 886, -434], [2054, 607, 467], [-8306, 59, 12], [-408, 158, 89], [-4714, -432, -589], [-5050, -62, 887], [-4986, -1079, -731], [-240, -2915, -754], [-3296, 832, 1327], [-4682, 222, -1565], [-10148, 712, 568], [-7238, 1750, 1317], [5882, -952, 1293], [174, 669, -468], [8264, -2057, -1421], [-2146, 431, -204], [-8064, -177, -134], [5000, -1705, -392], [-8888, -11, -831], [-8862, 591, 661], [11106, -1988, -633], [-4814, 1772, -448], [-11444, 513, -1297], [5384, 241, 34], [-1532, -907, 351], [5290, -301, -279], [1944, 2125, -195], [-10576, -2701, -504], [9416, 234, 1336], [9708, -388, -1239], [-13664, 1533, 1107], [11766, -1692, 538], [4180, 2904, 161], [6508, -305, 1553], [14524, 1765, -463], [11606, -1955, -1671], [-5594, -460, 273], [11652, 128, 408], [-608, 671, 584], [7118, -2302, -137], [-608, -3821, -230], [-1998, -2344, -356], [-6682, 1760, -1826], [-2896, 2147, -389], [-5088, 1588, -50], [11448, 2195, -1174], [10578, 62, -1892], [19446, 864, -29], [9448, 1274, 1294], [10950, -2157, 1177], [3026, -1804, 1991], [8750, -1808, -2123], [-9512, 696, -1214], [14324, 856, 735], [13602, 2539, 245], [-16880, -494, 1605], [-7510, -4074, 1392], [-6952, 3652, 1314], [17642, -3538, -1472], [16412, -2778, 2287], [6504, 114, 3192], [-4196, 487, 872], [-20856, -57, -329], [-2952, -691, 1249], [-8964, -1641, -1264], [26616, 1845, -609], [-21476, 3946, 2341], [19874, 2073, -445], [-25396, -2706, -226], [-24098, -1764, -1101], [-32474, 1528, -708], [11230, 54, -3152], [-14076, 1648, -544], [11964, 1243, 735], [-6784, -2065, -5193], [5338, 97, -2954], [-10760, 2204, 1690], [-4802, 2609, 2413], [30534, -199, -1795], [46, -2083, 2399], [-9214, 731, -1868], [22298, 1514, 2890], [1890, -46, 3301], [-23330, -3688, -2407], [-374, 1643, -103], [-4312, 2901, 4215], [-19670, -5004, -1677], [5472, 4307, -1082], [6522, 2118, -3758], [-4386, -984, 736], [9388, -3727, -2277], [426, -4628, -2156], [-11326, -906, 1697], [-30358, -1349, -3091], [-12656, -7416, 1884], [-22510, -1835, 575], [-37668, -4641, 325], [-534, 6586, -2136], [-15562, 3794, 1025], [15206, 5724, 3476], [11544, -206, -270], [6676, 6160, -2076], [-13666, -8621, 1771], [-17658, 2634, 3668], [32260, -197, 2657], [8864, -5940, -4291], [1678, -2270, -2696], [-9808, -10314, 1004], [-18730, -4215, -3775], [-44634, 2906, 309], [-23754, 473, 1553], [-6236, -3529, 2881], [-43012, 3996, 2096], [19936, -423, -386], [47508, -1532, -1816], [17536, 968, 4983], [-1980, 8800, -187], [-10928, 11045, 1654], [41144, 3905, -330], [-18714, -8748, -2717], [8426, -774, -5434], [42524, 1585, 717], [4220, -2464, -1749], [36168, 2458, -2707], [-36784, -960, 886], [-2780, 5727, 1596], [13416, 309, 3581], [-17190, -2416, -773], [6228, -3124, 4053], [7944, 9650, 1452], [212, 11998, 2123], [29918, 999, 31], [-33718, 5328, 509], [36548, -10386, -5886], [11352, 4877, 2657], [33904, -4122, 5157], [31156, -6557, -2233], [5844, 7449, 5112], [-25186, 690, 2725], [30922, -5425, 429], [-50730, -2029, -4457], [22692, -9207, -7413], [60530, 5230, -710], [6986, 855, -4062], [3544, 4238, 3180], [58168, -1839, 3858], [-10428, -14028, -3171], [-2148, -13472, -418], [60988, 656, 2724], [-6486, 7872, 1207], [33188, -2541, 750], [-9080, 4949, -7375], [-50450, 6088, 4693], [57986, -6191, -1741], [-26300, 1882, 1122], [-6956, -5217, -3715], [45850, -179, 8755], [-39400, 4241, -848], [-40180, -11489, 3265], [37314, 2787, -228], [6576, 7077, -1307], [-46740, -9996, 368], [-73508, -5333, 1359], [8354, -1540, -546], [4248, -9792, -10105], [22498, 10973, -5602], [29700, 9933, -3669], [15612, -11661, 4065], [-50150, 2801, -2830], [18744, 10809, -2679], [5552, 15930, 4063], [-39592, -7606, -1179], [3410, 7897, 4596], [48214, -7981, 3579], [-146, 16665, 3641], [-44448, 5043, 487], [2458, 3621, -1639], [-11672, 9286, -3536], [15054, -733, 2485], [19596, -13028, -8103], [48360, 6983, 6667], [-27420, -8337, 1641], [-11494, -13506, 1676], [33738, 4370, 780], [12158, -1821, -2081], [-45660, -2748, -920], [39136, -10036, 7271], [4990, -11628, 398], [-51360, 7309, -8163], [-20426, 10339, 731], [21754, -4376, 8052], [23966, -2703, -588], [-75240, 8018, -1623], [-18364, -3131, 6981], [56966, 9627, -2633], [-3010, 4620, 657], [-1194, 7459, -1018], [12590, 21185, 2475], [-43450, 9837, 10713], [5828, -10489, 181], [64348, -1785, 6945], [-38296, 13276, 1062], [20, -21938, -6384], [-41622, -15912, -1324], [-65104, -7945, 2547], [-18054, 15675, -826], [-32182, -935, -5425], [63824, -6724, -6065], [78760, -4595, 2765], [6314, 420, -296], [26770, -2069, -4097], [-6152, 4620, -486], [1916, 17308, -5567], [27824, -581, 15727], [-44426, -1879, -7989], [29730, -15109, -12765], [119190, -567, 458], [8174, 7839, 8791], [-52438, 8909, 4282], [96544, 3027, 7455], [-42456, -20853, 5096], [-64038, -1965, 2843], [-12080, -8225, 8035], [-33004, 12590, -10382], [-109876, 4780, 6552], [18126, -15741, -5873], [-8716, -2811, 12115], [39376, 16121, 2006], [119134, -5973, 2564], [-67106, 14414, 6536], [45292, 10421, -761], [30356, -16428, -13979], [7614, -3089, 9147], [-4762, -3903, 8400], [-26390, -21944, 7431], [-102098, 2933, 1077], [64450, 9989, 1030], [102360, 1703, 5183], [17590, -10316, 4502], [-95126, 4587, -3671], [10148, 6670, -2654], [-19554, -1130, -12488], [-20768, 17963, 11480], [-21832, -18038, -4590], [135414, -3095, 8921], [-19182, -12892, -10424], [-70992, -26029, 2923], [91872, -8384, -7886], [-54984, -5612, -2508], [100, -18021, -14488], [-52592, -18340, -4749], [91586, 9440, 8642], [17004, -280, -4596], [40652, 8399, 8109], [63010, -14346, -8647], [-23174, 10843, -12988], [-33416, -5159, -12496], [42930, -3092, -10348], [35856, 17821, 1154], [31064, -285, 6425], [-24886, 28846, 5096], [41530, -16431, 2031], [-89822, -7102, 5088], [-43868, 18464, 5260], [-78638, -23678, 4444], [-97644, -7225, -1719], [-69970, 29007, 13403], [23972, -4720, 1788], [-30076, -12903, 3317], [2470, -6913, -1979], [47978, 14624, -4689], [-160560, -1573, -2924], [84136, -2043, -1986], [89970, -17641, -8708], [-64132, -14979, 4578], [39658, 8090, 5750], [-3768, -6778, -19238], [128258, -7795, 8126], [110124, 12080, -6355], [91920, 12209, 4937], [-14350, -16645, -18519], [-33016, -9404, -8913], [-49228, 10888, 12028], [-39644, 11793, 3611], [89282, 20171, -2812], [-51812, -8039, 100], [32262, -4662, -1902], [42364, 20586, 10456], [-60686, -28204, 52], [-43442, -18855, -14844], [81588, -11057, 6573], [9728, -5399, -5945], [59336, -14636, 1571], [-67264, 13694, -16316], [62716, 4063, 6172], [-94506, 8148, -11651], [166370, -6904, 1973], [20832, -3231, 3794], [-70270, -9764, -7820], [-95914, 2287, 327], [-77218, 1996, -3950], [70392, 39681, -2806], [110806, -6620, 7707], [-49082, 34267, 20679], [37652, 24877, 12427], [-93808, 5761, 12719], [114360, -1133, -1967], [76996, -7441, 15792], [-10250, 17212, 8297], [-30896, 8475, -19195], [-28798, 4149, 5107], [-96972, 20460, -5645], [-63150, 8772, -6985], [72488, -1372, 3834], [-107898, 10509, -4770], [-83074, -5796, 2338], [-46138, -31743, -1258], [-49294, -1056, 12016], [-80958, 7428, -7385], [-86982, -13855, -13689], [76702, -13879, -10713], [-127638, -2264, 8644], [16940, -25156, -14194], [12408, 833, -3706], [-117160, 302, 3505], [-94272, 8651, 1771], [17630, -15718, -9444], [18982, -24874, -18400], [-76484, 1557, -5357], [-121708, 7569, 27], [95816, 6758, 12033], [-74108, -19993, 12158], [104778, -33898, -10715], [-140516, -1605, -4683], [70278, -18833, -4201], [130882, -14302, -6350], [-106304, -18968, -1984], [3754, -26409, -9360], [-43374, 32143, 1857], [-21434, 9315, 25058], [-15080, -13284, -21115], [32850, 15469, 1181], [-2038, 29798, 12613], [178752, -9006, 7172], [88018, -35390, -21350], [48954, 5578, 20470], [152490, -21476, 4747], [-112616, -33285, 4904], [107962, -5503, -1310], [5528, -38499, -407]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_354_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_354_4_a_e();".
// 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_354_4_a_e(:prec:=3)
    chi := MakeCharacter_354_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_354_4_a_e();".
// 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_354_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_354_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![678, -175, -4, 1]>],Snew);
    return Vf;
end function;