
// Make newform 98.10.c.i in Magma, downloaded from the LMFDB on 01 June 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_10_c_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_98_10_c_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
        poly := [1849, 0, 43, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 8, 0, 0], [0, 0, 1, 0], [0, 0, 0, 8]];
    Rf_basisdens := [1, 1, 43, 43];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0, 1, 0]];
    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]];
    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 := 10;
    raw_aps := [[0, 0, -16, 0], [0, 1, 0, 0], [0, -35, 0, -35], [0, 0, 0, 0], [-9380, 0, -9380, 0], [0, 0, 0, 3413], [0, 1866, 0, 0], [0, -10727, 0, -10727], [0, 0, -978936, 0], [-4317214, 0, 0, 0], [0, 152014, 0, 0], [0, 0, 2714394, 0], [0, 0, 0, 171606], [-34755692, 0, 0, 0], [0, -804002, 0, -804002], [-68067926, 0, -68067926, 0], [0, -652537, 0, 0], [0, 3161153, 0, 3161153], [-242944420, 0, -242944420, 0], [-94292464, 0, 0, 0], [0, 2541664, 0, 0], [0, 0, 677625160, 0], [0, 0, 0, 8412459], [0, -10584880, 0, -10584880], [0, 0, 0, -24189050], [0, 26082959, 0, 0], [0, 3662854, 0, 3662854], [0, 0, -1048549940, 0], [-2037576178, 0, -2037576178, 0], [-470998718, 0, 0, 0], [2875981904, 0, 0, 0], [0, -113822379, 0, -113822379], [1397099338, 0, 1397099338, 0], [0, 0, 0, 151846989], [0, 0, -11026047754, 0], [3944737688, 0, 3944737688, 0], [0, 128926457, 0, 0], [0, 0, -2944734132, 0], [0, 0, 0, -303212450], [0, -196911109, 0, -196911109], [-10802531748, 0, -10802531748, 0], [0, 0, 0, 117031657], [0, 0, -9387113016, 0], [-9064087634, 0, -9064087634, 0], [-7311024186, 0, 0, 0], [0, -28793642, 0, 0], [-18914721004, 0, 0, 0], [0, 0, 0, -1024384628], [0, -124159541, 0, 0], [0, 397548115, 0, 397548115], [0, 0, 19155851990, 0], [-25864759344, 0, 0, 0], [0, 613436206, 0, 0], [0, 0, 0, -461841355], [0, -679649200, 0, -679649200], [119368973920, 0, 119368973920, 0], [0, -2012604343, 0, 0], [0, -1201932848, 0, -1201932848], [88295272490, 0, 88295272490, 0], [-14221587162, 0, 0, 0], [0, 2748619759, 0, 0], [0, 0, 0, -1409018901], [0, 0, 0, 2129938627], [0, -4213521272, 0, 0], [0, 2051612802, 0, 2051612802], [0, 0, -325634388354, 0], [0, 0, -169544526268, 0], [-126756308770, 0, 0, 0], [179107727580, 0, 179107727580, 0], [0, 0, 0, -3314480043], [0, -1722277188, 0, 0], [0, 0, -183949685240, 0], [0, -6887452436, 0, 0], [0, 0, 162420555766, 0], [-10783189356, 0, 0, 0], [0, -13302770010, 0, -13302770010], [598959409158, 0, 598959409158, 0], [0, 7017970615, 0, 7017970615], [0, 0, 111219062814, 0], [0, -8433766194, 0, 0], [0, 0, 0, 14392000673], [431285177670, 0, 0, 0], [-1013751491296, 0, -1013751491296, 0], [0, 0, 0, 11494019270], [0, -8659730112, 0, -8659730112], [0, 0, 1008887291724, 0], [15107012610, 0, 0, 0], [0, 0, -1033797235078, 0], [0, 0, 0, -11745787359], [887424857624, 0, 0, 0], [0, 33597003365, 0, 33597003365], [0, -2386853514, 0, 0], [-1919069226472, 0, -1919069226472, 0], [-1298013748596, 0, 0, 0], [0, 0, -426075730620, 0], [0, 0, 0, -33489029756], [0, -49377931489, 0, -49377931489], [0, -18369010166, 0, 0], [0, -11970943295, 0, -11970943295], [0, 0, -3115729658882, 0], [1737655288972, 0, 0, 0], [4384264938162, 0, 4384264938162, 0], [0, 49662845161, 0, 0], [0, 0, -1020516137706, 0], [-302031918372, 0, -302031918372, 0], [0, -13793166668, 0, 0], [0, 0, 0, 80329026953], [0, 107183492796, 0, 107183492796], [-765733610784, 0, -765733610784, 0], [0, 0, 0, -18369026632], [0, -43556364984, 0, -43556364984], [-1194594009722, 0, -1194594009722, 0], [-3405744729626, 0, 0, 0], [0, -308104229, 0, 0], [-4727350470768, 0, 0, 0], [1834696742930, 0, 1834696742930, 0], [0, 0, 0, 57343764849], [0, -97285787754, 0, 0], [0, 0, 4123416186002, 0], [-7146118477172, 0, 0, 0], [0, 143656930871, 0, 0], [2712808583966, 0, 0, 0], [0, 32054777031, 0, 32054777031], [-3579368635564, 0, -3579368635564, 0], [0, 80320265717, 0, 80320265717], [-6323823163934, 0, 0, 0], [0, 0, -8013204686054, 0], [0, -35226733350, 0, -35226733350], [0, 0, 0, 182042824010], [0, 46755777317, 0, 46755777317], [-10331390498092, 0, -10331390498092, 0], [2900977466712, 0, 0, 0], [0, 0, 1755322278672, 0], [12883493919466, 0, 0, 0], [0, 37581117790, 0, 37581117790], [0, 0, 0, 160957020770], [0, 243854705943, 0, 0], [0, 279898168939, 0, 0], [0, 0, 0, -258265084527], [14323047880614, 0, 14323047880614, 0], [0, 0, 0, -399709403221], [0, 0, -14533780835338, 0], [-18353198394784, 0, -18353198394784, 0], [-778350465012, 0, 0, 0], [0, -186718889441, 0, 0], [0, 0, 0, 45558557466], [0, 0, 0, 259923850373], [0, 62330447790, 0, 0], [0, -3742615569, 0, -3742615569], [0, 0, -9033510097464, 0], [0, 0, 7053130540818, 0], [0, 0, 0, 642205455344], [23689132148884, 0, 0, 0], [0, 417455907510, 0, 417455907510], [-14179712007196, 0, -14179712007196, 0], [-5445669812528, 0, 0, 0], [0, 0, 27558337495248, 0], [0, 193995542550, 0, 193995542550], [0, 0, 0, -375206004168], [0, -144117520521, 0, 0], [0, 0, 24237014007884, 0], [26941124348154, 0, 0, 0], [21351312434008, 0, 0, 0], [0, -11840588639, 0, -11840588639], [21287974209106, 0, 21287974209106, 0], [0, 107832513506, 0, 0], [18245753854168, 0, 18245753854168, 0], [0, -184392679657, 0, 0]];
    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_10_c_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_98_10_c_i(:prec:=4)
    chi := MakeCharacter_98_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_c_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_98_10_c_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_98_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![7573504, 0, 2752, 0, 1]>],Snew);
    return Vf;
end function;