
// Make newform 1620.4.i.u 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_u();".
// 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_u();".
// 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 := [36864, -17280, 8292, -294, 91, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-29852544, 1365120, -655068, -83093, -7189, 79], [-559104, -11053236, 136318, -121303, 1333, -1365], [45773136, -1572480, 754572, -16279, 8281, -91], [2697216, 53085092, -657622, 585187, 15175, 6585], [-270336, -3110265, 65912, -58652, -1381, -660]];
    Rf_basisdens := [1, 1474584, 23593344, 1474584, 3932224, 368646];
    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, 0, -1, 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, 0, 5, 0, 0, 0], [0, 0, 5, 0, -1, 0], [0, 0, -8, 0, 0, 1], [-11, 0, -11, -1, 1, 0], [-14, 2, 0, -2, 0, 0], [7, 1, 0, -3, 0, 0], [-11, 2, -11, 3, -3, -2], [0, 0, -74, 0, 5, -2], [-44, -3, -44, -2, 2, 3], [58, -2, 0, -8, 0, 0], [-33, 0, -33, 6, -6, 0], [0, 0, -40, 0, 2, -6], [0, 0, -179, 0, 3, -2], [-89, -10, 0, 9, 0, 0], [-75, -9, -75, -5, 5, 9], [0, 0, -160, 0, 6, 12], [-4, -10, -4, 20, -20, 10], [-190, 1, 0, -8, 0, 0], [354, -10, 0, 2, 0, 0], [0, 0, -342, 0, -26, 4], [0, 0, -234, 0, -32, 18], [-380, 8, 0, 11, 0, 0], [0, 0, -852, 0, 26, -2], [0, 0, 154, 0, -45, -14], [417, 22, 417, 55, -55, -22], [-90, 6, 0, 14, 0, 0], [686, 18, 0, 43, 0, 0], [1190, 22, 1190, 38, -38, -22], [771, 8, 0, 11, 0, 0], [899, -17, 899, 17, -17, 17], [0, 0, -102, 0, -18, 0], [231, -23, 231, -11, 11, 23], [914, 16, 914, -128, 128, -16], [0, 0, -2502, 0, -20, -11], [-571, 14, -571, -59, 59, -14], [1148, 36, 0, -82, 0, 0], [1136, 4, 1136, 74, -74, -4], [0, 0, -709, 0, -35, -4], [-951, -15, 0, -109, 0, 0], [780, 2, 0, -143, 0, 0], [0, 0, -1120, 0, -18, -13], [-1264, 26, -1264, -46, 46, -26], [-2463, -36, 0, 19, 0, 0], [2752, -80, 0, 32, 0, 0], [449, 83, 449, -53, 53, -83], [0, 0, -2112, 0, 20, 16], [0, 0, -2552, 0, 94, -8], [-2712, -20, -2712, -82, 82, 20], [-1660, 34, 0, -98, 0, 0], [-558, 36, -558, -190, 190, -36], [0, 0, -3168, 0, 83, 28], [-2151, -12, 0, -17, 0, 0], [1090, -52, 1090, 60, -60, 52], [0, 0, -1851, 0, -127, -90], [-2324, -34, 0, 87, 0, 0], [2334, 44, 0, 86, 0, 0], [0, 0, -1111, 0, -89, -150], [0, 0, -4231, 0, 175, 68], [-2680, -82, -2680, 72, -72, 82], [3275, -14, 3275, -137, 137, 14], [5108, 42, 0, -6, 0, 0], [-2318, 173, -2318, -108, 108, -173], [0, 0, -2240, 0, -12, 116], [0, 0, -573, 0, -343, 18], [0, 0, -3136, 0, 132, -105], [-3102, 124, -3102, -10, 10, -124], [-402, 96, -402, -300, 300, -96], [0, 0, -1432, 0, -147, 66], [0, 0, -2546, 0, 124, 46], [-2038, 109, 0, 176, 0, 0], [0, 0, -5328, 0, 112, 70], [-3690, -158, -3690, 98, -98, 158], [509, 0, 0, -205, 0, 0], [1169, -116, 1169, -109, 109, 116], [0, 0, -2384, 0, -106, -140], [-3258, -76, 0, 88, 0, 0], [311, -104, 311, -41, 41, 104], [605, 140, 605, 105, -105, -140], [1280, -212, 1280, 344, -344, 212], [0, 0, -3940, 0, -231, -30], [-4268, -73, 0, -106, 0, 0], [-2692, -132, 0, 274, 0, 0], [0, 0, 134, 0, 252, 33], [0, 0, 506, 0, 324, 50], [-2409, -156, 0, -314, 0, 0], [0, 0, 140, 0, 150, -150], [0, 0, -390, 0, 459, -90], [197, -34, 197, -457, 457, 34], [1326, -312, 0, 336, 0, 0], [0, 0, 8382, 0, -116, 3], [-4949, 160, 0, -379, 0, 0], [-10423, -77, -10423, -33, 33, 77], [1559, 35, 1559, 101, -101, -35], [10384, -4, 0, -128, 0, 0], [5922, 192, 5922, 504, -504, -192], [-10439, 356, 0, -91, 0, 0], [10794, 80, 0, -46, 0, 0], [-17658, -118, 0, -93, 0, 0], [0, 0, 4260, 0, -32, 316], [-3411, 408, 0, -237, 0, 0], [4848, 210, 4848, -562, 562, -210], [0, 0, 2971, 0, -606, 364], [3772, -195, 3772, -544, 544, 195], [-12976, -102, 0, 492, 0, 0], [0, 0, 9742, 0, 424, 142], [19094, -176, 0, -52, 0, 0], [-18534, 81, -18534, -24, 24, -81], [0, 0, 933, 0, 804, 136], [11148, 22, 11148, 154, -154, -22], [-5919, 476, 0, -61, 0, 0], [-7618, -248, -7618, 178, -178, 248], [0, 0, 8491, 0, 503, -352], [-1316, -41, 0, 750, 0, 0], [0, 0, 1760, 0, 425, -232], [-5164, 386, -5164, 14, -14, -386], [2984, -26, 0, 540, 0, 0], [3642, -288, 3642, -482, 482, 288], [0, 0, 3885, 0, -203, -384], [242, 50, 242, 491, -491, -50], [0, 0, 22646, 0, 372, -108], [0, 0, 4765, 0, -781, -380], [25186, 8, 0, -350, 0, 0], [0, 0, 4229, 0, -471, 456], [-4092, -258, 0, 505, 0, 0], [0, 0, 12430, 0, -348, 56], [2618, -425, 0, 436, 0, 0], [0, 0, 91, 0, 611, -196], [-14346, 472, -14346, -68, 68, -472], [3556, -245, 0, 244, 0, 0], [7660, 164, 7660, 374, -374, -164], [24950, -364, 24950, 278, -278, 364], [-23083, -192, 0, -369, 0, 0], [-24895, -92, -24895, -142, 142, 92], [-5888, -216, -5888, -529, 529, 216], [21166, 194, 0, 448, 0, 0], [10778, 152, 10778, 860, -860, -152], [-8962, -428, -8962, -426, 426, 428], [905, 256, 0, -1250, 0, 0], [-8456, 229, 0, 72, 0, 0], [0, 0, -5264, 0, 195, 454], [8604, -122, 8604, 216, -216, 122], [10588, 596, 0, 36, 0, 0], [-18530, -146, 0, 355, 0, 0], [0, 0, 9472, 0, 514, 451], [0, 0, 21014, 0, 582, -162], [0, 0, 11090, 0, -38, 104], [-1020, 571, -1020, -1220, 1220, -571], [41633, 100, 0, -75, 0, 0], [-9151, -364, -9151, -1313, 1313, 364], [-19020, -324, 0, 1719, 0, 0], [14718, -160, 0, -464, 0, 0], [493, 314, 493, 405, -405, -314], [0, 0, -9354, 0, 574, -602], [0, 0, 11582, 0, 368, -187], [4708, 673, 0, -230, 0, 0], [0, 0, -7992, 0, 799, -720], [-14112, 620, 0, 642, 0, 0], [2798, 580, 2798, 248, -248, -580], [0, 0, 28712, 0, -140, 122], [20096, 16, 0, 384, 0, 0], [32300, 392, 32300, -298, 298, -392], [1095, -33, 0, -175, 0, 0], [-13142, 668, -13142, 122, -122, -668], [0, 0, -7884, 0, -962, -696], [-10732, -609, 0, -930, 0, 0], [0, 0, 247, 0, 599, 1130], [-26973, 740, 0, -10, 0, 0], [41989, -214, 41989, -81, 81, 214], [0, 0, -1941, 0, 1903, -147], [10070, 794, 10070, 1121, -1121, -794], [-46146, -237, -46146, -496, 496, 237], [0, 0, 6316, 0, 430, -184], [19970, 416, 19970, -1322, 1322, -416], [15009, 216, 15009, -1280, 1280, -216], [0, 0, -31081, 0, -869, -240], [-54600, -174, 0, 287, 0, 0], [38960, -132, 0, 364, 0, 0], [0, 0, -5336, 0, 103, -322], [0, 0, -13052, 0, -858, -130], [0, 0, -5177, 0, -2113, 496], [-29629, -142, -29629, 1073, -1073, 142], [-34116, 24, 0, 830, 0, 0], [39305, -290, 39305, 5, -5, 290], [0, 0, 2164, 0, 467, -2], [-9689, -548, 0, 883, 0, 0], [0, 0, 6542, 0, 580, 948], [-17297, 312, -17297, 346, -346, -312], [-50358, -228, 0, -182, 0, 0], [27202, -1328, 0, 960, 0, 0], [0, 0, -5178, 0, -1556, 402], [13876, 832, 0, 524, 0, 0], [0, 0, 8392, 0, 343, 358], [21388, -466, 0, 1670, 0, 0], [35144, 418, 35144, 1356, -1356, -418], [12615, -200, 12615, 736, -736, 200], [0, 0, 7859, 0, 741, 450], [0, 0, -15734, 0, 842, -1106], [11621, 1204, 0, 503, 0, 0], [25456, 782, 25456, -345, 345, -782], [0, 0, -19412, 0, 710, -241], [-16815, 214, -16815, -557, 557, -214], [0, 0, -26207, 0, -268, -724], [-1628, 224, 0, -652, 0, 0], [-63211, -356, 0, 1191, 0, 0], [37394, -33, 0, -1468, 0, 0], [27366, -48, 27366, -898, 898, 48], [0, 0, 4186, 0, -1544, -356], [-3548, -84, -3548, -260, 260, 84], [19974, 1076, 0, -2792, 0, 0], [-36562, 934, -36562, 741, -741, -934], [0, 0, 1203, 0, 1147, -1220], [0, 0, -14972, 0, -8, 160], [26540, 727, 26540, 78, -78, -727], [0, 0, -19433, 0, -2446, 1064], [27544, 210, 27544, -952, 952, -210], [0, 0, -26468, 0, 419, -1316], [-27019, 1138, 0, -201, 0, 0], [86742, -408, 86742, 180, -180, 408], [-12264, -1394, -12264, -1915, 1915, 1394], [17550, -1985, 17550, 208, -208, 1985], [1671, -1452, 1671, 98, -98, 1452], [58969, 376, 0, -533, 0, 0], [21144, -1488, 21144, -726, 726, 1488], [0, 0, -27858, 0, 1221, -350], [0, 0, -15306, 0, 1572, 156], [-40566, -720, 0, 330, 0, 0], [0, 0, -19477, 0, 373, 822], [0, 0, 31383, 0, 1255, 120], [-26411, 2106, -26411, -1225, 1225, -2106], [27525, -349, 0, -889, 0, 0], [39600, 976, 39600, -1512, 1512, -976], [9787, -1024, 9787, 267, -267, 1024], [0, 0, -21388, 0, 240, -756], [0, 0, 46665, 0, -671, -510], [33583, 732, 33583, 2802, -2802, -732], [4178, -878, 0, 142, 0, 0], [7699, 872, 7699, 2945, -2945, -872], [-12216, 531, 0, 1358, 0, 0], [0, 0, -39408, 0, -406, -72], [-19569, 68, 0, -3415, 0, 0], [-20825, 630, -20825, 495, -495, -630], [-14634, -1420, 0, 1196, 0, 0], [61998, 576, 61998, -3154, 3154, -576], [0, 0, 11182, 0, -3668, -671], [9047, -1494, 0, 575, 0, 0], [-70609, -752, -70609, -1635, 1635, 752], [-12171, 115, -12171, -229, 229, -115], [4760, -1190, 0, -2590, 0, 0], [8638, -1206, 8638, 2160, -2160, 1206], [-46079, 344, 0, 1944, 0, 0], [42668, 454, 42668, -1650, 1650, -454], [0, 0, -48941, 0, 1484, 392], [0, 0, 36571, 0, 137, -494], [18365, 148, 0, 2139, 0, 0], [4964, -726, 0, 3345, 0, 0], [0, 0, -12828, 0, -3524, 1198], [-13513, -710, 0, -147, 0, 0], [7804, 1186, 0, -1304, 0, 0], [0, 0, 42727, 0, 273, 230], [0, 0, 47930, 0, -316, -1522], [-24798, 298, -24798, -2261, 2261, -298], [27909, 1880, 0, 2319, 0, 0], [-15592, 382, -15592, -3466, 3466, -382], [0, 0, -26589, 0, 1627, -35], [-10238, 920, 0, 2392, 0, 0], [0, 0, 26797, 0, -3716, -476], [-59592, -632, -59592, -1928, 1928, 632], [-30345, 132, -30345, -3801, 3801, -132], [21556, -2598, 21556, 1463, -1463, 2598], [-29944, 888, 0, 2940, 0, 0], [0, 0, 33502, 0, -694, -1624], [-1556, 2223, -1556, -390, 390, -2223], [4610, -316, 4610, -1992, 1992, 316], [41784, -1966, 0, 1466, 0, 0], [-38360, 710, -38360, 2856, -2856, -710], [0, 0, -26144, 0, -111, 146], [5439, -1168, 0, -245, 0, 0], [0, 0, 48915, 0, 659, 672], [47621, -830, 47621, 2381, -2381, 830], [34416, -752, 34416, 3640, -3640, 752], [0, 0, -6621, 0, -3421, 798], [0, 0, 26604, 0, 130, -632], [-32124, 244, -32124, -1166, 1166, -244], [-62856, -747, 0, 1982, 0, 0], [-28118, -1466, 0, 1544, 0, 0], [-63377, 278, -63377, -53, 53, -278], [0, 0, 92568, 0, 154, -215], [81410, 352, 0, -2704, 0, 0], [0, 0, -70216, 0, 1127, -1210], [-32148, -1488, 0, -4372, 0, 0], [6774, 90, 6774, -1558, 1558, -90], [-43564, 865, -43564, 1580, -1580, -865], [0, 0, -32915, 0, 4025, 314], [1764, 546, 1764, 3109, -3109, -546], [0, 0, 74470, 0, 2004, -319], [0, 0, 43406, 0, -850, -1954], [-57573, -351, 0, -2139, 0, 0], [0, 0, -11522, 0, -3430, 638], [-21004, -1468, -21004, -2866, 2866, 1468], [53833, -2062, 0, 603, 0, 0], [-75512, -1439, 0, -3382, 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_u();".
// 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_u(: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_u();".
// 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_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![394384, 406944, 429324, -8464, 873, 15, 1]>,<11,R![301091904, 37220040, 4184577, 86184, 2721, -24, 1]>],Snew);
    return Vf;
end function;