
// Make newform 1776.2.a.q in Magma, downloaded from the LMFDB on 18 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1776_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_1776_2_a_q();".
// 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_1776_2_a_q();".
// 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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1776_a();"
function MakeCharacter_1776_a()
    N := 1776;
    order := 1;
    char_gens := [223, 1333, 593, 1297];
    v := [1, 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_1776_a_Hecke( : Kf := Kf)
    return MakeCharacter_1776_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], [1, 0], [1, 1], [2, 0], [2, 2], [0, -2], [-1, -1], [2, -2], [3, 1], [-1, 3], [4, 0], [-1, 0], [-2, 0], [4, -4], [0, -4], [0, -6], [-3, -1], [-2, -4], [6, 0], [-4, 0], [-2, 2], [6, 2], [6, 2], [3, 3], [-8, -6], [10, -4], [10, 2], [-8, -4], [4, 6], [-1, 7], [8, -8], [-9, -3], [-8, -6], [-2, 4], [18, 0], [0, 8], [-2, 2], [-8, 0], [-9, 1], [0, 10], [-5, 5], [10, -2], [-9, -7], [2, 0], [-2, 4], [-4, -4], [0, 12], [8, -8], [-3, 3], [10, 0], [-14, 0], [-1, 13], [0, -2], [-5, -11], [-9, -9], [14, 10], [-6, -12], [6, 8], [0, 10], [-17, 7], [-14, -6], [12, -2], [28, 0], [-21, 1], [-6, -8], [-16, -2], [-14, -6], [-18, 8], [-7, -13], [-2, 6], [-15, -3], [-14, -10], [-8, 8], [22, -2], [14, 8], [-27, -5], [3, 15], [14, 2], [-1, 7], [-12, -14], [-2, 6], [-4, 6], [-13, 1], [6, -6], [-4, 4], [16, 8], [-7, 13], [-24, -10], [-21, -9], [4, 4], [33, -5], [3, -3], [2, 10], [-18, 10], [-4, 0], [5, -5], [-24, -2], [10, 8], [-12, 12], [24, 10], [20, 12], [-31, 1], [31, -7], [-17, 7], [6, 8], [-22, -4], [3, 13], [30, -4], [24, 8], [-2, 14], [-14, -10], [14, -16], [-24, -14], [-20, -16], [-14, -14], [10, -12], [-14, 10], [-15, 7], [1, -7], [18, -14], [18, 0], [38, 6], [-12, 10], [33, -5], [2, 12], [9, 1], [-12, -18], [14, -2], [8, 12], [-2, 0], [0, -20], [-10, -18], [30, -4], [-20, -10], [36, -6], [-34, 8], [22, 4], [-36, 8], [-15, 9], [17, -19], [-6, 0], [20, -6], [0, 8], [-21, 13], [32, -6], [18, -10], [-10, 8], [23, 15], [8, 16], [6, 6], [14, 18], [12, 2], [22, -10], [-2, 18], [8, -12], [9, 7], [14, 10], [6, -24], [-10, 8], [8, -18], [43, -3], [-16, -10], [-28, -4], [2, -2], [31, -9], [-18, 14], [52, 4], [-18, -4], [26, -4], [3, -17], [21, -13], [-10, 8], [-1, 17], [38, 0], [10, -8], [27, 11], [-14, 18], [6, -12], [16, 0], [6, 32], [26, 10], [11, -19], [-48, -6], [-13, 19], [30, -14], [8, 26], [14, -20], [2, 22], [-52, 2], [16, -28], [8, 30], [48, 4], [36, -8], [28, 2], [-8, 24], [8, 18], [-2, 32], [-52, 2], [-6, 12], [9, -13], [19, -17], [-20, 4], [-46, 0], [6, -22], [8, 12], [-39, -7], [38, -8], [12, -12], [-39, -3], [-6, -4], [-38, -16], [41, -7], [22, -18], [-58, 2], [-15, 11], [14, 14], [22, -14], [-3, -15], [1, -5], [-24, 22], [-50, -2], [28, 20], [-26, -16], [-24, -20], [-6, -26], [-14, 28], [4, -6], [-38, 14], [22, -8], [45, -9], [-26, 6], [52, 8], [-40, -8], [64, -6], [4, 0], [38, -2], [34, 4], [37, 13], [15, 5], [-33, -3], [39, -19], [-16, -12], [-26, 0], [-6, 24], [32, -26], [-21, 5], [40, -8], [-35, 19], [-30, 4], [13, 27], [-4, 18], [12, -6], [-22, -18], [32, 18], [-51, -3], [34, 22], [34, 6], [-30, 20], [-4, 14], [-22, 28], [0, 24], [-9, -11], [-38, 12], [26, 16], [33, 5], [-26, 8], [12, -10], [-37, -5], [-22, 28], [-3, 5], [6, 24], [18, -10], [40, -14], [22, 10], [-10, 12], [20, 4], [0, 12], [26, -20], [42, -16], [13, 19], [-18, 14], [-6, 2], [-50, -14], [-14, 16], [-34, 6], [2, 2], [8, 6], [-18, -16], [10, -10], [-23, 13], [17, 9], [-25, 25], [-48, 2], [2, -34], [22, -26], [14, 32], [-10, 12], [-40, -18], [21, -25], [-6, -8], [66, -8], [-20, 34], [18, 4], [-17, -15], [-20, -4], [-4, 6], [-43, 15], [-44, 2], [48, 20], [18, 8], [-36, 0], [56, -6], [-36, 6], [-10, -28], [-27, -9], [36, 2], [-54, 14], [-3, 3], [26, 28], [-7, 29], [60, -16], [26, 8], [17, 1], [-50, -12], [44, -10], [16, 34], [16, 20], [-4, -28], [-53, -19], [-2, 20], [66, 14], [-9, 35], [10, -34], [11, -27], [28, -20], [-52, -16], [22, 22], [2, 4], [-56, -22], [-54, -20], [22, 24], [-74, -12], [-21, -33], [-50, 22], [-51, -3], [21, 35], [-54, 6], [50, 4], [-21, -19], [-70, 0], [-32, 12], [70, 8], [35, 7], [-8, 0], [34, 0], [-44, -22], [39, -15], [23, 37], [6, -16], [9, -25], [14, -44], [40, -6], [15, -3], [-19, -41], [20, 32], [-38, 12], [-3, -3], [58, -18], [2, -12], [53, -5], [70, -14], [14, -22], [6, -28], [-10, -30], [10, 6], [24, -8], [40, 0], [70, 10], [17, -27], [6, 20], [-77, -9], [15, -25], [40, -12], [-20, 18], [8, -28], [10, -30], [20, 44], [-4, 46], [-26, 18], [-7, 19], [22, 26], [17, 33], [1, -33], [50, -2], [52, -8], [2, 10], [8, 20], [28, 38], [-52, 0], [6, 24], [78, 6], [-1, 23], [44, -24], [-67, -15], [57, 1], [44, -12], [-12, -6], [-46, 16], [-22, 36], [-34, 26], [70, -18], [-6, -36], [-7, 47], [-2, 42], [28, 10], [-20, 2], [36, 8], [-26, -36], [-48, -34], [-21, 29], [61, -3], [30, -28], [20, -32], [24, 4], [6, 56], [50, 4], [6, -46], [-40, -34], [4, -16], [-3, 31]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1776_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1776_2_a_q();".
// 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_1776_2_a_q(:prec:=2)
    chi := MakeCharacter_1776_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_1776_2_a_q();".
// 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_1776_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, -2, 1]>,<7,R![-2, 1]>,<11,R![-8, -4, 1]>],Snew);
    return Vf;
end function;