
// Make newform 384.4.c.d in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_384_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_384_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_384_4_c_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_384_4_c_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 := [4624, 0, 11952, 0, 10236, 0, 3500, 0, 549, 0, 39, 0, 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], [0, 5456, 0, 3220, 0, -82, 0, -223, 0, -29, 0, -1], [0, 22472, 0, 171832, 0, 42164, 0, 449, 0, -401, 0, -19], [0, 9468, 0, 11762, 0, 2399, 0, 12, 0, -22, 0, -1], [-193936, -118836, -387056, -126186, -189499, -38697, -36958, -4977, -3026, -285, -85, -6], [48688, 281488, 223040, 497900, 195364, 254146, 49300, 51367, 4556, 4277, 136, 121], [55590, 39612, 158848, 42062, 124372, 12899, 30753, 1659, 2839, 95, 85, 2], [-706384, -141648, -1365440, -134036, -883660, -19406, -205156, 1323, -18428, 337, -544, 13], [242896, 110680, 356864, 157984, 134164, 68388, 20638, 12511, 1394, 985, 34, 27], [48688, -281488, 223040, -497900, 195364, -254146, 49300, -51367, 4556, -4277, 136, -121], [-1073992, 756832, -2091680, 1002644, -1285948, 408934, -289408, 71275, -25568, 5417, -748, 145], [4964, 296176, 34000, 497900, 68612, 254146, 21488, 51367, 2176, 4277, 68, 121]];
    Rf_basisdens := [1, 216, 3672, 153, 918, 7344, 306, 2448, 612, 2448, 3672, 1836];
    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_384_c();"
