
// Make newform 1620.4.i.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1620_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1620_i_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_1620_4_i_t();".
// 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_1620_4_i_t();".
// 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 := [57600, 21600, 7860, 570, 91, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-6069600, -2208660, -89362, -25571, 281, -273], [-42188400, -1965600, -715260, 16711, -8281, 91], [28921080, 2095200, 762420, -66397, 8827, -97], [87112800, 31699380, 2829870, 367003, -4033, 4093], [-120981600, -44023860, -5759018, -509691, 5601, -7889]];
    Rf_basisdens := [1, 5894880, 1473720, 736860, 2947440, 2947440];
    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_1620_i();"
function MakeCharacter_1620_i()
    N := 1620;
    order := 3;
    char_gens := [811, 1541, 1297];
    v := [3, 2, 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_1620_i_Hecke();"
function MakeCharacter_1620_i_Hecke(Kf)
    N := 1620;
    order := 3;
    char_gens := [811, 1541, 1297];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, -1, 0, 0, 0, 0], [1, 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, 0, 0, 0, 0, 0], [-5, -5, 0, 0, 0, 0], [0, -1, 0, 0, -1, 0], [0, -8, 0, 0, -1, -1], [-1, -1, -1, 2, -1, 2], [-10, 0, -2, -2, 0, 0], [-9, 0, -4, -1, 0, 0], [-33, -33, 1, 0, 1, 0], [0, -18, 0, 0, -1, 0], [-24, -24, -5, 1, -5, 1], [-6, 0, -8, 2, 0, 0], [-137, -137, -2, -4, -2, -4], [0, 148, 0, 0, 10, 4], [0, -25, 0, 0, -3, 10], [57, 0, 1, 0, 0, 0], [-99, -99, 28, 9, 28, 9], [0, 228, 0, 0, -2, -16], [-4, -4, 10, -10, 10, -10], [214, 0, 1, 29, 0, 0], [-22, 0, 30, 18, 0, 0], [0, 374, 0, 0, -6, 12], [0, 30, 0, 0, -28, 0], [252, 0, 33, -18, 0, 0], [0, 512, 0, 0, -26, 6], [0, 678, 0, 0, 37, -24], [355, 355, 33, 36, 33, 36], [422, 0, 4, -26, 0, 0], [-794, 0, -29, -8, 0, 0], [-186, -186, -62, 18, -62, 18], [-1311, 0, 25, 20, 0, 0], [-701, -701, -70, -31, -70, -31], [0, 1378, 0, 0, -2, 44], [655, 655, 84, -9, 84, -9], [-498, -498, 84, -24, 84, -24], [0, 814, 0, 0, 23, -41], [531, 531, -51, -32, -51, -32], [-2100, 0, 8, -34, 0, 0], [-592, -592, 72, 22, 72, 22], [0, 1465, 0, 0, -133, -34], [1297, 0, -78, 47, 0, 0], [-1568, 0, -27, 4, 0, 0], [0, 612, 0, 0, -145, 33], [76, 76, -150, -42, -150, -42], [1491, 0, 91, 78, 0, 0], [-2508, 0, -108, 56, 0, 0], [489, 489, -60, -71, -60, -71], [0, 3832, 0, 0, 72, -44], [0, 412, 0, 0, -68, -142], [608, 608, 78, 104, 78, 104], [2776, 0, -122, 38, 0, 0], [-2670, -2670, 2, 0, 2, 0], [0, 3280, 0, 0, 15, 142], [449, 0, 81, -158, 0, 0], [-3602, -3602, -16, -28, -16, -28], [0, 39, 0, 0, 97, 36], [1168, 0, 107, -52, 0, 0], [-5434, 0, -66, 48, 0, 0], [0, 3783, 0, 0, 17, -16], [0, 3025, 0, 0, -1, 110], [-3140, -3140, -70, -66, -70, -66], [-1739, -1739, -209, 8, -209, 8], [-2680, 0, 210, 0, 0, 0], [-4374, -4374, -107, -39, -107, -39], [0, 2804, 0, 0, -176, -108], [0, 1877, 0, 0, 135, -44], [0, 3328, 0, 0, -79, 61], [1922, 1922, 282, 56, 282, 56], [-1318, -1318, -166, -2, -166, -2], [0, 1576, 0, 0, 167, -236], [0, 1626, 0, 0, 24, 18], [138, 0, 97, 225, 0, 0], [0, -912, 0, 0, -50, -58], [574, 574, 218, -102, 218, -102], [-5163, 0, 101, -166, 0, 0], [5499, 5499, 235, -198, 235, -198], [0, 2708, 0, 0, -410, -56], [-638, 0, -408, -92, 0, 0], [-4273, -4273, 257, 166, 257, 166], [3445, 3445, -265, -210, -265, -210], [3248, 3248, -192, 304, -192, 304], [0, -5288, 0, 0, 335, 4], [-8840, 0, 337, 143, 0, 0], [5404, 0, -26, 328, 0, 0], [0, 866, 0, 0, 219, 387], [0, 670, 0, 0, 324, 200], [695, 0, -282, -416, 0, 0], [0, -3748, 0, 0, -66, 186], [0, 1506, 0, 0, 333, -324], [-6441, -6441, -187, 256, -187, 256], [-4918, 0, -214, -206, 0, 0], [0, -1766, 0, 0, -243, 101], [-5439, 0, 141, 278, 0, 0], [3169, 3169, 204, -235, 204, -235], [-6073, -6073, -458, 17, -458, 17], [2584, 0, -132, -268, 0, 0], [-2354, -2354, -536, -64, -536, -64], [-6351, 0, -549, 222, 0, 0], [6562, 0, -430, -344, 0, 0], [1878, 0, -369, -184, 0, 0], [0, -4912, 0, 0, -228, -96], [-1209, 0, 795, 18, 0, 0], [15944, 15944, 250, -8, 250, -8], [0, -4037, 0, 0, -634, 80], [148, 148, 613, 141, 613, 141], [10428, 0, 88, 26, 0, 0], [0, -7458, 0, 0, 264, 276], [7342, 0, -532, -208, 0, 0], [2254, 2254, -887, -427, -887, -427], [0, -15595, 0, 0, -16, -432], [-8852, -8852, -174, -456, -174, -456], [22163, 0, -141, 54, 0, 0], [-12434, -12434, -242, -292, -242, -292], [0, -3877, 0, 0, 363, -486], [-4636, 0, -71, -381, 0, 0], [0, -4072, 0, 0, 713, -74], [-15520, -15520, 658, 140, 658, 140], [-23264, 0, 18, -130, 0, 0], [19966, 19966, 158, 308, 158, 308], [0, -6107, 0, 0, 573, 362], [4878, 4878, -757, -584, -757, -584], [0, -902, 0, 0, -520, 628], [0, -5625, 0, 0, 341, 498], [13326, 0, -82, -72, 0, 0], [0, -12187, 0, 0, -147, 174], [-20868, 0, -155, 24, 0, 0], [0, -16686, 0, 0, -700, 80], [-16410, 0, -105, -81, 0, 0], [0, -20759, 0, 0, 305, -302], [-4782, -4782, -388, 520, -388, 520], [6388, 0, 443, 703, 0, 0], [19948, 19948, -236, 230, -236, 230], [-3666, -3666, -178, -128, -178, -128], [18423, 0, 151, -166, 0, 0], [-10079, -10079, -562, -280, -562, -280], [9104, 9104, -151, 518, -151, 518], [23246, 0, 712, -242, 0, 0], [-4718, -4718, -630, 234, -630, 234], [-12070, -12070, -530, 40, -530, 40], [-7903, 0, 170, 412, 0, 0], [-14728, 0, -1343, 609, 0, 0], [0, 18776, 0, 0, 561, 916], [-24596, -24596, -266, -714, -266, -714], [-16248, 0, -740, 756, 0, 0], [12918, 0, -1505, -172, 0, 0], [0, -14160, 0, 0, 591, -399], [0, 62, 0, 0, 186, -990], [0, -3970, 0, 0, -1146, -740], [-9188, -9188, -225, 267, -225, 267], [9483, 0, -265, 540, 0, 0], [13667, 13667, -1, 566, -1, 566], [-18260, 0, 385, -262, 0, 0], [13130, 0, 610, 474, 0, 0], [-10177, -10177, -291, -1406, -291, -1406], [0, -5002, 0, 0, 792, -354], [0, -8226, 0, 0, -1797, 699], [-18044, 0, -421, -1343, 0, 0], [0, 27880, 0, 0, 675, -286], [5472, 0, -1290, 128, 0, 0], [-25842, -25842, 508, 324, 508, 324], [0, -3292, 0, 0, 930, 1066], [49940, 0, -92, 40, 0, 0], [3228, 3228, 560, -158, 560, -158], [-44081, 0, 210, -271, 0, 0], [-5226, -5226, -438, 912, -438, 912], [0, 5020, 0, 0, 96, -226], [-29844, 0, 1177, 275, 0, 0], [0, 3073, 0, 0, 1073, 256], [3067, 0, -70, 640, 0, 0], [18779, 18779, -1065, -752, -1065, -752], [0, -26229, 0, 0, -382, -351], [21998, 21998, -1079, 116, -1079, 116], [-7690, -7690, -1061, 1123, -1061, 1123], [0, 13000, 0, 0, -38, -764], [-6270, -6270, 354, 460, 354, 460], [-13727, -13727, 1964, 728, 1964, 728], [0, -3801, 0, 0, -841, 1322], [-8308, 0, 127, -272, 0, 0], [-2336, 0, 1300, 112, 0, 0], [0, 6372, 0, 0, -1035, 932], [0, -6388, 0, 0, -914, 1236], [0, 6431, 0, 0, 763, -998], [-2971, -2971, 577, 236, 577, 236], [2256, 0, 2198, 420, 0, 0], [5819, 5819, -867, 1042, -867, 1042], [0, 15620, 0, 0, 817, -116], [-419, 0, 1355, 766, 0, 0], [0, 53214, 0, 0, -334, 218], [8063, 8063, 1098, -100, 1098, -100], [-33922, 0, -438, 484, 0, 0], [20154, 0, -304, -832, 0, 0], [0, -30406, 0, 0, 568, 532], [-37364, 0, 736, 244, 0, 0], [0, 5912, 0, 0, -991, -1292], [-24468, 0, 1242, 96, 0, 0], [25232, 25232, -1940, -710, -1940, -710], [38023, 38023, -48, 552, -48, 552], [0, 50773, 0, 0, 827, 604], [0, -1682, 0, 0, -522, 206], [64719, 0, -257, -198, 0, 0], [-27208, -27208, -1821, 220, -1821, 220], [0, 1740, 0, 0, -665, -1603], [8071, 8071, 579, -1284, 579, -1284], [0, 11001, 0, 0, 568, 1292], [-10388, 0, -1088, -1732, 0, 0], [943, 0, -1377, -1426, 0, 0], [-27014, 0, -837, 799, 0, 0], [29270, 29270, 1342, 280, 1342, 280], [0, 12282, 0, 0, 972, 1236], [11676, 11676, -2576, -1172, -2576, -1172], [13798, 0, 792, 172, 0, 0], [-25134, -25134, 2201, 216, 2201, 216], [0, 24801, 0, 0, -1991, -1462], [0, 27792, 0, 0, -1224, 1116], [-56224, -56224, -1163, -581, -1163, -581], [0, 12111, 0, 0, -1370, -844], [-9592, -9592, -2434, -514, -2434, -514], [0, 69772, 0, 0, 627, -226], [2191, 0, 777, -220, 0, 0], [5746, 5746, 2020, -976, 2020, -976], [26716, 26716, 1181, 216, 1181, 216], [-29706, -29706, -1729, -89, -1729, -89], [20695, 20695, -666, -1096, -666, -1096], [-10325, 0, -2425, 910, 0, 0], [-20328, -20328, -2808, 2058, -2808, 2058], [0, 14798, 0, 0, -469, -180], [0, -7046, 0, 0, -848, -2452], [47122, 0, 946, 704, 0, 0], [0, 10977, 0, 0, 503, 1586], [0, 3959, 0, 0, 1687, -962], [-4589, -4589, -1025, 1512, -1025, 1512], [-3579, 0, 3304, 1577, 0, 0], [5560, 5560, -3776, 0, -3776, 0], [-64621, -64621, -363, -602, -363, -602], [0, 65284, 0, 0, 320, 1072], [0, 41203, 0, 0, 537, -1348], [20951, 20951, -2810, 32, -2810, 32], [83330, 0, 398, 874, 0, 0], [-16317, -16317, 435, 1434, 435, 1434], [-39812, 0, 837, 827, 0, 0], [0, 21588, 0, 0, 2620, -1002], [-43137, 0, 1027, 794, 0, 0], [-46371, -46371, 2903, 1582, 2903, 1582], [-49470, 0, 124, -1900, 0, 0], [42122, 42122, 310, 3076, 310, 3076], [0, 3166, 0, 0, 427, 167], [-36443, 0, 531, 1426, 0, 0], [7871, 7871, -1217, -2822, -1217, -2822], [33365, 33365, -732, -559, -732, -559], [68232, 0, 754, -864, 0, 0], [15334, 15334, -3384, -18, -3384, -18], [9345, 0, 2836, 168, 0, 0], [-14740, -14740, -422, -2300, -422, -2300], [0, 4627, 0, 0, 4280, -320], [0, 7389, 0, 0, 2663, 852], [-52595, 0, 2337, -250, 0, 0], [-13704, 0, 73, 1460, 0, 0], [0, 18372, 0, 0, -3074, -2086], [2305, 0, -2451, 788, 0, 0], [-18776, 0, 1532, -206, 0, 0], [0, 22149, 0, 0, -109, 242], [0, -346, 0, 0, -544, -1508], [-2150, -2150, -357, -816, -357, -816], [-6009, 0, 663, 458, 0, 0], [-55044, -55044, -938, 738, -938, 738], [0, 41979, 0, 0, 2014, 353], [43366, 0, -2220, -832, 0, 0], [0, -24939, 0, 0, 3420, 2676], [23640, 23640, 3104, 520, 3104, 520], [62101, 62101, 3583, -2218, 3583, -2218], [-884, -884, -1085, -1824, -1085, -1824], [-30248, 0, -880, -3404, 0, 0], [0, 26434, 0, 0, 542, -2108], [-50768, -50768, -771, 1287, -771, 1287], [9634, 9634, 1880, 2100, 1880, 2100], [28648, 0, 1178, 1024, 0, 0], [66812, 66812, 210, -1346, 210, -1346], [0, -40264, 0, 0, -2885, -1188], [-2225, 0, 369, 1270, 0, 0], [0, -32669, 0, 0, 2771, 1574], [-21361, -21361, 717, -3998, 717, -3998], [-16860, -16860, 836, 1600, 836, 1600], [0, 73329, 0, 0, -557, -60], [0, -19224, 0, 0, -3854, 308], [30528, 30528, -3028, 682, -3028, 682], [24272, 0, -1349, 133, 0, 0], [-4350, 0, -2976, 1790, 0, 0], [-65567, -65567, -3045, 1484, -3045, 1484], [0, -11260, 0, 0, -1035, 1419], [-52406, 0, 1436, -928, 0, 0], [0, 11428, 0, 0, -5039, -1804], [-42296, 0, 1464, 152, 0, 0], [1038, 1038, -4330, 1038, -4330, 1038], [-8220, -8220, 3673, -363, 3673, -363], [0, -49421, 0, 0, -1801, -332], [84560, 84560, 297, 1276, 297, 1276], [0, -22014, 0, 0, 4907, 395], [0, -66754, 0, 0, 554, -1406], [-13909, 0, -1612, 1519, 0, 0], [0, -18354, 0, 0, 1528, 3506], [-58968, -58968, -2842, -1208, -2842, -1208], [-76257, 0, 2971, 2232, 0, 0], [17748, 0, -4341, 365, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1620_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1620_4_i_t();".
// 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_1620_4_i_t(:prec:=6)
    chi := MakeCharacter_1620_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1620_4_i_t();".
// 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_1620_4_i_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![541696, 450432, 372336, 3308, 621, -3, 1]>,<11,R![296115264, -24521400, 2443617, -216, 2001, -24, 1]>],Snew);
    return Vf;
end function;