
// Make newform 43.6.a.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_43_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_43_6_a_b();".
// 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_43_6_a_b();".
// 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 := [-22734604, -5752252, 8437093, 384582, -719484, -10450, 21986, 266, -256, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [-40045363612, -996337120808, 224666692021, 59540816201, -14422814397, -1005840413, 239748231, 3451179, -1188163, 18033], [-192111505364, 762684015384, 64822510771, -20833059243, -6546797939, -397671097, 116173337, 7832247, -594245, -24107], [-912070606876, -418161182816, 287212616929, 54235511681, -15768164889, -2591602757, 213763899, 35600547, -820999, -144543], [2423789997252, 1590463778000, -937883085431, -220849424171, 39727817087, 8979038055, -421392509, -116809809, 1144977, 474917], [-5839603776708, -1656152504528, 1003571811959, 220849424171, -39727817087, -8979038055, 421392509, 116809809, -1144977, -474917], [-7896805510540, 768287694064, 1606414562725, -180644132719, -78913681917, 9333970747, 1407118071, -155012637, -7898035, 808641], [-30463422181444, -17120027667600, 5229545463959, 2673777652347, -189530468575, -100861721975, 1411070749, 1269871233, 307343, -5132245], [-18517909728476, -11776641778800, 3165045014041, 1432035207537, -122440956545, -50464104709, 1209002243, 612520467, -2695583, -2389487]];
    Rf_basisdens := [1, 1, 24633272448, 24633272448, 24633272448, 65688726528, 65688726528, 98533089792, 197066179584, 49266544896];
    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_43_a();"
