
// Make newform 98.10.a.f in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_98_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_98_10_a_f();".
// 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_a_f();".
// 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 := [-106, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 4]];
    Rf_basisdens := [1, 1];
    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_a();"
function MakeCharacter_98_a()
    N := 98;
    order := 1;
    char_gens := [3];
    v := [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_98_a_Hecke(Kf)
    return MakeCharacter_98_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 := 10;
    raw_aps := [[16, 0], [0, 3], [0, -31], [0, 0], [-27644, 0], [0, 2023], [0, -13458], [0, 8341], [-535704, 0], [-2591006, 0], [0, -148054], [-17807910, 0], [0, 741426], [-8759756, 0], [0, 662246], [-83488490, 0], [0, 1980149], [0, 1210325], [-185492924, 0], [370270672, 0], [0, -5973664], [-519907256, 0], [0, -7257663], [0, 7224592], [0, 18957890], [0, 31623077], [0, -52194194], [-834887572, 0], [1025626930, 0], [-465902302, 0], [-784044112, 0], [0, 140196417], [7176724918, 0], [0, -75595065], [6870700150, 0], [9067555720, 0], [0, -81463757], [6579618156, 0], [0, 7830298], [0, -40606793], [8429021124, 0], [0, 491266979], [-17822786808, 0], [15456727922, 0], [20365450758, 0], [0, -672676414], [-13069069900, 0], [0, -1015426972], [0, -1362769727], [0, -109046801], [-64466258858, 0], [-1231980048, 0], [0, -215710534], [0, 2410772063], [0, -1351681712], [-99772693280, 0], [0, -479205661], [0, 1428858064], [-41949460778, 0], [26271632550, 0], [0, -3004111219], [0, 810653529], [0, -5652229303], [0, 185227864], [0, 4119873258], [-86005117122, 0], [359275545572, 0], [-223831133314, 0], [124895327556, 0], [0, -100546425], [0, -4195780908], [-21507908248, 0], [0, 13321089092], [-126024078986, 0], [-53100234444, 0], [0, -15120261810], [-237879210822, 0], [0, 4116924739], [-903545671554, 0], [0, -25377249510], [0, -10137978781], [167897442246, 0], [-160399215040, 0], [0, 1080195970], [0, -13964299968], [-829838424276, 0], [823704668418, 0], [-1598281781734, 0], [0, -30960080949], [-313766001064, 0], [0, 22861308145], [0, 17241305826], [1218629855176, 0], [-57621884052, 0], [2388744323748, 0], [0, 43718092684], [0, -32261367029], [0, -53197975058], [0, -12341066531], [1000146279166, 0], [-3359699357012, 0], [139007524494, 0], [0, -94255255973], [1245597336822, 0], [-2565869398716, 0], [0, 91983179900], [0, -54817406917], [0, -109941042900], [3896235846432, 0], [0, 103753515880], [0, 117550339176], [-6723879736582, 0], [850616519174, 0], [0, -145072319599], [-5969085859056, 0], [-4215583511602, 0], [0, 134378055987], [0, 61168986882], [-7603452301166, 0], [-4452813055444, 0], [0, 129022683037], [-2037782725858, 0], [0, 245002079571], [9290758177868, 0], [0, -166465329439], [2517088879202, 0], [-6592327013798, 0], [0, 19163835954], [0, 113608732510], [0, 179262541385], [-3727774708148, 0], [8630615794488, 0], [17158104530160, 0], [-6697316151062, 0], [0, -74812210378], [0, 7931484022], [0, 476504220573], [0, 356441567009], [0, -230581139397], [14473704057210, 0], [0, 172760551873], [7470184694902, 0], [15848449942240, 0], [2275875911724, 0], [0, -310541379019], [0, 262121544846], [0, -428719279625], [0, -399017873286], [0, 20494703667], [-2462626664184, 0], [3003324960978, 0], [0, -11359678960], [-9282723258380, 0], [0, 242294680926], [-1039955299076, 0], [29279809812080, 0], [-13151890013424, 0], [0, -818191895538], [0, -462711950232], [0, 406568270685], [-23496514029332, 0], [27760693897722, 0], [-17298485022152, 0], [0, -293824552003], [-29968570714706, 0], [0, 18542997350], [-41481100355416, 0], [0, 1236595073437], [-22615655908382, 0], [0, -138093267021], [-52074414142836, 0], [0, 851887555239], [6316610241024, 0], [68792703264438, 0], [0, -759527832214], [0, -476733307148], [-55447188728020, 0], [-36131739817734, 0], [0, -1574727980588], [0, 696092205785], [1771676637408, 0], [0, -241186264697], [-25271225709798, 0], [0, -879396614652], [-18771255412736, 0], [0, -175795386365], [54478930334366, 0], [0, 813878151621], [57101781810646, 0], [0, 450986881726], [0, 2695482505804], [36074270603324, 0], [3849403185956, 0], [0, 103144272543], [-42880000280188, 0], [0, 1711985266148], [57852623493790, 0], [19189220881186, 0], [0, -464489710552], [0, -813430447392], [-2273241692786, 0], [0, 1219178160886], [0, -2774159095319], [0, 568991464408], [0, -2904676964427], [0, -4329225402471], [0, 2481879742430], [-147187897126740, 0], [-66209119333222, 0], [0, 1872745701067], [-177874322029314, 0], [0, -251176043307], [129072354880744, 0], [0, 1328382641877], [0, 3305978191568], [0, -2777057055818], [111745157178472, 0], [0, -592530908610], [60879293552832, 0], [142881589119586, 0], [-5803184069222, 0], [0, 2485115495856], [273959286132930, 0], [-34586272862800, 0], [0, 1519958124573], [61291377736682, 0], [0, -796420632304], [83129775271808, 0], [0, 1863842234412], [303056951352756, 0], [80345582576370, 0], [0, -8077219842073], [301268465467720, 0], [-172223343571574, 0], [0, 2762345616849], [0, 2381620541912], [0, 7308871675046], [347717145191030, 0], [-258704423208964, 0], [0, 719487655460], [99633894044684, 0], [0, -4010871902971], [0, 9770289651748], [-131156320677586, 0], [0, -5881526788536], [0, -9001155602190], [0, -6880280201872], [0, 4345599223101], [179880312279940, 0], [-103110483513448, 0], [-445940389509186, 0], [0, 3534302180756], [-13633392455376, 0], [0, -2927152592224], [0, 3791151253221], [8361072999796, 0], [-325852294223254, 0], [0, 1648025957483], [0, -3110615749731], [0, 1716014745106], [-544920729370480, 0], [-80069511122452, 0], [0, -8962967061227], [0, 387239608161], [0, 15024584714058], [0, -5773406733125], [263871407242830, 0], [0, 1466280705960], [-314356108860484, 0], [-305393529987526, 0], [0, -15870753856065], [176893656559612, 0], [0, 3248438616748], [251062263621616, 0], [0, 472989240472], [0, -444705646892], [-837535441675724, 0], [121218285780766, 0], [746682874459738, 0], [0, 16487202949221], [0, -9318191413556], [347970712570592, 0], [0, 449520399118], [0, 1269089643913], [0, 8267655250817], [792615898973856, 0], [-147341297719918, 0], [-264346022309514, 0], [0, -1159192319842], [0, -19267687113108], [340018364200206, 0], [0, 16040719159685], [-132768808841418, 0], [0, 4702834870181], [-411275075122098, 0], [0, -20311306568669], [0, 28702685787248], [0, 6051039809171], [0, -14303641425237], [0, -10863603056425], [0, -14083401902398], [-767044971769518, 0], [-393253956948392, 0], [-394869175427844, 0], [545606750209716, 0], [-221981238330850, 0], [931851408593860, 0], [0, 21262944256561], [165385515582888, 0], [-154672007708282, 0], [0, 6177847395780], [-147970386404310, 0], [-562175365772322, 0], [-1077323044730500, 0], [675976576992656, 0], [0, -8052117741728], [0, 17975475048923], [-1146339954437672, 0], [0, -9604678443136], [-744614325259474, 0], [0, 14057651449495], [-1209520114053658, 0], [0, -36574294636383], [-826514491589624, 0], [-242428153790726, 0], [0, -10393337370174], [-1746559904318244, 0], [0, 31663421175789], [-620998298026464, 0], [-809437672804262, 0], [1155871869455918, 0], [258871383633666, 0], [0, 41086151528814], [0, 2426677103035], [-2015369157702580, 0], [0, 47351362455061], [-2417361755911646, 0], [0, 12460598828164], [0, -53640677640956], [0, -20356595487882], [415567409620502, 0], [-1990297848557898, 0], [0, -32140853527013], [2608319083628064, 0], [1074548670714658, 0], [-1657972833463812, 0], [0, 33357357100959], [-1674155672527388, 0], [0, 21452889016524], [0, 1138031415525], [0, 45710241636315], [177694875445898, 0], [-382795321504370, 0], [0, -33164751607082], [3008070205328054, 0], [0, -25428645294556], [0, 25320684276570], [0, -5204058484951], [741211505834162, 0], [-577130597215688, 0], [-434689346565178, 0], [0, 6845042824008], [-1421361932346672, 0], [-2886389239437796, 0], [0, -34846323252283], [-535071089824314, 0], [0, 11370132310383], [-2752365580180168, 0], [-118507085782678, 0], [-48104961921276, 0], [0, 56948849655751], [-1673289839638712, 0], [-2009914263242954, 0], [0, 28185298918136], [-1888777707576194, 0], [0, 81858649496501], [2083407575890160, 0], [0, 28066307382256], [0, -92595980661502], [0, 60869030286722], [0, -25205535640233], [497428258402266, 0], [4236957429297504, 0], [-1541661004044638, 0], [0, -105249375458633], [0, -10067345365872], [2125659684197160, 0], [0, 32851995361545], [-843502042234468, 0], [0, -72085716938298], [1332130572212750, 0], [0, 108564231454501], [339849634535116, 0], [0, -94015390513033], [-372351351896392, 0], [3932448893707942, 0], [0, 102430994249034], [0, 17853401464542], [-376504252541380, 0], [-3958467805795350, 0], [0, 78492727837801], [-1709304650756158, 0], [62979666096920, 0], [0, -60506443958222], [0, 5363084053575], [0, 2470496560606], [2023523251591246, 0], [-4629403178896158, 0], [0, -17901166767005], [0, -51197148047349], [0, 90451422739864], [-669196031022198, 0], [-5529603748597724, 0], [-5483406211799132, 0], [-3085566977818218, 0], [0, -1909543614513], [3443611004596440, 0], [0, 97986600394910], [0, -53463269106422], [0, 42543567909420], [3311516613703234, 0], [0, 87650714294693], [443979286402584, 0], [0, 161250670573167], [0, -9772193829286], [0, -55803683761655], [-2869491217371108, 0], [1253922198624678, 0], [0, 99991466468855], [0, 54651388343954]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_98_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_98_10_a_f();".
// 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_a_f(:prec:=2)
    chi := MakeCharacter_98_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_98_10_a_f();".
// 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_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_98_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-15264, 0, 1]>],Snew);
    return Vf;
end function;