
// Make newform 5200.2.a.cb 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_cb();".
// 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_cb();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -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_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, -1, 0], [0, 0, 0], [-1, 1, 1], [2, 0, 1], [-1, 0, 0], [2, 0, -2], [0, 0, 1], [-5, 1, 0], [3, -3, -3], [4, -2, -1], [1, -3, -1], [-2, 2, -2], [-1, -3, 2], [-3, -1, -1], [2, 2, 4], [2, 2, -3], [1, 3, 1], [-3, -1, -5], [2, 6, -1], [-9, 3, 1], [6, -2, -4], [-7, -1, 1], [2, 4, 4], [-6, 4, 6], [2, -8, -2], [-5, 7, 0], [-13, 1, 2], [-6, -6, 4], [-2, -4, -2], [5, 5, 4], [2, -6, -6], [4, 6, -6], [-2, 2, 8], [-8, 0, -2], [-6, 2, -3], [2, 4, 4], [-5, -3, -1], [7, -7, -1], [-10, 6, -4], [-8, -4, -6], [3, 5, 1], [-8, 4, -4], [-8, -2, -10], [2, 0, 0], [0, 0, 10], [0, 8, 10], [-5, 1, -11], [-5, 9, 5], [2, 0, 2], [-6, 10, 6], [8, -6, -3], [-16, 4, -4], [2, -14, -2], [-2, -10, 6], [-7, 1, -8], [6, 0, 10], [0, 8, 7], [-12, 0, -2], [8, -4, 0], [3, 9, -6], [3, -5, -3], [3, -3, 7], [0, -8, 8], [-12, -10, 0], [-21, 3, 1], [6, 4, 7], [8, -10, -4], [-13, 3, -6], [-6, -8, -14], [13, -3, -1], [8, -8, -3], [7, -9, 4], [-2, 8, 16], [12, -18, -5], [-1, -7, 7], [-6, -4, -4], [1, -3, 3], [-8, -2, 6], [-14, -2, -2], [-6, 10, 2], [-6, -6, 0], [12, -6, -13], [0, 8, -8], [-14, 10, 0], [-27, 9, 2], [-2, 14, 6], [2, 16, -2], [-28, 6, 0], [11, -11, 7], [-9, 7, -8], [0, 8, -3], [-1, 1, 7], [-8, -16, 6], [0, -4, 13], [-5, 5, 6], [0, -10, 4], [19, -7, 5], [-9, 19, 8], [16, 2, 0], [-17, 1, 6], [5, -7, -1], [7, 1, 2], [-17, 5, -5], [-18, 6, -8], [19, -1, 5], [-29, 21, 11], [14, -8, -2], [-16, -8, 0], [22, -4, 0], [13, 3, -10], [16, 2, 12], [-16, 2, -6], [-22, -10, -3], [6, -16, -17], [-2, 0, -12], [13, 11, -5], [-3, -3, -8], [6, 16, 4], [-6, 10, 14], [0, 8, 18], [12, -10, -12], [-16, -12, -2], [-15, -1, -1], [20, 2, 1], [6, 8, 18], [0, 2, -4], [-2, 2, -14], [29, -13, -8], [-2, 8, 12], [12, -26, -11], [27, 1, 3], [-10, 10, -2], [34, -10, -8], [-24, -10, -6], [4, -10, 18], [13, -19, 3], [-1, 1, 15], [-4, -6, 2], [25, -5, 7], [-8, 2, -7], [-24, 20, 2], [-7, 1, 2], [-27, -9, -3], [-3, 15, 13], [2, -24, 9], [15, 11, -3], [0, -4, -4], [-20, 0, 10], [-13, -3, 17], [-12, -14, 8], [5, 3, 1], [17, -5, -12], [9, 1, -14], [11, -5, 20], [4, 12, 14], [-12, -8, -8], [-28, -8, 4], [-6, 10, 22], [18, 20, -6], [-23, -13, 5], [16, -16, -8], [3, -23, -15], [0, 0, -18], [23, 3, 5], [15, -23, -17], [14, -14, 8], [36, 4, 2], [20, -26, -2], [22, 10, -12], [-6, -12, 17], [2, 8, -10], [0, -4, 18], [21, 13, -1], [-14, 6, -16], [-30, 4, 12], [6, -26, -17], [34, -8, -10], [29, 7, 22], [26, -8, -4], [37, 11, -5], [-8, 16, 4], [-2, -26, 8], [-4, -10, -18], [-7, 3, -21], [1, -1, -5], [4, 18, 22], [-15, -9, -5], [28, 0, -12], [10, -10, -15], [40, -10, -4], [-11, -17, -11], [20, 16, 2], [6, -10, -12], [-15, -17, -18], [-24, 20, 20], [-16, 16, 12], [-12, -2, 14], [-39, 1, 11], [21, 7, 0], [18, -8, 2], [-38, -14, 2], [-16, 18, -4], [-11, -13, 7], [24, -18, 1], [-10, -2, -24], [-8, 34, -7], [9, 9, 22], [-2, -12, -12], [0, 32, -6], [8, 0, -20], [17, -1, -11], [1, 15, 24], [-17, 9, -3], [-26, 14, 9], [26, -34, -10], [19, 7, -8], [-34, -12, 10], [-7, -1, -3], [2, -12, 4], [9, -9, 17], [18, 8, 37], [-8, 18, 6], [-15, -17, -3], [-9, -17, 0], [-23, 23, 25], [-8, -8, -4], [-18, 34, 10], [7, 9, -22], [-8, 12, 25], [-10, -20, -32], [16, -4, -18], [4, 0, 1], [-34, 20, 10], [23, -29, 0], [3, -11, 19], [-6, 2, 10], [31, -29, -7], [-20, 16, 22], [-34, -6, -12], [-45, 13, 15], [0, -12, 20], [35, -11, -6], [28, -10, -12], [0, -10, -14], [-22, -10, -24], [9, -17, -17], [60, -6, -1], [-54, 12, -3], [7, -17, 16], [5, -15, -21], [16, -22, -2], [-29, 9, 9], [-30, -8, 16], [-34, -8, -20], [-12, 24, -13], [25, -21, -1], [37, -5, 9], [-8, 18, -6], [31, -13, -23], [-7, 3, 6], [-21, 11, 6], [-24, 18, 4], [24, -4, 2], [17, 13, 11], [16, 12, 8], [-58, 8, 6], [-2, 20, 0], [-29, 21, 17], [34, -6, -4], [-22, -12, -26], [-53, -3, -13], [-8, 2, 30], [8, 4, 18], [42, -8, 18], [23, -7, 7], [-45, 5, -11], [14, 16, 2], [-10, -26, -18], [-30, -6, 0], [29, -17, 0], [-46, 0, 11], [-17, -7, 28], [10, 24, -2], [19, 1, 19], [-2, 6, 18], [34, -6, 2], [-8, 22, 20], [26, -26, -21], [43, -3, -13], [21, 7, -15], [15, 17, -2], [-14, 0, -6], [0, -10, 23], [-34, 0, 8], [18, 12, -8], [8, 4, -18], [0, -6, -18], [8, 8, 24], [-23, 35, 9], [2, 14, 26], [-4, 22, 20], [-36, 28, 26], [-5, -1, 16], [42, -2, 12], [7, 7, -19], [-11, -27, -2], [-6, 4, 6], [30, 16, 21], [28, -2, 14], [-25, 23, -18], [34, -4, -22], [11, 25, -11], [19, 1, -4], [-13, -7, 7], [9, 31, 11], [-34, -14, -5], [4, 24, 41], [-17, 3, -19], [-34, 8, -6], [-14, 10, -30], [-17, -21, -3], [-27, -17, 9], [-9, 13, -9], [-17, 7, -15], [-1, -7, 3], [50, 2, -15], [-15, 3, 9], [-29, 27, -6], [-38, 4, -12], [38, 18, 0], [12, -34, -26], [12, -12, 4], [19, 9, 1], [26, -14, 9], [-15, 39, 19], [-30, 30, 12], [-10, -8, 10], [2, 6, 30], [-57, 3, 6], [34, 20, -4], [6, -24, 18], [-8, -28, 10], [-46, 2, -24], [14, 4, -8], [-38, 10, 18], [-10, -12, -34], [1, 11, 27], [16, 20, -21], [4, -26, 2], [-6, 24, 3], [-24, 18, 34], [22, -42, -8], [-27, -3, 14], [-18, 32, 8], [-60, 38, 16], [-8, 10, 11], [-32, 30, 5], [-74, -2, 10], [17, -41, -33], [-37, 35, 5], [5, 23, 3], [-13, 31, 32], [-12, -10, -5], [29, -21, -6], [-50, 40, 14], [-20, -22, 12], [-49, 17, 9], [-6, 20, -4], [24, 0, -2], [-8, 28, 4], [17, 7, -1], [11, -3, 27], [50, -6, 10], [4, 32, -22], [32, 24, 9], [-74, 18, 8], [50, 0, 18], [-19, 15, -31], [-14, 16, -18], [-14, 28, 22], [11, 7, -7], [-5, 25, 11], [-49, -5, 1], [-2, 36, 15], [27, 17, 27], [-4, 34, 23], [56, 0, 2], [57, -1, 1], [7, -47, 4], [34, 2, -18], [-23, 17, 11], [2, 14, -39], [9, -33, -4], [8, -4, -29], [-12, 4, 4], [30, 20, -1], [-33, 29, 21], [-2, 6, -8], [-6, 26, 8], [-50, 14, -8], [-36, -2, 20], [-51, 15, -5], [1, -27, -1], [46, 14, -8], [-6, 18, 32], [-9, -41, 21], [-2, -20, -32], [3, -35, -25], [86, -26, -11], [38, 6, 26], [-12, 16, 14], [11, -23, -12], [42, -10, 14], [-56, -4, -16], [18, 16, 44], [-32, 30, 1], [11, -15, -32], [-15, -11, -37], [25, 25, 26], [-51, 19, 5], [38, -40, 4], [35, 1, -17], [-32, -16, 2], [-18, -16, -34], [-25, 35, 37], [-21, 1, 38], [4, -20, -20], [-56, 24, 1], [-16, 8, -36]];
    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_cb();".
// 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_cb(:prec:=3)
    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_cb();".
// 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_cb( : 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, 4, 1]>,<7,R![-4, -4, 2, 1]>,<11,R![2, 8, -6, 1]>],Snew);
    return Vf;
end function;