
// Make newform 43.4.a.b in Magma, downloaded from the LMFDB on 25 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_4_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_4_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 := [60, 276, 251, -16, -32, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-34, -25, -36, -16, 2, 1], [30, 103, -36, -24, 2, 1], [118, 111, -44, -24, 2, 1], [182, 331, 24, -36, -2, 1]];
    Rf_basisdens := [1, 1, 8, 8, 8, 8];
    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 := 4;
    raw_aps := [[1, -1, 0, 0, 0, 0], [1, 0, 0, -1, 0, 0], [7, 0, -1, 1, 1, 0], [2, 2, 1, 0, 0, 3], [-3, 6, 3, -2, -5, 4], [7, 2, -1, -2, 3, -8], [4, 2, 4, 3, 1, -1], [-11, -10, 2, 3, -1, 3], [24, 6, 5, 5, -10, -7], [81, 24, 2, -5, 18, -8], [42, -18, -6, 1, -21, -1], [47, -18, 31, -3, 6, -9], [78, -28, 27, -17, 16, 3], [-43, 0, 0, 0, 0, 0], [79, -44, -9, 5, -40, 23], [67, 20, -37, -30, 7, 26], [62, 42, -8, 30, -4, -10], [-208, 46, 25, -4, -46, 13], [-113, 14, -69, 78, -1, -56], [-62, -56, -38, -28, 116, -46], [148, 146, -51, 92, 26, 9], [-297, 96, 14, -53, 95, -35], [-79, -136, 37, 102, -5, 64], [576, -2, 89, -62, -34, 17], [4, 102, -3, -29, 22, 133], [-153, -272, 31, -46, 19, -18], [-414, 304, -47, -47, -20, -107], [-166, 170, 74, -38, 56, -68], [-105, -194, 59, 54, -35, 138], [258, 172, -102, 18, -78, -80], [-144, -188, 108, -35, -173, 263], [211, -18, -201, 197, -64, 165], [740, -512, -42, -78, 130, -64], [-601, -80, 251, -208, 69, -96], [181, 458, 53, 111, -38, 97], [-734, 38, -55, -20, -112, 111], [1529, 78, 52, 99, -149, 237], [-435, 4, -153, 157, 19, 6], [1043, 188, 237, -324, -51, -2], [1140, -100, 2, 38, 68, -6], [903, 232, -9, -183, 41, -44], [398, -222, -122, -64, -154, -210], [-98, -92, -122, -94, 86, -16], [-332, -226, 11, 263, -62, -161], [-208, -558, 110, 114, -538, 438], [-1648, 128, 146, -266, -192, -98], [1485, 94, -37, 253, 114, -369], [1150, -174, 155, -304, -232, 73], [1385, 58, -62, -167, 99, -73], [57, 390, -293, 102, 189, -142], [-1272, -184, -8, -302, -332, 84], [-315, 224, -302, 113, -43, 119], [-3766, -280, -68, 162, -166, -142], [1089, 398, 463, -28, -271, 110], [986, -6, -329, 176, 46, -449], [-14, -796, 334, -104, 12, -518], [875, -174, -379, 162, 87, -542], [-154, 36, 209, 559, -260, 257], [1165, 688, 53, 35, 67, 44], [-652, 96, -284, -667, 673, -91], [-197, 288, -347, -198, -101, 8], [3438, 1014, 68, -308, 172, -474], [435, 320, -155, 258, 649, -322], [-927, 390, -211, 322, 359, 354], [1302, -134, -219, -94, -156, -77], [3873, -22, 43, -294, 23, 232], [3040, -910, 391, -636, 120, 461], [-2780, -672, 0, -813, 1199, -89], [3477, -328, 267, 747, -1221, 958], [201, -456, -134, -301, 46, -256], [1113, 2, 413, -390, 497, 716], [-750, 462, -926, 489, 191, -1573], [2621, 1824, 107, 739, -1128, -297], [1001, -2110, 220, -359, -737, -3], [-69, -1002, -75, -400, 265, 732], [5936, 1528, -858, 832, 380, -538], [1894, -764, -136, 156, -520, 608], [-2578, -1734, 264, -676, 494, -456], [-1338, 984, -684, 1041, -161, -45], [-4224, -950, 431, 42, -794, 755], [-2210, 1886, -31, 484, -630, 293], [4365, -2342, 492, 259, -157, 709], [334, -996, -872, 289, 525, 325], [1726, 666, -663, 360, 494, -155], [-2490, -2166, 1096, -245, -791, 1007], [-3016, -894, 112, -756, -182, -612], [-2784, 690, -299, 1360, 652, -849], [-3572, -414, 123, -800, -12, -115], [3238, -86, -594, 664, -546, -250], [2192, 634, 825, -254, 530, -155], [-4435, -214, -1007, 681, -18, 153], [-9894, 2090, -45, 169, 936, -435], [-7351, 1806, -236, 105, 597, 135], [-4565, -180, 229, -1137, 901, -142], [1641, 1408, 130, -1451, -238, 68], [-5070, -876, 424, -1392, 174, -694], [1269, -972, 569, 1698, -995, 278], [5730, -822, 639, 1886, -792, 1397], [-2159, -1628, -484, 417, -1726, 302], [-1569, -1328, 657, 0, 935, 1500], [-4521, 2024, -473, 1068, -465, 1374], [-1347, 246, -143, 294, -777, -334], [539, 146, -1537, 350, 2617, -1070], [-1775, 284, -1383, -624, -459, -2010], [6691, 2888, -632, 713, -784, -1196], [-5492, 2338, -223, 1146, -1244, -673], [-2522, -2820, 996, 1236, -1126, 1206], [4764, -1062, 459, -350, -1964, 1833], [-15344, -1228, 622, -1233, 49, 1111], [-374, 1164, 86, -730, 532, -318], [5504, -392, 416, 1016, 872, 444], [3894, 474, 2082, -2264, -1244, 256], [2438, -1830, 1379, -1483, -1128, 833], [4412, 2420, -1136, -324, 3216, -1284], [278, -1764, -128, 424, 1490, -1738], [-622, -1778, 2033, 88, -1310, -183], [-3714, -2494, 1848, -1978, 1992, 1458], [-2202, 916, -662, -458, 2650, -1320], [12021, -2066, 1050, -777, 1267, -541], [-10601, 726, 1713, -970, -1213, 258], [-2775, 384, -1537, -1188, 771, 1262], [11674, -658, 653, -430, 366, -835], [11099, 2338, -1870, -543, 833, -727], [8941, -34, -1643, 982, -1011, 1456], [4042, 894, -2101, 1492, -290, 63], [-4748, 3034, 26, 1710, -860, -376], [-5193, -158, 537, -1382, 709, 1740], [-11649, -1190, -1607, 1157, 1442, -1911], [-7862, -72, 380, -554, 1986, -110], [-15651, 186, 575, -1549, -1142, 487], [-1579, -3546, 151, -1783, -1654, -2117], [-3382, -884, -782, -610, 142, -1196], [-4600, 4186, 9, 60, -2844, 811], [-433, 526, 2423, 169, -1674, 3327], [-11634, 1564, -958, 462, -770, -2300], [-3373, -4188, 1223, 2147, -360, 695], [14663, -356, -1936, 1375, 2660, -1248], [-6394, 6398, -1500, 530, 4, -2154], [19130, -1818, -1400, -944, 824, -1234], [-7475, 2804, -1045, 1001, -2068, 415], [7441, -4888, -341, -159, -1725, -1150], [-5939, -1798, -323, 782, 1237, 1440], [6849, -5806, -1007, -814, 355, 830], [-3496, 3944, 1390, 464, 2130, 1800], [-1835, 6358, -711, 1567, 686, 1053], [1912, -1270, -883, 1958, -736, 1231], [1355, -3032, -855, -706, -1093, 664], [11669, 1198, 2138, 1359, -2959, 1233], [2283, -3270, 1234, -4645, -39, -111], [2640, -180, 3540, -3526, 950, -1666], [-5223, 5472, -1971, 2538, -1787, 1446], [16152, 1156, 1768, -385, -3181, 1223], [6817, -5706, 517, 142, -325, 3670], [4426, 3924, -450, 2112, -534, 1348], [16235, 1128, 587, 4804, -3001, 1554], [-3178, -2474, 1443, -4138, -878, 2815], [-10366, 2404, 162, -1015, 2849, -6373], [-9706, -356, 2006, -900, 756, -2950], [17308, 4558, 1645, -4054, 474, -279], [467, 918, 1419, 1068, 2727, 28], [-4989, -3684, -4147, 1012, 3331, -2140], [-9384, 5814, -969, 4540, -438, -2429], [14668, -1580, -1505, 1519, -578, -3255], [-14645, 2714, 823, 2848, 1505, -142], [-7325, -3996, 3013, -3261, -1852, 4825], [5144, 2266, 645, -2034, -2268, 2635], [11080, 5342, -1333, 728, -2198, -3273], [-305, 5580, -2166, -485, 404, 2978]];
    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_4_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_4_a_b(:prec:=6)
    chi := MakeCharacter_43_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(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_4_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_4_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_43_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![540, -608, 26, 124, -17, -6, 1]>],Snew);
    return Vf;
end function;