
// Make newform 490.4.c.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_490_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_490_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_490_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_490_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 := [9604, 0, 0, 0, 1325, 0, 0, 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, 1423, 0, 0, 0, 1, 0], [0, 0, -12319, 0, 0, 0, -10, 0], [682, 0, 0, 0, 1, 0, 0, 0], [0, 3822, 0, -1423, 0, 0, 0, -1], [0, -139454, 0, 31753, 0, -98, 0, 25], [0, 139454, 0, 51675, 0, 98, 0, 39], [0, 85946, 0, -51675, 0, 98, 0, -39]];
    Rf_basisdens := [1, 1911, 1911, 39, 3822, 53508, 53508, 53508];
    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_c();"
function MakeCharacter_490_c()
    N := 490;
    order := 2;
    char_gens := [197, 101];
    v := [1, 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_c_Hecke();"
function MakeCharacter_490_c_Hecke(Kf)
    N := 490;
    order := 2;
    char_gens := [197, 101];
    char_values := [[-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 := 4;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, -1, -1, -2, -2], [0, 0, 0, 0, 0, 0, 0, 0], [-3, 0, 0, -3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, -1, 2], [0, 0, 0, 0, 0, -13, -3, -13], [0, 0, 0, 0, 16, 1, 0, -1], [0, -4, 10, 0, 0, 0, 0, 0], [107, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 10, -32, 0, 32], [0, -96, -6, 0, 0, 0, 0, 0], [0, 0, 0, 0, -26, -20, 0, 20], [0, 26, -8, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -35, -43, -35], [0, -54, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, -66, -51, 0, 51], [0, 0, 0, 0, 104, -43, 0, 43], [0, -148, 16, 0, 0, 0, 0, 0], [-432, 0, 0, -18, 0, 0, 0, 0], [0, 0, 0, 0, 0, -8, 190, -8], [-367, 0, 0, -37, 0, 0, 0, 0], [0, 0, 0, 0, 0, -125, -106, -125], [0, 0, 0, 0, -46, 98, 0, -98], [0, 0, 0, 0, 0, -205, -175, -205], [0, 0, 0, 0, -48, -183, 0, 183], [0, 0, 0, 0, 0, 19, -137, 19], [0, -444, 48, 0, 0, 0, 0, 0], [1097, 0, 0, 39, 0, 0, 0, 0], [0, 568, 50, 0, 0, 0, 0, 0], [0, -530, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 212, -193, 0, 193], [0, -82, -80, 0, 0, 0, 0, 0], [0, 0, 0, 0, 38, -61, 0, 61], [-206, 0, 0, 128, 0, 0, 0, 0], [-517, 0, 0, 131, 0, 0, 0, 0], [0, 0, 0, 0, 0, 281, -340, 281], [0, 920, 124, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 69, -643, 69], [0, 0, 0, 0, 0, -290, 89, -290], [2880, 0, 0, -108, 0, 0, 0, 0], [0, 0, 0, 0, 2, 143, 0, -143], [1045, 0, 0, -49, 0, 0, 0, 0], [0, -1112, 86, 0, 0, 0, 0, 0], [0, -420, -78, 0, 0, 0, 0, 0], [0, 0, 0, 0, -172, 422, 0, -422], [-2521, 0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 601, 535, 601], [0, 0, 0, 0, 0, -32, -717, -32], [0, 0, 0, 0, 148, -299, 0, 299], [0, 2224, 32, 0, 0, 0, 0, 0], [693, 0, 0, -3, 0, 0, 0, 0], [0, 0, 0, 0, 114, 480, 0, -480], [0, 0, 0, 0, 186, 477, 0, -477], [0, 0, 0, 0, 0, 404, 142, 404], [0, -2520, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 822, -327, 0, 327], [0, 0, 0, 0, -326, 94, 0, -94], [0, 734, 262, 0, 0, 0, 0, 0], [-2463, 0, 0, 39, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1022, 1115, 1022], [0, 0, 0, 0, 0, -184, -1283, -184], [0, 0, 0, 0, 0, 498, 1161, 498], [0, 0, 0, 0, -1186, 314, 0, -314], [0, 0, 0, 0, 0, 747, 1149, 747], [0, -658, 394, 0, 0, 0, 0, 0], [6112, 0, 0, -20, 0, 0, 0, 0], [0, -2778, 66, 0, 0, 0, 0, 0], [0, 902, -404, 0, 0, 0, 0, 0], [0, 0, 0, 0, -636, -633, 0, 633], [0, 0, 0, 0, 0, -1297, 331, -1297], [1604, 0, 0, -356, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1775, 2069, 1775], [0, 3584, 250, 0, 0, 0, 0, 0], [-1872, 0, 0, 184, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1190, -1500, 1190], [-4571, 0, 0, 467, 0, 0, 0, 0], [0, 0, 0, 0, 0, 602, 851, 602], [2143, 0, 0, 359, 0, 0, 0, 0], [0, 0, 0, 0, -108, -1194, 0, 1194], [0, 0, 0, 0, -906, 549, 0, -549], [567, 0, 0, -563, 0, 0, 0, 0], [7529, 0, 0, -47, 0, 0, 0, 0], [0, 0, 0, 0, 0, -770, 490, -770], [0, 0, 0, 0, -192, -60, 0, 60], [0, 6782, 148, 0, 0, 0, 0, 0], [-5449, 0, 0, -659, 0, 0, 0, 0], [0, -3076, -602, 0, 0, 0, 0, 0], [0, 0, 0, 0, 934, 595, 0, -595], [0, 6746, -140, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 800, -2675, 800], [0, 0, 0, 0, -126, -1320, 0, 1320], [0, -3166, 118, 0, 0, 0, 0, 0], [-6913, 0, 0, 343, 0, 0, 0, 0], [-3489, 0, 0, 631, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2931, 2437, 2931], [0, 0, 0, 0, 1510, 1603, 0, -1603], [0, 0, 0, 0, 2262, -1488, 0, 1488], [0, 0, 0, 0, 0, -2383, -934, -2383], [8529, 0, 0, -749, 0, 0, 0, 0], [0, 1198, 560, 0, 0, 0, 0, 0], [0, 3006, 342, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 967, -2218, 967], [7790, 0, 0, -674, 0, 0, 0, 0], [8416, 0, 0, -56, 0, 0, 0, 0], [0, 0, 0, 0, 0, -733, -3097, -733], [0, 0, 0, 0, 0, 2857, 1274, 2857], [0, 0, 0, 0, 0, 849, 2261, 849], [-16145, 0, 0, -139, 0, 0, 0, 0], [0, 0, 0, 0, 596, -352, 0, 352], [0, 0, 0, 0, 0, 537, 1395, 537], [0, 6118, -730, 0, 0, 0, 0, 0], [0, -3498, 1038, 0, 0, 0, 0, 0], [0, 0, 0, 0, -236, 1735, 0, -1735], [6201, 0, 0, 499, 0, 0, 0, 0], [10806, 0, 0, -114, 0, 0, 0, 0], [0, 0, 0, 0, 0, -420, 1509, -420], [0, 0, 0, 0, 0, 3762, 5012, 3762], [0, -4600, -1034, 0, 0, 0, 0, 0], [419, 0, 0, -209, 0, 0, 0, 0], [0, 0, 0, 0, 1526, 869, 0, -869], [0, -3470, 1208, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 272, -2735, 272], [0, -4470, -708, 0, 0, 0, 0, 0], [0, 0, 0, 0, 958, -2663, 0, 2663], [-16547, 0, 0, -313, 0, 0, 0, 0], [-7997, 0, 0, -483, 0, 0, 0, 0], [0, 0, 0, 0, -1442, 1516, 0, -1516], [0, 0, 0, 0, 0, -2190, -2460, -2190], [0, 0, 0, 0, 0, 2798, 6347, 2798], [-3173, 0, 0, 535, 0, 0, 0, 0], [0, -3422, -1630, 0, 0, 0, 0, 0], [12183, 0, 0, -649, 0, 0, 0, 0], [0, 782, -1766, 0, 0, 0, 0, 0], [0, 0, 0, 0, 3254, -172, 0, 172], [0, 0, 0, 0, 3464, -2182, 0, 2182], [0, 0, 0, 0, 0, -1808, 839, -1808], [0, 0, 0, 0, 0, 586, 3787, 586], [0, 0, 0, 0, 0, -1608, -2201, -1608], [-5331, 0, 0, -1227, 0, 0, 0, 0], [0, 0, 0, 0, 1054, -359, 0, 359], [7107, 0, 0, -1335, 0, 0, 0, 0], [0, 10814, 364, 0, 0, 0, 0, 0], [0, 936, -348, 0, 0, 0, 0, 0], [0, 0, 0, 0, 3680, -937, 0, 937], [0, 0, 0, 0, 714, -120, 0, 120], [0, 0, 0, 0, 0, -5237, -9728, -5237], [0, 0, 0, 0, 0, -1138, -1434, -1138], [0, 0, 0, 0, 1242, 777, 0, -777], [0, -8242, 1372, 0, 0, 0, 0, 0], [0, 6924, -114, 0, 0, 0, 0, 0], [0, 0, 0, 0, -912, 204, 0, -204], [0, -10406, 284, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -5042, -4636, -5042], [0, -2566, -260, 0, 0, 0, 0, 0], [-10172, 0, 0, -1444, 0, 0, 0, 0], [-15371, 0, 0, 151, 0, 0, 0, 0], [0, 0, 0, 0, 3524, -682, 0, 682], [0, 0, 0, 0, 0, -3159, 3885, -3159], [0, 0, 0, 0, -3892, -2401, 0, 2401], [0, 8730, -708, 0, 0, 0, 0, 0], [0, -21722, -664, 0, 0, 0, 0, 0], [0, 2734, 2186, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4932, 357, 0, -357], [0, 1022, 2608, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 101, 4789, 101], [-8144, 0, 0, -326, 0, 0, 0, 0], [0, 0, 0, 0, 0, 894, 1815, 894]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_490_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_490_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_490_4_c_d(:prec:=8)
    chi := MakeCharacter_490_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_490_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_490_4_c_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_490_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![98, 0, 39, 0, 1]>,<19,R![15103008, 0, -20794, 0, 1]>],Snew);
    return Vf;
end function;