
// Make newform 3776.2.a.be in Magma, downloaded from the LMFDB on 17 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_3776_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_3776_2_a_be();".
// 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_3776_2_a_be();".
// 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, 1, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -2, -1, 1], [1, -4, -1, 1], [-4, -2, 2, 0]];
    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_3776_a();"
function MakeCharacter_3776_a()
    N := 3776;
    order := 1;
    char_gens := [1535, 709, 769];
    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_3776_a_Hecke( : Kf := Kf)
    return MakeCharacter_3776_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, 0, 0, 0], [-1, 0, 1, 0], [-1, 0, -1, 0], [1, 0, -1, 1], [-1, -1, 1, 0], [1, 1, 1, -1], [2, 0, 0, 0], [-1, 0, 1, 0], [3, 1, 1, 0], [-1, 2, -1, 0], [0, -2, 0, -1], [-5, 1, -1, 0], [-1, 0, -1, 1], [-2, -4, -2, 1], [-3, -3, -1, -1], [-1, 0, -1, 0], [-1, 0, 0, 0], [-5, 1, -1, 1], [3, -1, -3, 0], [0, 0, 4, 0], [-4, 0, -2, 1], [3, 4, -3, -1], [1, 1, -1, -1], [1, -1, -3, 3], [8, 0, 2, -3], [4, 6, 2, 0], [-7, -1, 3, -2], [-7, -2, -1, 0], [0, -4, -2, -1], [10, 4, 0, -3], [-11, 2, 3, -1], [-5, -1, -3, -3], [1, 2, 5, -1], [-4, 4, 0, 0], [-7, 1, 1, -2], [-8, -2, 0, 4], [-4, 0, 2, -2], [0, 4, -4, 2], [-7, -4, -1, 5], [-14, 2, 4, -1], [2, -6, 2, 0], [5, -4, -7, 2], [-18, -4, 2, 2], [-9, -4, -1, 1], [4, -2, -2, -2], [-3, -4, 3, -3], [-9, -3, 1, 1], [-10, 2, -2, 0], [-9, -3, 1, 3], [-7, 5, 1, 0], [3, -1, 3, -5], [3, 10, 5, -1], [-17, 2, 7, -3], [3, 2, -3, 2], [1, 4, -3, -1], [-1, 2, -7, 1], [2, 0, 4, -1], [-9, 0, 1, 3], [-5, 0, 3, -2], [-1, 8, -1, -1], [4, -4, 0, -2], [-3, 0, 1, 4], [-11, -4, -5, 0], [15, -2, 1, -3], [-11, -5, 1, 1], [-8, -6, 2, 6], [5, -2, 3, -4], [-1, 1, 7, -8], [13, 1, 3, 3], [6, 0, 0, -1], [3, 1, 3, -2], [-3, -6, -5, 7], [5, -3, 7, 1], [6, 4, -4, 6], [-13, 2, -3, -2], [-8, -8, -4, 2], [0, -2, 10, -2], [11, 3, -1, -4], [3, 1, -5, -2], [13, -1, 1, 2], [1, -5, 7, -4], [4, -4, -6, 8], [-2, -4, 2, 7], [-11, -2, -7, -5], [-2, 6, 6, 2], [4, -4, -8, 8], [-1, 2, 7, 1], [-7, 9, -3, 1], [6, 0, 4, 4], [-7, 3, -5, -4], [6, 6, -10, 3], [-8, 8, -4, 2], [5, 0, 3, 5], [19, 2, -3, 4], [3, 0, -3, 12], [12, -4, 4, -3], [-18, -6, -8, -2], [-2, -12, -4, 2], [3, 6, -3, 6], [11, 1, 7, 0], [-2, 6, -2, -4], [-23, 2, 5, -2], [11, 5, -3, -4], [0, 10, 2, 1], [-18, 0, -2, 6], [-11, -4, 9, 3], [13, -5, -5, 5], [23, 2, -1, 1], [1, 2, -1, -3], [14, 10, -4, -4], [-19, 0, 11, -1], [1, -13, 9, -1], [3, -10, -5, 1], [9, 8, 7, -2], [-26, -6, -2, 2], [28, -2, -2, -2], [-5, -4, -3, 0], [-9, 10, 1, 1], [-11, 2, 9, -2], [-16, 0, 4, -1], [17, -10, -11, 4], [7, -11, -1, -3], [-10, 0, 4, -10], [18, 4, 10, 4], [-7, -5, 7, -8], [14, -2, -8, 0], [-9, -2, 15, -6], [10, -14, 6, -3], [14, -6, -18, 6], [8, 6, -6, -2], [-37, -3, -3, -2], [-10, -2, -2, -2], [18, 8, -10, 0], [3, 2, 3, 8], [3, -10, 11, -1], [5, 9, -15, 2], [-9, -3, 3, 3], [16, -4, -4, 4], [-34, 2, 0, -1], [10, 4, 0, -3], [-7, -11, 7, 1], [15, 5, 3, -3], [1, 11, 3, -3], [18, 6, -6, 0], [9, 0, -3, 6], [17, -9, -13, 7], [11, -2, -5, -6], [0, 4, 2, -3], [-5, 5, -11, -4], [-14, -6, -10, 3], [3, 6, -5, -4], [11, 7, 3, 5], [11, -2, 13, -2], [8, -8, 8, -1], [-21, -12, -3, 10], [25, 0, -1, 1], [-29, -1, 9, -5], [11, -1, 3, -2], [1, 5, -3, 11], [7, -3, -5, -2], [13, 2, 3, 2], [8, 10, 10, 2], [10, -8, 6, 3], [17, -8, 15, -2], [14, 8, 12, -4], [16, -2, -16, 4], [-10, 12, 2, -6], [-13, -6, 3, 6], [30, -6, 4, 1], [4, 6, -6, 0], [2, -14, 2, -4], [-1, -5, 3, 9], [5, 4, 11, -11], [17, 3, -11, 4], [7, 4, 9, -3], [-7, 4, 13, -5], [-25, 14, -7, 4], [-21, 1, -1, 5], [6, -6, -2, 6], [-17, -12, 7, 6], [-17, 0, 9, -1], [19, -8, -19, 8], [4, -2, 10, -10], [37, 2, 1, 7], [-2, 10, -10, 6], [-13, -5, 15, -2], [-18, -2, 16, -2], [23, 7, 17, 7], [0, -2, 18, 1], [-1, -3, -11, -1], [27, 19, 3, -5], [-28, 10, 8, -4], [-3, -1, 11, -11], [-6, 0, 16, -2], [-19, 10, 3, 0], [0, 6, 2, 4], [-14, -12, -16, 0], [-16, 4, 6, -5], [8, 6, -14, 0], [10, 6, -10, 5], [-2, 4, 12, -8], [23, 0, 9, 5], [-14, 0, -8, -10], [-10, -8, 4, 9], [25, 12, 7, 2], [4, -8, -6, 8], [-12, -6, 12, 1], [-10, -8, 6, -3], [6, 6, 4, -10], [16, 8, -4, 2], [-11, 15, 9, -1], [9, 10, -3, -2], [-9, 8, 1, 7], [45, 8, -5, -6], [33, 8, -9, -1], [4, -4, -2, 11], [-4, 4, -16, 6], [-8, 10, -14, -4], [-3, -13, 7, -3], [-22, -4, -8, 6], [-2, 2, -8, 18], [-4, -2, 12, -7], [-3, -11, 9, -8], [27, -2, 5, 1], [-4, -8, -8, 0], [-1, 13, 3, -5], [7, 0, -25, 1], [18, 12, -10, 1], [13, -3, -1, 14], [17, 6, 7, 2], [-3, 11, 13, -6], [-17, 7, 1, 7], [-29, -1, -7, -2], [19, -7, -13, 3], [-16, 12, 20, -13], [45, -4, 11, 1], [41, 7, 5, -3], [13, 5, -3, -7], [1, 15, -9, 1], [-22, 2, 2, -12], [-49, -4, 1, -4], [14, 12, -18, 3], [-5, -2, 5, -17], [33, 0, 5, 0], [-17, 14, 7, -1], [-6, -6, -6, -6], [18, 10, -10, -8], [-22, 8, 18, -7], [9, 8, -25, 2], [-11, 2, 3, -17], [-23, 0, -3, 2], [-21, -7, -5, 6], [-6, -4, 6, -12], [17, -8, -11, -1], [7, -18, 7, -4], [-28, -12, -16, -6], [9, 4, -11, 2], [-2, -2, -2, 4], [1, -1, -15, -9], [8, 14, 10, -6], [21, 9, 15, -5], [41, -10, -1, 0], [-5, 12, -13, 2], [36, 10, 6, -6], [-9, -6, 15, -9], [-2, 6, -10, 9], [1, 16, -11, 6], [-14, 2, 8, 4], [-31, -6, 7, -6], [-3, 12, 1, 0], [-36, -8, -6, -2], [-34, 6, -2, 6], [10, -6, -8, -5], [-29, 2, -11, 9], [31, -16, -9, 1], [24, 10, -8, 4], [-4, -12, 0, -2], [-1, 8, -9, 2], [-20, -14, -2, 9], [11, 18, 13, 4], [-28, 12, 0, 6], [-15, 19, -21, 6], [42, 0, -10, -1], [29, -21, -11, 3], [-5, 11, -19, 4], [-8, 0, 16, 5], [-8, -10, 10, -8], [15, -16, -1, 0], [-54, -2, 6, -3], [-7, 2, 5, 3], [-7, -7, 1, -9], [8, -4, -4, 4], [8, -14, -22, 0], [-3, -9, -13, -5], [11, 6, 3, -2], [-36, 0, 10, 6], [22, 6, -2, 0], [27, -2, -5, 6], [6, 6, -2, 5], [-1, -9, 17, -11], [49, -8, 5, -1], [7, 19, -13, 0], [-1, -29, -3, -1], [-29, -3, 5, -8], [-49, -16, 9, 8], [-36, -6, 14, -5], [33, 4, -17, -4], [-23, -11, 17, -6], [17, -15, -21, 5], [-3, -21, -3, -2], [-39, 6, 15, -1], [-11, -2, -15, -10], [27, 18, -5, -11], [21, -1, -13, 7], [-35, -4, 11, 1], [3, 17, -13, -1], [-7, -9, -1, -7], [-29, -26, -3, 9], [14, 0, -12, 6], [-52, -10, -2, 4], [-2, 2, -10, -12], [-17, -5, 7, 2], [9, 18, 21, 0], [9, -10, -25, 1], [-3, -16, -7, 1], [13, 5, -7, -16], [-20, -20, -8, 0], [8, -20, 4, -8], [12, -6, -4, -12], [-13, -15, -9, 11], [-10, 0, 16, 1], [-42, 0, 8, 1], [19, 25, 9, -3], [15, -18, 17, 0], [4, 0, 16, -14], [25, -8, 7, 4], [29, 0, -7, -4], [7, 11, -1, -10], [-13, 7, 3, -13], [-35, -14, -5, 13], [0, -2, -6, 10], [8, -8, 2, -8], [44, -2, -14, -1], [15, 9, 13, -2], [-2, -8, 24, 2], [32, 12, -4, -5], [33, 17, -15, -3], [-13, 18, 21, -6], [24, -2, 16, 3], [-34, -2, -8, 11], [5, 19, 11, -13], [13, 8, 25, 5], [-9, -14, -9, -12], [35, 5, 9, 11], [-22, -8, 0, -2], [8, -30, -6, 2], [-39, -3, 3, -12], [-13, 12, -3, -2], [-13, 2, 19, 1], [1, -8, 15, 1], [30, 6, -8, -2], [3, 16, -21, -7], [-21, 0, 13, -7], [35, 15, -11, -14], [24, -20, 12, -6], [22, -10, 4, 6], [26, 4, -20, -7], [-17, -6, -15, 1], [1, 15, -11, -7], [34, 10, 2, -10], [-10, 0, -10, 5], [46, -2, 10, 8], [-8, -26, -6, 8], [-30, -2, 6, -9], [-27, 10, -7, 6], [-30, 0, 10, -15], [11, 19, -7, -1], [17, -11, -3, 4], [12, 8, -10, 2], [-19, 8, 9, -7], [5, 4, 1, -18], [-20, 8, 14, 0], [-42, -2, 14, -2], [14, 22, -20, -1], [-29, 6, 5, -10], [-8, -20, -16, 3], [23, 2, -15, 7], [-42, 12, 20, -4], [10, -18, 10, -4], [29, 1, -1, -12], [23, 3, -1, 8], [14, 28, 0, 3], [-9, 13, 9, -13], [46, -2, 6, 2], [-7, -13, -5, -1], [21, -9, -7, -2], [-3, -24, 11, 5], [-39, -10, 13, 11], [-35, 12, 3, 0], [13, -16, -15, 8], [0, 6, 10, 6], [-36, -2, 30, -3], [27, -8, -19, 11], [44, -10, -26, 16], [5, -4, 9, -6], [-47, -21, -5, 17], [-4, -14, 26, -15], [-29, -8, -13, -1], [30, 0, -10, -6], [0, 0, -4, 14], [21, 22, 9, -13], [-52, -2, -2, -4], [-1, -9, 1, -7], [29, 8, -5, -10], [19, 8, -37, 3], [-29, -22, -5, 16], [-29, 11, -7, 16], [3, -9, -15, 15], [10, 14, 0, 8], [29, 30, 3, -5], [-20, 6, 10, -7], [4, 2, -26, 18], [16, -8, -20, 2], [3, 4, 5, -14], [9, 6, 13, -17], [-15, 4, 5, 0], [-6, -10, 2, -6], [-20, -18, -10, -2], [1, 4, 7, -10], [8, 24, -4, 6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3776_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3776_2_a_be();".
// 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_3776_2_a_be(:prec:=4)
    chi := MakeCharacter_3776_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_3776_2_a_be();".
// 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_3776_2_a_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![4, -11, -5, 3, 1]>,<5,R![-2, -13, 1, 5, 1]>,<7,R![44, 39, -17, -3, 1]>,<11,R![32, -8, -16, 2, 1]>],Snew);
    return Vf;
end function;