
// Make newform 198.4.f.d in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_198_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_198_f_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_198_4_f_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_198_4_f_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 := [5856400, 169400, 75340, 2710, 2911, -141, 71, -1, 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], [48229141584676800, -4059658693406480, 8011043329394989, -111071208987556, 28230146638036, -1356924294556, 151013926876, 22554025143], [-66484077419717320, 8498101996878245, -1313471371492594, 12754848436776, -5250112809736, 1256420838616, 955320989289, 14112299722], [426480737760227920, 13624366122837560, 13504262211521188, -772584075715295, 374269556401525, -11662655347575, 5732748190805, -123788106187], [-12007762986133200, 4037135429586600, -523534449789100, 722720174659769, -16065997834439, 2855478562109, -268932734519, 15778904729], [-22785233088495405, 582451195267480, -53736302216310, -38031215360567, -619537249643, -3489045673392, -23011705883, -15728307097], [32952393866979400, 20338656497650260, 1043207365589370, 629078544513089, -18738040845679, 16218883337689, -130622718559, 254952731119]];
    Rf_basisdens := [1, 1, 342693986325717620, 171346993162858810, 685387972651435240, 31153998756883420, 7788499689220855, 31153998756883420];
    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_198_f();"
function MakeCharacter_198_f()
    N := 198;
    order := 5;
    char_gens := [155, 145];
    v := [5, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_198_f_Hecke();"
function MakeCharacter_198_f_Hecke(Kf)
    N := 198;
    order := 5;
    char_gens := [155, 145];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [4, 0, 8, 8, -5, 1, -1, 0], [-1, -2, -1, -1, 1, -2, -1, -1], [18, 0, 8, -6, 16, -3, 3, 2], [7, 3, 7, 16, 0, -3, 0, 3], [-23, 0, 2, 2, 27, -4, 4, 3], [-57, 2, 0, -55, 28, 8, -2, 0], [-42, -6, 76, 0, -76, 0, -6, 6], [-9, 10, 111, -49, 49, 10, -9, -9], [95, -25, 95, 90, 0, -21, 0, 21], [-27, 32, 53, -43, 43, 32, -27, -27], [-81, 24, 0, -57, 18, 17, -24, 0], [276, -7, 174, 0, -174, 0, 14, 7], [178, -9, 0, 169, 8, 12, 9, 0], [89, -47, 89, 64, 0, -39, 0, 39], [-26, 40, -229, 83, -83, 40, -26, -26], [-218, 0, -200, -200, 245, -27, 27, 28], [-19, 59, -102, 0, 102, 0, -51, -59], [-294, 0, -366, -366, 243, 51, -51, -32], [-45, -17, 373, 143, -143, -17, -45, -45], [47, 19, 47, 170, 0, 55, 0, -55], [-537, 0, -306, -306, 549, -12, 12, -92], [434, 61, 374, 0, -374, 0, -26, -61], [-819, -10, -819, 112, 0, 10, 0, -10], [-111, -45, -111, 336, 0, -17, 0, 17], [-41, 52, 559, 855, -855, 52, -41, -41], [-221, 72, 0, -149, 22, 95, -72, 0], [182, -64, -480, 0, 480, 0, -108, 64], [131, -80, 0, 51, -556, 116, 80, 0], [36, 0, -90, -90, -179, 143, -143, -28], [561, 143, -506, 0, 506, 0, -55, -143], [-963, 0, -1268, -1268, 905, 58, -58, 108], [-47, -28, 131, -1169, 1169, -28, -47, -47], [-444, 0, -460, -460, 443, 1, -1, -2], [-310, -107, 0, -417, -248, -64, 107, 0], [-708, -25, 0, -733, -984, 14, 25, 0], [1117, 281, 1117, 1828, 0, 234, 0, -234], [1233, -41, 1233, 446, 0, 111, 0, -111], [-354, 71, 0, -283, -548, -32, -71, 0], [-1241, 144, 0, -1097, 724, 84, -144, 0], [-1760, 0, -448, -448, 1797, -37, 37, -52], [-25, 46, 365, 1425, -1425, 46, -25, -25], [194, 0, -860, -860, -139, -55, 55, 350], [1096, 116, 76, 0, -76, 0, -146, -116], [1942, 60, 2564, 0, -2564, 0, -74, -60], [-643, -38, -643, 742, 0, 146, 0, -146], [1952, 99, 0, 2051, -3152, -182, -99, 0], [96, -404, -373, -1053, 1053, -404, 96, 96], [1059, -263, 1059, 3060, 0, -307, 0, 307], [-581, 516, -581, 2096, 0, -52, 0, 52], [2340, 89, 0, 2429, 84, 266, -89, 0], [-1883, -217, -1202, 0, 1202, 0, 683, 217], [-1291, -269, -1291, 438, 0, 281, 0, -281], [-67, 189, 3115, 4629, -4629, 189, -67, -67], [844, -342, -1808, 0, 1808, 0, 188, 342], [-3116, 0, -2456, -2456, 3119, -3, 3, -386], [-137, 78, -1189, -4537, 4537, 78, -137, -137], [-5053, 507, -5053, -3152, 0, 233, 0, -233], [-1365, 0, -4024, -4024, 2041, -676, 676, -144], [2370, 361, 0, 2731, 1224, 688, -361, 0], [-779, 1052, -1781, -865, 865, 1052, -779, -779], [2436, -255, -3886, 0, 3886, 0, -234, 255], [28, 217, 0, 245, 328, -350, -217, 0], [1423, 0, -2274, -2274, -1483, 60, -60, -155], [1653, -703, 1653, 1120, 0, 199, 0, -199], [2232, -595, 2650, 0, -2650, 0, -90, 595], [-500, 672, 6555, 2239, -2239, 672, -500, -500], [6655, 0, 5788, 5788, -6749, 94, -94, 385], [2800, -493, 0, 2307, 3320, -270, 493, 0], [-395, -153, -22, 0, 22, 0, -921, 153], [-429, 434, -2815, 2933, -2933, 434, -429, -429], [-309, -44, 1439, 1555, -1555, -44, -309, -309], [-6470, 850, -4216, 0, 4216, 0, -648, -850], [-1935, 0, 1378, 1378, 1339, 596, -596, -236], [593, 579, 593, -1102, 0, -191, 0, 191], [625, 558, 2895, 303, -303, 558, 625, 625], [5712, 378, -296, 0, 296, 0, 22, -378], [-3211, 0, 316, 316, 2909, 302, -302, 948], [-4153, -1003, -4153, -8960, 0, -849, 0, 849], [4344, 169, 6682, 0, -6682, 0, 458, -169], [1518, 117, 0, 1635, -1416, 1080, -117, 0], [-4507, -169, -4507, -9058, 0, -223, 0, 223], [50, 1100, 8171, 3551, -3551, 1100, 50, 50], [10150, -100, 6600, 0, -6600, 0, 470, 100], [1055, -12, 0, 1043, 14, -281, 12, 0], [4751, -659, 4751, 1406, 0, -704, 0, 704], [2415, 0, -420, -420, -2937, 522, -522, 204], [-3436, -1270, -4128, 0, 4128, 0, 582, 1270], [6228, 176, 4756, 0, -4756, 0, -576, -176], [-4108, 0, -5074, -5074, 3419, 689, -689, -370], [1244, 0, -1186, -1186, -909, -335, 335, -1066], [3304, -1281, 0, 2023, -4092, -1154, 1281, 0], [1229, -1107, -1671, -3509, 3509, -1107, 1229, 1229], [1591, -999, 4255, 3365, -3365, -999, 1591, 1591], [1360, -679, 0, 681, 6144, -66, 679, 0], [5356, 401, 0, 5757, -7472, 244, -401, 0], [826, -1904, 6789, 6137, -6137, -1904, 826, 826], [8617, 0, 4816, 4816, -9103, 486, -486, 47], [-8709, 1447, -8709, -6848, 0, 1325, 0, -1325], [2265, 684, 0, 2949, -3680, 196, -684, 0], [-1235, 1130, -15993, -1233, 1233, 1130, -1235, -1235], [8687, -178, 8687, 10610, 0, -290, 0, 290], [9413, 666, 0, 10079, -4112, 1688, -666, 0], [-9036, -460, -2456, 0, 2456, 0, 724, 460], [-155, 0, 8902, 8902, 325, -170, 170, -805], [-1076, 236, -889, 4267, -4267, 236, -1076, -1076], [2853, 1171, 6978, 0, -6978, 0, 451, -1171], [276, 0, -4546, -4546, -773, 497, -497, -1660], [-1333, -157, 8337, 831, -831, -157, -1333, -1333], [6527, 145, 6527, 9014, 0, 337, 0, -337], [5140, -1229, 0, 3911, -9856, 1008, 1229, 0], [8893, 1183, -2278, 0, 2278, 0, -1037, -1183], [-4929, 722, 0, -4207, 15536, -1044, -722, 0], [567, 828, -7537, 7623, -7623, 828, 567, 567], [-13161, -80, 0, -13241, 14606, -691, 80, 0], [-2905, 0, -11162, -11162, 4579, -1674, 1674, 32], [7381, 1069, 7381, 6158, 0, -775, 0, 775], [-1189, -80, 8967, 7999, -7999, -80, -1189, -1189], [5435, -359, 6186, 0, -6186, 0, 1779, 359], [-4650, 356, 1992, 0, -1992, 0, 1540, -356], [20445, 875, 20445, 12798, 0, 160, 0, -160], [-2338, 0, -8644, -8644, 2155, 183, -183, -530], [8852, -1940, 4960, 0, -4960, 0, 2112, 1940], [-4451, -1375, -4451, -7236, 0, 540, 0, -540], [-4786, 411, 0, -4375, 200, -80, -411, 0], [9674, 0, 15700, 15700, -8823, -851, 851, -278], [407, 784, 11497, -9139, 9139, 784, 407, 407], [-5476, -198, 3372, 0, -3372, 0, -2712, 198], [-1891, 2550, -5303, -5531, 5531, 2550, -1891, -1891], [-2715, 2873, -2715, -17584, 0, 694, 0, -694], [14402, 0, 7350, 7350, -14489, 87, -87, 558], [-21062, 445, 0, -20617, 11816, 358, -445, 0], [9371, -403, 9371, -6576, 0, 625, 0, -625], [9463, 2401, 9463, 9202, 0, -268, 0, 268], [11766, 1480, 14932, 0, -14932, 0, -1252, -1480], [-12778, 1367, 0, -11411, 15460, 382, -1367, 0], [-813, 0, 9524, 9524, 2817, -2004, 2004, -1083], [14088, 0, 15804, 15804, -13401, -687, 687, -328], [-8911, 0, -3826, -3826, 7563, 1348, -1348, 1759], [-4519, -436, 0, -4955, -4686, -3619, 436, 0], [-277, 316, -1253, 4571, -4571, 316, -277, -277], [-913, -1001, -913, -1054, 0, -1771, 0, 1771], [25767, -997, 25767, 3680, 0, 830, 0, -830], [-785, 488, -23399, 4965, -4965, 488, -785, -785], [7574, -33, 0, 7541, 3944, 974, 33, 0], [-21166, 0, -17052, -17052, 18393, 2773, -2773, -1756], [-238, -61, -2934, 0, 2934, 0, -1682, 61], [-15159, 835, -13418, 0, 13418, 0, 501, -835], [-8166, 0, -5470, -5470, 10079, -1913, 1913, 3204], [17540, 1227, 0, 18767, -19652, -2802, -1227, 0], [-8082, -519, 15046, 0, -15046, 0, -1522, 519], [-12885, -1586, 0, -14471, 4746, 151, 1586, 0], [-3863, 4238, -13023, -14587, 14587, 4238, -3863, -3863], [-6041, 0, 5976, 5976, 2525, 3516, -3516, -571], [-1083, -4541, -1083, -12366, 0, -2957, 0, 2957], [-17396, 0, -9990, -9990, 16201, 1195, -1195, -2098], [5361, 0, -9562, -9562, -6293, 932, -932, -3393], [12989, 875, 12989, -3086, 0, 474, 0, -474], [-3120, 0, 4116, 4116, 4919, -1799, 1799, -4004], [-26213, 1053, 3330, 0, -3330, 0, 1567, -1053], [2853, -657, -16257, 3077, -3077, -657, 2853, 2853], [8522, 1484, 16460, 0, -16460, 0, -3230, -1484], [14142, 151, 0, 14293, 8060, 696, -151, 0], [-6419, -1169, -6419, -4908, 0, 1381, 0, -1381], [-1375, 1518, -15651, 20317, -20317, 1518, -1375, -1375], [-3558, 170, 4700, 0, -4700, 0, 2410, -170], [-2055, -28, 10053, 26025, -26025, -28, -2055, -2055]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_198_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_198_4_f_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_198_4_f_d(:prec:=8)
    chi := MakeCharacter_198_f();
    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_198_4_f_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_198_4_f_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_198_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![68624656, 15739600, 3495696, 260490, 7381, -870, 146, 5, 1]>],Snew);
    return Vf;
end function;