
// Make newform 5200.2.a.bx in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5200_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_5200_2_a_bx();".
// 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_5200_2_a_bx();".
// 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 := [-8, -1, 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_5200_a();"
function MakeCharacter_5200_a()
    N := 5200;
    order := 1;
    char_gens := [1951, 1301, 4577, 1601];
    v := [1, 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_5200_a_Hecke( : Kf := Kf)
    return MakeCharacter_5200_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, 1], [0, 0], [-1, 1], [1, 1], [1, 0], [-1, -1], [4, 0], [-2, 1], [-1, 2], [-1, 1], [-10, 0], [4, -2], [-6, -1], [-7, -1], [-7, 2], [-1, -1], [-3, -2], [1, -3], [-8, -2], [-2, 2], [-10, 1], [-11, 1], [12, 0], [6, 4], [3, -6], [0, -1], [10, 1], [-8, 2], [-6, 3], [10, -3], [12, -3], [4, -2], [14, 1], [10, 4], [-5, 3], [3, -5], [4, -6], [4, -2], [-9, 3], [0, 3], [5, -3], [-18, 3], [4, -4], [16, -2], [-2, -3], [10, -6], [-8, 6], [-5, 1], [2, 6], [-6, 3], [-5, 1], [-16, 6], [12, 0], [1, 4], [20, -4], [-5, -2], [3, 5], [2, -9], [2, 2], [-10, -2], [18, 0], [20, -2], [18, -3], [-7, 0], [-2, 4], [8, 4], [-25, 0], [-14, -5], [-2, -10], [0, 0], [1, -5], [4, -3], [7, 2], [13, -3], [24, 0], [34, 1], [18, -2], [18, -6], [20, 0], [-28, -1], [12, 4], [-8, -8], [10, -1], [6, 2], [14, -10], [36, 0], [8, 0], [-10, 8], [17, 1], [12, -3], [-5, 7], [7, -3], [-22, 5], [-17, 9], [4, 1], [4, -2], [2, 11], [-2, -6], [6, -8], [8, 4], [24, -6], [-2, 13], [9, 0], [10, -6], [-10, 0], [-25, -1], [2, 2], [-12, 9], [5, 0], [10, 6], [22, 2], [-2, -8], [20, -2], [-20, 0], [35, -4], [-20, 12], [-8, 4], [-25, -1], [6, 3], [0, -2], [-17, -1], [-18, -3], [13, 7], [-5, -9], [33, -6], [-8, 8], [-40, -1], [-12, -7], [8, 0], [-17, 9], [-15, -3], [-2, -3], [17, 9], [14, -16], [20, -12], [22, -2], [3, 5], [-7, -10], [-6, 0], [-9, -13], [-14, 10], [-20, 9], [-7, -7], [19, 2], [-16, 14], [8, -12], [14, -1], [-18, 14], [17, -1], [-4, 12], [-7, 8], [0, 5], [2, -10], [-20, 9], [-2, 1], [-26, -6], [-18, 6], [-25, 0], [-18, 12], [-11, 13], [21, -3], [19, -9], [6, 6], [4, -14], [35, -1], [-50, -3], [-19, 6], [-20, 14], [-21, 6], [20, 2], [-4, 6], [8, 5], [-6, -2], [-14, -9], [19, -8], [23, -5], [34, -2], [22, -9], [3, -5], [-8, 6], [-10, -10], [-26, -4], [16, -2], [9, -3], [38, -7], [5, -6], [-5, 9], [-30, 4], [-9, 15], [-38, 8], [5, -13], [-10, 22], [18, 6], [-6, -6], [45, -3], [-30, 10], [-3, 10], [22, -8], [14, -10], [30, 6], [36, -4], [18, -20], [-11, -4], [45, -3], [-18, 9], [-27, -1], [-12, -9], [12, 0], [-20, 0], [29, -3], [-6, 0], [-20, 0], [39, -9], [5, -19], [-4, 12], [-22, 1], [11, -1], [11, -1], [20, 8], [22, -19], [-16, -2], [8, 14], [-35, 9], [-46, -1], [-1, -6], [38, -7], [-22, 14], [-32, 0], [19, 1], [30, 13], [4, -3], [55, 3], [14, 8], [6, -10], [32, 2], [-18, -8], [-10, 20], [36, -12], [32, 5], [4, -14], [-50, -3], [-8, -15], [-22, -6], [-2, -20], [8, -13], [-16, -2], [-32, -2], [-39, -7], [20, -13], [44, -6], [14, -4], [32, -10], [-1, -12], [34, 7], [7, 1], [26, -9], [49, -9], [-43, 14], [-58, 6], [-14, -3], [62, -7], [4, 14], [10, 5], [-60, 0], [22, -6], [16, -14], [42, 6], [-11, -15], [35, 14], [34, 11], [11, -11], [2, 6], [40, 9], [-11, -16], [-17, 3], [-36, -12], [26, 6], [24, -2], [46, 7], [-18, -15], [-32, 6], [-28, -4], [-52, 0], [1, -15], [22, 13], [59, 0], [-40, 2], [17, -5], [-19, -16], [37, -11], [-28, 8], [2, -4], [25, 7], [-5, 2], [-19, 5], [-32, 0], [42, 0], [-50, -2], [-19, 7], [9, 4], [4, 4], [-20, 3], [32, -1], [-12, -1], [18, 10], [-8, 4], [38, 9], [16, 16], [5, 6], [-26, -5], [-12, 24], [-43, -4], [30, 11], [47, 5], [46, -13], [1, -23], [-44, 10], [-12, -2], [-25, 20], [12, 5], [32, -12], [-14, -20], [-49, -5], [10, -8], [-5, 8], [-27, -7], [67, 3], [-20, 19], [31, -2], [2, -12], [-46, -4], [16, 9], [19, -5], [-63, -1], [1, -17], [-6, 16], [44, 2], [32, -12], [10, -18], [-64, 0], [-26, -20], [-44, -8], [30, 11], [-10, 26], [12, -3], [3, 22], [-35, 3], [35, 5], [5, -10], [-27, 29], [-40, -12], [56, -4], [14, 10], [50, -9], [-47, 16], [-7, -19], [-11, 7], [-51, 0], [-33, 21], [20, 18], [30, 12], [8, 17], [44, 8], [-58, 7], [-38, 23], [-24, 0], [-25, -11], [-13, 24], [56, 5], [-48, 17], [8, 14], [33, 18], [46, -18], [-7, 9], [23, -7], [42, -18], [-4, -6], [-9, -9], [22, 17], [40, -20], [-16, 20], [-11, -9], [52, 10], [36, -10], [0, 12], [19, 3], [7, 26], [-12, 14], [18, 3], [32, -24], [44, 8], [15, -9], [-50, 9], [-7, -25], [-21, 16], [19, -9], [-61, 11], [46, -9], [24, -24], [38, 12], [59, -4], [81, -1], [70, -2], [-70, 2], [-2, -21], [22, -10], [12, -18], [-71, 3], [20, -4], [-87, 1], [-23, -14], [20, -7], [-2, 6], [-78, 4], [-55, -7], [68, -4], [-52, 13], [-16, 14], [30, -21], [39, 3], [-54, -2], [-69, 3], [12, 9], [74, -12], [14, -10], [-56, 4], [-36, 0], [-55, -5], [24, 3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5200_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5200_2_a_bx();".
// 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_5200_2_a_bx(:prec:=2)
    chi := MakeCharacter_5200_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_5200_2_a_bx();".
// 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_5200_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-8, -1, 1]>,<7,R![-8, 1, 1]>,<11,R![-6, -3, 1]>],Snew);
    return Vf;
end function;