
// Make newform 2254.2.a.z in Magma, downloaded from the LMFDB on 07 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2254_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_2254_2_a_z();".
// 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_2254_2_a_z();".
// 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, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -4, 0, 1], [-1, 3, 1, -1]];
    Rf_basisdens := [1, 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_2254_a();"
function MakeCharacter_2254_a()
    N := 2254;
    order := 1;
    char_gens := [1473, 1569];
    v := [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_2254_a_Hecke(Kf)
    return MakeCharacter_2254_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+1)]];
    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 := [[1, 0, 0, 0], [1, 1, 1, 0], [2, 0, 0, -1], [0, 0, 0, 0], [1, 1, 2, 0], [0, 1, 2, 3], [1, -4, -2, -1], [2, 2, -2, 1], [-1, 0, 0, 0], [0, 0, -1, 1], [1, -5, -4, -2], [-3, -1, -5, -1], [2, -3, -4, -3], [0, -5, -4, 0], [3, -3, 2, 1], [-1, 1, -1, 4], [3, 3, 0, 0], [7, 4, 8, 1], [0, -3, 5, 2], [2, -5, -6, -3], [-5, -1, 0, 4], [-5, 2, 4, 3], [0, 4, -3, 1], [6, 4, 2, 5], [1, 2, 1, 3], [3, 5, 3, -4], [6, -1, -4, -2], [-6, -4, 3, 5], [1, 0, -4, -6], [-5, 3, 3, 7], [5, -2, 1, 3], [1, -1, 3, 6], [2, 6, 7, -2], [2, 6, 5, -5], [-4, 10, 4, 2], [-11, -2, -8, -4], [-8, -3, -3, -4], [2, -4, -9, -10], [2, 4, 2, 4], [-5, -8, -9, -4], [-9, -6, -13, -2], [2, -6, -1, -2], [7, 1, 0, -4], [-1, -7, -7, -3], [-10, 2, 5, 2], [5, 10, 1, -6], [9, 9, -2, -3], [2, -4, -1, -6], [9, -19, -9, -4], [-3, -11, -1, 0], [1, -7, 5, 4], [5, -5, 3, -3], [2, 1, 8, 2], [10, -3, -4, -7], [-13, 4, 0, -3], [-5, 1, -7, 0], [0, 9, 0, 0], [-1, 6, 1, 11], [1, 8, 7, 9], [-9, 2, -2, -5], [4, 0, 7, -5], [2, 9, -3, 5], [-8, -9, 0, -4], [18, 7, 12, 1], [-4, 6, 5, -5], [8, -10, -3, -2], [-9, 5, 4, 5], [8, 5, 1, -8], [-9, 4, 5, 8], [1, 9, 7, -8], [-2, -3, 9, -2], [-9, -5, -8, -6], [8, 4, 5, 5], [-6, -5, -10, 3], [5, 0, 7, 8], [1, 12, 6, 7], [11, 1, 2, -8], [-1, 10, -2, 3], [2, -7, -7, -1], [-18, -13, -23, -4], [23, -6, -7, -6], [-5, 12, 13, 1], [-4, 0, 6, 5], [-16, 0, -5, -4], [-1, 1, -3, -2], [-4, 22, 9, 3], [-10, 20, 5, 5], [-7, -14, 8, 8], [3, 0, -3, 9], [-4, -7, 6, 2], [-12, -8, -16, -10], [-4, 0, 5, -3], [18, 10, 11, 0], [-6, 10, 3, 4], [0, -7, -1, -8], [12, 9, 5, 19], [-15, 8, 2, 0], [-1, 5, -2, 3], [10, 5, -2, 15], [-6, 9, 16, -6], [-1, -11, -5, -9], [23, 0, 1, 10], [28, -14, -7, -3], [16, 9, -4, -4], [-5, -8, -7, 7], [-23, -11, -20, -1], [9, -8, -7, -10], [-2, -3, 2, 2], [5, -16, -18, -23], [-27, -4, -5, -1], [4, -19, -3, 1], [-3, 0, -18, -8], [-15, 18, 8, 1], [11, 10, 12, -5], [16, 11, 3, 13], [-14, -2, -6, 5], [6, 17, 9, 6], [-16, 9, 1, -2], [6, -1, -7, -12], [21, -4, 8, -3], [24, 10, 14, -6], [23, 5, 7, 4], [-3, 10, 15, 22], [-5, -14, 8, 6], [21, 6, -1, -13], [-15, -8, -7, -7], [-13, -2, 11, 5], [10, 2, 1, 11], [0, 9, 10, -3], [5, -9, 4, -13], [0, -9, 1, -12], [-12, 4, 8, -4], [-27, 5, -9, 3], [-2, -13, -11, -24], [-13, -23, -6, 6], [-15, 9, -2, 6], [-10, -13, -2, 6], [9, -3, -6, 7], [13, -4, 7, 2], [-2, 7, 10, 22], [-6, -13, -20, -1], [11, -16, -3, -2], [-22, 3, 12, -9], [7, 17, 10, 11], [-6, -11, 13, -2], [31, 14, 23, 4], [-10, -13, -11, -8], [-9, -6, -24, -9], [-9, 18, 4, 6], [21, 18, 28, 11], [-18, -1, -25, -5], [6, -1, -7, 15], [6, 16, 16, 25], [-4, 6, 19, -2], [-10, -5, 11, -7], [-2, -5, -12, 8], [13, -9, -4, -9], [-1, 4, -14, -4], [1, 1, 21, 9], [40, 2, 3, 6], [20, 18, 10, -8], [22, -30, -13, -13], [6, 17, -3, 0], [26, -13, -1, 2], [-5, 6, -6, -14], [14, -9, -9, -10], [-16, 4, 9, 16], [-13, 10, -4, -7], [-13, 6, 13, -10], [23, 11, -6, -14], [-2, 12, 16, -6], [11, 8, -2, -2], [5, 9, 6, 8], [-44, -7, -10, -4], [-8, 17, 20, 23], [-23, 10, 7, -2], [5, 13, 3, 10], [18, -12, -17, -7], [20, 2, 14, -6], [12, 3, -2, 0], [-11, 4, 16, 2], [7, -29, -11, -20], [10, 27, 12, 5], [-5, 35, 18, 9], [-11, 21, 15, -2], [4, -15, -4, 5], [4, 22, 19, 11], [0, -4, 16, 5], [-9, -10, 13, -1], [22, 0, -10, 8], [-43, 3, -5, -4], [13, 24, 28, 6], [9, -8, 5, 0], [16, -9, 12, -5], [3, 18, -4, -5], [42, 10, -2, -9], [-8, -13, 15, 10], [40, 2, 7, -6], [-1, -6, -3, 5], [-11, -15, -14, -9], [-16, -2, 2, -2], [22, 5, -10, -13], [6, -1, 16, 14], [-1, 7, -12, -8], [-27, -14, -31, -13], [25, -6, -5, -3], [0, -24, 13, -6], [9, -4, -10, 0], [25, 6, -14, -12], [-28, -12, 7, -1], [7, 0, 29, -9], [40, 0, 7, 9], [34, 17, 7, -9], [-20, 30, 13, 9], [-9, 25, 13, 9], [21, 0, 11, 8], [22, 1, 31, 11], [9, -14, -19, -13], [10, 36, 32, -13], [-36, 0, 9, 0], [-20, -24, -7, -9], [-7, 18, -13, -5], [-7, 30, 10, 7], [21, -10, -14, 5], [9, -27, -11, -7], [-1, 25, 3, 16], [-22, -6, 9, 17], [26, -16, -22, -22], [-19, -13, 6, 14], [-3, 10, 21, 31], [-11, -7, 2, -1], [5, -8, 22, 6], [-2, 4, -15, -9], [-6, -8, -5, -15], [-6, -24, 11, -7], [-1, 6, 28, 28], [-15, 5, -4, -8], [17, 2, 1, 21], [-17, -6, 6, -11], [27, -20, -3, 4], [21, 3, -16, -26], [-1, 12, -6, 6], [21, 29, 30, 6], [-26, -14, -23, -10], [6, -7, -4, 9], [23, 1, -15, -3], [-13, 30, 5, -2], [37, -3, -13, 2], [5, -33, -21, 6], [13, -3, -6, 13], [1, -3, 3, -16], [26, 8, 19, -3], [-18, -16, 11, -3], [-5, -2, -14, -4], [-33, 24, 17, -5], [-26, 21, -4, -4], [-2, -5, -17, -13], [0, -4, -16, 13], [11, -3, 27, 11], [-12, 12, 6, -8], [3, -1, -18, -15], [-14, 9, 6, -5], [-8, -20, 2, 10], [-30, -19, -22, -17], [25, -4, 25, 8], [-15, 6, 2, -10], [-36, -15, -15, -3], [2, 20, 31, 0], [-35, 4, 9, 21], [-5, -12, -7, 29], [7, -14, -20, -22], [11, -12, 9, -18], [-19, 3, 4, 5], [37, 15, 33, 23], [13, 11, -3, -26], [-10, 1, 11, 14], [-27, -16, -25, 0], [22, 16, -8, 5], [25, 3, 0, 11], [-11, -18, -19, -1], [-11, 9, -18, -20], [45, -1, -8, 11], [-16, 20, -16, 5], [-9, 4, 15, 2], [-38, -8, -25, -8], [-38, -11, -2, -23], [-16, 29, 15, 20], [-6, -8, 22, 21], [-34, -8, 5, 8], [-46, -2, -4, -11], [35, -33, -19, -6], [27, 15, -8, -13], [-36, -26, 0, 22], [20, 4, 8, 1], [-2, 12, 18, 20], [-11, 14, 28, 41], [-19, -13, -30, -22], [6, -5, -24, 1], [15, -13, 32, 6], [-39, -6, -20, -3], [-15, -8, 19, 13], [-15, 5, -2, 25], [-36, -16, -4, 16], [21, 36, 32, -5], [-21, -14, -30, -16], [6, 37, 36, 8], [52, -15, 7, 3], [-4, -7, -16, 6], [13, -16, -23, -25], [-8, -4, 10, -24], [-11, -1, -11, -16], [4, 22, 3, 2], [26, -5, -21, -30], [5, 12, 24, -15], [3, 25, 0, -2], [-54, 13, 3, -4], [-18, -29, 12, -8], [-22, -11, -13, 16], [-31, 35, 0, 8], [1, -18, -31, 14], [-11, 0, -2, -32], [-14, -24, -25, 18], [2, 9, 1, -2], [14, 29, 7, -8], [-20, -20, 6, -4], [1, -23, -17, 8], [19, 9, -10, 33], [-22, 21, -19, 4], [-8, -1, -28, -11], [13, -6, -25, -31], [29, -20, -21, -29], [36, -3, 2, 1], [-58, -1, 4, 4], [-28, 6, -14, 1], [17, -10, 4, -20], [-14, 18, 24, 19], [11, -38, -31, -31], [-40, 6, 14, 9], [-27, 34, 23, 3], [20, 8, -7, -36], [-5, 10, -14, 8], [-12, -12, 11, -5], [-15, -15, -6, 6], [9, -15, 8, 5], [-14, -45, -44, -3], [8, -12, -14, 16], [-32, 0, -33, -4], [20, 16, 13, 3], [12, -44, -22, -4], [-19, 1, -13, 16], [-4, -9, -10, -20], [-4, 18, 3, 3], [-23, 9, 16, -9], [-29, 15, -7, 0], [58, 7, -6, -12], [-45, 2, 11, -21], [-26, -15, -38, -6], [-42, 10, -13, -1], [0, 15, 36, -3], [27, -29, -24, -8], [-4, -44, -36, 4], [-4, 3, -26, 4], [25, 15, 37, 27], [-7, -9, -11, 16], [-34, -7, 6, 29], [36, -11, 3, -1], [5, -21, -22, 15], [21, -10, -4, -29], [20, 7, -9, 13], [-18, 36, 18, 12], [-22, 15, 16, 5], [15, 5, -4, -6], [-2, 17, 27, 9], [11, 7, 15, 28], [-29, 19, -2, 5], [-27, -14, -52, -28], [-11, 25, 34, 4], [19, -31, -28, -40], [7, 20, 34, -13], [-13, -19, 14, 0], [13, -25, -32, 5], [38, 8, 14, 5], [-32, 38, 21, 1], [2, -30, -18, -37], [-10, -9, 10, -25], [1, 16, 22, 28], [-43, 25, -10, -1], [-10, 14, 6, 14], [-20, 3, -7, 15], [11, 31, 29, 7], [-19, 10, -2, -9], [-3, -3, 6, 18], [11, -15, -20, 7], [27, -10, -14, 14], [-8, 16, -9, 14], [-37, 10, 1, 21], [53, 13, -10, -19], [21, -3, -28, 13], [1, -5, 21, 9], [-9, -2, -15, 13], [56, -4, 1, -8], [-36, 4, -3, 19], [-39, -24, -20, 0], [-17, 1, -22, -6], [-43, 8, 26, 11], [4, -21, 24, -4], [15, -44, -18, -25], [8, 12, 22, 7], [27, 2, 29, 7], [32, 29, 3, 1], [6, -13, 22, -19], [-38, -2, 12, -4], [10, 4, -22, 6], [3, -10, -4, 16], [-26, -14, 15, 24], [23, 36, 17, 3], [-3, 17, 39, 2], [3, 32, 26, 13], [13, 6, 42, 10], [-25, 10, 27, 30], [53, -32, -11, -19], [77, 9, -4, 7], [-5, -51, -42, 7], [18, -7, -18, -19], [-36, 9, -34, -7], [-11, -40, -44, 11], [20, 8, -7, -37], [33, 2, 14, 6], [39, 9, -2, -3], [-33, -20, 13, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2254_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2254_2_a_z();".
// 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_2254_2_a_z(:prec:=4)
    chi := MakeCharacter_2254_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_2254_2_a_z();".
// 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_2254_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2254_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 5, -1, -3, 1]>,<5,R![-3, -5, 13, -7, 1]>,<11,R![-9, 29, -12, -2, 1]>],Snew);
    return Vf;
end function;