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