
// Make newform 2976.2.a.r in Magma, downloaded from the LMFDB on 15 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_2976_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_2976_2_a_r();".
// 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_2976_2_a_r();".
// 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 := [-2, -8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-5, -2, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_2976_a();"
function MakeCharacter_2976_a()
    N := 2976;
    order := 1;
    char_gens := [2047, 1861, 1985, 1057];
    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_2976_a_Hecke( : Kf := Kf)
    return MakeCharacter_2976_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, 0], [1, 0, 0], [1, -1, 0], [-1, -1, 0], [1, -1, -1], [-1, -1, -1], [0, 0, 0], [5, 1, 0], [1, -1, 1], [-1, 1, -1], [1, 0, 0], [-1, -1, 1], [-1, 1, 0], [3, -3, -1], [4, 2, 2], [2, 2, 2], [-2, -2, 1], [0, -2, 0], [8, 0, 0], [4, 0, -1], [3, -1, 1], [0, 4, 2], [2, 2, 0], [4, -4, -2], [0, 0, 1], [1, 3, -2], [1, 1, -2], [0, 0, -1], [-6, 2, -1], [3, 1, 0], [1, 3, -3], [-2, 0, -4], [1, -1, 3], [7, 1, -1], [-6, 0, -2], [1, 3, 1], [-14, -2, -3], [3, -5, 0], [1, 3, 1], [-10, -4, 0], [8, 4, 4], [-10, 4, 2], [8, 4, -1], [-12, 0, 3], [5, -1, 3], [1, 3, 5], [-1, -5, -2], [-15, -1, 3], [6, 0, 2], [-13, -1, 1], [5, -1, -2], [10, -6, -4], [5, -3, -1], [7, -3, -3], [7, 5, 4], [6, 6, -2], [-1, 9, 1], [0, 4, 2], [-16, 6, 2], [23, 1, 2], [-6, -2, 0], [-8, -6, -2], [-9, -5, -4], [6, -6, 3], [14, -8, -2], [-3, -1, -6], [-4, -4, -6], [-10, 0, 0], [-21, -3, 3], [-14, -4, 2], [11, -3, -3], [-4, 4, 1], [-4, 8, 6], [-16, 12, 3], [6, 6, 2], [10, -2, 4], [13, -13, -5], [-12, 0, -5], [-1, 9, 3], [11, 3, -1], [2, 10, 3], [-4, 4, 1], [8, 2, 2], [0, 10, 2], [-1, -9, -2], [-8, 12, 1], [11, 5, -1], [21, 1, -3], [16, 0, 6], [-12, 0, -6], [-2, 10, 1], [8, -4, -5], [-7, -1, -1], [-17, 5, 3], [10, 6, 0], [-10, 14, 3], [3, 9, -1], [10, -4, -6], [-13, 9, 5], [-6, -6, -3], [-9, 7, -2], [21, -5, 3], [-6, -2, -3], [0, 4, 8], [-7, 11, 7], [-12, -2, 4], [-8, -8, 4], [17, -5, 4], [-12, 4, 1], [1, 5, 7], [-6, 2, 4], [12, 6, -6], [-12, 6, 6], [-16, 8, -2], [-6, -6, 4], [-18, 2, 6], [-10, -6, -4], [-15, -1, -3], [14, -16, 0], [16, -4, 3], [-12, 0, -5], [-1, -1, -3], [-3, 7, 5], [-10, -6, -7], [3, 3, 8], [9, -13, -4], [6, -12, -6], [10, 6, -8], [-11, 1, 2], [30, 6, 1], [3, -11, -1], [21, -17, -1], [-27, 9, 0], [-21, 7, -3], [17, 7, -7], [-18, 2, 3], [-7, 3, -3], [-18, -6, -4], [10, 6, -6], [-7, -1, -1], [18, 10, -4], [-8, 8, 2], [16, 8, 8], [-19, -9, 5], [16, 6, 10], [-10, 4, 2], [4, 10, 4], [20, -6, -2], [13, -1, 7], [-18, -10, 0], [10, -6, 3], [-24, 4, 4], [22, -2, 6], [2, -6, 3], [25, 5, 0], [-3, 7, 3], [16, -16, 0], [-1, -7, -7], [-14, 16, -2], [10, -6, -8], [19, -7, 5], [46, -6, -2], [-5, -3, 5], [18, -4, -8], [-29, -7, 6], [1, 11, -1], [-4, 4, 8], [8, -8, 1], [-31, -3, 5], [-44, 8, 0], [-19, 11, -3], [10, 12, -10], [-22, -4, -10], [2, 10, 13], [-15, 1, -8], [-2, 6, 4], [15, -5, -6], [-7, 7, -2], [24, 4, -4], [12, 10, 4], [-15, -11, -12], [-15, -1, -3], [-2, 14, 7], [4, 0, -4], [28, 0, -3], [2, 14, 12], [-26, -8, -6], [-3, -11, 10], [-17, 11, -3], [-2, -10, -1], [33, 9, 7], [8, 0, 3], [1, 15, 1], [24, 4, -2], [-34, 4, -4], [-11, 11, -1], [31, 3, 3], [22, -12, -6], [-17, -7, -4], [26, 10, 13], [9, -1, -8], [-21, 13, 5], [-2, 4, -4], [-6, -6, 5], [-20, 18, 6], [2, -2, 2], [15, 11, 10], [-26, 14, 2], [-37, -7, 4], [13, -3, 0], [1, -7, -15], [-6, 2, -6], [28, -16, 0], [-8, 0, 7], [37, -1, -5], [-2, -14, 3], [-32, 16, 4], [-13, 9, 6], [-33, 21, 3], [5, 15, 10], [3, -13, 3], [-5, 15, 2], [17, 15, 16], [7, -13, 0], [-2, 10, 1], [3, 3, -11], [19, 5, 8], [39, -23, -5], [12, 16, -2], [-6, -12, 10], [16, 10, 0], [-3, 1, 2], [-7, 1, -6], [9, -21, -5], [52, -8, -4], [21, -17, -3], [0, 12, -3], [10, 0, 0], [26, -2, 0], [16, -16, -4], [18, -12, -12], [23, -15, -9], [23, -7, 5], [28, -10, -10], [-31, -1, 5], [30, -12, -4], [29, 3, -5], [7, 1, 3], [-5, -15, 5], [2, 0, 6], [22, 14, 9], [23, 5, -2], [-38, -2, -2], [-22, -6, -5], [-35, -1, -4], [20, 14, 6], [2, -18, 1], [-21, -7, -7], [69, -1, 0], [12, 8, -3], [30, -14, -2], [11, -15, -7], [-20, -6, 2], [-42, 14, 7], [11, 1, 9], [11, 15, -10], [27, -15, -8], [-18, 8, -4], [22, 6, 2], [-23, 3, 6], [36, 6, 4], [26, -2, -12], [24, -14, -8], [18, -6, -8], [14, 6, -13], [51, -9, -4], [-48, 12, -1], [48, 6, 0], [-4, -14, 8], [5, -17, -3], [30, -14, 3], [9, 13, 16], [-2, 10, 1], [4, 0, 5], [5, 13, 16], [50, 2, -4], [6, 0, 8], [3, 5, 3], [28, -8, -4], [-15, -13, -3], [11, 1, 14], [-4, -20, -15], [22, 6, 4], [-54, 12, 0], [-31, -11, -13], [-17, -7, 5], [-12, 0, -10], [14, -16, -12], [18, -2, -10], [12, 8, 16], [-12, 6, 4], [-56, -4, 0], [35, -3, -3], [28, 2, -6], [6, 22, -2], [24, 6, 0], [-18, 22, -4], [34, 2, 3], [24, 8, 14], [-22, -10, 11], [21, -9, -3], [57, 3, -7], [-7, 7, -8], [-22, -2, -12], [-16, 8, -1], [-34, -4, 2], [-14, -18, 8], [-11, -9, -3], [-28, 16, -3], [-57, 5, 5], [21, 11, 13], [33, -19, -1], [21, -5, -4], [33, -15, -6], [30, -20, -10], [40, 2, -8], [-41, 7, 2], [-1, -5, 4], [-37, 25, 1], [-19, 3, -3], [30, -14, -5], [-9, 9, -4], [-49, -9, 6], [23, 13, 9], [-17, 7, 12], [16, -4, 7], [-59, 1, -5], [12, -6, 10], [-46, -2, 3], [-14, 10, -12], [21, 1, 11], [1, 3, 3], [2, 10, 12], [-26, 2, -10], [-64, 2, 2], [36, -24, 1], [14, -8, -10], [-9, -7, -13], [-68, -4, -6], [-7, -5, 6], [-16, 4, 12], [-30, -16, 2], [-35, -13, 2], [-41, -11, -5], [34, 2, 7], [10, -2, 4], [1, 27, -1], [5, -9, -9], [-27, -1, -13], [-28, -4, 5], [-54, 14, -3], [61, 3, 3], [-27, -17, 1], [40, 12, 5], [5, -15, -2], [12, 18, -12], [-7, 7, 2], [1, -9, -5], [38, -28, -6], [-18, 0, 10], [18, 6, 10], [-26, -16, 4], [-29, -11, -2], [35, -33, -6], [24, 6, -6], [11, -11, -3], [18, 14, 3], [38, -22, -1], [-28, -2, -2], [27, 15, -3], [-68, 12, 2], [27, -19, -7], [7, -7, 9], [29, -9, -3], [0, -4, 0], [-22, -2, -9], [21, -3, 8], [-22, -8, 10], [-17, -3, 13], [-25, 5, 1], [1, 9, -5], [18, 22, -14], [2, 22, 5], [10, -6, 2], [-38, -4, -10], [42, -12, 6], [33, 11, 21], [-39, -9, 8], [10, 2, 2], [-56, -4, 4], [-38, -8, -4], [53, -1, -6], [30, 6, 14], [17, 7, 6], [45, 15, -1], [37, -23, -10], [-44, 18, 8], [16, 20, -6], [-52, 8, 0], [50, -22, -6], [2, 12, -2], [31, -7, 12], [12, 4, -6], [-46, 18, 2], [-56, 24, 3], [-3, 11, -10], [27, -7, 13], [-37, 7, 8], [40, -14, -2], [24, 12, -11], [30, -14, -10], [-44, 14, 10], [30, 2, 2], [38, 10, -5], [0, -24, -11], [-77, 1, 5], [10, -28, 4], [63, -23, -3], [35, -3, -1], [-17, 9, -11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2976_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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