
// Make newform 5200.2.a.bn in Magma, downloaded from the LMFDB on 04 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_bn();".
// 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_bn();".
// 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_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], [-1, 1], [0, 0], [0, 2], [-1, -1], [-1, 0], [-4, -2], [1, 1], [1, -1], [6, 2], [-5, 3], [0, 0], [4, -2], [-9, 1], [8, -2], [4, -2], [3, -5], [-2, -6], [-6, -4], [-11, 1], [-4, 4], [10, -2], [0, -6], [-6, -4], [-2, -8], [-2, 4], [-1, -3], [-1, -11], [2, 8], [8, 6], [-7, 3], [-4, 4], [-2, -4], [10, 2], [6, -8], [-17, 3], [-6, 8], [-2, -4], [-4, -10], [-8, 6], [8, 8], [10, -2], [-12, -4], [2, 0], [-2, -4], [0, 4], [4, -4], [8, 10], [18, 0], [16, 2], [-18, 0], [-27, 1], [-4, 14], [-6, -10], [-6, 0], [-3, -5], [-14, 8], [11, 7], [4, 10], [-8, 2], [-5, -11], [0, -4], [-20, 2], [-14, -10], [0, -6], [-12, 8], [-7, 9], [-12, -6], [-3, 3], [16, -2], [0, 4], [1, -7], [-17, 9], [-6, 8], [15, 3], [-12, 6], [-18, 0], [12, -4], [10, -12], [16, 10], [22, 2], [-26, 4], [3, 11], [-22, 4], [0, 8], [-1, 17], [-4, -6], [10, 12], [12, -14], [14, 8], [3, 9], [1, -7], [-26, -8], [30, 2], [-19, -3], [-29, -7], [0, -2], [-2, 6], [-5, 13], [28, 6], [-17, 5], [-8, -8], [39, 1], [-14, -2], [10, 10], [-4, 20], [22, -12], [-6, -20], [30, 2], [10, -8], [9, -13], [14, -8], [18, 16], [27, -5], [13, -3], [6, -4], [-20, 6], [9, -5], [6, 16], [-22, -10], [14, 4], [-32, 2], [-20, 6], [18, 4], [-11, -19], [2, 16], [16, -6], [0, 20], [-9, -15], [2, 8], [-3, 1], [8, 10], [-42, -2], [20, 2], [-14, 0], [22, -4], [-12, 4], [8, 6], [-26, -12], [26, -10], [-3, -19], [-6, -4], [11, 9], [0, 2], [34, 6], [-5, -17], [-20, 16], [18, -8], [2, 6], [-44, 6], [14, 16], [2, 2], [7, 9], [-17, 17], [3, -23], [0, 12], [-22, -10], [12, 18], [34, -4], [12, 6], [12, 6], [22, -12], [-18, 0], [-16, -16], [-4, 4], [-2, -8], [40, 8], [-8, 10], [6, -28], [32, 2], [-1, -13], [-4, 30], [2, -22], [32, -4], [-20, 12], [-30, -16], [-43, 1], [-12, -14], [-19, -13], [6, -16], [16, 14], [-18, -10], [-52, 2], [-2, 12], [-30, 16], [-14, 2], [46, -4], [8, -22], [20, -10], [-13, -17], [16, -18], [-44, 6], [-16, 0], [42, 12], [21, -13], [-30, -12], [-16, 10], [-2, -20], [36, 0], [-13, 1], [8, 22], [-20, 24], [-2, -8], [34, 6], [-27, 9], [-12, -6], [-47, -3], [-9, -23], [-46, 0], [-14, 22], [10, -28], [22, 18], [3, -15], [12, 2], [-13, -13], [24, 14], [-17, 25], [6, 16], [14, 20], [-6, 8], [30, 10], [-5, -1], [26, 12], [-8, -26], [-5, 17], [2, 30], [74, 0], [46, 14], [7, -15], [21, 9], [2, -4], [-34, 2], [1, 21], [2, -4], [7, 25], [-6, -4], [-8, 10], [-20, 0], [-36, 4], [52, -4], [32, -18], [14, -26], [11, 17], [-40, -6], [-62, -8], [12, 28], [28, 18], [11, -5], [-9, -5], [-21, 25], [28, 28], [74, 0], [-36, -10], [34, 0], [-2, 16], [-5, 35], [-26, -18], [-46, -12], [-34, 16], [72, 0], [-11, 3], [-27, 11], [32, 22], [60, 6], [-36, 24], [-34, 14], [20, -26], [6, -4], [-22, 0], [-60, 6], [-42, 4], [-26, 4], [18, -24], [-8, -28], [-64, -6], [-16, 26], [2, -16], [-32, 26], [12, 10], [-6, 2], [3, -7], [-15, -7], [1, 11], [20, -26], [-8, 6], [38, -18], [-26, 32], [2, -20], [-43, -3], [-22, -2], [-2, 42], [-17, 13], [-30, 12], [3, 27], [-10, -16], [-34, -8], [-4, -48], [2, 8], [-30, -14], [-64, 2], [-22, -12], [18, 12], [-20, 24], [39, 1], [4, -8], [16, 0], [51, 1], [-34, 4], [-41, 27], [-6, -4], [-27, 11], [40, 18], [-42, -18], [65, 3], [24, -6], [34, -2], [-51, 13], [1, 5], [48, 16], [6, -40], [-26, -22], [20, -4], [54, -22], [34, -12], [36, -4], [-74, -6], [59, 3], [-20, -34], [33, 11], [42, -4], [-38, -16], [34, -12], [-34, -14], [2, 40], [27, 31], [-2, 0], [-2, 8], [38, 16], [-28, -10], [-11, 31], [-2, 12], [24, 22], [14, 24], [-46, -2], [-50, -12], [-72, 0], [42, 8], [-28, 6], [-21, -9], [-10, -16], [-43, 21], [18, -16], [-42, 24], [-25, -19], [-50, -16], [-72, -2], [-5, -1], [-7, -23], [18, -24], [0, 14], [-8, -36], [22, -6], [-37, 5], [-9, -37], [-67, 3], [48, -22], [-38, 4], [38, -16], [-34, -20], [0, 24], [40, -12], [66, 16], [10, -14], [-72, 12], [-40, 22], [-3, 29], [-78, -2], [-30, 28], [6, -34], [-48, 22], [20, -22], [-72, 8], [-32, -30], [-24, 0], [5, 33], [14, 16], [11, -29], [-56, 14], [-16, -6], [-27, -33], [20, 18], [0, 0], [63, -17], [43, -7], [-65, 19], [-38, 0], [49, -11], [10, 10], [-8, -12], [-2, -16], [-34, -32], [0, 10], [48, 14], [-12, -32], [26, -24], [28, -20], [24, -20], [14, -16], [10, 8], [-9, -17], [-30, -36], [-12, 14], [-15, 3], [-2, 18], [34, -16], [-10, -16], [-11, -15], [-51, 15], [24, -36], [83, 9], [-30, 38], [-78, -8], [-86, -12], [-30, 6], [2, 20], [-4, -8], [-5, -11], [16, 42], [97, -3], [66, 14]];
    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_bn();".
// 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_bn(: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_bn();".
// 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_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 2, 1]>,<7,R![-12, 0, 1]>,<11,R![-2, 2, 1]>],Snew);
    return Vf;
end function;