
// Make newform 5776.2.a.b in Magma, downloaded from the LMFDB on 09 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_5776_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_5776_2_a_b();".
// 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_5776_2_a_b();".
// 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_5776_a();"
function MakeCharacter_5776_a()
    N := 5776;
    order := 1;
    char_gens := [5055, 1445, 2529];
    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_5776_a_Hecke( : Kf := Kf)
    return MakeCharacter_5776_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 := [[0], [-2], [-1], [3], [3], [4], [5], [0], [0], [-2], [8], [10], [-6], [7], [9], [8], [14], [-5], [0], [-6], [-15], [-4], [-4], [0], [-16], [-18], [-14], [10], [-12], [-2], [-6], [9], [21], [-5], [17], [2], [14], [-4], [-2], [2], [-18], [-2], [15], [24], [18], [15], [-6], [22], [-20], [1], [-13], [3], [-18], [13], [24], [5], [-4], [8], [9], [10], [-13], [4], [16], [-31], [14], [18], [-8], [0], [-27], [-19], [2], [11], [-16], [-4], [18], [16], [-29], [13], [-24], [8], [12], [-20], [0], [26], [-26], [-19], [-24], [-29], [21], [37], [13], [28], [-2], [20], [29], [-12], [8], [-4], [26], [19], [-20], [-7], [14], [-8], [28], [-37], [29], [-18], [8], [22], [0], [-31], [33], [20], [-25], [24], [43], [-49], [21], [6], [16], [-6], [38], [-28], [-15], [30], [-6], [-29], [-7], [-14], [35], [-36], [-40], [-37], [-7], [-1], [-34], [-28], [0], [15], [0], [-11], [-37], [8], [-24], [30], [-30], [38], [-17], [-30], [-34], [37], [-41], [38], [4], [-2], [-4], [54], [-7], [-14], [-20], [-4], [48], [20], [-52], [20], [-10], [13], [40], [-27], [-58], [-20], [16], [58], [-12], [-61], [52], [21], [40], [-61], [-47], [-32], [-46], [18], [-29], [37], [10], [38], [10], [-4], [14], [-1], [52], [30], [-48], [-12], [-11], [10], [-10], [9], [60], [14], [-28], [22], [52], [25], [-11], [-24], [33], [26], [-62], [-22], [51], [28], [70], [-42], [24], [44], [-72], [-29], [-30], [70], [-54], [-43], [42], [-45], [-18], [4], [-22], [59], [-9], [16], [0], [-42], [-23], [15], [9], [31], [40], [-72], [30], [-47], [40], [18], [66], [-39], [65], [28], [-16], [33], [50], [-13], [-60], [-20], [-21], [4], [-47], [10], [-18], [50], [-46], [78], [-41], [-18], [15], [20], [-48], [47], [-10], [15], [-12], [22], [17], [-37], [68], [24], [59], [80], [-38], [15], [-66], [-60], [5], [-54], [-41], [-65], [-9], [-52], [-13], [-8], [-2], [-61], [72], [-2], [38], [-14], [8], [11], [4], [21], [-47], [34], [-13], [-4], [-27], [8], [12], [46], [-1], [-54], [39], [-46], [-24], [-58], [-48], [36], [53], [-44], [-49], [-11], [-50], [9], [-50], [44], [-26], [-16], [4], [10], [2], [69], [59], [14], [40], [-53], [3], [-3], [-16], [42], [-77], [-8], [-52], [13], [70], [-20], [18], [16], [-38], [-30], [-72], [-3], [26], [36], [-9], [-6], [-52], [-48], [64], [-12], [-7], [54], [5], [-6], [30], [28], [49], [-22], [-62], [-66], [28], [84], [-54], [-75], [-46], [23], [-59], [-12], [40], [43], [35], [0], [-42], [-21], [-7], [-93], [-14], [96], [40], [-38], [-23], [-42], [38], [-42], [48], [-47], [30], [14], [80], [-50], [-38], [-38], [8], [-17], [72], [78], [20], [-71], [-7], [-30], [14], [53], [-76], [-81], [46], [37], [2], [-18], [24], [80], [2], [6], [-28], [-86], [-27], [-6], [-76], [48], [6], [43], [-5], [9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5776_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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