
// Make newform 9702.2.a.bo in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9702_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_9702_2_a_bo();".
// 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_9702_2_a_bo();".
// 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_9702_a();"
function MakeCharacter_9702_a()
    N := 9702;
    order := 1;
    char_gens := [4313, 199, 5293];
    v := [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_9702_a_Hecke(Kf)
    return MakeCharacter_9702_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 := [[1], [0], [0], [0], [-1], [4], [4], [0], [0], [-2], [4], [10], [-12], [4], [4], [10], [-4], [-4], [4], [8], [-4], [8], [-16], [8], [8], [-12], [-4], [12], [18], [-2], [0], [-8], [-6], [16], [10], [-8], [-8], [12], [0], [4], [4], [0], [16], [-14], [-6], [12], [-12], [12], [-8], [16], [-6], [-8], [20], [4], [-24], [8], [-8], [24], [-10], [10], [24], [-4], [8], [4], [-32], [18], [20], [-2], [-12], [28], [24], [32], [12], [22], [4], [-4], [-10], [8], [34], [-20], [-36], [22], [40], [-40], [40], [-4], [-18], [26], [28], [-40], [36], [24], [-8], [-20], [20], [-24], [-24], [0], [-8], [-34], [-36], [-14], [0], [-6], [-12], [-40], [36], [-36], [24], [-28], [-16], [26], [-22], [-36], [-16], [2], [-20], [-20], [30], [-4], [-40], [-2], [4], [-4], [-28], [-2], [26], [-36], [-12], [-4], [28], [-32], [32], [-22], [44], [-20], [40], [-32], [16], [-10], [8], [-54], [0], [28], [24], [-36], [4], [-4], [-52], [32], [-46], [16], [4], [-8], [12], [40], [-16], [48], [-36], [28], [12], [54], [-8], [20], [50], [-60], [56], [-28], [-30], [40], [12], [-40], [-24], [-10], [28], [16], [-20], [-58], [40], [20], [32], [0], [-6], [-28], [-24], [-24], [-2], [-52], [-10], [-64], [-40], [-4], [20], [-32], [4], [24], [-34], [-14], [12], [8], [18], [-48], [-48], [-4], [-60], [32], [-36], [44], [22], [36], [-34], [40], [-8], [28], [-56], [48], [-8], [-20], [-24], [46], [-38], [-40], [-18], [64], [-24], [10], [48], [-24], [-8], [-60], [2], [56], [-56], [6], [60], [8], [40], [-54], [-20], [60], [60], [-16], [20], [-34], [-12], [-64], [20], [-52], [-76], [16], [-34], [-20], [8], [-16], [-36], [-60], [-38], [64], [-16], [-60], [16], [-36], [28], [-76], [-72], [-68], [-46], [32], [-4], [-58], [-8], [76], [8], [48], [44], [-68], [36], [-34], [-70], [-48], [-64], [-32], [24], [-28], [16], [-8], [2], [74], [28], [20], [-46], [-60], [26], [0], [-18], [12], [68], [-56], [16], [-64], [-36], [14], [56], [-4], [52], [78], [-60], [56], [48], [6], [48], [-58], [-46], [-52], [8], [-20], [-60], [48], [-24], [-30], [40], [38], [-36], [88], [-74], [16], [-36], [-68], [-24], [6], [14], [-66], [48], [64], [12], [-12], [82], [52], [-32], [88], [-74], [-6], [52], [-48], [-50], [60], [80], [84], [48], [24], [-32], [-38], [2], [24], [-74], [52], [-60], [-8], [-66], [64], [6], [-60], [8], [-84], [-52], [-10], [-12], [8], [74], [-92], [-28], [48], [-54], [-32], [-50], [52], [72], [-44], [-60], [-44], [48], [54], [48], [-82], [48], [84], [-72], [8], [-52], [20], [-2], [8], [-52], [28], [0], [-90], [-56], [24], [60], [54], [92], [-34], [104], [-56], [36], [64], [-82], [78], [-60], [60], [-4], [-42], [4], [20], [-74], [-48], [-80], [84], [8], [-16], [78], [12], [-96], [40], [64], [-40], [108], [10], [-76], [-24], [32], [-36], [84], [20], [-8], [-16], [102], [-22], [-28], [-32], [84], [-46], [26], [48], [28], [30], [-96], [0], [-40], [-52], [-20], [12], [60], [4], [-78], [-6], [-94], [88], [-84], [54], [100], [-8], [-68], [70], [32], [14], [-40], [36], [34], [-4], [32], [52], [-4], [50], [-12], [44], [30], [28], [32], [74], [64], [-28], [-16], [28], [4], [-12], [-30], [-60], [-36], [88], [68], [8], [58], [60], [116], [-44], [84], [-22], [80], [92], [-66], [-96], [-26], [-8], [-2], [-8], [-8], [92], [10], [-104], [64], [-80], [-4], [18], [44], [-62], [0], [92], [-64], [68], [74], [-76], [14], [-24], [-44], [-88], [104], [12], [60], [-64], [-104], [90], [-56], [68], [48], [24], [48], [-40], [-2], [-108], [-104], [66], [-44], [0], [-58], [-12], [104], [-84], [104], [68], [-18], [112], [108], [46], [-12], [92], [-108]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9702_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9702_2_a_bo();".
// 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_9702_2_a_bo(:prec:=1)
    chi := MakeCharacter_9702_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(4027) - 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_9702_2_a_bo();".
// 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_9702_2_a_bo( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9702_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<13,R![-4, 1]>,<17,R![-4, 1]>,<19,R![0, 1]>,<23,R![0, 1]>,<29,R![2, 1]>],Snew);
    return Vf;
end function;