
// Make newform 98.10.c.d in Magma, downloaded from the LMFDB on 14 September 2025.
// 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_d();".
// 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_d();".
// 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 := false)
    N := 98;
    order := 3;
    char_gens := [3];
    char_values := [[0, -1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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, -16], [170, -170], [0, 544], [0, 0], [-48824, 48824], [15876, 0], [-21418, 21418], [0, -716410], [0, 2470000], [5556826, 0], [5799348, -5799348], [0, 3894430], [6360858, 0], [-18701296, 0], [0, 56539068], [59894682, -59894682], [165629662, -165629662], [0, 51419016], [-93546508, 93546508], [-95633536, 0], [306496402, -306496402], [0, -496474152], [371486962, 0], [0, -165482550], [-758016742, 0], [-904211936, 904211936], [0, 1981567796], [0, -416378892], [1269209054, -1269209054], [-2835276218, 0], [5442824592, 0], [0, -644057066], [-1673755474, 1673755474], [4173302294, 0], [0, 464095794], [-7319293288, 7319293288], [-4430498980, 4430498980], [0, 13364528584], [12445637540, 0], [0, 10454418868], [4043907372, -4043907372], [-12473506836, 0], [0, 3819470376], [24119311378, -24119311378], [-12479824306, 0], [-2931272356, 2931272356], [33697816364, 0], [38720841544, 0], [76901138358, -76901138358], [0, 43511409436], [0, 20704302886], [21622018056, 0], [67778873990, -67778873990], [-4878954570, 0], [0, -27502872462], [22259484192, -22259484192], [17301651124, -17301651124], [0, 48190053840], [-80383379222, 80383379222], [-195595414054, 0], [-60280200818, 60280200818], [48674321640, 0], [-275178093862, 0], [112321746616, -112321746616], [0, -106139655722], [0, -2313577062], [0, 216185416336], [50029059726, 0], [184606495536, -184606495536], [-274666259140, 0], [-158053442286, 158053442286], [0, -340759279048], [-610215582184, 610215582184], [0, -434930487214], [-730676728472, 0], [0, 211073768204], [-7218571954, 7218571954], [0, -699386620620], [0, -640643691246], [-13149974290, 13149974290], [579915416766, 0], [166175089110, 0], [-757723233000, 757723233000], [1074848094418, 0], [0, 170418482232], [0, -1229368198820], [-72579192110, 0], [0, 664171699850], [1215008828180, 0], [293877819664, 0], [0, 473112442990], [-2059452977356, 2059452977356], [1222468367968, -1222468367968], [198224577252, 0], [0, 300744658292], [-330194392416, 0], [0, -63239868540], [-1889939538618, 1889939538618], [0, 895863406646], [0, -1002212297862], [2734364299872, 0], [4223585069978, -4223585069978], [-3083105288086, 3083105288086], [0, 274669372986], [-2824990181208, 2824990181208], [3765850120930, -3765850120930], [3008305339102, 0], [0, 3647747944314], [-4177784568600, 4177784568600], [-4844454419882, 0], [0, -1584443386752], [279203366814, -279203366814], [-5555757356602, 0], [-2704365937922, 2704365937922], [-4731577374256, 0], [-1388653484462, 1388653484462], [-3093980738618, 0], [2314526793756, -2314526793756], [0, 810574796046], [457354558208, 0], [7945570983352, -7945570983352], [-8928049414534, 0], [0, -8017304111532], [-4147243603236, 4147243603236], [0, -6055796063242], [1885985371762, 0], [0, 4762099916302], [0, 5348933079684], [-9082221151780, 0], [0, -12054698443944], [-10812835589688, 10812835589688], [6394329934008, 0], [0, 2305799232696], [-6853159775838, 0], [0, -1555197087922], [1311476118050, 0], [-9820099867688, 9820099867688], [-4816584893538, 4816584893538], [-7713435734004, 0], [-21286929478534, 21286929478534], [-24505260902038, 0], [0, 9728256485914], [828744996248, -828744996248], [24284206907004, 0], [19556973814744, -19556973814744], [7695769390876, 0], [2798954335156, 0], [-5561412164754, 5561412164754], [0, 3510516519242], [0, -14383750261768], [0, 6342782203766], [28928223024918, 0], [-7171542612652, 0], [0, -16801965695916], [18792365773812, -18792365773812], [-33949583280240, 0], [0, -10328682089704], [0, -27976677058122], [-33164894568050, 0], [31930911688552, -31930911688552], [0, -35692053942544], [-30492274052854, 0], [-34553250448624, 0], [0, -20670753114594], [-178789067610, 178789067610], [-14265650083116, 14265650083116], [27129633607840, -27129633607840], [-3867234062872, 3867234062872]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_98_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_98_10_c_d();".
// 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_d(:prec:=2)
    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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_98_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![28900, -170, 1]>],Snew);
    return Vf;
end function;