
// Make newform 4624.2.a.bg in Magma, downloaded from the LMFDB on 22 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4624_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_4624_2_a_bg();".
// 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_4624_2_a_bg();".
// 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, 1, 0], [-2, 0, 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_4624_a();"
function MakeCharacter_4624_a()
    N := 4624;
    order := 1;
    char_gens := [4047, 1157, 4049];
    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_4624_a_Hecke(Kf)
    return MakeCharacter_4624_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 := [[0, 0, 0], [1, -1, 0], [-2, -1, 1], [0, 1, 0], [2, 0, 2], [2, -1, 3], [0, 0, 0], [0, -1, 1], [4, -2, 1], [0, 2, -1], [3, -1, -2], [1, -3, -1], [-2, 3, 1], [-5, 1, 3], [7, 0, 1], [-6, -4, 2], [3, -1, -4], [1, 1, -2], [3, -6, 7], [7, 4, -3], [7, -2, 5], [1, 2, -6], [-3, -4, -2], [-5, 5, -7], [-2, 6, 0], [2, -4, -1], [8, -3, -5], [11, 0, 3], [8, 0, -4], [0, -4, -3], [2, 1, 5], [12, 8, -5], [-1, 6, -7], [-5, -6, 3], [10, 0, -1], [2, 3, 4], [2, -9, -2], [-3, 3, 3], [1, 3, -1], [3, -7, 15], [2, 4, -9], [-7, 10, -8], [-1, 7, -7], [14, 0, 7], [5, -7, 13], [10, -5, 13], [3, -5, -10], [7, 2, 6], [7, -8, 8], [-2, -1, 12], [21, -6, -3], [2, 9, -2], [-3, 5, -16], [1, 12, 4], [-2, 5, 0], [-5, 15, 0], [-7, -8, 4], [-17, 0, 0], [7, 15, -12], [13, 0, 10], [-22, -3, -3], [2, 8, -2], [0, -4, -1], [2, 1, -1], [-9, 0, -4], [-1, 15, -11], [-6, 0, -8], [11, 7, -5], [1, -18, 8], [-10, 12, -4], [1, 18, -5], [1, -3, -8], [4, 6, -9], [-15, -4, -1], [6, 10, -3], [-7, 5, 4], [-15, 6, -6], [-3, -17, 7], [-19, -10, 8], [5, 11, -10], [-6, -1, 6], [-8, 2, 8], [2, 19, -15], [-12, 2, 0], [22, 12, -3], [-6, 8, -15], [-3, -12, 10], [-17, -7, 12], [9, 17, -14], [-1, 7, -7], [15, -8, 7], [28, -4, 12], [2, 17, 2], [-5, 17, -1], [7, -8, -9], [4, 23, -9], [-9, -16, 13], [12, 6, 8], [-3, 3, 6], [-19, -1, 10], [1, 16, -17], [15, -10, 5], [-3, 5, -23], [25, -4, -10], [-1, -18, 19], [-6, -5, 3], [3, 2, -18], [1, 8, 3], [-6, -17, 4], [-11, -1, -23], [-9, -1, -3], [4, -4, -1], [13, 20, -15], [-2, 22, -16], [3, 10, 8], [-9, 3, 12], [-16, -14, 16], [-3, 19, 9], [-10, -15, 5], [12, 7, -10], [5, 17, -16], [-8, 2, 11], [7, 15, -20], [-6, -4, 12], [20, -2, -7], [5, 19, -12], [-13, -23, 14], [22, -5, -11], [14, -14, -11], [13, -8, 1], [-16, 3, -3], [6, -14, -2], [-29, 8, -2], [9, 8, -5], [5, -7, -7], [1, -7, -10], [3, -11, 18], [1, 20, 8], [7, 13, -17], [2, -18, -11], [-27, 1, 6], [18, -7, 8], [-16, -1, 8], [-7, 1, 15], [15, 7, 5], [38, -2, 1], [-5, 9, -15], [-13, 8, -19], [17, 25, -8], [-23, -25, 16], [-23, -2, -7], [-15, 25, -9], [31, -11, -7], [-16, -18, 17], [-5, -1, -20], [16, -18, 2], [31, 2, 9], [-13, 5, -5], [34, -16, -1], [22, 18, -14], [-22, -9, 12], [16, 6, -7], [5, 14, -23], [-5, 9, -5], [-15, -26, 10], [16, 24, -17], [5, -22, -11], [14, -15, 24], [-14, 5, 4], [5, 27, -4], [3, -6, 24], [8, 5, 14], [32, -9, -13], [-13, 12, -32], [0, -18, 1], [14, -9, -8], [-25, 21, 12], [3, -24, 24], [20, -15, -1], [-13, 19, -7], [-33, 15, -9], [3, 12, -18], [-1, -3, -8], [30, 17, -7], [9, 23, -8], [39, 2, 5], [-14, 13, 6], [2, 26, -2], [14, -12, 27], [27, -5, 13], [-12, 2, -2], [-15, -20, -1], [-15, -31, 21], [-9, 13, -10], [-26, 6, 4], [7, -32, 13], [13, 38, -35], [-32, -10, -4], [35, 1, 15], [-14, -23, 24], [-22, 5, -6], [17, -16, 34], [-17, 3, -13], [7, -19, -1], [-29, 3, 5], [-5, 11, -41], [-18, 24, 10], [-12, -39, 12], [-33, 10, -17], [7, 37, -29], [-14, 6, -27], [-28, 14, -29], [5, 11, -8], [-20, 13, -19], [37, -9, 0], [23, -10, -4], [-24, 10, -40], [-7, 1, 30], [-10, -13, 22], [-10, -11, 26], [1, 27, -10], [2, 18, -1], [39, -17, 1], [15, 2, -15], [-22, -24, 28], [-15, -17, 0], [-39, 5, 11], [38, -4, 1], [23, 21, -2], [-10, 26, -26], [9, 11, 15], [14, -23, 1], [-21, 16, -6], [-37, -10, -8], [-6, 0, 4], [-4, -4, -9], [-26, -13, 20], [11, -27, -5], [-5, 11, 3], [-18, -42, 31], [11, 9, 13], [-22, -28, 27], [19, 10, -22], [9, 34, -14], [-38, -15, 16], [9, -20, 39], [37, -5, -18], [2, -20, -1], [-17, -27, 5], [20, -7, -26], [-29, 7, -11], [-6, -6, 28], [31, -3, 2], [5, 20, 3], [16, -5, -13], [1, 3, -25], [25, 12, -7], [-12, 5, -44], [3, 40, -10], [23, 34, -26], [-8, 38, -39], [11, -9, 2], [24, -32, -4], [-43, 21, -14], [21, 21, 7], [-4, 25, -15], [29, -32, 2], [53, 25, -19], [25, 7, 16], [10, -37, 12], [-11, 21, -20], [-28, 2, -7], [-23, -21, 36], [45, -17, 26], [28, -13, 11], [28, 2, 8], [-21, -10, 20], [-16, -7, 24], [0, 17, -17], [10, -29, 21], [-27, 8, -28], [-21, 6, 3], [15, -9, -13], [46, 22, -12], [5, -22, 31], [-30, -12, -3], [-28, -13, 22], [47, 7, -15], [1, 23, -34], [0, 1, -18], [13, 3, 28], [6, -45, 6], [32, 13, -8], [10, 11, 22], [-16, 0, -10], [-6, 8, -34], [24, 51, -33], [27, 18, -21], [1, 16, -26], [7, 10, -41], [-16, -41, 24], [-1, -54, 20], [15, 18, -23], [-3, -6, -33], [46, -2, -6], [-38, 4, -35], [10, 19, -21], [25, -5, 27], [23, 5, -20], [14, -25, 14], [22, 30, -42], [10, 50, -40], [12, -8, -23], [19, 4, 25], [39, -13, 19], [-1, -22, 21], [38, -20, 4], [-14, -5, 16], [-19, -18, 18], [-15, -9, -36], [14, -5, 13], [8, 3, 29], [3, 11, 24], [24, -18, 4], [47, -13, 16], [-23, 30, -32], [-33, -18, 0], [-5, -27, 21], [-8, 21, -56], [0, -35, 25], [20, 7, -13], [-2, -10, -9], [11, 27, -13], [14, -45, -7], [27, -2, 29], [-29, 13, 26], [5, 2, 0], [-7, 50, -23], [31, 22, -33], [16, -41, 1], [-21, 1, 31], [25, -15, 46], [-1, 14, 1], [16, 2, 26], [-9, 30, -39], [-6, 9, -21], [-10, 22, 4], [51, -21, -1], [29, -19, 28], [11, 8, 34], [-3, 28, -35], [27, -8, -13], [-38, -22, 3], [-22, -6, 3], [21, 35, 6], [-68, 3, 4], [-44, 19, -11], [-48, -1, -2], [36, 29, -10], [38, 17, 7], [10, 25, -25], [22, -24, 30], [-3, -45, 27], [-20, 10, -4], [36, -22, 17], [-1, -3, 20], [-18, -47, 8], [-47, -37, 33], [10, -25, 29], [29, 0, 16], [11, 1, 23], [-7, -23, 39], [-27, -14, -29], [-2, -17, 17], [23, -30, 31], [-31, 9, -43], [5, 25, -11], [22, -18, 48], [13, 3, -4], [11, -22, -31], [19, 29, -27], [6, -2, 43], [16, 0, 27], [-6, -27, 37], [61, -2, -5], [-28, -25, 34], [-24, 13, -21], [2, -26, -7], [3, -1, -19], [29, -28, 27], [-10, 36, -38], [28, -6, 3], [28, 9, -18], [-4, -38, 3], [56, -22, -5], [33, 22, -1], [-59, -1, 4], [18, -27, -35], [55, -4, 1], [1, -24, 24], [-46, 9, -12], [-30, -8, 15], [3, 8, -31], [12, 55, -43], [9, -14, 39], [-13, -24, 7], [-39, 2, -15], [17, 20, 4], [3, -16, 29], [17, 39, -43], [-23, -26, 17], [3, -13, 2], [36, -16, -17], [13, 6, 20], [-67, -15, 9], [-8, -23, -13], [21, -19, 1], [-14, -52, 32], [15, -48, 18], [-55, 5, -2], [-49, 14, 15], [17, 3, -27], [-70, 5, 10], [19, 3, 38], [-17, 36, -52], [-3, 23, 27], [-11, -41, 14], [-34, 13, -20], [-9, 49, -25], [26, -17, -30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4624_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4624_2_a_bg();".
// 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_4624_2_a_bg(:prec:=3)
    chi := MakeCharacter_4624_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_4624_2_a_bg();".
// 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_4624_2_a_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4624_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![3, 0, -3, 1]>,<5,R![1, 9, 6, 1]>,<7,R![-1, -3, 0, 1]>,<13,R![71, -9, -6, 1]>],Snew);
    return Vf;
end function;