
// Make newform 414.6.a.o in Magma, downloaded from the LMFDB on 11 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_414_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_414_6_a_o();".
// 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_414_6_a_o();".
// 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 := [-370980, -182616, -8369, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-16554, 58579, 307, -9], [-16554, 83947, 307, -9], [969000, 65224, 38, -8]];
    Rf_basisdens := [1, 12684, 12684, 3171];
    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_414_a();"
function MakeCharacter_414_a()
    N := 414;
    order := 1;
    char_gens := [47, 235];
    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_414_a_Hecke(Kf)
    return MakeCharacter_414_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 := 6;
    raw_aps := [[-4, 0, 0, 0], [0, 0, 0, 0], [-13, 1, 0, 0], [87, 0, -1, 0], [0, -1, -3, -2], [312, 5, -1, -5], [9, -10, -11, 0], [397, 19, 2, 10], [-529, 0, 0, 0], [-552, 40, 6, 2], [422, 38, 12, 28], [-2432, -61, 63, -10], [2978, 80, -80, -8], [3415, -21, -76, -28], [-2740, -115, 25, -47], [-6761, -159, 136, -20], [2196, -325, -153, 163], [-9480, -121, 71, 100], [-5909, -369, -180, 202], [-8016, -398, 294, 230], [-7318, -158, -86, -308], [-6653, 238, -27, -210], [29644, 71, 77, -296], [37581, 892, 303, 152], [-3692, 530, -424, 132], [37602, -760, 624, 418], [-34249, -412, 283, 246], [104536, 421, -281, 294], [-38218, 563, 737, -316], [81473, -1012, 291, 356], [26974, -1892, -262, 1096], [110336, -542, 826, 788], [137763, -1654, -333, -404], [91240, 60, 904, -864], [28161, 1297, 2474, -84], [234916, -2448, -1156, 506], [187788, -901, 563, -1154], [309562, 252, 278, 554], [64948, -4810, -562, -1238], [76188, 4328, -3374, -594], [-96788, 1823, 679, 1673], [262046, -6531, 1723, 470], [-266250, -3752, 2650, 790], [267548, -2499, -485, 1421], [-279852, 6724, -1878, -220], [102485, -4052, 3329, 456], [-99346, 3192, 4014, 4290], [-12044, 2946, -3282, 604], [86782, 3339, -1417, -4674], [-96266, -377, -763, -4076], [-166114, 2510, -6162, -1858], [208252, -8032, 1404, 3468], [25756, 1852, -4814, -3526], [441114, -649, -2885, -3648], [-21990, -440, 1824, 2000], [317078, -12630, 7192, 5850], [-22956, -804, -4622, -2884], [-381378, 11416, -3450, 16], [-113170, -3070, 270, 3796], [-194989, 7092, -967, 6476], [-777161, 11293, 258, 6318], [184533, 18997, 6878, -3204], [-493614, -18202, 5320, -916], [1055432, -429, -10321, 491], [9234, -15620, 15712, 4182], [-925636, -12742, -8284, -6660], [332178, -5682, -16360, -3924], [1550780, 14712, -10774, 8356], [182936, -11233, -24093, 989], [1731068, 14015, 1913, -14089], [-1026184, 25600, -9078, 2508], [-207978, -12672, -13294, -17030], [-1814277, -7870, -8279, 13094], [1043544, 16763, 1095, 2394], [-549953, 10025, 6478, -7424], [1116566, -13616, -8210, -6400], [-1489983, 25139, 9268, -3600], [-61226, -39028, 11748, -12520], [1609205, -24994, 5777, 13164], [-281020, -35765, 2545, -2765], [657656, 36667, 7725, -23640], [734862, 30135, 8993, 1590], [2759220, 30632, -5288, 14514], [1043094, 8166, 7254, 4028], [671132, -10300, -30928, 18944], [-716352, 45520, 24732, -20692], [1384114, 7670, 37254, 13038], [-381136, -26140, -26754, -21782], [-199656, -11702, -37228, 5478], [3337784, -11614, 8866, 7002], [813642, 7647, -22165, 11200], [-4342020, -13182, -6658, 3238], [2192744, -41242, -13762, 19982], [-1385608, 91777, 9013, -6397], [116010, -35104, 46858, -9022], [2847132, -45412, -4788, -3938], [-5008100, -1614, 36804, 4184], [3722069, -36070, 30985, -8168], [-5554753, -63185, -42808, -2454], [-664636, 35345, -31485, 14737], [-7348374, -36272, 11850, -17258], [208869, -107701, -5000, -14820], [4617658, -41781, 1027, 5710], [-492097, -4014, 46011, 2212], [2549793, 39445, 2420, -3184], [-628708, 93693, 17203, -6337], [-2746624, 103178, 2322, -1300], [8750130, 6590, -4906, 15110], [-3013996, 41488, -47228, -3880], [3981828, -34831, 27527, 17059], [6804404, -4940, 32880, 8882], [-16996, -134639, -1771, -45714], [-10536655, 31416, 5599, -3024], [2180797, 88031, -64898, -24920], [-2056563, -8474, 31415, 37256], [348473, 50054, 71005, -9224], [-3480841, -128165, -63940, -10140], [-10712612, -41603, -40395, -17843], [724882, 154, -71518, -5008], [-1857450, -35253, -79837, -59384], [-3836308, 30097, 90805, 6994], [-1847632, 38967, 12961, -18403], [-8281575, -75139, 72022, 31956], [-407532, -64182, 106406, -7148], [-10881982, -104644, -71978, -12690], [11112163, 73219, 46670, -31720], [5471130, 158081, 94535, 64984], [-9289884, -44891, 26949, 84341], [11792281, -175390, -14937, 34454], [-13414118, -6645, 20385, -866], [3548892, -243340, 60500, 18208], [-1381606, 7152, -87006, -59564], [11768355, -63566, -28855, -8008], [1764510, 75365, -74205, 28038], [11736564, 72860, 76274, 13220], [15377202, 65832, -40148, -8666], [-1433847, -67577, -252, 129080], [-2688049, 61183, -40520, 130216], [-7465929, 92923, 21478, -5120], [4376168, -68142, 84940, 12354], [-5709978, -20168, -103626, -14810], [10365738, -89700, 67036, 74], [-2341766, 3016, -81990, -26538], [-3738570, -101813, -97557, -77380], [-11319092, 333165, 15327, -75899], [-3284166, -36966, 80356, 59534], [-15073022, -139162, -13262, 49846], [-8850650, 121630, -93370, -23602], [9483344, 97606, -74086, -17514], [-10756892, -43477, 106267, -24613], [30182046, 39600, 22092, -91894], [13604411, 122568, -107907, 103084], [-1877966, 283574, 64920, -28708], [-10494176, -268741, 126195, -120213], [8228307, 76161, 114370, -112526], [-16617940, -20612, -110500, -124850], [-2202855, -80916, 296981, 32496], [-3213378, -296404, 92368, -91080], [24903986, 19832, -65528, 10248], [31877211, -149215, 24096, 54556], [-13154540, 63123, -37957, 164385], [-11739645, -165814, 8703, -103748], [16152030, 239558, -25460, 120572], [5033446, -95265, 267171, 182210], [-5686167, -119114, -46135, 143640], [2113484, -85728, -159120, -251006], [490274, 228592, 257146, 3526], [17049108, 281151, 77113, -260045], [-5373772, 66126, -59172, 122448], [-6780862, 34590, 187054, 63192], [5845986, -60477, 109343, -30212], [10509942, -437876, 196552, 9618], [-24292510, -164308, -1162, 23232], [-1804528, -143218, 201340, 9462], [-974766, -183932, 212582, 65108], [-2526231, 287452, -152353, -197388], [-41002432, -30234, 133770, 30702], [13956894, 295348, -272548, -170388], [-16364803, -141986, 117511, 19120], [-6324900, 344465, -54135, -17064], [30323530, 391506, 42708, 32908], [14691354, -46003, -119671, 153314], [-2274806, 382880, 237992, -5166], [32287408, 425334, 121160, 125862], [-30914840, 327944, -30684, 166926], [49048955, 21371, -38542, 45408], [-8967730, 365444, 68356, -12624], [-27338685, 300523, 52496, -12616], [56781686, 63192, -8636, -138862], [13215768, -119889, 156239, -119345], [18901370, -330336, 351920, 140614], [15934308, -15826, 539042, 315608], [-18142685, -71413, -10032, 384896], [-9803810, -254982, 224274, -221122], [-14211024, 556651, -376195, -294396], [-7345985, -397452, 284513, 154932], [7170738, 607110, 29526, -284014], [31456106, 409951, 425021, 42834], [51224141, -563736, 93599, 57500], [-3421476, 445780, 4080, 218240], [-7537855, -55797, -327540, -385292], [-27343950, -328206, -366004, -94458], [19855358, -650150, 121886, -91248], [-31652364, -285756, -327346, 138792], [47028108, 130147, -248659, -16182], [56667232, -727318, 97688, -1292], [60903377, -178178, 31299, -225994], [-1070956, 81915, -656257, -386341], [33620794, 472490, -465662, 61622], [-19509190, 64224, 464858, 273958], [56378238, 678, 59250, -104428], [43090122, 210024, -429740, -93196], [-38546859, -47412, 66977, -148374], [-5521548, -20355, -83953, 212848], [-29045232, -182798, 122894, 522726], [4171658, -377972, 232560, 121106], [23137520, 488972, 96500, 1022], [18291904, -237770, 351632, -312850], [-62537072, 633920, 83520, 123504], [19668018, 720316, -164016, 206192], [20715112, 2857, -451885, -69173], [-30930651, 254644, 252161, 432086], [-31690164, 157526, -148492, 192506], [-29090443, -694194, 612919, -28924], [-37009468, 241300, 14244, 119052], [42004660, -856021, -298631, 97933], [-32560471, 109024, -311609, -169420], [-39154272, 965213, 8221, 106749], [-26934261, -721362, 773141, -167688], [392784, -189888, 292, 519860], [-28754412, 258937, 62675, 319061], [5038615, 61845, -453006, -217706], [-26051041, -98270, -68659, -302688], [-31386852, 433026, -584308, 72310], [-43662283, 755247, -831282, -424308], [-5529856, -818424, 90060, -27302], [116406716, 318618, 357680, 147484], [-24699869, -426601, 197670, 402600], [-13063128, 219942, -397706, -130648], [55882736, 487465, 455849, -169067], [-63699906, 156603, -184201, 243994], [-43694478, -74308, -125674, 259102], [-11580122, 156404, 54690, 489626], [8710948, 98503, 689341, -68479], [23767110, -329486, 201674, 135990], [-30384868, 146996, 141592, 193576], [62623694, 3698, -406512, 646], [6143912, -1009237, -98803, 37068], [-45982769, 1124741, 68514, -91690], [-49293864, 1070260, -802956, -522280], [-5723354, -472333, -66999, -112432], [18219153, 438020, 5631, 715228], [-63995338, 280304, 172198, 675604], [-13039884, -854194, -851872, 328258], [-3912754, -185316, -662356, 402272], [3883800, 206940, 940256, 34060], [-47636346, -263091, -72093, 566498], [11470345, -296395, 661996, 595288], [-30247616, -295302, 182524, 422074], [7323196, 746941, -892573, 130549], [-11206179, 849154, -1129301, -398256], [28965832, 335333, -634665, 530466], [20622706, -681160, 159160, -475274], [-65970424, -845283, -712395, -66522], [-11777710, -83082, 666834, -59810], [60053637, 1323439, 48654, 228328], [-43061505, -46497, 847890, 333000], [-76013915, -347028, 325131, -256264], [43259943, 1175125, -226862, 183234], [-67377460, -486058, -458852, -138110], [95660566, 320368, 783316, 111482], [64098359, 1970395, 644076, 511316], [-5710780, 1227856, -763854, -649888], [71875077, -834340, 198049, -585586], [-82917150, 473454, 1471438, -403970], [22270524, -1036208, 556020, 866656], [35719632, -40949, 1216739, 649407], [-112156382, 586590, 267058, 189666], [2218386, 1121516, 880908, 726156], [6466308, 597247, 812481, 570518], [36893232, -2053321, 21011, 539903], [128081235, -436124, -321097, 258674], [-1433114, 1254692, -1311242, 128642], [82369336, 1180081, 265497, -489234], [113151882, 1002586, -622988, 374484], [69688752, 1615465, 48253, -482507], [12829088, 666964, -1188450, -969550], [102696045, -999561, 51700, -689584], [53296288, -1721878, 884738, 851310], [131600700, 443848, -50334, -242428], [51363653, -235299, -1140310, 836780], [-3450844, 925181, 548075, -563250], [-116577480, 686904, 620182, -424792], [-9080454, -1955993, -1050801, 220286], [-170445372, 112507, 384765, -385937], [117005507, -252919, -207464, -1545896], [61405055, 581200, 659799, -1109824], [-7668882, -1334220, -135800, 782606], [55596396, 717568, 513168, 100148], [-116179532, 116950, -883242, 260598], [-120923414, 676284, -95736, 875794], [-23198619, 886695, 614988, 167388], [225108505, 1121402, 264375, -147082], [24041616, 379173, 575629, 355325], [-17464999, -506045, 765278, 1305414], [70413804, -1021079, 29599, 871605], [30486208, 858284, -162728, -373852], [-176971262, -675033, -197207, 229752], [53178390, -3046758, 76392, -435078], [-196414924, -772537, -659523, -47807], [106655700, 1559427, 845171, -904025], [-42224575, -193851, -451998, -390308], [4058133, -1468734, -610463, -509896], [77303984, 1142674, 1525342, 103486], [129234576, -1295418, -179798, 354416], [-140612364, 363098, -514172, -323614], [177477888, 622868, 1804872, 771940], [-188151260, -399469, 792447, -408525], [-76568412, 733410, 119644, -794906], [-78304382, 1527700, 1077780, -848144], [48476819, 52287, -598356, -1015320], [140583894, -1668778, 324262, -1005196], [17420286, 460154, 1418362, 958494], [-24098292, -55844, -307088, -162294], [11978235, -1965774, 1187335, 955844], [104778764, -252818, 1554748, 678652], [204547563, 502343, -578404, 156448], [-241853280, -793520, 1353652, 344400], [-94661760, 3128554, 330978, -655894], [205067183, -15501, 697086, -777116], [318974162, -331360, -496032, -370106], [-48698210, -482124, 949584, 283406], [-86764200, 1373594, 440658, 2074242], [1533156, -315750, -2095362, -671136], [223458843, -217319, 1541762, 892250], [-90392568, -3051501, -519513, -219483], [-122990072, 698595, 99143, -524410], [-43471653, -1099172, -1248111, 1495508], [-112820500, -3300279, -696801, 374481], [274208547, -175660, 1455615, 634890], [157372484, -2539257, 643885, 322793], [-12013767, -2387282, -1813907, 587248], [-18909530, -1428180, 987188, -1308552], [179278715, 567256, -1531733, 1079044], [75996489, 1378935, -1213188, 635544], [290003448, 1439732, -1739232, 80416], [-105026496, -858903, -801221, -1003229], [74956326, -2032790, 1630920, 960772], [-53758856, -2814496, 563244, 946302], [-11624335, -984015, 347382, -436592], [201375996, 1463880, 1126032, -520612], [142742636, 1964287, 90941, -580887], [-163766404, 1097582, 1172284, -1275554], [111299679, -873490, 1084297, 451946], [6551020, -557295, -176291, 903018], [-225455700, -1242806, 1199024, -909582], [-124692366, 1061144, 649866, -462572], [24835926, 695929, 1701209, 1988778], [6072728, 1146172, 15126, -1858464], [130943368, 1093525, -31971, -2578955], [10372788, 2889967, 1910235, -1734992], [-127900368, -282888, 790118, -1515872], [-42195516, -832310, -502558, -57450], [-207835354, 2091093, -337431, 343768], [-87836284, -3057160, -566016, -1579724], [55102866, 3700228, -501892, 668138], [70609694, 705512, 409160, -427632], [-139464917, 1043138, -1266439, 1436814], [112724486, 3084688, 2161744, 1183786], [-278944032, 2145165, -1347695, -638881], [1165590, 2101640, -23674, 237346], [-1045440, -1584738, -2088326, 887018], [231975463, 1432851, -2212558, -244896], [109863105, -870462, 391703, -170256], [-178668486, -3058722, -1133270, -1016198], [-89415092, 2387074, 674790, -460820], [112875652, -1100078, 2199018, 762208], [117657206, 1191450, 816398, 2037682], [307664533, -1889854, 211929, 1254516], [43169772, 1296981, -2697645, -335119], [-247542369, 1318515, -653866, -990644], [-213862761, -887470, 1891055, 2647436], [-125643118, -2821052, 2014886, 1263564], [-55664454, -338874, -2434338, -1381782], [42944063, -1264887, 1129366, 238664], [-27342752, 2714640, -2447384, -525164], [163146122, -2267718, -1391116, 1296502], [-515834546, -1924258, -1241350, -376512], [27715893, -630079, 1698516, 1176012], [217324140, 1217938, 118330, -2836748], [192978492, -29190, -2177436, 277718], [-129173592, -2018864, -1247622, 46388], [170577052, 1690797, 2079073, -1429463], [212841122, 3247856, 1717594, -280098], [-73258268, 3539798, 1631478, 170268], [-161962640, -5287392, -3776406, 167530], [-119158193, 3134858, 2588317, 155212], [43306109, 2858862, 986949, 2242948], [-84658711, -2801243, 1795500, 547658], [99864690, -16900, 421680, -786044], [-291244182, -1492818, 2306050, -159962], [103792872, 338756, 3431458, 517812], [-170742637, -1348250, -3038467, -320190], [36576055, 3382854, -2404993, 236448], [222345202, -5004262, 131630, -983882], [-88051632, 665072, -2121784, -2256926], [43956742, -4812311, 87151, -1375846], [-59465188, -2410254, 1634380, -1615734], [178207307, -4974835, -1165730, -176826], [26958908, -3943411, 3604493, 496779], [-33180896, -1828557, -769083, 77161], [81767010, -4564344, -1221884, 1706432], [265325376, -2487633, 1396961, 1990300], [-367120285, 1770487, 1090388, 1120470], [110692968, -1137850, -1247940, -65442], [32906792, 1235308, -2332150, -2697098], [374261332, 1880609, 361973, 1098337], [-247585018, -1631712, 3670046, -1867442], [-145249475, -568066, 2334685, 566408], [41654130, 1330266, 1726840, -2474872], [-480759737, -2203433, -320950, -1415596], [-333975816, -955675, 1219657, 133844], [446453268, 1793308, 3449728, 1724164], [-297884884, 3505265, -692723, 1718953], [-104238126, 1090336, -539216, -578844], [73264014, 5692294, 1730722, 673120], [-252882706, -2102395, 2519673, 2756660], [-144992982, 846272, 1810300, -863664], [1378114, 4589334, -837152, -762216], [-45654468, 1195675, 611087, 1252407]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_414_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_414_6_a_o();".
// 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_414_6_a_o(:prec:=4)
    chi := MakeCharacter_414_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_414_6_a_o();".
// 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_414_6_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_414_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-9068808, -613004, -9218, 54, 1]>],Snew);
    return Vf;
end function;