
// Make newform 882.4.g.bg in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_882_g_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_882_4_g_bg();".
// 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_882_4_g_bg();".
// 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 := [4, 0, 2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_882_g();"
function MakeCharacter_882_g()
    N := 882;
    order := 3;
    char_gens := [785, 199];
    v := [3, 2];
    // 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_882_g_Hecke();"
function MakeCharacter_882_g_Hecke(Kf)
    N := 882;
    order := 3;
    char_gens := [785, 199];
    char_values := [[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 := [[2, 0, 2, 0], [0, 0, 0, 0], [0, 5, 0, 0], [0, 0, 0, 0], [0, 0, 40, 0], [0, 0, 0, 45], [0, 1, 0, 1], [0, -8, 0, 0], [-68, 0, -68, 0], [110, 0, 0, 0], [0, -84, 0, -84], [20, 0, 20, 0], [0, 0, 0, 35], [-340, 0, 0, 0], [0, -64, 0, 0], [0, 0, 628, 0], [0, -620, 0, -620], [0, -649, 0, 0], [0, 0, 540, 0], [-420, 0, 0, 0], [0, 205, 0, 205], [760, 0, 760, 0], [0, 0, 0, -668], [0, -815, 0, 0], [0, 0, 0, 355], [0, -1245, 0, -1245], [0, -160, 0, 0], [-2024, 0, -2024, 0], [0, 0, -404, 0], [1008, 0, 0, 0], [1000, 0, 0, 0], [0, -60, 0, 0], [0, 0, 2034, 0], [0, 0, 0, 1228], [-2140, 0, -2140, 0], [0, 0, 2120, 0], [0, 1235, 0, 1235], [-3340, 0, -3340, 0], [0, 0, 0, -260], [0, -2397, 0, 0], [0, 0, 720, 0], [0, 0, 0, 1311], [-3980, 0, -3980, 0], [0, 0, 3710, 0], [956, 0, 0, 0], [0, 2892, 0, 2892], [2868, 0, 0, 0], [0, 0, 0, -1860], [0, -120, 0, -120], [0, 2223, 0, 0], [4482, 0, 4482, 0], [-1740, 0, 0, 0], [0, 891, 0, 891], [0, 0, 0, 4120], [0, 3315, 0, 0], [0, 0, 2172, 0], [0, -1915, 0, -1915], [0, -4376, 0, 0], [0, 0, 6130, 0], [-1970, 0, 0, 0], [0, -1100, 0, -1100], [0, 0, 0, -5435], [0, 0, 0, 6080], [0, 5360, 0, 5360], [0, -2175, 0, 0], [2324, 0, 2324, 0], [-9508, 0, -9508, 0], [-4720, 0, 0, 0], [0, 0, -6504, 0], [0, 0, 0, 3717], [0, 8635, 0, 8635], [7340, 0, 7340, 0], [0, -5420, 0, -5420], [2990, 0, 2990, 0], [-11900, 0, 0, 0], [0, 6868, 0, 0], [0, 0, 2150, 0], [0, -2405, 0, 0], [12090, 0, 12090, 0], [0, 5793, 0, 5793], [0, 0, 0, 740], [-3870, 0, 0, 0], [0, 0, -2700, 0], [0, 0, 0, 4155], [0, -4488, 0, 0], [6928, 0, 6928, 0], [-1320, 0, 0, 0], [-1290, 0, -1290, 0], [0, 0, 0, 12475], [5680, 0, 0, 0], [0, -5440, 0, 0], [0, 11680, 0, 11680], [0, 0, 13680, 0], [2280, 0, 0, 0], [-860, 0, -860, 0], [0, 0, 0, -4052], [0, -3245, 0, 0], [0, 10315, 0, 10315], [0, 4320, 0, 0], [17210, 0, 17210, 0], [4060, 0, 0, 0], [0, 0, 10356, 0], [0, -16412, 0, -16412], [-5890, 0, -5890, 0], [0, 0, -5612, 0], [0, 12585, 0, 12585], [0, 0, 0, -5616], [0, 9955, 0, 0], [0, 0, -7300, 0], [0, 0, 0, -6171], [0, 7500, 0, 0], [0, 0, -13980, 0], [-2654, 0, 0, 0], [0, -16888, 0, -16888], [-6400, 0, 0, 0], [0, 0, 15350, 0], [0, 0, 0, -12620], [0, -9900, 0, -9900], [-26382, 0, -26382, 0], [14400, 0, 0, 0], [0, 20211, 0, 20211], [-18120, 0, 0, 0], [0, -12585, 0, 0], [0, 0, 1728, 0], [0, -12084, 0, 0], [13410, 0, 0, 0], [140, 0, 140, 0], [0, -18340, 0, 0], [0, 0, 0, -6560], [0, 18015, 0, 0], [0, 0, -6924, 0], [-29108, 0, 0, 0], [-31448, 0, -31448, 0], [-13300, 0, 0, 0], [0, -3395, 0, 0], [0, 0, 0, -11973], [0, -13747, 0, -13747], [0, -14660, 0, -14660], [0, 0, 0, -20211], [0, 0, 22280, 0], [0, 0, 0, -18456], [3540, 0, 3540, 0], [0, 0, -28400, 0], [38736, 0, 0, 0], [0, -16553, 0, -16553], [0, 0, 0, 20780], [0, 0, 0, -15735], [0, -9781, 0, -9781], [0, -28048, 0, 0], [-31988, 0, -31988, 0], [33460, 0, 33460, 0], [0, 0, 0, -9045], [-35260, 0, 0, 0], [0, -10916, 0, 0], [0, 0, 33100, 0], [39620, 0, 0, 0], [-20944, 0, -20944, 0], [0, -32695, 0, 0], [0, 0, 0, 35725], [0, 6985, 0, 6985], [-30216, 0, -30216, 0], [35512, 0, 0, 0], [-720, 0, 0, 0], [0, 10880, 0, 0], [0, 0, -41574, 0], [0, 31280, 0, 31280], [0, 0, 12272, 0], [0, 40795, 0, 40795]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_4_g_bg();".
// 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_882_4_g_bg(:prec:=4)
    chi := MakeCharacter_882_g();
    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_882_4_g_bg();".
// 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_882_4_g_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![2500, 0, 50, 0, 1]>,<11,R![1600, 40, 1]>,<13,R![-4050, 0, 1]>],Snew);
    return Vf;
end function;