
// Make newform 7098.2.a.bt in Magma, downloaded from the LMFDB on 23 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_bt();".
// 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_bt();".
// 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 := [-4, -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], [0, -1], [1, 0], [-1, 1], [0, 0], [-3, -2], [-1, 1], [2, 2], [-3, 2], [0, 0], [-4, -1], [-5, 4], [-8, 0], [-5, -3], [7, 0], [2, -2], [-5, 4], [6, -2], [-2, 6], [-4, -1], [-5, 1], [-2, 2], [5, 1], [-4, -2], [2, 5], [0, -4], [3, -7], [-6, 4], [0, -1], [0, -8], [8, -4], [14, 1], [-7, -1], [-14, 1], [-11, 7], [-6, -3], [12, -8], [0, -8], [-18, 0], [-8, -4], [7, -4], [-2, 2], [-3, -2], [11, -1], [-16, 0], [2, -2], [16, 4], [-14, -2], [3, -9], [-8, -6], [10, -6], [-8, -5], [2, 10], [-15, 6], [2, -2], [24, -2], [-4, 12], [-18, 1], [2, -7], [-20, 0], [4, 7], [1, 7], [11, -7], [-6, 0], [14, 1], [10, -6], [-1, 8], [1, -9], [-18, 0], [-26, 5], [-8, -4], [-2, -10], [-14, -7], [22, -10], [-5, 5], [-10, -3], [17, -7], [6, 5], [-10, 1], [14, -6], [-2, 13], [10, -6], [-26, -3], [-20, 4], [-13, 9], [-16, -6], [18, -7], [-8, -9], [17, 3], [-12, 16], [9, 7], [19, -3], [-4, 8], [24, -4], [-16, 8], [-34, 5], [29, 2], [-9, 5], [2, -11], [-18, 10], [9, -2], [-12, -4], [-22, 0], [-18, 2], [-34, 1], [-4, -4], [-9, 16], [2, -14], [8, -13], [-24, 16], [20, -1], [6, -11], [13, 7], [-21, -7], [10, 1], [43, -3], [-23, -9], [19, -1], [13, 7], [-6, 9], [-9, -4], [-6, 12], [28, -8], [-8, 16], [-19, 13], [-18, 13], [-7, -5], [40, 0], [-7, 14], [6, -6], [8, 8], [-33, 5], [34, -12], [26, -16], [8, 2], [2, -12], [17, 11], [38, -8], [-2, -7], [24, 0], [7, -13], [-32, 4], [28, -4], [9, 6], [12, -4], [21, -6], [18, 1], [7, -7], [38, -2], [-2, 17], [34, 9], [-20, 0], [-23, -9], [2, 2], [-2, -10], [-35, 7], [-9, -4], [-36, -1], [-20, -6], [57, -1], [16, 2], [-16, 8], [26, -10], [-24, 11], [0, -12], [1, 19], [-17, 16], [30, 4], [-24, 15], [-7, -17], [41, -2], [22, 6], [18, 13], [20, 8], [-29, 16], [-14, -2], [19, 16], [10, 2], [55, -5], [16, -8], [0, 0], [42, 9], [-37, 3], [0, 8], [-16, 7], [22, -24], [-39, -1], [-6, -15], [-23, -1], [22, -15], [-12, -8], [-22, 26], [-24, -2], [20, -16], [63, -1], [-43, 10], [38, -11], [46, -3], [-9, -3], [13, -22], [-14, -6], [-38, -11], [-10, 1], [28, -12], [18, 5], [-28, -4], [20, -4], [30, -3], [-1, -23], [-5, 0], [-26, 0], [61, -1], [8, 4], [17, -5], [-16, 7], [1, 7], [9, 10], [46, -6], [63, 3], [44, -5], [-22, -6], [30, -19], [15, -31], [28, 8], [-8, -13], [-47, -6], [22, -10], [-34, 14], [-20, 32], [2, 21], [-43, -1], [-19, 35], [-16, -21], [-1, -3], [-47, 11], [26, 8], [25, -14], [36, 4], [3, 9], [9, -9], [-9, 9], [38, -10], [-36, 11], [-15, 14], [35, -23], [-6, -14], [8, -12], [30, 2], [26, 14], [-44, 18], [-5, 27], [-6, 2], [16, -13], [46, 0], [-39, 15], [0, -18], [16, 0], [18, -28], [-36, -5], [9, -9], [-27, 11], [-51, 2], [-5, 28], [-31, -6], [-20, 20], [5, 21], [34, 5], [-6, -6], [-45, 4], [-14, 33], [-44, -8], [0, 11], [57, -1], [-32, 26], [-34, -10], [49, -9], [-28, -13], [-13, -24], [-58, 14], [-12, -8], [-48, -12], [-31, 7], [39, 0], [28, -8], [42, -10], [59, 0], [-19, 10], [-14, -10], [38, -3], [-3, -19], [52, -4], [-18, 13], [-2, 22], [-12, -14], [-8, 15], [-36, -16], [18, 5], [-26, -10], [37, -17], [-24, 7], [47, -8], [19, -39], [-36, 4], [2, 14], [-47, 26], [-7, 35], [-31, 34], [58, -10], [-80, 3], [33, 15], [6, 0], [-38, 33], [-32, -4], [-20, -12], [0, -13], [18, 18], [-36, 12], [-36, 14], [28, -21], [-25, 21], [-9, 7], [8, 3], [15, -15], [-20, -26], [-8, -5], [-24, 12], [-28, 8], [-70, 2], [-10, -15], [-20, -17], [-46, 9], [2, -14], [2, 2], [28, 0], [-28, 4], [-48, 19], [-22, 8], [-20, 31], [-46, -18], [24, 6], [-6, -11], [30, 17], [-24, 16], [13, -19], [28, -36], [23, -16], [-24, 32], [-13, -11], [-64, -2], [1, -17], [-13, 27], [30, -39], [-2, 10], [-20, -21], [31, -28], [-24, -4], [18, -14], [28, 7], [8, 24], [-46, 21], [9, 26], [-62, 22], [45, 3], [49, -1], [13, -23], [4, -30], [11, 17], [-7, -26], [5, 11], [-43, 19], [-14, 14], [-49, -12], [-22, 14], [-84, -5], [-2, 22], [-14, -14], [-18, 4], [-14, -19], [66, 5], [-78, 12], [-8, 7], [-53, 9], [38, -20], [4, -8], [43, 17], [-4, -20], [-6, -20], [-4, 4], [-13, -35], [34, 17], [20, -13], [-45, 25], [-55, 11], [4, -16], [34, 24], [18, 2], [-75, 17], [8, -8], [-69, -8], [-30, -20], [-2, 36], [3, 1], [19, -4], [44, -13], [-10, -18], [16, 22], [-10, -19], [57, -29], [-6, 6], [-30, 21], [-18, -31], [52, -16], [60, 12], [-33, 20], [70, 13], [40, 12], [-2, 26], [-63, 13], [7, -3], [-61, 8], [-1, -4], [24, -20], [-18, 34], [54, -28], [46, -3], [-3, 27], [-28, 7], [32, 0], [27, -3]];
    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_bt();".
// 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_bt(: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_bt();".
// 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_bt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7098_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 1, 1]>,<11,R![-4, 1, 1]>,<17,R![-1, 8, 1]>],Snew);
    return Vf;
end function;