
// Make newform 99.4.d.c in Magma, downloaded from the LMFDB on 11 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_99_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_99_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_99_4_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_99_4_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 := [5776, 0, 5786, 0, 1113, 0, 62, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-42252, 0, -15948, 0, -1018, 0, -17, 0], [-2321, 0, -1059, 0, -95, 0, -2, 0], [4415, 0, -638, 0, -95, 0, -2, 0], [0, -644650, 0, -79265, 0, -2973, 0, -36], [0, 128158, 0, 20605, 0, 1398, 0, 25], [0, 64166, 0, 20605, 0, 1398, 0, 25], [0, 754098, 0, 228591, 0, 13750, 0, 223]];
    Rf_basisdens := [1, 4631, 421, 421, 87989, 31996, 31996, 31996];
    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_99_d();"
function MakeCharacter_99_d()
    N := 99;
    order := 2;
    char_gens := [56, 46];
    v := [1, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_99_d_Hecke();"
function MakeCharacter_99_d_Hecke( : Kf := false)
    N := 99;
    order := 2;
    char_gens := [56, 46];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0]];
    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 := 4;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -5, 0], [0, 0, 0, 0, -2, -1, 0, 0], [0, 0, 5, 0, 0, 0, 12, 1], [0, 0, 0, 0, 2, -8, 0, 0], [0, -22, -2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 10, -5, 0, 0], [0, 0, 0, 0, 0, 0, -30, -10], [0, -30, 10, 0, 0, 0, 0, 0], [-4, 0, 0, -12, 0, 0, 0, 0], [-80, 0, 0, 20, 0, 0, 0, 0], [0, 50, -30, 0, 0, 0, 0, 0], [0, 0, 0, 0, 38, 3, 0, 0], [0, 0, 0, 0, 0, 0, -170, 0], [0, 0, 0, 0, 0, 0, 5, -20], [0, 0, 0, 0, 0, 0, -92, 30], [0, 0, 0, 0, 60, -50, 0, 0], [260, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 254, -20], [0, 0, 0, 0, -154, -82, 0, 0], [0, 0, 0, 0, -170, -55, 0, 0], [0, -68, 60, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -443, 36], [1070, 0, 0, 60, 0, 0, 0, 0], [0, -30, 190, 0, 0, 0, 0, 0], [-940, 0, 0, 0, 0, 0, 0, 0], [0, 396, -60, 0, 0, 0, 0, 0], [0, 0, 0, 0, -190, 20, 0, 0], [0, 0, 0, 0, 0, 0, -185, 60], [0, 0, 0, 0, 46, 211, 0, 0], [0, -320, -410, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 595, -120], [0, 0, 0, 0, 90, 125, 0, 0], [0, 310, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 290, 195, 0, 0], [-970, 0, 0, 0, 0, 0, 0, 0], [160, 0, 0, -220, 0, 0, 0, 0], [0, -196, -510, 0, 0, 0, 0, 0], [0, -314, 246, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -520, 100], [1624, 0, 0, -88, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -746, 192], [0, 0, 0, 0, 428, -272, 0, 0], [0, 22, 482, 0, 0, 0, 0, 0], [-1880, 0, 0, -40, 0, 0, 0, 0], [0, 0, 0, 0, 610, 315, 0, 0], [120, 0, 0, -140, 0, 0, 0, 0], [0, -252, 28, 0, 0, 0, 0, 0], [2310, 0, 0, -20, 0, 0, 0, 0], [0, 298, 410, 0, 0, 0, 0, 0], [0, 620, -210, 0, 0, 0, 0, 0], [0, 0, 0, 0, -810, 70, 0, 0], [0, 0, 0, 0, 0, 0, 2836, -120], [0, 0, 0, 0, 0, 0, 705, 260], [0, -956, -66, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -3073, 40], [0, 0, 0, 0, -50, 745, 0, 0], [0, 0, 0, 0, 538, -136, 0, 0], [0, 1670, -790, 0, 0, 0, 0, 0], [0, 0, 0, 0, 634, -243, 0, 0], [0, 162, 290, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1038, 291, 0, 0], [0, 0, 0, 0, 0, 0, 2926, 30], [360, 0, 0, 220, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1695, 140], [-1984, 0, 0, -12, 0, 0, 0, 0], [0, 0, 0, 0, 426, -394, 0, 0], [0, -988, 612, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1400, -390, 0, 0], [0, 0, 0, 0, 0, 0, 135, 200], [0, -440, 920, 0, 0, 0, 0, 0], [7160, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -556, -1058, 0, 0], [-5080, 0, 0, 60, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -590, 210], [0, 0, 0, 0, 0, 0, 2293, -660], [-2720, 0, 0, 1100, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -9905, 0], [0, 0, 0, 0, -830, 330, 0, 0], [0, 0, 0, 0, 0, 0, 1240, 0], [1544, 0, 0, -768, 0, 0, 0, 0], [0, -1820, 710, 0, 0, 0, 0, 0], [-1480, 0, 0, -1020, 0, 0, 0, 0], [0, 0, 0, 0, 610, 515, 0, 0], [0, 0, 0, 0, 0, 0, 5020, 30], [0, 0, 0, 0, 0, 0, 4577, 196], [0, 0, 0, 0, -1022, 1094, 0, 0], [0, -1410, -2210, 0, 0, 0, 0, 0], [-4020, 0, 0, -560, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -10060, 250], [0, 1100, -1330, 0, 0, 0, 0, 0], [12400, 0, 0, -340, 0, 0, 0, 0], [0, -1420, -3060, 0, 0, 0, 0, 0], [8936, 0, 0, -300, 0, 0, 0, 0], [0, 1964, 994, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 9303, 140], [0, 0, 0, 0, 0, 0, 8075, 100], [0, 0, 0, 0, -434, 1273, 0, 0], [0, 0, 0, 0, 610, -800, 0, 0], [0, 0, 0, 0, 602, -309, 0, 0], [0, 2994, 1770, 0, 0, 0, 0, 0], [0, 848, 2130, 0, 0, 0, 0, 0], [0, -890, -1110, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1710, 5, 0, 0], [-8810, 0, 0, -400, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -560, 570], [0, 3422, -2270, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -4950, 650], [0, 0, 0, 0, -1040, 2360, 0, 0], [0, 0, 0, 0, -1854, 671, 0, 0], [0, 0, 0, 0, -1472, -1142, 0, 0], [0, 0, 0, 0, 0, 0, -1955, 660], [13412, 0, 0, 516, 0, 0, 0, 0], [-1580, 0, 0, -40, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7815, 200], [-17340, 0, 0, 1060, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -530, -150], [0, 0, 0, 0, 0, 0, 4705, -180], [0, -1760, 2850, 0, 0, 0, 0, 0], [10610, 0, 0, -720, 0, 0, 0, 0], [0, 0, 0, 0, 764, 2172, 0, 0], [0, 3194, -1570, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -12460, -380], [-28, 0, 0, -600, 0, 0, 0, 0], [0, -5650, -1610, 0, 0, 0, 0, 0], [2102, 0, 0, -444, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -9442, -716], [3920, 0, 0, 2460, 0, 0, 0, 0], [0, 0, 0, 0, 2546, 988, 0, 0], [0, 0, 0, 0, 3050, 185, 0, 0], [0, -2424, -2584, 0, 0, 0, 0, 0], [3452, 0, 0, 2100, 0, 0, 0, 0], [28120, 0, 0, 680, 0, 0, 0, 0], [0, 2670, -2830, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1940, 2100, 0, 0], [0, 0, 0, 0, 0, 0, -11885, 960], [0, 0, 0, 0, -6046, -581, 0, 0], [0, 0, 0, 0, 0, 0, -11015, -1680], [0, -3050, -1690, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1290, -3615, 0, 0], [0, -8410, 3530, 0, 0, 0, 0, 0], [23400, 0, 0, 1240, 0, 0, 0, 0], [0, -108, 4452, 0, 0, 0, 0, 0], [-5438, 0, 0, 1676, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -2202, 1430], [0, 0, 0, 0, 2664, 262, 0, 0], [0, 1066, 570, 0, 0, 0, 0, 0], [17432, 0, 0, -744, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 5830, -1170], [0, 0, 0, 0, -6996, -1486, 0, 0], [0, 0, 0, 0, 0, 0, -439, -80], [15940, 0, 0, -1180, 0, 0, 0, 0], [0, 7152, 3632, 0, 0, 0, 0, 0], [26580, 0, 0, -1760, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -2390, -1500], [0, 0, 0, 0, -7270, -2695, 0, 0], [0, 0, 0, 0, 0, 0, 11257, 1920], [0, 0, 0, 0, -5004, 456, 0, 0], [0, -3590, 5950, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -8120, 300], [0, 966, -4434, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5354, -2741, 0, 0], [0, 0, 0, 0, 0, 0, 10780, 450], [0, 0, 0, 0, 0, 0, 13935, -580], [0, 0, 0, 0, 0, 0, -8210, 1650], [-20524, 0, 0, -1992, 0, 0, 0, 0], [0, 0, 0, 0, -4464, -2474, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_99_d_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_99_4_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_99_4_d_c(:prec:=8)
    chi := MakeCharacter_99_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_99_4_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_99_4_d_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_99_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![48, 0, -27, 0, 1]>],Snew);
    return Vf;
end function;