
// Make newform 4598.2.a.bf in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_bf();".
// 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_bf();".
// 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 := [-3, 0, 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_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)
    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+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, 0], [-1, 0], [1, 1], [-2, -1], [0, 0], [0, -2], [4, -2], [-1, 0], [-1, 0], [0, 1], [2, 2], [-3, 2], [9, -1], [2, 4], [9, -2], [-3, 4], [1, 6], [-3, -1], [14, 0], [9, -3], [-2, 0], [-3, -3], [9, 3], [7, -3], [10, -2], [1, -9], [-1, 1], [8, 3], [-6, -7], [-3, 1], [-4, 0], [14, -4], [6, -2], [10, 2], [6, 10], [19, -1], [-7, -1], [0, -10], [0, -2], [-8, -7], [-9, -4], [14, -6], [-7, 6], [-16, -2], [-12, -4], [10, -4], [-8, -7], [1, -7], [2, 6], [-2, 6], [10, 1], [2, -7], [-13, -1], [12, 2], [14, 10], [-4, 12], [-9, 12], [-10, -10], [-3, 7], [3, 11], [-18, 2], [0, 7], [0, 9], [-12, -6], [17, 2], [0, 12], [1, -12], [19, -3], [9, 11], [-6, -12], [-3, 2], [-18, 6], [-9, 8], [22, 3], [17, -4], [30, -2], [15, 9], [16, 6], [3, 11], [-10, 2], [-3, 17], [-19, -10], [-15, 5], [-2, -12], [-14, 2], [18, 0], [14, -8], [-4, -17], [23, -3], [26, 0], [6, -16], [30, -1], [-4, -18], [-14, -6], [23, 1], [-8, -5], [27, -4], [0, 10], [-18, -5], [4, 18], [10, 3], [8, 18], [16, -5], [-12, 16], [3, 15], [-2, 18], [5, 21], [14, 7], [-30, -6], [-2, -12], [-5, -1], [-17, 3], [5, 4], [24, -6], [3, 14], [-39, -3], [10, 16], [-17, -8], [-20, -10], [0, 10], [-5, -14], [-1, -9], [-28, 5], [-2, 12], [9, -11], [6, -2], [-4, -8], [-16, 0], [-11, 10], [-12, -4], [23, -5], [16, 2], [-12, 0], [15, 21], [2, -27], [-12, 9], [17, 6], [-6, -11], [22, 6], [14, -3], [0, 27], [23, -11], [-25, -2], [-4, 10], [-16, -20], [-11, -15], [16, -22], [20, 2], [-39, -11], [-36, 4], [-24, 8], [-17, -2], [-9, 9], [-21, 5], [5, -14], [-11, -9], [16, -22], [-13, 26], [-42, -7], [0, 14], [-4, -16], [-11, -15], [14, 13], [17, -2], [-24, -2], [-15, -15], [3, 11], [-19, -5], [-29, -5], [-24, -2], [6, 2], [-1, 30], [40, 0], [24, 5], [26, -8], [9, 20], [-23, 1], [-22, 8], [17, -15], [-31, 15], [17, -18], [-24, 13], [37, 6], [-1, -19], [1, 10], [-15, -19], [16, 9], [-9, -6], [-43, -11], [52, -5], [9, 17], [47, 5], [14, 0], [8, -12], [-13, -5], [-12, 28], [20, -6], [-1, 29], [-24, 7], [0, 18], [-30, 11], [10, -2], [-12, 12], [6, 6], [-8, -16], [-16, 26], [-11, 4], [12, -1], [0, 13], [-15, 26], [38, -3], [-36, -6], [1, -30], [21, -8], [4, -8], [-32, -16], [24, 13], [-18, 10], [39, -17], [13, -27], [-32, 5], [58, 6], [-19, -5], [-2, -20], [-14, -31], [-1, 29], [-35, -11], [6, -6], [26, 2], [33, -3], [22, 10], [-22, 15], [21, 5], [58, 6], [-8, -22], [60, -9], [62, 2], [11, 23], [-51, -7], [11, -9], [29, -6], [11, 11], [-15, -14], [35, 12], [13, -21], [58, -7], [-11, 24], [-36, -6], [-22, 7], [-10, -11], [-2, -22], [-30, 23], [0, 14], [17, -11], [-4, 30], [-1, 11], [-35, -21], [-4, 3], [-10, 12], [34, 5], [-28, 30], [-6, -1], [-32, 20], [-20, 20], [-8, 8], [-16, -10], [-37, 0], [42, -8], [-20, -1], [-1, -21], [-43, -2], [49, -16], [-9, -8], [-26, 6], [41, 7], [17, 6], [18, -32], [52, -5], [-13, -1], [-3, -25], [10, -22], [27, 14], [6, -18], [40, -15], [-58, -14], [25, 8], [2, -8], [-32, 13], [-15, 14], [-19, 17], [17, -15], [7, -5], [3, -19], [-24, 3], [-62, 9], [21, -3], [-19, -35], [-6, -36], [-56, -13], [70, -4], [10, -39], [-52, 12], [44, 23], [-40, 22], [-43, 11], [11, 23], [3, 34], [-3, 38], [14, 16], [67, -1], [-12, 31], [19, -21], [-3, 49], [11, -6], [-28, 33], [0, -22], [55, 5], [-24, 16], [61, -2], [24, 6], [-10, -27], [73, 4], [-40, -20], [-14, -32], [-18, -7], [-47, -7], [-31, -2], [-49, -2], [0, 24], [-31, 7], [21, -15], [-9, -14], [-46, -3], [-68, 6], [39, -27], [38, 16], [-43, 0], [-30, 10], [-52, 24], [-26, 11], [-23, 24], [-21, -28], [-18, -1], [56, 14], [9, 2], [-48, 1], [-66, -14], [18, 20], [35, 33], [-42, -18], [-72, -4], [71, -11], [3, -19], [-79, 9], [-10, 11], [66, -2], [-9, -22], [17, 1], [-8, 15], [15, -19], [-1, -31], [72, -7], [-4, -34], [10, 5], [-13, -19], [22, 0], [-34, -28], [-8, 48], [41, -15], [32, 20], [-88, 2], [-24, 12], [64, -17], [-6, -11], [-3, -33], [50, -24], [22, -2], [-16, -28], [28, 3], [41, -7], [-21, 6], [-37, 24], [20, 8], [12, -11], [-32, 7], [-56, 18], [26, 24], [-5, -21], [25, -25], [15, 27], [-14, -26], [-3, -2], [-4, 46], [69, -11], [6, 12], [-13, -13], [-33, -23], [-45, 9], [-56, 20], [-16, 0], [-52, 6], [-21, -20], [-66, 14], [-63, -15], [-72, -17], [-56, -12], [-30, 12], [-43, -3], [-13, -28], [63, -9], [-28, 20], [-46, 18], [-17, -38], [61, 3], [4, 51], [43, 27], [10, 6], [1, 3], [-4, -52], [31, -31], [9, 44], [46, -7], [28, -36], [2, -30], [23, 13], [17, -2], [9, 36], [-12, -41], [31, 15], [38, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4598_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4598_2_a_bf();".
// 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_bf(:prec:=2)
    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_bf();".
// 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_bf( : 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, -2, 1]>,<7,R![1, 4, 1]>,<13,R![-12, 0, 1]>],Snew);
    return Vf;
end function;