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