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