
// Make newform 336.4.bc.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_336_bc();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_336_bc_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_336_4_bc_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_336_4_bc_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 := [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], [-142839531, 145536102, 81309015, -61874280, 17528769, -6980468, 632573, -161148, 1327, -146502, 22601, 538], [271271106, 15136227, -61499898, 12229137, 1141056, -26593, 33772, -83625, -69172, 26109, 3322, -109], [-336854862, -4113747, 5390226, 3432699, -2301324, 658001, -289700, 24405, -6088, 627, -5426, 857], [-8693961417, 3646715337, 938815677, 245384073, -198180063, -12125077, -15945431, 5417499, 1385435, 231543, -145853, 4301], [-3237833817, -1006011252, 425453877, 124247358, 45805959, -4401802, -6882797, -3202098, 330857, 126396, 50035, 4280], [-151814979, 13338513, -1371249, 7836021, 1005399, -641129, -227449, -82569, 6421, 6255, 209, -1523], [-151814979, -149794191, -1371249, 7836021, 1005399, -641129, -227449, -82569, 6421, 6255, 209, -1523], [-585313371, -328627368, 63733311, 57560058, 12758757, -1880782, -1298243, -725238, 39527, 50088, 12349, -1228], [5512873689, -2180220300, -784745901, -75013614, 126399249, 34199906, 8057845, -3679350, -2138089, -61380, 116845, 22376], [864004968, -328734531, -137629368, -11721861, -5875446, -1810579, 1816582, -321723, -51046, -1005, -4808, -8011], [-1611033867, 145536102, -444340809, -49790376, 6563745, 31906828, -585763, -11964, -719729, -146502, -2263, 25402]];
    Rf_basisdens := [1, 489398112, 69914016, 163132704, 489398112, 244699056, 54377568, 54377568, 40783176, 489398112, 163132704, 489398112];
    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_336_bc();"
