
// Make newform 720.6.f.n in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_720_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_720_f_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_720_6_f_n();".
// 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_720_6_f_n();".
// 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 := [9, 0, 969, 0, 460, 0, 41, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-29412, -203676, -19752, -86042, -2232, -7372, -66, -176], [0, -160458, 0, -82106, 0, -7420, 0, -182], [29412, -646692, 19752, -295142, 2232, -26548, 66, -656], [-390564, -203676, -259752, -86042, -17592, -7372, -282, -176], [-144180, -203676, 457848, -86042, 59688, -7372, 1710, -176], [-29412, 991374, -19752, 454172, -2232, 40168, -66, 974], [-147060, 1499754, -98760, 676528, -11160, 59120, -330, 1426]];
    Rf_basisdens := [1, 639, 213, 639, 639, 639, 639, 639];
    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_720_f();"
function MakeCharacter_720_f()
    N := 720;
    order := 2;
    char_gens := [271, 181, 641, 577];
    v := [2, 2, 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_720_f_Hecke();"
function MakeCharacter_720_f_Hecke(Kf)
    N := 720;
    order := 2;
    char_gens := [271, 181, 641, 577];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [-1, 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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [-1, 1, 0, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 1, 0], [-92, -1, 0, 0, 1, 0, 0, 0], [0, -2, 1, -1, 0, 0, -4, 1], [0, 9, -14, -1, 0, 0, 0, -2], [-172, 19, 4, 0, 1, 0, 0, 4], [0, 1, 6, -10, 0, 0, 9, -4], [-734, -26, -4, 0, 4, 2, 0, -4], [-528, 16, 4, 0, 0, 4, 0, 4], [0, 5, 137, 26, 0, 0, 16, 1], [-2950, 34, 9, 0, 16, -5, 0, 9], [0, 54, -81, 108, 0, 0, 54, 0], [0, -81, -168, 50, 0, 0, -9, 28], [0, 70, -39, 191, 0, 0, 36, 17], [11460, -57, -12, 0, 13, -16, 0, -12], [15482, -263, -53, 0, -8, 6, 0, -53], [0, -214, -33, -124, 0, 0, 10, 16], [-15704, 458, 84, 0, -2, -36, 0, 84], [0, -103, -388, -311, 0, 0, -8, -40], [-5408, -628, -124, 0, 28, -20, 0, -124], [0, 302, -615, -236, 0, 0, 342, -176], [5238, -270, -36, 0, 48, 42, 0, -36], [0, 107, -486, 49, 0, 0, -488, 86], [-84006, -950, -188, 0, 20, -10, 0, -188], [0, 115, 202, -106, 0, 0, 599, -164], [0, 1564, 1003, -144, 0, 0, -108, -320], [-67494, 131, 71, 0, 192, 32, 0, 71], [0, 548, 1444, -520, 0, 0, -288, -156], [0, 2133, -982, 244, 0, 0, -129, -352], [-103716, -1831, -460, 0, -413, -56, 0, -460], [0, 1310, -1370, 620, 0, 0, -1800, 222], [-106724, -1751, -368, 0, -129, 40, 0, -368], [-22914, -185, 1, 0, -88, 278, 0, 1], [136760, -3094, -592, 0, 190, -56, 0, -592], [0, 4531, -17, -138, 0, 0, -904, -753], [0, 2992, -1159, -1356, 0, 0, -868, -696], [0, 153, -4566, -886, 0, 0, -819, -44], [0, -2547, -6083, -1514, 0, 0, 288, 149], [156668, 649, 168, 0, 79, 112, 0, 168], [8854, -406, 20, 0, 396, 110, 0, 20], [47712, -4464, -792, 0, 640, -136, 0, -792], [0, -403, -5010, -433, 0, 0, -440, 82], [0, 4644, -63, 669, 0, 0, 1620, -1119], [278296, 1382, 188, 0, -510, 68, 0, 188], [81908, -5981, -1124, 0, 801, -440, 0, -1124], [0, 441, 8262, 4100, 0, 0, -1221, 976], [0, 1112, 2143, -116, 0, 0, -1188, -8], [359526, 2598, 396, 0, -4, -614, 0, 396], [0, 4599, -1172, 3375, 0, 0, -504, -144], [-523648, -8364, -1636, 0, 316, -132, 0, -1636], [-354946, -1018, -469, 0, -1352, 25, 0, -469], [-31468, 2275, 552, 0, -347, 832, 0, 552], [0, 6444, 9376, 316, 0, 0, 2232, -1672], [0, 1665, -7484, -5548, 0, 0, -4293, -584], [89814, 6303, 813, 0, -2024, -214, 0, 813], [-1080704, -1972, -484, 0, -804, 356, 0, -484], [0, 6633, -8811, 6842, 0, 0, 3504, -659], [972474, 12152, 2165, 0, -528, -799, 0, 2165], [0, 21168, 8069, 6500, 0, 0, 2172, -3368], [0, 773, -10365, 1956, 0, 0, 9648, -1693], [0, -242, 7155, -7740, 0, 0, 4022, -2304], [793896, 9126, 2160, 0, 410, 1264, 0, 2160], [0, 7442, 20974, -3848, 0, 0, 7000, -3658], [0, -6516, -12657, 3619, 0, 0, -180, 2063], [-868948, 1021, 628, 0, 727, 1392, 0, 628], [0, -1766, -5216, 9602, 0, 0, 4568, 1360], [0, -6490, 4561, -8456, 0, 0, 16794, -3752], [739966, -9674, -2276, 0, -1396, -310, 0, -2276], [0, 18558, -32180, -11006, 0, 0, -8784, -4156], [-1341128, 4898, 816, 0, 222, -1040, 0, 816], [0, -20807, -30, -12568, 0, 0, 3719, 904], [0, -26651, -22347, 6534, 0, 0, 4160, 5805], [-1094740, 15845, 2984, 0, 1915, -2840, 0, 2984], [0, 3447, -8842, 19944, 0, 0, 9657, 1368], [812334, -21577, -3655, 0, 4472, -1170, 0, -3655], [0, 24840, 18597, 12373, 0, 0, -12972, 101], [-427394, -18034, -3708, 0, -640, 134, 0, -3708], [-679178, -6366, 135, 0, 6752, 289, 0, 135], [4364652, -20851, -4144, 0, 179, -48, 0, -4144], [500050, 31061, 7391, 0, 5800, 94, 0, 7391], [373472, 35444, 5764, 0, -5828, -796, 0, 5764], [0, -5211, 65274, 2579, 0, 0, -21840, 5926], [2710680, 21354, 5664, 0, 6694, 272, 0, 5664], [0, 17856, -71913, 14920, 0, 0, 14184, -3424], [1089234, 9458, 3053, 0, 5128, 679, 0, 3053], [0, 20268, -60506, 23762, 0, 0, 24024, -4106], [-3066222, 42994, 9268, 0, 628, 2718, 0, 9268], [0, 15005, 67952, 20962, 0, 0, 14377, -1684], [0, -20376, -54197, -6576, 0, 0, 28440, -2928], [-1750048, 38688, 6416, 0, -8088, 1480, 0, 6416], [0, -70033, 8204, -45252, 0, 0, -59, 4968], [-4345964, 37963, 7940, 0, 4561, -2824, 0, 7940], [-3656860, 1711, 1024, 0, 7953, -4544, 0, 1024], [0, -37267, 18774, -18286, 0, 0, -2079, 4212], [1395650, 31014, 6044, 0, -6988, 6194, 0, 6044], [-4420010, 18744, 2464, 0, -7312, 888, 0, 2464], [0, 26996, 43673, 44036, 0, 0, 16360, 136], [-1404962, 47314, 11236, 0, 3148, 5718, 0, 11236], [0, -21916, 28645, -48972, 0, 0, 1864, -5784], [0, 38817, -17683, 15274, 0, 0, -43848, 4061], [0, -42624, 12239, -40212, 0, 0, -25308, 5544], [4986666, -13402, -2743, 0, 1792, -2105, 0, -2743], [2741324, -23259, -3648, 0, 3483, 1536, 0, -3648], [0, -17618, 85124, 37610, 0, 0, -35632, 18172], [0, 42142, 113081, 4880, 0, 0, -29862, -1480], [0, 8908, 40308, -7280, 0, 0, -15768, -84], [2138776, -8874, -3164, 0, 1066, -8012, 0, -3164], [4385766, 29172, 4515, 0, -1984, -4613, 0, 4515], [0, -167663, 24296, -39850, 0, 0, -23647, 30292], [0, -110480, 36535, -49793, 0, 0, 45812, 2975], [0, -59579, -147480, 2545, 0, 0, 18144, 8796], [-3004628, -117315, -24564, 0, -9233, 3728, 0, -24564], [-1681064, 75474, 14688, 0, 822, -2856, 0, 14688], [980850, -16554, -3387, 0, -4232, 3851, 0, -3387], [0, 48258, -6269, -10256, 0, 0, 23046, -16312], [0, -47747, -103120, -32676, 0, 0, -25209, 8056], [0, -76716, 31739, -15593, 0, 0, 44388, 3347], [6544380, 103793, 23840, 0, 9287, 6120, 0, 23840], [-976750, -64589, -12893, 0, 656, -532, 0, -12893], [0, 32471, -137710, 14661, 0, 0, 30520, -9666], [0, 92430, -89923, 77163, 0, 0, -18612, 669], [0, 17602, 115645, 86824, 0, 0, 15102, 10824], [-8226828, -106597, -18652, 0, 5033, 8304, 0, -18652], [9234742, 20101, -1375, 0, -16752, -10224, 0, -1375], [5885414, -51158, -13196, 0, -10852, -3970, 0, -13196], [1154656, 38004, 12076, 0, 25956, -3580, 0, 12076], [0, -73377, 152132, 5228, 0, 0, -7035, 17128], [0, 33237, -32645, 84268, 0, 0, 25656, 5075], [5283828, -142741, -29416, 0, -7603, 3264, 0, -29416], [0, -62955, 14200, 99244, 0, 0, 35199, 25400], [-9272432, 105260, 21848, 0, -1892, 5872, 0, 21848], [0, 124187, -80783, -17712, 0, 0, -44024, -19575], [1163830, -41114, -4348, 0, 27560, -8186, 0, -4348], [6948098, 111256, 23440, 0, 1656, 4288, 0, 23440], [0, -141946, -97379, -42781, 0, 0, 87300, 2373], [0, 63106, -66401, -67244, 0, 0, -85870, -8896], [0, 155898, 145867, 2885, 0, 0, 5292, -31661], [7998774, -251544, -49728, 0, -9424, 12328, 0, -49728], [-5356836, 12881, -424, 0, 2519, -17520, 0, -424], [-5565522, -51871, -8875, 0, 2928, 4568, 0, -8875], [0, 85655, -80114, 30934, 0, 0, -90941, 7244], [0, 53658, 98669, -100840, 0, 0, -50778, -20744], [8332538, 64753, 21355, 0, 40568, 1454, 0, 21355], [6436632, -1358, 2752, 0, 3078, 12040, 0, 2752], [0, -79334, -307049, -93999, 0, 0, 58580, -14649], [0, 95008, -13578, 26918, 0, 0, 60840, -25786], [12298396, -88743, -20676, 0, -11301, -3336, 0, -20676], [0, -137457, 27860, -120330, 0, 0, -58653, 15156], [0, -81551, 389911, -89548, 0, 0, -101632, 18727], [790450, 170516, 30129, 0, -39048, 19177, 0, 30129], [0, 111136, -420427, -8312, 0, 0, 207272, -65344], [0, -133299, -48520, 87404, 0, 0, 94023, 25336], [0, 300016, 136397, 16276, 0, 0, -101380, -36472], [1038816, 286188, 56508, 0, 16308, -19956, 0, 56508], [1568424, 12970, 7324, 0, 46182, -22532, 0, 7324], [12180850, -249150, -52115, 0, -7032, -4393, 0, -52115], [0, 113917, -129692, 126245, 0, 0, -80992, 18664], [-4883182, 75190, 21228, 0, 5668, 25282, 0, 21228], [0, 105642, -221511, 25040, 0, 0, 171198, -50360], [0, 91620, 161302, 127194, 0, 0, -147816, 36678], [0, 95195, 591246, -75454, 0, 0, 37171, -41564], [-5946252, -254013, -58668, 0, -31655, -7672, 0, -58668], [0, -424333, 81566, 26301, 0, 0, -70416, 104210], [0, -80195, 47652, 13544, 0, 0, 14859, 15776], [15708704, -25816, -7696, 0, 7416, -20080, 0, -7696], [0, 127314, 41755, -29491, 0, 0, 231420, -77645]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_720_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_720_6_f_n();".
// 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_720_6_f_n(:prec:=8)
    chi := MakeCharacter_720_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_720_6_f_n();".
// 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_720_6_f_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_720_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![2623778518100224, 0, 25184325932032, 0, 2632172640, 0, 89728, 0, 1]>,<11,R![37397137664, -126641408, -468000, 368, 1]>],Snew);
    return Vf;
end function;