
// Make newform 3776.2.a.ba 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_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_3776_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, -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, 0, -1], [1, -1, 2], [0, 3, -1], [0, 0, 2], [-2, 2, -2], [1, 4, 0], [1, 1, 2], [6, -2, 2], [-4, 1, -3], [6, 0, 0], [-6, 4, -2], [1, -2, 1], [4, -4, 2], [6, -2, 6], [3, -2, -1], [-1, 0, 0], [10, 2, -2], [-12, 4, -2], [7, -6, -2], [2, -6, -4], [5, -8, 1], [-2, 4, -10], [0, 0, -2], [-2, 10, -2], [4, -14, 8], [0, 0, -10], [-3, 5, -6], [-4, -2, -6], [8, -2, 2], [-5, 15, -6], [2, 4, 2], [-4, -7, -3], [-1, 2, -6], [8, -6, 14], [-12, 6, -6], [8, -2, 10], [3, 6, -2], [8, 3, -5], [2, 2, -2], [-18, 0, -4], [-3, 6, 1], [0, 2, 8], [-1, -11, 2], [11, -4, -4], [15, -8, -5], [0, 6, -8], [-1, -2, -2], [6, 0, 8], [4, 12, -8], [10, -14, 6], [8, 3, -5], [12, -5, 11], [8, -15, 9], [0, -9, -9], [17, -3, 14], [-16, 10, 2], [3, 3, 6], [5, 3, 6], [-3, 6, -7], [-2, 2, -12], [-16, 13, -19], [24, 1, -3], [-15, -3, 10], [-16, 18, -12], [14, 8, 4], [19, -4, 11], [-8, 2, -22], [12, -18, 10], [8, -12, -2], [-6, -4, 2], [5, -20, 13], [10, -20, 12], [-7, 20, -8], [12, 9, -7], [-16, 4, -20], [1, 4, 4], [2, -2, -12], [16, -14, 16], [12, -6, 24], [6, -14, 8], [-12, -10, 4], [-2, -16, 2], [4, -7, 21], [3, 22, -6], [4, -12, -18], [-15, -1, -14], [0, 2, -10], [14, -16, 24], [-12, 12, -10], [-18, 10, 16], [13, -26, 14], [7, -8, -5], [-11, 4, -19], [16, -21, -1], [-2, 18, -10], [0, 24, -14], [-17, -8, 4], [9, -20, 21], [24, -16, 22], [-20, -4, -4], [-1, 10, 7], [-6, -10, 10], [-8, -12, 10], [12, 12, -6], [7, -6, 7], [-30, 16, -24], [1, -13, -18], [12, 5, -7], [0, -4, -4], [-11, 9, 10], [-20, 18, -8], [-3, -1, 14], [12, -15, 5], [8, -8, 16], [17, -8, -4], [9, 17, -2], [9, 1, 10], [-13, 18, -21], [-18, 8, -12], [-8, -5, -5], [-22, 10, 8], [2, 4, -24], [-8, 36, -6], [12, 2, -14], [-4, -8, 0], [11, -15, 18], [6, 14, -8], [4, -24, -8], [-15, -8, 12], [0, 10, -10], [13, -6, -6], [0, 4, 6], [3, 5, 18], [-31, 3, -6], [-28, 14, 8], [-14, -10, -2], [-36, 12, -12], [-14, 0, -12], [32, -10, 10], [36, 4, 6], [-22, -6, -8], [6, -12, -14], [15, -30, 18], [-16, 33, -23], [-20, 8, -30], [29, -10, -7], [10, -2, -16], [-8, -16, 0], [-6, 20, -26], [37, -26, 33], [36, -22, 38], [-13, 11, -22], [24, -26, 16], [-8, -1, -17], [4, 19, -5], [30, -18, 40], [0, 28, -10], [-14, 14, -4], [2, 14, 4], [-20, -9, 11], [-18, -4, 4], [10, -6, 10], [20, -23, 33], [-16, 36, -24], [14, 16, 10], [-4, -8, 22], [-7, 6, -7], [14, -32, 30], [-32, 8, -6], [-47, 18, -30], [0, 2, 4], [29, 17, -10], [22, -2, 28], [19, 7, -18], [11, -2, 31], [29, -8, 29], [22, -32, 12], [-1, 10, 30], [-40, -5, -9], [9, 4, 5], [21, 9, 14], [-34, 6, -16], [-15, -22, 13], [29, 2, -18], [6, -6, -2], [-4, -30, 4], [28, -20, 20], [22, -6, 42], [-10, 10, 4], [-20, 2, -26], [-36, 22, 2], [14, -2, 6], [5, 0, 16], [-39, -7, -10], [12, 20, -14], [11, -8, -24], [-4, -6, 18], [6, 0, -4], [24, -18, -20], [17, 0, 4], [12, -27, 33], [19, -20, -24], [16, -16, 6], [9, -12, -3], [26, -16, 22], [4, 32, -8], [-4, 4, 32], [-6, 20, -36], [36, -40, 40], [-6, -8, 20], [-41, 26, -17], [12, -39, 17], [-20, 33, -27], [-17, 16, 7], [24, -10, 10], [17, -10, -6], [25, -20, 12], [-14, 20, -38], [19, -40, 0], [-6, 24, 2], [40, 8, -4], [-32, 20, -2], [37, -3, 26], [-26, 2, -16], [44, -30, 46], [-1, 21, -34], [4, -12, 14], [-30, 8, -42], [-7, 17, -10], [-58, 18, -32], [12, -22, -18], [10, 12, -6], [-4, 30, -22], [46, 0, 0], [-9, 8, -13], [-14, 2, 14], [26, -4, 32], [16, 4, 2], [-24, -4, -4], [-48, 19, -45], [34, -14, 4], [-31, 33, -34], [23, -3, -2], [-24, 11, -41], [-13, 22, 22], [12, 14, -10], [34, -10, -22], [9, 0, 5], [15, -25, -10], [-16, 9, -35], [-12, -28, 14], [44, -2, 18], [-5, 50, -33], [5, -22, -35], [24, -20, -4], [12, 41, -19], [54, -26, 56], [-24, 26, -20], [-45, 16, -48], [48, -16, -8], [23, -16, 3], [27, -26, -13], [-5, 8, -24], [24, -41, 27], [14, 46, -18], [23, -19, 2], [-34, 16, -12], [23, -12, 31], [27, 21, -10], [32, 28, 0], [23, 2, 26], [4, 26, 18], [31, -28, 11], [27, -43, 10], [-62, 22, -40], [-19, -14, 10], [-28, -1, -17], [26, -24, -30], [-15, 0, -19], [-40, 4, -12], [36, -2, 8], [-8, -46, 14], [12, -22, 18], [-38, 0, 6], [-22, 28, -30], [10, 30, -6], [-4, -9, 35], [-8, -18, -14], [-24, -15, -3], [-26, 0, -42], [29, -30, 22], [-27, 36, -36], [16, 44, -18], [16, -43, 21], [46, -18, 2], [61, -34, 54], [-33, 17, -22], [6, -20, -6], [16, -4, 18], [-28, 39, -9], [36, -20, 24], [40, -10, -20], [14, -30, 10], [29, 5, 10], [20, 12, -10], [-41, 11, -22], [-10, -28, 32], [-36, 4, -38], [-14, 4, 16], [-7, -8, 9], [-23, -25, -2], [17, 3, 2], [0, 30, -10], [-29, 16, 3], [-26, -8, 4], [22, -24, 30], [-19, -27, 10], [25, -44, 24], [13, 4, -40], [16, -28, 40], [26, -4, 18], [25, -17, -38], [-43, 4, -3], [-37, 6, -13], [-18, -14, -26], [8, 30, 0], [-25, -22, 6], [-34, 40, -26], [44, -12, -16], [2, -30, 6], [0, 8, 4], [-16, 38, 4], [-32, 33, -23], [9, 14, -2], [-31, 24, 25], [15, 9, 38], [24, -54, 12], [-30, 30, -36], [45, -12, 29], [-22, 36, 24], [66, -12, 22], [2, -20, 12], [0, -8, 16], [4, 6, -34], [44, -20, -24], [38, -12, 32], [-29, -25, 6], [20, 0, 30], [66, 2, 0], [-32, 8, -52], [-36, 11, -9], [-31, 46, -7], [2, 34, -14], [-5, -12, -16], [12, -20, 48], [10, -14, 14], [32, -5, 39], [-53, 22, -29], [51, 12, -9], [-30, 0, 6], [-56, -7, -15], [16, -19, -15], [44, -28, 36], [24, 24, 16], [50, 24, -6], [30, -4, 36], [20, 23, -33], [16, 42, -20], [21, -46, 18], [0, -36, 44], [-30, 18, -8], [7, -36, 16], [-38, 16, 26], [28, -33, -9], [66, -40, 62], [12, -30, -20], [-10, 18, -32], [-18, 28, -22], [-19, 27, -22], [-32, 17, -7], [48, -2, -22], [-4, -40, 20], [-60, 14, 14], [-25, 43, -18], [-22, 58, -12], [60, 7, 7], [63, -32, 64], [-7, 2, 34], [-62, -6, -22], [-42, 52, -24], [-30, 38, -6], [44, -4, 12], [-50, 12, 14], [-20, -18, 2], [-18, 18, 2], [35, -8, 27], [0, -59, 33], [-8, -7, -3], [32, 21, 25], [38, -24, 4], [66, -22, 28], [-3, 0, -47], [57, 0, 4], [-19, -14, 25], [-18, 28, -14], [44, -20, 0], [-9, 33, -6], [48, -16, -26], [-49, 14, -14], [55, -35, 22], [-10, -20, -24], [62, -4, 18], [-28, -35, 9], [-56, 1, 21], [17, -14, 37], [-30, 28, -58], [22, 28, 24], [44, 14, -28], [-35, 16, -11], [20, -50, 26], [-15, 8, -48], [-20, 56, -20], [7, -64, 31], [32, 25, -3], [-63, 2, -3], [-60, 10, -32], [38, -32, -8], [-28, -3, -19], [-39, 26, 30]];
    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_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_3776_2_a_ba(: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_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_3776_2_a_ba( : 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;