
// Make newform 4056.2.a.z in Magma, downloaded from the LMFDB on 20 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_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_4056_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, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-4, 1, 1], [-4, -1, 1]];
    Rf_basisdens := [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_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, 0, 0], [-1, 0, 0], [0, 0, -1], [1, -1, 0], [0, -1, 1], [0, 0, 0], [0, -1, 0], [2, 1, 1], [0, -1, 1], [-4, 0, -1], [1, 0, -1], [2, 1, 0], [0, 1, -2], [-7, -1, 0], [-4, -1, 1], [-2, 0, -3], [2, 2, 0], [1, 1, 1], [9, -1, 0], [4, -1, 1], [-3, 0, 2], [3, -2, 3], [-6, -1, 3], [8, 0, 2], [7, 0, -1], [-4, 2, 1], [1, 1, -2], [-4, -1, 1], [3, 2, 1], [14, 1, 0], [3, -2, 3], [-10, 4, -2], [-4, -1, 4], [-3, 0, 3], [6, -2, -1], [-2, 1, -3], [-3, 1, -3], [7, 0, 1], [-8, 6, -2], [6, -2, -2], [-6, 1, 1], [14, 1, 0], [-2, 2, 0], [3, -2, 2], [-4, -4, -2], [-9, -1, -2], [-9, -2, 3], [16, 0, 0], [-2, 5, -3], [2, -2, 2], [6, 0, -4], [-6, -1, 3], [12, 0, 3], [0, -2, 2], [-4, 1, -2], [6, 3, -1], [4, -2, 0], [-3, -4, 3], [10, -1, 2], [-10, 1, 4], [1, 5, -2], [-16, -2, -3], [5, -1, 4], [18, 1, 1], [9, 4, 1], [6, -6, 3], [25, 0, -1], [9, 4, -2], [10, -1, 3], [17, 2, -5], [-2, 3, 2], [6, 1, 1], [3, 1, 0], [-19, -3, -3], [3, 2, -9], [8, -4, 4], [2, -6, 7], [-3, 6, -5], [4, 3, 4], [-7, -4, 10], [4, -4, 0], [7, 1, 3], [-18, -1, 3], [15, -4, 4], [9, 3, 0], [0, -2, 2], [6, 0, -4], [-3, -6, 4], [-10, 2, 3], [7, -1, -2], [0, 3, -3], [8, -2, -2], [22, -1, -1], [-8, -3, 7], [4, -2, 2], [-20, -3, 7], [-4, -6, 5], [4, 7, 0], [-10, 3, -5], [3, 7, 1], [-5, -3, -4], [2, 8, -3], [2, 6, 4], [-6, -6, 2], [-30, 1, 1], [16, 4, -9], [2, 0, -2], [-18, 3, 2], [18, 0, 6], [8, -2, 5], [4, -2, -6], [1, -1, -5], [-10, -3, -4], [29, -4, 3], [-1, -4, -3], [-10, -1, 6], [-1, 0, 5], [18, 4, 2], [-16, -6, 8], [4, 0, 4], [5, -5, -5], [15, 0, 8], [-12, 2, 4], [2, 0, -2], [-17, 3, 2], [-28, -2, 0], [19, -7, 7], [14, -6, 4], [-11, -7, -6], [-33, 1, -1], [12, 0, 4], [-10, -2, -4], [6, -3, 9], [-2, -4, 4], [-8, 0, 2], [-6, -2, -10], [-14, -2, 2], [15, 4, -3], [-24, -4, 10], [24, 5, 6], [13, -4, -1], [-26, 6, -2], [20, -6, 6], [24, 2, -6], [-1, -3, -5], [26, 4, 6], [5, -5, -5], [-10, -3, -4], [9, 1, -2], [-16, -3, 7], [6, 7, -2], [-16, -1, -4], [-3, 0, 7], [-6, -2, -4], [0, -10, 10], [-20, 6, -6], [12, -2, -6], [-16, 5, 2], [0, 4, -5], [-2, -2, -10], [-24, -2, -2], [10, 10, 2], [-6, 13, -7], [-8, 12, -8], [0, -5, -8], [-30, 6, 0], [2, -1, -9], [-7, -1, 3], [15, 0, 7], [-4, 6, 1], [-6, -7, -7], [-26, -5, 2], [10, 6, -16], [-19, 8, -6], [-20, -6, -10], [18, -9, -2], [1, 3, -4], [48, -2, 1], [-7, 4, -1], [-15, 2, 3], [2, 3, 3], [30, -4, 6], [3, 1, 7], [26, -6, 2], [32, 5, 7], [8, 0, -1], [-1, -6, 13], [16, 2, 6], [5, 6, -8], [22, -5, -1], [-11, 10, -8], [-2, -1, -9], [5, -7, -6], [-14, 0, 12], [20, 5, 7], [-12, 0, -2], [7, -6, -6], [11, 9, -5], [-14, -3, -4], [6, -4, 2], [10, 0, 5], [-19, -2, 13], [7, -3, -1], [9, -2, 0], [4, 9, 7], [10, 0, 1], [33, 3, -8], [0, 0, -12], [-8, -7, -2], [8, 2, -6], [7, 12, 4], [-28, -2, 0], [21, 9, -10], [-48, 1, -1], [12, 2, 6], [-24, -2, 5], [-31, -4, -1], [6, 7, -18], [-18, 6, -12], [16, 2, 0], [-17, -1, 1], [23, 4, -3], [16, 7, 8], [-37, 6, 3], [38, -1, 7], [33, 7, -13], [-6, 1, 4], [-8, 0, 4], [-29, 8, -3], [-12, 4, -12], [-25, 3, -7], [-5, 4, 1], [-8, 8, 4], [10, 3, 6], [-25, 14, -5], [38, 4, -14], [11, 0, 3], [20, -4, 3], [4, -10, 10], [-8, 7, 1], [34, 5, -3], [-6, 3, -5], [6, 9, 5], [5, 5, 9], [46, -1, -6], [32, 8, -4], [-39, -2, -3], [18, 0, -6], [5, 5, -18], [-2, -11, -3], [-25, -6, 5], [14, 2, -2], [-34, 2, -4], [-7, 8, 6], [-2, -8, 8], [4, -9, 1], [-18, 0, -8], [-42, 5, 1], [-12, -10, 8], [0, 2, 1], [-4, 8, 0], [-20, -4, 12], [-17, 1, -5], [-11, 13, -7], [-4, -7, 6], [37, 1, 6], [18, 8, -12], [18, 9, 4], [18, -7, 9], [-26, -8, 9], [-3, -11, 9], [-11, -2, 9], [12, 8, -17], [32, -6, -2], [51, 4, -9], [22, -3, -7], [-2, 10, 8], [10, 5, -8], [-17, 10, -2], [-2, -3, 21], [-28, -3, 7], [40, 0, 0], [-50, -2, 4], [9, -5, -1], [-74, 3, -1], [-32, -7, -1], [-11, 12, 2], [8, -12, 11], [31, 1, 0], [-22, 3, -6], [-32, -2, 4], [-8, -11, 11], [52, 5, -10], [-34, 14, -8], [-3, 6, 3], [2, -4, 9], [0, -12, 4], [-8, 4, -1], [6, 12, -6], [-31, -5, 16], [-13, -4, -4], [-24, 0, 7], [-42, -7, 9], [14, 10, 8], [17, 3, -4], [-15, 6, -8], [24, 11, 5], [-10, 9, -12], [14, 8, -10], [10, -3, -4], [-30, 5, -7], [-26, 6, -2], [44, 9, -6], [23, -5, 2], [32, 3, -11], [17, 12, -6], [14, 1, -3], [28, -1, 9], [-1, 0, -9], [2, 1, -12], [27, 5, -20], [1, 14, -13], [-34, -6, 3], [11, 1, 8], [26, 4, -4], [-11, -8, 14], [15, -5, 10], [26, 1, 9], [16, 9, -21], [28, 4, -13], [26, -3, 4], [-20, 2, -3], [-9, -3, -12], [38, -1, -5], [-25, -3, -4], [0, 3, 9], [53, -1, 3], [-22, -4, 4], [-20, -4, -5], [45, 6, -15], [-22, 0, 4], [48, -1, 8], [-32, 2, -3], [-3, 11, -4], [58, -6, 6], [12, 9, -1], [-1, 1, -21], [-8, -4, -4], [16, 7, 17], [0, 18, -8], [-27, 19, -8], [-38, -10, 22], [46, 8, -7], [-39, -11, -14], [-42, -9, 10], [40, -1, 4], [-30, -13, -5], [28, 12, -4], [40, -9, 0], [6, -3, -3], [-38, -9, -10], [-4, 11, 4], [-10, -10, -8], [50, 2, -4], [29, -8, -1], [-7, 12, -7], [-24, -10, -4], [53, -4, 3], [16, -4, 11], [28, -2, 6], [19, 7, -10], [-60, 3, 1], [-26, 2, 11], [-2, -11, -11], [10, 11, 10], [2, -5, 3], [-26, 1, 5], [-7, 14, 3], [-58, 1, 0], [13, 8, 10], [24, -10, -4], [10, -3, 8], [42, 3, -9], [46, -8, -4], [13, -8, 19], [22, 1, -7], [-2, -3, 1], [31, -14, -3], [19, 10, -5], [14, 12, 2], [76, 0, 3], [20, 4, -1], [26, 9, -7], [26, 11, -29], [52, 4, -16], [-1, 4, -13], [26, -1, 7], [-26, 2, -18], [-20, -12, 20], [14, 4, -7], [-31, 4, 13], [-30, 12, -12], [1, 2, -19], [-18, 23, -6], [54, 0, 5], [11, -5, 14], [-5, 8, -1], [-12, 5, 2], [1, 1, -18], [0, -4, -4], [19, -6, -10], [-6, 22, -9], [8, 3, -15], [24, -16, 4], [-19, -4, -2], [38, -8, -7], [0, -6, 6], [-45, 9, 4], [-48, -2, 16], [24, -20, 8], [-32, 2, 13], [29, -11, 13], [-54, 13, -7], [54, -11, 5], [17, -4, 9], [-12, 0, -5], [-18, 6, -4], [16, -3, 22], [-65, 9, -8], [-50, 4, 10]];
    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_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_4056_2_a_z(:prec:=3)
    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_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_4056_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4056_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, -15, 0, 1]>,<7,R![36, -18, -3, 1]>],Snew);
    return Vf;
end function;