
// Make newform 9702.2.a.dy 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_dy();".
// 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_dy();".
// 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 := [-2, -11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-8, 3, 1], [-8, -1, 1]];
    Rf_basisdens := [1, 2, 2];
    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_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, 0, 0], [-1, 0, -1], [0, 0, 0], [1, 0, 0], [0, -1, 1], [-1, 0, -1], [-3, 1, 0], [0, -1, -1], [-2, 1, -1], [1, 0, 3], [4, 0, 2], [1, 0, 1], [4, 1, -3], [3, 1, -2], [4, 0, -2], [2, -2, 0], [-4, -1, -3], [2, 1, 1], [-2, -1, -3], [5, 0, 1], [2, -1, -1], [7, 0, 1], [6, 1, 1], [-6, 2, -2], [2, 2, -2], [-3, 0, -1], [-2, 0, -2], [8, 0, 0], [-4, 1, 3], [2, -1, -1], [17, 0, -1], [8, 1, 3], [1, 1, 4], [-2, -2, 2], [8, 2, 2], [15, 0, -1], [-4, 2, 2], [6, -2, 4], [8, -2, 0], [-2, 1, -7], [5, 0, 1], [-4, -3, 5], [-6, 0, 4], [-6, -3, 3], [11, 0, 1], [0, -3, 1], [5, 0, 7], [11, 0, 5], [-1, 2, -3], [-2, 4, -4], [0, -2, -2], [7, 0, 3], [-14, -2, -4], [-2, -1, 3], [-2, -3, 1], [-23, 0, 1], [14, 0, -2], [4, 2, -2], [-6, -2, -2], [17, 1, -4], [-4, 0, 2], [-9, -3, 2], [3, 1, -2], [8, 2, 0], [16, 2, 0], [-6, -1, 3], [-16, 2, -4], [-2, 0, -2], [-14, 1, 1], [-2, -1, 3], [6, 3, 3], [7, 0, -3], [-4, -1, 5], [0, 2, 6], [-17, 1, 2], [6, 4, 4], [13, 2, -1], [8, 1, 3], [13, 0, -3], [4, 4, -4], [18, 0, 4], [10, -1, 3], [-6, 0, 8], [-10, 2, 0], [-14, -1, 3], [20, 1, 3], [-2, -2, 6], [14, -4, 4], [4, 0, -4], [0, 2, 2], [16, 0, 4], [10, 2, 4], [-8, 0, 4], [6, 1, -7], [-18, -2, 4], [-11, -4, 9], [2, -1, 7], [-11, 1, -8], [0, -3, 7], [18, 1, 11], [6, -1, -7], [31, 0, 1], [30, -2, -2], [6, 1, -1], [8, 2, 0], [-10, 0, 2], [9, 0, 9], [10, -1, -3], [-11, -4, -7], [4, 2, -10], [24, 3, 1], [-24, -2, -2], [4, -2, -2], [26, -4, 2], [8, -6, 2], [14, 2, 0], [-21, 1, -2], [-10, -4, 4], [-18, 6, 0], [-5, 6, -3], [16, 2, 4], [-16, 2, -8], [-10, -1, -5], [-22, -4, -6], [2, 6, 2], [0, 6, 4], [-21, -1, -4], [1, 4, 7], [16, 3, -3], [26, 3, -3], [4, 0, 4], [-6, -4, -6], [-20, 2, -8], [27, 2, -7], [-17, 4, -5], [3, 0, -9], [29, -3, 4], [-17, 2, -3], [-4, 2, 4], [-3, 7, 6], [-18, 0, 0], [26, -4, 2], [-16, 0, -4], [-11, -6, 3], [-21, -1, -4], [4, -3, -9], [-23, 4, -7], [-26, -4, 2], [-12, 1, -11], [0, 0, 4], [12, -7, -1], [8, 2, 14], [-16, -2, 6], [-18, -1, 3], [12, 1, -11], [12, -2, 2], [-18, -3, -3], [-19, 2, 3], [-4, -6, -4], [-16, 6, 2], [32, 0, 2], [-12, 2, 6], [-12, 2, 2], [-12, 2, 2], [15, 5, -10], [0, 2, 6], [30, 1, -3], [22, -2, 6], [21, -2, -5], [-18, 2, -4], [-11, -2, -5], [20, 0, -4], [-12, 2, 0], [-7, 0, -5], [0, -3, 15], [18, 1, -13], [-18, 0, 0], [-18, -4, -2], [-30, -1, -5], [0, -6, -2], [1, 0, 7], [8, 6, 0], [11, 2, 1], [-14, 7, -7], [-13, -4, 7], [-20, 1, 3], [-8, 0, 0], [-16, -4, 14], [10, 6, 4], [12, 2, -8], [-6, -2, 4], [2, -7, 5], [-35, 0, 1], [0, 6, 6], [-30, 1, -11], [-20, -2, 0], [12, 2, -12], [-7, -2, -9], [-2, -8, 2], [6, -6, 6], [26, -2, 8], [-15, -2, -9], [19, 6, -3], [4, -2, 2], [-25, -2, -3], [-7, 4, -1], [-28, -6, 14], [12, -2, 16], [-12, 2, -2], [-36, -4, 6], [21, 0, 9], [-28, -4, 8], [10, -4, 6], [-6, 0, -6], [0, -4, 10], [-26, 1, -3], [-19, -2, -9], [-26, 3, 1], [-14, -2, 14], [16, 7, 9], [-14, 4, -2], [36, 5, 11], [4, 10, -6], [3, -4, -7], [-32, 0, -4], [-8, 1, -13], [-2, 1, -13], [-14, -8, -2], [-14, 0, 10], [4, -2, -12], [3, -1, 16], [-8, 4, 12], [-48, -2, 4], [-8, -2, 10], [26, -2, 0], [-42, 0, -4], [2, 6, 2], [24, -8, 4], [-25, -1, -8], [18, 1, 13], [15, -3, 2], [-11, 8, -1], [-6, 0, -8], [41, -2, 3], [50, 2, -8], [9, 4, -9], [22, -2, -4], [-2, 9, -1], [18, -3, -3], [-36, -3, -17], [3, 10, -11], [30, -1, -7], [-18, -4, 16], [16, 4, 14], [26, -6, 8], [0, 0, -2], [5, 7, -10], [-7, 4, -3], [35, -2, 5], [28, 2, -2], [-8, 8, -12], [-12, 1, 3], [-10, 1, 5], [4, 9, 7], [-26, 6, 0], [0, 4, -14], [4, 5, 3], [-10, -1, -19], [-26, -1, 9], [-21, -8, 3], [8, 4, -8], [-28, 0, -14], [34, 1, 9], [55, 2, 5], [-15, 4, -9], [-16, -2, -6], [-32, -3, -1], [-14, -2, -6], [1, -8, -1], [8, -12, 8], [-28, 6, 6], [-24, 0, 12], [-38, -5, 7], [-7, 7, 2], [52, -1, 3], [46, 1, 3], [-18, 0, 12], [-35, -4, 11], [57, 2, -1], [-28, -6, 8], [64, -2, 2], [14, 2, -2], [-7, -4, 19], [12, -10, -6], [-30, -8, -8], [-3, -4, -5], [-15, -4, -19], [-29, -8, -19], [9, -1, 10], [-5, 0, 3], [-14, 0, -8], [10, 1, 9], [-10, 13, -3], [48, 2, 6], [-18, -1, 9], [4, -2, 14], [19, 0, 15], [22, 7, -19], [-12, -10, -6], [16, 2, 6], [6, 8, -4], [26, 0, -4], [-46, -5, -5], [-4, -4, 16], [-39, -4, 1], [10, -2, -4], [46, -1, 3], [8, -2, -4], [10, -2, 2], [11, -7, -6], [-10, 12, -12], [-4, 8, -2], [18, 2, 12], [36, 6, -12], [-12, 12, -10], [12, -14, 2], [28, 0, 12], [14, -5, 15], [26, -4, 4], [-20, -5, -15], [-18, -10, 2], [10, -2, -8], [9, 0, 15], [54, -3, 7], [4, -2, 26], [12, 8, -18], [11, 8, 7], [30, 6, 14], [48, 0, -4], [-18, 6, -2], [-48, -2, -2], [8, 6, 8], [-14, 8, -2], [46, 2, -6], [40, 0, 4], [-21, 2, 1], [-4, 14, -10], [20, 10, -18], [-43, -6, 11], [-31, 7, 2], [-26, -5, 9], [-36, 4, -14], [16, -2, -2], [-16, 6, -6], [39, -6, -3], [21, 7, 10], [-27, 4, 7], [24, 0, -6], [22, 9, -17], [-8, 6, 2], [5, 6, -1], [-10, 5, -5], [0, 6, -18], [8, 8, -12], [6, -2, 14], [12, -8, -2], [50, -11, 1], [-70, -4, 8], [56, -2, -6], [-24, -8, 12], [42, 1, -11], [-54, -3, 3], [-44, 12, 0], [2, 6, 6], [-16, 4, 12], [50, 3, 11], [-7, 4, 5], [-5, 4, -1], [-7, 10, -1], [15, -10, -7], [-8, 4, -16], [-14, -11, 9], [28, 8, -18], [-13, -11, -10], [27, -15, 6], [-22, 2, -4], [19, 4, 19], [-20, 1, -3], [-31, 5, 4], [-22, 8, -4], [-3, 0, -15], [-36, -4, 20], [26, -4, 18], [-2, -3, -17], [-24, 10, 8], [-60, 0, -4], [24, 3, 9], [-22, -5, -17], [-30, 2, 14], [-32, -7, -1], [8, -8, 0], [36, -4, 0], [52, -9, 1], [28, 4, 14], [58, 2, -4], [22, 4, -12], [-4, -4, 22], [-52, -6, -2], [-8, 4, -4], [41, 6, -5], [2, 7, -15], [0, -10, 2], [26, -3, 15], [68, -6, 0], [-5, 0, -17], [-18, 5, -19], [29, 4, 11], [8, 3, -7], [-12, -12, 0], [-14, -6, -14], [16, 5, -13], [6, 1, 19], [21, -8, -5], [-12, 4, -6], [15, 8, -13], [-38, -3, 13], [66, 2, 2], [36, -2, 18], [52, 0, -8], [44, 2, 24], [-34, 2, -20], [-2, -7, -11], [-3, -15, 12], [23, -10, 9], [-2, 3, -17], [-20, -2, -12], [20, 6, 0], [-16, -10, 26], [-42, -8, 6], [34, 4, -10], [0, -10, -10], [56, -3, 3], [60, -4, 8], [5, 8, -15], [-72, 0, 6], [53, 3, 10], [2, 4, 18], [-50, 0, 0], [-36, -9, -19], [-68, -1, -5], [-7, -5, 18], [62, 6, 8], [-27, -2, -5], [18, -14, 14], [36, 8, 2], [-32, 7, -3], [-47, -8, -1], [0, -3, -13], [52, -7, 3], [-70, -1, -13], [58, 2, 4], [26, 6, -28], [-82, 0, 0], [13, 3, -6], [-12, 6, 4], [28, 12, -16], [54, 4, -2], [-22, -8, 12], [-50, -8, 10], [36, 2, -18], [24, 0, 12], [3, 3, 24], [-2, 4, 12], [4, 0, 16], [14, 5, 9], [-2, -2, 2], [41, -4, 15], [48, 2, 2], [-40, -6, -4], [24, -6, -16], [-33, -10, -7], [-24, -6, -4], [24, 12, 6], [51, -4, 13], [-18, 6, 0], [-20, -4, -14], [-34, -10, 28], [16, -6, 6], [-28, 4, -8], [-18, -5, 3], [-58, -4, -2], [-6, -11, 23], [-26, 14, 6], [0, -2, -26], [16, -11, -5], [8, 0, 4], [24, -4, 14], [-10, 2, -24], [14, 9, 3], [-70, 2, -2], [-32, 10, 10], [32, 4, 6], [22, 9, -19], [-18, -6, -14], [4, 9, 7], [-32, 3, -5], [-9, 16, -3], [64, 3, 17], [-23, 7, 10], [-33, 8, -7], [-12, 6, 18], [-49, -4, 15], [-16, 12, -10], [-4, 7, -5], [66, 1, 11], [39, 4, 31], [-68, 5, -1], [20, 1, 9], [25, 4, -17], [20, -6, -12], [78, -3, 7], [56, -4, 10], [-10, -5, 9], [53, 0, 1], [33, 4, -5], [18, -4, 16], [-18, 4, -8], [28, -6, 22], [-31, -8, -15], [70, 7, 15], [-4, -6, 2], [2, -15, 9], [2, -15, 5], [-1, 8, 15], [6, 14, -4], [-19, -2, -25], [20, -1, 1], [-52, 8, 2], [-16, 3, 3], [-82, -2, 0], [68, 0, -10], [33, -4, -17], [77, -4, 7], [28, 8, -6], [28, 0, 8], [22, 0, 26], [44, 4, -12], [-16, 4, 20], [64, -2, 8], [-4, 4, 6], [15, -3, 2], [47, 5, -2], [-42, 16, 4], [114, 1, 1], [62, 3, -5], [42, -1, -9]];
    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_dy();".
// 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_dy(:prec:=3)
    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_dy();".
// 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_dy( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9702_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-12, -10, 2, 1]>,<13,R![16, -44, 0, 1]>,<17,R![-12, -10, 2, 1]>,<19,R![-188, -6, 10, 1]>,<23,R![48, -56, -2, 1]>,<29,R![-96, -32, 6, 1]>],Snew);
    return Vf;
end function;