
// Make newform 4900.2.a.bd in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4900_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_4900_2_a_bd();".
// 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_4900_2_a_bd();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-4, 2, 1], [-3, -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_4900_a();"
function MakeCharacter_4900_a()
    N := 4900;
    order := 1;
    char_gens := [2451, 1177, 101];
    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_4900_a_Hecke(Kf)
    return MakeCharacter_4900_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], [0, 0, -1], [0, 0, 0], [0, 0, 0], [1, 0, -1], [3, 0, 1], [3, -1, 0], [1, 1, 0], [1, 1, -1], [1, 1, 2], [0, -1, -2], [-1, 0, 3], [-3, -1, 3], [3, -1, -1], [2, 1, 1], [-6, -1, -3], [2, 0, 1], [-6, 1, -2], [-6, 0, 2], [-7, 0, -2], [4, 0, 0], [-1, 1, -3], [11, 1, 4], [4, -1, -1], [6, 2, 1], [0, 3, 0], [4, 2, 3], [11, -1, 1], [-5, -2, 1], [2, 3, -2], [-1, 1, -3], [-2, -3, -4], [1, 1, 5], [13, 2, 3], [9, 3, 6], [9, 1, 2], [4, 2, -3], [10, -1, 1], [-1, 2, 1], [14, 1, -2], [-2, -2, 2], [-5, -1, 0], [5, 2, 4], [-11, -1, -5], [0, -2, 3], [2, 1, 5], [4, -3, -2], [10, 2, -3], [4, -3, 2], [8, 0, -1], [5, 2, 4], [11, 1, -2], [5, -3, -1], [-6, -3, -6], [18, 2, 0], [-8, -4, -1], [-11, 4, 2], [-8, 1, 3], [-2, -2, -5], [-8, 2, 2], [2, -2, -7], [18, 1, -3], [3, -5, 1], [2, 2, 10], [1, 0, 3], [-5, 0, -4], [-7, -2, 6], [20, 1, 6], [2, 4, 1], [-8, -1, 3], [8, 5, 4], [0, -5, 0], [-20, -1, 0], [-10, 3, 0], [0, 3, 2], [-1, -4, 7], [-13, -3, 7], [-6, 1, 1], [-2, 0, 5], [-3, -6, -2], [5, -1, -2], [2, 0, 9], [11, -4, 1], [3, 5, -2], [7, -1, -9], [8, 1, 4], [11, -4, 4], [-10, -5, 3], [12, 1, 6], [2, 6, 6], [24, -1, 0], [13, -2, 5], [-1, -3, 0], [-14, 4, 2], [-5, 4, 4], [-15, -3, 0], [-16, -6, -8], [0, 2, -6], [11, 0, 2], [2, -1, -3], [-10, -4, 3], [7, -3, -1], [9, 2, 0], [-17, 7, 2], [-28, 2, 3], [8, 3, 14], [-6, -1, -3], [8, 2, 4], [-6, 0, 6], [11, 5, 5], [-23, -1, 0], [5, 5, 0], [-22, -3, 4], [17, 4, -4], [-2, 5, 4], [10, -1, -10], [-11, -4, -6], [-10, -3, -11], [4, -7, -7], [-16, 4, 7], [4, 2, 0], [-4, -2, -15], [21, -3, -6], [36, 1, -3], [-11, -4, -9], [5, -5, -2], [18, 2, -1], [-38, 1, -4], [-19, 2, -1], [-14, -1, 6], [17, -2, 6], [-12, 0, -15], [2, 6, -3], [21, 5, 8], [17, 2, 10], [-26, 5, 0], [17, -7, -5], [-15, -5, 1], [24, 0, -3], [-3, 3, 0], [1, -3, 9], [0, 3, -12], [-8, 3, -8], [-22, -3, -8], [16, 3, 15], [-22, -2, 4], [-23, -6, 9], [41, -1, 1], [25, -2, 3], [-18, 5, 3], [-6, -2, -4], [30, 2, 3], [-7, -10, -3], [7, 3, -7], [-25, 0, 6], [-24, -3, 3], [-18, -5, 8], [-22, 0, -11], [-13, -5, -4], [15, -4, -3], [12, -2, 12], [-17, 7, 5], [11, -5, 0], [25, 4, -4], [27, 0, 9], [-28, -2, -11], [-11, -6, -2], [-8, -3, 3], [-14, 9, 1], [13, -1, -4], [-2, 11, 2], [10, 0, 15], [12, -9, -6], [32, -1, 0], [3, -1, -14], [-15, -5, -9], [42, -1, 5], [-4, 8, 13], [-16, -2, 5], [-6, 4, -14], [14, -6, -9], [-3, 6, -6], [-12, 4, -4], [27, -4, -3], [1, 7, 14], [-26, -8, -7], [-11, 9, 1], [-17, 3, 3], [-14, 0, -5], [12, -3, -3], [-26, -5, 0], [-28, -5, -8], [39, 5, 17], [31, 3, -7], [18, 0, -6], [20, -7, -5], [-22, -5, -18], [8, -8, 6], [14, 8, 19], [-23, 0, 8], [-7, -2, 7], [31, 3, 6], [-17, -2, 0], [-32, -2, 3], [-26, -2, -10], [27, 8, 9], [-6, -4, -17], [-3, 6, 6], [-3, 0, -12], [-46, -2, 5], [-12, -3, -4], [-9, 6, 6], [10, 3, 13], [20, 1, -2], [4, -2, 11], [-29, 3, 3], [5, 4, -6], [38, -1, 4], [46, 3, -1], [4, 1, 8], [-14, -1, 7], [-22, 10, 8], [29, 2, -5], [-40, 5, 0], [2, -5, 7], [-2, -1, -8], [19, 5, 14], [20, 0, 4], [-5, -10, 12], [1, -4, 11], [8, -11, -3], [16, 7, 6], [-36, -7, -10], [30, 0, -12], [-11, -1, -12], [15, -3, 3], [1, -7, 12], [-12, -5, -3], [2, 0, 7], [25, 2, -16], [34, 6, 5], [-35, 0, 9], [-5, -5, 21], [10, -3, -2], [27, -6, -3], [-50, 1, 5], [14, -11, -4], [-6, -9, -6], [17, 6, 12], [-1, -3, 13], [8, -11, 0], [32, -1, 7], [28, -8, 2], [0, -3, 19], [7, 1, -7], [2, -2, 19], [1, -7, -2], [-11, -4, -9], [16, -2, -10], [-29, 4, -3], [-19, -7, 6], [-41, 0, -1], [16, -1, -9], [20, 4, -1], [19, 4, -16], [19, -6, 12], [14, -7, -14], [-43, -2, -5], [-13, 4, -12], [-26, -2, 17], [7, -2, -9], [-10, -4, -21], [-26, 0, -15], [-3, 3, -10], [22, 0, -15], [0, -4, 4], [2, 3, -5], [-6, 13, 2], [-11, -2, -2], [13, 5, 11], [-25, -3, 13], [-4, 9, 6], [-1, -7, -17], [15, -3, -5], [-16, -2, -7], [64, -2, -1], [0, 5, 14], [-18, 3, -18], [10, -6, 18], [-1, -4, 13], [43, 1, 5], [44, 4, 13], [2, 4, -11], [4, 0, -7], [7, 4, 22], [-15, -9, 3], [-7, -6, -4], [51, 1, 12], [16, 7, 17], [-23, 12, -3], [7, 4, -6], [28, -13, -1], [-43, -11, -33], [-29, -5, 11], [-37, -9, -12], [1, 13, 13], [2, -6, -20], [13, 7, 3], [-17, -5, 14], [-7, 12, 3], [3, -15, -12], [-9, 3, -9], [-25, -2, -20], [-42, -2, -13], [-55, 2, 7], [39, 2, -11], [-29, -5, -7], [31, 1, -1], [-16, 14, 5], [32, 0, 1], [25, 11, 3], [8, 1, 9], [-50, 6, 5], [52, 1, -11], [-27, 0, -15], [4, -9, -15], [3, -8, 5], [47, 5, 5], [-15, -7, -3], [-30, -6, -9], [-21, -2, -19], [-31, -1, -5], [-20, 11, 0], [43, 7, 2], [6, 1, -25], [-4, 11, 7], [-15, 14, 8], [31, 10, -22], [-12, 7, 13], [16, 0, 3], [-17, 3, 1], [13, 0, 23], [29, 8, 16], [-31, 6, -3], [30, 6, 3], [-14, -3, -13], [-49, -1, -1], [38, 7, 9], [31, -14, -7], [23, 2, 25], [-33, -7, 7], [-16, -16, -15], [-25, -13, -17], [-26, 0, 3], [6, 6, -19], [38, -1, -2], [-41, -5, -28], [31, 2, 2], [33, 3, 21], [32, 8, 13], [0, -8, -16], [-33, -7, -21], [11, 6, -11], [6, 2, -21], [40, 2, 15], [24, 2, -16], [32, 0, -5], [-22, 7, 12], [-5, -3, -5], [11, -10, -2], [26, 9, -13], [34, -3, 8], [17, -4, -11], [25, -9, -15], [19, 6, 31], [-1, 16, -8], [7, -2, -13], [14, -17, -7], [-27, -3, 15], [-5, -11, -9], [-37, -6, -20], [14, 4, 10], [17, 2, -12], [-11, 10, 2], [7, 16, -15], [-16, 5, -8], [22, 4, 7], [-2, -6, -12], [-19, -6, 24], [12, 4, 6], [-29, -1, 1], [13, -4, -4], [-37, -11, -35], [0, 0, 10], [24, -1, 18], [-18, 2, -22], [17, 9, 11], [84, 1, -3], [46, -2, -2], [54, 6, -12], [49, -11, -3], [34, 4, 5], [-28, 4, -18], [19, -14, 2], [-14, -7, 5], [-5, 8, 0], [-9, -11, -16], [-55, 5, -5], [6, 3, 7], [2, -13, 16], [10, 3, -6], [54, 0, 0], [-6, 3, 3], [-20, -6, -2], [28, -10, 1], [21, -17, -9], [-33, 9, -3], [-17, -2, 12], [28, -2, 26], [-10, 10, -5], [-18, -4, -9], [-45, 5, 1], [-12, -3, -24], [-12, 2, -9], [10, 16, 12], [10, -19, -7], [-12, 16, 12], [20, 14, 13], [-50, -7, 0], [-68, -6, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4900_2_a_bd();".
// 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_4900_2_a_bd(:prec:=3)
    chi := MakeCharacter_4900_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_4900_2_a_bd();".
// 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_4900_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![3, -8, -1, 1]>,<11,R![9, -3, -4, 1]>,<13,R![3, 13, -8, 1]>,<19,R![-21, -23, -2, 1]>,<23,R![81, -36, -3, 1]>],Snew);
    return Vf;
end function;