
// Make newform 8016.2.a.p in Magma, downloaded from the LMFDB on 25 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_p();".
// 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_p();".
// 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, 5, -3, -2, 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], [-2, -1, 1, 0, 0], [2, 2, -4, -1, 1], [1, 4, -3, -2, 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], [-2, -1, -1, 0, -1], [1, -2, -1, 1, 0], [2, 1, -1, 0, -1], [1, -1, 1, 1, 2], [-3, 2, -2, -2, 2], [3, 3, 0, -2, 3], [2, 0, -1, -1, 2], [-1, 1, -3, -3, 1], [4, -3, 0, 1, -3], [1, -3, -3, 2, 0], [-4, 6, 1, 1, 1], [-1, 2, 1, 2, 5], [2, -3, -2, -2, -1], [1, -4, 3, 0, 0], [7, -2, -3, -2, -2], [-1, -6, -4, 5, -2], [3, -5, 1, -1, 2], [-5, 2, -6, -1, 3], [-1, 0, 0, -2, -1], [-3, -2, -1, 0, -3], [2, -4, 2, 6, -1], [-7, -5, -4, 2, -5], [-2, -1, -2, -3, -2], [2, -5, 0, 0, -6], [2, -2, -1, -1, -8], [-8, -1, -1, 2, -4], [2, -3, -2, 0, -8], [-2, -5, -1, -1, -4], [-6, 6, 2, -1, 6], [5, 7, 4, -7, 4], [-5, 0, -4, -10, -1], [1, -2, -4, -2, -1], [0, -9, 0, 3, -8], [-3, -6, -1, 1, -8], [7, -8, -5, 0, 0], [2, 3, 3, -5, -2], [-1, 0, 0, 0, 0], [5, 6, 9, -6, 4], [2, 0, -6, 5, -6], [-4, 4, 3, -2, 7], [6, -11, -1, -5, -3], [1, -7, -5, 2, 3], [-3, 3, -5, -3, -4], [-1, 2, 0, 8, -1], [4, 5, 0, -12, 8], [3, 2, 7, 9, 1], [9, 1, -5, -3, 2], [-4, 12, -3, -1, 0], [1, 3, 5, -4, 10], [-1, -5, 9, 2, -3], [4, 5, 7, -8, 4], [10, 3, 7, -6, 1], [10, 10, 12, 5, 14], [9, 1, 0, 1, 3], [0, 12, 7, -12, 9], [4, -14, -4, 15, -9], [6, 0, -3, 3, -7], [-6, 2, 0, -7, 10], [-1, 2, -1, 8, -4], [1, 4, 0, 3, 2], [3, 3, 3, 0, -4], [-7, -3, 1, -8, 2], [-3, 11, 0, 0, -4], [7, 3, 7, 2, 6], [12, 4, 0, -4, 3], [6, -2, 3, 9, 2], [-10, 6, -5, -8, -5], [-2, -11, -3, -1, -10], [-3, -18, -2, 6, -9], [-3, -16, 0, 5, -17], [2, 2, -3, -9, 6], [6, -8, -1, 14, -13], [21, -6, 1, 2, -8], [11, -3, 6, 9, 6], [-5, 9, -6, -3, -2], [16, -8, -1, -5, -5], [-1, -5, 3, -10, 4], [-3, -17, -6, 3, -16], [11, -12, 4, 8, 5], [5, -10, 3, 5, -5], [9, -5, -1, -5, 6], [13, -14, 1, -5, -6], [-6, 7, 1, -6, 2], [1, -8, 9, -6, -3], [12, -2, -2, 0, 9], [16, 9, 14, 0, 5], [1, 9, 13, 5, 10], [2, -18, 5, 11, -11], [18, 4, -1, -9, 19], [-1, 10, 1, -4, -7], [7, 1, -7, -8, -1], [8, -14, -4, 0, 0], [-9, 1, 0, 7, -7], [-3, 16, 6, -11, -1], [-7, -13, -16, 2, -14], [2, 0, -2, 8, -3], [13, -9, -3, -12, -9], [20, 12, 10, -5, 11], [-26, 17, 6, 3, 0], [-9, 3, -13, -11, -10], [-1, 16, 10, -1, 7], [4, 22, 11, -16, 3], [-12, -17, -4, 11, -20], [-16, 10, -8, 3, 15], [10, -9, -9, -7, 5], [-1, 16, 5, -15, 18], [-14, 5, -15, -15, 3], [6, -9, 13, 0, -6], [-12, 3, -12, -10, -10], [-3, 3, 8, -1, -11], [-13, -6, -5, -1, 5], [29, 4, -3, -2, 1], [-5, 11, -9, 0, -2], [-2, -2, 1, 11, 3], [5, 11, 1, -10, 19], [-8, 16, 9, 5, 3], [11, -7, 2, 15, -10], [-8, 14, -1, 10, 6], [-5, 10, 1, -5, 4], [19, 2, 4, -4, 20], [-5, 9, 4, -5, 4], [27, -9, -3, -7, 7], [-2, -1, -9, -3, 1], [-5, -5, 17, 3, 3], [-11, -5, -1, 2, -14], [0, -5, 4, 3, 7], [-9, -17, -5, 15, -6], [-16, 11, -1, 2, 3], [5, -7, 9, 1, 2], [-16, -18, -6, -2, -11], [6, 4, -3, -6, 8], [10, 3, 21, 9, 2], [0, -24, 7, 0, -13], [-6, -17, 9, 4, -2], [7, -28, -9, 1, -12], [-9, -3, 5, 2, -5], [-3, 2, -2, -4, 11], [-14, -4, -10, -1, -7], [10, 6, 4, -3, 3], [-14, 2, -6, -4, 11], [-3, 23, 0, -18, 18], [-13, 25, -11, -16, 21], [8, -5, -9, -2, -5], [14, 27, 13, -10, 26], [-4, 9, -6, -15, 15], [-29, 10, 4, 3, -7], [11, -4, -8, -13, -12], [-16, -6, -14, 1, -4], [20, -19, 7, 23, -8], [24, -16, 2, 7, 6], [3, -4, 10, 14, 12], [-6, 12, 5, -1, -10], [-14, 13, 3, -8, 22], [1, 11, 15, -25, 14], [11, 26, 15, 2, 21], [25, 1, -10, -12, 14], [9, 6, 0, 4, 2], [-24, 14, -1, -19, -1], [18, 5, 13, -8, -3], [6, 16, -15, 0, -6], [10, 6, 6, -19, -2], [27, -1, -10, 4, -5], [-28, 12, 10, 13, 1], [3, -2, -5, 7, -11], [14, -9, 18, 14, -7], [-15, 4, -6, -17, -3], [5, 6, 13, -1, 30], [-3, -9, 0, -4, -13], [7, 1, 1, -10, -1], [-15, -9, 6, 8, 7], [-4, -14, -4, 7, -8], [-14, 28, -4, -15, -4], [5, -19, -11, 15, -2], [11, -9, 2, 10, 9], [-9, -18, -16, 6, -15], [-6, -1, -3, -6, -8], [34, 1, 5, -14, 3], [-14, 14, -5, -19, -7], [-14, -5, 18, 11, -4], [-15, 18, 7, -17, 19], [-20, 8, -9, -14, -16], [-10, -16, -11, 27, -6], [-6, 10, 10, -6, 18], [7, 31, 15, -16, 22], [10, -13, -5, -4, -14], [-1, -9, -12, 3, -27], [-4, -35, -14, 25, -20], [-11, -23, -9, 13, -13], [2, 22, 9, -25, 12], [-25, 7, -10, -13, -7], [24, 15, -1, 1, -1], [-13, 19, 5, -24, 9], [-16, 23, 2, -12, -10], [15, -13, 6, 3, -9], [-10, 3, 0, 2, 2], [17, 11, 2, 7, 10], [-34, 12, 7, 3, -9], [5, -1, -4, -14, 10], [18, 5, 16, 11, -3], [8, 23, 11, -10, 13], [19, -39, 1, 16, -9], [5, 3, -10, -21, 7], [39, -3, 1, 0, -1], [11, -7, -6, 9, -3], [7, 13, -7, -21, 23], [-7, 11, -2, -6, 39], [24, -11, -13, -4, 11], [26, -7, 8, 4, -9], [4, 1, -20, 4, 1], [-14, 6, -3, -16, -1], [22, -11, 3, -12, 4], [17, -19, 7, 15, -11], [-10, 3, -1, 12, 23], [-13, -26, -17, 15, -21], [-3, -18, -16, 16, -14], [4, -5, -6, 9, -21], [39, 3, 12, -8, 5], [22, 6, 4, -17, 4], [-19, 22, -1, 10, 27], [-10, -23, -28, 3, -18], [-14, 16, -6, -9, 22], [-8, 19, 19, 9, 9], [17, -21, -1, 16, -1], [-9, -9, -8, -19, -1], [39, -21, -4, 11, 1], [-2, -19, -15, 22, 1], [29, -12, 4, -2, -21], [-34, 5, 1, 0, 17], [-3, -14, 4, -2, -22], [24, -17, -11, -16, -5], [-27, 4, -4, 25, -4], [-2, 11, 7, -8, 16], [42, 5, 8, -2, 19], [-4, 23, -4, -3, -3], [-5, -27, -5, 0, -30], [-31, 3, 10, 7, 1], [-39, 7, -2, 9, 22], [-8, 11, 8, 1, -3], [-16, 5, 8, 11, -6], [17, 20, 20, -8, 29], [0, -10, 9, -6, -18], [7, 13, 19, -1, -3], [-24, 16, -3, 14, 0], [-11, 20, -13, -3, 28], [14, -12, 4, -8, -15], [17, 2, 24, 11, 8], [33, -12, 3, 13, -13], [-3, 16, 1, -3, 7], [-18, -7, 9, 21, -15], [-25, -2, -6, -5, 4], [30, 18, 13, -16, 12], [3, 20, 7, -7, 16], [2, -2, -22, 9, -10], [-2, -11, -2, 8, -26], [6, -30, -10, 28, 2], [23, -33, -2, 6, -14], [-19, -6, -18, 19, 6], [23, 16, 5, -6, 6], [0, 4, -5, -17, 6], [9, 12, 29, 15, 22], [4, -15, -8, -28, -7], [14, -8, 10, 23, -1], [-8, 12, 17, -16, 12], [18, -3, -1, 7, 0], [16, 21, 26, -16, 26], [-2, 11, 5, 20, -4], [8, -19, -11, 1, 13], [-21, 17, 12, -13, 18], [-5, 9, -14, 0, -11], [-19, -12, 4, 14, -10], [2, 3, 8, 14, -19], [-23, 3, 25, -8, 11], [-24, 28, 9, -12, -8], [-35, 15, 8, 6, 10], [-23, -37, -16, 19, -35], [-19, -34, -17, 27, -7], [9, -3, -10, -18, 8], [-1, -14, -9, -3, -29], [-15, 25, 5, -1, 2], [-24, 14, 3, -14, 17], [-12, 18, 11, 0, 2], [13, -21, 6, 25, 9], [13, 14, -9, 2, 17], [-5, 15, -20, 2, -9], [25, 24, 27, -4, 31], [10, -6, -8, -10, 5], [1, -7, -9, 2, 20], [7, 4, 2, 12, -4], [-35, 12, -13, -4, 13], [37, -26, 7, 17, -24], [-12, 5, 0, 20, -2], [-21, 20, -5, -11, 19], [7, -19, -29, -26, -14], [-5, -11, -25, -18, -32], [-1, -7, -13, -7, -23], [5, 19, -2, -6, -12], [-13, -6, 17, -5, 25], [-26, -14, -14, 18, 12], [26, 13, 3, -14, 18], [29, 12, -1, -11, -8], [-30, -2, 10, 9, 6], [-18, 0, -32, 5, 2], [19, -24, -12, 10, 11], [3, -11, 6, -9, 3], [-3, 6, 30, 0, 15], [32, 1, -2, -1, 8], [-31, 28, 13, 5, -9], [1, 20, 7, -13, 11], [-16, -11, -8, -5, -3], [-13, 14, 13, 29, 2], [-18, 21, 14, 11, 1], [-29, 15, 7, -3, 23], [23, -36, 15, 9, -19], [36, -25, 4, 30, -16], [35, 44, 18, -19, 30], [-35, -34, -10, 8, -32], [13, 4, 14, -21, 18], [-10, -9, -18, -12, -3], [34, -14, -17, 1, -13], [-4, 48, 3, -23, 5], [6, -25, 14, 2, -10], [24, -7, -11, -8, -25], [-12, -4, 15, 11, 20], [-3, -26, 12, 16, 3], [11, -3, 6, 38, 1], [-13, 11, 6, -24, 2], [40, -23, 10, -8, -16], [14, -28, -1, 10, -16], [2, 5, 12, -14, -12], [1, -1, -26, -5, 1], [-3, 46, 13, 9, 31], [-27, 0, 8, 5, -6], [14, -6, 7, -4, 17], [28, -11, 6, 14, -18], [22, 8, -3, 6, 8], [19, 11, 9, -19, 42], [32, -11, 14, 13, -20], [1, 4, 4, -32, -5], [-23, 6, -6, 7, 0], [-8, -35, -16, 22, -33], [17, -18, -22, -23, -11], [-3, -31, 6, 11, -22], [10, -21, -1, 11, 20], [-7, -15, -7, 14, -29], [-60, 24, -6, -8, 11], [8, -33, -5, 2, -14], [-1, -3, -9, -23, -1], [-35, 22, -9, -1, 30], [31, 11, 15, -7, 17], [8, 12, -23, -8, -23], [-29, 44, 4, -8, 8], [7, -31, -6, -4, -13], [29, -4, -12, 10, -15], [10, 15, 12, 8, 33], [31, -20, -16, 15, -11], [-12, -17, -7, 4, -10], [39, 22, 21, 1, 23], [-15, -1, 0, 33, -17], [-38, 0, 5, 12, -9], [-23, 38, 0, -1, 11], [-31, 2, -9, 21, 9], [-28, 19, -13, -27, 7], [-5, 3, 0, 5, -2], [19, -7, 17, -17, 5], [1, -3, -17, -2, -6], [-2, 1, -7, -27, 18], [-20, 41, -6, -36, 15], [-30, -5, -14, 4, 4], [31, -34, 7, -5, -8], [54, 18, -1, -17, 25], [7, -19, -13, -11, -18], [-2, 0, 18, 5, 21], [-9, -15, -8, -34, -8], [3, -19, 10, -1, 7], [13, 29, 35, -5, 13], [16, 4, 3, -26, 27], [26, -24, 0, 10, -20], [-8, 19, 17, 0, 23], [5, -20, -3, 32, -40], [2, -16, 18, 13, -28], [-7, 4, 29, 1, 13], [-25, -7, -14, -21, -16], [-12, 27, 2, 7, 10], [15, -42, 25, 12, -32], [-53, 26, -3, -20, 8], [-28, 2, -9, 5, 29], [-15, 23, 26, 18, 6], [20, 26, -3, -33, 21], [-2, 3, 35, 23, 5], [42, 12, 5, 12, 7], [26, 6, -9, -21, 22], [30, -25, 13, 27, -28], [7, -42, -13, 48, -33], [-28, 13, -3, -9, 19], [16, -5, 10, -17, 8], [-3, -45, -30, 4, -25], [1, 17, 16, -9, -18], [5, 22, 21, -36, 9], [-6, 15, 18, 28, 34], [-35, -12, -7, 13, 5], [-34, -2, 27, -8, 9], [-25, 10, 11, 7, -30], [16, -11, -1, -13, -13], [-6, -30, -27, 11, -37], [-7, 19, 28, 4, 5], [5, 49, 2, 12, 26], [-7, 15, -25, -18, 6], [54, 16, 7, 2, 7], [17, 4, -16, -7, -19], [28, -22, 18, 5, 8], [14, 12, -21, -15, 12], [-3, -15, 5, 10, 21], [9, -3, -19, -1, -10], [-10, -9, -4, 1, 19], [-7, -3, -22, 19, -31], [-2, -9, -44, -4, 1], [-23, -17, 0, 11, 4], [-2, 19, -3, -2, -18], [4, -2, -22, -21, -28], [-1, 30, -9, -4, 37], [34, -21, -4, 14, -8], [-23, -18, 5, -20, 8], [27, 24, 10, -4, 32], [19, 8, 2, -32, 19], [0, 13, 6, 11, 23], [-10, 15, -29, -29, 12], [-1, 26, -13, -2, 22], [44, -4, 20, -21, -21]];
    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_p();".
// 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_p(: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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8016_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-37, -39, 12, 25, 9, 1]>,<7,R![-83, 55, 49, -15, -4, 1]>,<11,R![761, -447, -36, 69, -15, 1]>,<13,R![687, 412, -32, -41, 0, 1]>],Snew);
    return Vf;
end function;