
// Make newform 882.5.c.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_882_c_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_5_c_b();".
// 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_5_c_b();".
// 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, 0, 0, 1], [1, 0, 1, 0], [0, 4, 0, 1]];
    Rf_basisdens := [1, 1, 1, 1];
    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_c();"
function MakeCharacter_882_c()
    N := 882;
    order := 2;
    char_gens := [785, 199];
    v := [2, 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_882_c_Hecke();"
function MakeCharacter_882_c_Hecke(Kf)
    N := 882;
    order := 2;
    char_gens := [785, 199];
    char_values := [[1, 0, 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 := 5;
    raw_aps := [[0, 1, 0, 0], [0, 0, 0, 0], [0, 0, -9, -2], [0, 0, 0, 0], [-27, 6, 0, 0], [0, 0, 8, -36], [0, 0, 153, -32], [0, 0, 5, 90], [-243, -240, 0, 0], [-810, -24, 0, 0], [0, 0, 91, 180], [223, -270, 0, 0], [0, 0, -72, -208], [586, -648, 0, 0], [0, 0, -117, 316], [1377, -774, 0, 0], [0, 0, 2061, 146], [0, 0, 1281, -738], [2531, -1674, 0, 0], [-4698, 456, 0, 0], [0, 0, 2879, -900], [-397, 972, 0, 0], [0, 0, -2448, -100], [0, 0, 2079, -564], [0, 0, 216, -1224], [0, 0, 729, -1602], [0, 0, -4211, 1800], [-15579, -1758, 0, 0], [-14105, -54, 0, 0], [9558, 264, 0, 0], [938, -1080, 0, 0], [0, 0, 7587, 1446], [-13959, 3924, 0, 0], [0, 0, -896, -3780], [28809, -4914, 0, 0], [13723, -5616, 0, 0], [0, 0, 8463, -5490], [4883, -5886, 0, 0], [0, 0, 8712, 304], [0, 0, -1377, 8730], [16821, -12966, 0, 0], [0, 0, -21824, -3348], [-5211, -2268, 0, 0], [-617, -18360, 0, 0], [28134, 9432, 0, 0], [0, 0, -21573, -6408], [1210, 648, 0, 0], [0, 0, 8832, -5472], [0, 0, 10341, -15162], [0, 0, -19079, -1854], [45225, -3492, 0, 0], [-18738, 1536, 0, 0], [0, 0, -25713, -7560], [0, 0, 5256, -7412], [0, 0, -46089, -5736], [64989, 8784, 0, 0], [0, 0, 23553, 13178], [0, 0, -36387, 9756], [-8497, 486, 0, 0], [32454, -43368, 0, 0], [0, 0, 52571, 3798], [0, 0, -51696, -76], [0, 0, 73552, 2916], [0, 0, -43587, -2072], [0, 0, 5713, 1620], [2673, 29514, 0, 0], [-8909, -28890, 0, 0], [50170, -27000, 0, 0], [113805, 16566, 0, 0], [0, 0, -12600, -756], [0, 0, -20151, -4424], [34965, 25728, 0, 0], [0, 0, -23453, 6084], [80015, 39258, 0, 0], [-11774, 30672, 0, 0], [0, 0, 38619, -12604], [-56295, 10602, 0, 0], [0, 0, -70423, -6930], [-149607, -40656, 0, 0], [0, 0, 50119, 46332], [0, 0, -94320, 31852], [145274, 60264, 0, 0], [-91179, -27348, 0, 0], [0, 0, 18632, 3096], [0, 0, 95781, -11448], [24165, -20646, 0, 0], [258822, -25320, 0, 0], [-112721, 92124, 0, 0], [0, 0, 15480, -9628], [-49270, -6264, 0, 0], [0, 0, 2835, 48366], [0, 0, 15021, 50228], [-134045, 96768, 0, 0], [285822, -336, 0, 0], [18931, -117558, 0, 0], [0, 0, 22176, -31528], [0, 0, -74025, 9194], [0, 0, 9729, 37796], [0, 0, 122645, -49050], [-26233, 4158, 0, 0], [-5182, -129168, 0, 0], [63369, 132198, 0, 0], [0, 0, 3645, 2118], [-151551, -99636, 0, 0], [-225301, 96498, 0, 0], [0, 0, 2767, 5904], [0, 0, -299376, 33012], [0, 0, -92169, 39392], [29133, 124968, 0, 0], [0, 0, 21592, 5904], [0, 0, -204875, -27108], [-164185, 62694, 0, 0], [-2538, 84264, 0, 0], [0, 0, -133837, 78822], [336938, 41256, 0, 0], [413073, -94800, 0, 0], [0, 0, 234080, 34020], [0, 0, -165699, -65376], [203553, -99390, 0, 0], [216486, 193080, 0, 0], [0, 0, 205039, -29502], [348250, 89640, 0, 0], [0, 0, -108729, -71490], [71253, -20442, 0, 0], [0, 0, -33331, 38466], [-283986, -164928, 0, 0], [109231, -249102, 0, 0], [0, 0, 129123, 40196], [0, 0, -98704, 70200], [0, 0, 107777, -11250], [-580645, -32130, 0, 0], [-222858, 126360, 0, 0], [441979, 1620, 0, 0], [-481766, -161784, 0, 0], [0, 0, -99081, 167348], [0, 0, 392, -36792], [0, 0, 170793, 64318], [0, 0, -424269, -93222], [0, 0, 242568, 98052], [-313119, 85788, 0, 0], [0, 0, 333504, -103428], [636201, 4062, 0, 0], [434483, 227880, 0, 0], [435942, -157320, 0, 0], [0, 0, 591415, 54774], [0, 0, -133200, -180680], [0, 0, -336536, -144252], [0, 0, -238959, -49124], [0, 0, 147765, -2322], [-386883, -301284, 0, 0], [501047, 69606, 0, 0], [0, 0, 619056, -76416], [176362, -252936, 0, 0], [0, 0, 648315, 28504], [622531, -116478, 0, 0], [-326106, -378072, 0, 0], [-692309, -59400, 0, 0], [0, 0, 29151, -210224], [0, 0, 519424, 49032], [0, 0, 488385, -9142], [-1101411, -148890, 0, 0], [429462, 12264, 0, 0], [-271366, 117720, 0, 0], [0, 0, 3843, -156286], [-1114263, 39216, 0, 0], [0, 0, -497547, -69136], [67219, -616140, 0, 0], [0, 0, -26785, -143478]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_5_c_b();".
// 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_5_c_b(:prec:=4)
    chi := MakeCharacter_882_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_5_c_b();".
// 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_5_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<5,R![21609, 0, 678, 0, 1]>,<11,R![441, 54, 1]>],Snew);
    return Vf;
end function;