
// Make newform 4830.2.a.bx in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4830_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_4830_2_a_bx();".
// 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_4830_2_a_bx();".
// 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, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-3, 0, 2]];
    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_4830_a();"
function MakeCharacter_4830_a()
    N := 4830;
    order := 1;
    char_gens := [3221, 967, 2761, 1891];
    v := [1, 1, 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_4830_a_Hecke(Kf)
    return MakeCharacter_4830_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], [-1, 0, 0], [1, 0, 0], [-1, 0, 0], [1, -1, 0], [-2, -1, 1], [-3, 0, 1], [1, 0, -1], [1, 0, 0], [1, 3, -2], [1, 2, 1], [0, 2, -4], [4, 0, -2], [-1, 1, 0], [-3, 2, 1], [-2, -2, 2], [-2, 2, 0], [-4, -2, 4], [-5, -3, 0], [3, -1, -2], [-6, 0, 0], [2, 0, 2], [3, -2, 3], [-8, -5, 3], [-2, 3, -3], [0, 1, -3], [-2, 4, -6], [4, 6, -2], [0, 0, -2], [0, 4, -6], [-7, -5, 4], [-4, -4, 4], [2, 0, 4], [-2, -2, 4], [4, -2, 4], [-8, -2, 2], [-8, 0, -2], [12, 6, -2], [-3, 0, -5], [-5, -8, 3], [10, 6, -4], [-4, 6, 4], [14, 0, -2], [-14, -6, 2], [-8, -4, 6], [-2, -6, 0], [-6, 0, 6], [-6, -3, -3], [-1, 4, 1], [-6, 2, 2], [8, 0, 2], [-1, -1, 2], [-7, 4, -7], [-2, 5, 1], [-2, 6, -10], [0, -2, -2], [-6, -5, 1], [-3, -6, -3], [-17, -1, 0], [-9, -5, 4], [-12, 1, 3], [8, 8, -10], [-14, -4, 2], [-2, 1, 9], [-2, 5, 3], [6, -6, -6], [12, 2, -6], [-25, 3, 0], [2, -6, 0], [-13, 4, -1], [-2, 6, -2], [14, 0, 6], [2, -8, 2], [-4, 6, 4], [-8, -2, 2], [12, -2, 2], [-10, -6, 10], [-18, -1, 1], [5, -7, 8], [-8, 8, 2], [-4, -1, -7], [-22, -4, 4], [4, -2, -2], [-22, -5, 1], [9, -4, -1], [14, -6, -4], [-20, -8, 2], [-13, -3, 2], [-8, -3, 1], [1, -7, -2], [-11, -10, 9], [2, 8, -14], [-23, -7, 6], [2, 10, -12], [-6, 8, -2], [4, 4, -12], [-12, 1, 1], [-8, -1, 7], [28, 5, -1], [4, 10, -8], [-12, -2, -6], [0, 12, -10], [-25, -6, 3], [13, 5, 4], [-26, 6, -4], [10, 4, 0], [-30, 2, 0], [10, 14, -6], [-5, 1, 12], [-18, -4, 0], [-24, -7, 3], [-10, -2, 6], [-16, -10, 8], [-1, -12, 5], [14, 0, -10], [-13, -5, 8], [6, 1, 9], [-9, -2, -5], [28, -2, 8], [-1, 11, -2], [6, 6, -6], [0, 4, 2], [2, 8, -4], [-2, 2, 4], [26, 0, -2], [-14, 4, 0], [-24, -6, 4], [-6, -1, -1], [-8, 6, 10], [4, -12, -6], [2, 6, -4], [14, 12, -6], [12, 0, -12], [2, -2, 10], [8, -6, 4], [11, -2, -11], [30, 8, 0], [10, 9, -11], [-8, 4, 2], [-2, -6, -10], [12, 4, -8], [-3, -3, 8], [-15, -13, 12], [8, -10, 2], [29, -4, -3], [-10, -10, 0], [10, -5, -7], [-38, -6, 6], [22, 0, -6], [44, 6, -2], [-27, -9, 10], [10, -5, 1], [20, 10, -6], [-9, -6, 15], [17, 5, 2], [28, -2, -6], [14, -2, 12], [20, 12, -10], [-20, 7, 3], [-14, -8, 4], [10, -8, 6], [0, 0, 6], [21, 9, -14], [-10, -11, 9], [16, 14, 0], [-4, -6, 6], [0, -2, 18], [6, -1, -15], [18, -4, 4], [21, -12, -3], [-1, -3, -12], [29, 14, -13], [6, 8, -2], [5, 5, -8], [-7, 4, -1], [18, 9, -13], [0, -12, 24], [19, 17, -18], [-2, -10, 8], [-8, -14, 12], [-9, 13, -12], [-22, 5, 5], [29, 11, -2], [-16, 2, -8], [28, -8, 12], [2, 10, 6], [15, -9, 0], [0, 7, 1], [28, 2, 8], [-4, -1, -3], [14, -6, 10], [-6, 4, 2], [24, -2, 2], [10, -3, 7], [32, 0, -8], [9, -14, 11], [-22, -6, -2], [24, 0, 10], [-41, -2, 1], [7, -10, -13], [22, 22, -10], [-33, 0, 5], [-28, 9, 9], [-19, -8, 9], [0, 5, -1], [17, 0, -11], [16, 8, -8], [42, -4, 2], [-42, 0, 4], [6, 6, 4], [-20, -2, 16], [0, -7, 13], [16, -4, 12], [-7, -14, 25], [-2, 5, 5], [15, 6, -7], [11, 15, -18], [-8, 10, -12], [2, -12, -2], [4, -6, -12], [12, -16, 2], [-48, -6, 6], [-10, -8, -4], [52, -4, 4], [-24, 4, -16], [-28, -8, 10], [-19, 14, 3], [25, -11, 2], [-34, 4, -6], [10, 14, -12], [7, 5, -14], [9, 10, -11], [30, 18, -16], [-12, -20, 6], [0, 13, -5], [-10, -6, 12], [-1, -10, 9], [54, -2, -6], [-18, 6, 0], [-40, 7, 1], [-36, 8, -4], [28, -8, -4], [18, 15, -13], [8, -18, 0], [-2, -18, 6], [-4, 11, -7], [-46, -5, 7], [-36, -13, 5], [8, 4, -12], [-2, 0, 6], [30, 14, -2], [-4, -9, -13], [20, -16, -4], [-1, 10, -11], [-11, 14, -29], [-24, -12, 0], [0, -16, 6], [-30, -7, 5], [-29, 10, 17], [-2, 2, -2], [-24, 12, -4], [-6, 10, -4], [11, 10, 1], [32, 6, -4], [-14, -10, 18], [29, -6, 9], [-2, 0, 16], [-4, -1, -5], [43, 5, -8], [-28, -22, 12], [5, 14, -5], [39, -9, -14], [22, 7, -15], [-24, 6, -2], [-22, -20, 4], [42, 3, -1], [0, -6, 6], [28, -10, 4], [4, 2, 4], [-12, 5, 3], [27, 24, -11], [-16, 14, 6], [-36, 14, -6], [-28, -14, 0], [8, 10, 10], [-5, 23, -2], [33, -13, 14], [46, -8, 0], [13, 8, -9], [-24, 16, -2], [0, -2, -8], [3, 8, -7], [22, 10, -2], [18, 5, -3], [1, -11, 16], [10, 16, -28], [-36, 2, -6], [33, -8, 13], [8, -2, 6], [-28, -4, 4], [20, 5, -11], [0, 14, -12], [0, 4, 12], [-18, -20, 22], [28, -12, 16], [-8, -6, 8], [8, -8, 4], [-22, 2, -14], [-30, -12, 10], [57, 5, 0], [-17, 14, -5], [40, 0, 2], [7, 23, -24], [-2, 20, -10], [48, -6, -14], [-5, 4, 15], [-18, 8, -14], [29, -3, 14], [18, 3, 9], [-2, 20, -16], [21, -12, -9], [-17, 11, -24], [14, 3, -11], [-1, -5, 6], [-6, 2, -6], [-19, 16, 1], [8, -4, -20], [54, -8, -14], [22, -6, 24], [-28, -4, 10], [-50, 8, 16], [-20, -26, 24], [7, 24, -3], [-20, -24, 8], [-8, -20, 4], [26, 6, 4], [-10, 14, 6], [-13, 8, -13], [12, -12, -6], [2, -10, -4], [-23, -23, 20], [24, -2, 0], [-14, -15, 19], [-8, -14, -6], [24, 14, -4], [-26, -2, -16], [15, 6, -7], [-30, 16, 18], [10, 2, -8], [34, -16, -12], [24, 0, 0], [-2, 8, -20], [7, 15, -12], [-2, -22, 4], [6, -2, -10], [2, 26, 6], [6, 2, 20], [-6, -5, -17], [48, 0, 10], [-20, -24, 4], [6, -14, 26], [-52, 0, 10], [-12, 20, -8], [-35, 5, -2], [12, -12, 20], [20, 20, -10], [-49, -22, 13], [-44, 8, -4], [-8, -2, 20], [-10, 6, 12], [14, -8, -22], [-36, -12, 24], [-22, -4, -16], [22, 14, 4], [1, -3, -24], [-26, -16, 18], [-42, -24, 10], [22, -3, 3], [20, 7, 3], [-6, -20, -4], [-26, 14, 22], [-56, -8, 14], [-9, -23, 32], [22, 18, -10], [-19, -10, -3], [33, 14, -15], [-16, 10, -10], [-30, -9, -11], [35, 13, -8], [12, -14, -18], [-18, 14, -2], [-45, -2, 13], [-16, -12, 16], [10, -16, 30], [14, -24, -10], [-13, 19, -20], [-60, -18, 14], [-2, -19, 11], [68, -6, 2], [9, -1, -22], [17, -14, -5], [-24, -8, -6], [-48, -24, 20], [37, 2, 15], [-30, -3, 23], [-3, -20, 27], [-2, -4, 4], [10, -26, 14], [44, 1, 11], [16, -14, -14], [-26, -6, 10], [62, 12, -16], [-16, 24, -24], [22, 4, -2], [11, -17, -16], [10, 15, -3], [9, 27, -20], [56, 23, -11], [17, -2, -25], [4, 4, -12], [26, 12, -24], [-16, 12, 14], [56, 28, -20], [54, -6, 8], [38, -2, -14], [19, 0, -5], [-36, -22, 26], [14, -8, -4], [22, 22, 4], [-32, 7, 1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4830_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4830_2_a_bx();".
// 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_4830_2_a_bx(:prec:=3)
    chi := MakeCharacter_4830_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_4830_2_a_bx();".
// 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_4830_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4830_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![8, -4, -4, 1]>,<13,R![-8, -4, 4, 1]>,<17,R![-8, 12, 8, 1]>,<19,R![8, -8, -2, 1]>,<29,R![104, -64, 2, 1]>],Snew);
    return Vf;
end function;