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