
// Make newform 4928.2.a.bn in Magma, downloaded from the LMFDB on 01 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4928_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_4928_2_a_bn();".
// 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_4928_2_a_bn();".
// 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 := [-4, -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_4928_a();"
function MakeCharacter_4928_a()
    N := 4928;
    order := 1;
    char_gens := [4159, 1541, 2817, 3137];
    v := [1, 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_4928_a_Hecke(Kf)
    return MakeCharacter_4928_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 := [[0, 0], [0, -1], [0, -1], [-1, 0], [-1, 0], [-2, 0], [-4, 0], [-2, 0], [4, 1], [6, -2], [-2, 3], [2, -1], [-4, 2], [8, -2], [6, -2], [-6, 4], [-12, 1], [-10, 2], [0, 5], [0, 3], [-4, -2], [8, -2], [-2, 4], [6, 1], [-10, 3], [-6, 6], [-2, 2], [0, -4], [10, -4], [-6, 3], [16, -2], [-6, 10], [2, -9], [-6, 2], [2, 6], [0, 6], [-12, -1], [-4, 0], [-4, -6], [22, 0], [-8, -3], [0, 5], [4, -9], [-6, -6], [-18, 4], [-2, 2], [8, -4], [-2, -9], [18, -6], [-16, 1], [-10, 6], [8, 6], [12, -8], [4, -11], [2, -4], [8, 0], [-20, -2], [12, -6], [-6, -4], [-10, -4], [2, -10], [-2, -8], [2, 4], [-6, -2], [-6, -7], [-2, 1], [0, 3], [-2, 2], [16, 6], [10, 10], [-2, 1], [24, -2], [-2, -5], [-10, -2], [8, -17], [-2, 7], [-14, 1], [0, -6], [30, -4], [24, 2], [-12, 12], [26, 0], [24, -4], [-2, 11], [-12, 0], [8, -3], [18, 9], [-22, 6], [2, 6], [-8, -9], [0, -3], [0, -6], [-36, 1], [-28, -4], [12, 0], [-4, 2], [16, 9], [38, -1], [-6, 8], [-18, 16], [12, 8], [30, -6], [-6, -2], [-2, 14], [-20, 8], [10, -1], [-24, -4], [-12, -8], [-12, 12], [-8, -4], [0, 2], [14, -22], [-30, 4], [16, 3], [4, -11], [14, -15], [12, 13], [-2, 5], [-6, 15], [32, 6], [-24, 15], [-2, 0], [-10, -6], [-20, 0], [20, -15], [18, 6], [-30, -1], [22, 7], [-34, -1], [-10, -14], [20, -2], [-8, 12], [20, -1], [-10, 20], [-8, 6], [-24, -6], [-8, -2], [-34, -2], [-20, -5], [-46, 4], [2, -4], [10, 8], [12, -3], [-20, -6], [32, -13], [-10, -5], [6, 4], [16, 0], [20, -3], [16, 0], [18, 0], [26, -17], [-20, 8], [0, -6], [-20, -8], [16, -24], [-16, -6], [58, 0], [20, 2], [6, -4], [-40, 5], [10, -2], [24, -12], [-16, -5], [-2, -9], [10, 3], [-20, -4], [-22, -2], [-30, 16], [16, -7], [-40, 6], [0, -10], [32, -2], [6, 8], [-38, -7], [-30, 19], [-28, 12], [2, -17], [-4, 0], [-14, -6], [12, -4], [-38, 12], [-6, 5], [16, 10], [-16, 3], [12, -22], [6, -20], [12, 16], [-34, 14], [-4, 26], [58, -1], [8, 20], [-8, 5], [24, 10], [12, -18], [30, -3], [-18, 26], [-22, -1], [-12, 14], [28, 8], [2, -28], [36, 2], [8, -10], [4, 0], [-40, 15], [-16, 15], [-22, 17], [4, 12], [18, -14], [-4, 8], [14, 10], [4, -23], [0, -11], [-16, -4], [28, 8], [-22, 25], [24, -14], [8, 0], [20, -12], [34, -13], [6, -12], [4, 26], [18, 7], [8, -13], [10, -24], [10, -8], [6, -4], [-12, 4], [-20, -2], [-16, -6], [-14, -11], [-26, 0], [0, 6], [10, -30], [-40, 1], [12, 10], [-2, -17], [26, -12], [16, 19], [-22, 1], [24, -9], [-50, 2], [-18, 10], [-50, -11], [8, -8], [20, -28], [-42, -6], [-64, 4], [-20, 6], [-24, 18], [-18, -14], [4, -32], [16, -21], [18, -12], [30, -18], [-8, -24], [-34, 20], [2, -18], [-16, -1], [20, -20], [-24, 16], [20, 10], [-2, 14], [-22, -2], [6, 16], [-32, 28], [-2, -17], [58, -9], [44, -14], [-10, 12], [-36, 15], [-24, 11], [-42, 12], [64, -10], [-60, -2], [-58, 15], [-48, 11], [-18, -4], [-46, 4], [46, -12], [16, -6], [16, -21], [16, 22], [50, 12], [30, -6], [-36, 7], [-42, 8], [2, 2], [34, -3], [40, 8], [-50, -11], [36, -4], [-34, -18], [14, 2], [-6, 26], [-6, 4], [18, -3], [-16, -15], [18, -10], [18, -12], [0, -4], [-14, -16], [16, 16], [-36, 24], [16, 15], [34, 21], [-40, 27], [8, 19], [28, 4], [-70, 8], [48, -12], [30, -8], [-2, -8], [-8, 9], [16, 16], [-84, 0], [-20, 3], [8, 10], [-42, 20], [-42, -8], [14, -4], [22, -37], [-18, -18], [12, -25], [18, 24], [-22, 13], [32, 15], [-8, 11], [-40, -14], [-22, 18], [22, -12], [-10, 20], [28, -12], [-46, 18], [52, -16], [24, -43], [-14, -27], [-40, 20], [14, -3], [-72, 4], [-34, 5], [-42, 1], [-10, 8], [-60, 9], [50, -9], [20, -2], [-40, 29], [24, -13], [40, -14], [-52, 1], [-78, -4], [-6, 29], [-22, 12], [-24, 4], [-62, -2], [40, 2], [-14, -15], [10, -4], [-46, 12], [-24, 39], [-38, 16], [-8, -4], [-24, 1], [-20, 16], [-8, 7], [-2, -33], [-50, 12], [-24, 38], [-22, 16], [-40, 1], [36, 12], [-40, 16], [-18, -12], [48, 18], [6, -3], [-20, -8], [-8, 32], [-32, -10], [-20, -6], [-4, -4], [40, 10], [-34, -7], [0, 20], [-6, -6], [-30, 14], [-42, 7], [56, 4], [64, -21], [48, -10], [26, -17], [6, 23], [20, 9], [-40, 1], [-12, -13], [32, -27], [6, 16], [-40, 8], [6, -16], [-84, -4], [-14, -16], [-18, 2], [-2, -29], [16, -32], [46, 0], [-26, 18], [44, 8], [-38, 40], [10, 24], [4, 0], [-32, -5], [-76, -6], [14, 22], [36, -40], [-28, 32], [22, -30], [12, -13], [-24, 4], [70, -5], [30, 16], [48, 22], [-22, 19], [-42, -18], [-68, 12], [46, -22], [-58, 24], [-12, -15], [-8, 23], [38, -38], [-72, 3], [8, 32]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4928_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4928_2_a_bn();".
// 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_4928_2_a_bn(:prec:=2)
    chi := MakeCharacter_4928_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_4928_2_a_bn();".
// 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_4928_2_a_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4928_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, 1, 1]>,<5,R![-4, 1, 1]>,<13,R![2, 1]>,<17,R![4, 1]>,<19,R![2, 1]>,<23,R![16, -9, 1]>],Snew);
    return Vf;
end function;