
// Make newform 40.6.d.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_40_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_40_d_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_40_6_d_a();".
// 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_40_6_d_a();".
// 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 := [1099511627776, -137438953472, -73014444032, 20937965568, 4244635648, -926941184, 157024256, 79364096, -27930624, -1538048, 3580672, -96128, -109104, 19376, 2396, -884, 253, 78, -17, -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, 0, 0, 0, 0, 0, 0, 0, 0, 0], [11464324274978816, -297081277251584, -1192022035660800, -64235463770112, 53728355287040, 2583188733952, -1373389299712, 906022600704, -144808361472, -144586364416, 17963145184, 6542957136, -1059006312, -167940308, 17579546, -12508553, -3396972, 1230021, 62912, -67985], [38936417104430104576, 3379581800966782976, -2314359262031118336, 19270179452092416, 210707338900799488, 7314399222824960, 4761986870738944, 2858199953264640, -308378042677248, -209376218715392, 66989955357824, 16148446793808, -719687080656, -24303499972, 69605863660, -17200470427, 2347892670, 2750967783, 164467438, -79348087], [-36731983023308800, -1060268511592448, 1987318143516672, -115722776739840, -112168045379584, 4644870553600, -6629241389056, -2011089383424, 496420435968, 124686277376, -49422810752, -5713941552, 437239152, -129135524, 2524124, 21259597, -2345826, -952929, -37138, 36529], [177034869779757793280, -26666393143378706432, -13317643676248178688, 1657402226575933440, 285378387308969984, -11302647475994624, 38744507211677696, 3880844619042816, -6297386944217088, 83264729637632, 414570538595584, -13959106014192, -2795569027632, 1739742865996, -718292536252, -72698446823, 45014733006, 8955951363, -2347107250, -97985891], [-1550266383906897920, 275660321136312320, 180832148914176000, -6061205571502080, -7838825908797440, 1926810069893120, -50248724971520, -93706914631680, 82271702046720, 12397823115520, -4828965765760, -50299499280, 236780073360, 4737874100, 2106440260, 3862360175, -266710470, -153706635, 30164170, 6673115], [33390654176765149184, 15111222022950092800, -2032038956299714560, -282744569160794112, 191585425528193024, 31120845131481088, 458283032969216, 5578982574280704, 58866098325504, -381936366044416, 31872784133248, 25433106255696, -570023436240, 71837847676, 104897574572, -40339659563, -5689165602, 3743303607, 35235854, -69160775], [15000465339056128, 23971157371781120, 38568090132283392, 1241058499362816, 64149778333696, 314856479916032, 79128649990144, 25859031429120, 9296654579712, 2708453376256, -227096981632, 18788644848, 46845209616, 7316097524, 2131216804, 264714623, 6591738, -3689307, 2680522, 2121323], [183124395323945910272, 23419227737505660928, -1899663293065199616, -3505658856896200704, 1798632542207737856, -27352748135284736, -43553585263083520, 26730765666349056, -1648804311975936, -1949627409612544, 419549708390272, 137433907436016, -23360926939632, -5081228940428, 1467708071972, -311157762785, -28897641030, 22547436165, -1541606518, -1652193653], [46519200282337869824, -9585649942702063616, -4201827059883835392, 494759853466583040, 93131896266948608, -51318721181646848, 3665853378265088, 437212383965184, -1876370651080704, -238768006227712, 108433773083008, -6791259700368, -5669980042992, -110745422444, -85483833820, -58787611817, 2536434474, 2082932205, -782315974, -191297309], [77184783368618770432, 33898917718208282624, 9628539359821037568, -1168261401563627520, -150813533844537344, 148465276505292800, 41076144459907072, 11740860134240256, 3892854667689984, -162276836741888, -142981561273600, 35738566645488, 20864739367728, 1752375279092, 377520776188, 39588349847, -20184358830, 3207553677, 2811987922, 242971859], [587303771969482129408, 104802983984683286528, -56531194469582635008, -2614384754480381952, 2867221596643262464, 129403849000878080, -42847034255802368, 46265140049080320, -6949161965266944, -6642921415851776, 948236705727872, 320632357239024, -46213723821168, -7059227312716, 940126704580, -571957216081, -134270357190, 59421776949, 3110541514, -3066220261], [93662911967977799680, 2627948754501632000, -10469340056559550464, -1882563927456350208, 733271696324165632, -14829055780323328, -32689349068783616, 2439478277935104, -3933233687967744, -1915645378459904, 223123539658880, 62227502417808, -19050811187856, -3574170330196, -25085087684, -231772749511, -23374232682, 12218919363, -721259066, -1100290003], [620142114173983129600, 62591819346876563456, -39732701074896715776, 122314952508702720, 2185607719501692928, -74790839713005568, 36167708893315072, 69682632365125632, -6972745424111616, -4205227830653696, 967750251636608, 191782756727856, -20243528374704, 3652922233892, 1537773146356, -524496762781, -17357641998, 47847494961, 757890370, -1149574177], [-606461036125101228032, -31709836695618715648, 24897738341168971776, -3766338582151692288, -1710305209625870336, -482615504156753920, -84546880885293056, -30601039758594048, 6429888600324096, 1621979202386176, -1001559295189120, -150554252170128, 8925259005072, 1610896355156, 371256988996, 102019001735, -35922205590, -38128546179, 1748073274, 1378084499], [242829437331499384832, -30505133227045289984, -37552806709791031296, -2464278133868593152, 1028656954785923072, -21435013297602560, -22367264744734720, -1779445647249408, -10263922788108288, -3745521356023552, 805549508612992, 163217146923120, -32492244466800, -6230330395052, -431598392188, -442322344697, -7553046486, 34407860733, 397290362, -2613608813], [794041402225567203328, -32398542020156588032, -74567918626554249216, -3927365040746790912, 2093694875525447680, -3593514379902976, 50459561438150656, 26278680292651008, -24535050131245056, -6097421383894784, 1091725509280640, 200684140345968, -40791194023536, -6720187802668, -1037579128316, -828211435225, -5901549846, 57278130525, -1743424454, -2626005709], [-1255325012022498689024, 65785216987031404544, 64430477724943908864, -11020745276318023680, -1426642452441202688, 65992036296949760, -314493543457292288, -55675128487735296, 24671853793634304, 3443007790849792, -2028801123217792, -126022076786928, 6658243946352, -8296989691828, 1504396565116, 704230722833, -119712276474, -67876189173, -750933770, 2753749541], [-2297213194579040272384, -362805856335552315392, 175906584071195590656, 2512921342714576896, -9744803736730992640, -350263662661074944, -506020226235301888, -187724555019251712, 39120500097189888, 14777299412748032, -3845777127261056, -875554655592048, 78937971524208, -14791748101844, 488403661052, 2039605194649, -161753870442, -167461819677, -6606216634, 6092522125], [-539728464311666868224, -6938996296388706304, 83375240244294057984, 9956219996835151872, -4209641071912681472, -86318799004106752, 129719095658217472, -14803926030987264, 15553269216233472, 8273579040324352, -1060312386677632, -338152442675376, 73027906008624, 15987573176444, -733051948244, 970185399893, 63571279710, -58020083145, 2761897870, 4725901625]];
    Rf_basisdens := [1, 1286331967733760, 713485464769658880, 321582991933440, 535114098577244160, 32930098373984256, 164650491869921280, 3430218580623360, 2140456394308976640, 237828488256552960, 178371366192414720, 2140456394308976640, 713485464769658880, 713485464769658880, 713485464769658880, 1070228197154488320, 1070228197154488320, 1070228197154488320, 2140456394308976640, 1070228197154488320];
    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_40_d();"
