
// Make newform 5054.2.a.p in Magma, downloaded from the LMFDB on 30 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5054_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_5054_2_a_p();".
// 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_5054_2_a_p();".
// 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_5054_a();"
function MakeCharacter_5054_a()
    N := 5054;
    order := 1;
    char_gens := [1445, 1807];
    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_5054_a_Hecke( : Kf := Kf)
    return MakeCharacter_5054_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 := [[1, 0], [0, 1], [1, 0], [-1, 0], [-5, 0], [3, -3], [5, -3], [0, 0], [-5, -2], [-7, 2], [-3, 6], [1, -8], [2, 5], [-5, 3], [3, -8], [-9, 6], [11, 0], [5, -4], [6, -3], [-10, 0], [-9, 9], [-7, 3], [-8, 12], [3, -3], [-7, 4], [6, 3], [-12, 5], [-9, 8], [-8, 9], [2, -3], [-3, 7], [-5, -1], [10, -18], [1, 2], [2, 1], [-13, 2], [18, -7], [-2, -4], [8, 10], [3, 2], [1, -13], [-17, -2], [9, 10], [-4, 10], [-2, 9], [-8, -5], [-9, -8], [-3, -14], [-13, 2], [-7, 5], [-3, 13], [-13, -3], [11, 5], [4, -4], [13, 8], [-19, 10], [3, -10], [-7, -14], [-8, 0], [-11, 2], [12, 9], [15, -2], [0, -8], [21, 2], [22, 5], [1, -12], [10, -4], [-18, 25], [-10, -8], [-3, 6], [10, -5], [23, -8], [14, 7], [-5, 3], [4, -13], [1, -8], [12, 1], [-23, 15], [-14, -12], [3, -23], [-14, 19], [-13, -8], [-2, -8], [-27, 1], [-27, -8], [3, -23], [-16, 10], [20, -16], [24, -30], [-8, 9], [31, -4], [6, 10], [5, -10], [-6, 22], [9, -12], [12, -32], [-6, -12], [17, -14], [-16, 31], [-13, 28], [3, -10], [-29, -2], [20, -26], [-21, 15], [10, -34], [-7, -6], [-37, 8], [11, 9], [17, 0], [3, -18], [12, -8], [-2, 14], [-20, 7], [-28, 11], [8, -8], [22, 5], [14, -14], [-17, 39], [7, -27], [15, -30], [3, 24], [24, 5], [0, -6], [-11, 15], [7, -4], [11, 15], [31, -14], [25, -24], [19, 18], [21, 14], [4, -12], [-40, 17], [6, -10], [4, 16], [-1, -24], [32, -12], [6, 9], [-23, -7], [6, -11], [-28, -3], [-22, 30], [11, 2], [-35, -2], [14, 1], [-3, -16], [35, -10], [13, -42], [6, -19], [11, 26], [-11, -6], [1, -7], [16, 3], [-24, -21], [6, -24], [21, 7], [27, -31], [2, -13], [-17, 16], [20, -33], [13, -23], [40, -16], [-11, 32], [-46, 15], [-27, 12], [-29, 32], [20, 17], [-18, 12], [23, -13], [-35, 28], [-27, 7], [0, 13], [18, -16], [-15, -5], [-48, 13], [16, 20], [0, 16], [-22, 35], [41, 2], [35, -33], [42, -14], [25, -19], [3, 4], [12, 7], [0, 22], [10, 28], [-12, -8], [-4, -20], [48, -20], [-7, 2], [7, -25], [-6, 25], [-30, 22], [7, 11], [-31, 25], [-27, -4], [24, 5], [0, -19], [32, -11], [17, 10], [-33, 19], [33, 8], [-1, -26], [-5, -10], [36, -9], [-51, 1], [4, -27], [50, -30], [-6, 35], [25, -27], [-14, 39], [53, -2], [-1, -24], [-31, 13], [-38, 0], [-32, 13], [5, -45], [6, 2], [-8, 40], [-6, 26], [-40, 3], [-20, 12], [-57, -3], [4, 35], [34, 15], [-18, 30], [21, 0], [35, 2], [-4, -3], [5, -19], [-27, -15], [-5, 40], [20, -42], [-43, 42], [48, -25], [-8, 40], [15, 28], [-32, 5], [-19, 40], [-14, -10], [23, -11], [55, -14], [-32, -11], [-11, -20], [-41, -21], [26, 20], [-16, -3], [-22, 41], [15, -20], [-47, -18], [37, -22], [-53, -5], [44, -52], [-23, -22], [-15, 10], [-11, 14], [-12, 21], [7, -37], [-10, 37], [-9, -3], [-29, 55], [-49, -16], [-29, -5], [44, -10], [-26, 24], [19, 25], [-46, 13], [-8, -13], [36, 24], [27, -1], [5, -10], [-77, 8], [-22, 55], [33, -20], [-10, -21], [3, -10], [-16, 12], [17, -38], [21, -12], [-13, -21], [75, 4], [44, 0], [-65, 32], [5, -6], [-69, 13], [23, -7], [41, -25], [-7, 27], [-51, 7], [-1, 8], [-37, 4], [-10, 44], [41, -17], [52, -18], [14, -14], [-35, 24], [-21, 56], [-30, -6], [-22, -13], [-8, 4], [-13, -8], [-77, -2], [-10, 49], [-10, -25], [34, -26], [-28, 8], [-13, -25], [-9, -7], [44, 1], [12, -43], [22, -22], [-31, 49], [37, -59], [11, 0], [42, 10], [1, -42], [-47, 37], [2, -1], [1, -20], [22, -39], [1, 38], [-67, 27], [-50, 16], [-45, 6], [39, -9], [33, 24], [-59, 4], [-63, 29], [58, -20], [31, -65], [22, -50], [44, 15], [-14, -2], [-31, -2], [38, -4], [-59, 48], [-37, 7], [-14, 10], [37, 2], [26, -51], [40, -41], [-66, 46], [69, -22], [-32, 12], [-54, -6], [13, 38], [-50, 38], [12, 4], [23, -49], [0, 29], [-15, 45], [32, -35], [53, 15], [-39, -6], [-8, -50], [19, 45], [75, -21], [-28, 20], [-30, 10], [21, -63], [-9, -21], [-26, 7], [-42, 75], [54, -58], [2, -45], [62, -52], [-57, 28], [-3, 34], [-24, 0], [-62, -2], [50, 8], [30, 11], [-52, 22], [-18, 16], [-59, 9], [-46, -2], [-34, 0], [-10, 5], [-50, 62], [-12, -23], [-49, 31], [-11, -3], [-5, 38], [49, -24], [42, -35], [52, -41], [31, -30], [-57, -11], [20, -25], [29, 2], [60, -26], [62, -12], [-44, -12], [-64, 30], [43, -82], [31, -36], [-46, 3], [-67, 16], [5, 19], [-9, -55], [58, -5], [-27, 72], [-12, -29], [-18, -30], [-26, 42], [53, 8], [41, -48], [-41, 67], [-35, 32], [-70, -10], [-37, -34], [-16, -16], [3, 5], [17, -61], [-80, -5], [-63, 42], [-47, 56], [-13, 22], [-47, 20], [-10, 10], [-33, 34], [-12, 63], [74, 7], [-89, 14], [-11, -51], [49, -20], [-46, -29], [-2, 0], [12, -60], [1, -56], [40, -8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5054_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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