
// Make newform 9800.2.a.be in Magma, downloaded from the LMFDB on 12 January 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_be();".
// 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_be();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [0], [0], [3], [6], [5], [1], [7], [2], [-5], [-3], [-2], [4], [-5], [1], [15], [-5], [9], [0], [-7], [1], [-12], [7], [2], [3], [15], [-9], [-5], [18], [-8], [5], [-11], [-12], [-17], [-5], [9], [-13], [12], [13], [-13], [-10], [-11], [-3], [6], [-13], [-4], [24], [-11], [23], [-11], [20], [-17], [16], [21], [9], [-9], [-7], [17], [6], [13], [-6], [-4], [15], [1], [-3], [29], [10], [-15], [2], [-3], [21], [-23], [-11], [24], [3], [-29], [17], [27], [27], [20], [34], [3], [2], [21], [31], [-26], [17], [-30], [16], [3], [31], [-7], [-24], [-35], [32], [-9], [-33], [7], [-41], [8], [5], [41], [-33], [-13], [33], [20], [45], [-17], [22], [-13], [-43], [-30], [-9], [-16], [-17], [44], [-15], [-35], [44], [23], [26], [-39], [-27], [5], [-50], [-29], [-39], [-32], [-19], [-5], [16], [53], [-10], [3], [22], [-19], [17], [-18], [39], [12], [-9], [-47], [36], [11], [-24], [-34], [-39], [1], [-17], [-23], [-14], [20], [3], [1], [16], [-11], [7], [6], [-33], [-37], [-22], [-48], [-35], [-3], [21], [15], [41], [30], [-19], [31], [42], [9], [17], [-21], [-34], [-16], [15], [-16], [-41], [47], [44], [26], [41], [9], [-9], [-59], [13], [-21], [-45], [1], [-36], [17], [63], [-67], [-3], [19], [1], [-22], [47], [-61], [24], [37], [-53], [36], [-39], [-31], [39], [26], [31], [-3], [-54], [-40], [-21], [-37], [3], [-51], [11], [3], [2], [63], [-44], [23], [-21], [-28], [-46], [-51], [23], [-61], [-3], [41], [47], [16], [-5], [-28], [-15], [-13], [-39], [-68], [-36], [25], [41], [73], [-5], [-66], [-23], [56], [59], [-21], [4], [-26], [47], [29], [-42], [-79], [9], [-25], [13], [-66], [-3], [25], [60], [-21], [-34], [-27], [-55], [10], [-50], [-60], [-51], [7], [5], [-11], [-51], [18], [31], [-29], [55], [-1], [33], [-3], [-37], [24], [-6], [55], [-3], [81], [-10], [-57], [-66], [-45], [77], [73], [40], [-74], [43], [21], [46], [45], [-8], [49], [9], [51], [36], [-15], [-86], [9], [-62], [61], [1], [-65], [23], [-5], [65], [-8], [-77], [76], [67], [26], [-18], [59], [-59], [66], [-4], [49], [-25], [-35], [-13], [-57], [30], [51], [-51], [88], [-55], [83], [4], [-38], [-43], [26], [-73], [21], [-6], [-30], [-64], [37], [-36], [55], [-1], [-20], [85], [77], [53], [18], [-63], [75], [6], [-63], [-37], [-27], [24], [70], [-69], [69], [-75], [57], [13], [-42], [-51], [-38], [-1], [65], [-21], [22], [43], [93], [-29], [0], [61], [23], [74], [19], [34], [8], [9], [-28], [-51], [-73], [-23], [43], [32], [-46], [-7], [-33], [99], [-83], [-71], [-65], [-50], [-20], [-21], [99], [-59], [51], [9], [-85], [-55], [1], [22], [69], [-27], [-39], [-27], [-92], [-23], [66], [27], [13], [-67], [-102], [-13], [-9], [61], [-48], [-12], [-30], [-63], [-49], [-42], [-25], [-53], [23], [20], [-31], [60], [-94], [-9], [35], [47], [76], [-40], [9], [35], [-46], [3], [62], [18], [-84], [-87], [107], [59], [71], [0], [-59], [-49], [-7], [-78], [-89], [7], [-31], [17], [-45], [-103], [-19], [-5], [85], [-7], [4], [63], [-93], [64], [89], [-92], [100], [-90]];
    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_be();".
// 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_be(:prec:=1)
    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_be();".
// 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_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<11,R![-3, 1]>,<13,R![-6, 1]>,<19,R![-1, 1]>,<23,R![-7, 1]>],Snew);
    return Vf;
end function;