function MakeCharacter_384_c()
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    v := [1, 2, 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_384_c_Hecke();"
function MakeCharacter_384_c_Hecke(Kf)
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    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]];
    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], [1, 0, 0, 0, 0, -1, 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], [3, -1, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0], [0, 1, 0, 0, 1, -2, 0, 0, 1, 0, 0, 0], [0, 1, 2, 2, 0, -4, 0, 1, 0, 1, -1, 1], [-1, 3, -2, -1, 0, 0, -1, 0, -1, 0, -2, -2], [-9, 1, 0, 0, 2, -1, 1, -2, -1, 1, 0, 2], [0, -3, -4, 6, 0, 16, 0, 2, 0, -6, -2, 2], [-1, -9, -1, -4, 0, 1, -1, -4, -1, 1, 2, -6], [52, 3, 0, 0, -3, -22, -4, -2, 1, -6, -2, 2], [-1, 1, 0, 2, 0, -29, -1, -4, -1, 11, 2, -6], [-1, 11, 2, -7, 0, -4, -1, -8, -1, 4, 6, -10], [-106, 2, 0, 0, -4, 6, -8, -4, -2, 6, 2, 4], [-2, -1, 0, 4, 0, 38, -2, -8, -2, -10, 4, -12], [222, 0, 0, 0, -8, -7, 0, -8, -8, -5, -8, 8], [60, -13, 0, 0, 1, -38, 4, 10, -3, -18, 10, -10], [-2, 14, 16, -24, 0, -7, -2, -8, -2, 5, 4, -12], [-155, -5, 0, 0, -2, -27, 1, -6, -11, -9, 2, 6], [-22, -8, 0, 0, -2, 36, 0, -10, -18, 14, 6, 10], [-3, 29, 3, 14, 0, -17, -3, -4, -3, 7, -2, -10], [381, 9, 0, 0, -12, 4, -14, -4, 5, 4, -7, 4], [-9, 18, 2, 32, 0, -25, -9, -11, -9, 12, -7, -29], [-7, -14, 0, 0, 12, -3, 21, 15, 1, -12, 5, -15], [-14, 5, -4, 58, 0, -6, -14, -6, -14, 4, -22, -34], [4, -4, 9, -46, 0, 56, 4, -8, 4, -16, 16, 0], [530, -4, 0, 0, 28, -11, 10, 4, 0, 7, 22, -4], [16, 7, 0, 0, 1, 14, 24, 10, 17, -14, -30, -10], [10, 52, 12, 108, 0, 26, 10, 22, 10, -16, -2, 42], [5, 45, 11, 100, 0, 43, 5, 20, 5, -21, -10, 30], [706, -24, 0, 0, -4, 19, 6, 20, -4, -7, 14, -20], [-13, -41, -12, 98, 0, 111, -13, -18, -13, -31, -8, -44], [12, 76, 0, 104, 0, -25, 12, 16, 12, 3, 8, 40], [0, 45, 32, 72, 0, -160, 0, -32, 0, 64, 32, -32], [18, 26, 13, -78, 0, -166, 18, 16, 18, 50, 20, 52], [-608, -15, 0, 0, -15, 190, -32, 32, 17, 64, 32, -32], [15, -5, 90, -87, 0, 24, 15, 24, 15, -16, 6, 54], [-679, -17, 0, 0, 14, -183, 3, 34, 17, -65, 28, -34], [22, 5, 96, 172, 0, -130, 22, -8, 22, 46, 52, 36], [1134, -36, 0, 0, 32, -9, 60, 16, -20, -27, 8, -16], [-740, 21, 0, 0, -3, 178, -4, -12, 9, 64, -20, 12], [-1224, -16, 0, 0, -40, -104, 6, 32, 16, -76, -30, -32], [-142, 44, 0, 0, -18, -36, -56, 10, 54, 10, -6, -10], [0, -37, -92, 106, 0, -144, 0, -18, 0, 54, 18, -18], [-10, -50, -51, -138, 0, 342, -10, 48, -10, -130, -68, 28], [2, 218, -92, -150, 0, 13, 2, 32, 2, -15, -28, 36], [5, -43, -21, 210, 0, 167, 5, -20, 5, -49, 30, -10], [1717, 41, 0, 0, -12, -72, 2, -4, 37, -32, -55, 4], [372, 77, 0, 0, -19, 58, -60, 20, 97, 40, -36, -20], [13, -56, 58, 132, 0, -43, 13, 25, 13, 6, 1, 51], [-810, 2, 0, 0, -84, 190, -20, -4, -2, 22, -66, 4], [46, 36, 0, 0, 46, -32, 12, -42, -6, 26, -2, 42], [143, -13, 0, 0, 28, 44, -50, 20, 7, 60, 91, -20], [-32, -250, -84, -8, 0, -72, -32, -18, -32, 30, -46, -82], [117, 59, 0, 0, -34, -587, -11, -54, 5, -193, -82, 54], [-20, 95, -32, -32, 0, 156, -20, -48, -20, -36, 8, -88], [21, 325, 179, 282, 0, -329, 21, -52, 21, 127, 94, -10], [-772, -69, 0, 0, 29, -206, 68, 46, -23, -110, 30, -46], [-5, 16, -122, 308, 0, -77, -5, 119, -5, -14, -129, 109], [-24, 272, 36, 162, 0, -93, -24, -72, -24, 55, 24, -120], [28, 43, 44, -10, 0, 380, 28, 58, 28, -146, -2, 114], [4, -180, 20, -510, 0, -125, 4, -88, 4, 71, 96, -80], [67, -51, 0, 0, -46, 715, 7, -42, -93, 217, -2, 42], [-901, -26, 0, 0, -62, 479, 67, 47, 21, 58, -103, -47], [0, 75, -8, -52, 0, 160, 0, -124, 0, -12, 124, -124], [-22, -134, 8, 424, 0, -191, -22, 8, -22, 61, -52, -36], [-471, 54, 0, 0, -110, 297, -131, -39, 15, 126, -33, 39], [-2189, 63, 0, 0, 132, -72, 90, -84, -21, 32, -21, 84], [20, 85, 0, 0, -143, -302, -44, -80, 5, -140, -184, 80], [12, -144, 136, -144, 0, -628, 12, -140, 12, 256, 164, -116], [3385, -9, 0, 0, 38, -919, -55, 2, -7, -245, 102, -2], [-85, -13, -321, 480, 0, -339, -85, 60, -85, 93, -230, -110], [-2448, 21, 0, 0, -99, -234, -80, 88, 109, -120, -40, -88], [-3, -95, 102, 459, 0, 30, -3, -24, -3, -2, 18, -30], [4512, 56, 0, 0, 24, -408, -106, -64, -8, -28, 74, 64], [42, -181, 88, 128, 0, 226, 42, 44, 42, -90, 40, 128], [1696, -181, 0, 0, -79, -66, -40, 6, -175, -50, 142, -6], [-84, 51, -194, -586, 0, 320, -84, -17, -84, -101, -151, -185], [-386, -112, 0, 0, -68, 220, -108, 96, -16, 68, 152, -96], [-4395, 177, 0, 0, -16, -212, -88, 16, 193, -28, -105, -16], [2164, 73, 0, 0, 253, 330, 100, 24, 97, 204, 80, -24], [4046, 42, 0, 0, -100, 422, 84, 12, 54, 14, -226, -12], [-603, 182, 0, 0, 36, 113, -23, -57, 125, 96, -123, 57], [-2, -122, 165, -310, 0, -1146, -2, 96, -2, 350, -100, 92], [703, -197, 0, 0, -112, -200, 80, 16, -181, -200, 5, -16], [-62, -325, -470, -458, 0, 422, -62, 61, -62, -161, -185, -63], [2110, 52, 0, 0, -220, -596, -124, 4, 56, -264, -148, -4], [-76, 349, -132, 14, 0, -780, -76, 114, -76, 222, -266, -38], [53, -323, 339, 60, 0, -557, 53, -76, 53, 211, 182, 30], [-3779, -159, 0, 0, -40, -336, 140, 72, -87, -256, -21, -72], [4, -4, 0, 0, -152, -324, -120, 104, 100, -164, -28, -104], [74, 10, 37, -372, 0, 1246, 74, 56, 74, -434, 92, 204], [-6126, -316, 0, 0, -16, -479, 64, 240, -76, -293, 236, -240], [46, 454, 284, 282, 0, -255, 46, 240, 46, 5, -148, 332], [3123, 349, 0, 0, -30, 1363, -149, -10, 339, 537, -230, 10], [78, 181, 408, -680, 0, -586, 78, 28, 78, 186, 128, 184], [-37, 183, -236, -806, 0, 855, -37, -18, -37, -279, -56, -92], [57, 213, 34, 201, 0, -694, 57, -128, 57, 274, 242, -14], [-5492, 47, 0, 0, 65, 1354, 68, -2, 45, 450, -50, 2], [89, 197, -142, -91, 0, 566, 89, 112, 89, -226, 66, 290], [38, -737, -316, -594, 0, -610, 38, 118, 38, 164, -42, 194], [-9287, 149, 0, 0, 80, 468, 64, -112, 37, 204, -133, 112], [-3, -195, 356, 166, 0, 913, -3, -226, -3, -229, 220, -232], [36, -660, -444, 18, 0, 423, 36, 168, 36, -197, -96, 240], [-571, -266, 0, 0, -246, -387, -95, 277, 11, -322, 115, -277], [-486, -12, 0, 0, 316, 917, 230, 84, 72, 335, 98, -84], [86, -378, -360, -716, 0, -466, 86, 52, 86, 138, 120, 224], [3583, 9, 0, 0, 194, 1199, 41, 62, 71, 481, 144, -62], [2826, 48, 0, 0, 94, -1260, -112, -50, -2, -266, 158, 50], [-47, 201, -525, -328, 0, 527, -47, 148, -47, -225, -242, 54], [11304, 127, 0, 0, -179, -818, -96, -138, -11, -282, -210, 138], [-87, -90, 446, -1224, 0, 601, -87, -229, -87, -124, 55, -403], [74, 42, 576, 28, 0, 993, 74, -72, 74, -307, 220, 76], [102, -26, 597, 52, 0, -1030, 102, 136, 102, 298, 68, 340], [-58, 309, -106, 842, 0, 706, -58, 227, -58, -311, -343, 111], [-35, -263, -270, 545, 0, -846, -35, -144, -35, 330, 74, -214], [5501, -133, 0, 0, -186, -571, -401, 138, 5, -93, 348, -138], [152, 721, -116, -978, 0, 456, 152, -6, 152, -150, 310, 298], [10354, -56, 0, 0, 144, -757, 80, 16, -40, -215, 120, -16], [-10416, 135, 0, 0, -227, 134, -104, -106, 29, -2, -258, 106], [-1159, 222, 0, 0, -76, 1277, 85, 91, 313, 288, -383, -91], [-78, 337, -716, 518, 0, 90, -78, -354, -78, 88, 198, -510], [-3369, 531, 0, 0, -36, -1048, -474, -268, 263, 32, -93, 268], [33, 21, 182, 79, 0, -970, 33, -56, 33, 342, 122, 10], [-42, 335, 268, -158, 0, -274, -42, 274, -42, 0, -358, 190], [11468, 59, 0, 0, 45, 66, -140, -146, -87, 194, 126, 146], [2514, -146, 0, 0, -260, -126, 90, -172, -318, -218, -204, 172], [88, -688, -423, -70, 0, -580, 88, -344, 88, 308, 520, -168], [836, -687, 0, 0, 225, -2430, 372, 180, -507, -968, 540, -180], [-192, -256, -824, -120, 0, 1535, -192, -128, -192, -469, -256, -512], [7737, 287, 0, 0, -146, -487, -193, -366, -79, -9, -240, 366], [131, 835, 95, -1174, 0, -399, 131, 36, 131, 121, 226, 298], [-13948, 537, 0, 0, 45, -342, -252, -264, 273, 172, -240, 264], [125, 855, 872, -618, 0, -775, 125, -8, 125, 261, 258, 242], [-5042, 60, 0, 0, 358, 480, 92, 166, 226, 282, 206, -166], [-134, -931, 76, -478, 0, 2914, -134, -46, -134, -956, -222, -314], [29, -447, 182, 1115, 0, 954, 29, -408, 29, -182, 466, -350], [-14, -217, -412, -146, 0, 26, -14, 358, -14, -128, -386, 330], [-1, 1029, -536, 210, 0, -1229, -1, -64, -1, 431, 62, -66], [-95, 493, -942, 29, 0, 1986, -95, 240, -95, -742, -430, 50], [202, -411, 340, 2478, 0, -1486, 202, -2, 202, 496, 406, 402], [-234, 582, 469, 1384, 0, 202, -234, -424, -234, 74, -44, -892], [778, 252, 0, 0, 332, -535, -150, -12, 240, 147, 230, 12], [-6168, 265, 0, 0, -303, -810, -552, 192, 457, -168, -16, -192], [-22307, 99, 0, 0, 62, 149, 149, -118, -19, 31, -186, 118], [-14184, 393, 0, 0, -131, -1602, -280, -20, 373, -428, -244, 20], [-31, -915, -324, 2118, 0, -587, -31, -262, -31, 283, 200, -324], [41, -227, 102, -2769, 0, -494, 41, -472, 41, 322, 554, -390], [1324, -164, 0, 0, -400, 76, -206, -120, -284, -64, -30, 120], [4052, 289, 0, 0, -319, 1282, -44, -60, 229, 264, -564, 60], [-94, -544, 260, -460, 0, 1314, -94, -270, -94, -348, 82, -458], [-233, 2059, 14, 323, 0, -1272, -233, -144, -233, 472, -322, -610], [4739, -515, 0, 0, 146, -1045, 195, 102, -413, -415, 466, -102], [-17, 107, 258, -355, 0, -2004, -17, 264, -17, 580, -298, 230], [-23430, -322, 0, 0, -284, -54, -100, 340, 18, -254, 138, -340], [-114, -898, -891, 1176, 0, 1450, -114, 632, -114, -694, -860, 404], [10, 725, 494, 3674, 0, 6, 10, -225, 10, 73, 245, -205], [-3453, 426, 0, 0, -144, -893, -461, 41, 467, -100, -109, -41], [12, -1359, 196, -1438, 0, -1268, 12, -754, 12, 674, 778, -730], [21410, 64, 0, 0, 300, 2119, 130, 308, 372, 717, 106, -308], [61, -1311, 556, 566, 0, -415, 61, 274, 61, 47, -152, 396], [238, 574, 365, 3120, 0, -1806, 238, 216, 238, 530, 260, 692], [-5413, -369, 0, 0, -340, 3468, 126, 292, -77, 748, -97, -292], [-40, -871, 818, -910, 0, 788, -40, -167, -40, -207, 87, -247], [-19161, -263, 0, 0, 378, -2321, 103, -322, -585, -483, 538, 322], [179, -989, -617, 302, 0, -455, 179, 308, 179, 49, 50, 666], [18548, -225, 0, 0, -419, 1850, -260, 146, -79, 462, 66, -146]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_384_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_384_4_c_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_384_4_c_d(:prec:=12)
    chi := MakeCharacter_384_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_384_4_c_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_384_4_c_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_384_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![370690624, -67009824, 2349600, 106488, -4152, -18, 1]>,<13,R![15061696, -231124992, 12415920, 39936, -7452, 0, 1]>],Snew);
    return Vf;
end function;