
// Make newform 4056.2.a.ba in Magma, downloaded from the LMFDB on 23 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_ba();".
// 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_ba();".
// 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, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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], [1, -1, 0], [-1, 1, -2], [0, 0, 1], [0, 0, 0], [-1, 1, -1], [-1, 1, 1], [-1, 1, 0], [1, -4, 3], [3, -6, 5], [4, 1, 3], [-2, 6, -1], [-5, 4, -2], [-5, 1, 3], [6, -4, -1], [-8, 2, -8], [1, -1, 7], [-6, -1, 4], [1, 4, -1], [3, -1, 2], [-10, 5, -8], [-4, -1, 1], [4, 5, -4], [13, -2, 0], [-3, 9, -10], [2, -12, 4], [6, -2, 9], [6, -10, 3], [-10, 7, 3], [-1, -4, -4], [-9, -6, -1], [5, -12, 2], [-8, 2, 7], [2, -3, -10], [-13, 1, -6], [-7, 0, 6], [-10, 7, -14], [5, 0, -8], [-5, -6, -5], [-13, 3, 0], [-18, 3, -6], [-6, 15, -10], [-1, 12, -4], [-2, 5, 7], [-16, 7, -10], [-1, -6, 9], [6, -6, 5], [15, -16, 18], [-5, 6, -7], [-3, 5, -5], [-6, 1, 3], [12, 1, -10], [-1, -1, 7], [-4, 9, -10], [2, -1, 16], [-3, -5, -1], [-8, -1, -1], [-10, 0, -17], [17, 5, 4], [-3, -17, 5], [-7, -3, 4], [-15, 4, -7], [0, -13, 2], [-3, 7, 15], [6, -19, 12], [-8, -6, 5], [-19, 10, -11], [10, -7, 3], [2, 8, 4], [2, 9, 8], [10, -7, 10], [-18, -3, 2], [6, -12, 5], [-20, 7, -3], [12, -5, 2], [-15, 6, 4], [-17, 17, -1], [-5, 10, -19], [1, 15, -6], [-3, 16, 2], [11, -7, -15], [-2, -1, -14], [-1, 19, -13], [7, -22, 13], [5, -5, -7], [11, -25, 19], [23, -21, 18], [-9, -2, -8], [-24, 12, -24], [25, 2, 0], [18, -17, 9], [-3, 16, 0], [6, 0, -17], [-4, 14, -2], [13, 1, -12], [-20, 20, -18], [9, 12, 6], [-1, -9, -8], [-12, -6, -11], [-20, 17, -3], [-13, -14, 7], [-6, 25, -5], [14, -12, 29], [-19, 15, -8], [4, 19, -19], [-8, 4, -10], [6, -4, -10], [-20, -7, -10], [25, -12, -10], [19, -14, 23], [-2, 1, -5], [26, 4, -8], [-21, 1, -13], [14, 11, -7], [25, -15, 32], [-9, 7, -9], [20, -8, 19], [-6, 25, -24], [12, -14, -19], [6, -3, 24], [4, -20, 13], [18, 15, -7], [37, -9, 12], [10, -34, 7], [-2, 18, 15], [35, -14, 27], [20, 12, -8], [22, 5, 3], [-2, -11, 10], [6, -7, 25], [11, -21, 9], [21, -17, 22], [12, -4, 7], [6, -25, 4], [6, -26, 14], [-25, -3, -12], [-6, 6, 17], [14, -26, -6], [-5, -8, -28], [5, -11, 15], [-12, 18, -9], [9, 9, 0], [19, -14, -1], [9, -17, 20], [35, -8, 12], [19, -19, -16], [8, 24, -14], [1, 27, -16], [-19, 25, -17], [-3, 8, 6], [29, -25, 25], [-31, 29, -21], [41, -26, 43], [12, -18, 15], [25, -18, 9], [4, -36, 5], [-11, -8, 12], [10, 21, -14], [-38, 10, 5], [14, 18, -3], [44, -27, 38], [6, -15, -11], [25, -16, -20], [-8, -5, 13], [20, -17, 28], [-34, 32, -37], [8, -9, -12], [10, 0, -2], [-2, 13, 3], [23, 7, -1], [-5, 24, -11], [-12, 36, -25], [16, -1, -17], [-14, 5, 19], [-13, 8, 12], [-15, -7, -8], [-1, 2, -19], [-12, 7, -9], [-7, 7, 4], [-11, 16, -28], [-6, -2, 4], [-2, -26, 21], [9, 27, 0], [-15, 9, -21], [-36, 17, -18], [3, 5, 13], [-36, 19, -12], [17, -19, 1], [0, 7, 29], [27, -8, -3], [11, 6, -6], [29, -21, 35], [-26, -11, 11], [16, 0, -2], [-3, -16, -9], [7, 33, -2], [-48, 24, -22], [-29, 42, -34], [45, -25, 42], [-28, -13, 7], [10, -11, 25], [-29, 3, -12], [-41, 15, -22], [-2, 11, -1], [-12, 27, -10], [15, -3, 8], [-32, 0, 5], [16, -12, 11], [9, -12, 2], [9, -36, 6], [13, -31, 6], [10, -4, 1], [-10, 1, -1], [-13, 31, -38], [-4, 16, 10], [7, -1, 13], [-34, 20, -14], [-8, -33, 2], [-34, 0, -18], [-16, 24, 2], [21, -30, 25], [-8, 11, 24], [6, -14, -25], [-38, 33, -46], [-26, 17, -6], [6, -13, 11], [-14, -25, 4], [20, -23, -10], [-3, 0, -12], [1, -13, 12], [-45, 15, -20], [3, 33, 3], [-22, -5, -3], [15, 7, -10], [-38, -14, -3], [-2, -11, -17], [-16, -8, 30], [-39, -22, 7], [49, -22, 13], [36, 2, -1], [16, 41, -13], [-19, 12, -30], [-24, 34, -47], [32, -34, 27], [-2, -31, -6], [-1, -26, -1], [35, 12, 5], [-15, -3, -21], [-9, 0, 10], [7, -43, 9], [15, -26, 22], [-5, 17, 23], [-14, 7, 29], [-30, -2, -16], [55, -4, -2], [8, 21, -1], [-27, 17, 19], [-1, 12, 2], [46, -33, 53], [18, -13, 23], [35, -28, 36], [-43, 6, -7], [8, 3, 42], [-41, 21, -59], [-28, 26, -31], [-51, 16, -7], [22, -19, 23], [5, -19, 5], [-58, 14, -7], [52, -18, 5], [7, -28, -16], [15, 28, -12], [-24, -20, 21], [16, 34, -27], [-12, 14, -2], [38, -17, 16], [-6, -18, 37], [-18, -1, -34], [-2, 5, -31], [3, -38, 11], [27, 16, -9], [26, -1, 27], [32, 0, 1], [-4, 42, -4], [-40, 34, -46], [-14, -13, -37], [20, -47, 9], [17, -4, -18], [10, 23, 8], [-6, -8, 19], [47, -26, 13], [-11, 38, 7], [-4, -6, -40], [-20, 43, -33], [1, -51, 15], [15, 5, -24], [26, 4, -23], [-33, 53, -51], [43, -36, 13], [5, -1, 6], [-29, 14, -45], [-14, 30, -31], [-58, -5, -8], [-8, -4, 39], [8, -4, 21], [23, -30, 48], [3, -46, -5], [-11, 54, -3], [14, -32, 46], [-9, 16, 42], [-53, 14, -35], [-55, 35, -23], [35, -29, 35], [-8, 10, 27], [-52, 28, -22], [55, -21, 26], [11, -70, 26], [-23, -10, -13], [-66, 18, -15], [26, -42, 7], [-7, -2, -3], [17, -9, -7], [-11, 31, -17], [7, -26, 13], [6, 34, -2], [32, -6, 36], [-29, 11, -27], [3, 4, -45], [-7, -9, -15], [12, 22, -16], [-6, -18, 16], [-11, 37, -13], [-9, 53, -38], [-16, 32, 9], [54, -4, 4], [-43, 27, -3], [4, 8, -3], [45, -15, 13], [0, 24, -4], [-45, -21, 12], [18, 10, 25], [-8, 2, 9], [3, 1, -29], [-24, 9, 8], [-26, 28, 43], [-6, 3, -32], [-42, 0, 2], [-43, 30, -29], [16, -7, -37], [34, -3, 12], [-3, -5, -24], [-54, 24, 13], [-24, 8, 39], [-18, 50, 10], [8, -11, 24], [-13, -3, -28], [-12, 7, -24], [4, -62, 20], [-7, 10, -39], [37, 18, 0], [-20, -8, -31], [-16, -30, -21], [-31, 47, -10], [-20, 51, -2], [-21, 49, -31], [-63, 18, -42], [21, -8, 18], [45, -12, -16], [-7, -9, 5], [4, -26, 1], [-45, 26, 37], [-32, -32, 30], [25, 14, 23], [-5, 19, -34], [40, -36, 32], [42, -12, 1], [4, -21, 16], [15, -18, -18], [43, -42, 31], [31, -42, 8], [33, 9, -19], [92, -13, 22], [26, 0, -15], [34, -9, 6], [-8, -26, 13], [-36, -22, 10], [8, 9, 22], [-62, -5, 12], [25, -15, 44], [30, -26, 13], [13, 11, -21], [23, -30, -45], [42, -14, 60], [-8, -18, 42], [-42, 40, -64], [-1, 47, -19], [-47, 4, -29], [42, -21, -9], [42, 8, 12], [-14, -29, -5], [5, -20, 47], [-5, -24, 1], [15, 37, -4], [41, -20, 42], [31, -27, 12], [-12, -3, 17], [24, 50, -25], [22, 32, 20], [41, 10, -25], [-2, 25, 9], [42, 7, 1], [-46, 18, -32], [-10, 38, -23], [-21, 36, -53], [-8, 34, 19], [-67, -18, -3], [-45, 18, -50], [-61, -10, -12], [-32, 27, -16], [-17, 8, 27], [-18, 23, -34], [-69, -21, 4], [-27, 34, -21], [-6, 13, -4], [43, -35, 68], [14, 0, -35], [-57, 51, -54], [50, -49, 66], [-31, 27, -29]];
    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_ba();".
// 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_ba(: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_ba();".
// 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_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4056_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, -1, -2, 1]>,<7,R![-7, -7, 0, 1]>],Snew);
    return Vf;
end function;