
// Make newform 8016.2.a.m 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_m();".
// 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_m();".
// 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 := [-10, -10, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-7, -1, 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_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], [1, 0, 0], [1, -1, 0], [0, -1, 1], [3, 1, -1], [-1, 1, 1], [1, 1, 1], [3, -1, 1], [5, -1, 1], [-3, -1, 1], [1, 0, 0], [5, -1, 0], [0, 2, -2], [1, 3, -3], [0, -1, 1], [-6, 0, -1], [1, -1, -2], [-4, 0, -4], [3, 1, 2], [1, 1, -3], [-7, 3, -1], [-2, 2, -2], [12, 2, -1], [2, -3, -1], [0, 3, -5], [4, 4, -3], [10, 2, 0], [6, -2, 4], [7, -3, 1], [-2, 2, -2], [9, -2, 4], [-5, 1, -1], [-8, -3, 1], [1, 1, -4], [-6, 2, 3], [-14, 0, -2], [2, -2, 4], [-4, 2, -5], [1, 0, 0], [-14, 0, 2], [-7, 7, 1], [7, -7, 1], [11, 2, 2], [9, 1, 5], [5, -1, 3], [-4, -2, 0], [-6, -4, 0], [6, 5, -3], [3, -5, 2], [8, -8, 0], [21, 0, -2], [4, -6, 0], [-9, 5, -1], [-5, 1, 5], [11, 3, -3], [-6, 5, -5], [3, 3, 2], [-7, -1, -1], [-16, 0, 3], [7, 6, 0], [-12, 6, -4], [-10, 2, -2], [2, 4, 1], [21, 0, 2], [-11, -5, 3], [17, -1, 5], [13, -1, 5], [-5, 6, -6], [5, -1, 2], [7, 5, 0], [1, -2, 2], [0, 6, 0], [8, -6, -4], [2, 0, -1], [0, 0, -1], [-2, 8, 2], [5, 1, -5], [-7, -3, 1], [-4, -2, -8], [6, -4, 8], [-4, -8, 4], [-3, -7, -3], [-9, 0, -4], [-11, -6, 0], [-14, 4, -2], [7, 5, -2], [4, -13, 5], [-8, -6, 6], [-9, 3, -1], [10, -4, 0], [6, 0, -4], [6, 0, 6], [-9, -3, 3], [14, -2, 2], [-17, 5, -1], [-10, -8, 6], [12, 10, -4], [11, 3, 1], [23, -1, 7], [-12, 8, 1], [-1, 9, -8], [3, 3, 3], [21, 1, 7], [-7, 5, -3], [4, 4, 7], [-12, 1, 3], [12, 0, 5], [13, 5, -1], [0, -7, 1], [10, -5, 5], [-10, 2, -8], [29, -1, -1], [8, 0, 2], [-5, 3, -9], [-11, -8, 2], [2, -8, 0], [-13, -7, -1], [4, -2, 0], [-6, 14, 2], [6, -8, -3], [-11, -1, 3], [-9, -7, -1], [7, -13, -1], [-11, 1, -7], [19, 1, 3], [-8, 8, -12], [-14, 8, -3], [-4, 4, -4], [-1, -1, -1], [-9, -1, 7], [2, -14, 7], [-20, -7, -1], [3, 9, 3], [-5, -5, -5], [-33, -4, 0], [43, 3, -3], [10, -8, 1], [19, 1, -1], [13, -13, 7], [8, 1, -3], [-3, 11, 2], [-5, 17, -3], [15, 7, -7], [3, -3, -5], [10, 4, -5], [-29, -6, 2], [0, 4, -8], [-19, -6, -2], [1, -13, 5], [-4, 4, -8], [-3, 15, -3], [10, 12, -6], [-1, -9, -5], [22, -14, 0], [-23, 3, -15], [15, -10, 2], [-28, 3, -13], [-29, 2, -4], [-17, 5, -3], [1, 11, -1], [16, -6, 10], [19, 5, 5], [-16, 8, 0], [4, 12, -5], [31, -3, -1], [-6, 8, -10], [-41, -9, 7], [9, -3, -5], [20, 5, 5], [44, 2, 2], [14, -6, 5], [14, 2, -8], [34, -3, 17], [19, 8, -4], [-10, 12, -8], [-24, -4, -2], [36, 2, 0], [-1, 1, -4], [-12, -8, -4], [-10, 10, 7], [21, -6, 2], [34, -2, 8], [-24, 10, 1], [-11, -17, 13], [-23, 11, 3], [-23, -5, 9], [19, -9, 15], [-1, 13, 1], [-17, 0, 2], [15, -15, -1], [-12, -2, -12], [22, -6, 5], [20, -4, 10], [-9, -17, 9], [-13, 13, -5], [0, 19, -13], [12, 5, -11], [-14, 8, -8], [-34, 3, 7], [45, -4, 6], [11, 17, -7], [5, 16, -14], [2, 14, -7], [10, 0, 10], [-15, -3, -3], [11, -9, 3], [19, -3, -1], [3, -1, 9], [-5, -13, 11], [-14, -12, -6], [-15, 8, -12], [-31, -9, 3], [-23, 3, 3], [13, -21, -3], [-14, 14, -2], [-17, 6, -2], [-15, 7, 7], [12, 12, 6], [5, 0, 16], [-17, -1, -6], [19, 19, -7], [1, 6, -14], [-12, -10, 12], [-14, 2, -14], [43, -11, 3], [26, -4, 0], [-28, -11, 11], [24, -8, 16], [-31, 15, -5], [-20, 16, -10], [20, 10, -1], [-21, 3, -17], [-39, 7, -13], [21, -15, -1], [20, -6, 18], [23, 15, -9], [24, 2, 12], [15, -13, 17], [34, -18, -1], [12, -16, 4], [55, -3, 3], [18, -4, 2], [22, 12, -6], [24, 2, 1], [-18, 0, -20], [-56, 2, -4], [0, 3, 3], [13, -15, 8], [-8, -22, 6], [2, 0, 12], [2, 2, -4], [-6, -6, 4], [-22, 14, 0], [19, 5, -7], [3, -7, -7], [5, 5, 7], [-31, 5, 0], [25, -7, -7], [0, -2, -5], [-19, -2, -12], [9, -1, -11], [-4, -18, 21], [11, -13, 12], [19, -19, 10], [-22, -4, -4], [15, -9, -7], [23, -7, 9], [12, 18, 0], [-9, -3, 14], [2, -2, 8], [-7, 21, -1], [-12, -8, 2], [-33, -1, 9], [26, -13, -1], [-34, 8, -4], [-51, 3, 5], [-14, 14, 1], [-33, -1, -2], [13, 19, -15], [8, 14, -12], [-20, 6, -12], [-24, -4, -8], [-15, -11, -1], [-24, -20, 14], [16, -4, 19], [-29, 1, -9], [-19, -18, 6], [-13, -19, 5], [-9, -8, 14], [-15, 13, 5], [-4, 2, 10], [21, -9, 10], [-46, 5, -1], [33, -7, 3], [0, -12, 14], [28, 10, 4], [12, -15, 11], [-18, 4, 13], [4, 10, -9], [26, -12, 6], [-44, 4, -10], [3, -13, 4], [-14, 9, -1], [-7, 15, -19], [-4, 24, -12], [-24, -6, -6], [-52, -2, 5], [-43, 13, -9], [-22, -20, 12], [-1, -9, 9], [36, -4, -2], [-55, -1, -9], [-30, -6, 12], [-13, 15, 11], [-35, -7, 1], [38, 12, -8], [45, -1, 16], [28, 25, -19], [-38, 8, -8], [-14, -4, -10], [-10, -10, 6], [26, -3, 11], [6, 24, -12], [54, 12, -2], [0, 20, -20], [20, 23, -19], [-32, 10, 2], [-11, -15, 15], [-46, -5, 5], [-21, 7, -27], [-11, 23, -7], [23, 9, 1], [21, 1, -11], [-5, -15, -5], [-55, 3, -7], [-37, 9, -11], [26, -4, 2], [-26, -8, 2], [-29, -19, 13], [29, -4, -6], [33, -1, -13], [32, -16, 10], [-16, 12, 1], [-15, -31, 17], [55, -1, -5], [-18, 2, -4], [6, -26, 4], [-38, 6, -10], [-39, 3, -1], [6, 16, 4], [25, 5, -1], [-2, -22, 6], [19, -21, 2], [-2, -4, 0], [22, -22, 7], [8, 4, 6], [-7, -30, 24], [3, 7, 0], [25, 7, -9], [-11, 14, -16], [-5, -3, 3], [66, -14, -2], [-8, -4, -10], [-10, 22, 8], [-4, 2, -7], [-22, 16, -4], [29, -11, 8], [-12, -6, 8], [-3, 0, -14], [-32, -4, 3], [21, 15, -15], [24, 0, 0], [-48, -8, -8], [14, 0, 16], [-14, -14, -13], [19, 9, 19], [-39, 15, 3], [3, -12, -4], [12, -4, -2], [-54, -12, 12], [8, 14, 10], [-35, 16, 4], [-6, -22, 10], [1, 16, -10], [-49, -7, -1], [59, 9, -3], [-6, -22, 6], [-43, -5, -10], [38, -8, 2], [-35, 17, -3], [31, -9, -7], [-20, 14, -10], [47, 9, 5], [2, 0, -15], [-6, 12, 12], [11, -25, 15], [-10, -15, 9], [-14, 29, 3], [30, -12, 3], [-11, -9, 14], [-52, 18, -4], [2, -10, 4], [39, -1, 1], [1, 5, -17], [-42, 10, -3], [1, 7, -7], [-69, 9, -2], [2, -16, -2], [50, -12, 1], [-19, -5, -17], [68, 10, 0], [-19, 9, 3], [-17, -7, -1], [19, 5, -7], [44, 0, 18], [-38, 4, -6], [-44, -12, -6], [23, -12, 10], [-5, -22, -4], [2, 5, 13], [-11, -25, -1], [7, -7, 0], [-6, -7, -9], [9, -3, -11], [-31, 2, -16], [53, -9, 3], [6, -16, 18], [-38, -11, 11], [18, -8, 6], [-5, 7, -5]];
    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_m();".
// 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_m(:prec:=3)
    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_m();".
// 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_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8016_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![19, -7, -3, 1]>,<7,R![-17, -13, 1, 1]>,<11,R![20, 20, -10, 1]>,<13,R![-68, -28, 4, 1]>],Snew);
    return Vf;
end function;