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