
// Make newform 4598.2.a.bi 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_bi();".
// 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_bi();".
// 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 := [-1, -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_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, -2], [-1, 1], [-2, 3], [0, 0], [0, 1], [-3, -2], [1, 0], [3, -2], [-4, -4], [-1, -6], [-3, -3], [-4, 5], [-6, 6], [5, 4], [-7, 8], [-5, -5], [-6, 1], [2, -5], [-7, 2], [-10, 7], [3, 0], [-7, 5], [7, -10], [-3, 12], [-7, 4], [6, -9], [3, 0], [-1, 7], [-3, 12], [-3, -10], [6, -14], [-5, 4], [0, -3], [21, -2], [10, -6], [6, -6], [16, -13], [-10, 1], [-9, 11], [-14, -2], [17, -8], [3, 8], [-11, -9], [17, -10], [4, -16], [-21, 8], [-20, 0], [-8, 13], [19, -9], [15, -14], [-12, 21], [4, -7], [16, -8], [-5, 7], [8, -13], [15, 8], [2, -6], [-8, -3], [20, -13], [-15, 6], [17, -4], [-15, -2], [10, 4], [-3, 8], [-3, 0], [0, 6], [1, -10], [10, -22], [-24, 7], [14, 8], [-15, -3], [28, -9], [10, -18], [17, 3], [-13, -1], [-14, 26], [-9, 24], [-23, -4], [-3, 0], [12, 12], [9, -12], [-6, -13], [-26, -4], [22, 3], [-3, 3], [3, 6], [9, 0], [13, -28], [-21, 3], [11, -17], [-5, -2], [11, -8], [-24, -3], [31, 0], [1, 11], [-21, 30], [9, 4], [25, -19], [-19, 27], [1, 11], [-14, -8], [-23, 22], [-12, 4], [-15, 16], [-21, 23], [-27, 12], [9, 12], [6, 3], [13, 15], [3, 0], [8, -18], [-10, -1], [-9, 5], [-7, 3], [24, -38], [6, 12], [1, -1], [21, 7], [-47, 4], [-45, -1], [-31, 15], [-35, 20], [-14, 23], [24, 2], [-24, 3], [-35, 2], [30, -3], [-31, 24], [-20, 9], [-14, 18], [8, 10], [-23, -16], [-33, 29], [-25, -16], [45, -6], [33, -17], [-6, 22], [28, -11], [8, 8], [48, 4], [15, -9], [-20, 2], [46, -11], [0, 20], [-23, 31], [2, 1], [31, -5], [-9, 4], [-14, -10], [-7, -17], [-36, 8], [-36, 30], [-9, -22], [-56, 3], [-12, 20], [-3, 12], [17, 8], [6, -6], [27, 8], [-7, 8], [-4, -26], [-1, -33], [-17, -13], [-14, 22], [30, -30], [39, -24], [21, 4], [-15, 14], [17, -11], [1, 4], [26, -12], [7, -14], [-7, -8], [-33, -12], [-18, 36], [42, -14], [-18, -12], [-9, 37], [12, 0], [-12, 15], [41, -25], [3, -12], [43, 7], [15, -21], [59, -10], [-30, -18], [-27, 32], [-11, -21], [3, 25], [-30, -6], [-8, 19], [12, 12], [17, 8], [-32, 13], [-33, -18], [35, -5], [9, -13], [15, -13], [17, 14], [33, -4], [-11, -18], [-15, 21], [9, -33], [16, -1], [6, -13], [5, -20], [-18, -30], [6, -29], [-59, 6], [57, -6], [-36, 31], [-6, 38], [-12, 42], [13, -34], [15, 4], [-43, -3], [-49, 5], [21, -31], [12, -9], [16, -25], [38, -32], [20, -25], [-12, 22], [52, -25], [-11, 50], [-30, -3], [-8, 16], [-5, -36], [39, 9], [39, 18], [-8, -19], [32, -48], [41, -4], [21, 19], [25, -29], [-37, 9], [9, -3], [-40, 50], [9, 9], [15, 24], [-40, -9], [11, 13], [50, -6], [13, 11], [-44, -20], [-12, -2], [-3, -42], [11, -24], [-23, -17], [-33, 18], [29, 13], [21, -42], [16, -27], [-23, 31], [-27, -20], [12, -48], [7, -36], [18, -3], [9, 6], [-47, 23], [0, -9], [37, 3], [-41, 36], [-9, 15], [-12, -6], [19, 17], [37, -16], [21, -14], [58, -2], [-12, 27], [-11, 6], [-6, 6], [-52, 48], [-18, -30], [-21, 39], [-12, -26], [-10, 3], [62, -6], [32, 14], [-45, 14], [-17, -16], [60, -36], [16, -33], [-14, 36], [-71, -8], [-2, -45], [0, -28], [25, -36], [61, 14], [9, 0], [-9, -26], [-39, 59], [-30, -12], [-28, 48], [65, -2], [33, -54], [17, -16], [-47, 55], [53, -6], [43, 12], [-21, -24], [-21, 57], [6, 24], [28, -42], [-57, 18], [23, 29], [46, 18], [56, -22], [-21, 6], [-45, -12], [11, 14], [-21, 10], [49, -40], [28, -10], [-6, 42], [-12, -12], [-11, 19], [-15, 11], [-63, 7], [-55, 21], [45, -26], [-15, 1], [-33, 20], [34, -40], [-59, 41], [-42, 74], [6, 16], [-10, 34], [-60, 18], [-21, -12], [28, -1], [-51, -22], [41, 23], [-47, -27], [36, 4], [-57, 18], [0, -42], [29, 3], [-30, 9], [0, 10], [-32, -34], [-41, 19], [-69, 40], [60, -24], [64, -20], [16, -42], [-31, 70], [-9, -27], [46, 8], [37, -49], [-55, -12], [23, -10], [-9, 11], [29, -30], [33, -24], [-37, 13], [6, 30], [-33, 4], [32, -5], [-47, 9], [-15, 30], [66, -22], [-25, 34], [7, 18], [77, -26], [-44, 50], [-6, -36], [33, 0], [-37, 49], [-24, 10], [-43, 53], [65, -26], [-28, 42], [-57, 57], [-36, 3], [-15, 30], [-36, 46], [-6, -43], [-27, 30], [7, 14], [-27, -15], [-15, 0], [-23, 19], [-31, 12], [-8, 31], [-11, 36], [-7, 40], [-35, -18], [-23, -5], [48, 7], [-65, 47], [41, 11], [10, 18], [19, -2], [-66, 9], [-54, 19], [78, -29], [-83, 15], [3, -28], [15, -6], [47, 20], [-63, 12], [24, 3], [46, -40], [-5, -52], [63, -12], [-45, 30], [68, -48], [15, -40], [83, 12], [-82, 28], [-81, 18], [-18, 13], [54, -51], [48, -45], [-69, 6], [-25, 1], [53, 20], [21, 25], [-57, 68], [-1, -47], [-12, -5], [33, 7], [49, -78], [-7, -19], [4, -17], [-61, -7], [-1, 16], [-3, 32]];
    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_bi();".
// 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_bi(: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_bi();".
// 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_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4598_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, 0, 1]>,<5,R![-1, 1, 1]>,<7,R![-11, 1, 1]>,<13,R![-1, -1, 1]>],Snew);
    return Vf;
end function;