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