
// Make newform 1620.4.i.i 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_i();".
// 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_i();".
// 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 := [1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, -1], [1, 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, 5], [-2, 2], [30, -30], [0, 4], [-90, 0], [-28, 0], [0, 120], [210, -210], [0, 4], [200, 0], [0, 240], [136, -136], [-120, 120], [30, 0], [0, -450], [166, -166], [0, -908], [1020, 0], [-250, 0], [916, -916], [-1140, 1140], [420, 0], [-1538, 1538], [450, -450], [0, 1150], [1620, 0], [-1702, 0], [0, 1350], [2450, 0], [0, 690], [2070, -2070], [0, 1924], [0, 2910], [-176, 176], [0, -2348], [-1996, 0], [0, 3120], [1770, -1770], [2130, 0], [-1654, 0], [1740, -1740], [0, -86], [2490, 0], [-832, 0], [0, -2084], [1174, -1174], [-3120, 3120], [0, 58], [5910, 0], [0, 3300], [2986, -2986], [6630, 0], [0, -1530], [2640, -2640], [7350, 0], [3512, 0], [5368, -5368], [-3060, 3060], [0, 5044], [0, -2010], [-2752, 0], [0, 9540], [-9254, 9254], [150, -150], [-1892, 1892], [0, 7378], [0, 6720], [-5186, 5186], [3330, -3330], [-9000, 0], [8758, -8758], [0, -4724], [7292, 0], [0, 14520], [7110, -7110], [-11488, 0], [0, 780], [0, -5402], [0, -2190], [7162, -7162], [-9360, 0], [12806, 0], [-11288, 11288], [-8520, 8520], [1260, 0], [13750, -13750], [-3210, 3210], [0, 12850], [8220, 0], [-7020, 7020], [-8122, 0], [0, -13470], [0, -2468], [4440, 0], [0, -11190], [4020, 0], [-9076, 0], [-7486, 0], [-7400, 7400], [-11490, 0], [0, -19320], [8340, -8340], [0, -21044], [1418, 0], [-22020, 22020], [-25230, 0], [0, 8280], [18874, -18874], [0, -10550], [11000, 0], [0, -11310], [17572, -17572], [1604, 0], [31320, -31320], [0, 31300], [-10920, 0], [0, -3210], [-11910, 11910], [0, 3382], [-15950, 15950], [32190, -32190], [-22140, 0], [6172, -6172], [-19170, 0], [21898, -21898], [-16680, 0], [-6518, 6518], [0, 23200], [-16324, 0], [0, -120], [0, -30548], [16952, 0], [0, -20220], [0, 20722], [-4350, 0], [0, -41972], [0, -39510], [-16680, 0], [-15484, 0], [4170, -4170], [0, 30226], [14760, 0], [-9934, 0], [-23520, 23520], [-29816, 29816], [-35430, 35430], [0, 36196], [-480, 0], [0, -28532], [20340, 0], [-10756, 0], [0, 600], [-25400, 25400], [-36240, 36240], [6572, 0], [2340, -2340], [2522, 0], [0, -52770], [28200, -28200], [15570, 0], [0, 8350], [-43650, 0], [0, 18810], [-25320, 25320], [-6736, 0], [20500, -20500], [-18202, 0], [0, 23010], [59550, -59550], [0, -48494], [0, 48120], [-41006, 41006], [0, -56012], [0, -52980], [16924, -16924], [-38310, 0], [43646, 0], [-2078, 2078], [59578, -59578], [810, -810], [0, 42136], [4650, 0], [0, 54000], [36270, -36270], [-15292, 0], [-43076, 43076], [0, -40742], [41340, 0], [-8434, 0], [43080, -43080], [17156, 0], [-570, 570], [-49980, 0], [0, -54930], [0, -64802], [-19100, 19100], [34590, -34590], [44400, 0], [0, 31350], [77092, -77092], [0, 4300], [-36686, 36686], [84450, 0], [78210, 0], [87308, 0], [0, 46680], [-55860, 55860], [0, -12836], [-16162, 0], [0, 7470], [-76634, 76634], [-1320, 1320], [0, -50940], [-35138, 35138], [0, 75718], [15180, -15180], [75720, 0], [0, -40590], [0, -35054], [0, -47432], [0, 70680], [59150, 0], [0, -3780], [-61358, 61358], [50190, -50190], [-1080, 0], [61162, -61162], [17190, -17190], [0, 76084], [-77596, 0], [0, -78344], [0, 40740], [-74900, 74900], [-38400, 38400], [0, -63074], [-102750, 0], [0, 87870], [47580, 0], [21360, -21360], [-67204, 0], [0, -25214], [-31582, 0], [0, 65970], [9060, -9060], [-89542, 0], [0, 42150], [0, 30892], [73800, 0], [0, -59600], [-65280, 0], [0, 94200], [57502, -57502], [-30870, 30870], [14310, 0], [55706, 0], [-64100, 64100], [8430, 0], [89750, 0], [-71954, 71954], [-6240, 6240], [0, 84994], [-22336, 0], [0, -13290], [113236, -113236], [52530, 0], [-124680, 124680], [0, 56500], [0, 103710], [0, -90686], [66800, 0], [2050, -2050], [0, 43948], [0, -88718], [44906, 0], [0, -73200], [-55562, 55562], [37274, 0], [103050, -103050], [0, 29880], [0, 85192], [-93240, 93240], [129034, -129034], [0, -118592], [-20580, 0], [-45526, 0], [0, 20430], [-21584, 21584], [-84480, 0], [-98730, 98730], [69180, 0], [0, -132990], [0, -3330], [75544, -75544], [0, -129090], [-31724, 31724], [-31470, 31470], [-21270, 0], [-153200, 153200], [0, 48850], [-107670, 0], [53432, 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_i();".
// 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_i(:prec:=2)
    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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![4, 2, 1]>,<11,R![900, -30, 1]>],Snew);
    return Vf;
end function;