
// Make newform 4730.2.a.n in Magma, downloaded from the LMFDB on 19 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_n();".
// 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_n();".
// 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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, 1], [-1, 0], [0, -1], [1, 0], [-1, 1], [-1, -2], [0, 3], [3, 1], [0, 1], [-1, -2], [0, -3], [3, -3], [1, 0], [2, 4], [-3, 4], [-9, -3], [-10, -3], [-4, 2], [6, -3], [10, 0], [1, 3], [7, 5], [-12, -1], [-2, -6], [2, -6], [2, -10], [2, -2], [-4, 4], [-2, -2], [4, -6], [10, -5], [3, 5], [0, 6], [2, -1], [-15, 5], [-4, -7], [-2, -7], [-1, 0], [-6, 4], [-12, -4], [-14, 4], [0, -2], [-13, -8], [-10, -6], [-10, 7], [6, 1], [23, 3], [-10, 4], [-14, -4], [6, -7], [-26, 0], [-15, 5], [-7, 7], [14, 8], [22, -5], [9, -3], [-11, 1], [-25, -3], [15, -3], [-12, 10], [9, -5], [-14, 4], [1, 10], [-16, -2], [25, 2], [-10, -10], [-17, 2], [-6, 16], [8, 10], [7, 1], [2, 2], [-7, 13], [11, 11], [-17, 9], [-13, -5], [9, 9], [32, 4], [-15, -2], [-2, -2], [21, -1], [-12, -16], [-19, -3], [4, -12], [7, 15], [-18, 4], [10, -4], [-2, 21], [-17, -8], [-20, 10], [-10, -15], [14, -6], [-21, 7], [6, 7], [-21, 1], [-20, 8], [18, 14], [-6, -4], [-1, 13], [19, 12], [16, 0], [26, 4], [9, 7], [-11, -15], [8, 3], [8, 2], [-18, -5], [8, -22], [-27, 0], [-1, -9], [12, -1], [-11, -1], [-45, -1], [5, -3], [-42, 1], [-4, -3], [-19, 4], [23, 3], [-22, -13], [21, -6], [-10, 0], [-18, -7], [-17, 13], [-33, -6], [17, 5], [-3, 16], [19, -15], [31, -8], [-16, -6], [17, 3], [-8, -14], [26, 7], [38, 5], [4, 2], [15, -5], [16, -10], [18, 15], [14, 2], [30, 2], [-27, -9], [-14, 5], [-12, 8], [-15, 13], [18, 6], [-1, 1], [0, 24], [-11, -21], [45, -4], [-38, 0], [22, 16], [-20, 10], [-38, 2], [13, -2], [32, -8], [-7, 8], [12, 9], [6, 18], [20, -1], [40, -8], [-5, 4], [-45, 2], [16, 7], [-1, -16], [12, 16], [6, 10], [3, -5], [-24, -16], [30, -6], [-28, -10], [3, 32], [-6, -9], [29, -7], [33, 5], [1, -20], [20, -12], [-21, 2], [-20, 0], [20, 20], [-15, 8], [10, -29], [-4, -6], [-33, 10], [34, 9], [10, -1], [-27, 1], [-18, -24], [-21, 13], [28, 16], [60, -2], [-24, -4], [-21, 3], [3, 17], [1, 3], [9, 19], [15, 5], [-4, -2], [8, 12], [-18, -22], [48, -8], [0, 25], [-9, -2], [20, -22], [-14, -13], [-42, 6], [9, 3], [-12, 7], [8, -6], [20, -4], [19, -1], [-4, 28], [-6, -11], [66, -2], [38, 2], [39, -8], [-6, 14], [21, 4], [36, 11], [42, 8], [-41, 5], [23, -14], [28, -2], [20, -14], [36, 15], [30, -2], [23, -7], [7, 20], [52, -2], [28, -7], [-20, 0], [-38, -18], [-24, -18], [27, -12], [-2, -4], [-16, 14], [12, -24], [-31, 24], [-34, -17], [-25, 17], [-7, 35], [-37, 22], [-42, -13], [-12, -28], [-58, -2], [-41, -7], [-4, 2], [2, -8], [0, -40], [-35, 3], [15, 20], [-25, -16], [4, -2], [-26, -6], [-20, -10], [8, 9], [-30, 26], [2, -41], [26, 2], [2, -40], [24, 30], [-21, 14], [52, 8], [-18, -2], [-3, -36], [29, 11], [-12, 16], [-32, 4], [34, -18], [11, 0], [-13, 13], [-8, 26], [7, 21], [-22, -5], [11, 41], [1, 9], [-1, 12], [-57, 7], [-20, -10], [52, -10], [-33, 21], [10, 11], [15, 6], [-48, 14], [-46, -4], [-4, -9], [-17, 33], [36, 1], [-6, -28], [50, 8], [14, 7], [-8, -38], [-30, 22], [-18, -32], [-13, -2], [22, -35], [-66, 4], [-18, 16], [26, -16], [41, -4], [-20, 18], [-38, 12], [15, -40], [-30, 14], [-21, -5], [12, 24], [10, -40], [45, 11], [32, -20], [47, 17], [0, -13], [-8, 36], [-48, 18], [10, -4], [70, -2], [-12, 3], [3, -46], [24, 6], [-20, 14], [-57, -17], [45, 11], [1, 31], [17, -28], [50, 24], [8, 2], [-25, -11], [-40, -5], [-31, 20], [-3, 45], [-2, 8], [3, -28], [47, -11], [-40, 23], [-20, -8], [13, -25], [13, 1], [7, -18], [-33, 2], [25, 13], [-8, -17], [-58, -11], [-20, 9], [-52, -4], [-7, 17], [-2, -45], [34, -5], [-5, -24], [31, -34], [22, -10], [31, -22], [1, -1], [33, -14], [-31, 4], [-29, -5], [-55, -19], [24, 13], [-15, 12], [0, -15], [-4, 15], [-8, 27], [48, -4], [-12, 36], [6, -16], [-23, -37], [-64, -4], [-8, -41], [-31, -18], [13, 47], [51, 15], [17, -30], [10, 6], [11, -27], [5, 7], [-52, 4], [-24, -43], [58, -16], [32, 14], [-19, 23], [-39, -5], [3, -24], [39, 17], [18, 11], [-61, 7], [15, -23], [-24, -18], [-24, -41], [-40, -10], [-12, 20], [32, -8], [29, 28], [41, -11], [-18, -20], [-23, 34], [64, -1], [4, -20], [-32, 16], [6, 14], [22, 6], [-10, 48], [18, -27], [-37, 31], [-44, 25], [35, -8], [4, -14], [-68, 14], [13, 37], [54, -4], [22, 0], [2, -15], [-28, -6], [6, -47], [-47, 7], [54, 22], [-27, 35], [-36, -30], [50, 12], [-24, -36], [-33, 19], [-27, -11], [-33, 39], [-53, 9], [18, -11], [1, -53], [12, 0], [-30, -6], [-31, 6], [-23, -19], [-78, 7], [12, 45], [52, 20], [-28, -8], [67, -5]];
    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_n();".
// 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_n(:prec:=2)
    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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4730_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 0, 1]>,<7,R![-3, 0, 1]>,<13,R![-2, 2, 1]>],Snew);
    return Vf;
end function;