
// Make newform 98.8.c.b in Magma, downloaded from the LMFDB on 05 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_98_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_98_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_98_8_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_98_8_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 := [1, -1, 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_98_c();"
function MakeCharacter_98_c()
    N := 98;
    order := 3;
    char_gens := [3];
    v := [2];
    // 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_98_c_Hecke();"
function MakeCharacter_98_c_Hecke(Kf)
    N := 98;
    order := 3;
    char_gens := [3];
    char_values := [[0, -1]];
    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 := 8;
    raw_aps := [[0, -8], [66, -66], [0, 400], [0, 0], [-40, 40], [-4452, 0], [-36502, 36502], [0, 46222], [0, 105200], [-126334, 0], [170964, -170964], [0, -20954], [318486, 0], [77744, 0], [0, -703716], [-1603278, 1603278], [1171894, -1171894], [0, 2068872], [994268, -994268], [33280, 0], [2971454, -2971454], [0, 2376168], [-2122358, 0], [0, -6920346], [4952710, 0], [-3230000, 3230000], [0, 1799092], [0, 15642876], [6318902, -6318902], [-10228762, 0], [6007248, 0], [0, -20639618], [-4761986, 4761986], [-5057234, 0], [0, 27273642], [-6489208, 6489208], [63081028, -63081028], [0, -83227112], [30691556, 0], [0, 52733836], [-84273852, 84273852], [-103956300, 0], [0, 124775256], [-147588782, 147588782], [155811574, 0], [13319260, -13319260], [-204939964, 0], [-68485816, 0], [19362654, -19362654], [0, -308156764], [0, -35579722], [-230056104, 0], [-5034950, 5034950], [-103282578, 0], [0, 232282254], [-416748960, 416748960], [314678668, -314678668], [0, -192136944], [440393410, -440393410], [359234794, 0], [81146726, -81146726], [253416072, 0], [872705554, 0], [671611384, -671611384], [0, 192216410], [0, 133837218], [0, -425298128], [1077025518, 0], [723763728, -723763728], [-448132412, 0], [1499455086, -1499455086], [0, 256889896], [-650424296, 650424296], [0, 466127498], [285859576, 0], [0, 1650749612], [-1513041962, 1513041962], [0, 863794380], [0, -114041742], [1183278274, -1183278274], [227959494, 0], [-39070050, 0], [2586200136, -2586200136], [-1788926482, 0], [0, 458904888], [0, -1384588684], [-2736106798, 0], [0, -2430532870], [3948844172, 0], [2574529456, 0], [0, -298482218], [-2620001836, 2620001836], [4166618752, -4166618752], [2412999948, 0], [0, 1040918876], [-1172730720, 0], [0, 81381756], [2774584074, -2774584074], [0, -4992130226], [0, -1630951038], [2009498976, 0], [4479586498, -4479586498], [1507303010, -1507303010], [0, -2330877174], [2911013688, -2911013688], [8648050526, -8648050526], [-6335131754, 0], [0, 1701620838], [-3019770024, 3019770024], [-5927081734, 0], [0, 1456492416], [6716071014, -6716071014], [7020270742, 0], [-5143517194, 5143517194], [-4415735056, 0], [-694175662, 694175662], [9508087022, 0], [7732150044, -7732150044], [0, 5063212326], [8081130304, 0], [-6300892840, 6300892840], [-9626240902, 0], [0, 9454287564], [-248879244, 248879244], [0, 3464118526], [5563217018, 0], [0, -8236965866], [0, -5852120028], [15170608348, 0], [0, 15596918520], [6955729944, -6955729944], [-11780290968, 0], [0, 6962001960], [-20711388486, 0], [0, -16539242782], [-23365045634, 0], [-7092628232, 7092628232], [12302989254, -12302989254], [-3666498444, 0], [29660925226, -29660925226], [25127795602, 0], [0, -4577720206], [-1931326360, 1931326360], [15809448468, 0], [2465355896, -2465355896], [25186129948, 0], [10730560652, 0], [27933158466, -27933158466], [0, 19498261714], [0, 16355068552], [0, -26887351186], [10891847946, 0], [-39954189700, 0], [0, -13030553388], [-40401450948, 40401450948], [19891905168, 0], [0, 41099018216], [0, 19037392746], [39383049314, 0], [15918631144, -15918631144], [0, -3572371568], [4051007578, 0], [25579109264, 0], [0, -41032282794], [-48727686138, 48727686138], [6947617428, -6947617428], [18356454496, -18356454496], [-34495366616, 34495366616]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_98_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_98_8_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_98_8_c_b(:prec:=2)
    chi := MakeCharacter_98_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_98_8_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_98_8_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_98_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![4356, -66, 1]>],Snew);
    return Vf;
end function;