
// Make newform 1776.2.a.g in Magma, downloaded from the LMFDB on 29 April 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_g();".
// 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_g();".
// 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_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], [1], [-4], [1], [3], [-5], [7], [-5], [-1], [-8], [-6], [1], [-2], [-12], [2], [-1], [4], [14], [-14], [-4], [-11], [-10], [-5], [-9], [-10], [10], [10], [-15], [-7], [6], [-13], [18], [12], [-2], [-6], [19], [20], [-7], [-3], [1], [0], [16], [-21], [-2], [5], [12], [4], [8], [12], [0], [14], [-24], [-16], [10], [-1], [-6], [1], [-24], [-19], [19], [-11], [7], [4], [24], [10], [18], [12], [5], [-18], [18], [14], [-30], [-23], [4], [-24], [1], [-10], [20], [-25], [-14], [-39], [6], [-3], [7], [34], [-12], [26], [32], [6], [30], [22], [21], [-2], [-41], [-31], [0], [11], [-22], [-16], [-25], [33], [2], [8], [41], [44], [34], [-16], [12], [30], [-49], [-42], [-14], [12], [46], [-16], [16], [23], [7], [-36], [-8], [-21], [13], [-27], [-6], [-28], [16], [-29], [-12], [-16], [18], [10], [12], [-32], [-7], [-6], [-24], [-11], [-42], [-40], [39], [40], [-45], [23], [18], [-11], [-16], [-17], [33], [41], [-34], [-2], [-48], [13], [42], [-19], [24], [-22], [-30], [-26], [54], [14], [-12], [-52], [28], [23], [30], [4], [33], [-46], [16], [8], [-22], [-32], [-27], [-41], [42], [16], [-41], [-16], [44], [8], [-60], [3], [6], [42], [25], [14], [-37], [26], [4], [-26], [-16], [47], [-39], [36], [-68], [0], [50], [54], [-51], [-34], [-21], [16], [-18], [12], [-18], [-21], [-15], [-65], [-26], [-2], [0], [32], [-3], [-21], [-35], [34], [-10], [-45], [21], [74], [-49], [-6], [-10], [-32], [-49], [6], [-44], [48], [36], [34], [34], [-51], [-18], [-54], [62], [-35], [4], [-30], [36], [32], [11], [-13], [11], [54], [-45], [-42], [-6], [-46], [61], [7], [38], [10], [34], [64], [56], [-14], [-16], [23], [-72], [68], [0], [-44], [44], [3], [0], [37], [-30], [64], [78], [7], [-83], [-14], [52], [35], [23], [-9], [-34], [43], [-72], [-2], [32], [-6], [-44], [52], [-40], [12], [-62], [8], [75], [76], [28], [-12], [-59], [-10], [42], [3], [-21], [76], [-44], [-50], [18], [40], [-56], [53], [38], [-38], [-14], [-24], [-17], [-84], [35], [8], [58], [77], [22], [-11], [-75], [6], [13], [-39], [77], [-42], [85], [84], [0], [-46], [4], [-47], [90], [-18], [-60], [-28], [22], [-47], [72], [-68], [-38], [32], [-60], [14], [88], [-30], [2], [-84], [54], [36], [-36], [-68], [46], [22], [27], [24], [-44], [52], [-26], [-65], [36], [48], [60], [-42], [-8], [-31], [6], [38], [-4], [-72], [-54], [32], [40], [-76], [-30], [-71], [2], [20], [-73], [16], [-51], [45], [-27], [-66], [-21], [-56], [-96], [56], [-48], [-25], [22], [76], [69], [49], [46], [-6], [-63], [8], [-19], [-70], [20], [-50], [-53], [-56], [27], [-12], [18], [-42], [-53], [-19], [-60], [-24], [36], [-77], [-17], [-6], [-51], [-84], [15], [84], [-13], [-42], [0], [-88], [59], [62], [15], [-35], [38], [85], [86], [-2], [0]];
    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_g();".
// 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_g(:prec:=1)
    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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![4, 1]>,<7,R![-1, 1]>,<11,R![-3, 1]>],Snew);
    return Vf;
end function;