
// Make newform 882.6.a.i in Magma, downloaded from the LMFDB on 10 June 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_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_882_6_a_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
        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]];
    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], [24], [0], [-66], [-98], [-216], [340], [1038], [2490], [7048], [-12238], [6468], [-15412], [20604], [-32490], [34224], [-35654], [12680], [42642], [-33734], [-85108], [-106764], [34884], [-18662], [153084], [-35864], [95454], [212222], [-62106], [-53044], [69324], [-129846], [104356], [-217194], [221000], [378370], [104816], [-426972], [331068], [400194], [-588098], [-939342], [338390], [237942], [-204464], [-348724], [-1470056], [-589560], [1045342], [-651222], [513462], [694714], [-1396080], [-1005204], [-1253010], [-1760688], [-770528], [707738], [-2304318], [-1609028], [517020], [-1350020], [1345380], [-256154], [-1846290], [-3332380], [-1634806], [841530], [977242], [3458568], [3473010], [-3119936], [-2016730], [-5380828], [807432], [-891390], [-1123454], [-1720374], [-77246], [-5206152], [1718474], [580626], [-4150874], [-3884072], [2314986], [1922814], [6862154], [2971668], [4874228], [-8173008], [2343972], [316928], [5200410], [-4867732], [426888], [-9416208], [1840392], [979108], [5961170], [8730248], [3010662], [11757264], [-13157814], [-10334440], [7881334], [-554568], [-9203688], [-8542950], [9615550], [-2212640], [-7962154], [13739682], [8701132], [445412], [8001186], [15840244], [1301868], [-7341486], [6189342], [19668970], [7182590], [-18919212], [-21220398], [-16327580], [5404698], [22119494], [25581888], [9294376], [-3406994], [21813536], [-3792462], [-20148256], [11842742], [2977908], [20244070], [-7379532], [-13628924], [-14954772], [-28724202], [15226540], [33100062], [-13591540], [-3139362], [-12708074], [-29831172], [19221538], [-26565468], [9168436], [29219598], [9712862], [16537248], [-23948692], [-4628460], [20612588], [3467490], [-36122704], [12936612], [-50139362], [-10556832], [3146838], [-52282890], [-24823468], [13307724], [-8177046], [-13246512], [-14854984], [3337690], [-28787218], [-40667988], [30669846], [-57889790], [-7566774], [-33152746], [24463144], [31374672], [196016], [51080418], [-53921504], [-3102494], [44171636], [2565948], [24041978], [22613832], [63414894], [-35473164], [27017462], [-34942244], [3783302], [10750104], [88285642], [-74982882], [-7512892], [50423124], [50436558], [81410064], [-43457698], [-54169726], [55525764], [54441180], [-32169714], [4451944], [56284246], [67783162], [-68660172], [43817292], [88225288], [-44337354], [-56993610], [-48811148], [-101369662], [-8057280], [59798048], [102542268], [-26837292], [-11369858], [100083896], [54185664], [56551518], [-13559478], [18267254], [-35080136], [77237526], [-27506320], [-58481220], [-61748734], [114626676], [100402614], [-71336408], [18772098], [42982334], [9237724], [-47072296], [-115301994], [115318084], [-85091712], [-105455654], [161207118], [130929762], [5118120], [47155434], [-27026660], [37125136], [112305170], [96311796], [138977940], [-92818712], [-113693880], [-7096744], [-120050226], [106917974], [123169896], [-118212342], [146436682], [151610124], [-56544066], [23311802], [135965668], [17421012], [-198501698], [-73672708], [-183063414], [10411246], [155546314], [-88827024], [60942676], [-47338650], [233766120], [97103456], [-143807982], [-3842198], [-148958044], [116057290], [168698024], [131346082], [251568664], [-247183242], [41028242], [171634286], [187756824], [136026024], [-41051980], [136578288], [288611050], [-22449500], [-291893166], [-47044078], [136351038], [-154502888], [95469948], [15059454], [129464028], [103552626], [118421016], [214599758], [228638796], [-155891480], [-204623664], [144502704], [-234530996], [-173461130], [210175002], [-15337564], [-21842466], [-80861608], [-283300918], [350825010], [-264028058], [-163559310], [-188486566], [54689736], [143778618], [364074090], [88611596], [-130052610], [-137545094], [-107503620], [-181737258], [56418754], [402710754], [-8915180], [-221741578], [370553652], [-22327576], [29987934], [-233498702], [-194139304], [64366348], [-155481366], [-429705054], [-363818506], [-306649374], [-385720160], [41557944], [-245003056], [-279199872], [358119470], [-408795636], [-81617102], [222753472], [-14281978], [275829090], [-110669664], [-337716832], [213314586], [-202027842], [-118402922], [-44976388], [-497789880], [-313730820], [-10380212], [-299198554], [86924766], [-441926024], [63281510], [288391824], [-444636336], [-177596964], [-517430058], [-217083414], [-52707226], [504401628], [-148295934], [171988854], [-74609228], [464039798], [451500168], [342662708], [-282528034], [-31865718], [-470799164], [-377713446], [-507113490], [419687848], [340365170], [-123562452], [135641574], [-319627946], [141523560], [-312061190], [-484549260], [-165763194], [-544070896], [123026838], [71588188], [-381430944], [469585616], [691621174], [-136550752], [-54044508], [-577918066], [405740856], [586204686], [-341325428], [546394578], [105789554], [261011176], [410699856], [-343318960], [-437159670], [779589514], [84935286], [-308743444], [-678399852], [454608792], [-358815656], [-268521502], [363398334], [-173495204], [240103272], [-426126578], [-238577358], [-576569646], [-250539340], [-319480138], [-52982136], [843925518], [-577186016], [42748272], [-63025932], [106421802], [193908922], [-171267294], [-778082844], [840795046], [774895164], [172048074], [729149202], [-527296988], [-173216364]];
    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_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_882_6_a_i(: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_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_882_6_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-24, 1]>,<11,R![66, 1]>],Snew);
    return Vf;
end function;