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