
// Make newform 3776.2.a.j 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_j();".
// 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_j();".
// 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], [-1], [1], [-1], [4], [-2], [2], [3], [-6], [-5], [-4], [6], [3], [8], [2], [-11], [1], [0], [-8], [8], [-6], [1], [6], [-16], [-10], [-2], [6], [3], [-10], [8], [-7], [-10], [-9], [-16], [-12], [10], [4], [16], [-21], [-6], [-16], [11], [-10], [27], [2], [-17], [4], [0], [-8], [4], [6], [-21], [-15], [-15], [-11], [15], [-8], [21], [-27], [15], [4], [-29], [-7], [-5], [-28], [14], [7], [-2], [18], [20], [6], [-3], [-10], [14], [-11], [8], [38], [8], [-18], [-22], [-30], [28], [-36], [-29], [8], [-24], [-15], [-34], [30], [-34], [18], [0], [3], [-3], [-21], [30], [44], [-18], [25], [-18], [12], [33], [18], [0], [26], [37], [44], [37], [25], [0], [7], [-16], [1], [9], [-16], [46], [-49], [-9], [1], [18], [-35], [20], [22], [-2], [10], [-20], [23], [6], [52], [14], [22], [36], [-46], [-49], [5], [28], [20], [40], [22], [0], [38], [56], [20], [36], [-53], [44], [11], [18], [-38], [-6], [43], [-6], [-19], [42], [-33], [-45], [-50], [-44], [30], [-30], [-33], [18], [-20], [-55], [38], [18], [-10], [11], [-46], [-18], [36], [14], [27], [-26], [-47], [25], [-11], [24], [-56], [45], [21], [-33], [-54], [39], [48], [-28], [-32], [-26], [-4], [44], [50], [-6], [56], [30], [-45], [-38], [-34], [-50], [-54], [-30], [54], [61], [2], [-56], [33], [8], [56], [-20], [56], [36], [-44], [-47], [49], [25], [19], [58], [-32], [2], [-48], [-46], [-44], [12], [52], [-1], [36], [-52], [-9], [-12], [-28], [23], [-38], [6], [16], [-16], [-26], [-69], [28], [26], [4], [-64], [-9], [68], [59], [-17], [-19], [-60], [72], [40], [-51], [-27], [27], [-42], [-10], [-51], [-61], [-20], [39], [-16], [52], [-6], [38], [39], [-23], [-30], [49], [38], [-25], [-60], [-13], [-1], [-52], [-20], [-62], [47], [-57], [14], [-4], [-7], [-4], [-3], [48], [26], [12], [-60], [-4], [-18], [34], [-35], [-30], [75], [-2], [-32], [54], [12], [-53], [-60], [56], [35], [-74], [34], [85], [36], [-50], [42], [-61], [-16], [-23], [0], [-42], [34], [53], [-51], [-23], [12], [-9], [-32], [76], [55], [-18], [46], [-44], [-4], [69], [13], [-79], [44], [80], [-20], [-86], [12], [-32], [-72], [0], [53], [12], [33], [51], [-4], [-18], [73], [26], [44], [-60], [-70], [18], [22], [-46], [-83], [-60], [-78], [88], [13], [-53], [80], [-10], [-62], [28], [-17], [-11], [15], [32], [15], [-95], [44], [-76], [-64], [0], [-17], [-76], [-4], [12], [8], [42], [-66], [29], [16], [66], [56], [44], [-19], [31], [-48], [-68], [98], [41], [-18], [-5], [58], [-48], [-20], [-72], [-8], [-16], [-76], [24], [-78], [67], [-13], [5], [15], [34], [0], [5], [-6], [31], [52], [-28], [-13], [34], [44], [-53], [-2], [50], [81], [11], [19], [-24], [-34], [24], [29], [-16], [-10], [104], [59], [-5], [7], [48], [-54], [-67], [-32]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : 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]>,<5,R![-1, 1]>,<7,R![1, 1]>,<11,R![-4, 1]>],Snew);
    return Vf;
end function;