
// Make newform 4830.2.a.bq in Magma, downloaded from the LMFDB on 24 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_bq();".
// 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_bq();".
// 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;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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], [1, 0], [1, 0], [-1, 0], [-1, -1], [1, 1], [2, -2], [0, -2], [1, 0], [1, 3], [0, -2], [4, -2], [4, 2], [-3, 1], [-2, 0], [10, 0], [0, 4], [-2, 0], [-11, 1], [3, 3], [6, 4], [-4, 0], [4, -2], [5, 1], [-1, 3], [-7, 5], [14, 2], [6, -6], [12, -2], [-2, -4], [7, -1], [0, -4], [14, 0], [8, 0], [12, -2], [10, -2], [0, -6], [-6, 6], [12, 2], [8, 0], [6, -6], [-2, 8], [0, 0], [0, -6], [10, 4], [-10, -2], [-12, 4], [-9, 5], [6, 4], [-14, 0], [20, 2], [7, -1], [-4, -8], [-5, -7], [2, -12], [16, 4], [-9, 3], [-12, -6], [9, 7], [13, -5], [-7, 3], [-10, -4], [22, -2], [-23, -1], [13, 5], [-4, 6], [-20, 4], [-23, -1], [-4, 8], [18, 2], [14, -8], [12, -4], [-18, -6], [-24, 2], [14, 2], [0, 8], [-4, 2], [13, -3], [-13, 9], [-10, -8], [5, -5], [2, -8], [10, 10], [19, -9], [-6, 4], [-16, 4], [-2, 0], [23, -7], [-7, -3], [1, 13], [20, -6], [26, 6], [5, 9], [-6, -2], [0, -8], [-6, 14], [9, 5], [-11, 9], [1, -5], [-4, 14], [-6, -10], [20, 10], [-4, -2], [-9, 5], [26, 2], [-12, -6], [22, 10], [10, 12], [17, -11], [6, 12], [-9, 17], [-24, -10], [12, 6], [0, 10], [16, 4], [13, -13], [21, -5], [2, 0], [-4, -14], [-21, -9], [-18, 4], [6, -16], [22, -8], [-4, 0], [-6, 6], [2, 4], [-16, 6], [-29, 5], [22, 2], [-14, 4], [4, 0], [-24, -12], [-32, -8], [-24, -2], [-20, -2], [22, -6], [-18, -8], [17, 7], [10, 0], [0, -22], [6, -2], [7, -3], [-21, 3], [2, 6], [-14, 14], [-24, 8], [9, -7], [-2, -16], [-30, 6], [-22, -10], [-15, -5], [13, -11], [18, -2], [26, 8], [-3, -11], [-30, 10], [-16, 16], [6, -20], [23, 15], [-18, 8], [36, 4], [-26, 12], [37, 9], [19, 1], [-4, 6], [-20, -4], [-18, 18], [-31, 9], [38, 4], [-4, 24], [-19, 13], [-4, -4], [12, -12], [-5, -7], [-14, 4], [-5, -1], [-32, -4], [-9, 1], [4, 12], [-58, 0], [-15, 9], [-17, -11], [-19, 7], [-38, 8], [-16, 8], [-10, -20], [-31, -1], [31, 5], [-44, 2], [-17, -3], [60, -2], [-12, 12], [-30, 6], [-23, -15], [-8, -16], [-4, 20], [-12, 22], [14, -4], [36, -8], [-14, -8], [20, -6], [2, -8], [-33, -9], [36, 0], [3, 21], [12, -16], [-24, 0], [-44, -4], [-22, -16], [0, 24], [4, -22], [13, -15], [-60, -4], [0, 6], [-35, 3], [-18, 2], [-5, -1], [-44, 6], [-32, -4], [4, -14], [14, -20], [-2, -14], [14, 20], [-20, -4], [20, -24], [10, -8], [-16, -8], [25, -7], [18, -18], [-58, 2], [31, 9], [-14, -12], [-28, -20], [-2, 0], [-35, -9], [-28, 8], [-30, -10], [2, 16], [-26, 18], [-33, 5], [16, 8], [10, 10], [1, -21], [36, -18], [14, -8], [-9, 13], [13, -25], [45, 11], [-20, 4], [-20, 0], [-4, 10], [-3, -7], [0, 8], [-10, 18], [-10, -10], [36, 0], [-12, -2], [25, 7], [14, 18], [38, 8], [0, -8], [-26, 14], [28, -8], [-44, 2], [18, 4], [30, 0], [34, -4], [49, 13], [21, 9], [-4, 10], [48, -8], [7, 15], [7, -13], [-36, 8], [26, 24], [41, -5], [4, 28], [-44, 6], [-20, 10], [-21, 21], [4, -10], [-40, -4], [40, 8], [14, 8], [-22, -6], [-45, 11], [5, 15], [62, -8], [26, -12], [22, -4], [64, 2], [6, 20], [-2, -4], [-17, -3], [-1, -3], [-2, -8], [6, -22], [-40, 4], [-26, -18], [20, -8], [-3, 17], [4, -10], [12, 12], [-24, -16], [16, -32], [-8, -26], [-16, -28], [10, -8], [-28, -4], [-1, 29], [-30, 16], [-46, 8], [41, -1], [-24, -4], [-32, -12], [20, 12], [10, 26], [-11, -19], [11, 7], [10, 0], [0, 6], [-63, 7], [-9, 27], [47, 3], [0, 38], [-8, -12], [-36, 4], [-22, -6], [28, -4], [-20, 18], [18, 28], [-12, -6], [-2, -4], [-40, -4], [28, -4], [-22, -10], [30, -8], [2, 26], [18, -4], [-8, 24], [35, -15], [-28, -10], [65, 9], [-4, -8], [-20, -18], [2, -18], [56, -4], [-8, 28], [40, 8], [-22, -12], [-6, 18], [-18, -20], [-31, 7], [76, 4], [14, 8], [-6, 28], [64, 8], [25, -29], [8, -2], [-72, -8], [24, -2], [62, -12], [-8, 24], [45, -7], [-8, 12], [30, 0], [54, -14], [-8, 16], [4, 26], [2, 22], [38, 10], [24, 8], [54, 16], [38, 6], [15, -11], [-42, 6], [-92, 4], [73, -7], [45, 17], [-18, 4], [-42, -12], [-6, 32], [-27, 29], [-46, -16], [30, -24], [26, 12], [18, -18], [-39, 9], [33, -3], [36, 4], [36, -10], [-30, -18], [-44, -24], [22, 14], [-52, 4], [-31, -9], [-22, -26], [19, -9], [-26, 34], [45, -17], [-40, 16], [8, 14], [44, -12], [60, -12], [-15, -15], [-42, -16], [-26, -24], [32, -22], [33, 27], [-46, -14], [-24, -6], [26, 8], [-56, 0], [-56, 20], [29, -21], [-49, 11], [-25, -21], [-47, 7], [-32, -16], [62, 2], [-10, 0], [-2, -16], [32, 8], [36, -16], [26, 4], [-80, 0], [-50, 2], [50, 8], [-8, -32], [23, 21]];
    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_bq();".
// 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_bq(:prec:=2)
    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_bq();".
// 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_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4830_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-4, 2, 1]>,<13,R![-4, -2, 1]>,<17,R![-16, -4, 1]>,<19,R![-20, 0, 1]>,<29,R![-44, -2, 1]>],Snew);
    return Vf;
end function;