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