
// Make newform 1620.4.i.p in Magma, downloaded from the LMFDB on 19 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_p();".
// 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_p();".
// 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 := [100, 10, 11, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [100, -11, 11, -1], [-100, 341, -11, 1], [52, 0, 0, 3]];
    Rf_basisdens := [1, 110, 110, 11];
    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], [-1, 1, 0, 0], [1, 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], [5, -5, 0, 0], [0, -7, 1, 0], [0, 10, -5, 0], [-3, 7, -4, -4], [-25, 0, 0, 5], [28, 0, 0, -13], [55, -50, -5, -5], [0, 50, 5, 0], [35, -36, 1, 1], [-82, 0, 0, 15], [180, -210, 30, 30], [0, -88, 7, 0], [0, 160, 25, 0], [-380, 0, 0, 10], [460, -440, -20, -20], [0, 25, -51, 0], [136, -199, 63, 63], [-840, 0, 0, 30], [86, 0, 0, -15], [0, -203, 60, 0], [0, 350, -100, 0], [-720, 0, 0, -60], [0, 297, 29, 0], [0, -500, 145, 0], [-314, 419, -105, -105], [-1510, 0, 0, -40], [-180, 0, 0, -38], [325, -170, -155, -155], [-790, 0, 0, -90], [715, -800, 85, 85], [0, -1770, -60, 0], [478, -643, 165, 165], [-225, 120, 105, 105], [0, -1055, -24, 0], [903, -674, -229, -229], [-1583, 0, 0, -34], [220, -260, 40, 40], [0, -3500, 10, 0], [-1900, 0, 0, 230], [2836, 0, 0, 65], [0, -2380, -130, 0], [-1418, 1121, 297, 297], [580, 0, 0, 220], [-867, 0, 0, 340], [-2994, 2929, 65, 65], [0, 168, -292, 0], [0, -3930, 270, 0], [2720, -2922, 202, 202], [2490, 0, 0, -90], [-790, 890, -100, -100], [0, -3969, 140, 0], [-3065, 0, 0, -185], [-2435, 2740, -305, -305], [0, -3740, 160, 0], [1075, 0, 0, -95], [5684, 0, 0, -285], [0, 4086, -424, 0], [0, -7160, -170, 0], [416, 372, -788, -788], [-1230, 810, 420, 420], [-5923, 0, 0, 159], [1060, -200, -860, -860], [0, -1413, 581, 0], [0, -3860, -620, 0], [0, -4709, 315, 0], [6164, -6621, 457, 457], [900, -1290, 390, 390], [0, 6733, -195, 0], [0, -3840, 615, 0], [-7160, 0, 0, -350], [0, 4921, -147, 0], [-5137, 4689, 448, 448], [652, 0, 0, -265], [3415, -3980, 565, 565], [0, 140, 575, 0], [-4277, 0, 0, 1031], [-60, 270, -210, -210], [3113, -2103, -1010, -1010], [5515, -5540, 25, 25], [0, -9521, -555, 0], [-10320, 0, 0, 570], [-6546, 0, 0, 508], [0, 2608, 72, 0], [0, 4340, 20, 0], [6070, 0, 0, -170], [0, 9010, 570, 0], [0, 10500, -150, 0], [-2726, 1931, 795, 795], [-9480, 0, 0, 660], [0, 8270, -1150, 0], [-1056, 0, 0, -713], [2900, -4090, 1190, 1190], [-1220, 512, 708, 708], [-4015, 0, 0, 665], [7995, -6930, -1065, -1065], [10320, 0, 0, -1170], [-20773, 0, 0, -258], [15726, 0, 0, 259], [0, 4393, 1110, 0], [9000, 0, 0, 1140], [-6550, 8420, -1870, -1870], [0, 6160, 1480, 0], [5634, -4325, -1309, -1309], [2444, 0, 0, -2151], [0, -90, 2220, 0], [12535, 0, 0, -65], [-11730, 10410, 1320, 1320], [0, -12034, 769, 0], [12682, -12037, -645, -645], [-6661, 0, 0, -390], [-5985, 3990, 1995, 1995], [0, -755, -327, 0], [21244, 0, 0, -85], [0, -1560, 1230, 0], [-5945, 4040, 1905, 1905], [4820, 0, 0, -2950], [7240, -5060, -2180, -2180], [0, -640, -400, 0], [6814, -7969, 1155, 1155], [0, -13901, -1425, 0], [0, 24500, -1000, 0], [13640, 0, 0, -1990], [0, 5572, -2850, 0], [7585, 0, 0, 2425], [0, 3495, 1337, 0], [13470, 0, 0, 900], [0, 2704, 204, 0], [-26150, 26450, -300, -300], [8576, 0, 0, -300], [-19035, 19140, -105, -105], [32509, -33169, 660, 660], [12821, 0, 0, 2466], [790, 190, -980, -980], [16257, -17717, 1460, 1460], [22010, 0, 0, -880], [-4061, 4517, -456, -456], [19520, -20080, 560, 560], [25080, 0, 0, -360], [3790, 0, 0, -2746], [0, 14200, -710, 0], [-19272, 21913, -2641, -2641], [17890, 0, 0, 490], [3872, 0, 0, -3195], [0, 4740, 2790, 0], [0, -12137, 1254, 0], [0, -5750, 3640, 0], [-7358, 9593, -2235, -2235], [-3565, 0, 0, 1445], [-1041, -1523, 2564, 2564], [31470, 0, 0, -2100], [-38648, 0, 0, -133], [-32075, 31300, 775, 775], [0, -13193, -240, 0], [0, 2280, -1080, 0], [28655, 0, 0, -2307], [0, 3530, -490, 0], [23046, 0, 0, 991], [18355, -18890, 535, 535], [0, 5560, -3230, 0], [7325, 0, 0, 4295], [-16178, 16073, 105, 105], [-24865, 0, 0, -2335], [12885, -9570, -3315, -3315], [0, -11230, -235, 0], [4841, 0, 0, 2424], [0, -21890, -2655, 0], [-583, 0, 0, 5748], [57610, -58160, 550, 550], [0, -20590, -1675, 0], [43090, -43054, -36, -36], [-19510, 19880, -370, -370], [0, -6631, -3617, 0], [-10977, 9517, 1460, 1460], [1600, 550, -2150, -2150], [0, 28716, 644, 0], [-23290, 0, 0, 380], [-45432, 0, 0, -431], [0, 21398, 2332, 0], [0, 3291, -2167, 0], [0, -10060, 140, 0], [-48401, 49478, -1077, -1077], [3635, 0, 0, -5035], [-29120, 29020, 100, 100], [0, 42410, 140, 0], [57599, 0, 0, -1728], [0, 10593, -2506, 0], [15662, -18675, 3013, 3013], [-19070, 0, 0, 2830], [-32762, 0, 0, 1073], [0, -8080, 5750, 0], [2904, 0, 0, 5761], [0, 16800, 45, 0], [-44580, 0, 0, -1260], [10850, -15730, 4880, 4880], [33766, -29581, -4185, -4185], [0, -24179, 3300, 0], [0, 8330, -2380, 0], [-46640, 0, 0, -2510], [47305, -49640, 2335, 2335], [0, 48349, 3315, 0], [-3158, 9563, -6405, -6405], [0, 21763, -5685, 0], [-9915, 0, 0, -2835], [-22360, 0, 0, 710], [45877, 0, 0, -2422], [25130, -25750, 620, 620], [0, -34590, -2940, 0], [68024, -67809, -215, -215], [51124, 0, 0, -2623], [37505, -42100, 4595, 4595], [0, -19253, -759, 0], [0, -36390, 120, 0], [-58330, 55610, 2720, 2720], [0, 8749, -8340, 0], [-4218, 4924, -706, -706], [0, -75730, 20, 0], [10775, 0, 0, 1955], [11010, -1950, -9060, -9060], [52424, -53535, 1111, 1111], [-5705, 10688, -4983, -4983], [-29440, 31700, -2260, -2260], [-59560, 0, 0, 5040], [-15930, 13770, 2160, 2160], [0, 37337, 5965, 0], [0, -6960, -8055, 0], [-13830, 0, 0, -6720], [0, 10029, -613, 0], [0, -85600, -475, 0], [-59118, 53971, 5147, 5147], [60854, 0, 0, 4350], [47265, -49604, 2339, 2339], [-67610, 63850, 3760, 3760], [0, 9889, 1215, 0], [0, 12740, 3560, 0], [-3803, 6893, -3090, -3090], [-2940, 0, 0, -6840], [36600, -43650, 7050, 7050], [-36820, 0, 0, -6160], [0, -62090, -1490, 0], [29576, 0, 0, -6945], [118, 9029, -9147, -9147], [-50902, 0, 0, -2895], [-18070, 19100, -1030, -1030], [0, -13950, 5250, 0], [14314, 0, 0, 5219], [31355, -28060, -3295, -3295], [-36370, 38772, -2402, -2402], [-2315, 0, 0, 2065], [9475, -16450, 6975, 6975], [8020, 0, 0, -260], [-19960, 22940, -2980, -2980], [0, 52387, -4305, 0], [0, -47590, -1840, 0], [-50485, 0, 0, 3005], [6344, 0, 0, 3801], [0, 72820, 165, 0], [26810, 0, 0, 140], [12590, 0, 0, 2940], [0, -10659, -4213, 0], [0, -24330, -4320, 0], [-2, 2657, -2655, -2655], [-35253, 0, 0, 3262], [-70445, 68500, 1945, 1945], [0, -32564, -9900, 0], [-7270, 0, 0, -12340], [0, -54570, 4410, 0], [36055, -27760, -8295, -8295], [-25560, 26040, -480, -480], [11256, -845, -10411, -10411], [4367, 0, 0, 3780], [0, -25610, 5280, 0], [-33797, 37067, -3270, -3270], [67478, -62994, -4484, -4484], [-55492, 0, 0, -2757], [22360, -31130, 8770, 8770], [0, 24342, -2722, 0], [87985, 0, 0, -6319], [0, 95770, 4885, 0], [45385, -46550, 1165, 1165], [1867, -5392, 3525, 3525], [0, 55390, 1585, 0], [0, -19631, -1605, 0], [3619, 1439, -5058, -5058], [-21790, 0, 0, -5770], [-42888, 0, 0, -4169], [65090, -63880, -1210, -1210], [0, -14333, 6900, 0], [-11870, 0, 0, -9140], [0, -17970, -2445, 0], [43520, 0, 0, -6190], [-66745, 57530, 9215, 9215], [105700, -100220, -5480, -5480], [0, -1982, -15732, 0], [27970, -37040, 9070, 9070], [0, -53085, 4769, 0], [0, 91440, 1770, 0], [-32865, 0, 0, 9375], [0, 26983, -1815, 0], [-46484, 46229, 255, 255], [-17840, 0, 0, 5830], [13305, 0, 0, 12583]];
    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_p();".
// 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_p(:prec:=4)
    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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![2500, -650, 219, 13, 1]>,<11,R![5062500, 33750, 2475, -15, 1]>],Snew);
    return Vf;
end function;