
// Make newform 7098.2.a.r in Magma, downloaded from the LMFDB on 17 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_r();".
// 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_r();".
// 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], [1], [0], [-1], [-1], [-6], [9], [-2], [2], [-5], [-2], [7], [-1], [-10], [-11], [-2], [8], [-8], [11], [12], [-11], [14], [-2], [-14], [3], [-16], [-6], [-12], [-8], [10], [-9], [-6], [3], [2], [-2], [0], [8], [-12], [-19], [4], [11], [-27], [10], [-6], [-20], [-2], [23], [18], [12], [-16], [-8], [-9], [-28], [16], [-2], [-2], [20], [-28], [-20], [-19], [-15], [-12], [-30], [-26], [-33], [-3], [6], [-26], [30], [-14], [0], [0], [-9], [22], [21], [-6], [-20], [-20], [26], [-28], [-18], [-20], [35], [30], [6], [24], [-1], [8], [-11], [29], [0], [30], [-8], [12], [19], [-11], [16], [32], [3], [34], [0], [-20], [-12], [26], [3], [-30], [2], [-46], [-28], [12], [-11], [33], [2], [43], [39], [-49], [9], [26], [-41], [-4], [4], [32], [1], [-24], [15], [-52], [-43], [38], [42], [23], [-36], [-10], [46], [-54], [29], [52], [-28], [36], [45], [-16], [-16], [19], [-8], [53], [18], [49], [50], [20], [2], [46], [-21], [34], [40], [29], [-13], [-4], [-32], [19], [-30], [32], [-58], [-36], [48], [45], [-35], [-34], [-4], [27], [-15], [-38], [-54], [-38], [-3], [10], [1], [24], [1], [-16], [20], [-34], [15], [-54], [52], [34], [41], [-10], [9], [-2], [12], [14], [-20], [28], [-3], [-9], [-54], [-18], [5], [27], [18], [-58], [-4], [8], [38], [-20], [-52], [-30], [29], [31], [-24], [61], [-12], [-35], [-6], [-3], [-9], [32], [-71], [-60], [-58], [44], [-59], [66], [10], [67], [-12], [22], [12], [-66], [39], [-5], [54], [37], [-3], [-22], [3], [64], [69], [-5], [-11], [18], [-40], [-11], [-27], [-48], [24], [48], [-42], [16], [-5], [-58], [56], [-18], [39], [18], [-44], [18], [-50], [-47], [-51], [5], [65], [69], [36], [15], [-18], [52], [51], [-38], [-36], [-34], [-15], [-62], [-12], [3], [8], [-83], [0], [84], [-8], [31], [35], [-32], [-18], [51], [71], [34], [-42], [-35], [-14], [56], [0], [50], [36], [-74], [-24], [72], [13], [50], [-3], [-61], [-36], [32], [-65], [-39], [59], [-66], [50], [-61], [10], [54], [56], [-30], [-74], [0], [-36], [82], [16], [-35], [45], [90], [1], [48], [16], [74], [28], [-64], [54], [42], [-14], [-50], [-4], [-52], [58], [76], [-14], [-64], [22], [-16], [-18], [48], [44], [75], [-52], [-43], [-70], [-49], [-34], [-75], [-67], [6], [8], [-36], [-27], [48], [-24], [24], [-48], [2], [-85], [-96], [95], [-53], [-95], [-30], [-23], [13], [-35], [99], [14], [-17], [50], [-28], [-6], [66], [20], [6], [28], [66], [-16], [-19], [-40], [-24], [83], [36], [6], [24], [49], [-94], [-66], [41], [-53], [-52], [-58], [-14], [71], [26], [1], [-6], [16], [-15], [-25], [-72], [102], [-12], [30], [-59], [-34], [84], [-102], [-76], [-72], [27], [40], [32], [6], [41], [-15], [-89], [-89], [82], [56], [6], [-98], [41], [30], [-8], [69]];
    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_r();".
// 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_r(: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_r();".
// 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_r( : 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![-1, 1]>,<17,R![1, 1]>],Snew);
    return Vf;
end function;