
// Make newform 147.4.c.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_147_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_147_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_147_4_c_a();".
// 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_147_4_c_a();".
// 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 := [531441, -59049, 0, -21141, 486, -441, 1564, -49, 6, -29, 0, -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, 0, 0, 0], [575491554, 410108427, 112284954, -82640331, -21396420, -2790145, 441628, 617943, 226448, -13815, -17114, -661], [255288510, 4113747, -5390226, -3432699, 2301324, -658001, 289700, -24405, 6088, -627, 5426, -857], [-1990167813, -260970336, -101793915, 46012374, 18485199, 3357106, -3622009, -468246, -216551, 15948, 15515, 2476], [-11337408, -6029559, 1909980, 1014363, 212958, -54343, -28370, -14415, 1790, 1107, 220, -31], [-1904802642, 284920173, 249912378, 27320031, 386256, 2276065, -2788588, 322857, 231268, 7683, -9850, 3517], [151814979, -13338513, 1371249, -7836021, -1005399, 641129, 227449, 82569, -6421, -6255, -209, 1523], [4735611702, -1942311879, -574520526, -106799229, 108193104, 15441661, 8001092, -3032283, -1174508, -97641, 87566, 6025], [-1125769185, 536512653, -211205151, 265284153, 29481381, 15016199, -6287543, -77001, -558841, 346095, 32191, 23393], [1611033867, -145536102, 444340809, 49790376, -6563745, -31906828, 585763, 11964, 719729, 146502, 2263, -25402], [-12282192, 5662143, 594864, 657801, -277146, 85231, -30454, 6711, -2906, 657, -112, 103], [4723920, -2670327, 734832, -17577, -95958, -58247, 9974, -399, 2026, 207, -112, -95]];
    Rf_basisdens := [1, 489398112, 81566352, 163132704, 1889568, 163132704, 54377568, 163132704, 489398112, 489398112, 1889568, 944784];
    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_147_c();"
function MakeCharacter_147_c()
    N := 147;
    order := 2;
    char_gens := [50, 52];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_147_c_Hecke();"