function MakeCharacter_40_d()
    N := 40;
    order := 2;
    char_gens := [31, 21, 17];
    v := [2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_40_d_Hecke();"
function MakeCharacter_40_d_Hecke(Kf)
    N := 40;
    order := 2;
    char_gens := [31, 21, 17];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := [[0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-10, -4, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [4, 22, 1, -4, 0, 3, 0, -2, 0, 1, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0], [-1, -15, -8, 2, 0, -1, -1, 2, -1, -1, 0, 0, 1, 1, -1, 1, 0, 1, -1, 0], [-1, -32, -2, -1, -1, 1, -1, -3, 1, 1, -1, 0, -2, -1, -1, 0, -3, -1, 0, -2], [-8, -30, 3, 10, 2, -13, 0, 4, -2, 1, 0, -1, 2, -2, 2, 2, -2, 1, 0, 0], [-227, 50, 0, 9, 9, -3, -3, 10, -6, -3, -1, 13, 3, 2, 1, -7, -3, 0, 1, -2], [16, 72, -54, -33, 5, 8, -2, 3, -7, -16, -4, 10, 19, -7, -1, -5, -1, -8, 10, 0], [374, -94, -4, -4, -4, 8, 12, -10, 0, 0, 10, 8, -22, 2, -6, 16, -2, 10, 0, -2], [18, 116, -20, -12, 0, 4, 22, -14, 8, -6, -14, 26, -8, -14, 8, -8, 0, 0, -6, 0], [565, 352, 16, 32, 9, 49, 49, -1, -15, 65, 0, -48, -16, -8, -8, 24, 8, 0, 0, 8], [-35, 80, 159, 85, -3, 65, 17, 10, 3, -43, -9, -19, -3, 34, 5, -3, -5, 6, -17, 0], [2168, -198, 40, 130, -8, -80, -56, 14, 3, -64, 4, 40, 18, 12, 4, -24, 12, 12, 8, 6], [-45, -489, -280, 44, -34, 27, 3, -26, 35, 91, 22, 34, -59, -17, -9, -11, 10, -5, -25, 0], [-118, -502, -225, -4, 4, 145, 42, 16, 28, -17, -10, -27, -28, 2, 36, -28, -4, -23, 22, 0], [248, 1426, -136, -26, 26, 58, -16, -48, 4, -48, -26, 26, -76, 6, -16, 68, 46, 6, 4, 0], [131, -496, -409, -537, -9, -161, 39, -78, 65, 75, -23, -69, -113, 2, 7, -17, 49, 58, 25, 0], [-9932, -410, 8, -88, 58, -22, 98, -42, 18, -134, 90, -38, -60, 0, -2, 66, 78, 76, -14, 30], [-5035, 32, -138, -423, -127, -45, -7, -19, 99, -221, 65, -118, -176, -41, -11, 98, 11, 27, -38, 62], [14568, 2194, -196, -650, 50, -10, -6, 214, -48, -210, 20, 6, 24, -18, 48, -42, -4, -22, -42, 6], [189, 3828, 979, 201, 65, 87, 97, -62, -65, -377, -89, 155, 257, -50, 73, -127, -73, -184, 95, 0], [228, -712, -356, -790, 178, 142, 26, 138, -50, -98, -6, 332, -104, 38, 58, -108, -138, -42, -36, 52], [6661, -1488, 578, 1723, 13, -253, -107, -131, -205, 179, -13, 62, 176, 53, -81, -26, 81, 97, 110, -134], [-808, -3304, 1322, 575, 101, -156, 22, 459, -167, -376, -44, -62, 371, 49, 79, -37, -145, -72, 50, 0], [-22787, -1110, -232, -843, -215, 197, -83, -30, -222, 245, -141, -51, 195, 6, 69, -39, -71, -172, -31, -18], [550, -48, 1407, -886, -30, -10, -218, -112, -90, 318, 82, 118, 138, -152, -166, 42, 46, 92, 26, 0], [658, 10142, 96, 1084, -80, 1048, 146, -612, 50, 34, 32, -192, -50, 174, 98, -50, -128, 94, -206, 0], [-13852, 2400, -488, -1548, -2, -74, -146, 330, -42, -490, 84, 520, 160, 92, 84, -72, -116, 28, -56, -248], [-17017, 3872, 1392, 3723, -75, -567, 89, 16, -308, 169, 139, -807, -23, -62, -187, 245, 545, 296, 157, 212], [502, 6766, -109, -88, -40, -1185, 462, -532, 152, -239, -206, 571, 136, -326, 216, -440, -104, -305, 50, 0], [-31154, 5344, 1104, 3894, -100, -60, 292, 22, 724, 692, 222, 170, -790, 164, -318, 466, 178, 440, 218, 328], [-1938, -10238, -871, 1310, 26, 2795, 506, 326, 454, 445, -58, 311, -838, -452, 474, -70, 6, -345, 70, 0], [558, 14068, 904, 2818, 146, -1336, -314, -156, -246, -538, 174, 82, 270, 120, 6, 222, -106, -520, 138, 0], [98764, -9364, 68, -274, 624, 500, 304, -672, 686, 764, -262, 36, 700, 118, 290, -436, 206, -266, -4, 344], [-1022, -12526, -12, 1118, -106, -3380, -322, 410, 404, 1186, 292, 152, -1484, -172, -136, 676, 434, 26, -162, 0], [2382, 24752, 895, 1706, -414, -4878, 286, -2552, 862, 2162, 466, -374, -1822, -224, 338, 98, 110, 144, -350, 0], [91369, -8482, 1128, 3357, 373, 753, 969, -1378, 372, 1665, 47, -551, -237, -42, -359, 501, 141, 236, 189, -198], [-3078, -18548, 8628, 1552, -60, 2536, 598, 1406, 4, -1150, -382, 290, 332, 350, 156, -340, -212, -40, -374, 0], [-4374, -42910, -8251, 190, 530, -8125, -562, 3314, -530, -403, -142, -433, -46, 176, -174, 1106, 174, 587, -14, 0], [-858, -16966, -12646, -845, -107, -1442, 228, 207, 679, 1366, -60, 466, -1819, -525, 61, 461, 511, 282, -224, 0], [-167578, 3980, 344, 1658, -402, -898, -1498, 1572, -1968, 46, -530, 1614, 1002, 480, 282, -954, -246, -316, 214, 60], [157491, 40848, 682, 1031, -65, 1885, 1399, 1603, -307, 3053, -417, -1962, 272, -295, -197, 622, 197, -379, 38, -14], [1931, 5357, 724, -3980, -386, 4251, -337, -1100, -199, 955, 320, -460, 1039, 11, -403, -641, -182, 525, 7, 0], [119702, 40662, -24, -462, -256, -216, -384, 2854, 578, -72, 52, 1208, 594, 444, 164, -120, 60, 124, 72, -186], [3660, 30998, 3883, -1322, 582, -12079, -644, -776, -582, -1565, -44, -1227, 774, 718, -106, 390, 106, -177, 836, 0], [23787, -83708, 96, 803, 1153, 1557, 2037, -6452, 2394, 1173, 759, 869, -1511, 322, -311, 977, 133, 816, 57, 320], [-4906, 4492, 11783, 11654, -98, -15652, 1510, 680, -350, -912, -246, 1628, 1502, -612, 1166, -802, -1614, -682, -1254, 0], [6206, 60334, 18318, 2629, -661, 10, 1288, -4043, 777, -594, -496, 2066, -597, -223, 131, -957, -15, -602, -876, 0], [-79741, 55040, -426, 265, 123, 573, -925, 3891, 461, 1645, -911, 2170, 1152, 391, 85, -1022, -1205, -677, 234, -1042], [-25294, 77442, 2828, 10132, 1460, -2992, -1148, 5582, -1954, -2008, 26, -784, 122, -630, -582, -1000, 78, 450, 424, -810], [-221897, 58840, 208, -460, -1097, 2023, 2103, 1277, 5735, 2151, 580, -1932, -1884, -96, -420, 2100, 652, 472, -108, 1008], [11602, 68574, -5307, -5898, 914, 19913, -1010, -4098, -418, 1487, -94, 157, -638, -1456, -190, 1474, 686, 637, 946, 0], [116440, -8848, -4564, -12404, -1890, 314, -1258, 2532, -5142, -2678, 276, 2610, -1586, 482, 632, 138, -1052, -330, -606, 916], [-255080, -53056, 1240, 1462, -2078, -4718, -4230, -2508, -2869, -3966, -926, -2326, 3406, -696, 502, -1790, 614, -940, -14, -876], [12420, 85074, -14280, -6158, -730, -522, -820, -5960, 120, 508, 490, -3402, -240, 2542, -1060, 0, 450, 1950, -520, 0], [-70284, -21874, 1564, -1874, -4386, 370, 1750, -3446, -410, 554, 1640, -4302, -864, 150, -324, 4050, 2904, 1402, -238, 1242], [-4710, 3856, -15368, 11978, -526, 1784, 3042, -1068, 2174, 722, -570, 746, -4166, -36, 1946, -182, -298, -348, -1738, 0], [63039, -12280, 1596, 1374, -1621, 2847, 1915, -147, -6593, 5375, 478, 2608, 1388, 1854, -82, 2048, 970, 974, 496, -564], [12286, 94044, 587, 1622, 814, 23776, 478, -5920, 1354, 1916, -470, 728, -5050, -1372, 822, 2342, 1346, 130, 162, 0], [-10484, -113424, -52180, -8794, 634, -962, -304, 5194, 858, 2716, 252, -5080, -3234, 990, 582, 1518, 910, 2344, 912, 0], [-703, 15216, -14413, 6017, -1111, -29631, 277, -118, 671, -3379, 27, 1445, -47, 1986, -807, -1295, 367, -2118, -533, 0], [-390302, -44988, 1044, 5352, -626, -1254, -186, -5200, 3516, -1278, -492, -7062, -3054, -2486, -936, 442, -132, -754, -262, 1280], [278980, 51968, 5288, 9418, -450, -3970, 1558, 956, 1326, -4210, 2898, -4334, -22, -352, -874, 2890, 3966, 3092, 194, -464], [-12641, -11979, 42364, 18852, -1418, 9651, 2811, -560, 1505, 2527, 1332, -3384, -953, 1527, 2725, -2057, -2638, -115, -2085, 0], [-2856, -17154, -4437, 1234, -926, 45177, -1848, -40, 174, 3123, 2120, 557, 690, -970, -654, -1038, -98, -2261, 1208, 0], [-296244, -1888, -6024, -15778, 5066, 6954, 4914, 2724, -5638, 2970, -10, 2838, -2018, 352, 1058, -610, -1382, -868, -858, 1904], [6615, 67500, 5419, 9243, -925, 62917, -285, -3914, -307, 1461, 517, 4577, 787, -1718, -693, -173, -539, -984, -1699, 0], [2918, 37490, -67214, -6945, 633, 1930, 1228, -541, -909, -6762, -1380, 3618, 5961, -1449, 481, -4143, -757, -4542, 3272, 0], [251176, 7568, -3764, -1694, 2338, -2666, -1374, 4218, -202, -7722, 2098, 7844, -6608, 606, -662, -476, -2698, 2006, -92, 396], [-260328, 24472, 2788, 3702, -548, -2096, 1132, -2876, 1788, -2536, 1006, -7824, 1012, -2370, -1426, 2056, 1258, 838, -168, -3780], [395175, 32804, -1952, -4221, 5873, 1717, 3029, 3612, -3076, -1547, 1407, 4797, -183, 546, -15, -711, -931, 1312, -95, -2280], [6670, 10696, -51960, -4890, -2770, -6612, -5306, -3812, -1110, 8886, 4218, -202, 2430, -292, -3858, -210, -22, 1268, -1134, 0], [-9204, -111022, -26251, -14496, 836, 68525, -2568, 8694, -3508, -4481, -120, -4511, 7636, 2932, -1852, -620, -820, 2199, 1352, 0], [260837, 32352, -1904, -4591, 247, 451, -13, 4184, -8888, -989, -863, -4373, -1061, -1770, 63, -593, -669, -1464, -601, 780], [16060, 88290, 126768, -9090, 2522, 14778, -3348, -3684, -2532, 2452, 338, -6986, -228, 1130, -488, 5292, 478, 5438, 568, 0], [34763, 139961, -30168, -25698, 476, 2675, -5845, -9694, -2101, 5707, 540, -2572, -1595, 617, -4829, 5797, 3204, 7345, -1101, 0], [-452078, 25848, 2552, 11412, 764, -8116, -9580, 6396, 3948, -4100, -3084, 8096, 6824, 1996, 2268, -7848, -652, -2044, 1040, 1184], [288319, -10144, -8704, -18116, 1791, 5015, -2681, -2491, 5751, 4007, -5556, -1556, 2876, -3016, 428, -5228, -7380, -6424, -868, -4712], [16804, 140170, 21865, -3300, -2440, -63563, -3480, -10846, 1064, 4407, 3832, 185, 664, -32, -2088, -2792, 712, -4353, 2456, 0], [-8730, 26036, -40776, 30394, 922, 7048, 4094, -764, -126, 4270, -506, 11002, 1014, -9400, 4510, -762, -3714, -3992, -1614, 0], [722748, -98126, -788, -2202, -3950, 4870, 538, -14594, 15678, 8414, -2564, -4890, 928, -1482, -1192, 1558, -2540, -2510, 54, -3234], [-556523, 41344, 6470, 11263, 2009, 4019, 7161, -809, -7341, 7347, 335, -12444, 810, -2085, -921, 3204, 4205, 371, 36, 1254], [682772, -96928, -9764, -19746, -392, -6764, -8520, 5220, -5536, -14772, 606, 14228, -3448, 2570, 2886, -5204, -2694, -294, -900, 5020], [-40120, -241764, -67677, 27940, 1380, 64254, 600, 17752, 1172, -2006, 704, 5918, -3140, -3628, 2684, 796, -132, -8214, 2536, 0], [1263191, 157512, -5572, -23226, 10543, 15395, 15359, 6273, 5571, 9859, 2214, 8, -508, 654, 966, 3032, 1442, 942, -1272, 396], [34350, -108048, 12868, 40228, 2068, -6344, 4012, -14766, 3528, -3832, 2620, -19418, -8550, -5946, -4712, 4638, 3612, 3282, 662, 780], [20800, 98088, 95894, -46839, -2013, -6852, 450, -16363, 5887, 9136, 2644, -3274, -3499, -4049, 1081, -8275, 2793, -6088, 9686, 0], [-2065716, 213946, -3184, -14194, -10704, -12928, -9040, 17990, 1961, -20000, 5704, 10320, -1638, 3384, 360, 3504, 2040, 5336, -368, -1674], [23252, 55676, 53915, -49932, -3284, -59970, 5692, -9692, 6108, -9902, -5236, 4174, -3948, 3656, -2828, -8268, 5652, -1882, 2116, 0], [-126946, -96568, -5232, -19758, 8454, 2286, 8798, -9680, 12302, -9458, 4002, -9314, -6146, -3132, 942, 1702, 3686, 1592, -2410, 5304], [307712, -43660, 13288, 42178, -7222, -3734, -8062, -6608, -2183, 13882, -4558, 5330, 9482, 2096, -2922, -1238, -3146, -852, 3706, -10208], [-27512, -209762, 32115, 15742, 3014, 47245, -912, 18356, -982, -6529, -1616, 10929, -842, -5318, 486, 2806, 1546, -7633, 3152, 0], [-16624, 166578, 10721, 74728, -3452, -79395, 15220, -8782, 3596, -4665, -2868, 3921, -1004, 2456, 8900, -6188, -8756, -69, -12340, 0], [806145, 192098, -23920, -69979, 9229, 3089, 3521, 13010, 21702, -21263, 1243, -8007, -6513, -5534, 4485, -4475, -1839, -4280, -5523, 6878], [-73678, -409714, -227078, 46979, -3075, 43582, 3872, 28559, 2875, -12078, 1236, -2926, -847, 9663, 2033, -4903, -2233, -7762, -2244, 0], [-663034, -193760, 4024, 21964, -10540, -1316, 2004, -18292, 20732, -612, 7308, 9648, -19256, 3804, -4948, 12400, 68, 8860, 1552, 3672], [18372, -134020, -94577, -54584, 1304, 81786, -10604, -4840, 112, 35894, 5780, -16870, -14272, -4444, -3520, 14048, 4936, 19778, -724, 0], [27060, 78600, 33062, 10605, 4087, 2816, -22298, 6157, -12693, 8852, 6880, -12566, 2841, 6999, -11331, 22545, 2725, 14784, -4766, 0], [-13056, -131556, 52431, -35456, 5848, -69918, -744, 20764, -13152, -29738, -6560, 6002, 35568, -1536, -1456, -9264, -5848, -5002, 8552, 0], [-16942, -303214, 10216, -21972, -1840, -79672, -9206, 11664, -2138, 20050, 5308, -23284, -7078, 10054, -5738, 11354, 1760, 21626, -7966, 0], [-52830, -276312, -54793, 28366, -3834, -14410, 17810, 4296, 8386, 14326, -2298, 20950, -2962, -18792, 11678, -13810, -7126, -8256, -3282, 0], [644415, 232304, -22576, -55616, -10569, 34175, 15807, 12657, 1375, 29967, 1184, 16656, -19056, 5368, -2376, 14968, -10648, -128, -1312, 1160], [38376, 227758, -18319, -3536, 4644, 82107, -11836, -5170, -11764, 2545, 1868, -5497, 12052, 248, -5324, 11476, -1796, 10821, -2116, 0], [-1680346, -13584, 5540, 34574, -15436, -40480, -28572, 6488, 1120, -46848, 7006, 13652, -9928, -310, -4986, -572, -3830, 8818, 1812, -9068], [13687, -93372, -134329, -58137, 7959, 9561, 3691, 17882, -4863, -38191, -15131, 19421, 10959, -3170, -3481, -1233, 6577, -6236, 8597, 0], [1224470, -409680, -30740, -104812, -16400, 20476, 2296, -21014, -4596, 7916, 1148, 23194, 2678, 9106, 5888, 6978, -4084, -2362, -3510, 356], [-973426, -498542, -10368, -27938, -15172, 12204, 6380, -35014, -11098, 7660, -492, -23140, -19854, -5704, -2068, 11564, -932, -3520, -3028, 12250], [-1150825, 249512, -10644, -25914, 22827, 1935, 7003, 20093, 20847, -13777, 4358, 18624, -340, 2678, 3670, -7568, -926, 2950, -1408, 988], [1732284, 304322, 3808, 22722, 8812, 13324, 8044, 21950, -9513, 22412, -4660, 116, -3218, 40, -668, -2380, -2972, -3296, 1364, 4934], [61133, 518953, -282708, 5866, 1380, 78381, -1943, -30792, -2953, 9077, 1570, -9342, 217, 907, 1007, 5689, -2580, 9797, -3939, 0], [711587, -243472, 12874, 57657, 23159, -27299, -10809, 2121, -24451, -30915, 3753, 18524, 1094, 909, 33, -15124, 363, 6437, 2684, -1734], [25086, 400994, 86623, -23328, -1880, 44457, 6622, -22928, -4184, -18977, 226, 18093, 40376, -12742, 4968, -32008, -11032, -27987, 17442, 0], [-578034, 53656, -23708, -45772, -9490, -950, -1178, 4932, 2284, -24430, 6668, -1238, -31858, -5950, -5296, 10138, -11068, 2950, -3718, -188], [-768825, -369816, 38376, 124624, 14991, -12585, -9249, -6043, -48393, 22455, -7904, 18324, 18908, 7852, 808, -16476, 4688, 404, 8308, 3608], [-35801, -473100, 69875, -46433, 2911, -23847, -17909, 31058, -3783, 337, 6853, -5603, 3735, 182, -8145, 3831, 7273, -9404, 16117, 0], [-5291686, 83588, 7408, -1044, 5820, 7372, 1180, 3008, -2253, 20972, -8140, -2812, 29452, 2592, 5644, -9212, 5020, -7144, 996, -4008], [57953, 617717, 363980, 22770, -15596, 52541, 16733, -54272, 17435, 5033, 98, -350, -19019, 13127, 1235, -15851, 604, 529, -14639, 0], [81492, 379474, -91755, -49868, 960, 5369, -27048, -24190, -8368, 24355, 12008, -11779, 2128, -424, -14080, 14608, 6672, 8283, 5992, 0], [-49716, -253852, -125064, 32788, -8268, -90382, -7516, 29700, -9344, -37796, 3216, 10056, 35888, 17672, -12568, -17200, -5044, -17212, -1164, 0], [-2376365, -358688, 29006, 104581, 25319, -2671, 15343, -34185, 18529, 8321, 4333, -7974, -13864, -3517, -7439, 898, 3999, 8631, 4298, 2950], [111133, 417279, -213900, -104636, -3014, 215057, -15999, -40424, 6875, 24813, 4428, -26408, -31043, 13965, -14585, 17293, 18446, 23047, -447, 0], [27819, 158056, -100321, -1265, 511, 6527, 9887, -10646, 4273, -4917, -9047, -15165, -19537, 14770, 1351, 10991, 3433, 23674, -15583, 0], [-36252, -150890, -214669, 46066, -6950, 22277, 13724, -15428, 21766, 45567, 6484, -1479, -44038, -11366, 13258, 506, 1558, -533, -6364, 0], [24834, 140226, 164080, 13784, 3156, 24440, 15634, 12, -1174, -25150, -17940, 17876, -4154, 2154, 850, 6502, 1132, 14058, -16998, 0], [-37672, -354564, 507734, -4747, 3079, 190216, 15994, 36237, 4407, -57960, -20696, 33010, -2355, 4627, -1623, -6459, 9109, -16348, 1030, 0], [-80286, -835114, 46172, 115956, -16896, 7388, 29184, -68414, -53426, 31764, 15526, -32340, -24782, 90, -15202, 38404, 19602, 20858, 5332, 3786], [-4703708, 440668, -45664, -161078, 2822, 82958, 64174, 20208, 11977, 56078, 13426, 13542, -30562, 12188, 4510, 35134, 4374, 5856, -7570, 22960], [96736, 295354, 422644, -37512, -2912, -10070, -28452, -40118, 8394, 76392, 17214, -11594, -54378, -9236, -14150, 37590, 19632, 24334, -6568, 0], [-706, -209102, -44587, -19766, -9554, 79295, -5566, -10782, 7778, 48041, 9742, -19829, -25154, 5024, -5378, 9598, 3602, 25803, -15362, 0], [-2828434, 57044, -47272, -171256, -28644, 40532, -516, 21232, -35723, 34308, -5784, 49404, 25652, 20252, 12976, 4684, -8360, -9516, -3732, -6008], [-1634930, 36184, -20192, -75842, 6970, -39710, -30846, 33592, 5172, -68766, 6518, 45202, 24394, 12100, 16554, -23926, 8258, 3248, -3270, 7184], [45020, 758662, -27424, 148154, 3134, -248986, -11716, -39460, -9868, 49316, 17262, 4890, 1012, -22442, 8680, 18724, -15414, 2218, -10608, 0], [3749802, -326000, 61104, 170076, -11900, -40812, -23356, -58824, 62420, 2836, -8692, -44356, 25420, -11136, -10028, -5060, 9188, -536, 8156, -19440], [2164340, -267528, 40732, 150622, 34926, 29050, 40102, -46886, 48410, 58730, -3106, -33912, -27852, -8562, -11178, 6624, 4050, 2518, 5624, 18276], [-134113, -539361, -468388, 150278, 1140, 233387, -6773, 61900, -21791, -27689, 7658, 40074, 59759, -15991, 2025, -16177, -22676, -37205, 3439, 0], [-30397, -105768, -139849, 12799, 27423, 219943, 6631, 44674, -16335, -58029, -19711, 1067, 19119, -5878, 14343, 13551, -3255, -8150, 18329, 0], [-54187, -269047, -233452, 88742, 24440, -27607, 6745, 30300, 1867, 18509, -6662, 37618, -31627, -50777, 24523, 27893, 1784, -20811, 16109, 0], [887582, -40224, 53448, 158140, 22980, -14820, -6684, 1684, -81348, 30492, -13220, -10776, 40592, -4364, -6932, -17976, -556, -3292, 9928, -31864], [-49882, 196382, 88877, 255330, 798, -360611, 19650, 5038, 10562, 2003, -4786, 23697, -48002, -608, 15662, 26878, -4302, 405, -34370, 0], [53066, 158386, -126440, -9372, 3736, -432868, -4542, -13168, -8002, 29338, -3276, 21204, -2270, -21738, -4082, 18274, -184, 22154, -14262, 0], [2111931, -260438, 44264, 139119, -63009, -53821, -43045, -35574, 14668, -20333, 1269, -30037, -13543, -6454, -16461, 18847, 2495, 8332, 7063, -11090], [-8607, 255884, 355195, 109477, 9837, -358133, -40267, 40426, -50101, -47557, 12139, -21273, 85765, 26878, -18291, 14437, -21973, 5144, -4597, 0], [153056, 932150, -446848, -144042, 7898, 148442, 1632, -51572, -7176, -32744, -13702, -26818, 17664, 16278, -4172, -3312, 4894, 18114, 10300, 0], [3633590, 390048, 35988, 158712, -12158, -24258, -11350, 13268, 52298, -1178, 9664, 27918, -37934, 6002, -16756, 13614, -6880, 19438, 9774, -2348], [84503, 55729, -368884, -249656, -14222, -216505, 31571, -53608, 35993, 2007, -18000, -23204, -43745, 17811, -651, -28241, 22422, 19825, 4219, 0], [-5116908, 46800, -20964, -55848, -16234, -56814, -47170, 19768, -29374, -87422, 5584, 16878, 12922, -6078, -1396, -11978, -13432, 2862, -2722, -37452], [-58190, -1095182, -454333, -98580, -3308, -324203, 2642, 34832, 21836, 41835, -4850, 7417, -61772, -10614, -5516, 18100, 24044, 19085, -5522, 0], [-1064786, -1807002, -116680, -331712, 3206, 75350, 24478, -99086, -18289, 9542, -3898, 40550, -18892, 3744, 14178, 1598, -33006, -19884, -15986, 2154], [100056, 530300, -353580, -15038, -6282, -142066, -7276, -51186, 22090, 39208, 6036, -25464, -73090, 17006, -7522, 28910, 23330, 22052, -12108, 0], [-860491, 484016, 89276, 309550, 28557, -20503, 15061, 34203, -35095, 33209, 3502, -21768, -33148, -2754, -16586, 3296, 16242, 17558, 14056, 26772], [196796, 799312, 87767, -111124, -23940, 331576, -47572, -84184, -788, 86256, 28572, -13712, -19324, 10088, -42940, 20900, 18212, 39988, -21996, 0], [-6782390, -927588, 1976, -21168, 4004, 11708, -20924, -74896, 55679, 46316, -31376, 4868, 71772, 4412, 15080, -35692, -4592, -29180, 2196, -12632], [-136590, -477040, 57979, 179694, -11226, -293858, 41746, 36624, 21482, -48386, -15474, 81974, -11018, -15928, 15046, -31946, -4790, -54848, -10770, 0], [-4660030, 922914, 115188, 426532, 18784, -18540, -7648, 53662, -17812, 85756, -11422, 34980, -11394, 10398, -26934, -5460, -9914, 15678, 27100, -13866], [13217638, 1499450, 18240, -53914, -56948, 17820, 9628, 89010, -43618, 44252, -7852, -86020, 33066, -1992, 12044, 23340, 41948, -12992, -5140, 35682], [-2839821, -1167560, 13108, 76746, 49811, 44575, 10579, -81307, 91359, 91679, -29174, 54096, 30916, 17722, 13226, -40816, -10850, -20838, 8336, 22196], [4375329, -1428512, -21330, -143797, -35551, -29325, -39967, -103673, 104019, -40013, -3141, 22764, 65498, 16511, 24355, -15956, 20241, -8153, -5012, 1582], [69086, -266746, 482070, -148063, -22769, -282986, -46768, -22103, 10901, 68670, 28856, -37326, -39089, 27125, -40681, 17287, 28813, 27182, -5156, 0], [-1769, 134760, 623979, -63165, 30227, 353175, 23627, 9978, -6491, -38181, -22267, 1459, 19499, -30238, 31587, -6517, -7851, -17394, 36853, 0], [9284858, 1482320, -113148, -292228, 89368, 83388, 31600, 107222, 10540, 22028, -24780, 52078, 34050, -9194, 15424, -48986, -58012, -37646, -12866, -49300], [-7684923, 495422, 7096, 123409, 46177, 17677, -26091, 37126, 45736, 68541, -51469, 9085, 18247, -11354, 3189, -63463, -41863, -43948, 7521, 5258], [32058, 293742, 999427, -118632, -14656, -486433, -9222, -28640, 6368, -29367, 13222, 12587, 44704, 1654, -10656, -57440, 2368, -60525, 43718, 0], [7247127, -173232, 114450, 358805, 47927, 3957, 83047, -62303, 10453, 39317, 33829, -87036, -80778, -18975, -37011, 52980, 36095, 45705, 11876, 20898], [3196864, -351900, -133096, -400458, 6398, -26866, 2230, 12752, -30481, -189058, 46798, 18158, -58866, -13984, 7994, 17318, -11510, 19684, -27114, -10568], [-5661612, -1597724, -18928, -73704, -42372, 23420, 7404, -116932, -57442, 20508, -9076, -82180, -19040, -21872, -5468, 23084, -2460, -16744, -7668, 7052], [6005, -391959, -380816, -178896, 28774, 366641, -37747, 41166, -18655, -10227, 6226, -41794, 19495, -8243, -2747, 17815, 12866, -12267, 58825, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_40_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_40_6_d_a();".
// 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_40_6_d_a(:prec:=20)
    chi := MakeCharacter_40_d();
    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_40_6_d_a();".
// 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_40_6_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_40_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;