
// Make newform 4032.2.a.bx in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4032_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_4032_2_a_bx();".
// 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_4032_2_a_bx();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_4032_a();"
function MakeCharacter_4032_a()
    N := 4032;
    order := 1;
    char_gens := [127, 3781, 1793, 577];
    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_4032_a_Hecke(Kf)
    return MakeCharacter_4032_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, 0], [1, 1], [1, 0], [1, 1], [0, -2], [-3, 1], [2, -2], [-1, 3], [6, -2], [2, -2], [0, 2], [-5, -1], [4, 4], [6, -2], [8, 0], [2, 2], [0, 2], [8, 0], [5, 1], [-6, -4], [4, 4], [-4, -4], [-9, 3], [2, -4], [11, 3], [14, 2], [9, 1], [2, 4], [-4, -4], [0, -8], [-16, 0], [-6, 2], [4, -4], [0, -8], [12, -4], [-12, -2], [8, 0], [2, -6], [11, 3], [11, -5], [4, 2], [-11, -7], [8, 2], [-4, 4], [8, 0], [24, 0], [4, 4], [6, -10], [-8, -2], [-2, -10], [11, -1], [-10, 8], [-10, 6], [23, 3], [-17, -5], [1, 1], [-6, 6], [16, -2], [-2, 6], [-2, 2], [-21, -5], [14, 2], [-2, 6], [2, -8], [-12, -4], [0, -8], [6, -8], [23, -1], [16, 2], [1, 5], [-19, 1], [-8, 0], [-6, 8], [-24, 0], [32, 0], [6, -2], [4, -2], [22, -2], [-26, 0], [2, 2], [8, 6], [-11, 9], [2, 0], [4, -12], [19, -5], [-4, -4], [-18, 8], [3, 3], [0, 8], [-30, 2], [-14, -6], [-4, 12], [-13, -13], [20, 4], [20, 4], [-15, 9], [5, 9], [-16, 0], [-16, -10], [-12, -12], [-12, -4], [-2, 14], [-22, 2], [-20, -4], [-30, 0], [-6, -6], [-3, 9], [-27, 1], [18, -8], [-20, -4], [14, -12], [42, 2], [-20, 4], [0, 8], [-10, -18], [10, 6], [-26, -2], [-2, 6], [-15, -7], [-20, -2], [12, 14], [7, -17], [3, -5], [24, 8], [2, -6], [-6, 4], [28, -4], [-10, 10], [16, 14], [-40, 0], [-7, -19], [-24, 0], [10, 4], [-1, -5], [10, 8], [23, -1], [28, -12], [-17, 7], [-32, 0], [-24, 8], [28, 4], [28, -4], [-27, 5], [-36, 2], [-10, -2], [32, -6], [-1, -5], [-30, -2], [-33, -5], [-18, 12], [-19, 9], [4, 4], [26, 2], [-4, -4], [5, 9], [-36, -4], [-53, -1], [6, 4], [1, -23], [9, 9], [-16, 16], [24, -16], [-8, 8], [10, 18], [4, 4], [-36, 12], [-28, -10], [16, -10], [-5, -5], [17, -7], [20, -2], [5, -15], [4, 10], [-24, 0], [-11, -15], [-12, 4], [10, 2], [-6, -10], [4, -18], [12, 12], [-12, 20], [24, -10], [-3, -23], [-5, -1], [47, -1], [-2, 8], [-8, 24], [-28, 10], [-40, -8], [-26, -8], [1, 17], [24, 0], [15, -1], [-23, -7], [-23, 5], [36, 6], [-56, -2], [27, 15], [-6, 18], [24, 0], [20, 4], [-44, 2], [-14, -4], [4, -12], [-45, 3], [-20, 12], [13, -3], [-12, 20], [18, 14], [10, 24], [5, -19], [4, -12], [0, 16], [22, -2], [6, 20], [4, 4], [-31, -3], [-13, -1], [-26, -2], [18, -20], [22, 10], [8, 8], [8, -16], [0, -16], [-16, 2], [-17, -13], [-5, -25], [-6, 22], [3, -5], [-14, -12], [-2, 18], [4, -12], [44, -4], [30, -14], [16, 0], [-30, 12], [24, -16], [15, 7], [12, 12], [-13, -5], [-32, 0], [44, -4], [0, 26], [15, -21], [2, -6], [2, -18], [-42, -10], [4, 4], [-9, -21], [30, 8], [9, -11], [1, 5], [42, 12], [-25, 15], [-19, -11], [40, -10], [42, 6], [-37, -5], [30, -20], [36, 4], [7, -9], [-8, 14], [8, -6], [53, 1], [-44, -4], [-16, 8], [17, 5], [36, 4], [18, 10], [28, 6], [16, -8], [-38, 12], [0, 8], [-10, 24], [38, -6], [-47, -7], [8, -30], [-8, -22], [30, -18], [60, -4], [48, 8], [4, -12], [-12, -26], [40, 8], [-27, -7], [22, -8], [-52, 4], [-38, -10], [3, 15], [-16, -8], [32, 0], [18, -6], [14, 30], [26, 16], [23, -17], [40, 0], [-7, 9], [38, -10], [-44, 12], [46, 12], [-46, -6], [16, 8], [29, -3], [12, 12], [6, 8], [3, -13], [0, 14], [45, -15], [40, -6], [-60, 4], [2, 10], [-2, -26], [12, -20], [11, 23], [-38, -4], [60, -4], [-5, 15], [34, 12], [-42, -2], [46, -14], [-20, -10], [-29, 3], [28, 12], [8, -24], [-58, -8], [-64, 8], [50, -2], [25, -27], [14, -10], [-26, -16], [-18, 22], [10, -26], [-14, 34], [40, -16], [2, 18], [22, -12], [-13, -17], [2, -12], [2, 14], [34, 0], [30, 6], [25, -7], [16, 8], [-14, -22], [-55, 9], [-12, 34], [44, 12], [4, 20], [-41, 15], [18, -2], [-24, -10], [48, -8], [84, 4], [-14, -16], [-75, 1], [-12, 36], [16, -16], [-12, 4], [-59, -15], [-6, -8], [-37, -1], [77, 1], [-43, -3], [-56, 8], [-60, 14], [-43, -11], [-4, 12], [8, 10], [-13, -21], [30, -30], [57, -3], [56, 0], [42, 22], [-8, 14], [-40, -24], [27, 7], [10, 24], [-59, 17], [58, -4], [-5, 35], [-32, -16], [-40, 16], [-4, -36], [-56, 8], [-16, 16], [20, 20], [32, -10], [36, -12], [-22, 18], [-44, -14], [5, -11], [-11, 13], [14, 34], [-3, -7], [-42, 0], [-24, 16], [13, -7], [4, 4], [90, 2], [20, -18], [-44, -12], [8, 0], [11, 31], [49, 17], [-8, -32], [-8, -18], [36, -12], [60, 4], [34, 2], [-26, -4], [-10, -18], [3, -13], [-60, 4], [36, 10], [9, -23], [11, 15], [-42, 10], [-11, -15], [-58, -2], [2, 10], [-24, -14], [-35, -7], [80, 0], [-26, 20], [23, 23], [-29, -5], [-22, -30], [-16, 16], [-6, -30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4032_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4032_2_a_bx();".
// 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_4032_2_a_bx(:prec:=2)
    chi := MakeCharacter_4032_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_4032_2_a_bx();".
// 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_4032_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4032_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, -2, 1]>,<11,R![-4, -2, 1]>,<13,R![-20, 0, 1]>,<17,R![4, 6, 1]>,<19,R![-16, -4, 1]>],Snew);
    return Vf;
end function;