function MakeCharacter_336_bc()
    N := 336;
    order := 6;
    char_gens := [127, 85, 113, 241];
    v := [6, 6, 3, 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_336_bc_Hecke();"
function MakeCharacter_336_bc_Hecke(Kf)
    N := 336;
    order := 6;
    char_gens := [127, 85, 113, 241];
    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], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 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, 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, 1, 0, 0, 0, 0, 0, 0, 0], [4, 2, 3, -1, 0, 0, 1, 1, 0, 0, -1, 3], [0, 1, 0, 0, 2, 1, -2, 2, 0, 1, 0, 3], [9, -3, -3, 18, 0, 0, 5, 0, 0, 0, -3, 2], [0, -8, 0, 0, 0, -1, -9, -9, 2, 0, 0, 1], [-34, 1, 1, -17, 0, 0, 1, 0, 0, 0, -2, 2], [0, -5, 0, 0, 0, 0, -10, -5, -1, 0, 0, 5], [0, 1, 0, 0, 5, 13, 7, 14, -13, -5, 0, -6], [55, -12, -4, -55, 0, 0, 10, 8, 0, 0, 2, -2], [0, -15, -11, -135, 0, 0, 19, 4, 0, 0, 0, 4], [0, -8, 0, 0, -16, 8, -6, 0, 8, -16, 0, -2], [87, 5, 31, 0, 0, 0, 13, 26, 0, 0, -31, 18], [0, 17, 0, 0, -14, 10, 0, 27, -5, 0, 0, 17], [0, 38, 0, 0, -6, -10, -28, 28, 0, -3, 0, 66], [0, -50, 0, 0, 0, -4, -54, -54, 8, -19, 0, 4], [228, 51, -38, 114, 0, 0, -38, -89, 0, 0, 76, 13], [-181, 62, 0, -181, 0, 0, 23, -62, 0, 0, 39, 85], [0, 19, 0, 0, -4, 17, 18, 36, -17, 4, 0, 1], [-145, -38, 22, 145, 0, 0, 49, 60, 0, 0, -11, 11], [0, 38, -12, 325, 0, 0, -88, -50, 0, 0, 0, -50], [0, -14, 0, 0, -13, 14, 27, 0, 14, -13, 0, -41], [0, -103, 0, 0, -48, 52, 0, -51, -26, 0, 0, -103], [156, 81, 81, 312, 0, 0, -44, 0, 0, 0, 81, 37], [0, -87, 0, 0, 0, 48, -39, -39, -96, 2, 0, -48], [-86, -19, -93, -43, 0, 0, -93, -74, 0, 0, 186, -112], [0, -54, 0, 0, 59, 0, -108, -54, 32, 118, 0, 54], [-507, 2, 0, -507, 0, 0, -75, -2, 0, 0, 77, -73], [0, 177, 0, 0, 0, -41, 68, 136, 41, 0, 0, 109], [-1163, -90, -264, 0, 0, 0, -87, -174, 0, 0, 264, -177], [0, 96, 0, 0, -13, -90, 0, 6, 45, 0, 0, 96], [0, 67, 0, 0, -88, -94, 27, -27, 0, -44, 0, 40], [221, 5, 5, 442, 0, 0, 171, 0, 0, 0, 5, 176], [0, 27, 0, 0, 80, 0, 54, 27, -32, 160, 0, -27], [18, -13, 0, 18, 0, 0, -242, 13, 0, 0, 229, -255], [-254, -55, -36, 254, 0, 0, 37, 19, 0, 0, 18, -18], [0, -153, -192, -950, 0, 0, 114, -39, 0, 0, 0, -39], [0, 107, 0, 0, -86, -107, 102, 0, -107, -86, 0, 5], [0, 265, 0, 0, 110, -214, 0, 51, 107, 0, 0, 265], [0, -120, 0, 0, -116, 73, 47, -47, 0, -58, 0, -167], [807, -3, -3, 1614, 0, 0, 327, 0, 0, 0, -3, 324], [0, 69, 0, 0, 78, 0, 138, 69, -205, 156, 0, -69], [219, 66, 0, 219, 0, 0, -218, -66, 0, 0, 284, -152], [0, -141, 0, 0, -66, 97, -22, -44, -97, 66, 0, -119], [-664, 357, 60, 664, 0, 0, -327, -297, 0, 0, -30, 30], [-696, -484, 292, 0, 0, 0, 388, 776, 0, 0, -292, -96], [-850, 299, 299, -1700, 0, 0, -32, 0, 0, 0, 299, 267], [0, -87, 0, 0, 0, -147, -234, -234, 294, -59, 0, 147], [-2546, 243, 23, -1273, 0, 0, 23, -220, 0, 0, -46, 266], [0, -289, 0, 0, 80, 0, -578, -289, -71, 160, 0, 289], [0, 354, 0, 0, -222, 14, 184, 368, -14, 222, 0, 170], [994, 349, -126, -994, 0, 0, -412, -475, 0, 0, 63, -63], [0, -48, 0, 0, 267, 48, 231, 0, 48, 267, 0, -279], [0, -9, 0, 0, 160, 378, 0, 369, -189, 0, 0, -9], [0, 313, 0, 0, -52, 28, -341, 341, 0, -26, 0, 654], [0, -209, 0, 0, 0, -67, -276, -276, 134, 285, 0, 67], [1680, 272, 371, 840, 0, 0, 371, 99, 0, 0, -742, 643], [-1913, -100, 0, -1913, 0, 0, 539, 100, 0, 0, -639, 439], [0, 557, 0, 0, 46, -65, 246, 492, 65, -46, 0, 311], [3393, -46, 34, -3393, 0, 0, 63, 80, 0, 0, -17, 17], [0, 133, 0, 0, -301, -133, 609, 0, -133, -301, 0, -476], [-1249, -709, -709, -2498, 0, 0, 1109, 0, 0, 0, -709, 400], [0, 85, 0, 0, 0, 218, 303, 303, -436, -154, 0, -218], [2042, -808, 180, 1021, 0, 0, 180, 988, 0, 0, -360, -628], [0, -268, 0, 0, -287, 0, -536, -268, 337, -574, 0, 268], [0, 479, 569, 927, 0, 0, -389, 90, 0, 0, 0, 90], [1437, -518, 560, 0, 0, 0, 539, 1078, 0, 0, -560, 21], [0, 326, 0, 0, -36, -137, -189, 189, 0, -18, 0, 515], [2636, -322, -322, 5272, 0, 0, 276, 0, 0, 0, -322, -46], [0, -210, 0, 0, 0, 147, -63, -63, -294, 146, 0, -147], [0, -505, 0, 0, 0, 0, -1010, -505, 260, 0, 0, 505], [1137, -198, -296, -1137, 0, 0, 50, -98, 0, 0, 148, -148], [0, 443, -399, -4057, 0, 0, -1285, -842, 0, 0, 0, -842], [1713, -133, 217, 0, 0, 0, 175, 350, 0, 0, -217, 42], [0, -165, 0, 0, 464, -126, 0, -291, 63, 0, 0, -165], [0, 756, 0, 0, 24, 17, -773, 773, 0, 12, 0, 1529], [5958, -221, 547, 2979, 0, 0, 547, 768, 0, 0, -1094, 326], [0, -335, 0, 0, 58, 0, -670, -335, -413, 116, 0, 335], [-2655, 820, 1448, 2655, 0, 0, -96, 628, 0, 0, -724, 724], [0, 104, 0, 0, 742, -104, 1266, 0, -104, 742, 0, -1162], [3191, 753, 687, 0, 0, 0, -33, -66, 0, 0, -687, 720], [0, 108, 0, 0, 772, -359, 251, -251, 0, 386, 0, -143], [2531, 665, 665, 5062, 0, 0, -781, 0, 0, 0, 665, -116], [2248, -1070, 1065, 1124, 0, 0, 1065, 2135, 0, 0, -2130, -5], [0, 46, 0, 0, -145, 0, 92, 46, -454, -290, 0, -46], [0, 761, 0, 0, -254, 379, 570, 1140, -379, 254, 0, 191], [0, -380, -164, 4215, 0, 0, 596, 216, 0, 0, 0, 216], [0, 182, 0, 0, 292, -182, 618, 0, -182, 292, 0, -436], [3235, -1131, -561, 0, 0, 0, 285, 570, 0, 0, 561, -846], [0, 691, 0, 0, -564, 278, 0, 969, -139, 0, 0, 691], [0, -588, 0, 0, 0, -117, -705, -705, 234, 358, 0, 117], [2577, -302, 0, 2577, 0, 0, -222, 302, 0, 0, -80, -524], [0, 203, 0, 0, -35, -49, 77, 154, 49, 35, 0, 126], [0, 1777, 881, 3921, 0, 0, -2673, -896, 0, 0, 0, -896], [0, 276, 0, 0, -714, -276, 150, 0, -276, -714, 0, 126], [0, -1350, 0, 0, -833, -144, 0, -1494, 72, 0, 0, -1350], [0, -389, 0, 0, 0, -406, -795, -795, 812, -270, 0, 406], [-4670, -591, -477, -2335, 0, 0, -477, 114, 0, 0, 954, -1068], [0, -141, -837, 6725, 0, 0, -555, -696, 0, 0, 0, -696], [-1664, 522, 2178, 0, 0, 0, 828, 1656, 0, 0, -2178, 1350], [0, 443, 0, 0, 894, -541, 98, -98, 0, 447, 0, 345], [0, 1438, 0, 0, 0, -106, 1332, 1332, 212, -625, 0, 106], [0, 1123, 0, 0, 32, 0, 2246, 1123, -194, 64, 0, -1123], [-15787, -304, 0, -15787, 0, 0, -643, 304, 0, 0, 339, -947], [7711, 30, -768, -7711, 0, 0, -414, -798, 0, 0, 384, -384], [0, -149, 0, 0, 1355, 149, -405, 0, 149, 1355, 0, 256], [0, 2105, 0, 0, -864, -32, 0, 2073, 16, 0, 0, 2105], [0, -811, 0, 0, 240, 358, 453, -453, 0, 120, 0, -1264], [53, 308, 308, 106, 0, 0, 465, 0, 0, 0, 308, 773], [15270, -506, -88, 7635, 0, 0, -88, 418, 0, 0, 176, -594], [-13964, -231, 0, -13964, 0, 0, 519, 231, 0, 0, -750, 288], [0, 532, 0, 0, 716, -212, 160, 320, 212, -716, 0, 372], [-4093, 1616, 414, 4093, 0, 0, -1409, -1202, 0, 0, -207, 207], [6232, 837, 57, 0, 0, 0, -390, -780, 0, 0, -57, 447], [0, -1082, 0, 0, -772, 833, 249, -249, 0, -386, 0, -1331], [9419, 971, 971, 18838, 0, 0, -1719, 0, 0, 0, 971, -748], [0, -1321, 0, 0, 0, -608, -1929, -1929, 1216, -1338, 0, 608], [0, -840, 0, 0, 605, 0, -1680, -840, 427, 1210, 0, 840], [0, -1103, 0, 0, -52, 1163, 30, 60, -1163, 52, 0, -1133], [3247, 2618, 4518, -3247, 0, 0, -359, 1900, 0, 0, -2259, 2259], [-4053, 754, 1172, 0, 0, 0, 209, 418, 0, 0, -1172, 963], [0, -2042, 0, 0, -559, 1970, 0, -72, -985, 0, 0, -2042], [0, -784, 0, 0, -370, 868, -84, 84, 0, -185, 0, -700], [266, 2939, -1463, 133, 0, 0, -1463, -4402, 0, 0, 2926, 1476], [0, -2746, 0, 0, 583, 172, -1287, -2574, -172, -583, 0, -1459], [0, -1529, -2522, 8796, 0, 0, 536, -993, 0, 0, 0, -993], [0, 1165, 0, 0, 564, 872, 0, 2037, -436, 0, 0, 1165], [3033, 408, 408, 6066, 0, 0, 1895, 0, 0, 0, 408, 2303], [13178, -1349, 585, 6589, 0, 0, 585, 1934, 0, 0, -1170, -764], [-10687, 744, 0, -10687, 0, 0, -357, -744, 0, 0, 1101, 387], [0, 844, 0, 0, 386, 92, 468, 936, -92, -386, 0, 376], [0, 88, 1730, 3633, 0, 0, 1554, 1642, 0, 0, 0, 1642], [4878, 4162, -1294, 0, 0, 0, -2728, -5456, 0, 0, 1294, 1434], [0, 1311, 0, 0, -80, -1398, 0, -87, 699, 0, 0, 1311], [-9901, 2114, 2114, -19802, 0, 0, -809, 0, 0, 0, 2114, 1305], [0, 1717, 0, 0, 0, 356, 2073, 2073, -712, -1998, 0, -356], [16608, -1039, 352, -16608, 0, 0, 1215, 1391, 0, 0, -176, 176], [0, -602, 0, 0, -181, 602, -435, 0, 602, -181, 0, -167], [0, -2, 0, 0, -356, -1399, 1401, -1401, 0, -178, 0, -1403], [2634, 72, 72, 5268, 0, 0, 12, 0, 0, 0, 72, 84], [0, -350, 0, 0, 11, 0, -700, -350, -2390, 22, 0, 350], [-22498, -907, 0, -22498, 0, 0, 11, 907, 0, 0, -918, -896], [0, 990, 0, 0, -57, -2752, -881, -1762, 2752, 57, 0, 1871], [2021, -2708, -4418, -2021, 0, 0, 499, -1710, 0, 0, 2209, -2209], [0, 1006, 0, 0, -742, -1006, 138, 0, -1006, -742, 0, 868], [-3851, 1753, 1753, -7702, 0, 0, -4087, 0, 0, 0, 1753, -2334], [0, -3957, 0, 0, 0, -198, -4155, -4155, 396, 1394, 0, 198], [-16280, -2125, 1416, -8140, 0, 0, 1416, 3541, 0, 0, -2832, -709], [0, 1319, 0, 0, 300, 0, 2638, 1319, -1450, 600, 0, -1319], [0, -319, 1224, -9436, 0, 0, 1862, 1543, 0, 0, 0, 1543], [0, -135, 0, 0, -654, 135, 1800, 0, 135, -654, 0, -1935], [-3267, -2005, -6215, 0, 0, 0, -2105, -4210, 0, 0, 6215, -4110], [0, -3915, 0, 0, -964, 612, 0, -3303, -306, 0, 0, -3915], [-711, 908, 0, -711, 0, 0, -905, -908, 0, 0, 1813, 3], [0, -3985, 0, 0, 328, 1085, -1450, -2900, -1085, -328, 0, -2535], [0, 2331, 3701, 13599, 0, 0, -961, 1370, 0, 0, 0, 1370], [0, -287, 0, 0, -358, 2810, 0, 2523, -1405, 0, 0, -287], [21977, -1582, -1582, 43954, 0, 0, 689, 0, 0, 0, -1582, -893], [0, 4730, 0, 0, 0, -302, 4428, 4428, 604, 1093, 0, 302], [0, 253, 0, 0, -706, 0, 506, 253, 1994, -1412, 0, -253], [0, -815, 0, 0, -1012, 223, -296, -592, -223, 1012, 0, -519], [-821, 294, 4452, 0, 0, 0, 2079, 4158, 0, 0, -4452, 2373], [0, -2690, 0, 0, 1287, 2132, 0, -558, -1066, 0, 0, -2690], [0, -147, 0, 0, 4036, -1678, 1825, -1825, 0, 2018, 0, -1972], [0, 870, 0, 0, 0, 249, 1119, 1119, -498, 3898, 0, -249], [-17901, 3028, 0, -17901, 0, 0, -930, -3028, 0, 0, 3958, 2098], [6533, -4336, -2666, -6533, 0, 0, 3003, 1670, 0, 0, 1333, -1333]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_336_bc_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_336_4_bc_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_336_4_bc_d(:prec:=12)
    chi := MakeCharacter_336_bc();
    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_336_4_bc_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_336_4_bc_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_336_bc();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![2962842624, 0, 1937507040, 0, 1245448953, 0, 13986756, 0, 121221, 0, 396, 0, 1]>,<13,R![82121472, 0, 1731204, 0, 4335, 0, 1]>],Snew);
    return Vf;
end function;