
// Make newform 882.6.a.e in Magma, downloaded from the LMFDB on 28 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_a();"
// 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_6_a_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_882_6_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_882_a();"
function MakeCharacter_882_a()
    N := 882;
    order := 1;
    char_gens := [785, 199];
    v := [1, 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;

function MakeCharacter_882_a_Hecke(Kf)
    return MakeCharacter_882_a();
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 := 6;
    raw_aps := [[-4], [0], [-6], [0], [666], [559], [-1740], [-1157], [3468], [-3372], [-6293], [3131], [-4866], [-11407], [2310], [28296], [20544], [4630], [-18745], [38226], [-70589], [-62293], [79818], [-18120], [-124754], [-93390], [167731], [-69180], [-219559], [39354], [317093], [-154830], [-67332], [365215], [168060], [153536], [-202418], [-179764], [217302], [-73980], [-789366], [477739], [-358974], [-181933], [-717924], [-203096], [1170980], [-1246352], [-918942], [-1203749], [919062], [625338], [-1253822], [-1513332], [-1554930], [1115316], [35670], [292768], [863213], [-1471104], [-688841], [722832], [20125], [-1743558], [-1808543], [-1023552], [-1007533], [-1565707], [-757284], [455638], [-3631386], [4024836], [-2577875], [-2531329], [-3066769], [-3925200], [4026690], [-4574399], [2269440], [4045963], [-3912810], [-2780863], [4382070], [-1249463], [6744208], [-478896], [-724506], [-2339563], [2982468], [4284227], [-5740350], [2650512], [2805539], [4684500], [1475753], [63606], [6211566], [1412052], [-5229347], [4413725], [-11903764], [-12913302], [-11369838], [5697954], [-7042207], [2581969], [4694592], [13423506], [-5046012], [10639081], [-1416083], [9463034], [-12938778], [3803761], [-9174976], [-10245372], [5723455], [-9987942], [1198878], [-11806536], [-4720391], [-8708257], [5111052], [17719776], [22599337], [818148], [-5091826], [-480858], [14078329], [-2039321], [-16495699], [23812086], [1924961], [8980922], [14599092], [-27838055], [-28285722], [-9872], [-10891908], [5235294], [-12614744], [15342378], [-14959504], [-28049790], [-14731097], [23634660], [-14396459], [12470976], [12505888], [-28028922], [23117282], [-9598908], [443183], [-24009666], [17585375], [29559852], [-3914821], [-3220086], [51650353], [-7286976], [31244778], [26827320], [-10025665], [115800], [-8738094], [23841264], [-33371923], [-54468659], [62306861], [24697560], [-61222224], [1283122], [34223460], [24017501], [-31476905], [-51970776], [11146463], [6709410], [-35813216], [7344913], [-11556223], [-17385672], [43594601], [30055440], [1489374], [-40951404], [10072262], [66440581], [-55140175], [-4011702], [-53887145], [46203306], [-18178000], [-1429608], [25712520], [55721304], [-27069901], [-34708594], [52815954], [-9970536], [-57120582], [8400685], [21163258], [77790982], [-6849642], [7094682], [-61772240], [-28319334], [108027540], [-15653204], [-37119169], [60951864], [-34305268], [22658088], [-18904320], [79007473], [-55506592], [84978876], [6907488], [-130627566], [21641309], [50458567], [76289130], [-111833224], [-80614062], [15130706], [23052288], [-80676474], [76046893], [-11540286], [90899141], [-127012772], [-26587405], [83481450], [-9334037], [44383974], [-16401773], [38178354], [86418228], [-64692234], [-68476194], [68808859], [113579263], [24487454], [-13273128], [116433168], [-46889975], [-82444650], [134631440], [-131465928], [-181352299], [96474828], [-91417362], [-39904253], [134205576], [-147177600], [138646553], [104102317], [118606350], [-212694158], [221827895], [-14557632], [52407979], [-76863491], [-156312714], [-146517749], [-56653578], [-194719410], [-144848116], [5630970], [200708581], [69120884], [-114336269], [60727187], [139747006], [160463284], [58798458], [112662215], [-39775381], [219374628], [-206610264], [89782139], [120444042], [-30341519], [-121827068], [-93868470], [-222922951], [36282894], [230337919], [147777366], [157714308], [38410476], [120613566], [-74345220], [-114438373], [33346350], [-265414109], [222066864], [31281690], [-58576883], [237131722], [74901942], [128213444], [129354252], [-204492559], [-162005107], [-17688006], [-97822385], [353483784], [355839539], [-289428360], [193006770], [245141502], [-23597992], [184187208], [-108839369], [304097166], [24386052], [-117823865], [-5470434], [-83969105], [-35653057], [29257734], [-181151773], [-159489126], [-254778929], [32158619], [-392860361], [404917452], [-187458234], [45235169], [-312519762], [-244999685], [-124417278], [-197191297], [-290015466], [-144263734], [-190323444], [295580611], [-118555793], [416415119], [87594240], [229391460], [-218067775], [-452962602], [136729458], [411015439], [40791812], [128825598], [103725162], [242985628], [187795154], [7091838], [-342703832], [-95980489], [229863846], [273836394], [35650464], [472473276], [370311570], [527637434], [341254218], [-18670518], [-329741970], [-539106293], [67358462], [-582461808], [388931285], [144244622], [-223638408], [-178577873], [-453819726], [31437210], [-223985675], [-19765159], [-79729980], [258235644], [-162216182], [584044236], [430927879], [123298236], [-503315748], [247593008], [348155112], [628117084], [28777644], [-433097125], [334930042], [-344427313], [-678582966], [19988537], [-608895786], [593916564], [-290427275], [-501458754], [234703394], [121095988], [656483634], [100340651], [-499596378], [84571570], [87781464], [-39142000], [380942346], [518219850], [-67282301], [329862398], [-486116124], [489979879], [217055484], [-341214098], [-376897404], [106372656], [-97877524], [-390693199], [-509219670], [-428790210], [-5162021], [-440878212], [-240202644], [-495556476], [429084313], [652539624], [172236078], [-137178974], [335225478], [-774790542], [-438502704], [-118344404], [45607920]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_6_a_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_882_6_a_e(:prec:=1)
    chi := MakeCharacter_882_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_6_a_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_882_6_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![6, 1]>,<11,R![-666, 1]>],Snew);
    return Vf;
end function;