
// Make newform 5586.2.a.bt in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5586_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_5586_2_a_bt();".
// 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_5586_2_a_bt();".
// 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, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -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_5586_a();"
function MakeCharacter_5586_a()
    N := 5586;
    order := 1;
    char_gens := [3725, 4903, 4999];
    v := [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_5586_a_Hecke(Kf)
    return MakeCharacter_5586_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+1)]];
    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 := [[-1, 0, 0], [1, 0, 0], [0, 0, -1], [0, 0, 0], [3, -1, -1], [0, -2, 0], [3, 0, 1], [1, 0, 0], [3, -1, 2], [-3, 3, -1], [3, 4, -2], [1, -4, 1], [1, -1, 0], [-1, -2, -1], [0, -2, 2], [1, -2, 0], [0, -5, 2], [8, 0, -2], [-6, 0, -2], [-3, 0, -1], [-2, -5, 1], [-1, 5, -5], [-7, 0, 2], [3, 5, 0], [-6, 5, 0], [8, 4, -2], [2, 1, 5], [10, -4, 1], [-5, 2, 5], [5, 7, -6], [-3, -6, 6], [1, 2, 4], [4, 0, 0], [7, 6, -3], [12, 0, 2], [-17, 2, 2], [-6, -2, 6], [2, 6, -4], [5, 4, -5], [10, -3, -5], [-4, 4, 4], [4, -10, 0], [14, 0, 2], [-8, 2, 3], [-4, -1, 5], [0, 4, -4], [-13, 5, -4], [5, -7, 5], [-8, 4, -3], [2, 0, -4], [12, 0, 6], [20, -6, -2], [14, -5, 2], [7, -5, 1], [2, 4, 0], [13, -1, 6], [-3, 5, 3], [20, 4, -3], [9, -5, 0], [-14, 2, 2], [5, 0, 3], [11, -1, 7], [9, -1, 10], [7, -3, 10], [9, 9, -3], [11, -8, 0], [-15, -7, 4], [-10, 5, 4], [-4, 1, -5], [-3, 5, -6], [3, -10, -1], [-18, 0, 0], [-4, -10, 1], [-6, 2, 8], [-4, -10, 10], [-4, 2, 2], [-12, 6, 8], [-18, 10, 2], [-6, -12, 4], [6, -7, 16], [14, -9, -5], [4, 2, -8], [11, 8, -11], [-4, -5, -7], [9, -11, 3], [-9, 5, -15], [-11, 7, -2], [7, -9, -3], [-6, 0, -8], [-12, 10, -2], [2, -5, 11], [18, -6, -4], [-7, -4, 0], [-7, 0, -8], [-2, 2, -6], [9, 3, -12], [7, 3, -1], [14, 0, 6], [13, 13, -6], [19, 3, 0], [-1, -1, -10], [10, 13, -8], [-2, 7, -12], [-16, 8, -2], [1, -2, -1], [-7, 8, -4], [3, 15, -9], [6, -10, -4], [11, 12, -11], [-6, 7, 14], [25, -11, 1], [-7, 13, 0], [-7, -14, 11], [8, 8, -10], [2, 12, -5], [9, -5, 8], [15, 0, -1], [11, -5, -2], [-4, -11, 10], [-24, -13, 7], [11, 12, 1], [-26, -4, 3], [-1, -2, 2], [4, -12, 7], [27, -4, 1], [-4, -11, 0], [7, 1, -2], [20, -4, -10], [-18, 4, 3], [37, -1, -2], [-9, 2, -9], [-24, 4, 8], [-7, -7, 7], [7, 3, -16], [4, -4, 10], [-17, -9, 1], [20, -9, 11], [2, -16, 8], [-3, 9, 9], [19, 2, -7], [5, -1, -4], [8, 13, 4], [-22, 12, 10], [2, 5, 12], [-20, 0, 8], [-1, 4, -13], [-19, -13, 2], [2, 10, -16], [-6, 20, -6], [-23, 0, 1], [-5, 16, -17], [-36, -2, 2], [-11, 10, 3], [-9, 14, -3], [19, -9, 6], [0, 2, 0], [20, -9, 15], [-31, 0, -3], [-11, 14, -18], [1, 8, -14], [0, 11, -7], [-16, -6, -6], [-12, 15, 6], [4, -1, -20], [-6, 2, 14], [16, 10, -10], [-21, -22, 14], [-28, -6, 10], [-18, -4, -3], [8, -9, -10], [-12, 9, -8], [-27, 14, -3], [28, -4, 2], [-3, 5, 3], [17, 3, -1], [-24, 0, 10], [0, 14, -2], [20, -15, 10], [-4, 1, -21], [-3, 7, 10], [24, -3, 0], [16, -2, 19], [8, -2, 2], [-29, 17, -4], [0, 20, 0], [0, 4, 15], [-10, -6, 10], [-37, -9, 2], [-40, 1, 4], [-10, 14, 14], [-16, -18, 9], [-31, -17, 11], [6, 8, 14], [-28, -5, -5], [-5, 10, 8], [11, 1, -2], [6, -1, -11], [-18, -4, 2], [14, 4, -14], [-37, 7, 8], [3, -11, -7], [-6, -5, 11], [-29, 14, -3], [32, 0, -2], [-30, -7, 5], [-40, 6, -1], [-10, 24, -6], [32, 11, -10], [-51, 6, 1], [-21, -13, 6], [-16, -1, -5], [-6, 13, -2], [10, 7, 12], [14, -11, -4], [-4, 10, 16], [8, -5, 1], [-16, 14, -5], [-14, 22, -6], [22, -14, -4], [16, 2, -12], [23, 2, -9], [-6, -13, 3], [-18, 8, -4], [-24, 9, 16], [36, 7, 4], [13, 3, -8], [-45, -3, -4], [21, -20, 5], [-1, -29, 19], [38, 3, -5], [-12, 14, -22], [20, 10, 8], [-9, -4, 16], [43, 3, -2], [-24, 2, 0], [22, -26, 4], [-35, 10, 14], [30, 12, 3], [-2, -1, 3], [37, -4, 1], [-4, 18, 10], [42, -20, 0], [-4, -20, 19], [6, 4, 10], [-9, 7, -28], [-5, 11, 10], [22, 2, -11], [-16, -4, -12], [-27, -7, 6], [34, -6, 0], [9, -19, 14], [22, 2, 18], [-45, 7, 2], [-18, 26, -2], [8, -17, 0], [27, -12, 2], [-3, -9, 14], [-7, 9, -22], [-21, -12, -6], [9, -15, 17], [-36, -12, 8], [26, -17, -14], [31, -7, 0], [-7, 24, -15], [-25, -20, 5], [7, -9, 8], [1, 1, 11], [-23, -10, -1], [39, 1, 12], [44, 3, 0], [-20, 22, -10], [12, -10, -6], [-7, -11, 5], [-30, 8, 7], [4, 14, -3], [-2, 24, -14], [3, 24, 0], [-35, 22, 5], [-4, -9, -7], [-4, 5, -5], [10, 20, -6], [38, -5, 8], [-37, 13, -6], [-13, -8, -3], [-26, -28, 14], [4, 8, 0], [29, 12, -6], [-15, -8, 8], [-34, 15, -4], [1, 19, 2], [-26, -4, -12], [11, 13, -7], [-3, -15, -6], [28, 9, -7], [0, 16, -2], [-48, -9, 6], [42, 0, -2], [36, -18, 8], [-20, 18, 6], [5, 8, 23], [-26, 4, 4], [-15, 24, -4], [50, -9, -2], [16, -10, 11], [49, 6, -9], [12, -8, -6], [-4, 3, 16], [-11, 14, -5], [-45, -19, 16], [33, -3, 10], [24, 6, -20], [-12, -2, -28], [-44, 8, -6], [-2, -2, -2], [-23, -13, 14], [28, -6, -16], [-31, -8, 10], [-34, -2, -14], [-5, -22, 18], [52, -16, -8], [-23, -13, 4], [36, -19, -3], [-1, 1, 9], [-12, 7, -11], [-27, 0, 19], [-32, 21, -18], [19, 15, -10], [-17, 17, 2], [2, -26, 18], [-26, 15, 10], [-22, 8, 4], [13, 12, -20], [-20, -2, 14], [-14, 36, -6], [-25, 6, -19], [16, -8, 16], [30, 22, -24], [58, -12, 0], [-5, 5, 15], [26, -14, -17], [30, -10, -12], [-30, 0, 10], [25, -13, 17], [-7, -11, 3], [-15, 11, 3], [-36, 13, 12], [-9, 13, -12], [-12, -32, 24], [10, -22, -14], [26, -25, -2], [6, -10, 10], [16, -20, 3], [8, 15, 9], [47, -5, -7], [-15, -28, 3], [-3, -7, -4], [-32, -16, 12], [11, 30, -18], [51, -2, -15], [26, -2, 10], [-13, 35, -12], [-5, 16, 7], [-15, 28, -5], [-20, 26, -14], [-20, 20, 10], [-44, 21, -4], [-24, 30, 4], [32, -3, -9], [6, -30, 29], [3, -18, 26], [-48, 4, -18], [-2, -22, 8], [-35, 8, 10], [44, -6, 14], [38, -18, 14], [-36, 12, -20], [10, -18, 10], [27, -10, 28], [23, 28, -3], [-14, -18, -2], [6, -17, 1], [-6, 2, 8], [40, -27, 5], [-68, 6, 2], [-21, 23, 0], [25, -16, 21], [10, 0, 34], [-14, -2, 4], [58, 4, -14], [45, -16, -13], [12, 21, -18], [-40, 10, 8], [-11, -43, 19], [9, -12, 1], [11, 22, -17], [-26, -6, 11], [45, -26, -4], [-28, -8, -18], [48, 14, 4], [4, 24, -19], [-48, 20, -14], [-37, -4, -7], [-36, 13, -21], [-15, 29, -20], [-3, 27, -27], [54, -27, -10], [-45, 9, -10], [-10, 30, -32], [-59, -3, -2], [35, 1, -13], [-54, -2, 5], [-36, 28, -7], [4, -2, -15], [14, 2, 10], [-6, -1, -23], [-18, -29, 10], [8, 28, 6], [-46, -3, -15], [-53, 20, -1], [-1, -8, 19], [-17, 14, 4], [-53, 6, -25], [-10, 2, -38], [-48, 2, -11], [20, 4, 18], [-44, -27, 25], [12, -21, 30], [-32, -28, 6], [57, -2, -17], [35, -23, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5586_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5586_2_a_bt();".
// 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_5586_2_a_bt(:prec:=3)
    chi := MakeCharacter_5586_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_5586_2_a_bt();".
// 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_5586_2_a_bt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5586_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-9, -7, 1, 1]>,<11,R![43, -1, -7, 1]>,<13,R![8, -20, 2, 1]>,<17,R![-6, 26, -10, 1]>],Snew);
    return Vf;
end function;