
// Make newform 4830.2.a.cc 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_cc();".
// 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_cc();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 2, 0], [-4, 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], [-2, 1, 0], [-2, -2, 1], [0, 1, 1], [-2, 1, -3], [-1, 0, 0], [0, -1, -2], [-6, -1, 1], [-2, -2, 0], [-2, 0, 2], [-6, 1, -2], [-6, -1, 1], [6, 2, 0], [-8, 0, 0], [2, 0, 2], [-6, 1, 2], [-2, 3, 0], [2, 4, -4], [0, -2, 4], [-6, 3, -3], [-2, -4, 5], [-6, -4, 1], [-6, 2, 3], [4, 0, -2], [0, 4, -2], [-2, 0, 2], [-10, -2, 2], [2, -1, -4], [-4, 0, 0], [2, 4, -4], [4, -4, -2], [-10, -6, 4], [0, -4, 6], [6, 0, 2], [-4, 0, -2], [2, 3, -5], [4, -7, 1], [8, 6, -4], [-6, 0, -6], [-4, -6, 2], [-2, 4, 0], [10, 2, -2], [-4, -2, 0], [12, 6, -4], [-4, 2, 1], [-14, -1, -1], [-10, 2, -8], [14, 0, -2], [-2, 3, 0], [0, 1, 1], [-4, -2, -5], [14, 2, -4], [8, 2, -2], [-2, 0, -1], [18, -1, 5], [20, -1, 2], [-4, -3, 2], [0, 2, 3], [-10, 2, 2], [8, 0, 2], [-12, 4, -1], [-6, 0, -1], [-2, -8, 2], [12, -6, -2], [12, 3, -4], [12, -4, 2], [-12, 5, 1], [14, 2, 4], [-12, -2, 2], [-4, -8, 6], [14, -6, -4], [8, 0, 2], [4, -6, 8], [-10, 0, 4], [-2, 6, -7], [0, 3, 6], [-18, -2, -2], [8, 0, 7], [2, -4, -4], [-4, 0, 0], [-6, 4, 5], [2, 3, -1], [4, 4, -2], [2, 6, -8], [-12, -1, 6], [-22, 6, -1], [2, -1, 6], [14, 1, 7], [-12, 0, -2], [10, -5, -2], [-12, -6, 6], [20, 2, -4], [4, 6, -2], [-6, 10, -9], [-2, 4, 9], [-8, 2, -13], [10, 2, 8], [16, -4, 8], [-2, 0, -6], [10, -5, -3], [8, 3, -6], [20, 2, -4], [26, 6, -4], [16, 2, 4], [-10, 6, -8], [-10, -5, 2], [-22, 0, -4], [8, -4, 3], [-2, 0, 0], [22, 2, 4], [2, -13, 7], [8, -10, 8], [4, -7, 14], [-12, 8, 1], [-10, -11, 11], [2, -2, -8], [-14, 3, -6], [-18, 6, 0], [-22, 2, 0], [2, 4, 4], [-12, 0, 2], [12, 0, -4], [-14, 0, 4], [10, -10, 2], [-12, 8, 1], [-16, -12, 6], [-18, -2, 2], [4, -12, 6], [0, -10, 8], [-8, -4, -4], [22, 4, 4], [-2, -2, -12], [12, -9, -3], [10, -4, 4], [-20, 4, -3], [-2, 6, 2], [-2, 8, -8], [-8, -6, 6], [-8, 3, -4], [2, -5, 4], [-24, -8, 6], [-32, -1, 3], [4, -8, 0], [-10, 6, -7], [-10, 10, -8], [-36, -4, 4], [16, -8, 18], [0, 13, -16], [2, -10, -5], [-20, 4, -2], [-18, -7, -1], [6, 7, -4], [32, 4, -2], [8, 16, -14], [-10, -2, -10], [6, -2, -9], [10, 4, -4], [-20, -6, 8], [-2, 14, -2], [10, 15, -6], [-12, -10, 7], [-10, -6, 12], [-12, 2, -4], [32, -4, 14], [6, -6, -7], [-22, -4, 0], [-8, 15, 3], [-14, -9, 0], [-8, 11, -7], [-20, -2, 2], [0, -3, -4], [10, -13, 7], [2, 2, -7], [20, 4, -12], [4, 1, -6], [-4, 0, 8], [18, -4, 10], [-42, 1, -4], [-4, 10, 7], [32, -3, -8], [-6, 4, 14], [0, -4, 4], [-6, 2, 2], [28, -1, 6], [0, 6, -3], [2, -10, 10], [-16, -10, 7], [10, 0, -6], [12, -10, -4], [0, 4, -10], [6, -4, -7], [-40, -4, 0], [0, 1, -1], [26, -8, -10], [-38, -6, 8], [12, 7, -7], [14, -3, 7], [-10, 12, -12], [-26, -11, 9], [2, -12, 21], [0, 17, -19], [-16, 12, 1], [-16, -9, 7], [32, 12, -12], [-4, 14, 0], [10, -12, 16], [-4, 4, 6], [14, 2, -4], [34, -10, 3], [24, -8, 0], [-10, -11, -1], [-4, 16, -17], [4, 3, -15], [-18, 1, -2], [-10, 6, 4], [-32, 2, -8], [-6, 10, -16], [10, -6, -6], [-8, -8, -2], [-6, 8, -4], [4, 16, -10], [-20, 8, 0], [2, 10, 2], [48, 5, -1], [-30, 9, 0], [36, 12, -2], [-8, -10, 0], [-4, 3, 12], [-34, -3, 7], [0, -16, 10], [-38, -6, -4], [8, -2, -5], [-8, -8, 14], [4, 7, -3], [6, -14, 4], [8, 2, 12], [-16, -10, 11], [-24, -8, -4], [24, -14, -2], [-28, 10, -13], [18, -10, 8], [6, -10, 0], [-16, -14, 19], [-28, 6, -9], [-24, 8, -17], [-48, -4, 4], [8, -2, 4], [46, 4, -4], [-10, 12, -19], [0, 20, -12], [-12, -9, 1], [0, -5, 9], [-20, 12, -8], [6, 24, -6], [28, -4, 9], [4, -7, 11], [26, -6, -6], [0, -4, -8], [-12, -10, -8], [-12, 13, -17], [-18, -10, 12], [6, -6, -8], [-2, 21, -5], [34, 0, -8], [-10, 16, 5], [2, -15, 14], [-22, 6, 4], [-8, -9, 21], [18, 9, 8], [10, 4, 5], [8, -2, 2], [-14, -4, 4], [12, -18, 3], [-20, 14, 6], [-30, -2, 4], [22, -14, 20], [-16, -20, 5], [-42, 5, -15], [8, 18, -2], [4, -6, 0], [-6, 12, -10], [20, -4, 2], [-10, 3, -12], [24, 1, 10], [26, -8, 16], [10, 11, -5], [38, -2, 10], [-10, 2, -16], [-6, -9, 7], [6, 22, -20], [-20, -10, 15], [-40, -3, -2], [-38, 4, 4], [0, -12, 18], [0, 19, -13], [-20, 4, -6], [-36, 4, 4], [-10, 10, 1], [50, 2, -10], [0, 0, -16], [12, -2, 16], [0, 8, -12], [-18, 6, 8], [20, -8, 16], [-50, 2, -8], [8, 2, -16], [-64, 5, -6], [6, 13, -17], [-22, 10, 4], [-36, -3, -2], [40, -10, -2], [16, -18, 2], [-12, -21, 11], [-24, 0, 14], [-38, 1, 4], [-62, -12, 5], [58, 0, 0], [-34, -7, -7], [-28, -21, 16], [-26, -8, 3], [-18, -11, 2], [-6, 12, 6], [48, -3, 1], [-48, 8, -20], [-8, 20, -18], [-24, 4, 6], [30, -4, -10], [22, 0, 12], [42, -10, 12], [-2, 17, -15], [12, -12, -8], [8, -8, 12], [72, -6, 0], [-34, -2, 0], [-4, 19, -29], [22, -14, -2], [-52, 8, -20], [-48, -3, 6], [54, -10, 4], [14, -20, 5], [-64, 2, 2], [-62, 2, 6], [-16, 22, 0], [4, 25, -25], [-12, 18, 4], [-36, -8, 16], [2, 8, -12], [-16, 22, -2], [2, 0, 4], [4, 5, -16], [28, -4, -4], [-18, 6, -16], [-10, 6, -8], [20, -12, 16], [-28, 18, -11], [38, 4, 14], [-16, 8, -20], [-50, -4, 12], [-18, 18, -6], [-48, -4, -4], [-18, -31, 14], [-44, 8, 8], [-14, -18, 16], [-28, 21, -1], [-40, 4, 8], [-34, 6, -4], [36, 18, -18], [4, 0, 0], [-8, -4, -8], [10, -4, 4], [12, -6, 0], [40, 5, -6], [-40, 12, -14], [-24, 18, -12], [2, 8, -1], [-50, 4, 5], [-14, 0, 16], [18, -14, 14], [-58, 6, 6], [-26, -15, 16], [6, 10, -8], [-2, 9, -21], [34, -5, 25], [32, 16, -6], [-18, 10, -19], [10, -11, 14], [12, 2, 12], [42, 4, -10], [4, 9, 7], [-36, -12, 0], [-56, 4, -6], [20, 14, -22], [-12, 7, -24], [-64, -12, 10], [42, 22, -15], [64, 0, 6], [-24, -17, 6], [-48, 15, 1], [38, 20, -18], [12, -24, 18], [-8, -3, 11], [-18, 4, 9], [50, 3, -5], [2, 0, 20], [6, -24, 12], [-8, 18, -17], [28, -12, 10], [42, 20, -6], [-42, 16, 8], [-16, -8, 4], [-44, 6, -14], [-12, 15, 0], [6, -8, 3], [10, -3, 2], [32, -8, 21], [32, -7, -5], [-20, 10, -14], [10, 4, 8], [6, -18, 10], [24, -12, 0], [-16, 4, -20], [66, -6, 2], [28, 25, -23], [16, -28, -2], [-14, 4, -12], [-12, -12, -2], [-48, 6, -25]];
    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_cc();".
// 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_cc(: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_cc();".
// 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_cc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4830_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-24, 0, 6, 1]>,<13,R![-136, -24, 6, 1]>,<17,R![-72, -36, 0, 1]>,<19,R![-456, -72, 6, 1]>,<29,R![136, -84, 0, 1]>],Snew);
    return Vf;
end function;