
// Make newform 143.4.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_143_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_143_4_a_c();".
// 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_143_4_a_c();".
// 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 := [-2988, 9710, -2245, -7888, 345, 1144, -12, -59, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0], [322364, -171682, -82789, 154641, 9822, -14878, -350, 357, -1], [-945052, 1596466, 1290477, -418873, -168206, 29774, 6990, -621, -87], [-1282084, 1253102, 1200419, -109591, -148562, 18, 6290, 93, -89], [-1429268, 1011254, 1212663, -131707, -133194, 6346, 4810, -119, -53], [-612268, -549206, 1287513, 240843, -237974, -21674, 14550, 551, -283], [1310876, -1848178, -1433101, 525529, 263118, -35982, -16270, 653, 311], [495876, -483326, -783307, -6305, 134978, 5246, -7810, -181, 145]];
    Rf_basisdens := [1, 1, 37760, 75520, 75520, 37760, 75520, 37760, 15104];
    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_143_a();"
function MakeCharacter_143_a()
    N := 143;
    order := 1;
    char_gens := [79, 67];
    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_143_a_Hecke(Kf)
    return MakeCharacter_143_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 := [[0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, -1, 0, 0, 0, 0, 0], [4, -1, 1, -1, 1, 0, 0, 0, 1], [2, 0, -1, -2, -1, -1, -1, 0, -1], [-11, 0, 0, 0, 0, 0, 0, 0, 0], [-13, 0, 0, 0, 0, 0, 0, 0, 0], [9, 5, 0, 4, -3, -2, 4, -1, 4], [8, -1, -2, 1, 1, -2, 2, 3, 4], [21, -5, 5, 4, -4, 3, -11, 1, 5], [-7, -2, -1, -1, 6, 0, 14, 9, 3], [68, -12, -10, -4, -4, 6, 4, 0, -8], [103, -41, 0, 4, 3, 0, -6, -3, -8], [-17, 11, 3, 0, 4, 19, 3, -7, 9], [12, 13, -21, 7, 3, 2, 16, -6, 9], [-43, 33, 12, 10, -51, 10, -20, 7, -8], [128, 33, 2, 41, 29, 18, -16, 1, 10], [-41, -70, 25, -5, 22, -6, 30, -3, 19], [43, -40, 3, 11, -2, -20, -6, -7, -13], [-45, 64, -71, -19, 32, 8, -8, -9, -5], [211, 27, -36, -34, 1, -24, -68, -11, -38], [417, -37, 1, -2, 59, 4, 44, 2, -7], [-132, -20, -76, -80, -8, -22, 36, 6, -18], [-192, -139, -58, -17, 0, 29, 51, 4, 20], [156, 62, 26, 52, 28, -12, 28, 26, 46], [456, 64, 18, 54, -92, 30, 4, 4, 40], [-412, 144, -40, -46, 46, -20, -6, -4, 46], [503, -13, 9, 42, -70, -19, 7, 7, -35], [-449, 36, 1, 5, 36, 32, -26, 13, -31], [289, -70, 44, 95, 64, -28, 70, -26, 34], [523, -17, -51, -32, 39, -4, 106, -4, -37], [222, -74, -48, -52, 62, -74, 56, 32, -50], [-258, -55, 91, -71, 149, 46, -10, -34, 15], [440, 234, -14, 144, -68, 58, 108, -16, -52], [815, 173, 80, 52, -219, 68, -120, -7, -22], [684, 1, -46, -19, 52, -61, -53, 26, -30], [11, -59, 4, -164, -49, 26, 140, -23, -24], [144, -113, 26, 3, -24, -25, 31, 30, -38], [751, -56, 55, -51, 46, -66, -60, -67, 15], [223, 9, -155, -204, 27, 16, -80, -30, 17], [-285, -48, 9, -153, 144, -4, 60, 103, 23], [-769, 51, -150, -2, -179, -6, -76, -19, -34], [-370, 361, -132, 71, -31, -126, -140, -13, -152], [-795, -167, -9, -18, 223, 44, 10, 22, 217], [1366, -101, 234, 213, -278, 71, 31, 60, -74], [-857, -212, 252, -161, 102, -60, 78, 24, 126], [-153, 37, 103, 156, -105, -12, -142, -50, 85], [-1687, 131, -268, -124, 353, -100, 176, -39, 130], [-397, -193, -138, 142, 213, 22, 110, 63, 236], [-30, -581, 364, 159, 13, 22, 142, -11, 70], [822, -9, 209, 133, -451, 32, -174, 82, -57], [-953, -679, -100, -326, -249, -38, -344, -31, -280], [-1458, -230, -101, 136, -110, 122, -128, -7, 59], [138, 175, -114, 169, 286, -81, 123, 40, -158], [892, -295, 80, -425, -110, 73, 155, -16, -26], [574, -66, 139, -198, 123, -35, -65, -118, 101], [-2512, -650, 26, 250, 32, -4, -204, -2, -14], [-758, -309, 170, 361, -58, -219, 69, 80, 194], [641, 710, -150, 337, -122, -72, -66, -10, 152], [2349, 792, 339, 369, -14, 108, 182, -31, 135], [953, -77, -203, -50, -493, 136, -16, 10, -427], [-1053, 58, 235, 715, 4, 40, -236, 33, -51], [159, -467, 50, 426, -1, -26, 208, 35, 226], [1444, 298, 70, 638, -150, 404, 216, -116, 154], [-1716, -1427, -222, -281, -149, -206, -152, 95, -26], [518, -328, 21, -708, 349, -279, -361, 158, -33], [2303, 594, -165, 13, -80, -158, -76, 135, -393], [1393, 530, 9, -115, -166, 276, -508, -63, -297], [1993, -807, 378, 396, -41, 40, 88, -11, 136], [-2199, -37, 348, 204, -33, -30, 308, 29, -208], [-315, -652, 216, -263, 403, -17, 141, -95, 216], [1788, -1168, -232, -90, 402, 46, 170, -74, 24], [-1481, -189, 353, 1050, -258, 279, 357, 103, 229], [-2054, 19, 174, 567, -271, 18, -260, 57, -314], [-757, -1098, -841, -319, 554, -80, 332, -89, 33], [1748, 310, -536, -454, 352, 58, 38, -228, 196], [527, -393, 272, 106, 111, 266, -64, 81, -188], [3044, 75, -146, 67, 523, 394, -192, 3, -22], [2461, 1352, 621, -295, 4, -8, -16, -29, 191], [2600, 1126, -314, -192, 276, -52, 658, 96, -220], [2317, 1548, -135, -303, -76, -314, 298, -53, 315], [2533, 18, -530, -235, -539, 311, -165, -69, -128], [1862, -421, -23, -427, -505, -96, -670, 44, -69], [-3159, 154, -210, 209, 401, -115, 65, 231, 152], [-178, 1162, 31, 66, -188, -254, 110, -75, -255], [-2234, -416, -10, 266, 446, 222, 258, 92, -358], [-1659, 1130, -1074, -155, -391, 103, -169, -165, -780], [1618, 1380, -418, 504, -32, -6, -288, -116, 60], [5857, -859, 259, -264, 605, -288, -344, 318, 199], [-2621, -1140, 246, -1121, -134, -236, -538, -62, -424], [404, -906, -510, -426, -286, -570, 90, 200, -274], [480, 276, 852, 888, -372, -84, 320, -64, -56], [408, -407, -337, 451, -1065, 92, -758, -74, 53], [4762, 640, -282, -290, 908, -200, 530, -96, 260], [-1024, -701, -289, -235, -241, -408, -728, 36, -493], [195, -280, -433, -547, 1190, -172, 6, -147, -717], [438, -3718, -272, 536, 342, 122, 786, -42, 72], [394, 172, 264, -1148, -756, 216, -202, 222, -374], [-3980, 702, -37, 508, -555, 3, 829, 40, 145], [3702, -750, -72, 248, -336, 36, 192, 84, 440], [-1161, 6, 1096, 237, -259, -101, -351, -193, 100], [1522, 155, 167, 403, -1271, 170, -136, 268, 553], [-31, -384, -230, 437, -27, 457, 343, -103, 646], [1019, 2795, -756, -782, -5, 104, -430, 201, -268], [7593, 417, 1270, 924, -885, 432, 644, -167, 216], [-7044, 257, -245, -349, -1039, 282, -374, -334, -81], [10842, -398, -370, -1350, 716, -124, 90, 72, 60], [-273, 44, 807, -351, -262, -388, -604, -25, 113], [-4350, 391, 1498, 809, -430, 411, -289, 124, 222], [-2931, 1363, 1697, 1568, -1695, 232, -962, 430, -673], [-1307, -1465, -144, -298, -63, -312, 446, 603, -292], [7162, 730, -1506, -1652, 1208, 494, 250, 6, -58], [6112, 671, -118, -1277, -369, -154, -146, -167, -8], [4918, -194, -1750, -1534, 350, -686, 1180, 258, -736], [-4499, -4520, 565, -837, 800, -50, -464, -47, 657], [-501, 501, 506, 272, 763, 42, -874, 21, 392], [-225, 1415, 395, -708, 1396, 433, 81, -259, 209], [6774, -584, 836, 14, 634, -314, 378, -214, 924], [-152, 2013, -1550, 1267, 123, -254, 472, -269, -194], [-6982, -3404, -1736, -1840, 792, -256, 360, -92, -240], [808, 166, 1100, 1082, -1288, 598, -400, -426, 826], [-5808, 534, 400, 1600, 324, 376, 990, -322, 114], [11423, 123, 222, -1668, 383, -182, -158, -335, 692], [-12414, -1536, 672, 0, -526, -846, 686, 270, 192], [9201, -316, -331, 723, -514, 300, -722, -369, -475], [4876, 1164, 400, -1000, 906, -550, -612, -172, -442], [-889, -1424, 843, -625, 296, 334, 660, 107, 759], [1321, -370, -2051, 87, -228, 54, 856, -7, 525], [-14773, 1732, -283, -71, -312, 674, -66, -385, 251], [2598, -205, 230, -149, -194, -169, -1683, -698, 56], [-1115, 2546, -78, 999, -607, -45, -1891, -347, -94], [5678, 3321, -492, -691, -692, -71, -1185, -130, -178], [6496, -751, 1991, 271, 1095, -52, 438, -94, 13], [4723, -3681, -141, 942, -1391, -764, -50, 624, -711], [4070, 581, -672, -1525, -436, -87, 985, 148, 104], [-1063, -1879, 37, 1304, 1672, 25, 413, -517, 19], [3253, -795, 345, -476, -1524, 657, -855, -209, -1041], [-1215, 373, 0, -656, -1227, 302, -844, 3, -1728], [2158, 2295, 146, 1483, -170, -383, 291, 902, -916], [-18442, 3390, -886, -442, 1650, -820, -136, 348, -78], [6783, -461, 450, 444, 1719, -368, 312, 257, 812], [2058, -3043, -804, 201, 524, -55, 2019, -6, 910], [-4057, 1409, -870, -770, 199, -666, 380, -981, -898], [-1885, 2859, 83, 206, 384, 751, 989, -253, 1779], [-4918, -2561, -170, 495, -527, 38, 1302, -653, -152], [-10580, -149, 2058, 31, -584, -145, 907, 922, 482], [3202, -360, 1314, 58, -498, -978, 14, -572, 898], [2601, -3418, 430, 1979, -240, 1296, -290, -456, -652], [1906, 3670, 3198, 1554, -468, 172, -796, 242, 406], [666, -1473, -1420, 567, 1569, -678, 2260, -17, -1424], [10357, 1757, 480, 834, -219, 962, -1954, 341, -1034], [-5553, 4220, -1328, 755, -738, 720, -206, -16, 230], [5258, -472, 1021, -2480, 566, -350, -854, -967, 1659], [3595, -1368, 74, 853, 3564, 616, 1592, 6, 1126], [2246, -3482, -490, -340, 1746, -266, -238, 248, 1334], [3441, 756, -1412, 1927, -845, -393, 303, 491, -662], [3088, 879, -1494, 429, 224, 229, 839, 1164, -164], [-5408, 1142, 574, -3046, -2040, -618, -1754, 306, -86], [9796, -2876, -660, 694, 1330, -1540, 998, 764, 62], [3010, 738, 1092, -14, 918, 920, 238, 428, 686], [5509, 2190, 690, 403, 932, -148, -830, -904, 1108], [-2104, 604, 1728, 1408, -1266, -400, -806, 1092, -1714], [-2247, -563, 1934, -852, 81, 146, 1248, 125, 270], [-1314, -3122, 289, 1444, -1670, -166, 204, 731, -23], [5365, 3094, 2416, 4401, -834, 756, -1184, 186, 1204], [-13032, 2774, 1780, 1124, -952, 2282, 1026, -340, 2036], [-315, -1325, -1150, -1144, 2941, -1290, 1490, 551, -964], [12867, 3973, 5, 1884, 11, -1552, 1726, 400, 811], [-2265, 7454, -871, 945, -2576, 576, -1486, 81, -595]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_143_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_143_4_a_c();".
// 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_143_4_a_c(:prec:=9)
    chi := MakeCharacter_143_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_143_4_a_c();".
// 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_143_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_143_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-2988, 9710, -2245, -7888, 345, 1144, -12, -59, 0, 1]>],Snew);
    return Vf;
end function;