
// Make newform 7098.2.a.bq in Magma, downloaded from the LMFDB on 18 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_bq();".
// 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_bq();".
// 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], [1, 1], [1, 0], [0, -1], [0, 0], [-5, 0], [0, -3], [-4, -2], [-1, 0], [0, -2], [-3, 5], [1, -2], [-8, 2], [0, 3], [-9, 2], [-8, -2], [-1, 0], [4, -2], [4, 0], [5, -1], [4, -1], [0, 4], [2, 3], [-2, -4], [-17, -1], [4, -6], [-12, 1], [-6, 2], [-1, 7], [-8, 4], [4, -8], [-7, 5], [0, -3], [5, 5], [20, -1], [7, -5], [-4, 2], [0, -8], [-10, 2], [4, -8], [3, 4], [16, -4], [5, 6], [-2, 1], [8, -10], [-8, 2], [-4, 8], [-8, -2], [-10, -5], [-6, 0], [-4, 0], [-19, 3], [-12, 8], [-25, 4], [0, -8], [-10, 2], [-8, -2], [-1, -1], [5, -5], [-12, 8], [-3, 3], [16, 7], [20, 1], [2, 10], [9, 1], [20, 6], [-9, -8], [-8, 3], [-14, 8], [-3, 5], [20, -6], [-4, 6], [19, 1], [20, -8], [-16, 3], [11, 3], [6, -3], [13, -11], [33, -1], [-8, 12], [-11, 1], [-12, 12], [-13, 3], [-8, -8], [4, -15], [-18, 0], [21, -3], [-7, -9], [4, 3], [28, 0], [0, 1], [-16, -3], [-12, 4], [12, 6], [0, 8], [-35, 3], [-17, 0], [28, -5], [1, -1], [8, -12], [9, -12], [-16, 6], [-14, 10], [24, -4], [-39, 3], [-16, -6], [-7, -10], [-28, 2], [19, 7], [16, 2], [-3, -13], [-11, 15], [-12, 3], [-36, 5], [19, 7], [24, 1], [-8, -5], [-6, -5], [-36, 3], [-3, 5], [19, -4], [-34, 10], [-4, 0], [8, 8], [-14, 9], [13, -13], [4, 7], [40, 4], [-7, -10], [-32, -6], [-24, 6], [12, -5], [-2, -2], [22, 8], [-18, 16], [-6, -8], [12, -5], [22, -18], [7, -7], [-16, 4], [30, -7], [4, 4], [32, -8], [-17, 18], [-8, 0], [-15, 6], [11, -13], [-24, -5], [20, -18], [25, -13], [19, 11], [12, 2], [8, -1], [28, -2], [-36, 12], [4, 1], [-19, 10], [11, 1], [-38, -6], [8, -3], [-22, -12], [-16, 8], [-16, 2], [21, -9], [-4, -20], [-4, 1], [-17, 0], [-18, -16], [-49, 5], [8, 13], [-7, 26], [-36, 6], [-15, -3], [-4, -2], [3, -18], [-16, 10], [-35, 18], [20, -12], [18, 5], [16, 16], [-16, -8], [-13, 11], [10, 5], [16, -2], [15, -19], [14, 4], [8, 11], [21, -3], [16, -3], [7, 15], [-20, 8], [4, 6], [42, -6], [12, 0], [-42, -1], [-47, -2], [-21, 19], [-19, -3], [12, -3], [41, 4], [60, 2], [17, 13], [-17, 13], [48, -8], [31, -21], [-40, -8], [40, -12], [61, 1], [8, -17], [11, -12], [30, -18], [-20, 9], [52, -12], [-36, -3], [-31, 1], [-48, 13], [-13, 16], [32, -8], [6, 5], [7, 17], [12, -30], [53, -5], [16, -11], [-4, 10], [-13, -17], [43, -12], [-44, 0], [12, 6], [-28, 0], [55, -1], [-12, -15], [40, 3], [27, -9], [4, -29], [12, -27], [-2, 16], [-59, 8], [-24, 0], [12, -19], [0, -11], [-24, 15], [-4, -6], [41, -9], [65, -8], [12, -19], [36, -8], [-28, 28], [-16, 20], [8, -18], [-22, 22], [34, 9], [-12, -22], [3, -19], [-2, 4], [-32, 17], [22, -12], [-16, 28], [-10, 28], [-31, 5], [16, -23], [-24, 27], [1, -18], [-57, -4], [37, -20], [40, -4], [46, -9], [33, 9], [-12, -12], [55, 6], [3, -17], [36, -24], [-3, 5], [24, -15], [2, 0], [12, 16], [-24, 5], [-7, -17], [-27, 8], [44, -20], [12, 24], [-4, -4], [24, -13], [-23, -24], [-20, 20], [16, 18], [11, -24], [41, -16], [24, 22], [-5, 15], [18, -19], [-8, 18], [37, 3], [-52, -8], [14, 8], [-33, 17], [20, -34], [-25, -7], [-28, 24], [-12, -5], [39, -29], [25, -38], [-4, 15], [0, 4], [56, -4], [5, -22], [-12, 19], [3, 6], [40, -18], [-37, 15], [24, -1], [42, -12], [19, -13], [-44, 0], [8, 26], [-53, -13], [28, 4], [0, -24], [-18, -28], [-33, 33], [20, 3], [66, -9], [-37, 11], [0, 1], [-66, 10], [67, 1], [-28, 14], [-4, -24], [12, -12], [-49, -1], [45, -19], [35, 7], [-76, -2], [20, 12], [-76, -4], [32, -38], [29, -5], [-34, -4], [-43, 23], [40, -6], [18, 2], [23, -21], [49, -25], [16, 4], [-34, -13], [16, 4], [-57, 8], [32, 10], [72, -5], [6, 4], [-16, 15], [-30, 39], [-15, -11], [-40, 0], [55, 13], [-13, -18], [12, 20], [-28, 32], [11, 29], [16, 12], [25, -35], [35, -4], [16, 24], [32, -15], [16, -15], [-42, -9], [2, -4], [-52, -11], [-81, 6], [-24, -13], [16, 25], [48, -18], [3, -34], [0, -10], [-25, 41], [-68, -2], [12, -6], [38, -6], [-9, 27], [-65, 9], [66, -12], [-7, -13], [20, -15], [54, 14], [-84, 12], [12, -29], [-64, -4], [-26, -12], [-24, 4], [-64, 13], [-3, 17], [-39, 37], [-12, -29], [-20, -19], [20, -28], [-54, -4], [-76, 10], [-18, 9], [48, 6], [-19, 2], [50, 4], [-6, 2], [28, 5], [49, -14], [9, -5], [-36, -2], [-6, 30], [21, -23], [-20, -21], [0, 10], [-33, 25], [7, -37], [20, -24], [-24, -20], [-45, 0], [3, 25], [-20, -4], [16, -30], [-6, 7], [20, -15], [-5, -26], [-27, 8], [-28, 6], [-32, 16], [-42, 0], [29, -19], [24, -1], [37, 21], [16, -8], [-40, 1]];
    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_bq();".
// 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_bq(: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_bq();".
// 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_bq( : 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, -3, 1]>,<11,R![-4, 1, 1]>,<17,R![5, 1]>],Snew);
    return Vf;
end function;