function MakeCharacter_147_c_Hecke(Kf)
    N := 147;
    order := 2;
    char_gens := [50, 52];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, -1, -2, 0, 0, 0], [0, 0, -9, 0, 0, 3, -2, 0, 0, -2, 0, 0], [0, 0, 0, 0, -4, 0, -9, 0, 0, 9, 0, 0], [0, 0, 17, 0, 0, 1, -1, 0, 0, -1, 0, 0], [0, 14, 0, -5, 0, 0, 0, 0, 5, 0, 0, 0], [0, 38, 0, 7, 0, 0, 0, -5, -7, 0, 0, 0], [0, 0, 55, 0, 0, 2, -10, 0, 0, -10, 0, 0], [-135, 0, 0, -4, 0, 0, 0, 0, -4, 0, 0, -19], [0, 0, 0, 0, 32, 0, 6, 0, 0, -6, -16, 0], [-87, 0, 0, -13, 0, 0, 0, 0, -13, 0, 0, 5], [0, 0, 0, 0, 20, 0, 27, 0, 0, -27, -14, 0], [0, 96, 0, -28, 0, 0, 0, -3, 28, 0, 0, 0], [0, 0, 0, 0, 16, 0, 54, 0, 0, -54, -19, 0], [0, 0, 114, 0, 0, 38, 51, 0, 0, 51, 0, 0], [-181, 0, 0, -62, 0, 0, 0, 0, -62, 0, 0, -85], [0, -32, 0, -18, 0, 0, 0, -4, 18, 0, 0, 0], [0, 0, 145, 0, 0, 11, 49, 0, 0, 49, 0, 0], [-325, 0, 0, -50, 0, 0, 0, 0, -50, 0, 0, -88], [0, 0, 0, 0, -56, 0, 27, 0, 0, -27, 13, 0], [0, 0, 0, 0, -104, 0, 51, 0, 0, -51, 48, 0], [0, 0, -156, 0, 0, -81, -37, 0, 0, -37, 0, 0], [0, 0, 0, 0, 192, 0, -39, 0, 0, 39, -2, 0], [0, 0, 43, 0, 0, -93, 19, 0, 0, 19, 0, 0], [0, -20, 0, -54, 0, 0, 0, 59, 54, 0, 0, 0], [507, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, -73], [0, -300, 0, 68, 0, 0, 0, 0, -68, 0, 0, 0], [1163, 0, 0, 87, 0, 0, 0, 0, 87, 0, 0, -90], [0, 0, 0, 0, -180, 0, 6, 0, 0, -6, -13, 0], [0, 322, 0, 27, 0, 0, 0, -44, -27, 0, 0, 0], [0, 0, 221, 0, 0, 5, 176, 0, 0, 176, 0, 0], [0, -74, 0, -27, 0, 0, 0, -80, 27, 0, 0, 0], [18, 0, 0, 13, 0, 0, 0, 0, 13, 0, 0, 255], [0, 0, 254, 0, 0, -18, 37, 0, 0, 37, 0, 0], [950, 0, 0, -39, 0, 0, 0, 0, -39, 0, 0, 114], [0, 0, 0, 0, 428, 0, 102, 0, 0, -102, 86, 0], [0, 0, 0, 0, 428, 0, -51, 0, 0, 51, -110, 0], [0, 386, 0, -47, 0, 0, 0, 58, 47, 0, 0, 0], [0, 0, -807, 0, 0, 3, -324, 0, 0, -324, 0, 0], [0, 682, 0, 69, 0, 0, 0, 78, -69, 0, 0, 0], [-219, 0, 0, 66, 0, 0, 0, 0, 66, 0, 0, -152], [0, 432, 0, -22, 0, 0, 0, 66, 22, 0, 0, 0], [0, 0, -664, 0, 0, -30, 327, 0, 0, 327, 0, 0], [696, 0, 0, -388, 0, 0, 0, 0, -388, 0, 0, -484], [0, 0, -850, 0, 0, 299, 267, 0, 0, 267, 0, 0], [0, 0, 0, 0, 588, 0, 234, 0, 0, -234, -59, 0], [0, 0, -1273, 0, 0, -23, 243, 0, 0, 243, 0, 0], [0, -862, 0, 289, 0, 0, 0, -80, -289, 0, 0, 0], [0, 312, 0, -184, 0, 0, 0, -222, 184, 0, 0, 0], [0, 0, -994, 0, 0, -63, -412, 0, 0, -412, 0, 0], [0, 0, 0, 0, -192, 0, 231, 0, 0, -231, -267, 0], [0, 0, 0, 0, -756, 0, -369, 0, 0, 369, -160, 0], [0, -570, 0, 341, 0, 0, 0, 26, -341, 0, 0, 0], [0, 0, 0, 0, -268, 0, -276, 0, 0, 276, -285, 0], [0, 0, -840, 0, 0, 371, -272, 0, 0, -272, 0, 0], [1913, 0, 0, -100, 0, 0, 0, 0, -100, 0, 0, 439], [0, -752, 0, 246, 0, 0, 0, -46, -246, 0, 0, 0], [0, 0, 3393, 0, 0, -17, -63, 0, 0, -63, 0, 0], [0, 0, 0, 0, -532, 0, -609, 0, 0, 609, -301, 0], [0, 0, -1249, 0, 0, -709, 400, 0, 0, 400, 0, 0], [0, 0, 0, 0, -872, 0, -303, 0, 0, 303, -154, 0], [0, 0, 1021, 0, 0, -180, -808, 0, 0, -808, 0, 0], [0, 812, 0, 268, 0, 0, 0, 287, -268, 0, 0, 0], [-927, 0, 0, 90, 0, 0, 0, 0, 90, 0, 0, -389], [1437, 0, 0, 539, 0, 0, 0, 0, 539, 0, 0, 518], [0, -926, 0, 189, 0, 0, 0, 18, -189, 0, 0, 0], [0, 0, -2636, 0, 0, 322, 46, 0, 0, 46, 0, 0], [0, 0, 0, 0, 588, 0, -63, 0, 0, 63, -146, 0], [0, -30, 0, -505, 0, 0, 0, 0, 505, 0, 0, 0], [0, 0, 1137, 0, 0, 148, -50, 0, 0, -50, 0, 0], [-4057, 0, 0, 842, 0, 0, 0, 0, 842, 0, 0, 1285], [-1713, 0, 0, -175, 0, 0, 0, 0, -175, 0, 0, -133], [0, 0, 0, 0, -252, 0, -291, 0, 0, 291, 464, 0], [0, 1478, 0, -773, 0, 0, 0, 12, 773, 0, 0, 0], [0, 0, 2979, 0, 0, -547, -221, 0, 0, -221, 0, 0], [0, -2322, 0, 335, 0, 0, 0, -58, -335, 0, 0, 0], [0, 0, 2655, 0, 0, 724, -96, 0, 0, -96, 0, 0], [0, 0, 0, 0, 416, 0, 1266, 0, 0, -1266, -742, 0], [3191, 0, 0, -33, 0, 0, 0, 0, -33, 0, 0, -753], [0, -934, 0, -251, 0, 0, 0, -386, 251, 0, 0, 0], [0, 0, -2531, 0, 0, -665, 116, 0, 0, 116, 0, 0], [0, 0, -1124, 0, 0, 1065, 1070, 0, 0, 1070, 0, 0], [0, 1724, 0, 46, 0, 0, 0, -145, -46, 0, 0, 0], [0, 376, 0, 570, 0, 0, 0, 254, -570, 0, 0, 0], [4215, 0, 0, -216, 0, 0, 0, 0, -216, 0, 0, -596], [0, 0, 0, 0, -728, 0, -618, 0, 0, 618, 292, 0], [-3235, 0, 0, -285, 0, 0, 0, 0, -285, 0, 0, -1131], [0, 0, 0, 0, 556, 0, 969, 0, 0, -969, -564, 0], [0, 0, 0, 0, 468, 0, 705, 0, 0, -705, 358, 0], [2577, 0, 0, 302, 0, 0, 0, 0, 302, 0, 0, 524], [0, 350, 0, -77, 0, 0, 0, -35, 77, 0, 0, 0], [-3921, 0, 0, -896, 0, 0, 0, 0, -896, 0, 0, -2673], [0, 0, 0, 0, 1104, 0, 150, 0, 0, -150, 714, 0], [0, 0, 0, 0, 288, 0, 1494, 0, 0, -1494, 833, 0], [0, 0, 0, 0, -1624, 0, -795, 0, 0, 795, 270, 0], [0, 0, 2335, 0, 0, -477, 591, 0, 0, 591, 0, 0], [6725, 0, 0, 696, 0, 0, 0, 0, 696, 0, 0, 555], [1664, 0, 0, -828, 0, 0, 0, 0, -828, 0, 0, 522], [0, 1968, 0, 98, 0, 0, 0, 447, -98, 0, 0, 0], [0, 0, 0, 0, 424, 0, -1332, 0, 0, 1332, -625, 0], [0, 1470, 0, -1123, 0, 0, 0, -32, 1123, 0, 0, 0], [-15787, 0, 0, 304, 0, 0, 0, 0, 304, 0, 0, 947], [0, 0, -7711, 0, 0, -384, -414, 0, 0, -414, 0, 0], [0, 0, 0, 0, -596, 0, -405, 0, 0, 405, -1355, 0], [0, 0, 0, 0, 64, 0, -2073, 0, 0, 2073, 864, 0], [0, 2338, 0, -453, 0, 0, 0, -120, 453, 0, 0, 0], [0, 0, -53, 0, 0, -308, -773, 0, 0, -773, 0, 0], [0, 0, -7635, 0, 0, -88, 506, 0, 0, 506, 0, 0], [13964, 0, 0, -231, 0, 0, 0, 0, -231, 0, 0, 288], [0, -1168, 0, 160, 0, 0, 0, -716, -160, 0, 0, 0], [0, 0, -4093, 0, 0, -207, 1409, 0, 0, 1409, 0, 0], [-6232, 0, 0, 390, 0, 0, 0, 0, 390, 0, 0, 837], [0, -3830, 0, 249, 0, 0, 0, -386, -249, 0, 0, 0], [0, 0, 9419, 0, 0, 971, -748, 0, 0, -748, 0, 0], [0, 0, 0, 0, 2432, 0, 1929, 0, 0, -1929, -1338, 0], [0, 28, 0, 840, 0, 0, 0, -605, -840, 0, 0, 0], [0, -4592, 0, -30, 0, 0, 0, -52, 30, 0, 0, 0], [0, 0, -3247, 0, 0, 2259, -359, 0, 0, -359, 0, 0], [-4053, 0, 0, 209, 0, 0, 0, 0, 209, 0, 0, -754], [0, 0, 0, 0, -3940, 0, 72, 0, 0, -72, 559, 0], [0, 3304, 0, 84, 0, 0, 0, 185, -84, 0, 0, 0], [0, 0, -133, 0, 0, -1463, -2939, 0, 0, -2939, 0, 0], [0, 3262, 0, -1287, 0, 0, 0, -583, 1287, 0, 0, 0], [8796, 0, 0, 993, 0, 0, 0, 0, 993, 0, 0, -536], [0, 0, 0, 0, 1744, 0, 2037, 0, 0, -2037, 564, 0], [0, 0, 3033, 0, 0, 408, 2303, 0, 0, 2303, 0, 0], [0, 0, 6589, 0, 0, -585, -1349, 0, 0, -1349, 0, 0], [-10687, 0, 0, -744, 0, 0, 0, 0, -744, 0, 0, -387], [0, 568, 0, -468, 0, 0, 0, 386, 468, 0, 0, 0], [-3633, 0, 0, 1642, 0, 0, 0, 0, 1642, 0, 0, 1554], [4878, 0, 0, -2728, 0, 0, 0, 0, -2728, 0, 0, -4162], [0, 0, 0, 0, 2796, 0, 87, 0, 0, -87, 80, 0], [0, 0, 9901, 0, 0, -2114, -1305, 0, 0, -1305, 0, 0], [0, 0, 0, 0, 1424, 0, 2073, 0, 0, -2073, 1998, 0], [0, 0, 16608, 0, 0, -176, -1215, 0, 0, -1215, 0, 0], [0, 0, 0, 0, 2408, 0, 435, 0, 0, -435, -181, 0], [0, 2794, 0, 1401, 0, 0, 0, -178, -1401, 0, 0, 0], [0, 0, 2634, 0, 0, 72, 84, 0, 0, 84, 0, 0], [0, -10260, 0, 350, 0, 0, 0, -11, -350, 0, 0, 0], [-22498, 0, 0, 907, 0, 0, 0, 0, 907, 0, 0, 896], [0, 9246, 0, 881, 0, 0, 0, -57, -881, 0, 0, 0], [0, 0, -2021, 0, 0, -2209, 499, 0, 0, 499, 0, 0], [0, 0, 0, 0, 4024, 0, 138, 0, 0, -138, 742, 0], [0, 0, 3851, 0, 0, -1753, 2334, 0, 0, 2334, 0, 0], [0, 0, 0, 0, -792, 0, -4155, 0, 0, 4155, -1394, 0], [0, 0, 8140, 0, 0, 1416, 2125, 0, 0, 2125, 0, 0], [0, 3162, 0, 1319, 0, 0, 0, 300, -1319, 0, 0, 0], [-9436, 0, 0, -1543, 0, 0, 0, 0, -1543, 0, 0, -1862], [0, 0, 0, 0, 540, 0, -1800, 0, 0, 1800, -654, 0], [3267, 0, 0, 2105, 0, 0, 0, 0, 2105, 0, 0, -2005], [0, 0, 0, 0, 1224, 0, -3303, 0, 0, 3303, -964, 0], [-711, 0, 0, -908, 0, 0, 0, 0, -908, 0, 0, -3], [0, -7240, 0, 1450, 0, 0, 0, 328, -1450, 0, 0, 0], [-13599, 0, 0, 1370, 0, 0, 0, 0, 1370, 0, 0, -961], [0, 0, 0, 0, -5620, 0, -2523, 0, 0, 2523, 358, 0], [0, 0, -21977, 0, 0, 1582, 893, 0, 0, 893, 0, 0], [0, 0, 0, 0, -1208, 0, 4428, 0, 0, -4428, -1093, 0], [0, -8482, 0, 253, 0, 0, 0, -706, -253, 0, 0, 0], [0, 1484, 0, -296, 0, 0, 0, 1012, 296, 0, 0, 0], [821, 0, 0, -2079, 0, 0, 0, 0, -2079, 0, 0, 294], [0, 0, 0, 0, 4264, 0, -558, 0, 0, 558, 1287, 0], [0, 3062, 0, 1825, 0, 0, 0, 2018, -1825, 0, 0, 0], [0, 0, 0, 0, -996, 0, -1119, 0, 0, 1119, 3898, 0], [-17901, 0, 0, -3028, 0, 0, 0, 0, -3028, 0, 0, -2098], [0, 0, -6533, 0, 0, -1333, 3003, 0, 0, 3003, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_147_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_147_4_c_a();".
// 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_147_4_c_a(:prec:=12)
    chi := MakeCharacter_147_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_147_4_c_a();".
// 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_147_4_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_147_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![504, 0, 238, 0, 31, 0, 1]>],Snew);
    return Vf;
end function;