
// Make newform 4730.2.a.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4730_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_4730_2_a_t();".
// 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_4730_2_a_t();".
// 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 := [-5, -8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-5, -1, 1]];
    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_4730_a();"
function MakeCharacter_4730_a()
    N := 4730;
    order := 1;
    char_gens := [947, 431, 1981];
    v := [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_4730_a_Hecke(Kf)
    return MakeCharacter_4730_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], [0, 1, 0], [1, 0, 0], [0, -1, 0], [-1, 0, 0], [-4, 0, 0], [-3, -1, 1], [1, -1, -1], [0, 0, 0], [4, 0, -1], [2, -2, -1], [-2, 2, -1], [2, -2, 0], [1, 0, 0], [0, 1, -1], [1, -1, -3], [-4, -1, -1], [0, 4, 1], [-4, 0, 0], [-4, 1, 0], [-10, -2, 2], [0, -1, 3], [-4, 1, -3], [0, -4, 1], [6, 0, 2], [-4, 3, 1], [-5, -1, 2], [1, -3, 2], [3, -3, 2], [-11, -3, 2], [-8, 4, 0], [2, 2, -1], [2, 0, 4], [8, 4, -4], [6, 0, 3], [-16, -2, 2], [-12, -2, 1], [-1, 1, -1], [-8, 0, -1], [-2, -4, 0], [4, -4, 0], [-4, 2, 4], [3, 1, -4], [-6, -3, -4], [8, 6, -2], [-11, -1, -1], [-4, 7, 2], [0, 0, -4], [-12, 4, 2], [0, 0, 2], [-4, 4, 3], [-3, -7, 4], [-2, -7, -1], [9, 1, 2], [-17, -1, 0], [-1, -3, -5], [12, 6, 0], [-8, 8, 2], [-1, 3, 0], [20, 2, 2], [1, 5, -4], [4, 2, 6], [-12, 7, 1], [14, -2, 3], [-5, -1, -4], [-2, 7, 4], [-6, -4, -6], [11, 5, -5], [-18, 0, 0], [18, -4, 0], [10, 6, -4], [0, 0, 0], [-3, 5, 0], [6, 1, 7], [4, -1, -1], [10, 2, 0], [6, 7, 5], [4, -1, -7], [-3, 3, -3], [9, 9, 2], [-6, -6, -6], [15, -5, -2], [0, 5, 7], [-10, 8, -2], [-15, 1, 4], [-22, 0, -2], [-6, 4, -4], [-8, 0, 1], [9, -1, -5], [-6, 0, 8], [-3, 3, 3], [-12, 4, -4], [-8, -3, 7], [-8, 1, 4], [-6, 0, -4], [21, -5, -4], [12, 2, -2], [20, 0, -2], [-18, -8, 4], [-10, -3, -12], [12, -3, 5], [-22, -4, -4], [8, 0, 4], [-18, -2, 2], [-25, -3, -3], [-2, -13, -1], [4, -9, -4], [-4, -6, -8], [4, 4, -5], [-18, 7, 1], [-25, 9, 3], [4, -14, -6], [2, -2, 6], [-11, 9, 4], [-4, 13, -4], [18, -10, -5], [6, -2, 1], [2, -2, 0], [8, -6, -5], [-4, 12, 7], [12, -2, -8], [2, 8, 1], [6, 7, 11], [22, -4, -3], [-14, 6, 4], [15, 5, -5], [-22, -2, 8], [-4, 6, 1], [0, -4, 6], [-3, 9, -4], [14, -7, -5], [-8, -1, -12], [-20, 7, 0], [2, 6, 6], [-22, -4, 2], [20, 10, -4], [16, 2, -3], [-23, -3, -2], [-12, 5, 7], [12, -16, -8], [-8, 7, 0], [4, 7, -11], [-32, -4, 2], [-32, 8, 0], [-6, -4, 0], [4, -8, 4], [-12, -6, 2], [14, 9, -8], [10, 14, 2], [-8, -6, 8], [-28, -2, -4], [-20, -3, -1], [-16, -6, -3], [-3, -5, -4], [-14, -6, -11], [13, -9, -1], [-24, -3, 5], [18, -12, -3], [-10, 2, 10], [11, -7, 5], [12, 8, -5], [-8, -2, 7], [-4, 6, 3], [17, 5, 2], [-2, 4, 10], [30, 2, 4], [28, 0, 4], [2, -17, 5], [-2, -8, 0], [6, -1, -2], [-9, 1, -13], [14, -11, -1], [-8, 14, -6], [8, 2, -5], [15, 9, -4], [30, 1, -4], [4, -12, 4], [10, 5, 15], [-4, -6, 3], [2, 6, 9], [-6, -6, 2], [6, -2, 5], [-4, 2, -5], [2, 10, 3], [-4, -8, 12], [-18, 7, -1], [-13, -9, 12], [51, 5, 0], [0, -4, -6], [-44, -4, 0], [8, -12, -6], [-4, -4, 2], [8, 13, -7], [7, 7, 4], [22, -2, -2], [18, 7, -1], [-22, 2, 4], [3, -7, -6], [-12, 5, 7], [-3, -17, -1], [-28, 6, 7], [-26, -4, -4], [52, 0, 1], [6, -4, 6], [-14, 12, -4], [-2, 6, 11], [-6, -11, -5], [-16, -8, 0], [10, 7, 1], [-33, -1, 6], [-34, 2, 1], [24, -8, 8], [-20, -9, -5], [2, 0, -11], [-18, 20, 10], [-8, -6, 7], [17, 3, -9], [30, -1, 7], [12, -6, 0], [11, -7, -1], [16, 0, 10], [0, -8, -14], [0, 12, -3], [16, 7, -9], [8, -4, 2], [-50, -1, -4], [6, -8, -4], [1, -9, -13], [27, -7, 0], [-1, 5, 8], [24, -4, 6], [18, 0, 5], [-40, -5, -7], [-5, -9, -16], [36, -12, -4], [-28, 14, -1], [14, -4, 13], [-36, -4, -8], [14, 0, 16], [-12, -6, 9], [-5, -3, -7], [-27, 7, 4], [0, -17, -5], [4, 10, 6], [10, 2, -6], [8, 11, 5], [48, 4, 4], [11, 15, -2], [-26, -14, -3], [-12, -10, 7], [-2, 12, -8], [24, 6, 18], [-29, 3, 8], [-38, 4, -3], [14, 13, 3], [-16, -11, 12], [-31, 5, -2], [-32, -7, 11], [28, 10, 4], [3, -15, -1], [-2, -13, 5], [14, 6, -8], [-20, -6, 13], [-2, 20, 2], [-34, -5, -3], [46, 8, 2], [17, 13, -18], [57, -5, -1], [-28, 8, -2], [-26, -4, -12], [-30, 12, 2], [-14, -6, -11], [22, -7, 5], [14, -16, -14], [66, -5, -2], [24, 12, -4], [16, 6, 2], [-28, 12, 6], [24, 16, 4], [-40, 5, 2], [-14, 2, 15], [24, -2, -2], [14, -14, 0], [50, -10, 1], [26, -6, 6], [-42, 6, -3], [-42, -14, 10], [-31, -19, 8], [-13, -15, 3], [-4, -20, 6], [20, 8, 20], [2, 2, 8], [24, -2, -13], [35, 13, -15], [30, 4, -8], [-8, 5, 3], [-34, 18, 0], [-36, -6, 9], [-40, 10, -6], [-36, -15, -1], [-10, -11, -10], [-10, -12, -2], [-61, -5, -4], [24, -2, 2], [30, 0, 8], [39, 15, -4], [-40, -4, 8], [65, -3, 0], [31, -3, 5], [15, -9, 2], [30, 3, -15], [42, 3, -9], [2, 2, -4], [60, 3, 2], [48, 8, -5], [-10, 14, 10], [31, 3, 8], [-16, -8, 6], [-36, -2, -2], [1, -3, 8], [-14, 26, -1], [-2, -5, 3], [-34, -12, 16], [-16, -5, -1], [8, 22, -9], [33, -13, -3], [20, -24, -12], [16, -12, -8], [4, 6, 5], [-2, 3, -1], [-14, 0, 1], [-17, 5, 6], [38, -8, 8], [-14, -26, 4], [-54, 0, -1], [-14, 14, -3], [-58, -3, -9], [8, 2, -7], [22, 4, 15], [-26, -2, -3], [24, 13, 7], [10, -1, -3], [18, 6, 3], [20, -31, -8], [-14, 13, 4], [-26, -22, 3], [10, 5, -1], [-22, -14, 11], [26, -8, -12], [-18, -17, -4], [-24, -2, -5], [6, -9, -7], [-28, -6, -8], [-30, 22, 7], [10, 17, 2], [8, -2, 15], [24, -23, 2], [-40, -7, 14], [0, -7, -5], [7, -5, -2], [14, 12, -12], [-27, 13, -4], [0, 0, 0], [8, -9, 4], [-16, 24, 9], [-22, 11, 7], [26, -23, 3], [-26, 2, -1], [-35, 9, 10], [-32, -6, -16], [-22, 10, 2], [-44, -16, 12], [18, 16, 11], [-8, 16, -6], [-44, 14, 8], [-18, -6, -6], [-16, -7, -19], [-31, 11, -11], [-34, 0, -8], [-48, -16, 9], [-40, 16, 6], [18, 22, -4], [-36, -10, -6], [-32, 12, 5], [26, -32, -10], [-8, -11, -11], [-50, -5, -3], [46, 11, -16], [-4, 27, -3], [33, -27, -12], [2, 21, -6], [-6, 0, -9], [30, 8, 10], [6, 6, -4], [22, 11, 9], [-36, -5, 1], [44, 7, 5], [6, 10, -1], [-20, -12, 4], [16, 10, -5], [59, 5, 1], [-18, -12, 12], [50, 14, -8], [-34, -14, 6], [-54, 10, 2], [28, -16, -10], [2, 4, -1], [30, -2, -10], [29, 11, -11], [-49, -5, -6], [1, 23, 2], [66, 3, -9], [68, 0, -8], [16, -22, -10], [16, 22, 0], [16, 8, 6], [-24, -11, -13], [-17, 15, -8], [-22, -14, 0], [9, 15, 9], [-7, -27, 4], [28, 4, 0], [46, -26, -8], [12, -10, -17], [-18, -28, 6], [8, 16, 9], [-6, -18, 9], [-9, -5, 2], [8, -11, -7], [-10, -10, 8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4730_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4730_2_a_t();".
// 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_4730_2_a_t(:prec:=3)
    chi := MakeCharacter_4730_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_4730_2_a_t();".
// 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_4730_2_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4730_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, -8, 0, 1]>,<7,R![5, -8, 0, 1]>,<13,R![4, 1]>],Snew);
    return Vf;
end function;