
// Make newform 2058.2.a.e in Magma, downloaded from the LMFDB on 05 October 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2058_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_2058_2_a_e();".
// 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_2058_2_a_e();".
// 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, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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_2058_a();"
function MakeCharacter_2058_a()
    N := 2058;
    order := 1;
    char_gens := [1373, 1375];
    v := [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_2058_a_Hecke(Kf)
    return MakeCharacter_2058_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 := [[-1, 0, 0], [1, 0, 0], [-2, 0, -1], [0, 0, 0], [-2, 1, 0], [0, 2, 0], [-1, -1, 3], [4, -3, 0], [1, -7, 3], [-6, 4, -6], [5, -1, 3], [-2, -2, 3], [-2, 3, 4], [-8, 2, -6], [-2, 2, 0], [-2, 6, 2], [0, -2, -4], [-4, 6, -4], [-10, 0, 0], [-4, 0, -1], [-2, -4, -2], [4, -2, 6], [-8, 2, -2], [-7, 1, -3], [-4, 8, -8], [-8, -7, 2], [8, -10, 11], [-14, 2, -3], [-6, 1, -10], [0, 0, 0], [-6, -4, -2], [-10, 8, -16], [4, -8, 6], [14, -4, -3], [4, 4, 4], [-8, 12, -2], [10, 8, -6], [-10, 6, -4], [6, -4, 10], [2, -8, 0], [-7, -5, 1], [2, -2, -6], [5, -7, 15], [-4, -12, 5], [-6, 4, 10], [0, 10, -1], [0, 0, 0], [-2, -5, -10], [22, -10, 18], [10, -14, 0], [-10, 6, -8], [8, -3, 2], [2, -6, 10], [-8, 4, 4], [-8, 10, -11], [-12, 8, -3], [-4, -1, -6], [16, -14, 15], [3, 3, 9], [6, -6, -6], [-9, 19, -1], [-2, 20, -8], [-1, 15, -5], [-20, 2, -4], [0, -20, 10], [8, 14, -10], [8, -8, 12], [-9, 17, 11], [10, -18, -3], [-10, 14, 4], [2, -8, -4], [4, -8, -9], [-3, -5, -13], [-11, 5, -17], [10, -16, 18], [0, 12, -14], [24, -12, 8], [-10, 0, -4], [6, 14, -12], [-14, 14, 12], [14, -10, 18], [18, 3, -10], [0, 17, 2], [12, 6, -10], [14, -13, 22], [-10, 1, 0], [18, 12, 2], [24, 9, 0], [3, -7, 17], [6, -12, -18], [2, -18, 6], [12, -14, -8], [-12, 0, -12], [-2, 6, 1], [24, -12, 12], [6, -20, 20], [22, 12, -4], [6, 25, -8], [-32, 17, -32], [15, -13, -11], [0, -4, 0], [2, -8, -18], [8, -6, -22], [2, -6, -4], [-8, 30, -18], [-8, 22, -8], [0, 20, -8], [24, -22, 27], [4, 12, 8], [2, -12, 24], [36, -6, 11], [-6, -13, 10], [22, -6, 22], [-28, 19, -12], [-6, 4, -28], [12, 8, -6], [-24, 24, -16], [-18, 4, -24], [-18, -2, -2], [-8, 8, 0], [-10, 10, -20], [-19, 3, 13], [20, -15, -10], [14, -14, 27], [-20, -11, -4], [24, -20, 6], [-7, 21, -5], [-12, 22, -2], [0, -10, 15], [2, 6, 0], [-40, 2, -2], [-21, 11, -3], [34, -22, 38], [-14, -3, 2], [10, -9, 20], [-2, 0, -12], [-13, 33, -3], [-4, -29, 12], [8, 9, 6], [-26, 20, -30], [-1, -17, 23], [24, -4, -14], [-14, 16, -18], [4, -28, 16], [10, -8, -8], [-14, 6, 8], [-24, -12, 2], [-24, 18, -19], [-11, -31, 17], [20, -23, 26], [-22, 26, -17], [8, -6, -13], [14, -20, 24], [-22, 16, -34], [-30, 4, -26], [3, -1, -3], [-28, 10, 14], [32, -14, 9], [-18, -10, 20], [25, -29, 3], [-22, 3, 0], [-8, -8, -14], [30, -32, 40], [-16, -6, 14], [-6, 2, 12], [-20, 2, 16], [6, 14, -6], [-32, 4, -22], [16, 4, 3], [-12, -7, -14], [-37, 9, -21], [16, 12, -4], [32, -31, 42], [-10, -4, 0], [6, 1, 22], [27, -5, -5], [-10, -34, 14], [40, -14, -2], [12, 2, 23], [-24, 28, 4], [18, -16, -4], [-16, 24, 2], [-30, 12, -4], [4, -6, 11], [-12, 24, -25], [18, -8, 16], [-17, -1, -27], [10, -16, 31], [-10, 8, -4], [4, 12, -12], [-38, 14, 14], [9, -21, 5], [-18, 26, -18], [31, -19, 1], [-18, 10, -1], [24, -6, 11], [0, -3, 20], [-6, 5, 18], [45, 5, 1], [20, -30, 30], [32, -8, 4], [-17, 13, -27], [12, 10, 18], [-8, 32, -28], [14, -22, 30], [16, 1, 34], [35, -23, 25], [6, -2, -1], [-26, 12, 2], [6, 20, -19], [-24, 1, 4], [-14, 0, -29], [-16, 38, -28], [8, -6, -14], [32, -18, 18], [-4, 32, -14], [0, 6, 26], [-8, -18, 7], [4, 13, 6], [-10, 26, 4], [30, -10, 25], [0, -12, -12], [8, -6, -32], [10, -20, -16], [0, 28, 10], [-30, -28, 4], [-6, 16, 12], [20, 0, 28], [-48, 12, -16], [14, 10, -1], [-6, 21, -2], [22, -16, -21], [36, 12, -6], [24, -26, 28], [-19, 5, 17], [0, 4, 6], [-30, 20, -28], [-38, 18, -50], [-18, -9, 16], [-32, -16, -8], [34, -33, 12], [0, 17, -4], [-32, 8, -12], [13, -19, 27], [-3, 41, -11], [-18, 20, 6], [24, -34, 15], [-6, 12, -18], [-4, 0, -10], [-32, 49, -42], [-30, 11, -22], [27, -25, 43], [29, -27, 19], [-58, -8, -6], [-10, 28, -20], [-40, -12, 16], [1, 45, -5], [19, -37, 15], [-12, -11, -38], [-8, -22, 28], [-6, -28, 30], [-39, -1, 21], [-10, -14, -20], [-4, -4, 6], [-22, 9, -32], [-3, 9, 21], [14, -18, 36], [-16, 6, -41], [-16, 10, 2], [-32, -2, -12], [20, 32, -14], [28, -30, -12], [0, -38, 28], [16, -22, -18], [10, 0, 22], [1, 3, -9], [1, 3, -27], [-2, -26, 9], [47, -3, 3], [-24, 18, -30], [20, -38, 30], [30, -22, 4], [-32, -4, 4], [64, -24, 38], [-6, 48, -15], [31, -9, -19], [-7, 7, 5], [2, 34, -10], [-28, -16, -16], [-12, 6, -15], [58, -24, 42], [-34, 12, 20], [-32, 18, -12], [-32, 12, 12], [2, -34, 33], [34, -28, 45], [22, -15, 14], [10, -28, 23], [-18, -24, -4], [-38, 8, -3], [36, -30, 14], [-36, 48, -30], [-12, 26, 18], [15, -11, 27], [16, -12, -26], [47, 13, 11], [-16, -4, -36], [58, -2, -4], [9, 37, -17], [-26, 20, -16], [-24, -38, 12], [-22, -10, 2], [22, -40, 28], [-34, -22, 18], [-8, 12, 5], [-18, 22, -20], [6, -20, 12], [-1, -17, -3], [-42, 20, -6], [-38, -14, 0], [48, -7, 28], [-8, 28, 23], [-22, 32, -7], [-28, 20, -2], [8, 30, -6], [26, -2, -2], [8, -24, 38], [38, -32, -13], [0, 36, -39], [-22, 20, -12], [14, -21, 22], [-18, -30, -16], [-28, 32, 20], [-4, -4, -42], [50, -16, 24], [6, -2, -18], [-1, -53, 17], [2, 43, -36], [66, 0, 12], [-3, 15, -21], [-38, 25, -18], [-24, 0, 22], [-35, 19, 7], [-18, 18, -36], [-52, 22, -42], [-26, -1, 20], [28, -12, 18], [-30, 26, -52], [4, -40, 32], [7, 5, 57], [32, -4, 48], [36, -31, 44], [28, 0, -14], [-40, -2, 1], [-70, -7, 2], [0, -42, 7], [4, 34, -18], [-42, 30, 18], [-12, 54, -4], [-28, 44, -51], [38, -27, 22], [-10, 3, 20], [16, -19, 14], [-53, 37, -25], [-31, 13, -31], [6, 16, 20], [21, 15, -13], [14, 6, 6], [-36, 15, -44], [10, -35, 36], [46, 8, 9], [23, -1, 21], [-4, -26, -2], [49, -13, -29], [54, -21, -14], [20, 6, -20], [63, -29, 33], [50, -38, 16], [35, -49, 47], [-44, 16, -36], [6, -20, 37], [10, -50, 30], [0, -14, 20], [-40, 28, -22], [52, -5, -20], [-46, 24, -58], [-8, -4, 30], [70, -16, -18], [-42, -18, -20], [32, -58, 32], [-33, 45, -29], [-2, 16, 28], [-42, 21, -36], [60, -51, 44], [0, -9, 2], [27, -15, -17], [55, 13, 9], [43, -1, -5], [-64, 12, -28], [-24, 30, 22], [56, -2, 30], [6, -30, 26], [-14, 18, 2], [60, -30, 49], [-52, 39, 2], [-3, -25, -9], [-50, 22, -13], [-34, 56, -50], [-6, 48, 1], [2, 34, -18], [-4, -36, -24], [-2, -52, 26], [-34, 54, -33], [-8, -18, 48], [20, 8, 5], [-63, -25, 11], [41, -23, 23], [18, -1, 46], [-4, -54, 19], [-28, 22, -16], [-28, 38, 4], [54, 4, -6], [33, 9, -29], [-6, -16, 2], [-8, -4, -42], [-5, 25, 21], [22, 39, 4], [-20, -16, -38], [6, -4, -9], [-18, -28, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2058_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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