
// Make newform 320.4.n.g in Magma, downloaded from the LMFDB on 24 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_320_n();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_320_n_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_320_4_n_g();".
// 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_320_4_n_g();".
// 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 := [5184, 2160, 450, -636, 532, 22, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-13371048, -24314742, 40097412, -5831540, -215714, -98830, 76486, -12827], [-172204272, -33851538, 55056948, 8851640, -430606, -138830, 110714, 11087], [33215616, 4941846, 13282020, -2042464, 59186, -19214, 31262, -4549], [33234264, -46051374, 4136484, 3185780, 228422, -108590, 8822, 4361], [5405022, -38621322, 8815752, -4290130, -37954, -99680, 25076, -7537], [-839823768, 68044878, 209735292, -197999140, -8895574, -697730, 729026, -386857], [61844418, 33376422, -20819392, 16985890, 759274, 66380, -67126, 33307]];
    Rf_basisdens := [1, 111061800, 55530900, 11106180, 7404120, 5553090, 111061800, 9255150];
    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_320_n();"
function MakeCharacter_320_n()
    N := 320;
    order := 4;
    char_gens := [191, 261, 257];
    v := [2, 4, 3];
    // 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_320_n_Hecke();"
function MakeCharacter_320_n_Hecke( : Kf := false)
    N := 320;
    order := 4;
    char_gens := [191, 261, 257];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 1, 0], [1, -1, 1, 0, -1, 1, 0, 0], [0, 6, 1, 1, 1, -1, 1, 1], [6, -6, -4, 0, 1, -1, 2, -2], [7, 7, 0, 4, -1, -1, 5, 5], [-14, 0, 4, -4, 1, 3, -1, 3], [31, 31, 0, -7, -8, -8, 3, 3], [0, -54, 16, 16, -1, 7, -1, -7], [0, -70, -11, -11, -11, -1, -11, 1], [24, 24, 0, -48, 1, 1, 0, 0], [100, 0, 28, -28, 7, -2, -7, -2], [-46, -46, 0, 21, -12, -12, 14, 14], [-113, 113, 45, 0, -15, 15, -12, 12], [114, -114, -28, 0, -18, 18, -9, 9], [14, 0, -4, 4, -29, 1, 29, 1], [-340, 0, 20, -20, 7, 12, -7, 12], [22, -22, -7, 0, -38, 38, -8, 8], [0, -502, 9, 9, 13, -25, 13, 25], [-189, 189, -60, 0, 14, -14, 28, -28], [392, 0, 0, 0, 24, -4, -24, -4], [-480, -480, 0, -55, -8, -8, -28, -28], [0, 284, 72, 72, 46, 2, 46, -2], [-103, -103, 0, -132, -30, -30, 26, 26], [-482, 0, 80, -80, -66, 24, 66, 24], [11, 11, 0, 33, 20, 20, -21, -21], [-232, 232, 93, 0, 52, -52, 36, -36], [0, -644, -4, -4, 51, 26, 51, -26], [-433, 433, -112, 0, -7, 7, -41, 41], [-981, 981, -59, 0, 21, -21, 32, -32], [0, -66, 21, 21, 73, 75, 73, -75], [-449, -449, 0, -96, 74, 74, 4, 4], [-642, 0, -68, 68, 103, 17, -103, 17], [0, -700, -56, -56, -103, 38, -103, -38], [0, -1782, 113, 113, 29, 27, 29, -27], [144, 144, 0, 16, 86, 86, -79, -79], [-976, -976, 0, -239, 72, 72, 104, 104], [-1303, 1303, 17, 0, -9, 9, -20, 20], [704, -704, 136, 0, -32, 32, 51, -51], [594, 0, -12, 12, 49, -153, -49, -153], [50, 0, -204, 204, -44, 56, 44, 56], [0, -1590, -267, -267, 37, -53, 37, 53], [515, -515, 132, 0, -117, 117, 5, -5], [204, 204, 0, -132, -149, -149, 142, 142], [892, 0, 168, -168, 90, 50, -90, 50], [0, -1434, 397, 397, -63, -141, -63, 141], [-1387, -1387, 0, 181, 76, 76, 105, 105], [-1230, 1230, -519, 0, -186, 186, 140, -140], [0, -290, -252, -252, -23, -139, -23, 139], [-283, 283, 228, 0, 107, -107, 147, -147], [824, 0, -320, 320, -92, 104, 92, 104], [-1228, 0, -132, 132, -109, -66, 109, -66], [0, -3042, -183, -183, -159, 119, -159, -119], [1051, 1051, 0, 448, 61, 61, 111, 111], [-1221, -1221, 0, -191, -144, -144, 163, 163], [0, 1992, -108, -108, -113, 124, -113, -124], [0, 1162, -451, -451, -15, -165, -15, 165], [-450, -450, 0, 16, -32, -32, -27, -27], [-1932, 0, 12, -12, 175, 122, -175, 122], [882, 882, 0, 29, -4, -4, 306, 306], [-1620, 1620, 392, 0, -89, 89, 42, -42], [-2710, 2710, -175, 0, 234, -234, -284, 284], [0, 906, 305, 305, -287, -17, -287, 17], [-591, 591, -152, 0, 181, -181, -255, 255], [-884, -884, 0, -84, 48, 48, -153, -153], [0, -3954, -399, -399, 261, -417, 261, 417], [1445, 1445, 0, -248, -112, -112, -84, -84], [-2328, 2328, 421, 0, 72, -72, 148, -148], [0, 1586, -220, -220, 127, 19, 127, -19], [2553, -2553, -800, 0, 308, -308, -148, 148], [-1316, 0, 232, -232, 10, -282, -10, -282], [-2529, 2529, 381, 0, 161, -161, -240, 240], [-4930, 4930, 720, 0, 164, -164, -7, 7], [-1602, 0, -868, 868, 291, 117, -291, 117], [-2419, -2419, 0, 1077, 12, 12, -191, -191], [0, 1144, 524, 524, 13, -28, 13, 28], [2470, 2470, 0, -188, -147, -147, 126, 126], [-2542, 0, -604, 604, -56, -336, 56, -336], [0, 178, 700, 700, 380, -477, 380, 477], [3586, 0, 340, -340, -91, -29, 91, -29], [5780, 0, -584, 584, 183, -164, -183, -164], [0, 1290, -211, -211, 153, 339, 153, -339], [5237, -5237, -28, 0, -98, 98, 346, -346], [-700, 0, 56, -56, 558, 154, -558, 154], [-398, -398, 0, -19, -116, -116, 114, 114], [0, 50, 1368, 1368, 50, 171, 50, -171], [-3735, -3735, 0, -32, -373, -373, -505, -505], [-2362, 0, -200, 200, -114, 368, 114, 368], [-87, -87, 0, 173, 580, 580, 305, 305], [2822, -2822, -639, 0, -114, 114, 296, -296], [-3488, 0, 1152, -1152, 220, -52, -220, -52], [-791, 791, 897, 0, 115, -115, -260, 260], [0, 4942, -159, -159, -99, -57, -99, 57], [-7286, 0, 4, -4, -127, 399, 127, 399], [-1505, -1505, 0, -327, 244, 244, -577, -577], [0, 6866, 1092, 1092, -377, -61, -377, 61], [8718, 0, 976, -976, -674, -220, 674, -220], [3278, 3278, 0, 565, 360, 360, -166, -166], [-1946, 0, -240, 240, 294, -232, -294, -232], [4738, -4738, -1303, 0, 414, -414, -236, 236], [4858, 4858, 0, -744, -137, -137, -132, -132], [-4452, -4452, 0, -311, 176, 176, 404, 404], [0, -2842, -156, -156, -592, -671, -592, 671], [0, 4326, 1721, 1721, -231, 231, -231, -231], [-1101, -1101, 0, 1256, 425, 425, 435, 435], [3180, -3180, -51, 0, -216, 216, -640, 640], [1261, -1261, 960, 0, -16, 16, 100, -100], [1380, 0, 952, -952, -562, -234, 562, -234], [4500, 0, -1068, 1068, -97, 1138, 97, 1138], [-1845, 1845, -715, 0, -563, 563, -548, 548], [-8, 8, -196, 0, 45, -45, 940, -940], [-4687, -4687, 0, 244, -983, -983, -611, -611], [-16442, 0, 460, -460, 311, 77, -311, 77], [0, 5402, -1087, -1087, -647, -281, -647, 281], [4244, 0, -1404, 1404, 43, 430, -43, 430], [5452, 5452, 0, 1201, -328, -328, 440, 440], [10153, -10153, 401, 0, -181, 181, -12, 12], [6284, -6284, -228, 0, 922, -922, -103, 103], [2714, 0, -396, 396, -711, 767, 711, 767], [2916, 0, -920, 920, -729, 56, 729, 56], [7033, -7033, 612, 0, 314, -314, 2, -2], [-5628, -5628, 0, 2364, 399, 399, -246, -246], [-3958, -3958, 0, -779, -524, -524, -170, -170], [0, 4246, -2163, -2163, -479, 619, -479, -619], [-10020, 0, 156, -156, -97, 376, 97, 376], [0, -17546, -24, -24, 41, -183, 41, 183], [-1512, 0, -2160, 2160, 132, -328, -132, -328], [-4347, 4347, -2231, 0, 775, -775, -300, 300], [8988, -8988, 1824, 0, -100, 100, -749, 749], [-20518, 0, 532, -532, 357, -677, -357, -677], [4139, 4139, 0, 1905, 244, 244, -233, -233], [0, 1162, 4013, 4013, 213, 523, 213, -523], [4942, 4942, 0, 2824, -92, -92, -711, -711], [11546, 0, -1524, 1524, 552, 312, -552, 312], [0, 17712, -1420, -1420, -156, 1184, -156, -1184], [-5792, 5792, 3244, 0, -759, 759, -464, 464], [8130, -8130, 1681, 0, -658, 658, 512, -512], [-4652, -4652, 0, 788, 756, 756, 355, 355], [0, -16796, -568, -568, -626, 1382, -626, -1382], [0, 158, 337, 337, 881, -809, 881, 809], [-6868, 0, -2564, 2564, 1091, 184, -1091, 184], [-2217, -2217, 0, 2425, 580, 580, -753, -753], [5856, -5856, -1019, 0, 1216, -1216, -140, 140], [0, -384, -2092, -2092, -253, 144, -253, -144], [-1892, 0, -3576, 3576, 238, -358, -238, -358], [-16780, 16780, -1956, 0, -511, 511, 212, -212], [-3781, -3781, 0, 1600, 834, 834, 256, 256], [-12290, 0, 876, -876, -269, -1143, 269, -1143], [-2443, -2443, 0, -1531, 896, 896, -1799, -1799], [16756, 16756, 0, 1392, 862, 862, 885, 885], [-108, 0, -828, 828, -757, -94, 757, -94], [5764, 5764, 0, -535, 1448, 1448, 308, 308], [16197, -16197, -839, 0, 287, -287, 84, -84], [11760, -11760, -1443, 0, -152, 152, 1208, -1208], [0, 8170, 2077, 2077, 221, -57, 221, 57], [6260, 0, -1816, 1816, -866, -1594, 866, -1594], [0, 4286, 512, 512, 1158, -1859, 1158, 1859], [-2943, -2943, 0, -2644, -603, -603, 1721, 1721], [-12182, 0, 844, -844, -60, -1128, 60, -1128], [-6830, 6830, 465, 0, -22, 22, -548, 548], [-4239, 4239, -2624, 0, 945, -945, -467, 467], [-14871, 14871, 3441, 0, 1067, -1067, 816, -816], [0, 358, 3457, 3457, 1285, 967, 1285, -967], [10101, 10101, 0, 1388, 90, 90, 854, 854], [-3577, -3577, 0, 1193, -560, -560, 2311, 2311], [0, 8218, 1413, 1413, -1935, 1991, -1935, -1991], [-12626, -12626, 0, -3820, -738, -738, -933, -933]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_320_n_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_320_4_n_g();".
// 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_320_4_n_g(:prec:=8)
    chi := MakeCharacter_320_n();
    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_320_4_n_g();".
// 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_320_4_n_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_n();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![506944, -82592, 6728, 5768, 2420, -8, 2, 2, 1]>,<13,R![4682705569936, 119865850752, 1534136832, -137033216, 9540264, 63776, 512, -32, 1]>],Snew);
    return Vf;
end function;