
// Make newform 7098.2.a.bk in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7098_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_7098_2_a_bk();".
// 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_7098_2_a_bk();".
// 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 := [-32, -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_7098_a();"
function MakeCharacter_7098_a()
    N := 7098;
    order := 1;
    char_gens := [4733, 5071, 6931];
    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_7098_a_Hecke(Kf)
    return MakeCharacter_7098_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], [-1, 0], [2, 0], [1, 0], [-1, 1], [0, 0], [5, 0], [3, -1], [-2, -1], [3, -1], [2, -1], [-2, 0], [1, 1], [6, 1], [1, 1], [-3, 0], [6, 1], [-3, 0], [10, -1], [-4, 1], [-4, 0], [7, 1], [0, -1], [-9, 0], [-2, 2], [-6, 2], [-2, -1], [13, 1], [-4, 0], [6, 2], [12, 0], [4, -3], [6, -2], [-13, 1], [-10, -1], [-1, -3], [2, 0], [14, 1], [8, 0], [4, 0], [-4, 2], [13, 1], [12, -3], [-5, 3], [-17, 0], [18, 1], [6, -2], [-4, 1], [2, 2], [-1, 0], [10, 2], [-4, -1], [8, -2], [16, 1], [5, -4], [-12, 0], [8, -2], [-26, 1], [18, -2], [-16, -2], [20, -2], [-12, 0], [1, 5], [7, 3], [4, 0], [-2, 1], [14, -2], [15, 3], [-13, -1], [-2, -1], [2, -1], [-2, 2], [-2, -1], [-20, 0], [0, 4], [-15, -1], [-6, -1], [-3, 0], [-22, 2], [24, 2], [4, -5], [14, -4], [-4, -1], [22, 2], [16, 4], [-3, 1], [14, 0], [6, -5], [4, -4], [3, -5], [8, -5], [35, 1], [33, -1], [0, 0], [-2, -1], [-24, 0], [-8, 4], [1, 1], [-7, 3], [8, 2], [36, 0], [1, -4], [-6, -2], [-16, 2], [-28, -1], [16, 2], [6, -1], [33, 0], [34, 1], [-22, 0], [18, -3], [-28, 2], [-32, 0], [-7, -3], [5, -5], [-10, 6], [15, -1], [17, 5], [21, 0], [-1, 3], [2, -3], [-1, 0], [12, 0], [4, -2], [40, 0], [3, -4], [16, 0], [-31, -1], [16, 3], [5, -4], [10, 1], [-38, 1], [-5, -5], [-8, -2], [-6, 8], [-6, -2], [10, -4], [17, -1], [0, 0], [-20, 0], [-12, 4], [-25, 4], [8, 4], [16, 4], [3, -1], [-24, 2], [-3, -4], [14, -4], [-11, 5], [-26, 2], [28, 2], [30, -3], [-22, 3], [-27, -3], [-6, 9], [4, 4], [-15, -7], [-39, 0], [-16, 6], [20, 0], [-3, 7], [22, -4], [-24, 2], [-22, -1], [-12, 0], [-24, 6], [-31, -3], [37, -4], [-18, -1], [16, 4], [21, -5], [17, -3], [2, 2], [18, 3], [-10, 2], [15, -4], [-10, -1], [-13, 4], [-12, 7], [-31, 0], [8, -4], [-8, -1], [22, 0], [-3, -8], [18, -5], [-28, -4], [6, 0], [37, -3], [-2, -8], [-25, 5], [34, 0], [12, -6], [-34, -5], [-8, -6], [-4, -4], [-17, -1], [-17, 3], [46, 0], [-14, 1], [11, 5], [1, 4], [2, 5], [-10, 4], [28, 4], [28, 4], [30, -6], [-28, 4], [-20, -2], [-38, 4], [-7, 9], [-41, -4], [-4, -2], [-7, -1], [-16, -3], [3, 9], [26, -2], [49, -3], [21, 4], [-32, 0], [27, -1], [4, 0], [42, -2], [-48, 0], [9, 7], [-6, -3], [-14, -4], [1, -4], [-40, -5], [-14, -2], [12, -12], [14, -4], [-37, 1], [15, -11], [34, -2], [-31, 3], [27, 3], [-42, -2], [-39, 0], [0, 6], [27, 5], [21, -1], [-23, -1], [-14, 5], [-44, 4], [23, -8], [-29, 1], [-8, 4], [-20, 0], [32, -5], [-2, -2], [28, 2], [25, 1], [38, -1], [-28, -2], [22, -4], [41, -5], [58, 2], [44, 2], [-18, -4], [-6, 2], [13, 3], [35, 7], [21, 1], [-7, -8], [-49, -4], [-20, 6], [45, 0], [10, -1], [20, 3], [-39, 0], [-30, -3], [-44, -3], [-18, 6], [53, 3], [54, 2], [24, 0], [5, -11], [32, -4], [-35, -4], [-48, 3], [44, -4], [-32, 10], [41, 5], [-45, -1], [24, 6], [14, -3], [-29, -8], [21, -7], [-18, 5], [18, 3], [7, 4], [-6, -6], [-36, -6], [24, 1], [-22, 0], [16, 4], [14, -6], [4, 10], [-4, 11], [-15, -3], [-10, 4], [31, 4], [-25, 7], [-12, -6], [-24, 7], [-41, 0], [-1, -11], [-29, -4], [2, -14], [2, 6], [-35, 7], [38, -9], [-74, 0], [8, 3], [-42, 1], [-18, -2], [-28, 8], [52, -1], [-58, -2], [-68, -2], [17, -3], [-67, 0], [-22, 2], [-51, 1], [-4, -6], [24, 4], [-46, -2], [60, 4], [48, -8], [-6, -5], [-6, 14], [38, 0], [42, 6], [4, 3], [-12, -5], [-6, 10], [-28, -4], [46, 5], [-64, -2], [6, -13], [-32, 12], [34, -2], [-4, -4], [36, 0], [-7, 8], [-44, 4], [5, 12], [6, 5], [-15, -9], [-30, 0], [41, -5], [37, -3], [-30, 0], [8, -16], [16, 0], [7, -1], [0, -8], [-36, 0], [12, -2], [36, -7], [-66, 4], [-7, 9], [32, -5], [17, 7], [7, -3], [-31, 0], [-42, 0], [-27, 9], [21, -4], [-37, -3], [-25, -5], [14, 5], [-43, 4], [-58, -5], [16, 12], [46, -5], [-10, 9], [-68, -4], [2, 0], [-36, 10], [26, 8], [-8, -4], [-79, 3], [40, 4], [16, 8], [13, 5], [-52, 4], [-10, 13], [-8, -13], [-49, 3], [-38, -9], [18, -12], [7, -3], [-25, -3], [12, 7], [38, -1], [-58, -6], [-27, 13], [-2, 7], [-37, -8], [-6, -7], [8, 2], [-19, 3], [29, -3], [4, 10], [14, 3], [4, -4], [-50, 4], [-7, 1], [46, 3], [-12, 8], [6, 7], [-12, -2], [-56, 7], [-29, 11], [16, 8], [-4, -8], [10, -15], [-13, 8], [-1, 1], [5, 0], [-9, -13], [2, -11], [-16, -1], [-70, 4], [-22, -6], [95, 1], [46, 4], [32, 2], [-13, 9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7098_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7098_2_a_bk();".
// 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_7098_2_a_bk(:prec:=2)
    chi := MakeCharacter_7098_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_7098_2_a_bk();".
// 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_7098_2_a_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7098_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 1]>,<11,R![-32, 1, 1]>,<17,R![-5, 1]>],Snew);
    return Vf;
end function;