
// Make newform 2277.2.a.d in Magma, downloaded from the LMFDB on 16 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2277_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_2277_2_a_d();".
// 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_2277_2_a_d();".
// 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_2277_a();"
function MakeCharacter_2277_a()
    N := 2277;
    order := 1;
    char_gens := [254, 1036, 1684];
    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_2277_a_Hecke( : Kf := Kf)
    return MakeCharacter_2277_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], [0, 0], [0, -2], [0, -2], [-1, 0], [2, 0], [2, 2], [4, 2], [1, 0], [0, 0], [4, -4], [6, 0], [4, 0], [4, 2], [-4, 0], [-8, 2], [-12, 0], [-6, -2], [12, 2], [8, 4], [-2, -4], [4, 2], [-4, -4], [8, 2], [-2, 8], [4, 4], [4, 6], [4, 0], [-2, -6], [-12, 2], [-18, 0], [-4, -2], [-4, -6], [14, -4], [6, 2], [2, 4], [14, 0], [4, 12], [20, 2], [0, -8], [12, 4], [2, 4], [-4, -12], [6, -4], [-16, 0], [8, 2], [-6, 8], [0, 0], [4, -4], [10, 8], [-12, 8], [-12, -2], [2, 14], [0, 4], [-16, 4], [16, -8], [-16, 8], [10, 0], [14, -4], [22, -2], [0, 6], [10, -2], [18, 0], [-4, -12], [2, -4], [0, -8], [12, -4], [-14, 6], [0, -18], [-2, -12], [8, 8], [24, -4], [-12, -2], [10, -14], [-8, -6], [0, 16], [0, 2], [-14, 0], [16, -2], [2, 4], [-16, 12], [-14, -8], [-8, 0], [-6, 0], [22, -4], [24, 0], [-8, 4], [2, 10], [0, 8], [-16, 8], [20, 8], [0, 12], [4, -16], [-24, 6], [16, -4], [-24, -8], [-24, 0], [4, -6], [28, 6], [-6, -4], [-26, 0], [14, -2], [-12, 4], [-10, -6], [-16, -10], [10, 0], [8, 12], [-12, 8], [16, 4], [22, -12], [2, -20], [2, 14], [0, 18], [-4, 2], [-28, 6], [-12, 6], [-8, 2], [4, -8], [-16, -20], [-20, 8], [-34, -8], [-2, -8], [30, -6], [0, 8], [-28, -4], [10, 2], [-38, 0], [12, -16], [16, -18], [14, 18], [-14, 20], [24, -12], [-32, 6], [-22, 8], [-24, 12], [-2, -6], [24, 14], [4, -6], [12, -6], [-32, 4], [2, 0], [-12, -4], [8, -12], [4, -16], [-14, 8], [-4, 12], [18, 8], [12, -8], [44, -8], [28, 0], [10, 28], [24, -6], [32, 4], [32, 6], [-8, -18], [-8, -24], [-16, 2], [-24, -4], [-34, -2], [6, -6], [36, 12], [-10, -6], [30, -8], [-24, -4], [-24, -6], [36, 4], [12, 4], [-42, -4], [-38, 10], [0, 32], [4, 20], [-18, 8], [32, -8], [-30, 2], [-8, 4], [-32, 6], [-38, 12], [40, -8], [-32, 18], [-6, 10], [12, 20], [-12, 20], [50, 0], [24, -4], [-20, 4], [32, 2], [14, -16], [4, 14], [-26, -12], [-8, 18], [-6, 32], [36, 18], [-12, -26], [0, -8], [-12, -12], [-36, 6], [22, 22], [26, 12], [-18, 2], [4, 10], [18, -10], [-34, -8], [10, -8], [2, 34], [-20, 0], [0, -8], [40, -10], [8, 18], [-20, -8], [48, -4], [-14, 0], [-24, 16], [32, 14], [-8, 4], [-12, 6], [18, -28], [30, 4], [24, -20], [-60, -4], [48, 0], [-14, -16], [-20, 30], [0, 8], [-20, -2], [36, -2], [30, -8], [-12, 18], [-28, 24], [20, -2], [20, 18], [-26, 0], [-44, -2], [68, -2], [16, 4], [-32, 22], [-16, 4], [-18, -20], [42, 14], [24, 4], [-28, -12], [56, -4], [-2, 24], [-28, -20], [-34, 16], [-20, -8], [4, 10], [-28, 20], [-12, 0], [-16, 22], [0, 40], [-34, -18], [-6, 34], [0, -32], [-34, -20], [-36, 20], [-28, 26], [50, 4], [32, 22], [8, -20], [6, 28], [8, 2], [-36, 4], [6, -20], [-22, -2], [-8, -12], [40, 22], [20, 2], [12, 38], [-20, -18], [-8, 24], [-34, 24], [40, -22], [-74, -4], [-4, -18], [-10, -4], [-28, 0], [-28, 0], [10, 24], [-26, -22], [52, -4], [24, -14], [0, -6], [0, 16], [2, -42], [-34, 16], [4, -24], [-18, -16], [34, -2], [-12, 0], [0, -12], [36, -26], [24, -12], [8, -28], [12, -12], [-2, -28], [18, -30], [-12, 34], [24, -16], [44, 14], [14, 20], [-34, 18], [-30, -18], [32, -10], [-12, 24], [-40, 18], [-26, -24], [0, -8], [-14, -8], [8, 0], [-10, 24], [64, 6], [-28, 10], [30, -2], [64, -8], [-16, 8], [-14, 26], [8, 0], [24, -30], [-10, -12], [-60, -8], [56, 10], [2, 12], [-52, -20], [-4, 32], [-58, -6], [-2, 16], [-20, -18], [8, -8], [32, -16], [-10, -26], [-50, -4], [-32, -16], [-38, 12], [12, 2], [32, 6], [-52, 8], [-2, 36], [-38, -2], [-26, -8], [-12, -30], [-26, 32], [-36, -10], [-28, -28], [12, -46], [-20, -34], [20, 2], [-6, -16], [-28, 12], [-8, 12], [16, 26], [30, -4], [70, -8], [0, -28], [20, 18], [-6, 6], [0, 36], [-52, -12], [-20, -20], [-8, -36], [4, 8], [10, -10], [56, -12], [8, -32], [-20, 4], [16, -32], [54, 8], [-44, 12], [-36, -30], [-26, 2], [-36, -12], [-4, -12], [-28, -6], [22, -14], [40, 10], [46, 0], [-8, -48], [40, -4], [-2, -54], [54, 14], [-14, 32], [24, -22], [0, -14], [-42, 8], [44, -32], [-72, -6], [-16, -12], [-4, -12], [-2, -24], [20, -2], [60, 20], [14, 32], [0, 36], [-36, -20], [-56, -20], [24, 8], [34, -26], [36, 30], [28, -14], [68, 14], [-12, 36], [-14, 16], [-72, 8], [8, -30], [-32, -18], [-12, 20], [42, -12], [50, 12], [-64, 4], [8, -26], [-60, -16], [-58, 16], [44, 20], [28, 16], [-28, 22], [58, -6], [16, -4], [40, 6], [-24, -36], [-12, 18], [-16, 12], [20, 18], [2, 6], [0, 0], [-40, 6], [78, 16], [24, 4], [24, 36], [44, -8], [28, 4], [-48, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2277_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2277_2_a_d();".
// 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_2277_2_a_d(:prec:=2)
    chi := MakeCharacter_2277_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_2277_2_a_d();".
// 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_2277_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2277_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, 0, 1]>,<5,R![-12, 0, 1]>,<17,R![-8, -4, 1]>],Snew);
    return Vf;
end function;