
// Make newform 4830.2.a.bu 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_bu();".
// 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_bu();".
// 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], [3, 1], [0, 0], [-3, -1], [-5, -1], [1, 0], [-3, -3], [-1, 3], [4, 2], [-4, 2], [1, -5], [3, -1], [0, 6], [-6, -2], [-2, -4], [-7, 3], [-3, -1], [-10, 0], [0, 0], [1, 1], [-10, 2], [12, 0], [2, -2], [2, 6], [0, 0], [0, -6], [-8, -2], [-5, 5], [-12, 0], [2, -8], [-16, 0], [-12, 2], [-12, 0], [0, -6], [-4, 4], [3, 3], [11, 1], [10, 2], [-6, 0], [-2, -2], [-8, -2], [-12, -2], [-10, 6], [-8, -4], [0, -6], [-3, 9], [-12, 6], [24, -2], [-19, -1], [-7, 3], [-4, 2], [-12, -6], [-12, 0], [-8, -8], [3, -9], [-13, 3], [19, -1], [2, -8], [12, 6], [-10, 6], [12, -2], [16, -8], [2, 8], [-4, -4], [15, 3], [0, 0], [-1, 13], [-4, -2], [6, -10], [-18, -6], [16, -2], [-24, 0], [10, -2], [-12, 6], [0, 0], [13, 5], [-8, 10], [30, 0], [14, 8], [30, -2], [16, 4], [-29, 3], [-12, -12], [30, 0], [-1, -9], [10, -2], [-1, 5], [23, -1], [2, 14], [-9, -3], [12, -8], [8, -12], [6, 2], [22, 10], [6, 2], [-22, 8], [-8, -10], [22, -6], [12, 6], [-23, 1], [13, 13], [-26, -2], [-6, 0], [-6, 14], [8, -2], [-7, 7], [14, 8], [18, -12], [4, -18], [24, -6], [1, 5], [4, -20], [7, -13], [12, -6], [-27, -7], [-36, 2], [9, 15], [-28, -2], [26, 4], [18, -8], [-16, -8], [12, 12], [30, -8], [-10, -4], [-12, 2], [-8, -4], [4, 2], [-8, 16], [-20, -4], [-4, 4], [12, 6], [36, 2], [47, -3], [6, 16], [-20, 2], [8, -2], [-12, 10], [-22, -6], [5, -7], [19, 13], [-4, -20], [5, -21], [-14, 2], [0, 0], [16, -14], [-8, 0], [-4, 16], [13, 13], [8, -4], [12, 12], [9, 5], [3, 21], [-36, 8], [0, 12], [0, -14], [38, -6], [6, -4], [8, 4], [48, -2], [-13, -15], [12, -14], [-12, 6], [22, -14], [-20, 16], [-8, 0], [-38, 0], [21, 3], [9, -21], [-31, 11], [34, 2], [-3, -3], [-29, -13], [-4, 4], [28, 8], [3, 15], [-22, -6], [-10, -16], [-3, 3], [-12, 10], [-7, -23], [18, 0], [-36, -12], [-30, 8], [-33, -9], [-42, 0], [38, 0], [14, 4], [18, 0], [32, 4], [-20, 12], [48, 4], [36, 8], [33, -1], [2, 4], [26, -16], [-9, -3], [21, -15], [12, 6], [25, -15], [6, 18], [-11, 15], [10, 8], [17, -17], [-44, -12], [-12, 0], [6, -4], [20, -20], [24, -6], [-14, 14], [8, -16], [-13, 11], [16, 10], [7, 5], [-35, -9], [-28, 10], [12, 12], [-16, -2], [0, -6], [32, 0], [42, 0], [-2, 26], [-48, -4], [-52, 6], [-19, 19], [-33, 5], [18, 6], [-42, -10], [-1, 11], [-25, -9], [-44, 8], [50, -4], [34, -8], [48, 4], [27, -15], [-36, 10], [30, -18], [18, 8], [-12, 24], [-46, -6], [-20, -14], [-16, 6], [-20, -14], [-66, -4], [-40, 14], [10, -4], [-32, 12], [12, -28], [40, 10], [38, -14], [-12, -4], [7, -19], [-39, 3], [24, 20], [-40, -6], [-16, 6], [-49, -7], [10, -4], [-56, 8], [2, 2], [-33, 9], [4, 6], [44, -2], [-21, 3], [30, 8], [-18, -14], [-27, 15], [-32, -10], [29, -1], [-11, 3], [24, 12], [60, 0], [-22, 4], [-8, 22], [-24, 8], [-24, -18], [-28, 22], [26, -16], [21, 21], [-32, -4], [-2, 2], [-38, -8], [-4, 20], [-15, 11], [21, 9], [6, -32], [-17, 15], [-48, -14], [12, -6], [25, -11], [0, 10], [0, -2], [-11, -15], [-34, -4], [-8, 8], [-27, -21], [-24, -24], [68, 0], [-14, 26], [-42, -12], [-20, -12], [-20, 8], [-20, -8], [44, -18], [36, 0], [8, 18], [36, 0], [1, -27], [-3, -23], [18, 0], [-21, 7], [-34, -6], [-28, 8], [-5, 5], [-42, 6], [-5, 25], [-24, 12], [-14, 16], [55, -5], [59, -1], [-24, 24], [29, -1], [2, -4], [25, -29], [32, -12], [14, -18], [-24, 12], [72, 2], [-82, 0], [0, 6], [65, 9], [-16, -4], [-24, -12], [-34, -14], [24, 30], [59, 5], [-48, -6], [38, -2], [-23, 29], [12, 14], [-16, 4], [32, 12], [-18, -4], [-18, -10], [23, -15], [-16, 8], [-18, -10], [10, 8], [2, -6], [-42, 12], [-17, 7], [42, -6], [0, 30], [-12, -18], [-18, 22], [12, -18], [-16, 14], [40, -16], [32, 18], [-32, 10], [28, 4], [39, 9], [0, -12], [-18, 0], [-49, 1], [-16, -32], [-4, 6], [80, -4], [20, 4], [28, 20], [-42, -16], [-50, 14], [-47, 5], [-78, -6], [32, -20], [-40, -16], [10, 22], [-18, 0], [66, -8], [-36, 10], [29, 27], [12, 14], [55, 15], [23, 19], [4, 0], [12, 12], [-11, 15], [-74, 10], [-10, -24], [27, 5], [-28, -8], [2, -22], [54, -18], [35, 15], [40, -8], [-40, 16], [-28, 20], [17, -7], [69, -9], [-48, -2], [-30, 6], [1, -25], [0, -20], [35, 27], [38, -24], [0, 6], [-86, -8], [-60, -12], [74, 0], [42, -20], [-24, 20], [-10, -22], [47, -21], [-8, 40], [-89, 1], [2, -24], [5, 43], [10, 22], [-6, 12], [-4, 18], [-24, -32], [-26, 2], [-34, 0], [-9, 29], [-12, 36], [6, 12], [-8, 24], [-26, -28]];
    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_bu();".
// 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_bu(: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_bu();".
// 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_bu( : 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, -6, 1]>,<13,R![0, 1]>,<17,R![4, 6, 1]>,<19,R![20, 10, 1]>,<29,R![-36, 6, 1]>],Snew);
    return Vf;
end function;