
// Make newform 9800.2.a.ch in Magma, downloaded from the LMFDB on 18 June 2026.
// 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_ch();".
// 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_ch();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [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 := 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]];
    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], [1, -1, 0], [0, 0, 0], [0, 0, 0], [-2, 1, -2], [0, -3, 4], [-2, 3, -3], [-2, 3, -1], [-1, -2, -1], [4, -1, -1], [1, 1, 3], [2, 3, -4], [-1, 2, 1], [3, 4, -3], [6, 2, -3], [-2, 4, 5], [1, -3, 0], [-3, -5, -1], [-4, 6, 0], [3, 0, 6], [-4, 0, -4], [-1, 0, -1], [0, -5, 3], [-2, 6, 1], [-7, 3, -6], [-13, -1, 1], [-1, -11, 10], [-3, -6, 9], [2, 3, -6], [-1, 1, -3], [-9, 8, -1], [-9, -7, 5], [-5, 6, 3], [-8, -1, 0], [-2, 1, -3], [-8, -7, 7], [-5, 7, 6], [0, 0, -1], [8, 5, 4], [-7, 3, -5], [-6, 4, -10], [-14, 3, -3], [-5, -8, 12], [-9, 2, -11], [-3, -15, 14], [-10, -6, 1], [11, 7, 1], [3, 11, -14], [19, -5, 5], [-5, -9, -4], [3, 6, 6], [6, -7, 11], [-15, -8, 3], [-3, -9, 9], [20, -6, 2], [-3, -13, 8], [3, 2, 16], [-14, 0, 1], [3, -7, -6], [16, 8, -10], [3, 7, 6], [-8, 6, -1], [5, -2, -11], [2, -4, -6], [-20, -13, 8], [23, -4, 4], [-15, 2, -16], [-13, -1, 3], [13, 13, -12], [-2, 14, -15], [-15, -3, 11], [-1, 3, 11], [19, 15, -9], [-7, 11, -15], [-11, 9, -9], [-16, 1, -6], [-1, -16, 7], [0, -2, -1], [-5, 9, -20], [-11, -4, -2], [2, 19, -3], [3, -7, 20], [10, -5, 6], [6, -5, -9], [-13, 0, 9], [-3, -7, -7], [15, 16, -8], [28, 2, -7], [3, -1, -1], [26, -8, -6], [15, 11, -5], [-10, -7, 8], [12, -13, -5], [24, -2, -8], [11, 6, -6], [-2, -1, 3], [6, -18, 10], [-8, 0, 2], [17, -8, 10], [10, 20, -7], [-1, -5, 16], [7, -12, -1], [3, -4, -12], [-16, -3, -15], [-5, -7, 2], [-19, 1, -7], [20, 8, -5], [-18, -2, -2], [-20, 6, 4], [-7, -10, -13], [4, 5, 21], [-14, -3, 7], [-17, 13, -25], [-27, -2, -6], [7, 13, 1], [3, -19, -7], [7, 4, 2], [14, -6, 5], [2, -22, 11], [-3, -13, 8], [-26, 14, 6], [27, -9, 6], [-8, 11, 7], [8, 2, 13], [-26, 5, -22], [-2, 21, -7], [11, -3, 18], [-1, -3, -27], [20, -9, -8], [-9, 13, 1], [5, -10, 28], [35, 13, -12], [7, 3, -2], [-2, -23, 15], [-23, 8, 6], [-1, -7, 23], [-19, -24, 11], [7, 30, -15], [-11, -3, -8], [12, -1, 5], [1, -8, -5], [-9, 15, 5], [3, -13, 7], [7, -19, -3], [-22, 10, 1], [-4, -18, 10], [0, -9, 2], [-7, 0, -7], [4, 3, -12], [0, -12, 9], [32, 2, -6], [-1, -15, -10], [-18, -3, -8], [-19, 10, -23], [17, -16, 10], [-18, -24, 5], [17, -1, -1], [-13, 5, 20], [-42, -1, -3], [-4, -31, 20], [-22, 14, -18], [-1, -28, 1], [14, 1, -3], [-11, -6, 18], [-8, 13, 0], [-7, 15, -22], [17, 6, -24], [-28, -16, 7], [-20, -18, 11], [4, -5, -23], [19, -7, -5], [-3, -17, 20], [1, 5, -29], [19, -21, 5], [-44, 11, -7], [15, -10, -7], [12, 20, -5], [-11, 25, 12], [5, -21, 18], [-4, 2, -28], [-3, -7, -6], [-7, 30, -4], [8, -12, 12], [-20, -3, -4], [-26, 7, -27], [15, 17, -20], [-25, -14, -5], [31, -8, 25], [-3, 23, 0], [36, 10, -7], [21, 11, -11], [-17, 11, 15], [-13, 4, 7], [15, 28, -27], [0, 34, -36], [-8, 0, 27], [7, 5, 9], [-2, 22, -4], [1, 7, -8], [-3, -26, 18], [18, 9, 6], [8, -13, 17], [-23, -10, 2], [5, -11, 18], [14, 16, -18], [-8, 13, -20], [-9, -21, 16], [21, -6, 8], [9, 12, 12], [23, -13, 18], [25, 17, -1], [3, -16, 34], [28, -16, 31], [27, 3, -15], [-13, 13, 10], [-3, 26, -19], [-1, 0, 10], [17, -9, 1], [-18, 2, 23], [-15, -19, -5], [12, -30, 13], [-4, -22, -10], [-38, 9, 6], [-23, 17, 9], [2, 30, -37], [-11, -17, 25], [2, -21, 31], [8, -24, -12], [-23, -20, -8], [-14, -15, -10], [-18, 26, 7], [-7, 1, 27], [-25, -21, 9], [2, -36, 28], [-20, 17, -15], [-15, 10, 7], [-6, 25, -5], [12, 4, 25], [-1, -13, -12], [-13, -20, 0], [-17, -17, 10], [16, -9, 38], [9, 18, -23], [-3, 15, -25], [22, -25, 26], [-18, 22, -15], [-13, 1, 1], [-13, 1, 23], [-1, -32, 8], [-17, 8, -5], [13, 1, -1], [22, 2, 25], [-26, 18, 16], [16, 12, -9], [-39, 22, -9], [25, 9, 10], [-8, 43, -9], [-22, -11, 30], [-48, 4, -2], [0, -19, -16], [36, -15, 35], [28, 25, -18], [-18, -14, -11], [43, 7, -20], [15, -32, 36], [29, 16, -8], [-27, 15, -37], [6, 21, -30], [-37, 2, -2], [41, 7, -10], [40, -15, -6], [-29, -1, 20], [27, -27, 0], [30, -9, 1], [-13, 13, 8], [-24, 8, -8], [-18, 2, 7], [17, -29, 31], [5, 20, 2], [-9, -26, -17], [-33, 16, -5], [19, -17, 17], [9, -34, 19], [3, 16, -13], [17, 27, -30], [11, 17, 6], [7, -21, 47], [23, 17, -11], [-42, 12, -6], [-32, 21, -32], [-7, 22, 11], [15, 29, -28], [-5, 21, -20], [-17, 17, -24], [-3, -6, 8], [11, -6, -19], [55, 0, -12], [-28, -11, 15], [30, 36, -29], [-28, -13, 22], [37, 22, -28], [-14, -26, -7], [-1, -22, 23], [-17, -8, -27], [30, 5, 5], [11, -6, 7], [-8, 2, -6], [-13, -34, 5], [-40, -17, -3], [8, -29, 16], [-4, -5, 43], [13, 30, 1], [21, 38, -22], [37, 29, -22], [12, -29, 44], [-14, 7, 6], [29, -30, -15], [17, 26, -29], [-13, 35, -10], [-27, 5, 16], [-11, -24, -3], [-38, 14, -17], [13, 7, 2], [20, 10, -31], [14, -19, 48], [12, 48, -39], [14, -5, 38], [19, 56, -25], [21, -20, -13], [-33, -27, 18], [6, 27, -14], [35, -2, 5], [-61, 3, -9], [40, 15, -19], [4, -28, 17], [24, 18, 3], [11, 10, -14], [3, 40, -2], [-44, 0, 5], [-59, 7, -4], [3, -20, -7], [20, -25, 4], [-7, 0, 0], [-14, -23, 12], [-9, -7, -2], [-8, 4, -47], [5, 14, 5], [36, 4, 15], [-28, 21, 8], [-14, -37, 18], [9, 22, -49], [29, 45, -28], [13, -2, 1], [-21, 3, -4], [33, -9, -26], [7, -3, -31], [2, 33, -43], [3, 14, -36], [9, -12, 5], [19, 37, -24], [0, -4, -48], [-1, -24, 15], [-28, -19, 8], [-3, -15, -18], [-41, -27, -2], [-2, 6, -18], [19, -21, -20], [5, -25, -13], [-49, 12, -33], [31, 42, -44], [12, -12, 17], [31, -7, 1], [54, -15, 12], [23, -10, 1], [32, -19, 14], [27, 42, -6], [-22, -49, 20], [50, 0, 25], [5, -36, -13], [-17, 40, -41], [21, -6, 14], [-24, -30, 44], [23, 8, -20], [-23, -20, -10], [-26, 19, 2], [-27, -59, 41], [19, 11, 20], [-16, -22, -14], [-1, 20, -20], [-42, -6, -20], [-29, -20, 37], [-47, 4, 20], [35, 24, -25], [6, 22, 20], [-35, 25, 3], [54, 16, -10], [-25, -14, -13], [18, -30, 3], [-2, 24, -10], [16, -22, 18], [-5, -6, 19], [-25, -3, 32], [38, -22, 0], [-25, 12, -22], [8, -18, 23], [71, 6, 2], [24, -15, 23], [13, -28, 51], [30, -10, 27], [41, -1, -5], [-17, 9, 5], [-22, -40, 16], [-22, -54, 39], [28, -16, 14], [3, -21, 14], [39, -6, 45], [-57, 28, -9], [-23, -52, 52], [44, 8, -2], [-19, -55, 22], [21, -5, 16], [-23, 42, -25], [29, -23, 41], [23, 9, 30], [6, 24, -24], [32, -2, 51], [24, -24, -12], [-25, -45, 26], [-29, -35, 13], [49, -1, -10], [-25, 17, -10], [11, 26, -53], [27, 22, -27], [57, 14, -20], [18, 0, 39], [20, 49, -47], [-83, -16, 11], [-14, 24, -6], [-18, -20, -6], [-12, 23, -53], [-24, 3, 28], [3, 44, -37], [-40, 10, -21], [-16, -25, -9], [-7, 0, 7], [36, 23, -29], [5, -27, -24], [-24, 28, -53], [21, -17, -6], [-1, -31, -18], [12, 32, 8], [-4, -10, -14], [16, -27, -29], [-12, 12, 8], [-16, -45, -4], [16, -8, -19], [26, 2, 13], [-8, -24, 13], [-19, 23, 31], [-12, 16, 23], [51, -6, -11], [21, -6, 13], [0, 40, 10], [-18, -24, -10], [-40, -28, -6], [22, -16, 43], [10, 48, -21], [67, -4, -4], [-9, 38, -26], [-38, -24, 41], [-32, 12, -37], [-34, -6, 37], [24, 5, -16], [31, 3, -30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9800_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9800_2_a_ch();".
// 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_ch(:prec:=3)
    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_ch();".
// 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_ch( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![3, 0, -3, 1]>,<11,R![-19, 3, 6, 1]>,<13,R![19, -39, 0, 1]>,<19,R![-17, -9, 6, 1]>,<23,R![17, -18, 3, 1]>],Snew);
    return Vf;
end function;