
// Make newform 5200.2.a.by 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_by();".
// 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_by();".
// 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 := [-18, -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], [1, 0], [0, 0], [0, 0], [1, -1], [1, 0], [-1, 1], [1, 1], [-2, -1], [-6, 1], [-2, 2], [0, -2], [5, -1], [-6, 1], [-4, 0], [4, 1], [0, -2], [-2, 3], [-9, 1], [-4, -2], [7, -1], [-2, -1], [3, 1], [-9, -1], [14, 0], [2, -3], [-8, 1], [-7, -2], [-4, -2], [-1, 2], [4, -3], [-14, 1], [1, -1], [-11, -2], [-12, 2], [-14, 0], [0, 2], [11, -3], [-10, 0], [-2, -4], [-11, 2], [4, 2], [-12, 3], [13, 1], [4, 2], [-12, 1], [13, 1], [-2, 0], [-12, 4], [-8, 4], [0, 3], [-12, 0], [-7, -1], [-3, 1], [0, -5], [0, 0], [14, -3], [-4, 0], [-16, -1], [14, 2], [5, 1], [6, 0], [5, -5], [-10, -1], [24, -1], [-6, 4], [17, 1], [3, 4], [21, 0], [10, 2], [6, -6], [-4, 0], [-10, 5], [6, -3], [15, 1], [18, 2], [6, -5], [-18, -2], [-19, 1], [-11, -3], [17, -2], [-32, 0], [-24, 0], [1, 8], [-18, -2], [-7, -3], [-11, 1], [5, -7], [6, -4], [-14, 0], [18, 1], [2, 0], [8, -8], [30, -1], [-4, -4], [-2, 1], [12, 2], [17, 4], [11, 3], [-2, -8], [-13, 7], [-2, 0], [-6, -1], [5, 4], [16, 4], [-5, -3], [7, -3], [15, -5], [-36, -1], [-29, -2], [30, -2], [-2, 2], [42, 0], [-24, -2], [16, 4], [0, 9], [20, 0], [18, 6], [-42, 0], [7, 6], [-10, 0], [2, 4], [-2, 3], [-3, 9], [13, 3], [10, -1], [10, 2], [0, 1], [36, -1], [-14, -2], [0, 0], [-28, -2], [12, -7], [16, 6], [-19, -5], [25, -7], [-18, 6], [-20, 0], [10, -5], [10, 8], [48, -2], [12, 0], [-38, 5], [-9, 5], [16, -5], [-10, -8], [20, 0], [21, -8], [11, -1], [22, 2], [40, 0], [16, -9], [-19, 0], [-20, -4], [18, 5], [-36, 5], [-16, 0], [-30, -6], [-13, -4], [-30, 0], [-12, -6], [-17, -3], [-24, -2], [-5, 7], [-7, 7], [-20, -2], [40, -3], [26, -1], [21, -9], [-22, 9], [7, 5], [14, 8], [-44, -1], [19, -9], [-2, -3], [-9, -4], [35, 1], [6, 6], [-32, 3], [18, 4], [-4, 10], [3, -9], [52, 2], [31, 1], [-30, 8], [14, -1], [44, -3], [13, -3], [17, -9], [-26, 0], [-7, 7], [-5, -5], [-43, 1], [-6, -2], [39, -5], [6, 4], [-49, -1], [14, -1], [-33, 1], [-16, -4], [-14, -10], [4, -12], [-28, 6], [-5, 2], [48, -2], [36, -3], [46, -2], [30, -5], [10, 6], [4, 8], [26, 8], [14, -12], [-24, -4], [-39, 7], [-26, 8], [33, 1], [44, 1], [27, 9], [-22, 12], [-18, -6], [-48, -3], [22, 8], [-35, -1], [2, 8], [37, 4], [-28, 3], [-37, 4], [-16, -8], [-22, 2], [-33, 11], [40, -3], [59, 2], [-20, -2], [37, -1], [20, 0], [-30, -4], [-23, 3], [4, 2], [21, -3], [8, 3], [17, 11], [23, 4], [-14, 1], [50, 2], [-41, 5], [12, 9], [-16, -2], [4, -14], [-9, 1], [-12, 5], [8, -6], [-53, 5], [36, -10], [19, 0], [4, 11], [11, 7], [28, -5], [-17, -13], [38, 3], [33, -3], [2, -13], [-45, 4], [20, -2], [-30, 3], [-15, -3], [-13, 3], [10, -4], [-42, -6], [13, -13], [54, -3], [18, -3], [-25, -5], [-21, 3], [10, -7], [16, -13], [4, -2], [29, 1], [40, -8], [-6, 8], [-51, 0], [6, 15], [24, 6], [16, 8], [-4, -4], [-37, 1], [-38, 7], [32, -3], [8, 2], [-16, -8], [-8, -5], [-70, 0], [4, -8], [-57, -3], [3, -1], [-14, 5], [58, 0], [50, 2], [20, -14], [48, -4], [-5, -1], [-23, 4], [-12, 4], [-20, -3], [-15, 10], [-41, 4], [-43, -7], [36, 8], [-22, 11], [-28, 4], [18, -1], [0, -9], [38, -2], [21, 4], [10, -15], [-36, 8], [40, 7], [-39, -9], [20, -14], [-9, -7], [-57, -4], [10, 9], [1, -15], [-30, 4], [-34, 0], [-18, 12], [-56, 5], [-25, 9], [8, 14], [24, -7], [6, -7], [-26, -4], [-44, -2], [-22, 17], [-19, -5], [9, -7], [-20, 8], [70, 0], [-10, 4], [11, 3], [32, 8], [2, 18], [27, 1], [-26, 2], [38, 5], [16, -16], [-30, -7], [-30, -7], [-5, -5], [6, 14], [-34, -5], [11, -7], [-30, 10], [-54, 2], [-8, 8], [-26, 5], [-45, -6], [-10, 4], [73, -3], [-36, -1], [-18, -10], [-34, 8], [5, -5], [-16, -17], [12, 12], [-17, 2], [-33, 6], [-2, 10], [22, 14], [-7, 22], [-18, 9], [-47, -8], [18, 0], [2, 7], [42, -2], [4, 18], [-15, -7], [6, 6], [27, 1], [-33, -7], [0, 1], [-20, -4], [9, -3], [38, -6], [15, 1], [8, 2], [-70, 2], [26, 0], [-28, -13], [-8, -2], [0, 11], [35, -13], [-18, -6], [-33, 1], [-61, 4], [8, -12], [5, -6], [16, -10], [-61, -3], [-11, 0], [-58, 2], [-28, -6], [9, 10], [-66, 2], [-27, -3], [-38, 2], [4, 19], [-96, 0], [-50, -4], [-16, -4], [3, 15], [33, 7], [-18, -13], [3, 14], [-20, -16], [89, 3], [10, 16], [-22, -2], [0, -9], [21, -17], [8, -1], [-24, 6], [-54, 2], [-44, -10], [-21, -2], [-59, 7], [20, -8], [-20, 8], [11, -5], [-59, 5], [30, -5]];
    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_by();".
// 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_by(: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_by();".
// 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_by( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<7,R![0, 1]>,<11,R![-18, -1, 1]>],Snew);
    return Vf;
end function;