
// Make newform 5586.2.a.bo in Magma, downloaded from the LMFDB on 24 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_bo();".
// 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_bo();".
// 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 := [-2, 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_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], [1, 0], [0, 0], [0, 0], [-4, 1], [0, -2], [-4, 2], [-1, 0], [0, -3], [-8, 0], [-2, 4], [-2, 0], [-4, 1], [-4, -2], [-2, -4], [-2, 0], [0, 0], [4, -1], [0, -3], [0, 10], [8, 1], [-4, 7], [-4, -4], [4, -1], [12, 2], [8, 0], [-2, -4], [-4, -4], [-2, -12], [-4, 4], [-4, 3], [-10, 0], [-2, 12], [12, -8], [-14, 0], [4, -3], [12, 3], [-4, 6], [-8, 12], [8, 3], [12, -8], [-8, 8], [8, -7], [-10, 0], [-18, -4], [0, 8], [-16, 7], [16, 0], [12, 4], [-4, -15], [2, 8], [0, -15], [12, 4], [6, -16], [-4, -17], [8, -3], [-8, 7], [-8, -4], [2, 8], [6, -16], [-12, 12], [-8, 1], [-2, 0], [0, 12], [0, 7], [-8, 8], [0, 1], [-10, 16], [4, -1], [12, -3], [-12, 10], [0, 1], [20, 4], [10, 0], [16, 7], [-24, -4], [2, 20], [-12, -17], [0, -4], [-12, -10], [-10, -8], [-14, 4], [-8, 18], [12, -2], [6, -12], [-20, -5], [-8, -12], [-24, -8], [16, 0], [8, 0], [20, -12], [8, -12], [4, -17], [-12, 5], [20, 10], [-24, 4], [0, -5], [-4, 7], [-2, 24], [-28, 4], [16, -11], [-18, -4], [0, -8], [12, -20], [-12, -12], [24, 7], [-12, 4], [-20, 16], [0, 26], [-12, -10], [8, 8], [24, -4], [-2, -12], [-16, -4], [8, 22], [22, 8], [24, -12], [-32, 4], [-14, -12], [12, -20], [-8, 20], [2, 8], [-8, -9], [4, 6], [8, 8], [-10, 12], [38, 8], [-16, 20], [24, -4], [-4, -15], [4, -24], [32, -4], [-20, -15], [0, 20], [-28, 16], [0, -23], [-16, 9], [14, -16], [0, 3], [6, 20], [14, 0], [22, -20], [8, -12], [-4, -8], [0, 18], [8, -12], [-12, 27], [-12, -15], [-12, 8], [48, -4], [-18, 8], [-12, -22], [-4, 6], [32, 16], [0, 25], [0, -6], [24, 4], [20, -6], [8, 7], [-40, 3], [-28, 13], [48, -4], [24, 18], [-28, 16], [0, 4], [-4, -12], [-12, -13], [-36, 5], [-30, 8], [-8, -8], [-4, -26], [-16, -4], [-16, -3], [-12, 32], [16, -24], [-44, 0], [28, -8], [-14, -12], [0, -24], [36, 17], [0, -30], [16, 0], [6, -12], [-28, -13], [-16, -7], [8, 36], [-6, 28], [-28, 8], [-26, 4], [22, 4], [20, 12], [-4, 43], [24, 7], [0, -13], [-20, -11], [4, -31], [12, 16], [32, -12], [-12, -14], [0, 36], [-42, 0], [8, -24], [-24, 0], [-20, 12], [-4, -20], [24, -16], [0, 24], [28, -10], [-26, 8], [-50, 8], [18, -24], [0, -28], [40, -8], [12, 32], [-20, 16], [-12, -36], [-16, -12], [4, -5], [16, -10], [-10, -24], [6, 20], [24, -8], [14, 0], [24, 16], [-12, -4], [-28, -12], [-52, 5], [16, 12], [-10, 28], [28, 13], [-42, 8], [42, 0], [20, 15], [-2, 32], [-8, -44], [-22, 4], [48, 5], [-26, -32], [12, 11], [-28, -28], [12, -34], [28, 12], [48, 4], [-30, -16], [-52, 5], [-16, 4], [4, -28], [24, 36], [-48, 15], [-8, 1], [-36, 28], [28, -12], [40, 15], [60, -8], [-16, -10], [-28, -33], [38, -16], [36, 16], [-24, 33], [40, -3], [-12, 7], [44, -14], [60, 5], [32, -2], [-20, -12], [-44, 8], [-22, 16], [36, -8], [0, -17], [-18, 40], [48, -16], [0, 43], [-32, -29], [24, -2], [4, 38], [72, 4], [-36, -29], [-38, -16], [10, 8], [36, 12], [-40, -20], [-8, 4], [8, 12], [0, 14], [12, 28], [-32, -15], [-16, 0], [-30, 8], [-48, -8], [-28, -21], [-14, -16], [-12, -36], [-10, -16], [16, -32], [2, -12], [8, -22], [54, -4], [0, 20], [-56, -4], [-48, 20], [-24, 25], [0, 40], [24, 22], [-4, 46], [-28, 2], [-14, 0], [-36, 18], [40, 26], [-16, -35], [-24, -20], [-34, -4], [6, -48], [-6, -16], [-16, -31], [72, 7], [-20, 46], [20, 44], [0, -14], [-32, 27], [-50, 12], [-60, 0], [18, 16], [32, 15], [-20, -5], [-42, 4], [-36, -16], [-72, -3], [-14, 16], [8, 30], [-42, -12], [-44, 28], [30, 16], [0, 0], [66, 0], [-36, 18], [20, 4], [42, -16], [-12, 7], [-8, 27], [28, -32], [30, -36], [6, 0], [-48, 5], [-60, 13], [-6, -24], [-52, -4], [20, 27], [48, 23], [8, 28], [-32, -8], [-4, -48], [-30, -40], [14, 24], [-72, -16], [-30, 40], [-60, 3], [22, -12], [-10, 0], [-30, -20], [24, 18], [20, -36], [-12, -48], [48, -22], [4, 10], [-16, -16], [2, 4], [40, -26], [-12, 43], [46, -20], [4, -3], [12, -32], [-24, -21], [-28, 0], [-8, -16], [8, -60], [-8, 12], [8, -13], [32, -21], [-60, -20], [-60, -16], [8, -13], [-50, 28], [24, 46], [38, 16], [-68, -8], [0, -28], [64, 10], [4, -55], [-12, 2], [16, 32], [-46, 8], [32, -11], [-36, -9], [16, 44], [72, -8], [6, -36], [-30, -4], [-12, 33], [-48, -13], [-50, 24], [56, -2], [-30, 36], [-28, -23], [-20, -41], [-24, 41], [-48, 4], [-10, -8], [-26, -16], [-38, 8], [52, 36], [-68, -22], [-42, 28], [-12, 28], [4, 2], [-42, 16], [-40, 6], [-40, -12], [0, -56], [20, 42], [28, -28], [-26, -56], [16, -40], [-24, 5], [-44, -36], [-44, 14], [-16, -27], [-76, 0], [-14, -40], [-12, 64], [2, -12]];
    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_bo();".
// 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_bo(:prec:=2)
    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_bo();".
// 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_bo( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5586_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<11,R![14, 8, 1]>,<13,R![-8, 0, 1]>,<17,R![8, 8, 1]>],Snew);
    return Vf;
end function;