
// Make newform 8016.2.a.q 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_q();".
// 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_q();".
// 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, 5, 3, -6, -1, 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, 3, -5, -1, 1], [4, 3, -6, -1, 1], [-6, -11, 11, 3, -2]];
    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], [-1, 0, 0, -1, -1], [1, -1, 0, -1, -1], [1, 2, 0, 1, -1], [-1, 1, 1, 1, -1], [-1, -2, 0, 0, 0], [1, -1, 2, -2, -1], [2, 1, 0, -1, 1], [-3, 0, 0, 1, 2], [1, -1, -2, 0, 2], [-2, 1, -1, -1, 0], [-2, 0, -1, -3, -2], [-2, 2, -3, 3, 1], [4, -3, 0, 4, 1], [-4, -1, 2, -1, 2], [2, -3, 2, 1, 2], [-2, 2, 2, 4, 3], [-1, 3, 3, -3, -1], [6, -1, -1, -2, 2], [-3, 3, -1, 0, 1], [0, 4, 1, 5, -1], [2, -3, 1, 2, 3], [-5, 3, 4, -2, -1], [3, 0, 1, -2, -1], [-2, 0, -3, 4, -2], [0, 1, 6, -1, 1], [5, 1, 3, -3, 0], [-8, 0, -7, -2, 2], [0, -3, -1, 1, 1], [-1, 2, -2, 4, 3], [-2, 2, -3, -2, -1], [1, 3, 3, 6, 5], [-9, -3, -3, 2, 5], [1, -4, 5, 0, -1], [-1, -1, 2, 1, 1], [-2, 3, -8, 1, 4], [-6, 3, -5, -3, -7], [1, 0, 0, 0, 0], [2, -5, -2, -7, -4], [-3, -2, -4, 2, -1], [3, -2, 3, 3, -5], [4, 2, -4, -3, -4], [6, 0, 0, -9, -7], [-1, 7, -1, 7, 7], [-3, 1, -3, -4, 1], [-6, -6, -3, 6, 4], [-7, -2, 3, -1, 2], [-1, 3, 1, 3, -1], [-6, -3, 6, -1, 3], [4, 1, -1, 1, 2], [2, 6, -4, -1, 1], [-1, 1, 1, -1, -8], [-1, -8, -4, -7, 3], [5, -8, -2, -8, 3], [-4, 5, -6, 10, -2], [-7, -4, -1, 11, 5], [1, -9, 3, 0, 0], [-2, 6, 1, 1, -2], [1, -2, -6, -6, 1], [-6, -11, 2, -7, 0], [-2, -2, -6, -2, 9], [-14, 7, -1, -1, 2], [-2, -7, -1, -5, -2], [-1, -8, 1, 6, 0], [-14, 3, -1, 7, 12], [-18, 3, -5, 8, 9], [-8, -3, 2, 1, -1], [3, -2, 3, 1, 7], [-4, 3, 1, 11, 11], [1, 1, 5, 4, -7], [10, 3, 5, 0, -8], [-2, 11, 0, 1, -9], [5, -8, 1, -3, 9], [-2, -7, 4, -1, -6], [4, 16, 5, 8, -5], [-6, 6, -7, 4, -5], [-2, 2, -7, -5, -12], [8, -3, 5, -1, -8], [-16, 2, -5, -10, -9], [-13, -1, 1, -4, 1], [-3, -2, 3, -9, -2], [7, 9, 11, 5, -7], [7, -5, 2, -13, -3], [-5, -3, 1, -9, -8], [-12, 4, -15, 5, 3], [-14, 7, -11, 0, -1], [4, -1, 4, 0, -3], [3, -3, 3, 3, -3], [-8, 0, 3, 9, 12], [-6, 10, 1, 11, 4], [-4, 0, -5, 1, 13], [-14, -4, 0, -3, 7], [-20, 4, -6, 8, 8], [0, -9, 2, 0, -6], [0, -7, 9, -6, -8], [-5, 6, 1, 4, 8], [-12, 9, -7, 12, 11], [-14, -6, -4, -3, 5], [5, -11, 3, -10, 6], [1, 6, 1, 0, 1], [-9, 3, 1, 5, -7], [0, 1, 9, -10, -6], [1, 10, 7, 7, -5], [-11, -4, -5, 14, 9], [-13, 7, -1, 14, -4], [6, -16, -2, -15, -4], [3, 5, -10, 17, 1], [-4, -2, -2, 3, -8], [3, 3, -1, 19, 6], [4, 14, -5, 2, 6], [8, 5, 0, -2, 6], [-3, 18, -5, 7, 6], [-4, -6, -5, 3, -3], [-8, 17, 1, -1, -6], [2, 14, -11, 5, -2], [-14, 4, -6, 5, -3], [16, 8, -9, 13, 2], [10, -4, 1, -4, -1], [-1, 1, 4, -7, 2], [-9, -15, -6, -3, 5], [5, 10, 0, 6, 2], [-12, 8, 7, -6, 5], [-9, 10, -6, 5, 6], [6, -6, 2, -23, -4], [-9, 14, 8, 13, 2], [12, 1, 3, -3, -14], [1, 7, 0, 12, 10], [5, -7, -1, 7, -5], [11, -14, -4, -17, -9], [11, 15, -7, 5, -7], [8, 5, -9, 2, 9], [5, 11, -10, 13, 4], [-18, -5, -7, 11, 7], [1, -12, -1, -19, -7], [-1, 1, 5, 1, 6], [-19, -3, 0, 7, 3], [20, -4, 8, 1, -11], [-3, 9, -3, 14, 1], [-7, 15, -7, 6, 0], [1, -13, 11, -4, 10], [16, -9, 1, -4, 13], [-5, -4, 3, 0, -8], [10, 12, -4, 3, 1], [-25, -10, 4, -7, 3], [1, -7, 5, -13, -6], [3, -7, -4, -20, -14], [-4, -3, 13, -4, -6], [2, -10, 12, 2, 13], [11, -12, 8, -14, -7], [-16, -13, 5, -15, -9], [-17, -10, -8, 2, 17], [-1, -14, -10, -6, 6], [8, -17, -8, -3, 1], [-5, 13, 9, 19, 10], [15, 5, 3, -11, -15], [10, -16, 1, -23, 1], [-5, -16, -1, -2, 10], [-5, -16, -10, -6, 4], [-8, -4, 9, -17, -4], [11, -14, -2, -25, -7], [-7, 1, 0, 11, 4], [13, 14, -10, 4, 5], [9, 3, 0, -10, -11], [-7, 7, 11, 12, 8], [25, -14, -7, -11, 2], [26, -5, 2, -4, -5], [-2, -9, 3, 12, 10], [-17, -25, 2, -5, 9], [9, 19, -4, 6, 1], [4, -2, 14, 11, 1], [-11, 1, -8, -16, -7], [-9, -6, 4, -20, -9], [1, 4, -6, 8, 13], [29, -1, 13, 5, -1], [7, -5, 6, 4, -3], [19, -13, 3, 0, 1], [-13, -7, 1, 3, 0], [-11, -6, 4, -3, -5], [-6, -12, 19, -9, 0], [21, -6, -3, 10, -3], [-7, -2, -9, 15, 6], [17, -13, 8, 19, 8], [2, -9, 10, 3, -1], [2, -20, 0, -22, -8], [-24, -1, -1, -1, -2], [-19, 1, -1, 17, 2], [6, 3, -6, 16, 0], [-27, 6, -11, 6, 21], [35, -8, 4, -21, -2], [-24, 15, -4, -1, 11], [4, -3, -8, 8, -8], [4, 2, 4, -19, -12], [10, -8, -4, -17, -25], [-8, 22, 1, 24, 8], [14, 1, -2, -14, -6], [-16, -18, -1, -12, -4], [0, 0, -15, 10, 1], [24, -8, -3, 3, 2], [5, 4, -7, -10, -12], [39, -5, 12, -6, -10], [9, 6, 8, 3, -15], [-20, 14, -8, -11, -13], [-40, 1, 0, -4, -6], [-38, 2, -10, 15, 11], [-4, 15, -6, 2, -10], [21, 12, -6, 1, -6], [-21, -7, -10, -16, -5], [13, 16, -6, 7, -9], [-10, 3, 10, 2, 13], [6, 21, -4, 6, -5], [13, 6, -7, -5, 9], [-1, -11, -3, -19, -16], [9, -2, 6, -21, -10], [9, -2, -2, -3, 15], [1, -10, 11, 7, 0], [7, 8, -4, -10, 4], [-7, -3, 4, -18, 2], [17, -15, 8, 2, 19], [15, 2, -4, 4, -13], [22, 2, 25, -1, -17], [-13, 22, -7, -4, 7], [-7, -6, -20, -10, 9], [-8, -20, 2, -11, -6], [-6, -8, 0, -15, -13], [36, -1, 6, -14, -22], [32, 1, 8, 0, -4], [21, -6, 10, 1, 3], [-5, 9, -1, 18, 17], [15, -2, -10, -13, 5], [13, 8, 2, -2, 6], [-11, 6, 14, 7, 13], [12, -6, -10, -10, 7], [7, 11, 13, 1, -6], [-16, 7, -2, -6, -1], [43, -7, 18, 0, -6], [-12, 9, -3, 9, 20], [12, -25, -4, -18, 0], [-12, 6, 15, 12, -15], [-9, 15, -14, -2, -18], [-15, -18, 3, 4, -1], [-21, 11, 13, 4, 11], [27, -3, 18, -15, -14], [-9, 16, 12, -7, -10], [37, -5, 10, 1, -2], [-25, 5, -14, 11, 7], [-4, -5, -5, -12, -25], [22, -6, -2, 4, -7], [11, -20, 3, 3, -8], [27, 2, 17, 3, -6], [8, -14, -6, 17, 12], [-30, 10, 2, -12, -5], [21, 17, 6, -5, -18], [-21, -21, -4, -21, -5], [-5, -2, 2, -2, -13], [-14, 18, -17, 4, -4], [16, 0, 12, 18, -2], [-15, 6, -9, 28, 12], [-6, 4, -10, -12, -11], [-14, 7, 14, -1, -12], [10, 11, 2, 23, 19], [-23, 5, 6, 7, 29], [-6, -15, -8, -18, -3], [23, -3, -9, 18, 6], [23, -13, 10, 13, 8], [10, -19, 21, -11, -3], [-18, 18, 3, -6, -6], [-11, -7, 5, -1, -6], [-18, 12, -8, 27, -4], [28, -2, 9, -18, -5], [-11, 5, -22, 18, 7], [-5, 14, -8, 0, 8], [6, -23, -6, -18, 7], [-14, 10, -24, -7, 9], [-31, 1, -16, -17, 0], [-1, -12, -5, 12, 0], [28, -9, 0, -26, 4], [-23, -22, -15, -7, 12], [7, 6, -5, -8, -2], [-11, 22, 7, -17, -8], [-9, -3, 1, -3, 1], [31, 18, 5, -9, -13], [-3, 13, 8, 5, 8], [4, 27, -12, 0, -8], [-54, 4, -19, -7, -3], [-11, -3, 4, 16, 11], [38, 2, 7, 15, 5], [16, -1, 3, 34, 17], [48, 3, 1, 3, 2], [-13, 16, 0, 8, -8], [-2, -10, -1, 1, 1], [33, -11, 2, -19, -19], [36, 2, 17, 12, 0], [9, -18, 13, -9, 4], [24, 13, 17, 5, -20], [10, 1, -9, 15, 10], [-21, 8, 10, 9, 18], [19, -22, -9, -28, -2], [15, 8, 13, -5, -14], [2, 22, -2, 30, 2], [-25, -5, 3, 15, 20], [-9, -11, -16, -21, -17], [-3, -2, -10, -16, -3], [3, -26, 16, -10, 1], [-5, -19, 11, 0, 15], [-10, 13, -10, 12, -14], [13, 3, 1, -12, -27], [-9, 6, 9, 6, -13], [19, -18, -7, 11, 2], [15, -14, -11, -21, -4], [1, 1, -4, 0, 0], [41, -15, -10, -1, -17], [25, 31, 8, 2, -14], [-19, 22, -12, 19, 12], [-13, 2, -13, -23, -12], [-34, 0, -15, 8, 22], [16, 6, -2, 2, -11], [43, 6, 6, -2, -14], [18, -12, 26, -26, -15], [16, -21, -28, -8, 3], [0, 8, -9, -5, 4], [-8, -16, -5, -9, 0], [-22, 20, -9, 22, 10], [-7, -34, 12, -17, -7], [-18, -1, -24, -3, 13], [-13, -5, 5, 2, 17], [-41, 15, 2, 0, -7], [-13, 18, -5, 0, 6], [0, -4, 1, 32, 6], [-31, 25, 6, 7, -10], [20, -16, 3, -20, 6], [12, 35, 4, -10, -24], [3, 16, -19, -1, -6], [2, -20, -20, -12, 1], [43, 6, 5, 3, -7], [6, 14, 7, 0, 2], [-19, 21, 12, 3, 6], [19, 15, 9, -23, -11], [-15, 38, 7, 4, -15], [-9, -23, -5, -16, 5], [52, -6, 12, -14, -9], [-18, -21, 8, -30, -7], [12, -23, 21, -14, -8], [-6, 30, -5, 30, 17], [-24, -3, -11, 9, 31], [16, 0, 4, -17, -1], [8, -23, -9, 8, 9], [31, 5, 19, -1, -12], [-3, -20, 20, -9, -14], [-1, -9, 10, -7, -3], [31, -4, -8, -15, -22], [11, 4, -1, -5, -15], [-7, 2, -16, 26, 8], [19, -9, 14, -18, -19], [-9, 1, -3, -4, -1], [-22, 25, -8, -2, 3], [-22, 29, -1, 4, -12], [17, 11, 3, 17, 12], [47, 0, 5, -13, 4], [-32, 17, -16, 14, -18], [17, 8, -13, 17, 1], [4, -7, -5, 4, -24], [21, -22, 5, -31, -20], [16, -20, 16, -23, -20], [24, -12, -7, 4, -13], [-31, -18, -4, -33, -22], [-14, -5, -3, 15, 10], [2, 5, -15, -13, 19], [-16, 5, 6, -4, 17], [10, 2, 9, -32, -16], [-53, 3, -2, -3, -17], [-26, 28, 5, -5, 2], [23, 7, 15, -19, -23], [19, -17, 11, 18, 16], [-5, -8, 11, 2, -6], [-8, 3, 8, -12, 10], [29, -14, -6, 23, 10], [11, 6, -9, -13, -41], [-24, 12, 0, 20, 22], [-5, -20, 4, 5, 5], [-28, 19, -12, 5, -26], [39, -6, 14, -16, -9], [-41, -26, -7, 3, 16], [14, -18, -17, 4, 1], [3, 0, 27, -30, -5], [24, -9, 8, -3, -10], [-2, -11, 0, 11, -24], [12, -12, 27, -17, 16], [-1, 30, 3, 20, -12], [-34, 14, -1, 37, 42], [-36, 6, 0, 7, 4], [-39, 14, -1, 19, 5], [10, -5, 18, 19, -3], [-12, -9, 5, 23, 7], [30, 4, 9, -1, -21], [28, 14, 0, -23, -2], [23, -26, -11, -26, -11], [-1, 13, 28, 4, -3], [12, 0, 11, 4, 5], [30, -20, 1, -25, -23], [12, 8, -1, -26, -2], [-17, -16, 1, 25, 0], [27, -18, 13, -5, -23], [-29, -5, -16, 7, -1], [-30, 2, -24, 15, 22], [-8, 6, -7, -15, -22], [13, -29, 4, -28, -13], [-39, -16, -9, -4, 2], [-2, -15, -11, -9, 10], [-23, 8, 7, 15, 7], [-24, -9, -9, -2, 4], [-35, -4, 0, 10, 29], [20, -15, -10, -29, -7], [32, 20, 16, 1, -15], [35, 7, 7, -5, -19], [-27, -13, 8, -8, -10], [30, -15, -10, -16, -24], [-22, 5, -10, 14, -9], [-34, 8, -15, -2, -11], [-39, 5, -19, 11, 22], [-41, -20, 4, -14, 7], [14, -8, -29, -5, -1], [14, -10, -17, 18, 12], [-24, 9, -30, 9, -6], [45, -22, 4, -18, -8], [-25, -7, -9, 26, 21], [-33, 11, -26, 0, 26], [20, -15, 17, 1, 11], [8, 31, -4, 29, 4], [15, 15, 11, -10, -6]];
    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_q();".
// 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_q(: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_q();".
// 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_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8016_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-9, -21, -6, 11, 7, 1]>,<7,R![-27, 27, 15, -11, -2, 1]>,<11,R![-243, 45, 84, -19, -5, 1]>,<13,R![27, -218, -124, -1, 8, 1]>],Snew);
    return Vf;
end function;