
// Make newform 4598.2.a.b in Magma, downloaded from the LMFDB on 28 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_4598_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_4598_2_a_b();".
// 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_4598_2_a_b();".
// 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_4598_a();"
function MakeCharacter_4598_a()
    N := 4598;
    order := 1;
    char_gens := [3269, 3631];
    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_4598_a_Hecke( : Kf := Kf)
    return MakeCharacter_4598_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], [-1], [-2], [3], [0], [-1], [7], [-1], [-5], [-1], [10], [-6], [-6], [4], [0], [-1], [3], [12], [3], [-10], [-3], [-8], [-8], [-8], [8], [-6], [12], [13], [13], [-12], [-16], [22], [-17], [14], [18], [-12], [-22], [-2], [22], [-14], [4], [-2], [3], [4], [12], [23], [-1], [10], [15], [20], [10], [-25], [4], [-6], [-22], [-4], [18], [15], [16], [-16], [14], [9], [16], [3], [21], [21], [29], [20], [26], [-10], [1], [17], [16], [-11], [-5], [2], [18], [34], [-2], [-34], [10], [15], [-34], [24], [14], [18], [24], [37], [8], [16], [20], [12], [-12], [-10], [-28], [19], [-34], [-20], [21], [16], [-8], [6], [-24], [12], [14], [23], [-12], [-42], [-4], [-8], [22], [28], [-30], [-20], [-8], [40], [-26], [3], [4], [-11], [29], [24], [29], [-8], [-14], [-24], [-26], [-33], [47], [14], [28], [0], [-50], [38], [11], [49], [-23], [-49], [19], [13], [25], [16], [-43], [-37], [25], [40], [-6], [30], [-30], [-6], [-27], [42], [-44], [4], [13], [-6], [-3], [29], [5], [-33], [-48], [-60], [-32], [-44], [-60], [-46], [44], [10], [24], [40], [33], [-57], [-48], [35], [-46], [30], [8], [-52], [-34], [-8], [-7], [1], [22], [16], [43], [0], [17], [44], [-54], [27], [-40], [56], [-60], [-35], [-48], [24], [45], [48], [43], [9], [38], [-32], [-57], [-62], [6], [-18], [-61], [-29], [9], [7], [-7], [-68], [8], [57], [-54], [8], [7], [28], [42], [18], [-6], [-4], [42], [11], [57], [-46], [68], [64], [42], [-32], [-26], [-17], [-16], [28], [-52], [-3], [-58], [74], [0], [30], [-36], [0], [57], [-53], [8], [-48], [16], [52], [-44], [3], [16], [-21], [-33], [-34], [-54], [50], [-52], [-28], [-26], [78], [34], [-20], [48], [-13], [58], [23], [9], [7], [-43], [60], [-1], [13], [17], [5], [8], [-27], [4], [59], [-70], [-76], [-42], [7], [-29], [47], [20], [24], [5], [-10], [25], [52], [-32], [-42], [-12], [44], [-50], [-42], [32], [16], [-63], [-12], [46], [53], [63], [63], [56], [42], [27], [-59], [-64], [40], [36], [72], [0], [-44], [40], [86], [12], [62], [43], [66], [-35], [27], [75], [90], [-1], [48], [-37], [45], [4], [62], [64], [-11], [-29], [50], [-70], [42], [-3], [-68], [23], [-43], [-15], [27], [3], [64], [-13], [-68], [-56], [73], [12], [24], [-68], [-22], [70], [30], [-10], [-28], [-13], [88], [-89], [-66], [-22], [-10], [42], [11], [-62], [26], [-78], [26], [-6], [60], [-31], [-69], [-5], [8], [74], [-75], [48], [62], [25], [-8], [94], [-26], [65], [-30], [-49], [-18], [-31], [-36], [66], [-42], [-90], [57], [-2], [12], [-30], [102], [-60], [0], [12], [62], [-34], [90], [0], [74], [-26], [-5], [46], [-48], [-31], [48], [-62], [-48], [-77], [80], [-51], [-92], [-10], [-50], [43], [26], [-10], [73], [-83], [-23], [-106], [77], [27], [23], [-102], [99]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4598_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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