function MakeCharacter_43_a()
    N := 43;
    order := 1;
    char_gens := [3];
    v := [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_43_a_Hecke(Kf)
    return MakeCharacter_43_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 := [[1, -1, 0, 0, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 1, 0, 0, 0], [13, 1, 0, 1, 0, -1, -1, -1, -1, 1], [8, -4, 2, 1, 0, -1, 1, 1, 0, -1], [66, 16, -3, 3, 5, -4, -11, -3, -5, 2], [192, 12, 1, 3, 5, 0, -11, -3, 7, 6], [402, 55, 8, -4, 7, 8, 25, -4, 4, -8], [-241, -15, -16, -4, 20, -10, 10, -4, 13, -8], [214, -44, 28, -17, 17, 25, 23, 13, 29, -13], [749, -2, -36, 18, -20, 102, 47, -10, 18, -36], [-500, -89, 50, -6, 27, -16, -87, -14, -56, -2], [-87, 286, -42, 51, 30, -127, -280, -141, -168, 63], [1037, 375, 93, 85, 37, -4, -251, 67, 110, 76], [1849, 0, 0, 0, 0, 0, 0, 0, 0, 0], [4628, 31, -251, -149, -82, -48, -106, 45, -15, -68], [12425, -263, -146, -273, -101, -7, -341, 63, -186, -95], [10469, -825, 407, -28, -310, -125, 1032, 186, 185, -315], [2554, -2926, -66, 237, 264, 139, -5, 45, 126, -213], [-954, -682, -713, -333, -477, -542, -9, 317, -505, 416], [1374, 500, 168, 278, 482, 90, 392, 46, -70, 46], [5706, -518, -318, 129, 312, 1115, 551, 141, 186, 135], [-9232, 224, 183, -648, 328, 73, 1250, 8, -242, 29], [-9905, 757, 538, -87, 299, -9, 1701, 117, 542, -853], [-7070, 482, -366, 393, 230, -1305, -1601, -659, 324, 579], [10134, -1604, -448, -157, -1075, 13, -771, -529, -1145, -605], [57671, -437, -644, -1397, -609, 1659, 595, 1235, -288, -53], [-4169, 3129, 899, 1067, 1309, -4, -2043, -1341, -210, 1460], [10013, -5797, -645, -1286, 362, -627, -1302, 700, -1031, -841], [-24218, 6452, 1379, -257, 689, -1630, 3459, 593, 1103, -84], [38640, 6012, -1566, 1154, 1038, 716, -3656, 446, -714, 360], [-35473, 16904, 1715, 1168, -2241, 467, -269, -470, 1137, -637], [-6113, -8112, 2922, 803, -1546, -1067, -4504, -25, -278, 617], [14984, -1570, 196, -118, 3484, -894, 1166, 730, 1522, 1170], [-31185, -7179, -408, -2281, -617, 5399, -2569, 2387, 2102, -1877], [13797, -22524, -3944, -1271, 622, -1551, 7560, 2509, 2502, 1351], [-215278, -13042, -2748, 497, 1456, -2871, 3357, -811, 74, -1019], [109511, -167, 624, 502, 662, 6072, -1938, -488, 373, 2438], [-107303, 16937, -1250, 1673, -680, -1011, -14119, -4187, -4463, -1257], [6333, -8825, -2034, 3013, -677, 2211, -6899, -4891, -1196, -1033], [153878, 15082, 3546, -426, -2748, 6480, 3144, 5466, 4638, -4896], [6537, -17743, 8224, 4569, -2510, 471, -1727, -1223, -985, 1325], [79727, -989, 3297, 1610, 1802, 2695, 5450, -896, -2583, -1131], [-103980, 3280, 3018, -4566, -1280, 1064, 19898, 2782, 6664, -2416], [157214, 19404, 1776, 6621, -1575, -3801, -1305, 33, -3621, 4629], [317253, 43887, -2355, 2610, 3178, -3021, 4004, -5704, 1221, -363], [134480, -14532, -6564, -4930, -4026, 5198, -9350, 7374, -3530, 422], [-100579, 35474, -1854, -2577, -3824, 5329, -16252, 491, -3014, -1651], [-155752, 41536, 6918, 2819, 7640, -1235, -1957, -3029, 5916, 753], [-93637, -34815, -10904, -5016, -11482, -7794, -8298, 5592, -16981, 4388], [247684, 17224, -9241, -6861, 5271, -4834, -1863, 8785, 2713, -1748], [19488, 10516, 5440, 2488, 4004, 10592, 10946, 9248, 12256, -2628], [40212, -17324, 9025, -5368, 2112, 12855, 37974, 12248, 12814, -17133], [110714, 6110, -4468, 6588, -3810, 5752, 4826, -5456, 5908, -6644], [-284734, 37098, 13637, 9403, -5721, -6276, 531, -2123, -10141, 9018], [215922, 34524, -6900, -8937, 11670, -7233, 21663, 2487, 6654, -405], [-145532, -28106, 538, -854, -9994, -8192, 40592, 7714, -5452, -5116], [367466, -60846, -2489, -6711, 5157, -1140, -22525, -10285, -14359, -3298], [-30297, -74439, -5301, -9469, -14657, 10688, 43073, 6983, -5464, -7772], [116349, 31433, -6926, -13333, -16716, -4737, 42949, 17249, 39, -4271], [232585, 39806, 17755, 688, 3175, 32139, 18603, -194, 13503, -7211], [-3537, 35651, 9760, -22151, 5229, -3439, -7285, 10457, 18298, -6603], [365083, -99903, 1481, 1264, -20622, 12049, -3834, -6562, -6233, -617], [-344577, -70723, 17440, 15217, 10569, -5947, 11909, -10411, 25876, -7995], [-305058, 120016, 6013, 8321, -17871, -30990, 19563, -385, -1445, 21768], [-78406, -88826, 6960, 9733, -4360, -8799, -11529, -13583, -3542, 1841], [-175598, -52856, 12961, 9707, -11961, -2476, -8325, -5243, -1447, 3758], [-1257466, -58944, -12018, -24013, -19566, 21257, 38857, 4959, 16870, -9691], [-158085, 64070, -5735, 15756, 12861, -13043, -31899, -17458, 473, 395], [-515925, 67831, 3468, 1777, 16630, 32535, -65915, -8023, -16607, 23681], [342551, -22708, -24366, 19778, 15148, -14892, -89121, -27886, 4640, 28222], [-328910, -166974, -535, -15159, -9353, 2310, -55905, -3849, -17081, 292], [72662, 130309, 25268, -10546, -15973, -25746, 41829, 9410, 28014, -17752], [122630, 169795, -15303, 10187, -6262, -16916, -42580, -37619, -22863, 1332], [296857, 5203, 20918, 11634, -18612, -15106, 6210, -5276, -29699, 27940], [-1389884, -20534, 6273, -31431, 11581, 13826, 27855, 28223, 12553, -1504], [-545996, 174472, -33100, 4390, 13988, -40782, -3290, -12898, 10196, 31422], [73562, -142144, -628, 23496, 6828, -24156, 27520, -48692, 16480, 35944], [420713, 191229, -46849, 19564, 13754, -31865, 70940, -7174, -21121, -12339], [704307, 247488, -37357, -13204, 9941, 33591, 56931, -22198, 13251, -3079], [-529374, 124282, 8062, 26871, 9862, -30847, 11057, 14203, 5964, -4967], [1938054, 45452, -17928, -33315, -7700, -10163, 9479, 41373, 20216, -16211], [1464659, 326161, -41244, -37306, -1186, -40748, 118706, 10408, -19755, 28074], [1242853, 126510, 24395, 44896, 28185, 5587, -26361, -10558, 5845, 12379], [-2633606, 30248, -34952, 7817, -12002, -9411, 72521, 5917, -23474, 11229], [1382858, 208335, 25588, -25864, -55439, -39496, 17077, 2548, -35006, -8730], [1836803, 92857, -3321, 44524, -4898, -46145, 24100, -23670, -35241, 49125], [348906, -22796, -7406, -17947, 4140, 48267, 78237, 5561, 17344, -40389], [-328100, -384026, -21424, 17571, 5616, 4967, -24441, -27977, 49930, 12499], [-1108359, -183787, 19483, 7934, 17618, -55459, 190810, 9188, 9263, 16823], [-183356, -279340, -42748, 49549, 4196, -11551, -12243, -27619, -21160, -4455], [2421283, -37888, 11396, 34637, 53760, 27633, -15106, -26387, 7272, -607], [1344218, 71240, -45482, -179, -36021, -1279, -82523, -22337, -121337, 79527], [1020451, -444145, 41220, -20282, -66018, -2392, 27210, 47256, 35, -58718], [957769, 191241, -43608, 43435, 53700, -45675, -181897, -29565, 10861, 41495], [1744387, -231034, -55732, -1574, 15542, -72010, -21267, 19010, 25880, 36366], [-615702, 218582, -14636, -69432, 1162, 91044, 71620, 58228, 33104, -17848], [3029587, 338515, 57322, 5445, -863, 46515, 21385, -623, 24158, -26161], [-841734, 139822, 65700, -4481, 98356, -51969, 8845, 5039, 62098, -57877], [-2474363, 64044, 12914, 15116, 2590, 91190, -85137, -6312, -10434, -46630], [111003, -430341, -36188, -35803, -64399, 21017, 55757, 71229, -16162, -37987], [-46477, -285045, 97768, 34955, -32909, -20473, 184489, -72389, 16324, 49611], [-141542, 113504, -42403, -22399, -85325, 28902, 61033, 126171, -48195, -24448], [2279728, 232982, -32887, 128719, 101059, -97036, -243031, -86827, -13161, 45278], [483429, 396649, -10184, 49173, 79407, 26845, 67253, 13329, 12058, 77781], [-2071509, -476246, 74182, 43744, 61348, 12798, -65345, -17612, 63998, -2830], [-2366424, -311598, 76604, -15923, 20574, -6263, -161139, -22511, -22368, 41249], [1737412, -199292, 9618, -10580, -3934, 7838, 105816, -26064, -107590, -16814], [1973346, 659324, 26466, 68175, -112774, -249167, -179249, -66865, -35698, 55585], [798375, 703822, -94933, 52882, -41635, -93059, -374981, -89556, -113447, 65497], [3470320, 160082, 75582, -81894, -126930, 44188, 263110, 23610, 42960, -76932], [1671266, 14102, -202350, -24040, 556, -51654, -120492, 145844, -15526, 25690], [-2613957, 208921, 73021, 126, 102838, 160547, 49688, 61288, 202647, -149219], [2695582, -510552, 70354, 110045, 14849, 6621, 208591, -41019, 38671, -4101], [4748512, 526724, 16820, -119540, -108928, -520, 79668, 63980, -69388, -61200], [-775582, 581450, -65908, 102568, 31194, -36916, -16508, -105260, -8772, -11020], [-2117482, -614816, -33400, 40161, -49646, 2005, -179943, -144923, -74094, 81305], [-3223319, 326643, -60721, -84844, 58342, -188821, -1164, 17430, 53757, 55073], [-2368600, 1098772, -88854, -74530, -83736, 124580, 100306, 49142, -75840, 1392], [-385743, -119213, 117206, 66132, 163470, 250860, -147464, -8534, 106039, -26714], [761086, -1457394, 92967, -19587, -31941, -8380, 96417, 52775, 103759, 54674], [-702467, 117811, -65220, -26965, -6725, 145075, -79475, 38315, 32660, 1195], [-3702388, -166750, -2334, -132703, -9044, 78099, 69009, 182273, 82610, -50981], [3838237, -1786049, -19804, -26976, 27830, -67630, -27400, -37226, -5377, -27660], [-3541334, -776350, -34923, -40359, -36679, 64950, -343379, -101285, -73023, 51624], [1956750, -1054456, -58736, -105393, -102768, 274999, 164829, 174887, 113504, -207409], [2687137, 135093, 23681, 64278, 230602, -96609, -329178, -126612, -70637, -40679], [-2456590, 667416, -58365, 103909, 194181, -62384, -62899, -158601, -33673, 164302], [-280985, -519772, -75764, -193703, -254168, 135297, 290196, 114409, 4488, -119357], [37258, -154838, 73872, 65480, 86260, -74012, -186704, -13240, -141970, 26056], [7905421, 35584, 163292, 14379, 37290, 174095, 87174, 92143, 256102, -153371], [-3796111, 219302, 8822, 119571, -45228, -242255, -225544, -268361, -272582, 207565], [-2725460, -163976, -10950, -63386, -7932, 269180, 7178, 113534, 68552, -41984], [4957160, 1453606, 20532, 51277, 7370, -181143, 405051, 91165, -61652, 40565], [8803613, -30166, -29822, -82877, -61438, -122971, -181088, -102117, -240, 39235], [279052, 1030440, 250578, 71194, 193614, -110844, -95056, -45174, 95590, 116840], [-38232, -1044887, 177395, -11017, -170644, -47654, -299196, -62407, -123275, -112268], [7127147, 279008, 106568, 22848, 162786, 79656, 731893, -4076, 170230, -175586], [723401, 645635, 16443, 124380, -110822, 154519, 231920, 49034, 92653, -115735], [5599475, -814755, -169695, 57236, 82638, 179205, 140050, 37362, 84335, 99511], [-11134406, 278569, 19791, 185411, -10484, -58470, -235050, -81763, -38395, 30892], [2258593, 631389, -16570, 238613, 238252, -156511, -391407, -307863, -229359, 241067], [8830924, -1037788, 60711, 98757, -107709, 138984, 44931, 31227, -91863, -23190], [-971648, -688858, 153463, 103389, 231733, -142304, 53671, 44551, 217197, 66466], [583776, -1144682, -264428, -301470, -259572, -1790, -348616, -12258, -115898, -110742], [-2395145, -369734, 5706, -365235, -173726, 124991, 155220, 289373, 62200, -165247], [-10052778, 1099252, -340438, -29611, 236400, 91715, -275965, -54771, -68216, 163615], [5933829, 515249, 168670, -13339, -230457, 12687, 1081513, 204317, 191154, -220085], [2755913, -556283, -83362, -321440, -32322, 398576, 179154, 180636, 6255, -120742], [5427325, -49273, -90592, 52084, -43714, -82978, -92274, 63860, -1759, 221760], [-6104608, 1243502, -86004, -34804, -278042, -316160, -181266, -193968, -173252, 234152], [5181279, -799829, 108650, 114317, 255257, 70123, -136059, -81379, 363994, -15977], [928725, 1140808, -108977, -50620, -47447, -116973, -4231, -50510, 148759, 148293], [-4520130, -213096, -105439, -5511, -337611, -16578, 498115, 207403, -86909, 93640], [-12342852, -302304, -34986, 43422, 37986, -206220, -1311066, -262914, -119622, 143988], [-1246641, 1430235, 21000, -289993, -174257, 300035, 159689, 514331, -13348, -48761], [-2861008, 1468534, 37126, -130493, -35506, -229155, -437647, 203235, 153156, 14005], [-6941411, -1542678, 65951, -106642, -113723, 30485, 10977, 91200, -7083, 13229], [-14573764, 519386, -202402, -30090, 156328, -72300, -104682, 197046, -39890, -44828], [-5996194, 1131770, -99426, -156683, 155494, 488303, 626035, 28865, 139332, -141993], [7825278, -101390, 27275, 421755, 47363, -241050, -1026607, -275311, -45665, 164536], [-3910187, 574753, 353926, 73725, -187125, 160071, 580763, 102857, -24094, -363169], [6236972, -1004184, -383248, -403925, -171540, -131613, 628197, 172543, -10024, -241281], [3651125, -679957, 324747, 168161, 7021, -231426, 133455, -362707, -229828, 141538], [-8199338, 1323396, 247911, 87159, 157053, -446242, -560427, 67709, 89215, -70084], [6784670, -315801, 19489, 103293, -34588, -189642, 36342, 228963, -262117, 2636], [1737486, -594992, -147726, -445547, 171088, 366939, 743719, 319409, 369016, -229945], [6869594, 1267446, -146082, -133373, -174858, -22187, 323483, -253041, -304432, 116305], [-6546867, 1919846, 137242, 56210, 178326, -177084, -543257, -231070, 36600, 138262]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_43_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_43_6_a_b();".
// 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_43_6_a_b(:prec:=10)
    chi := MakeCharacter_43_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(997) - 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_43_6_a_b();".
// 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_43_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_43_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-20373120, -9477216, 5497616, 2163208, -450596, -112716, 16722, 1734, -229, -8, 1]>],Snew);
    return Vf;
end function;