
// Make newform 5720.2.a.m in Magma, downloaded from the LMFDB on 05 November 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5720_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_5720_2_a_m();".
// 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_5720_2_a_m();".
// 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_5720_a();"
function MakeCharacter_5720_a()
    N := 5720;
    order := 1;
    char_gens := [1431, 2861, 4577, 2081, 2641];
    v := [1, 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_5720_a_Hecke( : Kf := Kf)
    return MakeCharacter_5720_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, 1], [1, 0], [-1, 0], [-5, 0], [-3, 0], [-2, 0], [-4, 1], [6, -1], [3, 2], [-7, 1], [1, 3], [-1, 3], [-4, 1], [10, 0], [6, 1], [-5, -3], [-2, 1], [-8, 2], [2, 0], [-6, 0], [-2, -1], [9, 3], [-8, 2], [4, 0], [-12, 0], [2, 4], [0, 0], [1, -1], [8, -3], [3, -3], [-12, 0], [-3, 6], [-15, 1], [-12, -3], [4, -3], [-4, 5], [5, -7], [1, -5], [11, -5], [1, -5], [-20, -1], [-14, -2], [-7, 2], [-6, -5], [4, 2], [6, -4], [12, 2], [-2, 5], [-11, 1], [14, -4], [5, -7], [-8, 6], [8, -1], [9, -1], [8, -8], [19, -3], [-15, -3], [-21, -1], [18, 4], [10, 0], [1, -8], [2, 0], [7, 0], [12, 4], [14, -1], [-9, 7], [-3, -7], [11, -1], [4, -4], [4, 0], [1, 5], [-2, 8], [-35, 1], [13, -3], [-7, 1], [-10, -7], [-17, 5], [29, -1], [2, -2], [11, 5], [-12, -8], [2, -2], [14, -10], [0, 2], [6, -1], [26, -3], [16, 6], [10, -1], [9, 3], [-13, -7], [14, 3], [-6, -6], [1, -9], [-28, -4], [-37, 3], [-12, 0], [23, -2], [-20, 4], [8, -2], [-23, 1], [-14, 10], [-24, -1], [22, 0], [13, 10], [-26, -4], [9, 8], [-14, 12], [31, 0], [4, -6], [6, -6], [4, 4], [4, 11], [1, -2], [4, 5], [6, 0], [-20, 7], [-18, -3], [22, 0], [11, -12], [-11, 7], [9, 2], [38, -4], [-14, -11], [-24, 6], [-32, 5], [4, 6], [20, 0], [47, 1], [-32, 1], [8, 5], [-14, 0], [-26, -4], [38, 0], [3, -6], [-14, -10], [-4, 2], [-32, 6], [23, -8], [-3, 1], [-10, -2], [16, -8], [-21, 1], [20, -4], [-2, 16], [-2, -3], [12, 6], [12, 6], [6, 0], [-11, -11], [14, -15], [28, 4], [-8, 9], [0, -1], [28, -8], [-32, 7], [9, -7], [43, -6], [3, 12], [11, -6], [-22, -3], [-16, 8], [-26, 10], [-35, 1], [3, 13], [18, -6], [-7, 5], [-6, 7], [-31, 4], [62, 0], [-42, 8], [20, 7], [-12, -12], [-5, 8], [-44, 0], [4, 16], [-31, -2], [4, -9], [7, 15], [4, 1], [-4, -13], [12, -9], [-13, -13], [-15, 17], [-57, 1], [12, 8], [-15, -7], [-24, -12], [-26, 2], [6, 6], [-51, 5], [-2, -14], [21, 3], [-8, 22], [41, -5], [12, 2], [32, 6], [-21, -12], [-3, 4], [-50, 4], [-17, 4], [-40, 4], [-22, 2], [10, -1], [-22, 6], [19, -11], [2, -4], [20, 12], [31, 2], [37, -5], [2, 2], [32, 7], [37, -5], [30, 1], [12, -5], [-22, -4], [-64, 0], [19, -8], [10, -12], [7, -9], [-32, 9], [-8, 0], [4, 12], [14, -15], [-36, 6], [25, -2], [39, 1], [-31, 3], [-14, -4], [26, 9], [55, -1], [-22, -12], [8, -12], [-28, -1], [-34, 17], [20, 2], [52, 0], [51, -6], [-61, 4], [-46, 2], [46, -6], [-22, 12], [4, 2], [14, 12], [-7, 3], [48, 2], [20, -3], [8, 15], [10, -20], [11, 5], [16, 10], [3, -16], [-7, 23], [-53, 6], [3, 13], [36, -6], [14, -4], [-14, -1], [-35, 11], [-9, 17], [-2, -7], [29, 9], [-46, -6], [35, -7], [16, 12], [24, -3], [14, -14], [7, -5], [-21, 3], [-33, -4], [-55, 3], [40, -6], [-13, -8], [5, -15], [-4, -20], [17, 9], [38, 0], [14, 1], [17, -20], [-42, -2], [-9, -15], [41, -14], [38, -14], [8, -15], [2, 16], [-14, 0], [0, -5], [40, -2], [-33, 9], [-4, 24], [-18, -19], [-36, 11], [-18, 0], [32, 2], [9, 23], [4, 11], [48, 4], [-36, 14], [38, 11], [54, -6], [-4, 12], [28, -8], [-8, -10], [42, -2], [2, 2], [51, 9], [-8, 17], [-65, 5], [-29, -7], [12, 2], [-22, -2], [-20, -15], [-24, -15], [50, -8], [-10, 8], [7, 1], [27, -21], [-36, -4], [48, -5], [55, -5], [26, -24], [8, -18], [36, -3], [-27, 14], [22, -4], [49, -13], [24, -15], [-39, 3], [6, 7], [-32, -2], [48, 0], [2, 12], [-21, 10], [-56, -11], [50, 0], [-12, -13], [-34, -13], [57, 8], [10, -4], [-22, 4], [25, 4], [15, 12], [-38, 7], [-26, 1], [19, -3], [13, 10], [0, 0], [-20, -9], [-12, 13], [22, -28], [-6, -18], [5, 2], [0, 23], [85, 0], [56, -7], [-5, 20], [-46, 8], [-41, 13], [46, -12], [-8, 16], [20, -24], [-25, 16], [28, 9], [-50, -2], [24, -22], [2, -13], [-26, 2], [-11, 31], [-21, -7], [-38, 22], [-40, -9], [4, 14], [6, 4], [72, -4], [58, -12], [-40, 7], [-14, -2], [2, -9], [28, -20], [1, -19], [54, -18], [-56, 1], [-65, 9], [25, -9], [-10, -14], [74, -3], [-80, 0], [32, -14], [50, -9], [-14, 13], [30, 2], [-6, 14], [40, 8], [65, -3], [25, -7], [-43, 10], [-49, -1], [34, 17], [-39, 20], [26, -28], [-30, 10], [-10, 18], [-37, -13], [-16, 18], [15, -8], [21, 17], [5, 6], [4, -2], [35, 3], [57, -9], [-6, 26], [-24, 4], [45, 5], [-50, 22], [-56, 16], [10, -18], [-17, -9], [64, 1], [82, -2], [28, 12], [7, -23], [10, 15], [-39, 21], [-23, 6], [42, -23], [-31, -17], [50, 10], [-44, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5720_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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