
// Make newform 43.6.a.a in Magma, downloaded from the LMFDB on 19 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_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_43_6_a_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 := [681984, 106368, -167688, -14192, 9118, 462, -173, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [-20471935488, -206135304, 2758106176, 85006462, -76756386, -2147429, 510320, 8125], [1709840448, 7674423864, -1837549088, -378607946, 80176782, 2601727, -681148, 12949], [-6710235008, -1052986520, 1274965584, 6237658, -37491046, 1611305, 269956, -17485], [-7712512416, -3214801896, 152252096, 252968474, 8711358, -5886547, -126518, 38033], [17642049216, 1067316504, -1263726976, -470063386, 14631678, 13177295, 19780, -83131], [-28238112000, 2176112520, 4067658416, -487223974, -129895854, 16607009, 1062904, -128521]];
    Rf_basisdens := [1, 1, 547265856, 547265856, 364843904, 273632928, 547265856, 547265856];
    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 := [[-2, 1, 0, 0, 0, 0, 0, 0], [-2, -1, 0, 0, 1, 0, 0, -1], [-28, 0, 0, 0, -1, -2, 1, 3], [-10, -13, -1, 4, 0, 2, -2, 1], [-74, 28, 19, -9, 0, -2, -1, -3], [-292, -4, 1, 13, 24, 2, -19, -1], [-419, 109, -17, -12, -67, -8, 9, 32], [-284, -17, -105, -62, -9, 64, 9, 38], [-329, -2, -21, 112, -125, -70, -26, 20], [-492, 103, 52, 54, 19, -122, 12, -139], [631, 137, 155, -140, -83, -202, 39, 56], [-176, -422, -307, 114, 217, 280, 98, -398], [-1208, -295, -274, -173, -1, 138, -214, -245], [-1849, 0, 0, 0, 0, 0, 0, 0], [-9863, 439, 8, 193, -25, -300, 108, -99], [-6787, -1303, -48, -100, 568, 406, -423, -348], [-3531, 815, 1163, -445, 226, 728, 388, 179], [-8856, -1315, 1067, -296, 1356, -646, 204, 161], [3110, 50, 1093, 77, -948, -874, 159, 1283], [-2506, -838, -1682, 816, -1340, 1644, 612, 1198], [780, 1677, -65, -280, -908, -714, -32, -463], [19609, 1226, 60, -639, 1839, 1676, 195, 275], [-7731, -1607, -502, 884, 384, -2078, -1885, -546], [-35082, 4015, 1847, 1528, -430, -1342, 1516, 1507], [22025, -1322, 1891, 1116, 4143, 2578, -760, -2298], [-39633, -1137, 2102, 594, 1584, -630, 3749, 2298], [-9154, 12319, -3768, 1451, -3121, 910, 1928, 3295], [-6755, 3189, 4293, 1699, -862, -1452, -712, -3091], [-16426, 2106, 2309, -85, 2632, -1386, 1439, -2569], [-30234, 1022, -2806, 626, -818, 4780, -3522, 848], [44744, -8874, -6630, 1941, -1707, 930, -3221, -5095], [-28890, 16370, 4873, -2044, -2501, -4986, 2782, 3896], [-13406, -26216, 5432, 256, 1158, -1352, 786, -326], [53651, 8915, -180, -1854, 10254, 5942, 2545, 4762], [-71174, -13564, -12827, -2824, -6029, -4648, -3086, -4856], [149944, -13275, -4655, 8598, -4788, -5622, -2618, 6771], [25014, -3015, 3981, -13194, 8321, 4068, 1085, -260], [-47438, 32340, -4522, 250, 5645, -16230, -5125, 8245], [68177, -17069, 10316, 3740, -4322, 5974, 13005, -5278], [-167124, -1942, -5788, 3782, -7038, 5864, 1484, 23098], [-46410, -15882, -14270, 1324, -6011, 5194, -9719, -2599], [-153949, -3465, 2955, -2021, 13656, -9744, -1070, -2055], [132482, -29686, 13786, -7806, -5198, -11508, -2874, 868], [-208883, 25548, -17595, 24, -6113, 9918, -4992, -2244], [-96013, -56847, 18351, -6245, 6210, 5740, 2766, 1715], [-347478, 39416, -698, 9592, 4554, -25792, -508, 20384], [121704, -36762, 15899, -18620, 6951, -762, 2760, 4554], [228818, -124799, 2737, -10216, 28872, 20506, 1042, -28065], [-200410, -9871, -41357, 10654, 7649, 25968, 3593, -31392], [-12708, -3386, 2937, -14317, 3488, 10054, 859, -37945], [-31822, 48870, 13492, 22572, -11198, -9060, -10960, -11470], [190783, 104746, -42056, -26673, -17291, 19836, 1665, -6779], [217648, -10278, -4330, 4320, 24966, -7476, -210, 27440], [200932, 6646, 13585, 1983, 55426, -27546, -12663, -22547], [-420016, 34861, -28109, 9878, 43648, 13474, 128, 13529], [357984, 108964, 41192, -33386, 9512, -27680, 18396, 21196], [-113358, 21332, -50139, 3323, -65340, -25290, -5207, 15139], [-65988, 118149, -41444, -10745, -15059, -1554, -18236, 30817], [-207062, -57686, 31922, -15586, -15187, 23362, 27879, 18239], [614502, -99446, 67404, 8141, 14203, -40332, 541, -13859], [57393, -90597, 16864, -38602, -29904, -65862, 35899, 28232], [-604297, -47775, -2817, -9521, -72668, -51376, -18192, 9753], [-851355, -77837, 53890, 21978, 59984, -19670, 36321, -5446], [234422, 157682, 16369, 11939, -26264, -47542, 26471, 63147], [-471542, 163677, 35215, -30494, -65418, -3606, -23030, 9379], [-1363530, 35640, -34563, 35561, 12292, 65058, 19913, 3639], [-561664, 213533, -43647, -3576, -32996, 13862, -25590, -2257], [180718, 46126, -27140, -4241, -59699, -9236, -35573, -15925], [-111994, -117836, 15716, -38828, -115009, -28422, 22195, -60379], [524678, 44725, -82962, 41568, -73773, 31918, 22740, -15029], [77318, -127262, 64489, -28199, 84840, -55954, 19519, -4845], [1086249, -54073, 95909, 59878, 118505, -61154, 1547, -64174], [901677, -82139, -53572, 1145, -64795, 85048, 13664, 79323], [512014, 94785, -55205, 14964, 9415, 88476, 61829, 10004], [-608050, 27276, -90585, -103001, -49574, 19350, -50803, 25619], [-615584, -152926, 3058, 7108, 63312, 123432, -25368, -175354], [-183606, -106660, 45100, -3944, 44604, 61436, -56732, 75612], [672225, 25619, 110503, 7333, -19900, -86272, -54490, -61939], [499512, 527438, 32602, -1595, -25737, -104292, -35821, 138147], [1467762, 245109, -4035, 17980, -202798, -17358, 21052, 207693], [-2339236, 245645, -164505, -8346, -78896, -19878, 18356, -13019], [1011410, -88603, -7339, 113378, 34481, -46276, -116535, -42084], [830786, -204066, 32876, -49587, -40503, 32562, -50519, -175061], [-1170968, 82243, 7165, -30854, 24928, 181210, 148000, 28955], [-2103757, -183817, -85015, 29758, -126297, 5510, -21823, 186624], [-1963463, -259767, -99807, 98839, 7444, 39472, -16298, -101597], [-2269052, 139997, -91907, -30388, -142228, 34694, -49194, 128027], [2662430, -424087, -152731, -81590, 36820, 63290, -47226, 4559], [-2028155, -242339, 121625, 78897, -187732, 26944, -11690, 18035], [-1343960, -186661, 92171, -112390, -64726, 45626, 40008, -101697], [-3950254, -251458, -152533, -11222, 102027, 105530, 33892, -73250], [-532973, -103002, 158533, 50574, 173963, 143838, -88824, -360350], [2635468, -246143, -82867, 110850, 186253, 7228, -18547, -124364], [-1766304, 508902, 133936, -88108, 4047, -20034, -15263, 193553], [2289852, 217635, 315024, 187536, 177719, -205812, -4350, -14055], [-4159278, -229280, -6066, 104216, -170116, 158548, 62938, 163202], [-1524857, 163003, -183036, -183424, -57956, 100054, -3597, -86280], [-116050, 196351, 43101, 57286, -29574, -243238, 8742, 307293], [-2469030, -306301, 113788, 3202, -130437, 24944, 63442, -50247], [4365813, -229125, -35560, -160198, 80226, 133662, 4429, 118182], [-2482953, -314653, -228466, -264806, -170814, 122402, -89849, -104024], [-2467938, 483730, 512235, 107321, 245240, -412082, -72347, -165547], [-336308, 511992, -257427, -36865, -389548, -47998, -82943, 71307], [2786755, 335899, -159618, -227586, -50538, 75738, 158487, 201336], [-2265404, -71045, 319850, 17406, 27199, 157528, 151708, 124367], [5295892, -164871, -28149, 167590, -195514, -97290, 2854, 154455], [769080, -646058, 398900, 26962, 77704, 228920, 14858, -5700], [2723658, -131795, 382715, 10032, 68334, -192418, 97422, -325673], [1736250, 391594, -83302, 369429, 145847, -282934, -286139, -64617], [3123994, -364990, -336692, -35270, 76206, -78220, -119400, -133814], [-164562, -831978, 144206, -85602, 240680, -139356, 128176, -197966], [3794683, -86489, 34585, -64797, -38040, -55808, -15724, 34671], [4455067, 542940, 52189, 194274, 349845, 277158, -10138, 59198], [4112216, 101384, -259984, 27988, 171072, -73912, -67832, 74272], [-1446366, -181568, 98898, -313892, 8788, -444056, 359834, 36822], [1000588, -136981, -296835, -42530, -72608, 128918, -14148, -395445], [-2042819, 550043, -274885, -147913, -261142, -10204, -205208, 531815], [-1923738, 261598, 451822, -27578, 589974, -421832, -121838, 27584], [-4288688, 1024693, -89887, -78060, 161989, 24480, -138431, -301244], [6238182, 15512, 174931, -212671, 481480, -230022, -54905, -174151], [-3429649, -152035, 47870, 140162, -606774, 224426, 34941, 61680], [-1376768, -564893, 71659, 70804, 509354, 162826, -125912, -166645], [242430, -454879, 296545, 428874, -242309, -357080, 29927, -262926], [-5345706, 300970, -351469, 140455, 266828, 95242, -120135, 376585], [-3640760, -390561, -28839, -327214, -399768, 366150, -254248, -255765], [-3924933, -967551, 210177, -32889, 702054, 223520, 242504, -404667], [-24374, -607200, 300119, 174331, -271372, -401682, 92135, 261889], [775086, 14162, 264783, 204352, 104031, 343704, -170162, -447234], [-3279140, 1091422, 454, 382596, -46610, 577192, 97530, -178252], [-13127854, -466798, -281589, 312656, -139297, 89444, 40258, 405702], [1982752, 34050, -527053, -13336, -221869, 303246, -203464, 192278], [-230510, -952386, 627706, 330574, 240926, -58704, -271074, -169396], [1278138, -1217659, 272225, -18954, 691716, 620990, -225058, -892825], [-4780912, 1666074, -211159, -224258, -636915, -180120, 355506, 785058], [-2041942, -1940514, -1382, -335942, -50566, 548044, 116894, -163472], [165925, 386157, -270770, -522897, -826293, 555066, 194690, 64847], [-6374918, 1811329, 386956, 282494, -245141, -351310, 135278, 108093], [7362641, -1684805, -454377, 59279, 259794, 750112, -344180, -595201], [-4093821, 555937, -343425, -385397, 415576, 502612, -187408, -167355], [-2083379, 1454135, -550502, 739, -438815, -108966, 186758, 808029], [-2095882, -741772, 317454, 69690, 344761, -406510, -431745, -526999], [-1081816, -312724, -414241, 495667, -401728, 582022, 317107, 826689], [-11408964, 306452, -560925, -376331, 133376, -471430, -307981, -192983], [13501004, -546630, 516028, -94552, -641724, -193488, 290346, 98100], [-10446356, 1365146, -681429, -189890, -491301, -441832, 175670, -86750], [10946170, -70291, -755261, 40168, 243034, 703086, 316994, -258645], [-4917767, 800335, 608910, -463268, -166708, 68902, 383941, 109714], [3137866, -211201, -675051, -714156, -291503, -713940, -111443, 498374], [3327926, -116089, 1015585, 276682, 659323, 412904, 371863, -344640], [-1999126, 16838, -101374, -89148, 329298, -194848, -191738, 688896], [-1383949, 2961827, -13712, 81288, -772928, 117590, -387561, 521244], [-5904628, -972520, -172262, -649487, 327321, 47524, -735049, -474287], [3885930, -947006, -733715, 481083, -791596, 12982, -185225, -77393], [8424124, 868476, -493870, -746626, 263380, 271000, -537606, -757378], [1152367, 1318835, -109370, 496850, 589690, 431186, -392485, -738708], [-3028980, 882215, -31261, -637036, -1329714, -94746, 499668, 327031], [18716226, 89188, 951986, 325493, 145477, -107090, -74671, 142737], [3416688, 1937464, 666008, -69230, -981572, -816560, -28508, 669888], [5981234, -7529, -160349, -979992, -890158, 715798, 480476, 713799], [-2960300, -104664, 708659, -698141, -85522, 840990, -377747, -415873], [15045085, -2079333, -408974, -417716, -349178, 550302, 353959, 494464], [8973694, -2014363, -1404729, 550514, -774516, 1167790, -238248, 343965], [1165690, -2155709, 310852, -100613, -625527, -129038, 381142, -491035], [6481384, -2341996, 36519, 35061, 1104638, 111990, 9105, -994125], [-7877401, -647539, 747030, -27819, 943707, -1445714, 564130, 279111], [6116862, -2784079, 671363, 285024, 744978, 398246, -26734, 526631], [-129676, 3342093, 298063, 309224, 222188, -156798, 133940, 373081], [-112812, 1017525, 197584, 859024, -198729, 473862, 632850, 1004813]];
    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_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_43_6_a_a(:prec:=8)
    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_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_43_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_43_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![259776, -439936, -39464, 49104, 3358, -1502, -117, 12, 1]>],Snew);
    return Vf;
end function;