
// Make newform 490.4.e.y in Magma, downloaded from the LMFDB on 22 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_490_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_490_e_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_490_4_e_y();".
// 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_490_4_e_y();".
// 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 := [8100, -5940, 4446, -114, 67, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [397980, -5940, 4446, -4489, 67, -1], [-90450, -3210012, 16683, -48374, 722, -737], [-12731310, 386100, -288990, -157, -4355, 65], [-87750, -2982018, 16185, -46930, -752, -715]];
    Rf_basisdens := [1, 1, 291942, 4379130, 291942, 97314];
    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_490_e();"
function MakeCharacter_490_e()
    N := 490;
    order := 3;
    char_gens := [197, 101];
    v := [3, 2];
    // 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_490_e_Hecke();"
function MakeCharacter_490_e_Hecke(Kf)
    N := 490;
    order := 3;
    char_gens := [197, 101];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, -1, 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]];
    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 := [[-2, 0, 0, -2, 0, 0], [0, 1, 0, -1, 0, 0], [5, 0, 0, 5, 0, 0], [0, 0, 0, 0, 0, 0], [0, 5, 0, 15, 0, 1], [1, 0, -1, 0, 1, 0], [0, 12, 0, -6, 0, 0], [17, -1, 1, 17, 3, -3], [-42, 16, -16, -42, 3, -3], [96, 0, -17, 0, 3, 0], [0, -2, 0, 10, 0, -4], [-269, 5, -5, -269, 1, -1], [-117, 0, 40, 0, 2, 0], [125, 0, -23, 0, -8, 0], [-309, 47, -47, -309, 3, -3], [0, 11, 0, 117, 0, -15], [0, -52, 0, 72, 0, 4], [-304, -19, 19, -304, 9, -9], [0, 35, 0, -49, 0, 12], [-384, 0, 60, 0, -12, 0], [0, -106, 0, 160, 0, -2], [70, -106, 106, 70, 6, -6], [-213, 0, 25, 0, 12, 0], [-138, 15, -15, -138, -29, 29], [-590, 0, 136, 0, -8, 0], [0, -109, 0, -210, 0, 35], [617, 15, -15, 617, 18, -18], [69, 189, -189, 69, -4, 4], [0, 59, 0, 380, 0, -3], [600, 0, -16, 0, 32, 0], [-211, 0, 155, 0, 9, 0], [-1155, -53, 53, -1155, 7, -7], [0, -136, 0, -108, 0, 8], [-278, 0, -86, 0, 16, 0], [630, -337, 337, 630, -29, 29], [0, 140, 0, -1024, 0, -54], [0, 165, 0, 1009, 0, 27], [904, 266, -266, 904, -42, 42], [2868, 0, -120, 0, -33, 0], [1101, -141, 141, 1101, 15, -15], [0, 131, 0, -1179, 0, -5], [-1640, 0, 195, 0, 79, 0], [-150, 142, -142, -150, 32, -32], [0, -266, 0, -1120, 0, -30], [1899, 0, 333, 0, -17, 0], [0, -12, 0, -1448, 0, 116], [-2323, 0, 181, 0, 67, 0], [4, 0, 118, 0, 14, 0], [0, -294, 0, 1476, 0, -50], [-940, -114, 114, -940, 78, -78], [1122, 4, -4, 1122, -16, 16], [3660, 0, -96, 0, 66, 0], [0, -511, 0, -1643, 0, -105], [1275, 0, -157, 0, -57, 0], [1344, 252, -252, 1344, 164, -164], [0, 287, 0, 1293, 0, 86], [0, 269, 0, 3360, 0, -105], [1856, 168, -168, 1856, 96, -96], [0, 456, 0, 518, 0, 48], [-567, 0, 231, 0, 73, 0], [0, 460, 0, -1634, 0, 92], [-627, 0, 277, 0, 31, 0], [2323, 0, -419, 0, -50, 0], [0, 544, 0, -1956, 0, -188], [-2536, 120, -120, -2536, -100, 100], [906, 196, -196, 906, -52, 52], [-5189, 617, -617, -5189, 91, -91], [2126, 0, -558, 0, 218, 0], [0, 1335, 0, 1947, 0, 92], [-3584, 0, 97, 0, 209, 0], [0, 800, 0, 2928, 0, 212], [4836, 408, -408, 4836, 22, -22], [0, -254, 0, 10816, 0, -7], [-4994, 574, -574, -4994, 174, -174], [-5443, 0, 25, 0, -281, 0], [6558, 244, -244, 6558, 177, -177], [0, -378, 0, 10188, 0, 34], [-5914, -576, 576, -5914, 0, 0], [-9213, 482, -482, -9213, 74, -74], [0, 85, 0, 7108, 0, -155], [-1005, 0, 403, 0, -67, 0], [1466, 0, 917, 0, -33, 0], [0, -510, 0, 4782, 0, -24], [-3248, 0, 256, 0, 144, 0], [1082, -702, 702, 1082, 6, -6], [-1971, -1477, 1477, -1971, -94, 94], [9807, 0, -588, 0, 10, 0], [-6914, -830, 830, -6914, 174, -174], [-3306, 0, -884, 0, 316, 0], [950, 0, 734, 0, 173, 0], [4257, -979, 979, 4257, 130, -130], [0, -1218, 0, -1482, 0, 224], [0, -1910, 0, -3652, 0, -110], [6522, 0, 678, 0, -44, 0], [6526, -406, 406, 6526, -96, 96], [12705, 0, 127, 0, -104, 0], [9060, -1371, 1371, 9060, -197, 197], [0, -333, 0, -4797, 0, 165], [-5908, -478, 478, -5908, 82, -82], [-3110, -485, 485, -3110, 101, -101], [2999, 0, -23, 0, 392, 0], [0, -737, 0, 5007, 0, -239], [0, -47, 0, 8877, 0, -318], [5127, 1547, -1547, 5127, 403, -403], [0, -440, 0, -14800, 0, -60], [0, 1070, 0, 4792, 0, -474], [14064, 0, 90, 0, 246, 0], [-1584, 100, -100, -1584, -332, 332], [0, -566, 0, 6714, 0, 102], [-4538, 0, -1884, 0, 44, 0], [-1630, 992, -992, -1630, -161, 161], [0, 1973, 0, -2671, 0, -233], [7950, 0, 2454, 0, -382, 0], [0, -1361, 0, -5315, 0, 187], [-3514, 0, 2114, 0, -228, 0], [0, 180, 0, 4785, 0, -390], [11530, 0, 1032, 0, -240, 0], [0, 294, 0, -13632, 0, 17], [5949, -939, 939, 5949, 193, -193], [-3240, 0, -1232, 0, 376, 0], [0, -169, 0, 2536, 0, -239], [-16150, 0, -666, 0, 238, 0], [7371, 83, -83, 7371, -409, 409], [0, 813, 0, 7455, 0, -554], [8930, 542, -542, 8930, -396, 396], [3174, 0, -575, 0, 127, 0], [6016, -1129, 1129, 6016, -407, 407], [-810, -34, 34, -810, -568, 568], [4528, 0, 2432, 0, -601, 0], [5657, -2527, 2527, 5657, 229, -229], [0, 173, 0, -10633, 0, -487], [7566, 0, -2162, 0, -159, 0], [25606, 262, -262, 25606, 422, -422], [-10762, 0, 2936, 0, -112, 0], [7065, 257, -257, 7065, 625, -625], [-10811, 0, -1161, 0, 65, 0], [0, -813, 0, -18561, 0, -255], [0, -1821, 0, 7243, 0, -266], [6546, 0, -1366, 0, -34, 0], [0, -1450, 0, 10395, 0, -178], [589, 0, 2617, 0, 869, 0], [-8118, -968, 968, -8118, -1144, 1144], [0, 579, 0, -23725, 0, 28], [-1629, 0, -1001, 0, 392, 0], [0, -1812, 0, -11606, 0, -212], [3732, 0, -1988, 0, -222, 0], [-24005, 0, 383, 0, -503, 0], [0, 216, 0, -24522, 0, -268], [-2680, 592, -592, -2680, -608, 608], [-10452, 540, -540, -10452, -635, 635], [433, -2521, 2521, 433, 739, -739], [-1407, 0, 214, 0, -304, 0], [-14608, 0, -2342, 0, -426, 0], [-4347, -1103, 1103, -4347, 588, -588], [0, 3461, 0, -15325, 0, -604], [16908, 0, 2724, 0, -130, 0], [-3734, 1954, -1954, -3734, 642, -642], [-7317, 356, -356, -7317, 826, -826], [16762, 0, -1970, 0, 1202, 0], [0, -1646, 0, 28776, 0, 334], [-41169, 415, -415, -41169, -498, 498], [15948, 0, -2772, 0, -364, 0], [-20191, 0, -2897, 0, -352, 0], [-13695, 1019, -1019, -13695, -413, 413], [0, -2324, 0, 10842, 0, -728], [0, 2742, 0, 3810, 0, -1255], [0, -254, 0, 11714, 0, -1452], [0, 3294, 0, 19882, 0, 774]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_490_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_490_4_e_y();".
// 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_490_4_e_y(:prec:=6)
    chi := MakeCharacter_490_e();
    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_490_4_e_y();".
// 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_490_4_e_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_490_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![23716, -9394, 4337, -64, 77, -4, 1]>,<11,R![10489856400, 255640320, 10429236, 102504, 4177, 41, 1]>],Snew);
    return Vf;
end function;