
// Make newform 882.4.a.m in Magma, downloaded from the LMFDB on 18 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_4_a_m();".
// 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_a_m();".
// 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 := 4;
    raw_aps := [[2], [0], [-6], [0], [30], [-2], [-66], [52], [114], [72], [196], [-286], [378], [164], [228], [-348], [348], [106], [596], [630], [1042], [-88], [1440], [-1374], [34], [438], [-1676], [2022], [-502], [2016], [1784], [-1608], [-2580], [-2144], [1500], [-1240], [-614], [92], [3924], [1902], [-6], [2878], [-354], [-4858], [-396], [-1712], [-772], [-776], [1788], [-5402], [3012], [3546], [3562], [-3348], [-366], [4170], [-6078], [-2468], [-394], [-396], [1348], [-7506], [-1748], [1140], [-146], [-8148], [-9700], [8174], [-4038], [-10766], [-3666], [-5106], [5776], [8462], [6860], [696], [11136], [-10838], [-8364], [1762], [-14580], [8534], [5934], [14758], [11392], [7026], [-3384], [-4282], [-16650], [-9664], [12324], [-18660], [-3400], [2970], [-988], [-5184], [-16854], [4398], [10672], [20702], [-22876], [-12876], [6900], [14676], [380], [11806], [19188], [-690], [-20490], [11590], [6424], [-9682], [5076], [-22664], [-8584], [372], [-3188], [12732], [-3576], [11430], [-22646], [-13570], [2838], [-6558], [21832], [16200], [36722], [-13776], [-34220], [13750], [39836], [34470], [5240], [18578], [-30534], [39958], [3966], [3760], [24102], [11712], [-37424], [13452], [20432], [24390], [28510], [36972], [14074], [8826], [20500], [7674], [-8890], [-738], [20], [-39804], [29180], [-48258], [25760], [44778], [44494], [7458], [17790], [-5832], [-13264], [-3984], [-38940], [8808], [18488], [5002], [9434], [-41658], [-19050], [37546], [-50106], [-10870], [-45992], [-46242], [-2140], [26400], [-31052], [-23150], [-37600], [-46296], [-15874], [-11202], [22602], [-25554], [-44134], [20536], [59546], [-5880], [754], [-32418], [-45700], [74334], [68718], [39750], [-14434], [72038], [-64350], [50124], [-81708], [25072], [-82154], [-78950], [18936], [-21810], [9952], [-64938], [-87768], [-12332], [-13246], [-21510], [-50632], [76656], [-33852], [-67322], [-61432], [-18930], [-4926], [47232], [-24478], [-23924], [-24240], [-62872], [-45288], [3314], [25338], [-75102], [-91244], [74418], [-79270], [69028], [-86920], [7248], [46852], [-95808], [-18830], [-82092], [-48438], [-21600], [33906], [42784], [-58448], [-69838], [-29790], [23988], [-95924], [109212], [100892], [20034], [218], [24870], [-15162], [1618], [93102], [47022], [-34], [102436], [87534], [-75530], [-92320], [76770], [38878], [41578], [55158], [68632], [-115740], [87678], [55172], [-73248], [-48710], [37028], [21922], [3944], [-31790], [-69428], [-73434], [22466], [-18610], [12828], [107880], [78536], [-17496], [43738], [-150464], [75390], [129278], [3708], [-126452], [128394], [19380], [-73416], [100068], [38772], [8246], [-117642], [33568], [-6750], [-88836], [22696], [-5258], [120840], [-82528], [146358], [106076], [-142882], [-42918], [53206], [47310], [-91798], [8328], [19992], [-14484], [-24388], [-119934], [-22430], [125352], [14394], [87802], [684], [89908], [-97162], [-9810], [-97432], [-36384], [18970], [-107620], [-80804], [-88338], [182376], [79850], [64200], [203092], [126636], [146396], [-112932], [-197962], [17418], [-94142], [-31916], [-59218], [-115236], [-190494], [-96712], [-173280], [-22914], [48382], [-54268], [-36072], [109326], [168028], [74882], [-170964], [-92288], [25166], [-217602], [20496], [-64416], [-152904], [66006], [-108034], [-110958], [33582], [24846], [219832], [-41578], [-88470], [91640], [180254], [191730], [24316], [224502], [-160740], [-178508], [-144178], [-244344], [-26622], [21886], [-124170], [-132374], [-74802], [-32544], [246296], [-29832], [143440], [170232], [-222136], [-21026], [165188], [-79812], [-3454], [167970], [154974], [103300], [-243498], [125894], [138472], [-121914], [-48076], [-7080], [59218], [-157368], [25616], [199002], [-199470], [53008], [155630], [166752], [203848], [-208212], [200230], [-40512], [84762], [-279340], [-221686], [50034], [168666], [-232652], [30150], [61572], [-253896], [-6446], [185382], [219672], [-72362], [160422], [-203214], [-23364], [295288], [-297516]];
    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_4_a_m();".
// 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_a_m(:prec:=1)
    chi := MakeCharacter_882_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_m();".
// 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_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![6, 1]>,<11,R![-30, 1]>,<13,R![2, 1]>],Snew);
    return Vf;
end function;