
// Make newform 5766.2.a.e in Magma, downloaded from the LMFDB on 22 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5766_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_5766_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_5766_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5766_a();"
function MakeCharacter_5766_a()
    N := 5766;
    order := 1;
    char_gens := [3845, 3847];
    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_5766_a_Hecke( : Kf := Kf)
    return MakeCharacter_5766_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], [1], [1], [-4], [1], [-5], [7], [-5], [6], [6], [0], [-10], [4], [8], [1], [-8], [6], [-5], [-7], [-15], [4], [-1], [-1], [-10], [17], [2], [-2], [4], [-12], [-8], [0], [6], [-2], [-4], [-23], [-23], [-12], [7], [-8], [-13], [-9], [-26], [12], [-17], [24], [-17], [4], [9], [-24], [-9], [28], [22], [-22], [-16], [0], [6], [-6], [11], [-9], [12], [21], [-10], [-12], [11], [-28], [3], [-34], [8], [5], [28], [13], [33], [-17], [-20], [-23], [24], [10], [2], [25], [-20], [-28], [-20], [40], [-6], [8], [24], [9], [-26], [-6], [7], [-10], [-9], [31], [20], [-24], [-3], [-20], [14], [34], [20], [20], [16], [30], [-30], [-28], [19], [-33], [-24], [11], [-26], [-8], [-29], [-46], [2], [-32], [-45], [-24], [6], [9], [-26], [-8], [2], [-10], [28], [37], [-15], [-7], [48], [18], [-6], [-12], [-36], [-8], [10], [-27], [2], [14], [-14], [24], [27], [-24], [50], [-7], [27], [14], [-40], [-8], [-10], [22], [-48], [28], [15], [10], [8], [47], [-46], [-18], [-30], [-7], [-44], [27], [3], [19], [0], [-36], [40], [-32], [-24], [38], [-38], [28], [31], [-39], [14], [10], [49], [-51], [26], [-32], [18], [-2], [-31], [-12], [3], [-13], [0], [-10], [-59], [10], [64], [46], [8], [56], [20], [-12], [-39], [-22], [46], [12], [9], [30], [-23], [-40], [59], [12], [-24], [34], [53], [42], [-65], [68], [-2], [56], [18], [66], [37], [-22], [-42], [-12], [1], [-2], [0], [-28], [-6], [14], [17], [38], [68], [59], [8], [-41], [-33], [6], [-37], [-40], [0], [-23], [51], [-4], [-56], [44], [28], [-16], [-13], [50], [16], [-8], [12], [-14], [7], [22], [42], [-42], [71], [-39], [6], [-20], [42], [62], [27], [26], [48], [-46], [44], [10], [60], [-67], [-78], [-72], [-63], [-56], [22], [36], [-55], [-9], [-46], [0], [30], [-18], [3], [-53], [-18], [75], [50], [68], [26], [64], [-46], [38], [21], [-17], [22], [-10], [32], [-57], [-80], [-64], [-49], [29], [22], [5], [-30], [-75], [-30], [-40], [-27], [15], [8], [-34], [-2], [8], [24], [42], [10], [48], [34], [33], [48], [6], [15], [40], [-4], [30], [-36], [54], [-64], [-9], [44], [-18], [-36], [20], [63], [26], [5], [27], [-46], [-67], [-84], [-69], [3], [25], [-31], [64], [32], [14], [-62], [-72], [-72], [4], [-54], [22], [8], [5], [-24], [62], [-13], [84], [87], [78], [-24], [-2], [-15], [-58], [-44], [11], [46], [-55], [17], [-35], [-38], [89], [-24], [35], [-56], [59], [-24], [15], [70], [0], [34], [-74], [-42], [-31], [-39], [-70], [-72], [-18], [58], [-10], [54], [10], [-14], [6], [-13], [-43], [7], [16], [26], [42], [-16], [75], [-50], [36], [24], [-8], [-42], [2], [-25], [-74], [-21], [-6], [66], [17], [52], [-55], [-15], [70], [-32], [-56], [80], [-8], [-33], [-78], [24], [-54], [-82], [32], [-43], [-106], [90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5766_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5766_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_5766_2_a_e(:prec:=1)
    chi := MakeCharacter_5766_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_5766_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_5766_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5766_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, 1]>,<7,R![4, 1]>,<11,R![-1, 1]>],Snew);
    return Vf;
end function;