
// Make newform 8016.2.a.u in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8016_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_8016_2_a_u();".
// 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_8016_2_a_u();".
// 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, 4, 0, -5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [1, 0, -4, 0, 1], [-3, 0, 5, 0, -1], [3, -4, -5, 1, 1]];
    Rf_basisdens := [1, 1, 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_8016_a();"
function MakeCharacter_8016_a()
    N := 8016;
    order := 1;
    char_gens := [3007, 2005, 5345, 673];
    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_8016_a_Hecke(Kf)
    return MakeCharacter_8016_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, 0], [1, 0, 0, 0, 0], [0, 1, 0, 0, 1], [1, 0, 1, 1, 1], [2, -1, 2, 0, 1], [-1, 0, 1, 0, 2], [1, 0, 2, 0, -2], [4, 0, -1, -1, 0], [0, 0, -3, -3, 1], [0, -4, 2, -2, 1], [4, -1, 1, -1, 0], [-4, 1, -3, 2, 2], [1, 0, -2, 1, 2], [3, -1, 4, -1, 0], [1, 0, 3, 3, 2], [2, 1, -1, 5, 1], [2, 5, -1, 5, -1], [0, -3, 2, -4, -4], [3, 6, -3, 4, -2], [-1, 5, 1, 8, 3], [0, 4, -1, 4, 3], [1, 3, -6, -3, 2], [1, -4, 1, -2, -5], [0, 4, 1, 5, 4], [-1, -1, 2, -1, 5], [-4, 0, -6, -1, 1], [-2, -4, 3, 5, 1], [-3, -9, 3, 0, 0], [-4, 0, 2, 1, -7], [6, -8, -1, 0, 2], [-5, 5, -4, 2, 2], [6, 5, -8, -1, 1], [8, -2, -1, -4, 1], [2, -8, -1, -2, -7], [-3, 11, -6, 3, -3], [7, -8, 1, -9, -5], [-4, 11, -3, 1, -1], [8, 2, 1, 4, 6], [1, 0, 0, 0, 0], [8, -7, 7, -3, -1], [9, 3, -4, 0, -2], [4, -5, 2, 1, 2], [-7, -2, -4, -2, -7], [-3, -1, -4, 2, -7], [5, -2, -3, -4, -2], [4, -2, -3, 2, 1], [2, -4, 10, 5, -1], [-6, 10, -8, 1, 2], [-5, -10, -1, -2, -14], [-4, 0, -1, 1, -11], [6, -3, 7, 4, -6], [11, -11, 10, -6, -3], [3, -5, 5, -6, 6], [2, 5, -12, -6, 5], [-1, 5, -4, -6, -6], [-3, 3, 9, 1, 0], [0, 5, 10, 9, 4], [0, 7, -1, -4, -1], [5, -6, -4, 3, -8], [7, 9, -2, 0, 6], [12, 3, 5, 11, 9], [-6, -7, -2, -4, -6], [-6, 5, -9, -6, 2], [2, -3, 3, 6, 0], [-7, 8, 2, 7, 3], [12, -3, 1, -2, -8], [3, -16, 9, -10, 1], [0, -12, -1, 1, 11], [-4, 5, -20, -5, -4], [2, -8, -1, -4, 10], [0, 0, 9, 4, 1], [-1, -7, 7, 10, 3], [-12, -8, 5, 7, -3], [6, 15, 2, -7, -4], [0, -9, 9, 1, 1], [10, -1, 10, 13, 9], [0, 3, 8, 7, -5], [-5, -8, -2, -1, -2], [2, -1, -9, -8, -8], [10, 1, 12, -1, -1], [24, 4, -3, 0, 3], [10, -18, 2, -3, 12], [5, -6, -3, -16, -10], [-1, -8, -7, -5, -11], [-1, -1, -3, -6, -12], [-13, 1, 6, 7, -2], [1, -8, 3, -2, -3], [3, 4, 17, 3, 8], [5, -6, 3, 8, -10], [1, -2, -8, -7, -2], [-3, -8, 8, 3, 10], [-9, -17, 6, -3, -12], [-17, 3, 6, 4, -1], [12, 8, 0, 6, 10], [-7, 11, 3, 19, 12], [-3, -1, -3, -8, 17], [-3, -10, -8, 3, -1], [-7, -10, -1, 2, 9], [-13, 3, 6, 6, 5], [-6, -11, -7, 0, 3], [-3, 3, 0, 5, 9], [9, 0, 5, 8, -2], [13, 9, 5, -8, 1], [2, 13, -12, 3, 0], [9, -7, 6, 5, -3], [-18, 5, -11, -8, -19], [9, -10, -4, -8, 1], [7, -8, 5, 11, 15], [19, 6, 0, 12, -7], [-15, -7, -9, -2, 4], [0, -4, 22, 9, -1], [-13, -7, 1, -3, 6], [2, 14, -14, -5, 0], [5, 7, -4, 13, 10], [8, 15, -7, -4, 6], [15, 18, -4, 5, 4], [11, -7, -18, -6, -3], [7, 4, -16, -9, 2], [16, -7, 10, -3, 9], [7, 3, 19, 3, 1], [-11, 8, -5, 1, -7], [-13, 6, -6, 4, -4], [-8, 11, 2, 3, 5], [8, 16, 2, 2, -3], [13, -4, -10, -22, -9], [-4, 6, -4, -20, -11], [-4, 15, 5, 18, 12], [8, -17, 5, -9, -14], [-11, 12, -13, -2, 0], [-10, 11, 12, 16, -5], [7, -16, -11, -2, -4], [11, 2, -5, -18, -7], [5, -7, -5, -3, 1], [-8, 22, -1, 16, 8], [26, -7, 12, -3, -8], [-27, -15, 17, 6, -8], [-9, -2, -15, -23, -17], [1, -15, 14, -4, -17], [-20, 6, -5, 4, 5], [16, -1, 3, -6, -3], [8, 17, -5, 4, 3], [-21, 6, 1, 4, 13], [-23, -14, 0, 3, -11], [-17, 7, 6, 0, -1], [-20, 13, -18, -6, -3], [-1, 13, 3, -2, 16], [-4, -3, -7, -3, 16], [9, -9, 9, 0, 15], [4, 11, -4, -18, 0], [-15, -5, 6, -10, 2], [-4, -14, 3, -16, -10], [-15, 13, -6, 14, 22], [7, -8, -10, -26, -10], [-18, 2, -9, -5, -17], [23, 11, -11, 6, 4], [5, -10, -15, -12, 6], [-3, -29, 16, -9, -10], [17, -2, -2, -9, -9], [-9, -10, 8, 12, -2], [9, 10, 6, -1, -2], [-6, -27, 14, -14, -15], [5, 19, -19, -1, 5], [-15, -1, 0, -10, -18], [2, -18, -5, -19, -6], [-14, 11, -23, -6, -13], [2, 8, -6, 7, 20], [-1, 14, 9, 5, -26], [-1, 19, -15, 0, 11], [11, 8, -15, 3, 5], [-22, -18, 5, -7, -8], [7, -19, 0, 0, 13], [-10, 16, -7, 13, -6], [9, -9, 0, -12, 8], [-7, 9, -8, -10, -12], [-15, -6, -3, 2, 4], [10, -10, 33, 7, 0], [-12, -16, -1, -14, 15], [1, 21, -25, -6, 2], [-14, -11, -14, 8, 7], [21, -14, -6, 3, -4], [11, 1, -16, -5, -13], [18, 6, -20, -9, 10], [5, -9, 1, 7, 15], [2, 2, 7, -17, 3], [-12, 8, -16, -12, -14], [6, 19, -31, -6, 4], [-5, 15, -3, -8, 14], [21, -3, 1, -15, -2], [23, -9, 8, 17, 13], [24, -6, 28, 22, 13], [8, -10, 17, 3, -1], [9, 5, 7, 17, 14], [-5, 18, 0, 26, 15], [-23, 3, -6, 6, -3], [10, 8, 6, -1, -5], [19, 7, -5, -15, -8], [4, 2, -28, -17, 3], [8, -3, 18, 15, -7], [1, -8, 8, -13, 14], [-15, -6, -24, 3, -13], [-12, 3, 15, 5, -10], [-4, 11, 10, 0, 5], [-5, -21, 14, -16, 11], [-1, -3, 3, -9, -6], [21, -1, 16, 4, -7], [3, -19, 1, -9, -16], [4, -2, 4, -12, -9], [6, 2, 19, 31, -2], [38, -15, 12, 2, 11], [13, 10, 7, 29, -2], [-23, 2, 13, 9, 0], [-18, -9, 10, 13, -4], [-23, 3, 1, 2, -14], [28, -4, 18, 2, -1], [10, 3, -6, -22, -17], [-14, -8, -14, -3, -24], [3, 14, -4, -8, 2], [-12, -9, -17, -25, -10], [-6, 10, -9, 5, 2], [11, 3, 18, 14, 8], [5, -31, 20, -11, -12], [-17, -33, 12, -9, -11], [-9, 17, 6, 2, 2], [-31, 2, 2, -14, 9], [33, 17, 2, 8, 33], [1, -13, -1, -7, -8], [19, -27, -9, -17, -20], [-22, -7, 4, -16, -9], [-22, -16, -5, -12, -5], [18, 29, -18, 6, 5], [-7, -8, 8, 0, 6], [8, -23, -12, -16, 7], [-20, 11, -12, 6, -14], [17, -11, 25, -4, 8], [-5, 16, 15, 5, -2], [-12, 9, 15, 19, -12], [-20, 1, 1, 0, 2], [3, -13, 5, 9, -6], [18, 7, -28, -11, 1], [-16, 9, 31, 25, -2], [11, 23, 0, 1, -7], [-16, -22, 11, 4, 1], [-23, 13, -15, 3, 1], [-16, -16, 0, -26, -21], [-7, -13, -5, 1, -9], [-21, -2, -15, -13, -11], [-3, 2, -29, -20, 9], [8, 27, -4, -6, 16], [-18, -6, -14, 11, 2], [10, -8, 14, 11, -14], [-3, 4, -28, -6, 9], [-36, 11, -14, 0, -12], [-5, 31, -9, 13, 9], [9, 4, -3, 13, 5], [-11, -5, -6, 20, 8], [12, 12, -6, 9, -15], [2, 26, 0, 8, 2], [11, 0, 2, -11, -7], [-8, 29, -16, -4, -4], [-18, 23, -11, 27, 11], [14, -20, 17, -5, 1], [-25, 22, -15, 31, 27], [9, 22, -9, -19, 6], [-24, -15, 25, 8, -17], [19, -3, -5, 17, -9], [2, 14, 11, -8, 2], [8, 10, 16, 15, -3], [-45, 7, 7, 6, -2], [-35, 14, 8, 2, -1], [34, 3, 20, 11, -5], [18, 14, -21, -3, 14], [17, 14, 10, 16, -14], [1, 4, 7, -13, 0], [23, -1, 18, 18, 25], [-5, -15, -9, -37, -19], [1, 26, -16, 27, -3], [-7, 7, 13, -13, -8], [18, -34, 0, -39, -22], [-59, 12, -8, -5, -9], [10, -8, 32, 15, 10], [7, 2, 21, -12, 4], [-2, 7, -36, -13, 8], [5, -31, 7, -5, -7], [23, -7, -5, -1, 20], [-29, -11, -2, 1, 18], [-18, -10, -19, -1, -24], [-9, 21, -22, -15, -10], [-43, 10, -11, -10, 1], [10, -3, 27, 6, -26], [19, -30, 4, -6, -2], [3, -21, 2, -29, -4], [-11, -10, -15, -13, 9], [12, 14, 0, 7, 19], [2, -24, -4, -19, 8], [38, 17, 1, 6, -4], [38, -27, 3, 0, 20], [16, -2, 18, -4, 3], [15, 20, 0, -7, 5], [-4, 10, -12, -3, 18], [10, 40, -10, 0, -8], [25, -15, 3, -6, 0], [9, 30, -19, 9, 15], [5, -29, 28, 14, 2], [7, -3, -8, -16, 20], [-22, -16, 21, 8, -5], [-43, 5, -5, 1, 4], [24, -10, 15, 12, 9], [1, 29, -24, 9, 5], [-14, 24, -18, -5, -2], [-4, 8, 22, 15, 14], [2, 3, 7, 25, 2], [13, 0, -3, -9, -25], [-14, -7, -3, -15, -34], [8, -26, -10, -40, -5], [-24, 26, 10, 9, 10], [-28, 6, -22, -5, -31], [28, 7, -4, -18, -10], [-27, -4, -2, 10, -10], [6, -13, 12, -8, -30], [-11, 26, -21, -3, 16], [19, 2, 10, 9, -8], [-37, -10, -4, 7, 12], [14, 2, 10, 7, -29], [-20, 29, -20, 6, 5], [0, -28, -5, -47, -13], [26, -18, 37, 10, 1], [20, 22, -1, -21, 2], [1, 14, -2, 25, 13], [-24, -28, -4, -3, -1], [25, 21, -15, 15, 17], [14, 2, 2, 5, -17], [-13, 39, 1, 13, 6], [-28, -22, 16, -5, -18], [56, 7, -2, -4, 6], [6, -3, -16, -33, -16], [-40, 2, -2, 5, 1], [7, -29, 23, -13, -11], [15, -16, -7, -22, -6], [-7, -23, -4, -27, -35], [50, -14, 21, -8, -5], [8, 1, 18, 34, -4], [-39, 22, -11, 13, 12], [-27, -5, 3, -4, -11], [-2, 25, -8, 3, -3], [34, -12, 7, -6, 18], [-1, -3, -28, -32, 5], [3, -32, -1, 6, -15], [11, 5, -3, 20, -6], [18, 6, -20, 2, -11], [11, -24, -5, -31, -11], [0, 50, -18, 26, 1], [-14, 7, 26, 15, 12], [13, -28, 22, -20, -24], [-12, -10, 5, -35, 4], [-24, -8, 37, 12, -3], [3, 36, -35, -9, -6], [-3, 31, -15, 18, -3], [-17, 19, -3, 6, -36], [-40, 8, -6, -15, 0], [13, 7, -43, -17, -6], [-10, 11, 24, 7, 8], [19, 19, 11, 10, 17], [-18, -14, -10, -17, -24], [-9, 4, -14, -16, -7], [4, -15, -6, -13, -31], [10, 34, -10, 0, -11], [18, -45, 41, -18, 8], [8, -34, 3, -16, 26], [29, 36, -7, -9, 12], [32, 18, -2, 9, -15], [-1, 14, -3, -17, 7], [-33, 4, -18, 17, 2], [-35, -12, 5, -2, -24], [4, -5, 7, -20, 13], [-7, 2, -10, -31, 21], [35, -11, -3, -9, -14], [-4, -8, 14, 10, 23], [-4, -25, -18, 1, -6], [-4, -26, 4, 12, 4], [6, 19, 18, 18, -3], [-10, 3, 31, 27, 17], [-25, 7, -2, 16, 0], [38, 18, -6, 17, 14], [-34, -27, 12, 13, 11], [51, 1, -6, 3, -7], [-22, 11, -19, -35, -27], [16, 5, -31, 5, -7], [-33, -2, 18, 15, 8], [21, 24, -26, -15, -7], [3, 34, -10, 5, -10], [-25, -2, -26, -6, -9], [-18, 27, -10, 27, 14], [-42, 14, -5, 11, 15], [-8, -40, 9, -6, -10], [7, -39, 18, -29, -8], [-15, -20, -2, -42, -7], [13, 5, -24, 11, 3], [4, 16, -37, -13, -6], [-12, -41, 10, -31, -5], [-15, -29, 18, 5, 4], [0, -26, -22, -7, 13], [12, -22, -16, -37, -28], [-10, 17, 24, 27, 20], [-13, 12, -25, 7, 11], [3, -20, 26, -6, -7], [-13, 6, 2, 9, -20], [-26, -4, -7, 17, 10], [-5, -2, -14, 3, 37], [8, 7, -7, 22, 20], [-30, 3, 36, 13, 0], [-27, 35, -29, -4, -7], [-35, -17, 28, 24, -2], [-18, 4, -7, 5, -37], [-25, 1, 8, 12, -15], [-7, 12, 23, 22, 14], [24, -15, -15, -7, 24], [19, 13, -17, -33, 4], [35, 10, 17, -1, 30], [-30, -5, 2, 5, -37], [-17, 21, -33, 22, -4], [-5, 1, 24, 20, -26], [11, -13, -34, -7, 6], [-34, -12, 14, -31, 15], [-22, -9, 3, -19, -13], [17, -58, 6, -22, 14], [-30, -18, -5, -22, -1], [2, -15, -21, -11, 20], [2, -28, 3, 6, 2], [16, 17, 27, 19, -5], [-44, 27, 9, 36, 11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8016_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8016_2_a_u();".
// 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_8016_2_a_u(:prec:=5)
    chi := MakeCharacter_8016_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_8016_2_a_u();".
// 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_8016_2_a_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8016_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, 17, -2, -9, 1, 1]>,<7,R![13, -37, 29, -3, -4, 1]>,<11,R![-121, -101, 92, -3, -7, 1]>,<13,R![17, -48, -66, -1, 8, 1]>],Snew);
    return Vf;
end function;