
// Make newform 1098.2.a.m in Magma, downloaded from the LMFDB on 22 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1098_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_1098_2_a_m();".
// 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_1098_2_a_m();".
// 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
        poly := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1098_a();"
function MakeCharacter_1098_a()
    N := 1098;
    order := 1;
    char_gens := [245, 307];
    v := [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_1098_a_Hecke(Kf)
    return MakeCharacter_1098_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]];
    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, 0], [0, 0], [1, -2], [-2, 1], [-2, 1], [4, -1], [1, 1], [4, 0], [5, 0], [2, -2], [4, 0], [1, 3], [-8, 1], [-1, 1], [-4, 2], [-6, 2], [8, 1], [1, 0], [-8, -3], [-3, 7], [7, -6], [-2, 7], [3, -5], [-11, 3], [-5, -1], [0, 4], [3, -1], [-7, 1], [8, 1], [0, 1], [-7, 5], [1, -3], [-4, 9], [1, -8], [-10, -1], [2, 3], [-14, -4], [-8, -4], [2, 4], [10, 4], [11, -3], [15, -5], [-8, -3], [16, 2], [14, 5], [9, 1], [-12, 8], [2, -1], [10, -1], [-14, 5], [-2, 2], [-2, 6], [-7, 8], [-2, -6], [-4, 6], [-28, 0], [-22, 0], [-1, -11], [-6, -8], [6, 2], [12, -10], [5, -11], [17, -8], [4, -5], [2, 10], [25, 1], [-5, 0], [-14, 10], [9, -13], [7, -9], [-26, -3], [-1, 1], [-8, 0], [9, -1], [4, 4], [-4, -1], [2, -4], [7, 11], [1, 1], [8, 0], [4, 0], [-7, -3], [-6, -12], [16, 2], [-21, 1], [-9, -3], [22, -1], [30, -2], [-9, 11], [27, 1], [-16, 15], [-2, -6], [8, -4], [-8, 8], [7, -6], [-16, -6], [-16, 10], [6, -8], [-13, 20], [1, -5], [0, 3], [30, -10], [8, -6], [-16, 5], [-4, -10], [8, 6], [18, -14], [-5, -5], [-13, 4], [13, -8], [11, 1], [-8, -14], [21, -3], [10, -8], [10, 9], [35, 1], [-13, -7], [7, -2], [16, -2], [-5, -13], [-30, -2], [14, 12], [20, -14], [-39, 3], [18, 6], [2, 16], [-5, 7], [-4, -8], [-24, 18], [-18, 1], [-9, 10], [27, 6], [-3, -9], [2, -1], [-26, -8], [-36, 10], [-3, -19], [36, -12], [2, 17], [30, -9], [-5, -8], [14, -4], [6, -6], [-1, 9], [-18, -5], [16, 8], [-10, 1], [-38, -1], [-20, 22], [-24, 0], [29, -17], [-10, -15], [5, -24], [-5, 1], [-23, 15], [-16, 12], [-31, -9], [-20, 13], [23, -8], [8, 0], [4, 15], [-27, 1], [33, -11], [-3, -15], [8, 6], [0, -20], [20, 4], [29, -7], [-24, 4], [-28, 0], [-34, -1], [10, 11], [-21, -4], [23, -13], [-4, -15], [8, -9], [-10, -4], [-2, -10], [-4, 5], [11, 7], [12, -7], [-42, -3], [-2, -17], [12, -10], [-12, -4], [-22, -4], [58, -3], [48, 2], [-6, 4], [24, -3], [-4, 4], [12, -4], [-60, 4], [33, -6], [-2, -1], [4, 15], [-1, -21], [15, 17], [-50, 0], [24, 2], [-39, -6], [-32, -8], [-2, 6], [42, -14], [25, 13], [35, 4], [-16, 17], [22, 15], [-1, 15], [23, -4], [43, 10], [35, -14], [13, -19], [8, -4], [33, 0], [-22, -4], [-28, -12], [-44, -1], [-28, 10], [0, -18], [-24, -1], [37, -15], [-5, -7], [3, -15], [30, 7], [7, -3], [42, -12], [20, -8], [22, -18], [23, -29], [-65, 1], [-38, 2], [-2, -1], [19, 7], [20, 0], [1, 12], [-22, 29], [12, -24], [-20, 24], [-10, -16], [28, -20], [-8, 19], [-28, -4], [2, 16], [-5, -3], [34, -12], [5, 3], [-12, -2], [16, 4], [24, 0], [-2, 10], [-22, 12], [7, -19], [42, -22], [29, 1], [52, 1], [-50, 10], [-16, 14], [26, 10], [36, 2], [-41, 5], [-65, -3], [16, 22], [16, 21], [-10, 32], [-28, 0], [14, -13], [34, -12], [12, -8], [15, 22], [2, -6], [-30, 26], [18, 11], [-8, -4], [-6, 6], [7, -11], [-36, -12], [30, -1], [-36, 6], [-44, 6], [35, 0], [-9, -1], [-48, -3], [37, -9], [-11, 3], [30, 12], [12, 10], [-31, -10], [-27, 27], [-2, -12], [-18, 22], [51, 3], [22, -7], [-12, 9], [-28, 7], [-13, 2], [51, -9], [-26, -10], [-12, 24], [3, 16], [26, 4], [22, -8], [11, -9], [32, 3], [24, 21], [9, 28], [-12, -2], [70, -5], [32, -12], [31, -1], [-13, 1], [7, -8], [-7, 31], [-22, 16], [20, 20], [-10, -1], [52, -16], [3, -12], [-49, -6], [-25, 1], [6, -36], [-52, 24], [-20, 14], [4, 28], [-39, -9], [12, 14], [-11, -13], [7, -20], [43, -4], [-6, 2], [-56, 10], [-27, 22], [18, 15], [13, -5], [40, 13], [-12, 9], [-58, 4], [46, -7], [-36, 36], [0, 23], [-2, -25], [29, -27], [-22, 16], [12, -9], [-17, 12], [-12, -31], [3, -35], [-75, 2], [-49, 24], [9, -4], [53, 8], [-8, -20], [50, -14], [-33, 11], [-22, -28], [-30, 17], [26, -2], [-30, 30], [35, 5], [-45, 14], [44, -3], [-34, -15], [8, -1], [4, -32], [14, -6], [48, 4], [-12, 14], [34, -2], [-35, -10], [-36, 0], [-32, -21], [68, -2], [59, 11], [-60, -12], [34, 16], [-62, 21], [-47, 12], [-34, -14], [18, -21], [36, 16], [4, -6], [-6, -2], [50, -13], [24, 2], [-32, 14], [59, -8], [23, 21], [-7, 21], [56, -4], [24, 22], [-38, -1], [5, -6], [65, 9], [-8, -11], [-42, 12], [-16, -16], [26, 27], [2, -19], [10, -6], [39, -6], [-6, 17], [51, -9], [68, -6], [35, -35], [-4, 20], [-57, 19], [-34, -21], [10, 5], [38, -36], [36, 4], [-58, 17], [-18, -14], [32, -24], [-54, 0], [12, -8], [-12, 18], [-12, 12], [73, -9], [-38, -10], [-22, -22], [-71, 10], [-27, 37], [-2, 8], [-56, 12], [35, -10], [-12, 0], [-20, -11], [-10, 36], [-19, 14], [4, 23]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1098_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1098_2_a_m();".
// 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_1098_2_a_m(:prec:=2)
    chi := MakeCharacter_1098_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_1098_2_a_m();".
// 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_1098_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1098_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-17, 0, 1]>,<7,R![-2, 3, 1]>,<11,R![-2, 3, 1]>],Snew);
    return Vf;
end function;