
// Make newform 242.4.c.n in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_242_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_242_c_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_242_4_c_n();".
// 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_242_4_c_n();".
// 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_242_c();"
function MakeCharacter_242_c()
    N := 242;
    order := 5;
    char_gens := [123];
    v := [4];
    // 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_242_c_Hecke();"
function MakeCharacter_242_c_Hecke(Kf)
    N := 242;
    order := 5;
    char_gens := [123];
    char_values := [[0, 0, 0, 1, 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, 0, -2, 0, 0, 0], [-1, 0, 0, 0, 1, 0, 0, 1], [0, 1, 8, 4, -4, 1, 0, 0], [-2, 2, -2, 0, 0, 3, 0, -3], [0, 0, 0, 0, 0, 0, 0, 0], [7, -3, 0, 4, 6, 3, 3, 0], [3, 1, 1, -25, 25, 1, 3, 3], [-34, 0, 21, 21, 36, -2, 2, -6], [42, -6, -70, 0, 70, 0, -6, 6], [-50, 10, -50, 120, 0, 1, 0, -1], [-95, 21, 0, -74, -20, 25, -21, 0], [-48, 32, -48, 80, 0, 5, 0, -5], [11, 0, -46, -46, -35, 24, -24, -7], [-255, -7, -167, 0, 167, 0, 14, 7], [-29, 0, -198, -198, 20, 9, -9, -21], [89, -39, 0, 50, 22, -47, 39, 0], [-69, -40, -69, 203, 0, -14, 0, 14], [-28, 1, -228, 18, -18, 1, -28, -28], [91, -59, -43, 0, 43, 0, 51, 59], [32, 19, -334, -72, 72, 19, 32, 32], [-205, 17, -205, -418, 0, 62, 0, -62], [47, 55, 0, 102, 104, 19, -55, 0], [-92, 104, 214, -231, 231, 104, -92, -92], [-521, 61, -435, 0, 435, 0, -26, -61], [819, -10, 0, 809, -941, 10, 10, 0], [111, 17, 0, 128, -492, 45, -17, 0], [844, 52, 844, 600, 0, 11, 0, -11], [45, 0, -104, -104, -117, 72, -72, 23], [-226, -64, 544, 0, -544, 0, -108, 64], [360, 0, 309, 309, -440, 80, -80, -196], [28, 115, -62, -126, 126, 115, 28, 28], [759, -143, -363, 0, 363, 0, 55, 143], [-108, 166, -1376, -305, 305, 166, -108, -108], [1094, 28, 1094, -178, 0, 75, 0, -75], [-2, 1, 458, 16, -16, 1, -2, -2], [205, 0, 622, 622, -312, 107, -107, -43], [-945, 0, -1678, -1678, 970, -25, 25, 39], [-1117, -234, 0, -1351, -430, -281, 234, 0], [-1233, -111, 0, -1344, 746, 41, 111, 0], [-651, 0, -934, -934, 580, 71, -71, -103], [-664, 0, 433, 433, 808, -144, 144, 60], [-52, 89, 396, -1312, 1312, 89, -52, -52], [-1404, -46, -1404, -390, 0, -21, 0, 21], [-350, 295, -1210, -1054, 1054, 295, -350, -350], [1358, -116, 192, 0, -192, 0, 146, 116], [2076, -60, 2624, 0, -2624, 0, 74, 60], [-643, 146, 0, -497, 1423, -38, -146, 0], [-3433, 0, -1382, -1382, 3334, 99, -99, -281], [-745, -404, -745, -469, 0, -308, 0, 308], [-1059, 307, 0, -752, -2264, 263, -307, 0], [581, 52, 0, 633, -2161, -516, -52, 0], [261, 0, 2690, 2690, -350, 89, -89, 177], [2783, -217, 1419, 0, -1419, 0, 683, 217], [-1291, 281, 0, -1010, 1998, -269, -281, 0], [-4507, -189, -4507, -3182, 0, -122, 0, 122], [314, 342, -2150, 0, 2150, 0, -188, -342], [386, -389, -2070, 660, -660, -389, 386, 386], [4478, -78, 4478, 1052, 0, 59, 0, -59], [-5053, 233, 0, -4820, 1394, 507, -233, 0], [-144, 820, 3880, 2659, -2659, 820, -144, -144], [-1551, 0, -4282, -4282, 1912, -361, 361, -327], [-1138, 1052, -1138, -1002, 0, 273, 0, -273], [-2415, -255, 4141, 0, -4141, 0, -234, 255], [239, 0, -6, -6, -22, -217, 217, 567], [-155, 95, 2119, 3697, -3697, 95, -155, -155], [1653, 199, 0, 1852, 170, -703, -199, 0], [1727, 595, 2055, 0, -2055, 0, 90, -595], [-2067, -672, -2067, -7055, 0, -172, 0, 172], [385, -479, -5403, 867, -867, -479, 385, 385], [-3543, 0, -5850, -5850, 3050, 493, -493, -223], [-373, -153, 175, 0, -175, 0, -921, 153], [2928, 434, 2928, -2386, 0, 5, 0, -5], [1908, -44, 1908, 1748, 0, -353, 0, 353], [4972, 850, 3366, 0, -3366, 0, -648, -850], [-236, -360, -1614, -3313, 3313, -360, -236, -236], [593, -191, 0, 402, -2274, 579, 191, 0], [880, -558, 880, -2270, 0, -1183, 0, 1183], [6068, -378, 82, 0, -82, 0, -22, 378], [-948, 1250, -632, 3527, -3527, 1250, -948, -948], [-4153, -849, 0, -5002, -3804, -1003, 849, 0], [-4055, 169, -6851, 0, 6851, 0, 458, -169], [-453, 0, 1182, 1182, 336, 117, -117, 963], [4507, 223, 0, 4730, 4382, 169, -223, 0], [2401, 1100, 2401, 8121, 0, 1150, 0, -1150], [-9580, -100, -6500, 0, 6500, 0, 470, 100], [255, 0, -788, -788, -267, 12, -12, 269], [4751, -704, 0, 4047, -2686, -659, 704, 0], [-204, 726, -624, -2835, 2835, 726, -204, -204], [-5288, 1270, -5398, 0, 5398, 0, -582, -1270], [6980, -176, 4932, 0, -4932, 0, 576, 176], [370, 319, -4704, -966, 966, 319, 370, 370], [-1066, 1401, 120, 2430, -2430, 1401, -1066, -1066], [-3965, 0, -1942, -1942, 5246, -1281, 1281, 127], [-3631, -1107, -3631, -2900, 0, 122, 0, -122], [2773, -999, 2773, 2664, 0, 592, 0, -592], [6757, 0, 7438, 7438, -6078, -679, 679, 613], [7629, 0, 1872, 1872, -7228, -401, 401, 157], [-7215, 1904, -7215, -5963, 0, 1078, 0, -1078], [-47, 533, 4769, -3801, 3801, 533, -47, -47], [-8709, 1325, 0, -7384, 414, 1447, -1325, 0], [4168, 0, 1219, 1219, -3484, -684, 684, 488], [-1128, 1130, -1128, -14758, 0, -105, 0, 105], [-8687, 290, 0, -8397, -2101, 178, -290, 0], [-3090, 0, 6989, 6989, 2424, 666, -666, 1022], [10220, -460, 2916, 0, -2916, 0, 724, 460], [-805, 975, -9707, -9057, 9057, 975, -805, -805], [-5107, -236, -5107, -187, 0, 840, 0, -840], [3573, -1171, 8149, 0, -8149, 0, -451, 1171], [1660, -1163, -2886, -4822, 4822, -1163, 1660, 1660], [-2321, 157, -2321, -9670, 0, 1490, 0, -1490], [6527, 337, 0, 6864, 2342, 145, -337, 0], [7619, 0, 3708, 3708, -8848, 1229, -1229, -2237], [-11113, 1183, 1095, 0, -1095, 0, -1037, -1183], [13770, 0, 9563, 9563, -14492, 722, -722, -1766], [6228, 828, 6228, -8104, 0, 1395, 0, -1395], [-13995, 0, -754, -754, 13915, 80, -80, 611], [32, 1642, 11194, 8257, -8257, 1642, 32, 32], [7381, -775, 0, 6606, -2292, 1069, 775, 0], [-9268, 80, -9268, -10156, 0, 1269, 0, -1269], [3297, 359, 5827, 0, -5827, 0, -1779, -359], [-5834, -356, 2348, 0, -2348, 0, -1540, 356], [20445, 160, 0, 20605, -8522, 875, -160, 0], [-530, 347, 8114, 6306, -6306, 347, -530, -530], [-4800, -1940, -3020, 0, 3020, 0, 2112, 1940], [4451, -540, 0, 3911, 1410, 1375, 540, 0], [-291, 0, -4666, -4666, -120, 411, -411, -491], [-278, 1129, -15978, -6026, 6026, 1129, -278, -278], [10330, -784, 10330, -11090, 0, -1191, 0, 1191], [-2962, 198, 3174, 0, -3174, 0, 2712, -198], [6190, -2550, 6190, 3412, 0, -659, 0, 659], [-2715, 694, 0, -2021, -17742, 2873, -694, 0], [558, -645, -6792, 7052, -7052, -645, 558, 558], [11729, 0, -8888, -8888, -12174, 445, -445, -87], [-9371, -625, 0, -9996, 15544, 403, 625, 0], [-9463, 268, 0, -9195, 2662, -2401, -268, 0], [-14498, 1480, -16412, 0, 16412, 0, -1252, -1480], [-14475, 0, -3064, -3064, 15842, -1367, 1367, 985], [1083, -3087, 10607, 10337, -10337, -3087, 1083, 1083], [328, -1015, 16132, 1716, -1716, -1015, 328, 328], [1759, -3107, 5585, -5085, 5085, -3107, 1759, 1759], [7869, 0, 12824, 12824, -8305, 436, -436, 3183], [4532, 316, 4532, -976, 0, 39, 0, -39], [913, 1771, 0, 2684, -860, 1001, -1771, 0], [-25767, -830, 0, -26597, 21090, 997, 830, 0], [5262, 488, 5262, -22614, 0, -297, 0, 297], [-4951, 0, -12492, -12492, 4918, 33, -33, -1007], [1756, 1017, -15296, 4114, -4114, 1017, 1756, 1756], [1383, 61, -2995, 0, 2995, 0, 1682, -61], [-14825, -835, -12583, 0, 12583, 0, -501, 835], [-3204, 1291, -8674, 2696, -2696, 1291, -3204, -3204], [23681, 0, 4914, 4914, -22454, -1227, 1227, 4029], [7079, -519, -14527, 0, 14527, 0, -1522, 519], [6483, 0, -7988, -7988, -4897, -1586, 1586, 1737], [-14962, 4238, -14962, -9160, 0, 375, 0, -375], [-571, -2945, -6547, -12017, 12017, -2945, -571, -571], [-1083, -2957, 0, -4040, -6742, -4541, 2957, 0], [2098, -903, -7892, 7406, -7406, -903, 2098, 2098], [3393, -2461, -6169, -14923, 14923, -2461, 3393, 3393], [12989, 474, 0, 13463, -16950, 875, -474, 0], [-4004, 5803, -8120, -7236, 7236, 5803, -4004, -4004], [26727, 1053, -4383, 0, 4383, 0, 1567, -1053], [881, -657, 881, -19110, 0, 2196, 0, -2196], [-13236, 1484, -17944, 0, 17944, 0, -3230, -1484], [-8605, 0, -22898, -22898, 8756, -151, 151, -545], [-6419, 1381, 0, -5038, 2680, -1169, -1381, 0], [-20174, -1518, -20174, 14276, 0, -143, 0, 143], [-5798, -170, 4870, 0, -4870, 0, -2410, 170], [-28108, 28, -28108, -12108, 0, 2083, 0, -2083]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_242_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_242_4_c_n();".
// 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_242_4_c_n(:prec:=8)
    chi := MakeCharacter_242_c();
    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_242_4_c_n();".
// 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_242_4_c_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_242_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![4748041, -895569, 115218, 65, 4301, 395, 92, 7, 1]>,<5,R![68624656, 29905240, 6892136, 964060, 106181, 7795, 556, 30, 1]>,<7,R![87027360016, -559917592, 205495772, -1168230, 318211, 915, 408, 4, 1]>],Snew);
    return Vf;
end function;