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