
// Make newform 5766.2.a.ba in Magma, downloaded from the LMFDB on 09 October 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_ba();".
// 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_ba();".
// 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, 4, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 1]];
    Rf_basisdens := [1, 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_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, 0, 0, 0], [1, 0, 0, 0], [0, 0, 2, 1], [2, 0, 1, 1], [2, 2, -1, 0], [0, 0, 0, -2], [0, 0, -2, -4], [0, 0, 0, -2], [6, 0, 0, 0], [5, -1, -2, 1], [0, 0, 0, 0], [-2, 2, -2, 0], [0, -6, -2, 2], [-2, 2, 2, -4], [-4, 2, 2, -6], [-4, -1, 2, -6], [2, -1, 4, 4], [-2, -2, -4, 0], [-2, 4, 2, 0], [10, -2, 4, 6], [-7, 0, -4, -3], [3, 6, -2, 3], [1, 4, -2, 0], [4, -2, -4, 8], [3, 0, 8, 8], [6, 0, 1, 8], [-5, 2, 4, 0], [10, -2, 3, 4], [8, -6, 2, 6], [-2, 4, 4, -6], [7, -11, -4, 3], [-9, 0, -2, -7], [6, 0, -2, -10], [-4, -6, -4, 6], [12, -3, -6, -6], [14, 0, 1, 1], [-4, -4, 8, 4], [10, -10, 4, 12], [-14, 4, -4, -16], [7, 1, -2, 15], [10, -5, 4, 12], [-6, 4, -4, -14], [4, -2, -6, 10], [7, -11, -8, -5], [12, 0, -6, 3], [-15, 7, 0, -3], [-2, 2, -6, -8], [2, 8, -11, -7], [-2, 10, -9, -8], [-10, -4, -4, 4], [6, -6, 2, -2], [10, 4, -6, -8], [-4, 0, 3, 3], [10, -2, 2, 5], [2, 2, 4, -2], [-8, 4, -2, -6], [-4, -4, 10, 7], [-8, 14, 1, -12], [-4, -12, 0, 0], [0, 6, 2, -8], [6, -14, -8, 8], [11, -10, -6, 8], [0, 6, -2, 6], [-8, 4, -8, -12], [1, -4, 8, 8], [-13, 2, -6, -4], [-10, 6, -6, 0], [-11, 4, 4, 4], [-4, -4, 7, -5], [12, -8, 2, -2], [20, -4, 0, 2], [0, 6, 0, 6], [5, -6, -6, 9], [6, -12, 0, 4], [10, 10, 2, -6], [0, 0, 2, 4], [-15, 6, -4, -17], [8, -4, -6, -18], [18, -6, 6, 18], [-7, 3, 0, -15], [-20, 4, -7, -7], [14, -12, -4, 12], [16, -2, -6, 4], [0, -8, -8, 11], [25, -1, 0, 13], [9, 0, 2, 19], [-18, 6, 2, -2], [8, -24, 0, 9], [4, 1, 2, 14], [-3, 6, -4, 8], [18, -15, 4, 8], [-4, -10, -6, 2], [-17, 2, 0, -8], [1, 4, 10, 12], [6, 0, -6, -20], [-12, -6, 6, -6], [-9, -6, -2, -4], [6, 0, 2, 10], [4, 2, -4, -4], [20, -4, -8, -10], [-14, 16, 6, -10], [10, -8, 3, 16], [0, 0, 7, 11], [-14, 16, 4, -12], [-4, 0, 12, -6], [24, -20, 4, 17], [-8, 4, 3, -17], [-6, 6, 20, 4], [8, 8, -6, -4], [-8, 20, -8, -15], [-19, 2, 10, 5], [20, -4, 6, 18], [18, -30, -8, 8], [8, -10, -12, 6], [26, -16, 5, 13], [26, 2, -8, 4], [24, -6, -2, 6], [6, -12, 12, 18], [-16, 5, -10, -30], [17, -1, 2, -3], [12, 4, -4, -14], [-20, 8, -3, -11], [14, -4, -9, 8], [-9, 0, -2, 8], [-10, 14, -6, -6], [-9, 6, -2, -4], [-34, 12, -6, -24], [12, -6, 16, 14], [-4, -6, -21, -12], [-16, 12, 12, 18], [16, 4, 4, 10], [-12, 18, -4, -20], [-13, -6, 12, -12], [2, 14, 10, 8], [-10, 14, 10, -2], [1, -16, -12, 16], [-8, 4, -2, -9], [-10, 0, -12, -30], [3, 9, -10, 7], [-20, 10, -2, 0], [8, 0, -18, -12], [20, -1, 10, 10], [22, -1, 6, 10], [22, -14, 14, 23], [-18, 0, -6, -20], [-20, 28, 2, -10], [2, 0, -6, -12], [-20, -2, -2, 12], [-26, -4, -10, -10], [-10, 14, 12, -16], [8, 6, 0, -24], [-22, -22, 8, -6], [8, 6, -12, -10], [-34, 2, -4, -24], [-18, 0, 16, 6], [12, 12, -14, 14], [9, -6, -4, 20], [22, -14, 10, 30], [7, 8, -16, 11], [-5, 1, -14, -21], [-11, 4, 2, 11], [10, 10, 0, 10], [12, 4, -8, 8], [2, -1, 24, 20], [-2, -20, 0, -2], [28, 4, -2, 18], [-19, 2, -10, -23], [14, 24, -12, 2], [-25, 24, 12, 0], [-12, 9, 2, -2], [1, -8, -14, -21], [-42, 10, -12, -36], [4, -2, 4, 36], [-4, -16, -1, -8], [6, -6, -20, 9], [26, 14, -2, -2], [-4, -6, 10, 10], [1, 10, -16, -13], [-25, -3, -12, -9], [-4, 0, -6, -24], [-2, 11, -10, -10], [14, -13, 8, 0], [30, -6, 0, 40], [-30, 12, 2, -44], [-4, 2, -12, -22], [-10, -4, -21, -13], [-10, -6, -8, -20], [-18, 16, 8, 4], [3, -12, 36, 28], [8, 2, -14, 22], [-16, 0, -9, -12], [-2, -14, -6, 19], [12, 4, 4, 14], [10, -32, -1, 8], [-42, -6, 2, -5], [28, -20, -4, -4], [39, -20, 0, 12], [-6, 6, 16, 6], [2, 20, -2, -2], [-14, 4, 0, -8], [-1, -7, -30, -13], [20, 6, 15, 8], [-50, -4, 6, -8], [-4, 24, 16, -5], [2, -10, 10, 19], [6, 12, 1, 8], [-27, -9, 16, 9], [5, 8, 6, -1], [-2, 10, 8, 8], [-14, 2, 20, 8], [4, -8, -4, 3], [5, 14, 0, -1], [-2, -5, -2, 10], [7, -20, 30, 25], [-26, 4, 12, -14], [8, 0, 21, 21], [8, 2, 1, 20], [-8, 10, 8, 14], [-8, 16, -18, -20], [-6, 0, 23, 19], [26, 12, -18, 0], [-36, 22, -9, -24], [6, -6, -18, -18], [-10, -6, 0, 15], [6, -6, -6, 21], [-8, 2, 6, 28], [-8, 4, 30, 4], [20, -22, 4, 22], [20, 8, -32, -16], [22, -14, 31, 36], [26, -16, 28, 38], [2, 20, 10, -4], [-49, -7, 12, 3], [-14, 28, -6, -26], [-4, 8, -10, 4], [-12, 0, -26, -34], [55, -16, 0, 19], [11, 5, -22, -9], [6, -6, -10, 25], [46, -2, -10, 2], [22, 22, -14, 3], [-10, 2, 4, 14], [-10, 26, 0, -15], [-22, 6, 12, 0], [-36, 18, -18, -36], [-18, 6, 18, 18], [-6, 18, 4, -15], [-8, -20, -19, 17], [30, 4, 2, 34], [0, -6, 2, -8], [0, -14, 36, 24], [12, 24, 8, -2], [6, -18, 16, 32], [-7, -28, 0, 9], [-8, 19, 6, 10], [-12, -12, 5, -11], [42, -2, -20, -16], [2, 12, 12, 30], [-27, -9, 14, 1], [-37, -3, -8, -29], [-7, -6, 0, 8], [-16, 8, -31, -15], [-16, 0, -26, -26], [-20, 8, 10, -12], [28, -26, -24, -8], [-42, -2, -4, -20], [3, -3, -2, -25], [-2, 10, 6, 40], [4, -4, 4, -12], [14, 8, -21, -25], [10, -10, -4, -28], [-32, 22, -8, -32], [-15, 16, 8, 16], [17, 6, 36, 12], [-16, 3, 0, 24], [1, 10, -6, 17], [-42, 9, -4, -20], [10, -8, 12, -16], [-28, 8, -23, -28], [35, -7, -2, -5], [-26, 4, -12, -44], [-26, -2, 4, 13], [0, -12, 8, 22], [-52, 14, -22, -26], [-28, 2, 10, 8], [-46, -4, 14, -18], [8, 0, 15, -1], [44, -19, 2, 6], [-1, -30, 2, 15], [-32, 40, 14, -4], [15, -15, -34, -5], [-33, -3, -2, -37], [-36, 0, 2, -20], [9, -21, -14, -7], [32, 0, 12, 30], [-18, -12, -20, -4], [14, 12, -3, -31], [-5, 10, -2, -24], [-33, 24, 6, -27], [-18, 4, 6, -18], [15, 33, -4, 11], [-18, 0, 12, 36], [10, 13, 10, 34], [-38, 19, 0, -32], [14, 14, 24, 6], [25, -25, -20, -3], [-1, 5, -6, 11], [8, 20, -10, 4], [0, -6, -10, 34], [8, -18, -18, 6], [-4, -16, -16, -18], [-42, -12, 16, -4], [12, -30, 10, 20], [18, 12, 12, -14], [-18, 6, 18, 6], [8, -1, 28, 20], [-22, 2, 1, -8], [-4, -10, 0, 8], [20, 8, -23, -19], [14, -10, 6, 8], [-18, 4, -4, -20], [-42, 0, 20, -16], [57, -9, 2, 13], [-43, -6, 2, -39], [24, 12, -8, 20], [-13, -24, 0, 27], [-10, -12, 18, 14], [20, 0, 30, 0], [-10, 32, 28, 4], [-34, 8, 3, -25], [32, 8, -8, 8], [60, -3, 10, 14], [20, 2, 17, 64], [-39, 0, -6, -9], [50, -18, 6, 8], [-41, 4, 10, 21], [18, -2, 28, 14], [44, -22, 10, 34], [-28, 24, 9, -27], [-29, 2, -6, -41], [12, 16, 6, -6], [-10, 8, 20, -12], [16, 4, -10, -1], [-4, -16, 12, 0], [26, -28, -23, 25], [2, 2, -22, 15], [42, -2, -18, -30], [20, 30, -6, 6], [2, 2, 2, 30], [-5, -26, -14, -36], [34, -8, -20, -26], [0, 12, -7, -4], [14, -4, -31, -36], [6, 15, 30, 10], [-32, -22, 34, 6], [24, -42, -18, 24], [-28, 8, 8, -12], [-30, 30, -10, -17], [14, -28, -20, 16], [36, 6, -4, -20], [-12, 12, -8, 12], [8, 8, 20, 12], [20, -22, -18, -4], [-43, 56, 2, -36], [-6, 12, 8, 32], [8, -12, -4, -15], [-4, -1, -22, 30], [-3, 3, 20, 29], [24, 0, -15, 37], [18, -6, -14, -7], [-4, 30, -4, 0], [2, -4, -36, -4], [36, 3, 26, 10], [27, -18, -10, 35], [-26, 8, 12, 28], [-43, 20, -18, -28], [52, 4, -10, -4], [-8, -4, -12, -11], [-6, 6, -6, 12], [28, 4, -8, -11], [-31, 2, 22, -44], [-6, 0, -22, 10], [-46, 2, 0, -15], [-48, 18, -4, -44], [30, 6, -22, 2], [36, -6, 18, -12], [-39, 34, 18, -27], [-10, -6, 6, 30], [30, -42, -18, -2], [-34, 8, -22, -12], [-4, 3, 36, -12], [-2, 40, 3, 7], [-1, 8, 30, -4], [12, -14, -38, 14], [-16, 2, 12, -22], [-4, 20, -33, -45], [71, -34, 10, 59], [4, -2, 32, -4], [32, -4, -16, 4], [25, 22, -32, -9], [-20, 16, 38, 24], [-30, 18, 40, 32], [26, 18, -20, -5], [-46, 2, -4, 12], [-6, -24, -12, 12], [-19, 6, 6, -27], [-4, 6, -18, -4], [18, -12, -20, -46], [14, 2, -32, -10], [14, 11, 36, -4], [21, 7, 8, -23], [18, -12, 3, -12], [62, -22, 10, 61], [-46, 18, 6, -24], [-24, 40, -1, -8], [36, -9, 10, 74], [-64, 20, 12, -4], [2, -6, 48, 39], [-28, 2, -6, -34], [34, -2, 34, 0], [18, -24, 39, 27], [-8, 8, 4, -6], [-8, 10, -4, -4], [11, 5, -42, -1], [-12, 31, 4, -28], [8, -4, 18, -1], [-17, 25, -18, -53], [-40, 14, 28, 40], [-54, -24, 2, -10], [24, -30, 36, 36]];
    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_ba();".
// 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_ba(:prec:=4)
    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_ba();".
// 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_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5766_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![45, 0, -15, 0, 1]>,<7,R![1, -8, 14, -7, 1]>,<11,R![-279, 126, 6, -9, 1]>],Snew);
    return Vf;
end function;