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