
// Make newform 354.4.a.h in Magma, downloaded from the LMFDB on 19 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_h();".
// 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_h();".
// 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 := [3, 19, -44, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [-8, -45, 0, 1], [14, -43, -1, 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_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, 0], [-3, 0, 0, 0], [5, 1, 0, -1], [3, 1, 1, -1], [5, 2, 0, 1], [5, -1, -2, -1], [26, -7, -1, 0], [38, -5, 1, 6], [8, -9, 1, 0], [71, 6, 1, 1], [71, 10, -7, 3], [160, -18, -5, -10], [167, 7, 5, 9], [47, -6, 6, -13], [23, -37, 1, 3], [59, -37, -4, -3], [59, 0, 0, 0], [165, -4, 1, 7], [-233, 12, -14, -5], [51, 35, -24, 11], [215, 27, 27, -7], [-179, -48, -28, 9], [251, -13, 7, 11], [319, 21, -3, 57], [-481, 0, -2, 57], [-580, 20, 10, 10], [-728, 25, -20, 40], [-392, -121, -7, 36], [-252, 44, 43, 26], [151, 76, 12, 13], [-1349, 62, -12, -33], [-312, 136, 78, -40], [-289, -48, -42, 49], [-531, -164, -14, 105], [1146, 29, 29, -88], [-547, 34, -21, 81], [-441, -23, 92, -79], [-883, -135, 7, 1], [1161, 172, -77, 1], [2535, 33, 15, 33], [437, 98, 58, 229], [-399, -193, 91, 23], [753, -60, -10, -211], [-240, 136, 48, 38], [754, -351, 72, 208], [-1485, -7, -89, -1], [-1182, 57, -29, 106], [-1824, -144, -164, -176], [-1344, -27, -91, -116], [-801, -232, -127, 57], [2444, -46, 222, 90], [-161, -271, -88, -257], [324, -168, -240, 246], [877, 324, -192, 45], [1148, -308, -76, 154], [-189, 370, 119, -301], [1667, -200, -144, 341], [-341, 102, 10, -385], [361, 324, -22, -73], [586, -118, -14, 360], [456, 457, 73, 456], [2228, 6, 245, -158], [872, -566, 196, 352], [4294, 210, 153, -150], [2102, 181, 271, -44], [-521, -307, -316, 121], [392, 480, -274, 24], [-4126, -213, -41, 184], [-565, -117, -191, 15], [5663, -157, 32, 281], [1678, -581, 7, 416], [-1482, 381, 34, 314], [-2163, -603, 322, 33], [2910, -335, 9, 336], [-6145, -92, -44, 103], [-1035, 561, 214, 181], [548, 1087, -82, -310], [2389, 877, 12, -721], [-1388, 219, -397, -190], [2026, 114, -144, -856], [-3050, 820, 416, -478], [5691, -111, -120, 269], [813, -527, -129, -575], [300, 115, -17, -370], [68, 269, 191, -900], [-7348, 949, 181, -320], [-8235, -610, 88, 335], [-3299, 285, 431, -305], [-56, -142, 149, 14], [-6618, 896, 531, -434], [-2416, -874, -180, 592], [-12960, -618, -3, 628], [-5240, -253, -23, 240], [-5573, -687, 91, 1115], [-4959, 144, 208, 121], [-3695, -195, -293, 13], [3919, 971, -131, -903], [7939, -21, 25, -139], [5451, -1100, 52, 507], [995, -1429, -242, 149], [7348, -425, -557, 344], [704, 1295, -146, -834], [-923, -26, -56, -1039], [-1363, -37, 299, -533], [6641, -988, -328, 405], [-1505, 1018, 458, 749], [-8203, -564, 102, -463], [8787, 509, 85, -1155], [-384, -275, 52, -1460], [9268, -499, -203, -646], [7827, 448, -414, -145], [3224, 1515, -352, 318], [-1242, 857, 645, -540], [1597, 1674, 46, -907], [-7129, 1804, 344, 187], [16089, 826, 204, -901], [-5196, 661, -91, -464], [-574, 595, -22, 718], [1233, -772, -497, 787], [-11384, 1289, 201, -908], [9619, -329, -5, 1065], [-9062, -1034, 404, -952], [7356, -405, -756, -54], [4007, -256, 106, 1035], [10820, 224, 26, -420], [1251, -681, -579, -595], [-6012, 1882, 54, -826], [14502, 733, 467, -1434], [5806, -1110, 432, -538], [-10529, 184, 438, -411], [11438, -217, 175, -658], [-12630, -1494, -341, 502], [8738, -265, -420, 450], [11402, -929, 91, 676], [6859, 800, 538, 877], [1466, 953, 667, 992], [9816, 2244, -438, -586], [-9356, 2200, 670, -804], [11784, 970, 706, -578], [-8874, 421, 329, 1076], [6490, -36, -362, -1414], [5855, 1343, 311, 601], [-3135, -657, -1260, 1349], [20331, -896, 608, 1107], [-5269, 125, -475, 1553], [-24287, -1582, -136, 909], [-15192, -1419, -49, 1122], [14759, -696, -188, -1703], [-4866, 382, 976, -1770], [13274, 1681, 227, -1366], [-13814, -974, 360, 1140], [5596, -710, -994, 290], [8504, 1396, 520, 244], [-5305, -934, -42, 1187], [12405, -218, 80, 1857], [-8239, -406, 95, 2097], [-8654, -2333, -148, 2578], [-18689, 378, -14, 361], [-14005, 2826, 806, 749], [-1513, -1162, -376, 241], [1153, 2007, 1029, -2159], [7704, 1662, 844, -866], [-18970, -936, 329, -594], [7156, 1715, 321, -1712], [-339, 604, -1532, 235], [23981, -610, -664, 1137], [84, -2448, 525, 620], [3063, 1237, 1111, -1059], [-408, -1230, -660, 14], [-20702, 2166, 568, -2064], [27279, 240, 1194, 559], [-8364, -2177, 378, 2354], [8228, 2272, -1139, -1088], [15945, -2500, 428, 2611], [-11204, -1308, -852, -468], [-14519, 1798, -906, 35], [-23, 3244, -174, -27], [27360, 2162, 478, -3410], [-9662, -3527, 671, -1030], [23742, 2168, 684, 728], [16834, 1398, 388, 818], [3432, 4374, -480, -836], [-15965, 2225, 576, -875], [-11696, 1014, 1174, -1202], [-17281, 2077, -160, 703], [420, 1673, -671, -1222], [-25386, 1177, 1668, -1604], [26062, -2328, -274, 2078], [13867, 1064, -1190, 853], [30232, -1169, 659, -864], [34027, 638, -862, -395], [-6345, 10, 140, -293], [23188, -660, 1532, 1196], [-44133, 568, 551, 1621], [35648, 514, 1044, -788], [-44344, -2593, -177, 3078], [-286, -1931, -1439, -608], [-41181, 4716, 825, -1043], [48785, -509, 795, -917], [-23430, -2107, 815, 2154], [-2982, 59, -422, -664], [26251, -2946, 924, 2519], [-3114, 107, 383, -1128], [-27242, -2661, 287, -476], [-19796, 900, -2170, -1776], [38211, 2865, -1181, 893], [14803, -1793, 1608, 167], [-30074, -103, -205, -1202], [-23084, 417, -1247, 2066], [30166, -4054, -1130, 542], [16550, -4097, 1785, 1156], [10601, 415, -118, -4829], [8332, 659, -1479, 1524], [23270, -522, 132, -902], [27177, 2449, 1870, -399], [21414, 5249, -1053, 620], [-11779, -1990, 136, 2385], [19313, -1975, 207, 539], [-24108, 3547, 363, 372], [9669, -2241, 828, 2815], [-13457, 4525, 1532, 1745], [25491, 2845, 1614, -5529], [-32244, 5812, 1120, -1250], [-6443, -1503, -1429, -4511], [20018, 6414, -1426, -1618], [-9305, -4672, 653, -415], [-20946, -2215, 505, 2884], [-9996, -3362, -2742, 1916], [-19998, 299, -3246, 938], [9944, 1797, -1517, -1916], [-31371, -260, 535, 1871], [40621, 168, 2450, 321], [-39128, 764, 167, -2552], [-7165, -3896, -3240, 2025], [62290, 412, 268, -1790], [52343, -4915, -1520, 2367], [2403, 3610, -1064, -2755], [-19511, -2261, -599, -2365], [-20609, -612, -656, -2401], [-30237, -2366, -1025, 4123], [-21845, -3938, -1036, 259], [-10892, 4846, -624, 1220], [19197, -1150, 2648, 481], [11330, -4136, -946, 3716], [-4050, -1849, -1397, -3252], [-25527, 1416, -573, -135], [-64125, 4929, 914, -1345], [37343, 848, -2208, 647], [37467, -3631, 1397, 4067], [-1331, 2565, -1730, -715], [-79348, 785, -675, -1810], [-9594, -5909, -513, 2720], [4235, -1925, -1091, -4249], [29111, -3316, -716, -3115], [-15125, 1999, -806, 4445], [-33143, -2334, 712, 3417], [16485, -824, 580, 4771], [-13966, -5450, -850, -4198], [-7691, -6462, 1312, 2871], [13306, 6189, 1993, -2548], [-24483, -3129, 508, 4737], [-26739, -890, 318, 2013], [-16684, 432, -3798, 1438], [-44632, 4368, 1582, -2358], [44751, 1502, 1364, -4735], [2880, 2478, 728, 1288], [-4884, 4740, 69, -1950], [-18466, -3146, -122, -1008], [23603, 4640, 232, -3789], [10401, 9885, -1142, -749], [-37736, 513, -2674, 566], [-66329, 3421, 847, 3315], [9658, 7391, 1987, -6184], [-14473, 1890, -3524, -3581], [-16197, -1068, -1948, -595], [-57864, 614, -2945, -4360], [-42831, -2665, 2259, -919], [62565, 158, 2974, 3875], [8447, -4194, -2558, 1321], [-7707, -7928, 1458, 6789], [-1577, -3859, 2956, -2265], [-15242, -8023, -868, -1466], [39798, 3738, 1826, 1582], [62212, -1693, -710, -2502], [10095, 8258, 858, -3269], [10661, 1013, -2715, 4009], [-41705, -2090, -4380, -2319], [-21748, -378, 2477, -5630], [51643, 2317, 4, -4633], [-50250, -4976, -1068, 7908], [43941, -4622, -1934, -441], [28088, 3736, -3522, 3756], [56066, 9265, -1759, 64], [-4305, -5118, -1898, 5215], [-18119, -9512, -534, -1569], [-2607, 3948, -1330, 5939], [25015, 6209, -1823, -5397], [52633, -7129, 1318, 851], [60403, -7943, 3, 3391], [2879, -3028, 1410, -1925], [-33725, -2895, 1169, -1043], [7345, 2954, 274, 91], [9521, 993, 1820, 5453], [-38902, 4032, -828, 2510], [49740, -7422, -592, -2604], [-55839, -7656, 3642, -1477], [77035, -9408, -3210, 3979], [36635, 4486, 3601, 2013], [-68971, 11127, 2627, 2113], [53410, -1351, -1508, 2720], [-10835, -5253, -1856, -4907], [82836, -3082, -229, -886], [109143, -4298, -544, 137], [22343, -2357, 2433, 1107], [7306, -1202, 3241, -5418], [76275, 4266, 2902, 1077], [2143, 2839, -2017, -2257], [12559, -609, 2202, -1713], [66630, 938, 354, 4536], [59031, 6450, -682, -7943], [-3050, 5548, 2604, -2438], [76112, 4752, 974, 726], [73309, 4090, 351, -1145], [-20362, 4342, -908, -3530], [87077, -4026, 300, 871], [10266, -12838, -2304, 1808], [32715, -10410, -266, 2295], [-16600, 6914, 1142, -5964], [37580, 6018, -3588, 3404], [30675, -10401, -2181, 7677], [63430, -2214, 2805, -2508], [-12366, -374, 2206, -3424], [-27338, -9523, -378, -7154], [34549, -226, -594, 4749], [95614, -12001, -2289, 4210], [-8179, -5049, 2125, 2997], [-44471, 1853, -2425, -6081], [-63638, 1076, 5232, -4536], [102869, 515, 207, 5079], [30729, 6876, -2906, 5253], [-57956, 9542, -2550, -4002], [-35953, -124, -948, 5217], [39452, -5508, -3522, 4842], [-145286, 5645, 366, -1534], [13712, 9712, 934, -8722], [74759, -4296, 1652, -857], [2019, 7715, -2048, -2859], [-50172, 2976, -812, -4288], [33233, -2956, 3870, 9285], [20985, 5630, -3392, -6501], [-101742, 2911, -9, 1162], [-17893, -7447, -3035, -4987], [-12801, -368, -261, 8833], [14079, -6968, -5955, 2219], [-3699, 10743, -683, 1547], [-48872, -9804, 2644, -4822], [-3250, 9702, -112, -154], [-81073, 9619, -1499, -5777], [-60662, -9625, -3091, 7328], [-9527, 8769, 4882, -1007], [19779, 1621, -850, 6717], [58362, 1079, 671, -3440], [-15670, -5421, 586, -5970], [-90887, -6576, 3220, -31], [-78159, -717, -2935, 1885], [-56591, 6693, 2249, 2179], [8412, 304, -5976, -1974], [-43610, 72, 54, -2146], [75974, 6282, 1092, -3660], [25463, 8609, 159, 255], [24791, 12868, -1720, -6917], [-49635, 11808, 7648, -4463], [38224, 6686, -479, 1710], [13472, 5323, -1276, -7808], [-119213, 6823, 1785, 377], [-54134, -9209, -1099, -2486], [-80466, 12637, 2301, 1198], [44581, 1467, 8959, 351], [-183922, 8736, 2560, -3036], [33691, -7372, -6300, 4481], [8704, -5861, -3612, 12622], [8545, 1387, -2937, 4251], [-30624, 3019, 6559, -2352], [-57079, 9586, 4590, -6573], [43871, 2370, 1898, -5609], [62949, -3806, 7308, 3313], [-97011, 2384, -3974, 249], [28835, -14739, -4315, 6249], [66520, 5767, 7245, -6968], [5747, 88, 5684, 3847], [-60953, -4596, -1888, 8217], [101052, -6723, -3505, 4482], [-51706, -1251, -6209, 2990], [-150780, 9196, -3182, -5860], [-24941, -12153, 5123, 5535], [86362, 12824, 1750, -8224], [-3513, 1227, -3951, 7955], [-26418, 8634, 1084, 10060], [-8156, 2385, -365, -4148], [131099, 7111, 308, 2317], [-172419, -4244, 634, 603], [61018, -2744, 2616, -10720], [-27396, -3830, -7022, 13356], [-30663, 4015, -4687, 7675], [-70062, 5178, 6289, -1496], [-97899, 89, 4444, -4143], [35398, -5489, -2092, -2660], [14792, -4332, 3054, -514], [79921, -5582, -1596, -6691], [-65837, 5412, -1334, -8285], [-110820, 4659, 1791, -122], [16585, -22382, 645, 3619], [-64396, -12385, 2107, -9008], [100681, -13420, -1482, 1773], [-57125, -1392, -2112, 6353], [-19090, -2125, -6310, -6012], [-28728, 4196, -3940, -8296], [-1889, 14226, 57, -12021], [-54795, 15640, 1004, -3445], [93687, -20398, -4319, 5239], [89964, 697, 5769, 2946], [33917, -4808, 3612, -9501], [-152060, 2682, -215, -1840], [-140486, 476, 1342, 9118], [100804, 264, -5056, 9346], [-119834, 7523, -2630, -7092], [29510, -2241, 3535, -9614], [-91709, 5745, 1473, -6971], [-42165, 3809, -1771, -5373], [-102007, 13629, 6642, -5815]];
    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_h();".
// 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_h(:prec:=4)
    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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_354_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-12744, 4684, -147, -22, 1]>],Snew);
    return Vf;
end function;