
// Make newform 7098.2.a.i 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_i();".
// 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_i();".
// 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], [-2], [-1], [3], [0], [-7], [-5], [6], [5], [-2], [-2], [-5], [2], [-1], [3], [-6], [7], [2], [8], [12], [3], [-8], [-11], [-2], [14], [10], [15], [-16], [6], [-12], [8], [18], [-19], [14], [13], [-18], [-14], [0], [12], [20], [-9], [-4], [13], [-9], [-26], [-10], [-4], [14], [27], [26], [12], [28], [-12], [-15], [-24], [-24], [2], [6], [16], [28], [12], [9], [23], [28], [30], [22], [-17], [17], [-18], [14], [18], [-10], [4], [-20], [31], [6], [-15], [18], [0], [4], [-22], [-8], [26], [4], [15], [-38], [26], [8], [-31], [-12], [21], [35], [-8], [14], [24], [-40], [21], [39], [20], [-32], [-15], [30], [-44], [-12], [20], [10], [-13], [-26], [38], [-30], [-28], [-20], [41], [15], [18], [-49], [1], [27], [-27], [-14], [23], [0], [36], [40], [13], [-28], [-15], [0], [-7], [-14], [-6], [-33], [32], [-18], [46], [-10], [25], [56], [52], [-4], [15], [-48], [-8], [-7], [-24], [41], [6], [35], [34], [40], [-26], [-14], [37], [-38], [-52], [-11], [-13], [52], [0], [-31], [-14], [32], [22], [8], [-32], [-3], [7], [34], [-36], [1], [-27], [50], [38], [22], [-29], [58], [27], [-52], [-37], [-24], [60], [-14], [7], [-30], [-56], [30], [-27], [-30], [9], [38], [-52], [-62], [-32], [12], [11], [-63], [-26], [-18], [27], [-7], [38], [-2], [8], [12], [-42], [-8], [-36], [-58], [-49], [-25], [16], [-19], [12], [69], [-46], [29], [-39], [48], [-29], [28], [-26], [24], [27], [-2], [-34], [37], [0], [-26], [-20], [2], [-19], [45], [2], [15], [-43], [6], [57], [8], [-5], [49], [7], [62], [48], [29], [-29], [4], [36], [20], [-74], [-44], [-37], [-38], [-32], [42], [-67], [-54], [44], [-2], [-46], [-31], [-23], [25], [75], [13], [60], [-19], [-10], [-32], [15], [22], [12], [-46], [9], [14], [-40], [-15], [-44], [19], [-32], [12], [80], [41], [-65], [8], [-46], [-29], [21], [-2], [18], [57], [58], [-24], [4], [-10], [-56], [-22], [-72], [24], [33], [34], [-89], [67], [-4], [36], [1], [-3], [73], [-50], [-34], [-27], [-66], [10], [-28], [-22], [-70], [12], [40], [34], [40], [-25], [59], [-30], [71], [-28], [-80], [70], [28], [-88], [-42], [42], [18], [86], [56], [-88], [62], [-28], [-6], [72], [-6], [4], [-62], [-40], [-20], [81], [-36], [79], [34], [-9], [78], [-15], [-93], [34], [-80], [-60], [19], [-48], [48], [-24], [-24], [-78], [-43], [-96], [45], [-63], [-23], [-34], [-57], [69], [9], [49], [58], [-13], [2], [-8], [26], [90], [-56], [42], [4], [-78], [-48], [-5], [-12], [-16], [19], [28], [42], [52], [-73], [6], [42], [11], [-7], [-96], [-26], [22], [-31], [-62], [-29], [-70], [44], [103], [39], [-4], [10], [-32], [-26], [25], [-34], [20], [18], [92], [100], [43], [-64], [28], [30], [-15], [-33], [-5], [-77], [22], [-32], [-26], [-42], [-3], [-54], [64], [-29]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : 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![-3, 1]>,<17,R![7, 1]>],Snew);
    return Vf;
end function;