
// Make newform 5077.2.a.a in Magma, downloaded from the LMFDB on 13 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_5077_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_5077_2_a_a();".
// 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_5077_2_a_a();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5077_a();"
function MakeCharacter_5077_a()
    N := 5077;
    order := 1;
    char_gens := [2];
    v := [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_5077_a_Hecke( : Kf := Kf)
    return MakeCharacter_5077_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 := [[-2], [-3], [-4], [-4], [-6], [-4], [-4], [-7], [-6], [-6], [-2], [0], [0], [-8], [-9], [-9], [-11], [-2], [-12], [-8], [-14], [9], [-2], [11], [6], [4], [0], [12], [7], [-5], [7], [-7], [-3], [4], [6], [9], [4], [-4], [-8], [-9], [9], [19], [-16], [-13], [-20], [-13], [-12], [21], [-26], [-10], [15], [-15], [-29], [8], [-18], [2], [-14], [18], [-13], [24], [-16], [9], [-17], [-32], [-14], [-22], [-4], [8], [12], [-35], [-34], [-15], [32], [0], [15], [-27], [-3], [10], [-18], [-31], [-20], [10], [-30], [12], [10], [-32], [14], [-21], [-6], [16], [-11], [-26], [-24], [40], [8], [-41], [42], [18], [6], [10], [9], [17], [-33], [2], [-31], [-22], [-26], [5], [16], [-10], [34], [10], [-4], [-3], [47], [-18], [-12], [-3], [24], [14], [10], [16], [-48], [-45], [2], [24], [-8], [-10], [-33], [-18], [44], [16], [-4], [-33], [-38], [-50], [3], [-1], [39], [-54], [16], [-24], [-31], [24], [-40], [15], [15], [-22], [-41], [21], [-32], [-33], [-22], [1], [-28], [-24], [-25], [-28], [37], [14], [-17], [48], [-23], [-2], [10], [17], [-13], [49], [-23], [-46], [25], [-12], [-4], [8], [-5], [31], [-43], [-30], [8], [-47], [55], [17], [46], [58], [36], [49], [18], [45], [43], [24], [17], [-34], [64], [-29], [12], [-32], [-22], [-19], [-28], [-45], [18], [-14], [46], [51], [16], [-18], [62], [3], [19], [-42], [-22], [-30], [24], [-51], [-27], [-26], [-8], [46], [65], [-45], [-48], [20], [11], [-64], [-12], [10], [-18], [45], [-41], [-24], [36], [15], [-56], [45], [-24], [-27], [-15], [-8], [55], [24], [-23], [-31], [-48], [-38], [-51], [-7], [-22], [-22], [31], [-17], [-14], [-30], [7], [-50], [21], [57], [-46], [23], [-58], [20], [-23], [63], [59], [62], [28], [-72], [76], [11], [46], [32], [50], [28], [71], [-54], [-42], [18], [47], [-20], [-64], [-45], [82], [-72], [-52], [78], [-61], [-9], [-66], [0], [4], [-53], [-45], [-52], [41], [-9], [-40], [-22], [-44], [6], [-28], [-77], [54], [16], [-20], [41], [-31], [30], [-42], [4], [-29], [-1], [-3], [9], [-9], [-12], [-77], [-20], [-66], [77], [-54], [-90], [-41], [60], [9], [76], [9], [2], [20], [-61], [-20], [86], [-34], [18], [68], [67], [19], [8], [-37], [42], [-11], [-34], [74], [25], [-31], [-40], [24], [46], [-63], [-46], [15], [24], [56], [15], [1], [35], [66], [30], [-48], [46], [90], [48], [-42], [-12], [-2], [-4], [46], [-64], [-47], [-86], [-7], [8], [78], [38], [30], [2], [14], [10], [36], [-50], [26], [27], [2], [26], [-25], [-54], [-18], [-75], [-27], [14], [-30], [53], [-90], [54], [-44], [48], [-6], [50], [-2], [84], [-70], [-74], [28], [18], [84], [36], [-30], [78], [82], [-78], [-50], [8], [61], [-48], [-21], [-48], [-43], [-40], [39], [-60], [2], [34], [94], [-26], [-64], [-12], [-45], [33], [-36], [-1], [-85], [6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5077_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5077_2_a_a();".
// 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_5077_2_a_a(:prec:=1)
    chi := MakeCharacter_5077_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_5077_2_a_a();".
// 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_5077_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5077_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 1]>],Snew);
    return Vf;
end function;