
// Make newform 9801.2.a.bb in Magma, downloaded from the LMFDB on 20 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_9801_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_9801_2_a_bb();".
// 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_9801_2_a_bb();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_9801_a();"
function MakeCharacter_9801_a()
    N := 9801;
    order := 1;
    char_gens := [9560, 244];
    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;

function MakeCharacter_9801_a_Hecke( : Kf := Kf)
    return MakeCharacter_9801_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 := [[1, 1], [0, 0], [0, -2], [-1, 0], [0, 0], [-4, 4], [-3, 3], [1, 0], [-4, 1], [3, -3], [0, -1], [-2, 5], [5, 4], [0, -3], [-7, 8], [-1, 5], [-1, 1], [9, -3], [6, 0], [6, 5], [-2, -3], [5, -9], [11, 2], [8, 2], [6, 0], [6, -4], [-9, 2], [-6, 13], [9, 3], [-16, 2], [-5, 9], [-20, 2], [8, -1], [6, -6], [9, -10], [0, -7], [9, 3], [17, -6], [7, 2], [20, -5], [10, 8], [-13, -5], [-1, 8], [-11, 0], [-7, 2], [-9, -3], [18, -4], [-5, 17], [16, -1], [4, -10], [0, -18], [-8, 4], [-12, 24], [-15, 9], [18, 5], [9, -6], [12, -15], [12, 2], [-18, 2], [5, -7], [-17, 0], [23, -10], [6, -3], [-9, 10], [1, -4], [-16, 8], [7, -12], [-9, 4], [-1, -16], [-6, -3], [9, -12], [21, -3], [-9, 6], [3, 14], [9, -11], [-18, 3], [14, -14], [9, 18], [-9, 9], [-22, 19], [-5, 5], [9, -2], [18, -26], [3, -19], [3, 6], [0, -2], [-5, 4], [-1, 0], [18, 3], [17, 0], [2, 2], [13, 2], [0, 21], [-3, 7], [31, -12], [12, 4], [21, -10], [28, -20], [0, 0], [-15, -5], [-28, 7], [-8, -14], [3, -28], [-32, 11], [-21, -4], [28, -12], [-6, 12], [6, -8], [1, -20], [-15, 4], [-11, -12], [18, -3], [8, -31], [22, -9], [-1, 16], [5, -25], [-5, 3], [-2, -10], [-11, -20], [3, 21], [-8, -6], [-24, 9], [-11, -8], [8, 4], [1, -22], [23, -40], [-27, -2], [6, -22], [4, -24], [46, -4], [24, -30], [30, -20], [-9, 36], [11, 0], [6, 21], [-9, 11], [-15, 14], [36, 0], [-15, 15], [15, -5], [-8, -27], [-24, 23], [-46, -6], [49, -13], [25, -30], [21, 6], [-41, -9], [-13, 20], [-27, 9], [1, 25], [-2, -22], [-8, -10], [-27, 14], [-4, -13], [-22, -12], [13, -10], [-4, 37], [39, -15], [-15, 13], [-8, 31], [-33, 6], [20, 17], [29, -38], [0, 15], [-17, -2], [-21, -19], [7, -22], [8, 1], [-5, 35], [6, -15], [42, -22], [42, 0], [-13, 29], [-37, 42], [15, 15], [7, 11], [6, 4], [7, -26], [1, 20], [21, 24], [-43, 7], [31, -2], [-22, 21], [24, 0], [-43, 11], [-48, -5], [15, 5], [0, 7], [-22, -24], [-18, 21], [-12, 15], [30, -33], [9, -33], [36, -18], [-18, 3], [-1, 29], [27, 21], [6, -21], [-18, 19], [-28, 25], [22, 11], [10, -19], [13, -21], [31, 2], [6, -24], [-1, -10], [-10, 6], [-27, 14], [2, -40], [3, -15], [-14, 27], [-9, 5], [-27, 24], [26, -8], [20, 25], [-37, 24], [-9, 22], [-26, 25], [-17, -8], [30, -24], [-1, 16], [-61, 0], [-59, 13], [12, -6], [16, -11], [27, 1], [-29, 4], [41, -35], [29, -48], [-37, 8], [41, -20], [36, -54], [-38, 41], [-29, 22], [40, -31], [-21, 36], [-1, 18], [-35, 16], [22, 4], [41, 13], [-33, 17], [-26, 48], [32, 13], [-32, -6], [14, -14], [55, -11], [-15, 27], [0, 18], [-21, 10], [14, -49], [12, 0], [33, 18], [-11, 22], [-51, 0], [-32, 7], [-45, -6], [-59, 27], [-33, -16], [-3, -43], [-49, -8], [58, -6], [8, 41], [33, -4], [3, 18], [7, 28], [34, -19], [-7, 44], [-60, 12], [48, -41], [66, 3], [-47, 32], [40, -24], [31, -61], [-24, -6], [8, 36], [11, 10], [3, 6], [-49, 22], [-14, 8], [5, 31], [51, 1], [11, 40], [69, -7], [25, -30], [-10, 48], [-17, -2], [21, 21], [13, 13], [20, -42], [-18, 50], [32, 2], [-17, 22], [5, -55], [-6, -3], [27, 18], [-61, 2], [45, -15], [31, -8], [33, -7], [5, -9], [24, -4], [-12, 11], [41, -27], [-24, 46], [-54, 45], [30, 18], [-15, 9], [-40, 3], [16, -22], [3, 24], [-8, 40], [-30, -21], [-9, 36], [-9, -24], [-15, 9], [-54, -2], [-42, 39], [5, 34], [-5, 9], [-3, -10], [-11, -28], [43, -54], [-44, 26], [9, -6], [14, -28], [-21, 36], [42, -12], [27, -55], [23, 38], [-9, -31], [7, -10], [39, -4], [-18, 3], [75, 0], [17, -33], [-33, 57], [-30, 54], [0, -18], [20, -15], [-40, -26], [18, 13], [-5, 46], [48, -21], [74, -33], [-45, 8], [-63, -12], [-56, 8], [6, -18], [22, -25], [-2, 35], [21, -52], [53, -62], [-39, 39], [9, 30], [-10, 48], [5, -58], [-38, 20], [12, -44], [-54, 18], [42, -12], [28, -34], [-32, -25], [33, -67], [-9, -48], [56, -12], [3, 18], [3, -43], [-6, -45], [16, 23], [18, -42], [23, -32], [13, -11], [-47, 34], [-27, 46], [18, -9], [8, 31], [63, 11], [34, -21], [-31, 29], [-39, 60], [44, -61], [-3, 34], [44, -42], [10, 46], [-31, 25], [17, -56], [-42, 76], [-50, 51], [-58, -18], [-19, -37], [6, 40], [48, -60], [53, -22], [-42, 40], [-30, -9], [11, -44], [-10, 3], [12, -39], [-44, -30], [45, 0], [-13, 6], [65, -35], [3, -18], [58, -13], [11, -26], [31, 20], [36, -26], [-83, 17], [-56, 39], [47, 2], [-61, 18], [-40, 26], [43, 10], [-73, 7], [46, -61], [8, -61], [39, -39], [16, -30], [44, -56], [62, -46], [-54, 74], [-53, -30], [-27, -12], [33, 12], [-38, 32], [6, -48], [-39, 72], [22, -68], [-86, 23], [33, -8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9801_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9801_2_a_bb();".
// 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_9801_2_a_bb(:prec:=2)
    chi := MakeCharacter_9801_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(2999) - 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_9801_2_a_bb();".
// 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_9801_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9801_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -3, 1]>,<5,R![-4, 2, 1]>,<7,R![1, 1]>,<17,R![-9, 3, 1]>],Snew);
    return Vf;
end function;