
// Make newform 882.4.a.y in Magma, downloaded from the LMFDB on 23 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_y();".
// 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_y();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_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], [0, 0], [0, 5], [0, 0], [40, 0], [0, 45], [0, -1], [0, -8], [68, 0], [110, 0], [0, 84], [-20, 0], [0, 35], [-340, 0], [0, -64], [628, 0], [0, 620], [0, -649], [540, 0], [-420, 0], [0, -205], [-760, 0], [0, -668], [0, -815], [0, 355], [0, 1245], [0, -160], [2024, 0], [-404, 0], [1008, 0], [1000, 0], [0, -60], [2034, 0], [0, 1228], [2140, 0], [2120, 0], [0, -1235], [3340, 0], [0, -260], [0, -2397], [720, 0], [0, 1311], [3980, 0], [3710, 0], [956, 0], [0, -2892], [2868, 0], [0, -1860], [0, 120], [0, 2223], [-4482, 0], [-1740, 0], [0, -891], [0, 4120], [0, 3315], [2172, 0], [0, 1915], [0, -4376], [6130, 0], [-1970, 0], [0, 1100], [0, -5435], [0, 6080], [0, -5360], [0, -2175], [-2324, 0], [9508, 0], [-4720, 0], [-6504, 0], [0, 3717], [0, -8635], [-7340, 0], [0, 5420], [-2990, 0], [-11900, 0], [0, 6868], [2150, 0], [0, -2405], [-12090, 0], [0, -5793], [0, 740], [-3870, 0], [-2700, 0], [0, 4155], [0, -4488], [-6928, 0], [-1320, 0], [1290, 0], [0, 12475], [5680, 0], [0, -5440], [0, -11680], [13680, 0], [2280, 0], [860, 0], [0, -4052], [0, -3245], [0, -10315], [0, 4320], [-17210, 0], [4060, 0], [10356, 0], [0, 16412], [5890, 0], [-5612, 0], [0, -12585], [0, -5616], [0, 9955], [-7300, 0], [0, -6171], [0, 7500], [-13980, 0], [-2654, 0], [0, 16888], [-6400, 0], [15350, 0], [0, -12620], [0, 9900], [26382, 0], [14400, 0], [0, -20211], [-18120, 0], [0, -12585], [1728, 0], [0, -12084], [13410, 0], [-140, 0], [0, -18340], [0, -6560], [0, 18015], [-6924, 0], [-29108, 0], [31448, 0], [-13300, 0], [0, -3395], [0, -11973], [0, 13747], [0, 14660], [0, -20211], [22280, 0], [0, -18456], [-3540, 0], [-28400, 0], [38736, 0], [0, 16553], [0, 20780], [0, -15735], [0, 9781], [0, -28048], [31988, 0], [-33460, 0], [0, -9045], [-35260, 0], [0, -10916], [33100, 0], [39620, 0], [20944, 0], [0, -32695], [0, 35725], [0, -6985], [30216, 0], [35512, 0], [-720, 0], [0, 10880], [-41574, 0], [0, -31280], [12272, 0], [0, -40795], [-52754, 0], [0, 30865], [11280, 0], [0, 8459], [-30660, 0], [-38240, 0], [0, 33008], [0, -36295], [-2700, 0], [-10230, 0], [0, 5460], [0, 15433], [44440, 0], [0, 39280], [-8580, 0], [0, 4561], [-55292, 0], [0, -20705], [-37050, 0], [0, 34380], [15320, 0], [0, -46340], [0, -13815], [43632, 0], [1340, 0], [0, -6715], [-47256, 0], [0, -13105], [11760, 0], [-43700, 0], [0, 43965], [0, 6320], [-70500, 0], [0, -984], [0, 13765], [0, -49967], [0, 29720], [0, -56921], [0, -9328], [-59088, 0], [26000, 0], [0, 8376], [40, 0], [0, 75], [37120, 0], [0, 35744], [0, 10360], [0, 33391], [91280, 0], [0, -20975], [5724, 0], [33198, 0], [-16540, 0], [0, -66468], [-45480, 0], [89000, 0], [0, -39820], [-83780, 0], [0, -7535], [-2780, 0], [0, -35180], [28440, 0], [5780, 0], [0, 34932], [52240, 0], [-86880, 0], [0, 67580], [0, 11520], [0, 48573], [9068, 0], [-33280, 0], [0, -12940], [22248, 0], [0, -83496], [0, 3000], [-17814, 0], [0, -67477], [0, -73540], [0, 42680], [0, 36040], [-42580, 0], [83468, 0], [82790, 0], [0, 8325], [12404, 0], [0, 77597], [0, 13513], [-55520, 0], [94900, 0], [0, -21200], [0, -13459], [0, -87745], [-53120, 0], [-7904, 0], [0, -3003], [0, -3455], [0, 34815], [0, -8448], [-94260, 0], [0, -41985], [-101740, 0], [68362, 0], [0, -2451], [-12980, 0], [0, -6675], [-80504, 0], [0, 23465], [0, -33100], [120264, 0], [-120250, 0], [-29530, 0], [0, -59200], [0, -13600], [129160, 0], [0, 16120], [0, -37341], [0, -37280], [55020, 0], [49870, 0], [70436, 0], [0, -68272], [0, 37205], [65740, 0], [0, 9044], [114482, 0], [0, -82220], [107030, 0], [0, 104125], [0, 80044], [0, -13135], [0, -55960], [0, 120880], [0, 21705], [-15966, 0], [15864, 0], [78552, 0], [126068, 0], [-52680, 0], [136704, 0], [0, -11783], [-138660, 0], [-17570, 0], [0, 71320], [44730, 0], [7190, 0], [-96740, 0], [60084, 0], [0, 83107], [0, 44360], [27340, 0], [0, -94225], [-165450, 0], [0, 35476], [102520, 0], [0, -43625], [3480, 0], [-60552, 0], [0, -17269], [-153316, 0], [0, 97980], [-107116, 0], [-31498, 0], [54090, 0], [-96386, 0], [0, -119908], [0, -75892], [-115180, 0], [0, -117724], [-162780, 0], [0, 72565], [0, -60219], [0, 53460], [-73330, 0], [7646, 0], [0, 106105], [67200, 0], [104498, 0], [-210760, 0], [0, 70689], [-133340, 0], [0, -82360], [0, 72555], [0, -95676], [192650, 0], [229540, 0], [0, -143920], [86990, 0], [0, 86345], [0, 2380], [0, -102560], [-137064, 0], [-28388, 0], [-70430, 0], [0, 83015], [-101076, 0], [-202800, 0], [0, 86220], [-170000, 0], [0, -32675], [-211040, 0], [-90730, 0], [-129360, 0], [0, -130848], [-33668, 0], [-134940, 0], [0, -11916], [-80730, 0], [0, -164580], [258420, 0], [0, 32145], [0, -99945], [0, -15345], [0, -72485], [158152, 0], [32880, 0], [-61504, 0], [0, -87032], [0, -54612], [-183888, 0], [0, 157035], [-224180, 0], [0, 167184], [11120, 0], [0, 148467], [-143200, 0], [0, -162300], [112780, 0], [9960, 0], [0, -36208], [0, -40715], [-143892, 0], [161290, 0], [0, 64977], [-17688, 0], [52160, 0], [0, -35621], [0, 173505], [0, 92324], [137290, 0], [3880, 0], [0, -182040], [0, -133860], [0, -44985], [-300906, 0], [85632, 0], [-194948, 0], [-1760, 0], [0, 90675], [-151740, 0], [0, -67480], [0, 67639], [0, 146552], [-51150, 0], [0, -33115], [-136956, 0], [0, 157700], [0, -81465], [0, -141455], [305568, 0], [81170, 0], [0, -104524], [0, 94140]];
    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_y();".
// 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_y(:prec:=2)
    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_y();".
// 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_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-50, 0, 1]>,<11,R![-40, 1]>,<13,R![-4050, 0, 1]>],Snew);
    return Vf;
end function;