
// Make newform 4598.2.a.bm in Magma, downloaded from the LMFDB on 24 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_bm();".
// 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_bm();".
// 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, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0], [0, 1, 0], [2, -1, 0], [0, 0, 1], [0, 0, 0], [-2, 0, -1], [-2, 0, -2], [1, 0, 0], [0, 0, -2], [-2, 1, 2], [0, -2, 1], [-6, 2, -2], [2, -2, 1], [0, 3, -2], [0, -2, -2], [-6, 2, 0], [-4, 4, 4], [-2, 0, 0], [0, 0, -1], [0, -1, 2], [-2, -2, -4], [0, -4, -2], [0, -5, 2], [2, 8, -2], [-6, 2, -2], [-2, 2, 4], [-8, -1, 2], [-4, 2, -2], [-6, 0, 0], [2, -2, 6], [-8, 4, 2], [0, 2, 1], [14, 0, 1], [8, -3, 6], [-10, -2, 2], [16, -2, 2], [-6, 1, -4], [4, -6, 4], [-8, -2, -6], [-2, 7, 2], [0, 4, 1], [2, 4, 6], [8, -2, -6], [2, -9, 4], [-18, 4, 0], [0, 2, -4], [4, -2, 4], [-12, 0, -4], [-12, 2, -8], [10, -2, 5], [6, -6, 2], [0, 3, 4], [-6, -7, 0], [-12, 0, 0], [10, -8, -6], [0, -9, 4], [-6, 6, 0], [0, 8, -5], [-10, 8, 8], [2, 1, 0], [8, 6, 1], [-10, 12, 5], [-12, 6, 4], [-8, 6, 0], [-2, 5, 2], [18, 4, 2], [-16, -3, 4], [-6, 6, -3], [4, -12, 0], [14, -4, 0], [2, 4, 8], [0, 8, -3], [-24, -2, 2], [-10, -1, 2], [8, -12, -3], [-8, -6, 1], [18, -1, 0], [-14, -2, -9], [2, -2, 4], [2, 1, -4], [20, 2, 6], [2, -6, 0], [-8, 12, -8], [-14, -4, 6], [8, -4, -8], [12, -8, -8], [2, -10, -4], [6, 4, 10], [14, -10, -6], [-16, -4, 4], [12, 8, 2], [16, 0, 1], [8, 11, 2], [0, 2, -3], [-12, 6, -10], [-24, -1, -4], [-14, -2, 6], [-14, -4, -8], [20, 2, 4], [-26, 2, -4], [-20, 4, -8], [-18, -2, -10], [4, -10, 2], [2, 6, 5], [-24, 10, 5], [-2, 12, 3], [12, -4, 0], [14, -4, 8], [0, 9, -10], [-22, 6, -5], [0, -16, -2], [-18, -4, -12], [14, 0, 1], [20, 6, 6], [-16, 12, -6], [-30, -8, 2], [4, 16, 0], [-16, 2, -16], [2, 6, 13], [-12, 4, -6], [2, -14, 6], [18, -2, -9], [-10, 1, 10], [20, -16, -8], [-4, -2, -10], [6, 2, 6], [-6, 14, 1], [-16, -2, 4], [-16, -8, -4], [-2, -20, 8], [-8, -19, 2], [8, -2, -2], [-4, -8, 0], [18, 11, -4], [6, 16, -6], [-10, 20, 4], [-38, 0, -4], [4, 2, -12], [-6, 4, -2], [14, -6, -10], [12, 10, 2], [14, -6, -8], [-8, 0, 4], [12, 12, -4], [-6, -4, -12], [0, -9, -6], [-10, 10, 10], [42, -2, -1], [12, -16, 12], [24, -6, 13], [-2, -5, 10], [-10, -4, -3], [-12, 10, 0], [8, -4, 8], [-4, 12, 12], [4, -16, 12], [8, -17, -4], [14, -8, 7], [-10, 16, -4], [18, 4, 0], [12, -6, -4], [6, -12, 0], [20, 12, 0], [-24, -1, 4], [10, 10, 2], [-8, -18, 3], [-8, -6, -5], [-34, 2, -12], [-14, 14, -17], [26, 10, 1], [28, -8, 0], [26, 8, 2], [-24, 7, 4], [14, 4, 10], [-20, -4, 4], [-10, 7, 10], [40, 6, -5], [14, 0, -8], [16, 2, 6], [-18, -8, 2], [-8, 8, 8], [12, 4, 16], [-14, 4, -16], [-6, 7, 12], [24, 0, -12], [14, -8, 8], [-30, 0, 4], [16, -1, 8], [-22, -1, -8], [8, 13, -8], [42, 6, -4], [-32, 6, -5], [16, -13, -4], [2, 4, 6], [0, 26, -3], [18, -2, 8], [-2, -22, 10], [18, -2, 7], [14, 24, -4], [20, -12, -12], [-2, 8, 3], [-16, -4, -8], [-14, 2, -2], [2, 7, 12], [-12, -6, 0], [-2, -12, -4], [8, -14, -2], [-20, -4, -18], [38, -2, -2], [24, -13, 12], [-2, 10, -12], [-30, 9, 8], [-8, 22, -12], [0, 28, -5], [-8, -4, 8], [-6, 8, 6], [-12, 16, 8], [46, -4, 12], [32, 10, -5], [18, -14, -13], [-26, -16, -1], [24, 2, 10], [18, -4, -14], [-16, -26, 6], [36, -4, -4], [14, -20, -16], [2, -8, 14], [0, 5, 6], [56, -6, -4], [24, 3, -6], [-22, 7, 4], [-12, -20, -2], [8, 2, 0], [26, -6, 19], [-20, 16, 2], [-24, -12, -13], [-10, 4, -3], [-34, -4, 8], [4, 14, -6], [32, -10, 3], [8, 5, 16], [-16, 10, 1], [32, 10, 4], [-14, 18, -14], [-2, 20, 4], [-8, 16, 5], [-16, 10, 16], [40, 5, 0], [20, -12, -6], [-44, 12, 0], [22, 12, 12], [-26, -8, 6], [32, -12, 6], [-30, -22, 4], [30, -18, -2], [56, -5, -2], [50, -15, -12], [36, 0, 18], [2, -24, -2], [-18, 0, 12], [16, -14, 8], [-12, 0, -22], [22, 4, -8], [-2, 5, -14], [54, -7, -2], [-4, -8, -12], [2, -6, -18], [38, -17, -14], [4, 6, -12], [-2, 0, 2], [34, -16, 16], [-16, 15, -4], [-34, -4, 1], [0, -17, 4], [-22, 25, -8], [24, 14, 12], [-12, 0, -18], [-50, 7, -10], [2, -3, 20], [-8, 9, -18], [-48, -6, -10], [-40, 10, 10], [-16, 9, 8], [-26, -7, -2], [-16, 3, 18], [24, -4, 2], [-2, 16, -9], [-10, -4, -9], [-24, 2, -10], [10, 1, -20], [-46, -14, 7], [-4, 8, 0], [-22, -26, 3], [-20, -10, -8], [-2, 21, 18], [-10, -8, -16], [-24, 6, -13], [-10, -4, 4], [20, -6, 18], [-8, -3, -18], [-26, -22, 4], [-34, -4, 3], [-20, -4, 0], [40, -11, -12], [52, 0, 4], [42, -14, 18], [0, -32, -3], [-54, -14, 6], [24, 0, 8], [46, -22, -6], [40, 4, 17], [34, -17, -8], [-6, -30, 5], [8, 3, 16], [0, -16, -7], [-26, -8, 8], [-12, 2, 18], [8, 12, 14], [30, -9, -18], [62, -4, -4], [20, 14, -16], [-22, -20, -12], [-14, 12, 12], [28, 0, 28], [-42, -10, 0], [50, 8, -2], [-8, 4, 13], [16, -13, -16], [16, -18, -4], [-26, -4, -2], [6, 14, 10], [-22, -6, -22], [24, -15, 20], [-28, -4, -20], [8, 3, 18], [-12, 26, -12], [34, 6, -8], [26, -22, -3], [42, 8, -4], [-8, 11, -24], [-62, 2, -6], [22, -21, -18], [-10, -8, 15], [-40, 3, -30], [-30, -16, -2], [-20, 24, 2], [-6, -10, -9], [-16, 8, 15], [8, -28, -6], [-2, 20, 0], [-28, 22, 18], [26, -8, -6], [18, 14, 7], [16, -26, 2], [-42, -12, -11], [2, -11, -12], [0, 28, 14], [-8, -3, -14], [-42, 8, -20], [24, -2, 5], [30, -24, -4], [-18, 14, -16], [-48, 7, -14], [-36, 24, 14], [20, 4, 30], [-38, -2, -22], [22, 14, 18], [0, 18, -8], [-22, 27, 20], [-36, 18, 10], [24, -4, 27], [-4, -4, 8], [6, -15, 10], [-12, -4, 16], [-2, 8, 8], [0, -24, 11], [-24, -12, 9], [62, -14, 2], [-2, 6, 12], [6, -28, 12], [26, 6, -6], [-34, 20, -3], [48, -8, -5], [-10, 6, -12], [-20, 4, 12], [20, 24, -12], [-24, -18, 0], [-62, 9, 8], [-64, 14, 5], [48, -3, 2], [2, -8, -4], [-62, -14, 0], [20, 12, 16], [4, -24, -10], [48, -6, 7], [-6, -9, 0], [-40, -8, -4], [2, -4, 28], [16, 0, -21], [-58, 10, 6], [14, 8, 7], [-2, -5, 18], [-8, -2, 18], [-30, -2, -22], [22, 1, 2], [36, -28, -24], [82, -6, -5], [-2, 0, -24], [12, -28, -12], [-28, -6, -14], [-34, -16, 0], [22, -12, 22], [20, 8, 0], [-16, 1, -26], [38, -16, 20], [-2, -44, 16], [-8, -14, 4], [40, 14, -15], [-2, 12, -1], [16, -22, 8], [-62, 0, 0], [-14, -8, 12], [48, 4, 2], [4, -18, -2], [2, -26, -18], [2, -10, -6], [16, -4, -15], [-18, 8, 6], [-20, 18, -16], [8, -29, -24]];
    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_bm();".
// 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_bm(:prec:=3)
    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_bm();".
// 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_bm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4598_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![4, -5, -1, 1]>,<5,R![2, 3, -5, 1]>,<7,R![4, -7, 1, 1]>,<13,R![-14, 1, 5, 1]>],Snew);
    return Vf;
end function;