
// Make newform 4900.2.a.j in Magma, downloaded from the LMFDB on 13 March 2026.
// 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_j();".
// 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_j();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [-5], [-6], [4], [6], [-3], [-3], [-2], [-7], [4], [7], [-2], [10], [14], [-4], [-3], [-13], [16], [1], [10], [-10], [-2], [-12], [2], [12], [9], [11], [13], [4], [18], [-4], [-9], [-13], [8], [-16], [-6], [22], [12], [-4], [0], [11], [-1], [4], [4], [-28], [10], [14], [-27], [-20], [-22], [24], [-2], [11], [30], [-30], [-6], [-19], [22], [2], [-16], [24], [-14], [19], [-11], [-2], [-29], [26], [18], [-25], [32], [23], [-3], [-6], [-19], [38], [13], [30], [18], [-25], [0], [28], [2], [16], [27], [31], [26], [8], [-14], [-30], [23], [15], [12], [-18], [2], [-14], [8], [-21], [-27], [31], [-26], [-3], [-15], [-34], [28], [24], [9], [0], [-10], [9], [17], [-14], [29], [-7], [-4], [14], [14], [4], [26], [-38], [-6], [-37], [-28], [22], [-26], [48], [-48], [20], [7], [-36], [20], [-11], [0], [32], [6], [-28], [48], [39], [-14], [-6], [1], [47], [-32], [16], [16], [-12], [-6], [43], [-10], [-2], [-27], [-44], [-28], [57], [41], [20], [4], [22], [-4], [15], [-56], [-30], [9], [-50], [-11], [-2], [-5], [-40], [-19], [-26], [-27], [-30], [4], [-28], [-47], [-6], [-14], [-22], [23], [-48], [5], [34], [-3], [-18], [55], [-14], [25], [12], [42], [1], [-29], [34], [-33], [-60], [-11], [1], [42], [-2], [34], [34], [42], [0], [0], [28], [34], [60], [-9], [64], [21], [24], [-41], [-32], [-60], [-8], [19], [-18], [-11], [-39], [53], [4], [27], [-51], [46], [38], [8], [53], [-40], [-13], [-23], [-54], [52], [51], [38], [6], [44], [-25], [-37], [56], [-11], [10], [18], [55], [42], [-12], [-38], [42], [20], [56], [-2], [-60], [0], [24], [30], [76], [5], [32], [18], [-42], [0], [7], [26], [34], [48], [-32], [-9], [-20], [31], [-63], [-12], [12], [-8], [-39], [16], [64], [71], [26], [-45], [32], [-76], [-64], [30], [-24], [-8], [39], [43], [27], [28], [-30], [-9], [70], [49], [16], [51], [24], [8], [14], [60], [-50], [-12], [14], [37], [39], [-7], [-30], [-7], [54], [-75], [-46], [24], [42], [73], [68], [-51], [52], [-78], [12], [-48], [-19], [-76], [-38], [82], [-75], [51], [-38], [65], [-66], [-59], [45], [-82], [-27], [-70], [-12], [68], [42], [-35], [42], [86], [40], [34], [73], [-24], [-91], [-3], [55], [-24], [31], [78], [-48], [-80], [-21], [-78], [58], [15], [-6], [-30], [-40], [-42], [-12], [35], [-50], [8], [31], [38], [-86], [-34], [43], [19], [15], [-22], [1], [66], [-62], [7], [16], [51], [16], [18], [-12], [80], [67], [9], [27], [84], [84], [-45], [58], [35], [68], [-55], [26], [-29], [18], [19], [-59], [-76], [26], [-48], [-87], [-42], [-45], [-11], [-54], [50], [-94], [83], [6], [36], [66], [-50], [81], [12], [-11], [-43], [2], [-48], [-12], [-36], [34], [34], [-44], [48], [40], [-18], [20], [35], [66], [-16], [-38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4900_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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