
// Make newform 98.5.d.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_98_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_98_d_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_5_d_c();".
// 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_5_d_c();".
// 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 := [4, 0, -8, 0, 14, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [20, 0, 0, 0, 0, 0, 1, 0], [0, 34, 0, 0, 0, 0, 0, 1], [2, 0, -28, 0, 7, 0, -2, 0], [0, 16, 0, -28, 0, 7, 0, -2], [2, 0, -21, 0, 7, 0, -2, 0], [0, 6, 0, -70, 0, 21, 0, -6]];
    Rf_basisdens := [1, 1, 14, 14, 14, 14, 7, 14];
    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_d();"
function MakeCharacter_98_d()
    N := 98;
    order := 6;
    char_gens := [3];
    v := [5];
    // 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_d_Hecke();"
function MakeCharacter_98_d_Hecke(Kf)
    N := 98;
    order := 6;
    char_gens := [3];
    char_values := [[0, 0, 0, 0, -1, 0, 0, 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+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 := 5;
    raw_aps := [[0, 0, 0, 0, 0, 0, -2, 0], [0, 4, 0, 7, 0, 0, 0, 0], [0, 0, 0, 13, 0, 5, 0, 13], [0, 0, 0, 0, 0, 0, 0, 0], [-6, 0, 103, 0, -6, 0, 103, 0], [0, -101, 0, 0, 0, 101, 0, -97], [0, -282, 0, -177, 0, 0, 0, 0], [0, 0, 0, 10, 0, -207, 0, 10], [0, 0, 0, 0, 26, 0, 144, 0], [-352, 0, -22, 0, 0, 0, 0, 0], [0, -698, 0, 74, 0, 0, 0, 0], [0, 0, 0, 0, -848, 0, -36, 0], [0, -251, 0, 0, 0, 251, 0, -460], [-506, 0, 1175, 0, 0, 0, 0, 0], [0, 0, 0, -1418, 0, 1732, 0, -1418], [4170, 0, 706, 0, 4170, 0, 706, 0], [0, 1379, 0, -2820, 0, 0, 0, 0], [0, 0, 0, 365, 0, 1523, 0, 365], [5204, 0, 786, 0, 5204, 0, 786, 0], [-496, 0, 1244, 0, 0, 0, 0, 0], [0, -1385, 0, 2736, 0, 0, 0, 0], [0, 0, 0, 0, -7404, 0, -2270, 0], [0, 4703, 0, 0, 0, -4703, 0, -1164], [0, 0, 0, 3746, 0, -3573, 0, 3746], [0, -5324, 0, 0, 0, 5324, 0, -141], [0, 13, 0, -2671, 0, 0, 0, 0], [0, 0, 0, -8248, 0, -4772, 0, -8248], [0, 0, 0, 0, -1018, 0, -5276, 0], [-17612, 0, 4196, 0, -17612, 0, 4196, 0], [19688, 0, -3, 0, 0, 0, 0, 0], [-20258, 0, -5450, 0, 0, 0, 0, 0], [0, 0, 0, -3157, 0, 9150, 0, -3157], [8588, 0, 8695, 0, 8588, 0, 8695, 0], [0, -1176, 0, 0, 0, 1176, 0, 1407], [0, 0, 0, 0, 14150, 0, 10878, 0], [8446, 0, -24202, 0, 8446, 0, -24202, 0], [0, -18709, 0, -6121, 0, 0, 0, 0], [0, 0, 0, 0, -16194, 0, 7079, 0], [0, 24092, 0, 0, 0, -24092, 0, -11274], [0, 0, 0, -13101, 0, -11365, 0, -13101], [19306, 0, -10280, 0, 19306, 0, -10280, 0], [0, -29875, 0, 0, 0, 29875, 0, 6673], [0, 0, 0, 0, 20464, 0, 2016, 0], [-36224, 0, -16235, 0, -36224, 0, -16235, 0], [-27770, 0, -23428, 0, 0, 0, 0, 0], [0, -11832, 0, 26612, 0, 0, 0, 0], [-27560, 0, 34994, 0, 0, 0, 0, 0], [0, 10604, 0, 0, 0, -10604, 0, -30438], [0, 2824, 0, 22521, 0, 0, 0, 0], [0, 0, 0, -6785, 0, -20865, 0, -6785], [0, 0, 0, 0, 25972, 0, -19917, 0], [55054, 0, 18306, 0, 0, 0, 0, 0], [0, -54485, 0, -712, 0, 0, 0, 0], [0, -43914, 0, 0, 0, 43914, 0, -1105], [0, 0, 0, 45577, 0, -21048, 0, 45577], [-15448, 0, 16826, 0, -15448, 0, 16826, 0], [0, 12825, 0, 44435, 0, 0, 0, 0], [0, 0, 0, -4702, 0, 18060, 0, -4702], [79330, 0, -9246, 0, 79330, 0, -9246, 0], [29664, 0, 6005, 0, 0, 0, 0, 0], [0, 1111, 0, -60118, 0, 0, 0, 0], [0, -2747, 0, 0, 0, 2747, 0, 41623], [0, 32870, 0, 0, 0, -32870, 0, 12099], [0, 44124, 0, -7096, 0, 0, 0, 0], [0, 0, 0, 10920, 0, 22471, 0, 10920], [0, 0, 0, 0, -38730, 0, -48038, 0], [0, 0, 0, 0, 137678, 0, -20729, 0], [101536, 0, 60394, 0, 0, 0, 0, 0], [26578, 0, 25915, 0, 26578, 0, 25915, 0], [0, 27209, 0, 0, 0, -27209, 0, 61929], [0, 11973, 0, -82486, 0, 0, 0, 0], [0, 0, 0, 0, -19950, 0, 86472, 0], [0, -85092, 0, 26930, 0, 0, 0, 0], [0, 0, 0, 0, 37910, 0, 42130, 0], [29554, 0, -67631, 0, 0, 0, 0, 0], [0, 0, 0, -56048, 0, -137630, 0, -56048], [91580, 0, 37066, 0, 91580, 0, 37066, 0], [0, 0, 0, 169061, 0, -36331, 0, 169061], [0, 0, 0, 0, 52902, 0, -113666, 0], [0, -32698, 0, -32421, 0, 0, 0, 0], [0, -54263, 0, 0, 0, 54263, 0, -202102], [104338, 0, -2014, 0, 0, 0, 0, 0], [-174878, 0, -38834, 0, -174878, 0, -38834, 0], [0, 72750, 0, 0, 0, -72750, 0, -31705], [0, 0, 0, 230168, 0, -95322, 0, 230168], [0, 0, 0, 0, 44708, 0, -170430, 0], [-132332, 0, 148388, 0, 0, 0, 0, 0], [0, 0, 0, 0, -43876, 0, 165285, 0], [0, -157127, 0, 0, 0, 157127, 0, -93551], [-48696, 0, -138290, 0, 0, 0, 0, 0], [0, 0, 0, -188838, 0, 67043, 0, -188838], [0, -62764, 0, 51364, 0, 0, 0, 0], [24222, 0, -92918, 0, 24222, 0, -92918, 0], [-39408, 0, -54418, 0, 0, 0, 0, 0], [0, 0, 0, 0, 305364, 0, 97258, 0], [0, 74648, 0, 0, 0, -74648, 0, -6398], [0, 0, 0, -769, 0, 123071, 0, -769], [0, 130366, 0, -131343, 0, 0, 0, 0], [0, 0, 0, 1781, 0, -33310, 0, 1781], [0, 0, 0, 0, 231206, 0, -14140, 0], [50398, 0, 144129, 0, 0, 0, 0, 0], [214506, 0, -184304, 0, 214506, 0, -184304, 0], [0, 48658, 0, 169063, 0, 0, 0, 0], [0, 0, 0, 0, -130752, 0, -32134, 0], [43714, 0, 93913, 0, 43714, 0, 93913, 0], [0, 100290, 0, -164319, 0, 0, 0, 0], [0, -95760, 0, 0, 0, 95760, 0, 149569], [0, 0, 0, -72736, 0, -4385, 0, -72736], [-322456, 0, 170822, 0, -322456, 0, 170822, 0], [0, -74310, 0, 0, 0, 74310, 0, -154605], [0, 0, 0, -13272, 0, -315440, 0, -13272], [11760, 0, 208428, 0, 11760, 0, 208428, 0], [370038, 0, 86174, 0, 0, 0, 0, 0], [0, 4092, 0, -64057, 0, 0, 0, 0], [377132, 0, -215184, 0, 0, 0, 0, 0], [39840, 0, 507670, 0, 39840, 0, 507670, 0], [0, -92050, 0, 0, 0, 92050, 0, -229215], [0, -44638, 0, -97630, 0, 0, 0, 0], [0, 0, 0, 0, -473032, 0, -17366, 0], [193098, 0, -276169, 0, 0, 0, 0, 0], [0, 48973, 0, -382033, 0, 0, 0, 0], [-364168, 0, -28543, 0, 0, 0, 0, 0], [0, 0, 0, 169263, 0, -132731, 0, 169263], [36372, 0, 94566, 0, 36372, 0, 94566, 0], [0, 0, 0, -72711, 0, 395866, 0, -72711], [-360084, 0, -90200, 0, 0, 0, 0, 0], [0, 0, 0, 0, -117940, 0, -190204, 0], [0, 0, 0, 223274, 0, -292908, 0, 223274], [0, 492700, 0, 0, 0, -492700, 0, -283826], [0, 0, 0, 134431, 0, 201323, 0, 134431], [-24442, 0, 43659, 0, -24442, 0, 43659, 0], [-644330, 0, -132152, 0, 0, 0, 0, 0], [0, 0, 0, 0, -416270, 0, 116794, 0], [-12164, 0, -290080, 0, 0, 0, 0, 0], [0, 0, 0, 176181, 0, -102352, 0, 176181], [0, -320103, 0, 0, 0, 320103, 0, 356524], [0, -189705, 0, 210991, 0, 0, 0, 0], [0, 479771, 0, 315642, 0, 0, 0, 0], [0, 21579, 0, 0, 0, -21579, 0, 312231], [-305328, 0, 252573, 0, -305328, 0, 252573, 0], [0, -458033, 0, 0, 0, 458033, 0, 340042], [0, 0, 0, 0, 469666, 0, -226888, 0], [-91308, 0, -882298, 0, -91308, 0, -882298, 0], [131562, 0, -183032, 0, 0, 0, 0, 0], [0, -160133, 0, 307485, 0, 0, 0, 0], [0, 16214, 0, 0, 0, -16214, 0, 305582], [0, -396741, 0, 0, 0, 396741, 0, -572023], [0, -445219, 0, -519774, 0, 0, 0, 0], [0, 0, 0, 375696, 0, 376521, 0, 375696], [0, 0, 0, 0, -802088, 0, 57030, 0], [0, 0, 0, 0, -656200, 0, -42998, 0], [0, -95006, 0, 0, 0, 95006, 0, -82177], [-48534, 0, -168332, 0, 0, 0, 0, 0], [0, 0, 0, -230044, 0, -538826, 0, -230044], [752094, 0, 66804, 0, 752094, 0, 66804, 0], [746666, 0, -409874, 0, 0, 0, 0, 0], [0, 0, 0, 0, 442860, 0, 480246, 0], [0, 0, 0, 726513, 0, 110018, 0, 726513], [0, 1587, 0, 0, 0, -1587, 0, 144392], [0, -427557, 0, 501055, 0, 0, 0, 0], [0, 0, 0, 0, 711406, 0, 310737, 0], [465040, 0, -308, 0, 0, 0, 0, 0], [-697218, 0, 564636, 0, 0, 0, 0, 0], [0, 0, 0, 228124, 0, -124435, 0, 228124], [455004, 0, -846359, 0, 455004, 0, -846359, 0], [0, 340198, 0, -457242, 0, 0, 0, 0], [-925440, 0, 242606, 0, -925440, 0, 242606, 0], [0, 262969, 0, 632157, 0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_98_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_98_5_d_c();".
// 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_5_d_c(:prec:=8)
    chi := MakeCharacter_98_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_5_d_c();".
// 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_5_d_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_98_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<3,R![1119364, 0, -275080, 0, 66542, 0, -260, 0, 1]>],Snew);
    return Vf;
end function;