
// Make newform 201.4.a.d in Magma, downloaded from the LMFDB on 18 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_d();".
// 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_d();".
// 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 := [-6656, 3808, 10352, -5472, -2039, 949, 138, -54, -3, 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], [-13, -1, 1, 0, 0, 0, 0, 0, 0], [-7552, -800, 4784, -492, -289, 146, -16, -6, 1], [1024, 1920, 832, -3996, 533, 558, -88, -18, 3], [-928, -4400, 1656, 1912, -411, -206, 36, 6, -1], [-2496, 10880, 1512, -5316, 493, 598, -88, -18, 3], [8192, -640, -11144, 3382, 1409, -486, -24, 16, -1], [-2432, -12960, 544, 12468, -1759, -1674, 264, 54, -9]];
    Rf_basisdens := [1, 1, 1, 640, 320, 160, 320, 320, 640];
    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, 0, 0], [-3, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, -1, 0, 0, 2], [7, 2, -1, 2, -3, -2, 0, 0, 0], [-23, 4, -3, 1, -2, -4, -3, 3, 0], [13, 0, -3, 6, 3, -2, 0, -2, 6], [15, 10, 3, -4, 5, 2, 4, 4, -2], [51, 1, -1, -3, -1, 0, -3, 2, 4], [64, -22, 2, -7, -3, -2, 9, -9, 0], [25, -9, -7, 11, -11, 5, -6, 8, -8], [-24, -19, 0, 8, 11, -11, 9, 3, 2], [44, -33, -10, -4, -9, -8, -12, 21, -2], [23, 1, 13, -8, 4, -9, 1, -5, 0], [61, -34, 1, 9, 28, 6, -3, -11, 6], [-34, -21, -8, -10, 11, 4, 8, -33, 20], [98, -43, -24, -18, -39, -8, 14, 17, 4], [-89, 14, 13, -37, -34, 2, 7, 19, -8], [-67, 0, 0, 0, 0, 0, 0, 0, 0], [353, -26, 17, -9, 10, 6, 23, 3, 6], [-123, -21, 7, 20, -6, 19, 15, -51, -4], [294, -24, 14, -39, -21, -10, 5, 5, 16], [132, -49, 4, -12, 17, 0, 26, 17, -40], [85, -2, -31, -36, -3, -18, -38, 34, 26], [-181, 4, 31, 32, 49, -30, 16, -18, 104], [249, 46, 15, 88, 15, -20, 40, -36, 6], [-81, -34, -7, -16, -7, 0, 50, -4, 36], [729, 50, 27, -14, 1, 10, -38, -18, -6], [63, 54, -13, 17, -42, 32, -51, 53, 20], [-91, 116, -61, -20, -53, -44, -50, 86, -60], [415, -102, -17, 56, -141, -50, 2, -8, -48], [215, 55, -13, 14, -6, 52, -60, 81, -32], [-288, 169, 2, -92, 7, -44, -10, 19, -32], [-50, -149, -64, -90, -25, -47, -25, 75, 6], [654, 30, -80, -53, -59, 90, 43, -87, -156], [1179, -172, 57, 66, 121, 112, -4, -60, -8], [-339, 51, -39, -18, -112, -33, 51, 39, -104], [524, -152, -152, -88, -84, -6, -86, 24, -4], [707, 407, -15, 127, 61, -28, 33, -118, 40], [505, -120, -99, 5, -38, 34, -19, 29, 26], [533, 272, 69, 18, -9, -22, -60, 206, -60], [-370, 167, -70, -82, -57, 177, 27, 31, -126], [504, -420, -56, 14, -76, -240, 10, -42, 196], [427, 15, -49, -176, -126, 179, -45, 81, -138], [624, 73, 0, -100, -145, 100, 84, -77, 4], [1214, -336, -62, -52, 194, -110, -70, 16, -64], [236, 292, 150, -262, 270, 32, 26, -66, -6], [-494, 510, -44, 60, -46, 124, 50, -90, -100], [764, 341, 252, 166, 149, 0, -72, -123, 108], [-2350, 416, -92, -27, 3, 14, -123, 85, -88], [-2471, -181, 17, 110, 110, -32, 102, -51, -108], [1086, 586, -78, -284, 90, 4, 28, -30, -12], [-1022, -115, 82, 132, 9, -49, 65, -73, 140], [-1758, 184, 154, 76, -320, 4, 24, 80, -28], [-1810, 226, 188, 60, 308, -166, 22, 210, 256], [-410, -135, -52, -313, -154, 164, -19, 290, -364], [-639, -796, 57, -93, 2, -64, 113, 51, 70], [318, -300, 142, 153, 527, -62, 29, -519, 340], [-1471, 353, 265, 4, 164, 41, -65, -229, -36], [547, 242, 233, 376, 161, -100, 40, -192, 454], [-149, -588, -221, 66, -145, 184, -66, 80, -148], [728, -320, 162, 13, -307, 242, 57, -163, -80], [-316, 114, 26, -262, 116, -88, 202, 76, 90], [299, -418, 209, -156, 137, -24, -156, -22, 78], [-3329, -110, 129, 168, -71, -250, -34, 200, -56], [-503, 724, 301, -159, 278, 194, 29, -431, -62], [1245, -885, -409, 40, -410, 251, 33, -219, -272], [189, -66, 251, -282, -379, 194, 220, 306, -80], [-2290, 258, -116, 450, 186, -400, 78, -132, 134], [-5072, -89, -424, 114, -167, -215, 127, 235, -90], [4757, 99, 289, 354, 12, 24, -88, -319, 190], [13, 189, -267, 41, 21, 432, -139, 250, -612], [-1720, 44, -176, -31, -563, -238, -183, -31, 296], [-2415, -174, -397, -279, 238, 194, -3, 25, 0], [3034, 655, 312, 22, 369, 251, -31, -449, -174], [-40, 632, 0, 474, 470, -214, 144, -154, -192], [-1239, 1078, -547, 87, -238, 372, 41, -39, -158], [-2900, 588, -34, -494, 128, 524, -146, -166, -456], [1790, -1065, -274, 280, -23, -196, -200, 201, -412], [3734, 190, -62, 474, -54, -120, -360, -60, 424], [1245, -87, -353, -386, -360, -532, -22, 283, 292], [-3107, 759, 445, 558, 806, -179, -23, -197, 556], [5334, -1459, -254, 281, -102, -500, -343, -120, 36], [2452, 1098, 660, 218, 360, -24, 372, -464, 396], [2416, -528, 32, 306, 154, -682, -36, 130, -56], [4535, 150, -323, -496, -187, 90, -110, 294, -318], [-143, -866, -435, -502, -239, 168, -54, -228, -210], [-5746, -238, -146, 76, -162, -784, -232, 118, 482], [-1442, -1350, -540, 71, -339, 228, -119, -523, -48], [-1348, -501, 600, 959, 222, -561, -398, 276, 126], [-1449, 202, 19, 48, -77, -190, 374, 712, 42], [1656, -2429, -684, -433, -368, -24, 87, 240, 200], [3901, 1615, 1, 173, -155, 63, 658, -486, -236], [4210, 319, 566, 184, 55, 88, -146, 5, 308], [1270, -408, 194, -106, 906, 446, 124, -566, 28], [-2641, 184, 605, -442, 1037, 278, 56, 86, 138], [469, 60, -939, 343, -152, -192, -127, -65, -310], [2203, -88, 203, -60, 843, 144, -256, -426, 20], [-5445, -34, -725, -246, 129, -310, -12, -338, 84], [1518, 1160, -840, -193, -135, 334, 535, -373, -348], [-7718, 1253, 464, -464, 451, -45, -161, -17, 370], [2207, 1104, 1219, -371, 528, -60, 523, -459, 242], [3515, 1532, 1701, 688, 701, 208, 404, -304, -10], [1915, 1394, -1277, 506, -1577, -1316, -646, 660, 226], [239, -1564, -687, 846, -987, -602, -454, 936, -1028], [10, 924, -100, 368, 720, 626, -78, 92, -412], [-2230, 278, 156, 698, 332, -36, 114, -888, 298], [4734, -33, 940, 52, -277, 152, -278, -499, 136], [5337, -1020, 63, 304, 1241, 800, 280, -584, -286], [-5968, 2322, -188, 444, 734, -230, -362, -662, 122], [-959, 3756, 1159, 100, -31, -110, -452, 822, 648], [-497, -1491, 123, -388, -138, 849, -157, 59, -460], [-213, 1528, -441, -840, -1433, -160, 248, 96, -494], [2679, 1372, 637, -344, 845, 780, 760, -410, 150], [6676, -376, -732, -523, -681, -416, -185, 353, -196], [3249, 739, -413, -334, 200, 356, 944, -311, -124], [1251, 2292, -729, 392, 159, -426, -960, 370, -198], [-1188, -2058, -24, 546, -580, -686, -76, -400, 404], [-423, 667, 217, 902, 756, -1504, -534, 1317, 692], [1341, -717, -507, -120, -546, 1352, 74, -501, 280], [3116, -684, 566, 67, 1147, -802, 775, -853, 508], [-589, -3352, 969, -128, 383, -230, 82, 354, -348], [3133, -1477, -173, -158, 454, 688, 292, 361, -1596], [5625, -3878, -105, -128, 107, -852, -204, 1038, -674], [580, -34, -792, 160, -222, -182, -126, -986, -136], [-3557, 127, -1491, 146, -272, -612, -1448, 869, -648], [-1897, -1143, -857, -1416, -116, -485, -1123, 891, -524], [7168, 337, -258, 735, 1288, 684, 5, -1058, 364], [-5871, 391, -3, 3, 1157, 209, -458, 288, 620], [2024, -4512, -1142, -911, -671, -416, -921, 913, -172], [4411, -4289, -955, 1394, -1218, -305, 123, 27, 320], [6531, 3617, 551, -965, 1113, 740, 771, -860, 708], [12678, -82, -1116, 1350, 40, -434, -642, -184, 636], [-1694, -2916, -298, -293, -17, 458, -359, -649, 164], [1792, 704, 766, -858, 300, 458, 308, 574, -1760], [-3835, -2208, 773, -228, 1615, -976, 402, -698, 104], [4072, 142, -234, 765, 3, -422, 273, 415, 912], [5763, -307, 713, -294, -1720, 1293, 21, -1623, -480], [1415, 150, 2779, -175, 1724, 462, 457, -1269, 198], [14568, -1593, -208, -40, 1263, 176, -320, 45, -56], [15669, 2289, -293, 742, 286, 49, -239, -723, -580], [7354, -1334, 756, 1301, 655, 246, 81, -213, 1452], [14449, -2860, 261, -1608, -685, 1126, -514, 330, -1704], [-3151, 542, -351, -782, -1297, -954, 528, 342, 354], [1820, -3104, 54, 116, 484, -706, 962, -300, -632], [-6703, 3418, -619, 449, 296, 1838, -227, -819, -1182], [-2562, -3880, 160, 1366, 998, -568, 1014, -1602, 812], [-11973, 1827, 1127, -78, 802, 428, -524, 633, -298], [-1019, 1670, -863, -1460, -533, 644, 546, 276, 54], [-2000, -435, -418, -343, -618, -76, 499, -348, 20], [1258, 4316, -232, -226, -710, 636, -982, 1274, -476], [-2144, -4878, 890, 1860, -278, 136, -736, 742, -416], [-14301, -697, -3291, -126, -1664, -191, -99, -529, -296], [7288, -613, -230, -1015, -912, 372, -1101, -998, -508], [10316, 1186, -294, -598, 596, 26, 592, -2384, 142], [-3667, 4202, 229, -1203, -184, 398, 621, -579, -1150], [2747, -2703, 443, 83, -3, 95, 44, 522, 536], [-893, 3332, -597, 672, -437, -952, 352, 1042, 464], [375, -1426, 219, -1182, 761, 1150, -498, 254, 120], [-6401, 366, -1507, 404, -2923, 1028, -408, 628, 386], [-6319, -6035, 287, 418, 1320, 352, -922, -701, 252], [-9072, 1554, -1166, 170, -392, 1592, 1158, -1296, -280], [-11127, -5476, 1001, -1386, 1345, -348, 1850, -116, -1416], [-9393, 2654, -693, 2882, 277, -802, 864, -1870, 882], [4798, -7668, -784, 558, 84, 288, 34, 178, -436], [-18918, -1288, 646, 1444, -554, 560, 668, -824, -824], [812, 5857, 472, 1047, 192, -2031, 400, 1946, 1074], [-19138, -1253, 3042, -1662, 1, 1043, 869, 575, 542]];
    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_d();".
// 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_d(:prec:=9)
    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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_201_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-6656, 3808, 10352, -5472, -2039, 949, 138, -54, -3, 1]>],Snew);
    return Vf;
end function;