
// Make newform 4056.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4056_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_4056_2_a_j();".
// 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_4056_2_a_j();".
// 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_4056_a();"
function MakeCharacter_4056_a()
    N := 4056;
    order := 1;
    char_gens := [1015, 2029, 2705, 3889];
    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_4056_a_Hecke(Kf)
    return MakeCharacter_4056_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], [-1], [3], [-4], [4], [0], [3], [-4], [-8], [-5], [-8], [7], [-9], [8], [-4], [-5], [4], [-5], [8], [-4], [11], [-4], [0], [-6], [-14], [11], [-4], [8], [-18], [-9], [-20], [8], [-9], [0], [3], [0], [23], [-8], [-12], [14], [16], [-1], [-8], [-13], [-26], [-8], [0], [-16], [-4], [-10], [10], [-28], [-5], [0], [7], [0], [-2], [20], [19], [-13], [-4], [-9], [8], [-12], [-6], [-25], [8], [23], [-16], [30], [-1], [8], [32], [-9], [-12], [24], [27], [-18], [-29], [-25], [0], [-1], [8], [-29], [-32], [0], [-30], [-9], [-5], [32], [28], [-36], [40], [0], [-36], [0], [31], [-9], [-20], [27], [-4], [35], [-36], [-22], [-4], [-9], [48], [7], [-24], [35], [28], [31], [27], [-20], [0], [35], [-44], [8], [-18], [40], [-5], [43], [38], [0], [-20], [-2], [-9], [4], [28], [-13], [-16], [8], [8], [-42], [42], [34], [38], [16], [-18], [-9], [-24], [-42], [4], [36], [11], [20], [19], [-33], [-8], [44], [35], [15], [52], [28], [-8], [-12], [-12], [11], [59], [-18], [36], [42], [-12], [12], [-29], [0], [-36], [35], [2], [-29], [32], [-13], [-24], [-45], [-4], [-45], [40], [-33], [-12], [46], [44], [32], [-49], [-22], [12], [-29], [-2], [-32], [-49], [24], [-9], [8], [-8], [-2], [12], [26], [-33], [-9], [7], [-12], [-29], [48], [23], [-17], [16], [-53], [-56], [36], [-45], [-52], [-13], [-42], [-32], [68], [-36], [15], [36], [43], [48], [-2], [27], [16], [19], [-20], [-48], [23], [43], [-4], [32], [44], [3], [0], [-28], [-53], [-40], [12], [-14], [-9], [68], [0], [-24], [-16], [-24], [-37], [-33], [52], [-36], [-36], [0], [48], [-2], [66], [-12], [59], [-18], [40], [54], [-4], [6], [-17], [-28], [-60], [35], [-61], [35], [-28], [-34], [75], [-44], [75], [-53], [52], [-53], [-24], [34], [-24], [-48], [-37], [27], [76], [48], [40], [-40], [-5], [24], [-72], [-29], [27], [-52], [-49], [30], [52], [-21], [-12], [-50], [-45], [-8], [-13], [12], [-20], [39], [3], [-20], [64], [-32], [35], [60], [39], [12], [-41], [-24], [-42], [-13], [-4], [72], [-69], [32], [-68], [18], [7], [68], [-54], [55], [8], [-6], [51], [4], [36], [-76], [23], [-57], [43], [28], [-92], [-40], [8], [-1], [-46], [-29], [-68], [-58], [-9], [75], [-8], [62], [24], [43], [80], [-24], [54], [0], [-38], [47], [-52], [59], [-45], [-64], [36], [-61], [-16], [-61], [-13], [-68], [-48], [52], [-38], [78], [44], [-41], [0], [-72], [16], [15], [-52], [-77], [-60], [60], [50], [-45], [47], [30], [-17], [-56], [-46], [40], [72], [72], [-42], [48], [12], [23], [27], [-40], [56], [-24], [26], [68], [-6], [20], [63], [30], [-94], [24], [-57], [51], [48], [-82], [-85], [-32], [-40], [87], [47], [88], [-36], [51], [-17], [8], [60], [82], [-84], [-49], [7], [-72], [12], [-6], [-49], [-96], [59], [-16], [12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4056_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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