
// Make newform 490.4.c.e in Magma, downloaded from the LMFDB on 19 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_e();".
// 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_e();".
// 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 := [60840000, 0, 33016000, 0, 5908496, 0, 405460, 0, 12748, 0, 185, 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], [31, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [167652000, 0, 40381408, 0, 1082536, 0, -32112, 0, -1331, 0, -11, 0], [-12402000, 0, -5385040, 0, -725074, 0, -33981, 0, -631, 0, -4, 0], [0, -326805600, 0, -124631048, 0, -12654320, 0, -511584, 0, -8765, 0, -53], [40345344000, 5032389600, 13584773280, 1578737104, 1229242560, 136581760, 45611280, 4984182, 737490, 80395, 4290, 469], [-40345344000, 5032389600, -13584773280, 1578737104, -1229242560, 136581760, -45611280, 4984182, -737490, 80395, -4290, 469], [0, 349737600, 0, 124631048, 0, 12654320, 0, 511584, 0, 8765, 0, 53], [0, 1474639200, 0, 324703332, 0, 5166700, 0, -510039, 0, -16335, 0, -128], [1575194400, 688632480, 1331831488, 259382640, 274726816, 37724400, 14793948, 1842210, 292864, 34995, 1924, 225], [1575194400, -688632480, 1331831488, -259382640, 274726816, -37724400, 14793948, -1842210, 292864, -34995, 1924, -225], [0, -2546759200, 0, -821150696, 0, -67921560, 0, -2341348, 0, -35885, 0, -201]];
    Rf_basisdens := [1, 1, 529200, 44100, 22932000, 137592000, 137592000, 11466000, 11466000, 13759200, 13759200, 7644000];
    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, 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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -3, -2, -2, 4, -2, 2, -2, 1], [0, 0, 0, 0, -5, 0, 0, -8, -3, 1, -1, -2], [17, -1, -2, 2, 0, -1, 1, 0, 0, -2, -2, 0], [0, 0, 0, 0, 2, -2, -2, 11, 2, -2, 2, 3], [-22, 3, -6, -2, 0, -11, 11, 0, 0, -3, -3, 0], [-54, -4, -1, 7, 0, 4, -4, 0, 0, -3, -3, 0], [0, 0, 0, 0, -6, -4, -4, -18, 1, -7, 7, -5], [-33, 0, -7, -12, 0, -6, 6, 0, 0, 3, 3, 0], [0, 0, 0, 0, -25, -15, -15, 5, -4, 1, -1, -4], [0, 0, 0, 0, -35, 3, 3, -91, 4, -4, 4, -9], [0, 0, 0, 0, -37, 1, 1, -28, 2, -10, 10, 7], [104, 26, -11, -21, 0, -6, 6, 0, 0, -3, -3, 0], [-42, -1, -9, -26, 0, 11, -11, 0, 0, -2, -2, 0], [0, 0, 0, 0, 12, -11, -11, 118, 1, -14, 14, -6], [170, 6, 11, -51, 0, -5, 5, 0, 0, -2, -2, 0], [0, 0, 0, 0, -5, -6, -6, 128, 15, -15, 15, -4], [142, -4, 9, -7, 0, 6, -6, 0, 0, -13, -13, 0], [0, 0, 0, 0, -90, 10, 10, 94, 19, 15, -15, 8], [502, 5, 3, 19, 0, 17, -17, 0, 0, -13, -13, 0], [0, 0, 0, 0, 98, -10, -10, -244, -2, 12, -12, 8], [-136, -5, 4, 88, 0, -34, 34, 0, 0, -1, -1, 0], [0, 0, 0, 0, -9, 48, 48, 100, -10, -13, 13, -30], [0, 0, 0, 0, -78, 25, 25, -32, -15, -14, 14, 12], [446, 21, -13, -22, 0, -33, 33, 0, 0, -2, -2, 0], [0, 0, 0, 0, 83, -7, -7, 192, -9, -9, 9, -28], [0, 0, 0, 0, -167, 8, 8, -293, -10, 13, -13, -11], [-173, -15, 19, -69, 0, 28, -28, 0, 0, -12, -12, 0], [0, 0, 0, 0, -152, -55, -55, -92, 18, 20, -20, 22], [16, 12, -46, -58, 0, -110, 110, 0, 0, -28, -28, 0], [666, -23, -35, 72, 0, -43, 43, 0, 0, -6, -6, 0], [-134, -40, -49, 11, 0, 10, -10, 0, 0, -17, -17, 0], [0, 0, 0, 0, 14, -20, -20, -538, -47, 1, -1, -29], [0, 0, 0, 0, 125, 58, 58, -693, 15, 19, -19, 26], [0, 0, 0, 0, 99, -58, -58, -48, -45, -11, 11, -37], [0, 0, 0, 0, -54, -34, -34, 158, -55, 33, -33, 31], [441, 67, -26, -54, 0, -73, 73, 0, 0, 38, 38, 0], [1068, -69, 44, 48, 0, 1, -1, 0, 0, -41, -41, 0], [300, -30, 38, -64, 0, -37, 37, 0, 0, 51, 51, 0], [0, 0, 0, 0, 378, -15, -15, 700, 74, -40, 40, -60], [0, 0, 0, 0, -56, -131, -131, -82, -45, 43, -43, 55], [1102, -40, -66, 20, 0, 99, -99, 0, 0, 1, 1, 0], [657, 85, -76, -10, 0, -62, 62, 0, 0, -1, -1, 0], [0, 0, 0, 0, -127, -211, -211, 1139, -51, -8, 8, -20], [0, 0, 0, 0, -365, 140, 140, -895, 151, 9, -9, 12], [1290, -12, 60, -34, 0, -19, 19, 0, 0, 30, 30, 0], [0, 0, 0, 0, 377, -224, -224, -1456, -67, 101, -101, -16], [-612, -36, -113, -139, 0, -53, 53, 0, 0, 18, 18, 0], [-1145, 93, 109, -7, 0, 32, -32, 0, 0, 67, 67, 0], [-311, 137, -62, -48, 0, -120, 120, 0, 0, -39, -39, 0], [0, 0, 0, 0, -492, -25, -25, -116, -16, -46, 46, -132], [0, 0, 0, 0, -137, -2, -2, 1140, 24, 139, -139, 114], [1586, 51, 11, -180, 0, -117, 117, 0, 0, 84, 84, 0], [432, 6, -135, -31, 0, 44, -44, 0, 0, -1, -1, 0], [0, 0, 0, 0, -417, 146, 146, -1114, 5, 3, -3, 138], [-247, -117, 159, 325, 0, 33, -33, 0, 0, 65, 65, 0], [0, 0, 0, 0, -53, 40, 40, 3071, -37, 15, -15, -48], [0, 0, 0, 0, -288, 153, 153, 678, -9, -19, 19, -237], [0, 0, 0, 0, 402, -226, -226, 8, -129, 25, -25, -72], [238, -120, -93, -301, 0, -36, 36, 0, 0, -65, -65, 0], [0, 0, 0, 0, 182, -75, -75, 1332, 82, 78, -78, -76], [0, 0, 0, 0, -429, -120, -120, 654, 181, -73, 73, -82], [83, -107, 82, 546, 0, 549, -549, 0, 0, -24, -24, 0], [0, 0, 0, 0, -319, 215, 215, -812, -167, -87, 87, -168], [0, 0, 0, 0, 288, 171, 171, -1106, 47, -52, 52, -176], [-3346, 113, 184, 36, 0, 97, -97, 0, 0, 31, 31, 0], [0, 0, 0, 0, -997, -78, -78, 2080, -101, 43, -43, -100], [4, 14, 9, -175, 0, 322, -322, 0, 0, -21, -21, 0], [0, 0, 0, 0, 230, 0, 0, -953, -148, 50, -50, 207], [0, 0, 0, 0, 272, 169, 169, -1712, -52, -162, 162, 56], [447, -77, 186, -320, 0, 192, -192, 0, 0, -45, -45, 0], [0, 0, 0, 0, 146, -34, -34, 655, -74, -114, 114, 37], [-1084, -54, 14, -218, 0, -43, 43, 0, 0, 50, 50, 0], [0, 0, 0, 0, 48, 35, 35, -840, -16, -16, 16, 372], [2893, 26, -182, 280, 0, -354, 354, 0, 0, -150, -150, 0], [-2366, 63, -112, 441, 0, 48, -48, 0, 0, -174, -174, 0], [-687, -79, -67, 19, 0, -113, 113, 0, 0, 225, 225, 0], [682, 153, -239, -2, 0, 2, -2, 0, 0, -86, -86, 0], [-2994, -84, -80, 18, 0, 475, -475, 0, 0, 155, 155, 0], [0, 0, 0, 0, 255, 107, 107, 3916, -51, 93, -93, 134], [-7628, 62, 264, 122, 0, 243, -243, 0, 0, 93, 93, 0], [0, 0, 0, 0, -209, -182, -182, -2943, -298, 94, -94, -6], [5321, -16, 253, 134, 0, 148, -148, 0, 0, 265, 265, 0], [0, 0, 0, 0, -430, -285, -285, -72, -122, -62, 62, -100], [1508, 150, 146, -84, 0, 310, -310, 0, 0, 366, 366, 0], [0, 0, 0, 0, -297, 266, 266, 158, -67, -165, 165, -61], [0, 0, 0, 0, 262, -255, -255, -898, 121, -276, 276, -358], [-4500, -214, 279, 407, 0, 496, -496, 0, 0, 89, 89, 0], [0, 0, 0, 0, -107, 70, 70, 1815, -317, 5, -5, -250], [-576, 60, 197, 305, 0, -119, 119, 0, 0, 224, 224, 0], [524, -362, -442, -396, 0, 271, -271, 0, 0, -285, -285, 0], [0, 0, 0, 0, 550, 74, 74, 1893, 289, -12, 12, 216], [-4482, 89, 164, -448, 0, -370, 370, 0, 0, 1, 1, 0], [-4551, 391, -261, 173, 0, -198, 198, 0, 0, -121, -121, 0], [0, 0, 0, 0, -961, -90, -90, 2781, -143, 127, -127, 138], [3432, -71, 740, 624, 0, 10, -10, 0, 0, 137, 137, 0], [0, 0, 0, 0, 484, 212, 212, 904, 203, -45, 45, 616], [0, 0, 0, 0, -860, -122, -122, -1486, 25, 299, -299, -183], [0, 0, 0, 0, 822, 293, 293, 2332, -95, 194, -194, -110], [-5143, 51, 119, -485, 0, -580, 580, 0, 0, 209, 209, 0], [-5512, -262, 323, -59, 0, 14, -14, 0, 0, -203, -203, 0], [0, 0, 0, 0, 796, -577, -577, -992, -2, -14, 14, -482], [0, 0, 0, 0, -1247, -581, -581, -91, -389, 196, -196, 282], [0, 0, 0, 0, 3, -206, -206, -216, 297, -247, 247, -110], [-40, -510, -80, -334, 0, 215, -215, 0, 0, 303, 303, 0], [6906, 24, -8, -64, 0, 528, -528, 0, 0, -366, -366, 0], [0, 0, 0, 0, -156, 364, 364, -3647, 420, 202, -202, -35], [0, 0, 0, 0, 557, -405, -405, 3164, -540, 162, -162, 363], [0, 0, 0, 0, -340, -370, -370, -2152, -250, 312, -312, -66], [-5639, 123, 85, -1063, 0, -576, 576, 0, 0, -76, -76, 0], [2442, 90, -26, -1554, 0, 474, -474, 0, 0, 30, 30, 0], [-11405, 282, -161, -256, 0, -555, 555, 0, 0, 401, 401, 0], [0, 0, 0, 0, -1871, 271, 271, -231, 271, -384, 384, -370], [0, 0, 0, 0, 396, -98, -98, 819, -306, 420, -420, 307], [0, 0, 0, 0, 721, -149, -149, 2356, 266, 346, -346, 733], [1592, 164, -83, -107, 0, -459, 459, 0, 0, 242, 242, 0], [2012, -91, -357, 752, 0, -577, 577, 0, 0, 86, 86, 0], [0, 0, 0, 0, 1612, 348, 348, -620, -288, 86, -86, 56], [0, 0, 0, 0, 303, -81, -81, 2660, -228, -170, 170, 177], [0, 0, 0, 0, -747, 66, 66, -3729, -442, 628, -628, -128], [724, 814, -94, -1284, 0, -259, 259, 0, 0, 193, 193, 0], [-2596, -33, -335, -908, 0, 294, -294, 0, 0, 280, 280, 0], [-2496, -195, -194, -350, 0, 100, -100, 0, 0, 439, 439, 0], [-934, -356, -250, 404, 0, 473, -473, 0, 0, -463, -463, 0], [0, 0, 0, 0, -311, 204, 204, -858, 489, -653, 653, -297], [0, 0, 0, 0, 3132, 208, 208, 3798, -73, -141, 141, -373], [1107, -543, 551, 187, 0, 304, -304, 0, 0, 186, 186, 0], [0, 0, 0, 0, -2061, 578, 578, -1970, 569, -25, 25, 495], [-2668, -146, 20, -286, 0, 693, -693, 0, 0, 91, 91, 0], [0, 0, 0, 0, -2321, 565, 565, -1382, 387, -275, 275, -272], [2249, 51, 123, -119, 0, 642, -642, 0, 0, -203, -203, 0], [-509, -295, -51, 557, 0, 1507, -1507, 0, 0, 305, 305, 0], [0, 0, 0, 0, -2513, -171, -171, -9732, 200, 130, -130, 593], [0, 0, 0, 0, 1664, 27, 27, 5096, 351, -212, 212, 234], [0, 0, 0, 0, 104, 210, 210, 6548, 58, -116, 116, 538], [5341, 382, -192, 602, 0, -356, 356, 0, 0, 216, 216, 0], [11535, 727, 278, -116, 0, -220, 220, 0, 0, 85, 85, 0], [11868, 346, 346, -748, 0, -1011, 1011, 0, 0, -4, -4, 0], [0, 0, 0, 0, -1924, 65, 65, -5629, 791, -745, 745, -322], [0, 0, 0, 0, 391, -715, -715, 741, 488, -179, 179, -1240], [7360, 82, 1298, -488, 0, -805, 805, 0, 0, 316, 316, 0], [-8646, 582, 632, 888, 0, -384, 384, 0, 0, 266, 266, 0], [0, 0, 0, 0, 2135, 478, 478, -2132, -118, 134, -134, 871], [0, 0, 0, 0, 1230, 701, 701, 4076, 720, 216, -216, 438], [9344, -30, 234, -1056, 0, 417, -417, 0, 0, 343, 343, 0], [0, 0, 0, 0, -4419, 263, 263, -1052, -549, -58, 58, -653], [0, 0, 0, 0, -177, -393, -393, -5344, 382, -516, 516, 427], [6277, 50, 793, -18, 0, -794, 794, 0, 0, 221, 221, 0], [0, 0, 0, 0, -3713, -557, -557, -10565, 143, -54, 54, 320], [0, 0, 0, 0, 1318, -447, -447, 9235, -893, -101, 101, 30], [0, 0, 0, 0, 295, -312, -312, 2055, 588, -456, 456, -48], [2958, -350, -172, 488, 0, -836, 836, 0, 0, -410, -410, 0], [18992, 198, -205, -1269, 0, -216, 216, 0, 0, -421, -421, 0], [-723, 1390, 197, -1408, 0, -297, 297, 0, 0, -109, -109, 0], [0, 0, 0, 0, -320, 918, 918, 148, -254, 62, -62, 274], [-16070, -936, 928, -926, 0, 757, -757, 0, 0, 328, 328, 0], [0, 0, 0, 0, 1896, 483, 483, -1068, 1215, -990, 990, -36], [0, 0, 0, 0, 2574, -10, -10, -4088, -566, -12, 12, 828], [0, 0, 0, 0, 1698, -542, -542, 4193, -1821, 602, -602, 100], [459, -439, -395, 1597, 0, -498, 498, 0, 0, -752, -752, 0], [0, 0, 0, 0, 452, -1273, -1273, -784, -1048, 130, -130, -628], [0, 0, 0, 0, 3299, 311, 311, -9776, -333, 154, -154, 639], [-10808, 722, -335, 1105, 0, -808, 808, 0, 0, -557, -557, 0], [0, 0, 0, 0, -1075, 94, 94, -770, -833, -303, 303, -350]];
    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_e();".
// 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_e(:prec:=12)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_490_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![34574400, 0, 31585449, 0, 5835817, 0, 413878, 0, 13302, 0, 193, 0, 1]>,<19,R![-1453282440, 170214204, 17245338, 120401, -10611, -93, 1]>],Snew);
    return Vf;
end function;