
// Make newform 3776.2.a.x 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_x();".
// 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_x();".
// 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_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], [3], [-1], [-3], [0], [0], [2], [3], [6], [1], [6], [2], [7], [-6], [0], [7], [-1], [10], [12], [0], [0], [3], [0], [10], [-12], [-10], [-18], [15], [12], [-14], [3], [12], [11], [12], [-8], [18], [-4], [12], [-15], [8], [0], [-3], [-6], [-5], [26], [21], [-6], [-24], [-6], [-12], [-4], [-15], [21], [-3], [-31], [9], [-22], [3], [-21], [-17], [0], [-23], [21], [-3], [26], [-10], [15], [-30], [12], [-26], [22], [-9], [24], [-14], [-27], [-12], [-26], [16], [-10], [-30], [-18], [0], [6], [-29], [24], [-24], [1], [-24], [34], [-6], [0], [0], [21], [33], [3], [-12], [-20], [26], [-15], [42], [-12], [31], [-42], [-22], [30], [-7], [42], [-7], [-33], [28], [-3], [-2], [-47], [45], [24], [-34], [-9], [-27], [-13], [48], [-13], [26], [26], [30], [30], [16], [21], [36], [-12], [30], [-18], [-24], [42], [-39], [1], [32], [34], [0], [-28], [10], [-12], [-46], [6], [-48], [-27], [-30], [-19], [-32], [30], [-36], [-23], [20], [-27], [-12], [-9], [-15], [-36], [-16], [52], [10], [3], [50], [6], [45], [22], [-54], [42], [1], [0], [-34], [36], [-4], [-27], [42], [-45], [13], [-15], [-38], [24], [-1], [15], [-9], [6], [-5], [24], [-40], [48], [-24], [-18], [18], [48], [-54], [-18], [-14], [27], [2], [-58], [12], [34], [0], [-22], [-33], [6], [-6], [45], [-52], [-42], [6], [8], [24], [38], [-49], [-33], [21], [69], [28], [0], [-38], [-6], [62], [60], [-30], [44], [69], [-60], [26], [-49], [-54], [12], [-45], [-30], [0], [72], [-46], [36], [-63], [18], [16], [18], [-72], [-69], [-54], [21], [-7], [41], [0], [72], [-6], [69], [-9], [33], [-10], [-42], [33], [-67], [-24], [9], [-24], [10], [-38], [-60], [3], [-45], [-34], [13], [-24], [65], [8], [-21], [-71], [76], [60], [36], [9], [27], [-18], [-12], [19], [-34], [9], [24], [66], [30], [10], [-72], [-60], [66], [19], [-24], [-29], [8], [48], [34], [-42], [-55], [4], [-84], [17], [-48], [72], [13], [52], [-12], [30], [15], [-18], [21], [84], [72], [-38], [39], [-13], [-11], [30], [33], [42], [-6], [81], [-54], [-22], [-24], [-32], [31], [-9], [53], [-12], [48], [84], [42], [26], [-90], [38], [66], [-63], [-60], [-87], [29], [80], [36], [15], [-46], [64], [-10], [-6], [46], [-12], [0], [-27], [6], [64], [18], [-63], [5], [54], [86], [-82], [-72], [-9], [-91], [-3], [8], [91], [-81], [-84], [84], [-64], [22], [-15], [-70], [-36], [-90], [48], [22], [-24], [3], [-6], [96], [-56], [-76], [93], [53], [-92], [-72], [44], [9], [-48], [45], [-90], [-84], [-24], [0], [-22], [-30], [0], [30], [66], [-15], [-41], [-15], [-91], [-50], [-14], [-57], [-38], [-11], [30], [-78], [47], [78], [-60], [-37], [10], [0], [69], [63], [13], [60], [-60], [-68], [-81], [-2], [38], [0], [-93], [43], [-83], [36], [-10], [21], [36]];
    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_x();".
// 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_x(:prec:=1)
    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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>,<5,R![1, 1]>,<7,R![3, 1]>,<11,R![0, 1]>],Snew);
    return Vf;
end function;