
// Make newform 9800.2.a.ct in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9800_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_9800_2_a_ct();".
// 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_9800_2_a_ct();".
// 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, 2, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-4, -1, 1, 0], [1, -7, -1, 1]];
    Rf_basisdens := [1, 1, 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_9800_a();"
function MakeCharacter_9800_a()
    N := 9800;
    order := 1;
    char_gens := [7351, 4901, 1177, 5001];
    v := [1, 1, 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;

function MakeCharacter_9800_a_Hecke(Kf)
    return MakeCharacter_9800_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 := 2;
    raw_aps := [[0, 0, 0, 0], [1, -1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, -1, 1], [-2, 0, -1, -1], [-2, -1, 0, -1], [-4, 0, -1, -2], [1, 2, 0, 3], [2, 0, 1, 2], [-3, 0, 1, 0], [0, 2, 1, 1], [-3, 2, 0, -3], [3, 1, 1, -2], [-4, 3, 1, 0], [-2, 0, 0, 1], [-1, 3, 0, 0], [-5, 1, 0, 3], [0, 4, 2, 2], [-5, -4, 0, -2], [0, -2, -2, 2], [-1, 0, 0, -3], [6, 0, 1, -2], [-4, 3, 1, 2], [-1, -2, -1, 1], [-3, -3, 0, -3], [5, 2, 1, 3], [5, 1, -1, 0], [0, 6, -1, 1], [3, -2, -1, -4], [-9, -3, 1, 0], [-7, -5, 0, -3], [-3, 4, -2, -3], [6, -6, 1, 1], [-4, -2, -3, 0], [14, -2, 1, 2], [-9, -1, 0, 2], [-12, 2, -2, -3], [-6, 0, -5, -1], [1, -1, 0, -7], [2, 0, 4, -2], [4, 6, 1, 6], [-5, 0, -4, -4], [1, 4, 2, 3], [-5, 9, 2, 0], [-4, 5, -1, 4], [3, -1, 4, 3], [-3, -2, -1, 1], [7, -3, -2, 1], [-15, 1, 0, -4], [-1, -3, -1, 1], [-6, 11, 2, 3], [-7, -3, -3, 0], [-1, -1, 2, 3], [-12, -6, 0, -2], [5, 4, 3, -1], [3, -5, 1, 5], [-16, -5, 3, 0], [5, 9, 2, 4], [-6, -9, 3, 1], [11, 7, 0, 2], [0, 0, 6, 3], [15, -3, 3, 6], [-16, 3, 3, 1], [8, 3, 0, 0], [-5, 3, 3, 3], [3, -3, 3, 3], [-5, -6, 1, 4], [11, -5, 0, 4], [-6, 0, 2, 7], [7, -6, -3, 2], [7, 7, 0, 5], [11, 3, 0, 1], [-5, -13, 2, -9], [-15, -1, 2, -5], [-4, -1, -6, -4], [5, 3, 3, -4], [0, 0, 6, -5], [11, -1, -2, -6], [-25, -2, 2, 0], [8, 4, 3, 0], [-17, 1, 0, 4], [10, -1, 0, -10], [-2, 3, -4, 1], [5, -4, -4, 1], [3, -5, 0, 1], [-5, -6, -6, -6], [4, -4, 2, -9], [-3, -11, 0, -5], [0, -9, 3, -7], [3, -3, -2, 11], [2, 3, 0, -12], [8, -5, -2, 5], [-20, 0, -6, -6], [-7, -1, 1, -9], [4, 8, -3, 2], [-10, 0, -2, -8], [14, 1, 5, 11], [7, 5, -3, -5], [-2, 8, 0, -5], [-3, -9, 2, 2], [-1, -9, -5, -6], [25, 1, -3, 1], [4, 11, 2, 5], [3, -7, 0, -2], [-7, 15, 2, 13], [20, 0, 4, -7], [4, 15, 5, 11], [-18, -3, -5, -13], [5, 9, -1, 2], [-8, -9, 2, -7], [16, -14, -1, -2], [19, -6, -1, 6], [-15, 11, 1, 11], [1, 4, 7, -6], [-11, 4, -1, 14], [-15, -5, -1, -11], [-14, 0, -6, -3], [6, -4, 2, 1], [-7, 5, 2, 10], [6, -8, -2, 4], [15, -2, 1, -5], [-18, 0, -3, 6], [4, -12, 2, -9], [-8, 12, 1, 11], [0, 4, 7, 6], [-21, -5, -2, -12], [11, -10, 3, -4], [4, -1, -4, -8], [15, -3, -4, 7], [-5, 3, -3, -7], [-1, -2, -1, 7], [-5, -7, -2, 8], [0, -12, -3, -12], [3, 2, 2, 0], [-23, -1, -4, -1], [-9, 1, 1, -2], [29, 3, 1, 0], [-7, 9, -4, 4], [10, -8, 1, 12], [-15, -9, -5, -10], [39, 7, 4, 11], [-3, -3, -4, 3], [-7, -9, 0, -11], [-30, 14, 4, 1], [2, 23, 1, 15], [2, 0, 5, 7], [-17, -5, 3, 2], [-6, 6, 1, -3], [6, -7, -3, -6], [-24, 2, -4, -10], [-17, 10, -1, 1], [24, -16, -3, -3], [15, 9, 3, 10], [-23, 7, -1, 1], [0, -1, -1, 6], [-9, 16, 1, -2], [21, -3, 2, 6], [0, 6, -1, 10], [22, -8, -3, 5], [6, -2, -4, 2], [-1, 7, -5, 4], [2, -9, 0, 9], [25, 7, 1, 3], [28, -5, 0, 0], [9, -9, 0, -2], [-3, 4, -6, -2], [4, -6, -2, 3], [-2, 7, 1, -10], [-10, 2, -1, -2], [19, -7, 4, 9], [-17, 1, -8, -4], [1, -7, 0, -3], [11, 14, 1, 6], [-4, 1, -4, -7], [17, -8, 2, -1], [12, -8, -8, -3], [-7, 1, 8, -4], [-11, 15, 4, 10], [20, -2, 8, 4], [31, 1, 2, 4], [-11, -1, -3, 1], [-12, 2, -10, 2], [-10, -6, 1, -7], [-2, -1, -2, -9], [-15, 1, 2, -2], [-13, 11, 5, 0], [5, -15, -3, -4], [-17, 4, 1, 5], [-4, 2, 0, -15], [-27, -5, -12, -13], [9, -7, 8, 7], [-23, -15, -7, -14], [-9, 3, -1, 4], [-16, 10, -4, 0], [12, 0, 12, 5], [-9, -19, -4, -17], [-18, 0, -10, 2], [-31, 9, 2, -6], [-13, -21, 5, 3], [-20, 2, -11, 3], [-8, 9, 4, 17], [-5, 5, 3, -11], [-27, 0, 1, -9], [2, -16, -8, -10], [-26, -8, -9, -17], [15, 14, 5, 1], [1, -9, 9, 1], [-3, 18, 6, 10], [9, 9, 4, 22], [-7, 2, 3, 2], [23, 19, -1, 13], [-10, -5, 3, 6], [-13, 11, -4, -21], [31, -10, -1, 5], [11, -16, -10, -1], [-19, 10, -2, -4], [-1, 21, 0, 5], [-18, 0, -2, -19], [-1, -17, 8, -1], [-36, 0, 2, -7], [-14, -1, -3, -9], [10, 11, 10, -4], [21, 0, -7, 6], [34, -10, -4, 1], [25, 21, -6, 5], [-18, 17, 2, -1], [-34, 5, -7, -7], [13, 6, -2, 2], [0, -14, 1, -13], [10, -4, 2, -19], [-5, -7, -2, 17], [29, -16, -3, 8], [-8, -3, -11, -3], [10, 6, 1, 8], [1, -6, 8, -3], [-8, -18, -1, -6], [40, -8, 0, 5], [-5, -3, 10, -2], [-3, -4, -4, -8], [-3, 11, 2, 20], [38, 2, 1, -9], [-21, -19, 7, -10], [-19, -1, 4, 9], [-30, 3, -4, 2], [12, 9, -9, 4], [17, 2, 1, 20], [5, 7, -4, -13], [29, -3, -3, 5], [-47, -4, -4, 3], [-21, 15, -4, -1], [6, -18, -12, -7], [12, 9, 15, 11], [-36, -4, -4, -1], [-9, -7, -5, 12], [-3, 11, 2, -16], [-6, 10, -9, 8], [24, -2, -7, 3], [-4, 2, 6, 8], [16, 11, 6, 22], [22, 6, -5, 6], [14, -2, -9, -3], [-26, -10, -4, -3], [-21, 5, -2, -14], [7, -8, 0, -4], [-27, 3, -5, 11], [-11, -1, 4, -19], [-20, -12, -11, -13], [63, 5, -1, 5], [-9, 11, -6, 16], [30, 14, -5, 9], [-3, -11, -4, -8], [-11, 2, 17, -3], [-10, -9, -8, 11], [27, 7, -6, -6], [-22, -5, -1, 19], [-14, 14, 4, 3], [-7, 7, 8, -11], [1, -6, 6, 12], [47, 3, -3, 4], [-13, -14, 2, 3], [-3, 6, -1, 2], [-7, -22, -4, -11], [19, -13, -5, 6], [17, 15, -4, 10], [9, -26, 1, 7], [11, 4, -1, -2], [49, 7, 12, 21], [-26, 2, -10, 0], [44, -1, 4, 20], [-25, -11, 7, -4], [7, -3, -8, -4], [7, 8, 1, 1], [41, -5, -4, -4], [5, -7, 7, -13], [47, -9, 1, 6], [-21, 3, -13, 15], [-14, -34, 1, -22], [-30, 16, 0, 3], [26, 8, -11, -1], [-35, 14, 8, 4], [-30, 2, -4, 9], [47, -14, 0, -3], [-5, -1, -5, -24], [8, -20, 3, -2], [-3, 8, 6, -15], [-32, 2, -4, 6], [3, -7, 7, -12], [-38, 18, -1, -14], [2, -6, 1, 21], [-20, 19, 8, -7], [-9, 15, 1, 24], [-25, 13, -5, -11], [-29, -17, -4, -10], [-28, 1, -16, -8], [-44, 8, -5, -19], [-3, 9, -1, 24], [-3, -20, -14, -13], [33, 2, 3, -7], [-9, -2, -3, 9], [1, 5, -15, -2], [18, -2, 8, 11], [-13, 23, 6, 0], [-60, -6, -8, -15], [2, -3, 10, 10], [8, -4, 8, -19], [-32, 2, -9, 25], [-3, 3, -1, 8], [19, -8, 12, 3], [25, -15, 6, -8], [-12, -6, 3, -19], [47, 11, 1, 14], [27, 2, 13, 8], [26, 14, 3, 22], [-12, -20, 4, 3], [-20, 8, 2, -1], [33, -5, 5, -1], [-49, -14, 2, 4], [24, 4, 16, 1], [7, 10, 7, 15], [11, -25, -5, -12], [4, -25, -2, -22], [29, -3, 1, -11], [32, -2, -11, 1], [49, 9, 10, 16], [-12, 14, 6, 5], [1, 5, 11, 16], [-20, 4, 4, 11], [18, 4, 1, 1], [8, -18, -1, 1], [25, -7, -5, -14], [-11, -16, -7, 1], [-9, 15, -15, -8], [-55, -8, 1, 1], [-7, 13, 6, 8], [-31, 8, 3, 10], [-34, 3, -12, -19], [27, -1, 5, -7], [15, 10, 10, -13], [-35, -17, 4, -12], [4, -2, -6, 18], [23, 7, -1, -18], [40, -11, -2, -6], [33, -17, 6, 8], [-25, 9, -4, -18], [-10, -12, -14, 8], [-17, 7, -12, 16], [5, 16, 7, -2], [17, -7, 5, 14], [-3, -13, 9, -19], [-40, -10, -2, -9], [27, -10, -9, -4], [24, -2, 1, 9], [-27, 20, 2, -1], [22, 14, -9, 9], [19, 27, 5, 23], [-4, 14, 15, 11], [-4, -7, -7, 8], [39, -8, 8, -9], [-9, 14, -6, 15], [-11, -19, 3, -11], [-8, 22, 0, 20], [-5, -5, -13, -9], [-15, -1, -9, 25], [-8, 34, 5, 7], [-29, 10, -3, -16], [25, -12, 13, -3], [16, 6, 4, -22], [-49, -11, -7, -11], [-4, 11, -3, -11], [3, 10, -6, 9], [-29, 7, -9, -1], [-11, -17, -5, 12], [10, 0, 2, 30], [31, 4, 3, 4], [40, -19, -7, -5], [-21, 1, 15, -6], [10, -14, -8, 7], [18, -2, 6, 8], [-20, 12, 2, -16], [-1, 11, -11, 16], [1, -31, -10, -10], [8, -21, -7, -11], [25, -5, 3, -3], [20, -18, -8, -5], [-15, -2, 8, -10], [38, 4, 5, -12], [-3, -2, -10, -1], [26, -16, 6, 19], [-5, -25, 10, 13], [39, -11, 8, -17], [-10, 8, 0, -24], [18, 8, -2, 29], [0, 6, 14, 8], [3, 0, 7, -15], [-29, -5, -3, 10], [41, -21, -5, 4], [25, -24, 0, 0], [30, -17, -5, 1], [-47, 3, 2, -12], [37, -27, -6, -14], [-1, -15, 7, -16], [51, -13, 8, 9], [-23, -1, -8, -18], [-4, -19, -7, 13], [16, 12, 10, 3], [-40, 20, -4, -24], [-5, -21, 0, -10], [-7, 5, -10, -13], [-19, 10, 5, -9], [11, 28, 1, 3], [-11, 21, -1, 12], [-55, 7, -3, -16], [9, 6, 20, 4], [58, 10, -2, -13], [4, 19, -8, 13], [-39, -4, -16, -15], [-2, -18, -2, -4], [18, -20, -16, -6], [-32, 3, -14, -7], [30, 8, 5, -15], [11, 2, -6, 3], [4, -34, -8, -23], [-32, -21, 4, -15], [-33, 6, -6, 21], [8, -1, 2, 25], [-31, 3, -10, 14], [-42, -11, 9, -6], [19, -13, -14, -4], [-39, 5, -2, 4], [12, -20, 4, 20], [66, 7, 1, 7], [2, 2, 3, -26], [18, 1, 9, -11], [-12, -11, 0, -4], [-4, 12, 0, 7], [10, -20, -10, 21], [16, 32, 4, 25], [-3, -25, 4, -23], [18, 7, -9, -2], [9, -21, -19, 0], [-11, -30, -8, -33], [36, 14, 14, 20], [18, 6, -10, 0], [-4, -10, -6, -8], [4, -3, 13, 0], [-16, 25, 1, 2], [61, 19, 7, 27], [15, 6, 0, 10], [-2, 16, -4, 21], [12, -6, 18, -3], [-2, 8, -10, 3], [-28, -15, -6, 6], [-15, 20, 5, -25]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9800_2_a_ct();".
// 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_9800_2_a_ct(:prec:=4)
    chi := MakeCharacter_9800_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(3361) - 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_9800_2_a_ct();".
// 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_9800_2_a_ct( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, 11, -4, -3, 1]>,<11,R![134, -49, -37, 0, 1]>,<13,R![-84, -105, -23, 4, 1]>,<19,R![-824, -359, -13, 10, 1]>,<23,R![953, -91, -79, 0, 1]>],Snew);
    return Vf;
end function;