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