
// Make newform 201.4.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_201_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_201_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_201_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 := [498, -956, -151, 373, 18, -38, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [-11, -1, 1, 0, 0, 0, 0], [1966, -6314, -408, 1339, 27, -47, 1], [17954, -5250, -9139, 310, 956, 10, -25], [4818, -4554, -7389, 434, 1152, 14, -35], [32134, 13418, -23919, -2556, 3010, 128, -87]];
    Rf_basisdens := [1, 1, 1, 466, 932, 932, 1864];
    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_201_a();"
function MakeCharacter_201_a()
    N := 201;
    order := 1;
    char_gens := [68, 136];
    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_201_a_Hecke(Kf)
    return MakeCharacter_201_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], [-3, 0, 0, 0, 0, 0, 0], [1, 0, -1, 0, 0, 1, 0], [-4, 0, 0, 0, 1, -2, -1], [-19, 3, -2, 0, 1, -1, 2], [1, 8, 1, -1, -4, 3, -1], [12, 13, 5, -2, -2, 2, 2], [-20, 3, 5, 8, -2, -4, 2], [-60, 1, -3, -3, 8, 6, -5], [-33, -15, 10, -13, -10, 1, 1], [-71, 7, 6, -10, -8, -7, -5], [51, 11, 16, -1, 11, -21, 12], [-110, -33, -15, 14, 5, 8, -14], [-35, -34, -7, 9, -9, 3, -16], [-138, -60, 8, 1, 7, -16, 29], [30, -31, -5, 2, 27, 16, -24], [-35, -71, 12, 14, -2, 11, 20], [61, -48, -35, -29, 46, 15, -29], [67, 0, 0, 0, 0, 0, 0], [-161, 32, 17, -45, -40, 31, -23], [136, -16, 0, 55, 44, -50, 16], [-326, -67, -21, -71, -51, -16, -15], [-396, 101, -13, 4, -29, 32, -22], [-214, 7, 45, 16, 52, -56, 68], [-113, 59, -46, -6, -53, -17, 82], [-269, -63, -64, -6, 111, -29, -72], [3, -163, -14, -16, -55, 141, -18], [-126, 241, 9, 78, 82, 6, 14], [39, -194, -67, 49, -62, 45, -59], [-125, 31, -82, 12, -3, 31, 84], [-372, -15, 27, 138, -14, 4, -38], [-839, -138, -5, -80, -78, 15, -30], [-570, 65, -13, 40, -69, -64, 30], [196, 145, 105, 137, 158, -96, -6], [-625, 199, 28, 63, 178, -127, -43], [-296, -99, -137, -32, 50, 196, -216], [924, -58, 146, -81, 4, -86, 26], [-531, 20, 5, -144, -57, 135, -48], [-947, 49, -98, -155, -55, 45, 91], [318, 238, 148, 29, 149, -302, -29], [-751, 41, 132, -56, -73, 67, 34], [-383, 61, 40, 117, -79, -175, 118], [-726, 792, -2, 74, 184, -14, 110], [322, 324, 90, -81, -140, 160, -12], [-302, -95, -57, -142, -7, -136, -110], [-713, -286, -307, 288, 177, 201, -88], [-612, 16, 48, -82, -264, -80, 210], [251, 280, -45, 20, -89, 125, 276], [1211, -511, -138, 76, -262, 157, 184], [170, 111, 163, -47, 247, -246, -171], [-17, -18, -121, 174, 26, 55, -86], [-60, 462, 150, 120, 94, -384, 152], [2359, -133, 172, -85, -199, -129, 44], [2410, -464, 142, 40, 186, 150, 192], [1453, 256, 19, 16, 55, -135, -52], [-50, -570, -382, -297, 20, 340, -59], [1211, -752, -369, -179, -280, 145, -209], [-284, -649, 319, -109, -247, -30, 227], [3839, -118, 77, 177, -15, -345, 64], [-833, -893, -266, -314, -13, -57, -128], [-1398, -1251, -487, -454, 134, 342, -388], [1584, 149, -165, 153, -83, -420, 305], [393, 370, -161, 120, -161, -269, 270], [-609, 385, -310, 328, -131, 209, 320], [2841, -447, 74, 500, 489, 169, 22], [2601, 270, 347, -281, -112, 107, -29], [245, 634, -251, 477, 237, -105, -184], [427, 1597, 460, -306, 17, -817, 268], [-2172, -524, 220, 506, -306, -476, 102], [-84, 431, -195, -77, 388, -366, 102], [665, -362, 113, -256, 260, -219, 154], [-4492, 317, -11, -537, -518, 98, 161], [536, 153, 65, -301, -359, 62, 427], [1005, -1928, -15, -139, -612, -5, -255], [-3384, 249, 129, 243, 320, -508, 438], [-3200, -1170, -118, 0, -432, -44, -246], [-1203, 370, 763, 287, -118, -29, 49], [5965, 376, 95, 388, 109, 33, 234], [2122, 575, 509, 582, -105, 40, 786], [1384, -48, 550, 76, 180, -670, 350], [-2308, 2532, 208, -480, -403, -172, -326], [1810, 382, 76, -51, -360, 684, 6], [-101, -1476, 473, -33, -269, -89, 5], [3170, -158, 142, 168, -354, 972, -694], [-555, -1066, -493, -858, 305, 623, -1022], [-71, 233, -180, -166, -955, 575, 328], [-6672, -281, -13, 796, 298, -202, 458], [3323, 320, -135, -494, -823, 1087, 96], [-4285, -141, -520, -535, -944, 933, -307], [-3396, 310, -286, 592, 719, 274, -525], [1605, -57, 330, -180, 309, 231, 780], [-2435, 1882, 137, 381, 637, -311, -205], [1289, 697, 36, 302, 424, 449, -99], [-751, 119, 434, 314, 40, -141, -238], [-5140, 2028, -204, -228, -460, -652, 694], [-835, -947, -172, -712, 729, 171, -1218], [0, 1326, 338, -833, -859, 1352, -113], [-6305, -3469, -1078, -390, 591, 907, -1188], [-9990, -2305, -389, -820, -238, 726, -624], [1916, 1235, -519, 373, -295, -824, 429], [2688, 3505, -243, -595, 328, -508, -40], [1851, -930, 181, 947, -346, 61, 325], [-2981, 1153, -502, -756, 1035, -515, -60], [360, -1419, -1019, 908, -26, 670, -718], [-2366, 1737, 237, 450, 430, 310, 852], [8620, 1584, -402, -1074, -592, 1178, -1168], [3688, 1334, 702, -370, 54, -1144, -42], [-5072, 1701, 193, 64, -657, -966, -66], [-2967, -343, 292, 308, -1275, -605, 744], [2811, 738, -869, 904, -377, -417, -76], [-2967, 2969, 72, 646, -517, 487, -202], [192, 3380, -320, -301, -602, 554, 316], [-950, 461, 419, -786, -908, -344, 80], [4511, 2885, -1158, 1126, 647, -359, -234], [-8826, 2761, 131, -803, -1315, 844, -273], [3577, -2400, 531, 884, 1918, -715, -310], [651, -2495, 530, 346, 951, -979, 398], [3590, -2600, -394, 308, 212, 498, -1118], [-9865, 3084, 517, 138, 230, -601, 298], [4414, -2182, 740, 480, -1351, 934, 976], [2002, -2587, -611, -1255, 631, 866, -1755], [-669, -361, 486, -260, -447, 1427, -986], [-423, -2474, 417, -552, -34, -567, 1246], [5057, 247, 330, -356, 591, 1039, -120], [745, 458, 363, 52, -431, 2043, 680], [-2533, -2732, 405, -236, -1516, 1027, 1210], [-2515, 2708, -1371, -809, -1159, 601, 972], [-6807, 2756, -21, 777, 95, 1809, -1427], [2211, 2117, -474, 64, 264, -205, 361], [10712, -1075, -353, 503, 1663, 872, 65], [-18613, 446, -365, 107, 213, 589, -498], [2163, -2003, -52, 1279, 2527, 23, -325], [-15169, -946, -607, 108, 1175, -91, 650], [-5906, 775, 99, -433, 1193, -678, -699], [1349, 2816, -801, -878, 1783, -1907, -658], [-8365, 1849, 276, 1388, 153, -509, 1990], [9283, -1383, -310, 369, -1520, -623, -457], [-10789, -8, 1125, -535, -439, -579, 794], [-4211, 2132, 665, 975, -1306, 439, 715], [6382, -2031, -137, -386, 375, 840, 954], [-6293, 3918, -705, -1227, -1839, -195, -830], [7689, 2079, -1082, 875, 576, -1673, -219], [-13286, -3819, 797, 614, -670, 630, 94], [6800, -5741, -479, 804, 274, -2632, -514], [8269, 2850, 741, -1464, -2391, 2709, 196], [-1208, 5342, 228, -673, 859, -2686, -457], [11775, -2634, -1125, 1392, 771, 663, 146], [-4469, -1892, -1587, 32, 22, 1871, -2398], [-2811, -831, 1736, 1820, 877, -925, -1482], [1313, 9506, 585, 55, -435, -1739, 1503], [9079, -3326, 47, -620, -797, 15, 2106], [-8585, 6486, -349, -690, -485, -1745, 320], [4315, -5430, 1355, -331, 595, 1913, -1162], [6289, -2078, -811, -1371, -1279, 25, -1151], [7583, -7958, -31, -1214, 115, -843, -646], [2784, -4860, -814, 829, 1769, 2006, -1763], [-5719, 3497, 3028, 1286, 10, -1423, 1277], [-5455, -4409, -1232, -654, -87, 1241, -2244], [2855, 2367, -654, 192, 71, -949, -1124], [-1345, -2137, -1042, 1814, 3003, -2757, -264], [20910, 3152, -1490, -964, 1667, 754, -974], [5865, 2236, -29, -988, -2929, 841, 1150], [5989, -1393, -246, -476, -1343, -753, -1228], [21994, -3055, 549, -1660, 396, -1594, 1722], [11765, -2084, -521, 528, 849, -1747, 174], [-8194, -3658, 352, 720, 370, -4954, -712], [-19766, -2910, 1188, -372, -297, 1392, 325], [21794, 301, -55, 265, 684, 1964, 126]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_201_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_201_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_201_4_a_c(:prec:=7)
    chi := MakeCharacter_201_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_201_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_201_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_201_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-498, -956, 151, 373, -18, -38, 1, 1]>],Snew);
    return Vf;
end function;