
// Make newform 3776.2.a.bd 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_bd();".
// 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_bd();".
// 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_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], [1, -1, 0], [0, -1, -1], [-3, 2, -3], [0, 2, 0], [0, 0, 2], [5, -4, 4], [-2, 3, -1], [-4, 0, 2], [-3, 2, 1], [-6, 0, 0], [-2, -2, 4], [-1, 1, -2], [0, -2, 4], [-4, 4, 2], [1, 3, -2], [1, 0, 0], [12, 0, 2], [8, 2, -4], [-1, -8, 6], [-4, 10, -6], [3, -7, 8], [-2, -6, -4], [0, 2, 0], [8, -8, 10], [-10, 6, -14], [0, -10, 0], [-2, -1, -5], [-6, 8, -2], [6, 0, -2], [-10, 9, -15], [-6, 6, -4], [-11, 10, -7], [-1, -4, -2], [2, -8, -6], [6, 0, -6], [6, -8, -2], [-9, 4, -6], [-11, -2, -3], [4, 0, 2], [18, -4, 0], [3, -7, 6], [-2, 10, -2], [-12, 9, -11], [7, 8, -4], [-7, -13, 8], [-6, -2, -6], [3, -4, 2], [-6, 8, 0], [16, -4, 12], [-4, 8, -14], [-11, -2, -3], [7, -6, -5], [7, -6, 15], [-9, 18, -9], [-14, 11, 3], [-6, -12, 10], [-6, 9, -3], [8, -9, 3], [3, 1, 6], [0, -10, -2], [-3, 6, 13], [-25, -2, -1], [18, 7, 3], [2, -6, 18], [22, -12, 8], [-15, 7, 4], [-6, 20, 2], [6, -8, 18], [-4, 14, -12], [-10, 2, -4], [15, -7, 20], [10, -8, 20], [13, -12, 20], [-21, 2, -9], [12, -16, -4], [5, -8, 4], [0, 14, -2], [2, -2, -14], [6, -18, -6], [8, -6, 14], [-22, 6, -10], [18, -14, 16], [-3, -14, -7], [-25, 16, -22], [8, -30, 12], [-16, 15, -1], [2, 8, 2], [-2, -8, -16], [0, 2, -12], [8, 26, -10], [13, -12, 26], [1, -13, 8], [7, -15, -4], [5, -22, 21], [-16, 8, -18], [24, -10, 24], [-25, 4, -8], [11, 1, 20], [8, -6, -16], [24, -8, 4], [9, -17, 10], [16, 0, 10], [-20, 2, -12], [-24, 6, -12], [1, -1, -6], [14, -8, -16], [-12, 31, -13], [-17, -2, -5], [-4, 8, -4], [2, 19, -9], [-2, -10, 18], [-4, -13, -1], [3, -10, 15], [0, 8, 8], [9, 12, -8], [-26, 15, -17], [-10, 11, -1], [5, 3, 18], [10, -4, -8], [-13, 10, -5], [-12, -18, 10], [6, 20, 4], [-28, 30, -36], [-14, -12, -2], [-12, 8, -8], [-4, -3, -15], [-20, 6, -14], [20, -32, 24], [-23, -4, -8], [-10, 0, -10], [-7, -12, 6], [-4, 10, -4], [8, -23, 5], [-28, 3, 3], [-14, -22, 14], [-24, 12, -10], [24, 0, -12], [-14, 12, 0], [22, 0, -10], [-40, 10, -4], [-28, 14, -6], [6, -26, 12], [15, -12, 30], [17, -10, 33], [12, -22, -8], [19, 17, -10], [8, 18, -2], [24, -16, 16], [-14, -6, -20], [11, -7, -26], [14, -16, -22], [2, -11, -11], [2, -10, 26], [9, -18, 1], [-23, 14, -19], [-12, 22, 18], [28, -18, 28], [0, -10, 14], [16, -18, 14], [29, 2, 9], [-22, 0, -4], [-4, 4, 6], [3, 10, 23], [20, -12, 36], [-30, 26, -16], [12, 14, 8], [-1, 1, 6], [-18, 2, -32], [-24, -2, 8], [29, -12, -18], [2, -6, 2], [-46, 7, -17], [20, -26, -2], [-26, -11, -7], [9, -29, -2], [-21, 21, 8], [-10, 20, -32], [-9, 40, -10], [-45, 14, -5], [-13, 9, -4], [-30, 23, -9], [-28, 10, 6], [-37, 9, -22], [-31, -16, -2], [0, 8, -6], [-34, 26, -30], [-8, 0, 20], [16, -36, -6], [0, 14, -10], [-18, 24, 2], [14, 24, -22], [-12, 4, 2], [5, -16, 0], [46, -17, 7], [32, -6, 20], [3, 32, -8], [-10, -12, -6], [6, 4, 0], [-6, -38, 18], [17, -4, 0], [15, 6, 27], [-1, 44, -20], [0, 10, -16], [3, -15, 12], [10, -6, -16], [-36, 24, -32], [0, 36, -4], [14, 16, 20], [4, 0, 40], [-14, -12, -8], [-15, -9, 26], [27, -22, 39], [-13, 6, -33], [1, 23, -16], [14, 0, -10], [-7, -16, 10], [5, 8, -20], [-6, -18, -20], [-21, 40, -40], [18, -26, 24], [-48, 4, -8], [-12, -18, 20], [-34, 23, 3], [24, -14, -2], [14, -16, -30], [20, 13, 21], [8, 2, 12], [22, -34, -8], [-10, 7, -17], [-40, 14, 18], [10, -40, 22], [-22, 6, -12], [26, -8, 30], [-46, 0, 0], [1, -5, -8], [-12, -16, 2], [22, -28, -4], [-20, 6, -4], [28, -8, 4], [29, -26, -19], [-20, -10, 14], [-2, -1, -33], [20, 5, -3], [-13, 30, 11], [-9, 44, -22], [-26, 4, -14], [-24, -32, 10], [-9, 5, 0], [10, -35, 25], [-7, 26, 9], [-40, 14, -28], [-42, 16, 2], [45, -17, 50], [-17, 57, -22], [-4, -24, 20], [53, -22, 41], [-28, 30, 26], [2, -6, 26], [-29, 32, 16], [-32, -24, 16], [-7, -13, 16], [1, 39, -26], [3, 16, 8], [-17, 14, -41], [-60, 28, -46], [4, 17, -19], [-18, -4, 16], [-11, 19, 12], [48, -11, 21], [60, -28, 28], [-25, 28, -2], [30, -44, 26], [-3, -17, 28], [-16, 33, -43], [40, -18, -22], [33, -4, 14], [-29, 18, -1], [2, 54, -24], [15, -19, 0], [36, -8, -4], [-34, 6, 2], [54, -32, 46], [-10, 4, -22], [38, 6, 0], [-6, -2, -28], [40, -24, 30], [-13, -26, -9], [26, -32, 18], [-39, 18, -15], [-26, 42, 0], [1, -8, 30], [9, 0, 36], [-60, 26, -44], [-27, 22, -43], [28, 16, -18], [-27, 20, 34], [-16, 5, 17], [14, -26, 20], [-12, 14, 4], [11, -30, 39], [16, -4, -20], [-30, -30, 10], [16, -20, 30], [-34, 15, -5], [32, -2, 12], [30, -11, -11], [-38, -4, -28], [32, -34, -4], [-10, -20, 4], [15, 1, 8], [-48, 27, -25], [20, -5, 3], [-30, 20, -30], [13, 19, -16], [-34, 4, -8], [2, 6, 24], [46, -17, 27], [-19, 20, -44], [17, 36, 4], [12, 12, 28], [22, -14, -4], [8, 55, -17], [39, 1, -4], [-31, 7, 6], [-32, 40, -14], [-38, 30, -30], [47, -16, 22], [-6, 14, -40], [32, 28, -12], [-28, 24, -30], [8, -12, 8], [-22, 42, -38], [-1, 10, -33], [-23, 12, -14], [7, 49, -24], [24, -47, 9], [-30, 42, -54], [0, 6, 30], [-33, 17, 12], [14, -60, 36], [54, -10, -12], [-18, 8, -20], [8, 8, 8], [10, 28, 6], [-24, -44, 20], [26, -20, -12], [54, -19, 25], [-20, 30, 0], [68, -2, 2], [24, -44, -8], [-25, -2, 11], [15, -39, 46], [-36, 20, -34], [-17, 28, -12], [-8, -28, -20], [4, 0, 14], [-27, 34, 5], [-31, 7, 22], [-63, 3, -12], [-30, -6, 0], [-63, 22, -7], [3, -34, 19], [-16, 8, 28], [-48, 40, -24], [74, -18, 24], [26, -32, -4], [-43, -10, -23], [58, -22, 42], [25, -28, 46], [36, 8, 36], [12, 10, -18], [-29, 20, -36], [22, 42, -16], [-5, 42, -33], [-26, 22, 40], [18, -50, 30], [8, 14, 18], [10, -6, 28], [8, -5, 27], [-15, -10, 17], [46, 24, -2], [44, -20, 40], [-46, -28, 14], [-18, 25, -43], [-36, 46, -58], [-67, 14, -7], [31, -32, -32], [5, 36, -2], [68, -28, 6], [10, -28, 52], [8, -32, 38], [-40, 8, 4], [38, 26, -12], [38, -16, 18], [0, -20, 18], [-27, 19, 8], [-59, 26, -59], [15, -10, 7], [53, -46, 21], [14, 20, -24], [44, -6, -22], [3, -47, 0], [57, -4, 0], [-33, -11, -14], [-10, 14, -28], [24, 20, -20], [24, -27, 33], [-32, -42, 16], [35, 0, -14], [20, 13, -35], [-30, 44, -20], [-58, 14, 4], [63, -26, 35], [-55, -22, 1], [3, -23, -14], [2, -30, -28], [-50, 52, -28], [58, 14, 14], [19, 5, -16], [-30, 24, -50], [-7, 40, 8], [-36, 36, -56], [57, -33, 64], [57, -22, 25], [-61, 1, 2], [50, -22, -10], [6, 40, -32], [31, -22, 3], [13, 56, -26]];
    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_bd();".
// 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_bd(:prec:=3)
    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_bd();".
// 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_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, -1, -2, 1]>,<5,R![7, -7, 0, 1]>,<7,R![-43, -11, 4, 1]>,<11,R![8, -8, -2, 1]>],Snew);
    return Vf;
end function;