
// Make newform 208.4.i.e in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_208_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_208_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_208_4_i_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_208_4_i_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 := [16, 4, 5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [16, -5, 5, -1], [4, 0, 0, 1]];
    Rf_basisdens := [1, 1, 20, 5];
    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_208_i();"
function MakeCharacter_208_i()
    N := 208;
    order := 3;
    char_gens := [79, 53, 145];
    v := [3, 3, 1];
    // 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_208_i_Hecke();"
function MakeCharacter_208_i_Hecke(Kf)
    N := 208;
    order := 3;
    char_gens := [79, 53, 145];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 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, 3, 1, 0], [-10, 0, 0, -5], [7, -1, -7, -1], [0, 15, 1, 0], [9, -5, 40, -7], [-43, -16, 43, -16], [-73, -5, 73, -5], [0, -33, 89, 0], [0, -60, 13, 0], [120, 0, 0, 100], [0, 44, 73, 0], [0, -20, -259, 0], [179, -97, -179, -97], [-100, 0, 0, -140], [190, 0, 0, -165], [-377, 55, 377, 55], [-351, -200, 351, -200], [0, 91, -283, 0], [11, -105, -11, -105], [250, 0, 0, -85], [-140, 0, 0, -40], [-180, 0, 0, -100], [0, 125, -523, 0], [-27, -469, 27, -469], [0, -320, -151, 0], [1080, 0, 0, -320], [0, -601, -367, 0], [-230, 0, 0, 260], [-659, -388, 659, -388], [0, -481, 1853, 0], [-820, 0, 0, -840], [-663, -16, 663, -16], [-297, -245, 297, -245], [1913, 40, -1913, 40], [-960, 0, 0, -540], [254, 0, 0, -417], [-781, 1103, 781, 1103], [0, -1721, 993, 0], [-1771, 223, 1771, 223], [0, -445, 473, 0], [-970, 0, 0, -105], [2159, 335, -2159, 335], [0, -352, 1421, 0], [0, -1731, 1313, 0], [-2157, -1325, 2157, -1325], [0, -945, -111, 0], [0, -33, -1111, 0], [1823, 1051, -1823, 1051], [330, 0, 0, -1700], [-4162, 0, 0, 276], [-5576, 0, 0, -300], [989, 2680, -989, 2680], [5691, -45, -5691, -45], [0, -116, 1493, 0], [0, 1587, -3831, 0], [2553, -45, -2553, -45], [0, 695, 3921, 0], [5093, -804, -5093, -804], [-7990, 0, 0, -725], [0, 303, 2601, 0], [-3359, -3148, 3359, -3148], [300, 0, 0, 2120], [-5080, 0, 0, 1120], [-3450, 0, 0, 1980], [-630, 0, 0, 2355], [3299, 2815, -3299, 2815], [2690, 0, 0, 1295], [-4717, -349, 4717, -349], [0, -815, -1323, 0], [0, 3552, -3511, 0], [-5304, 0, 0, -1200], [0, -3081, -807, 0], [2069, 5088, -2069, 5088], [0, 5355, 193, 0], [-4729, -1653, 4729, -1653], [3890, 0, 0, 3135], [-6287, -3189, 6287, -3189], [0, 280, -1139, 0], [-5163, -1020, 5163, -1020], [0, 395, 11373, 0], [8862, 0, 0, -625], [0, 2455, -10251, 0], [2021, -2488, -2021, -2488], [0, 975, 7677, 0], [11260, 0, 0, 2100], [337, 4295, -337, 4295], [0, 7016, -3143, 0], [-5299, -5860, 5299, -5860], [-14120, 0, 0, -1080], [6920, 0, 0, 5220], [0, -2225, -3867, 0], [7763, 1111, -7763, 1111], [0, 1175, -59, 0], [3220, 0, 0, 6500], [3951, 1027, -3951, 1027], [0, -4540, -9287, 0], [6738, 0, 0, 6575], [0, 5243, -6299, 0], [-3110, 0, 0, -7785], [-5860, 0, 0, -6020], [0, 3004, 15133, 0], [12631, -3513, -12631, -3513], [0, 3645, 1253, 0], [-5620, 0, 0, -2880], [-3214, 0, 0, 4047], [0, -5001, 11853, 0], [6522, 0, 0, -81], [-6380, 0, 0, -1600], [0, 3080, -14291, 0], [11363, 3351, -11363, 3351], [0, -1492, -18799, 0], [-14607, 2876, 14607, 2876], [-14420, 0, 0, -2840], [4619, 9175, -4619, 9175], [16029, 4840, -16029, 4840], [-20949, -3973, 20949, -3973], [0, 2011, 9997, 0], [0, -3743, 2229, 0], [14027, -5585, -14027, -5585], [0, 6000, -16479, 0], [0, -8612, 1081, 0], [19210, 0, 0, -4580], [20711, 5967, -20711, 5967], [0, -8305, -12519, 0], [-14150, 0, 0, -8220], [6413, 1720, -6413, 1720], [-8753, 1575, 8753, 1575], [-8920, 0, 0, -5860], [6890, 0, 0, 17855], [0, -2225, 20157, 0], [0, -8193, 19709, 0], [0, -3645, -3671, 0], [0, 5649, -3747, 0], [249, 5415, -249, 5415], [0, -3255, 16833, 0], [1361, 13907, -1361, 13907], [-15053, -941, 15053, -941], [53, 7471, -53, 7471], [0, -8660, 10573, 0], [-13968, 0, 0, -1700], [0, -2795, 33641, 0], [-4621, -7197, 4621, -7197], [9236, 0, 0, -13728], [0, -7220, -5843, 0], [-14293, 4055, 14293, 4055], [4590, 0, 0, 5755], [-18630, 0, 0, -8065], [4820, 0, 0, 4480], [-16192, 0, 0, 11516], [-38583, -3176, 38583, -3176], [0, -8140, -11691, 0], [11140, 0, 0, 15140], [0, -2349, 46117, 0], [0, -13149, -3143, 0], [-25760, 0, 0, 3420], [-11737, -13765, 11737, -13765], [24973, 160, -24973, 160], [-21350, 0, 0, -3605], [10390, 0, 0, -1760], [0, 2499, 1033, 0], [1261, -8693, -1261, -8693], [2160, 0, 0, 10040], [25699, 10135, -25699, 10135], [0, -15716, 7113, 0], [26640, 0, 0, 8500], [0, 3695, 3069, 0], [7393, 1496, -7393, 1496]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_208_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_208_4_i_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_208_4_i_e(:prec:=4)
    chi := MakeCharacter_208_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(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_208_4_i_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_208_4_i_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_208_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1024, 160, 57, -5, 1]>],Snew);
    return Vf;
end function;