
// Make newform 2960.2.a.z in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2960_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_2960_2_a_z();".
// 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_2960_2_a_z();".
// 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 := [2, 8, 4, -8, -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], [3, 4, -7, -1, 1], [6, 5, -8, -1, 1], [-11, -15, 15, 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_2960_a();"
function MakeCharacter_2960_a()
    N := 2960;
    order := 1;
    char_gens := [2591, 741, 1777, 2481];
    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_2960_a_Hecke(Kf)
    return MakeCharacter_2960_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], [0, 1, 0, 0, 0], [-1, 0, 0, 0, 0], [0, 0, 0, -1, 0], [2, -1, 1, 0, 1], [1, 0, 0, -1, 1], [-1, 2, 0, -1, -1], [0, 2, 1, -2, -3], [2, -2, 0, 0, 0], [-2, 0, 0, -2, 0], [2, -1, -3, 1, 3], [1, 0, 0, 0, 0], [-2, 1, 1, 2, 1], [4, -2, -2, 0, 0], [2, 0, 2, 1, 0], [-4, 1, 1, 0, -3], [6, 1, -3, 1, 3], [2, -2, -4, 2, 4], [2, 4, 1, -2, -3], [2, 3, 1, -2, -3], [4, 1, 1, -2, -3], [0, 3, -1, -1, -1], [6, -1, 0, 0, -2], [-4, -2, -4, 0, 2], [6, 2, 0, 2, 2], [-1, 1, 1, -3, -6], [2, -2, 0, 6, 4], [4, -1, -3, 5, 3], [-4, 0, 4, -2, -2], [1, -6, -2, 3, 7], [2, 1, 4, -2, 2], [6, 2, -3, 2, 3], [4, -2, -2, 4, 4], [6, -4, 0, 2, 6], [1, -5, -3, 5, 8], [-2, 4, 2, -2, -4], [12, -3, 1, 2, 5], [8, -6, -6, -2, 4], [-8, 2, -4, -4, -2], [2, -3, 3, -2, -3], [8, 2, 3, -2, -1], [-1, 5, -1, -1, -4], [-8, -1, 3, 1, -5], [2, -6, 2, 4, -2], [6, -7, -3, 4, 3], [-2, 0, 1, 0, -1], [8, -5, -5, 6, 1], [-6, -1, 0, -6, -2], [-10, 10, 2, 0, -6], [6, -3, -3, 2, 1], [4, -4, -6, 2, 0], [-2, -8, -1, 4, 5], [-4, 8, -4, 0, -2], [6, -4, -1, -2, -7], [-7, 10, -2, -1, -1], [0, 5, 0, 2, 4], [-13, 0, 0, -1, 3], [-2, 1, 1, 0, 5], [3, -8, -2, 7, 1], [-4, 6, 6, 0, 0], [2, -10, 2, 4, 2], [-14, 2, 0, 2, -4], [2, -6, -2, -1, 4], [-4, 1, 1, -5, -3], [14, -6, -4, -2, 2], [8, -8, -6, 6, 0], [-2, 4, 1, 2, -5], [0, -5, -3, -8, 1], [-2, -8, 0, 2, 4], [-1, -4, 0, 11, 3], [-10, 8, 0, -4, -8], [-2, -7, -1, 12, 3], [-8, 8, -1, 0, 1], [16, -7, 3, 4, 11], [4, -3, 1, 0, 3], [0, -4, -2, -6, 0], [-12, 6, 2, -6, -8], [12, -3, 3, 2, 7], [2, -16, -4, 4, 12], [2, -4, 4, 2, 0], [-18, 15, 1, -4, -3], [-12, 6, 2, 2, -8], [-14, 5, 3, -11, -3], [-2, 1, 11, -2, -7], [8, -4, -3, -4, -3], [-6, 6, 2, 1, -8], [-18, -4, -2, 0, 2], [14, -6, -4, 2, -2], [-4, 4, -2, -2, -4], [-12, 8, 6, 2, -8], [-2, 10, 8, -14, -4], [-2, -2, -7, -4, 3], [-2, 0, 2, 6, 6], [14, -6, 0, 0, 2], [8, -3, -1, 9, 11], [8, 2, 8, -2, -2], [-14, 11, -5, -2, -3], [-9, 11, 5, -1, -2], [8, 2, 6, -4, 4], [6, 6, 10, -2, -6], [14, 6, -4, 0, 8], [-17, 6, 0, -1, -5], [16, 0, 0, 4, -2], [-12, -4, 6, -2, -4], [26, -9, -1, 4, -1], [-11, 4, 4, -5, -3], [6, -4, -6, 8, 2], [-8, -5, 3, -4, -9], [2, -1, 7, 2, 3], [-7, 14, 4, -1, -7], [0, -8, -4, 16, 2], [18, -11, -1, 0, 9], [2, -17, -3, 4, 11], [-8, 15, 3, -6, -19], [-4, -10, 1, -4, -3], [-1, -3, -3, -3, 2], [4, -10, 2, 2, -4], [2, 4, 2, -8, -10], [-18, 16, 0, -4, 0], [22, -5, 1, 6, 1], [-10, 0, -4, 4, 8], [22, -1, -1, 2, 5], [0, 7, -5, 2, 11], [10, -8, -12, 2, 8], [14, -6, -10, 16, 4], [-24, 0, -6, 0, -4], [4, 10, 4, 2, 2], [-16, -3, 5, -4, -9], [-2, -6, -10, 6, 14], [6, -1, -5, -2, 1], [-4, -3, 7, -4, 5], [26, -2, -4, 1, 10], [-12, -5, 3, 4, -11], [-2, 14, 10, -8, -10], [2, 3, 3, -6, -15], [2, -20, -6, 10, 10], [-14, 9, 1, 0, -5], [-6, 16, 12, -11, -14], [-17, 2, 8, -13, -13], [-18, 0, 6, -14, -2], [24, -3, 7, 0, -3], [18, -5, -5, 14, 13], [2, 1, -5, 5, 15], [2, -10, -2, 0, 2], [-6, 14, 2, -4, -14], [4, 4, 8, -8, 4], [14, 12, -2, -2, -8], [10, -2, -16, 10, 14], [0, -7, -5, -5, -5], [0, 4, 1, 4, 7], [-4, -12, -2, 14, 0], [-13, 10, -4, -11, -9], [10, 2, -2, 0, 2], [0, -12, -4, 5, 0], [-14, -14, 4, -2, 4], [-10, -15, -1, 7, 1], [2, 7, 1, 3, -1], [-6, -16, 8, 0, -6], [10, -9, -5, 0, 5], [3, -2, 8, -3, 15], [6, 14, 6, -4, -6], [14, 7, 13, -4, -9], [22, 2, 4, 2, -4], [4, -2, 4, 2, 0], [-10, 4, 2, 2, -4], [-4, -9, -2, 10, 2], [26, 8, -1, 4, -3], [-6, 6, 10, -8, 6], [-5, -11, -5, -1, 12], [-10, 8, 2, -10, 4], [4, -7, -13, 9, 19], [-2, -2, -12, -4, 0], [-4, 4, -9, 8, -1], [-12, 19, -1, 0, 3], [2, 1, 5, -12, 5], [10, -18, 0, 2, 4], [14, -11, 5, -3, -1], [-7, -10, 0, 3, 1], [2, 20, 6, -3, -16], [10, 0, -8, -4, -2], [28, -20, 0, 12, 10], [14, -18, -7, 6, 7], [5, 22, 0, -7, -3], [-6, 4, 2, 2, -8], [-8, 7, -13, 1, -7], [38, 3, 7, -2, -5], [20, -13, -7, 10, 9], [2, 6, -2, 2, 18], [16, -2, -2, 0, 4], [-28, 3, 9, -6, 3], [25, 10, -4, 1, 1], [8, -14, -5, 14, 1], [28, 9, 3, -9, -5], [2, -13, -5, 6, 13], [16, -6, 8, 1, -8], [22, -15, -1, 2, 13], [2, -14, -4, 20, 4], [13, 20, 2, -3, -13], [0, 9, 3, 2, -1], [-20, 10, -4, -4, -10], [-18, 0, 8, -14, -4], [-8, -9, -15, 8, 15], [12, -6, 2, 0, -8], [19, -7, 5, 1, -6], [-20, -6, -2, -6, -2], [11, -20, 0, 9, 23], [10, -16, 4, 6, 2], [22, -5, 3, -5, -5], [12, -4, -6, 12, 0], [36, -11, 7, 8, 5], [11, 10, 6, 9, 5], [22, 20, -2, 6, -6], [2, -12, -6, 0, -6], [-24, 2, 1, 10, -5], [-24, 18, 3, -8, -9], [11, 9, -7, -7, 10], [12, -6, -16, 18, -2], [0, -4, -2, 12, -4], [16, 14, -2, 2, 0], [-16, -6, -2, 16, 8], [7, 19, 13, -5, -14], [22, -11, 7, 10, 19], [11, -7, -15, 5, -2], [-8, -10, 0, 14, 6], [-14, -5, -8, 8, 14], [10, 2, 8, -10, -20], [28, 10, -8, 8, 2], [0, 3, 5, -10, -1], [-14, 10, 16, -1, -18], [22, -16, 13, 6, -1], [20, 15, 13, -4, -15], [10, -7, -11, 22, 13], [-2, 25, 5, 2, -11], [2, 7, -1, -2, 1], [-32, -2, 0, -1, -8], [8, 7, -10, 2, 10], [2, 4, 0, -8, -2], [9, -2, -2, -5, -21], [-8, -8, 3, -6, -13], [-4, -5, -9, -13, -9], [-26, 14, 10, 2, -10], [12, 7, -3, -9, 9], [-14, 3, 4, -6, 2], [-30, 18, 12, -12, -8], [22, -20, -4, 8, 4], [-6, -5, 1, 17, -5], [14, 4, 16, -8, -20], [6, -9, 3, -1, 5], [-6, -7, -5, 6, -1], [30, -8, -6, 2, 14], [-7, 4, -2, 1, -5], [-5, 12, 4, -1, 3], [18, 6, 5, 8, 1], [16, -2, -8, 2, 10], [-18, 6, 6, 12, 2], [4, 9, 3, 12, 13], [22, -9, 11, 2, 3], [18, -16, -7, 2, 13], [0, -7, -3, -4, -7], [-26, 20, 0, -16, -16], [-44, 4, -2, 6, -4], [-16, 2, -2, -16, 0], [-2, -12, -24, 8, 12], [46, 6, -2, 6, 2], [-11, 16, 2, -3, -1], [8, -1, -5, 4, -3], [15, -13, -1, 1, 12], [16, -16, 0, 14, 6], [-4, 11, 14, -12, 6], [-7, -4, -2, 13, 3], [-20, 2, 6, -4, -12], [16, 8, 6, 4, 0], [-51, 8, -4, -5, -11], [22, 9, -1, 11, 5], [-4, 4, 10, -10, 8], [-34, -3, 15, -3, -17], [20, -6, -5, -10, 17], [32, -18, -12, 2, 22], [-10, -15, 9, 2, -7], [-22, 17, 1, -13, 3], [24, -6, -2, 9, 2], [18, -14, -11, 8, 7], [48, -5, 3, -3, 13], [2, 7, -9, 2, 17], [-2, 18, -10, 0, -10], [-22, -3, -11, -10, -7], [11, -6, -14, 5, 9], [22, -6, 4, -2, 8], [28, -1, -9, 5, -1], [10, -2, 0, -4, 8], [-44, -2, 2, -6, 0], [12, -6, -2, 12, 0], [2, -9, -9, 0, 17], [-20, 3, -3, 12, 7], [16, -13, 5, 10, 17], [-38, -3, 13, -2, -25], [12, 7, -5, -12, -3], [36, -14, 4, 12, 14], [-26, -1, 7, 3, -3], [-18, 9, 4, -4, -6], [18, -16, 0, 4, 20], [8, 19, -9, -2, 11], [10, -15, -7, 26, 13], [-30, 20, 6, 0, -22], [30, -15, -19, 3, 19], [-21, 6, 16, -13, -29], [0, 22, 0, -10, -22], [-4, -14, -4, 22, 2], [0, -21, 7, -6, -3], [-13, -14, 2, 9, -3], [-8, -2, -2, 7, 22], [31, 3, -1, 9, 12], [23, 7, -5, 13, 16], [-4, -4, 10, -9, -6], [24, 12, -4, 0, -2], [2, -12, 2, 14, 10], [4, -25, -11, 20, 15], [-40, 8, 7, 12, -5], [-30, 3, 9, -12, -25], [16, 6, 12, 2, -2], [16, 25, 3, -7, -13], [22, -21, -7, 22, 11], [-16, 6, -8, -16, -10], [38, -15, -1, 1, -9], [4, 3, -13, -10, 7], [-8, 4, 0, -4, 10], [12, 4, -2, -4, 2], [4, -18, -8, -4, 18], [2, 4, -6, 0, -14], [4, -16, 0, 2, 6], [-10, -9, 7, -10, -1], [2, 14, -4, -18, -2], [-42, 2, 13, 0, -9], [-24, -12, -24, 8, 14], [32, -4, -5, 6, 23], [-28, 15, -7, 1, -1], [-2, 19, 3, -2, -17], [-32, 13, 3, -26, -21], [-14, -10, -14, 10, 10], [18, 1, -1, -7, 7], [16, -17, -5, 2, 15], [4, -7, -3, 2, 21], [-4, 4, 14, -8, -24], [-12, 10, 15, -4, -13], [-30, 22, 2, -20, -14], [12, 5, 3, -5, -9], [-14, -29, -13, 18, 33], [-14, 22, 26, -11, -12], [-28, 39, 11, -13, -13], [28, 3, 17, 16, 1], [0, 24, -2, 4, -22], [-40, 1, -1, -26, -17], [18, -10, -6, 0, 10], [-34, 14, 10, 4, -6], [11, 18, -4, 1, -5], [-4, -14, 0, 0, -2], [16, 1, -15, 9, -15], [-36, 0, -7, 6, 1], [16, 15, 11, 0, -5], [28, 16, 0, 2, 2], [-31, -10, 6, -1, -21], [18, 7, 7, 18, 3], [14, -4, -24, 8, 8], [-10, 10, 21, 2, -17], [12, -18, -12, 13, 16], [34, 6, -8, 10, -2], [-17, 20, 24, -15, -21], [-18, -14, -2, 4, 14], [-46, 4, 4, 6, -4], [-20, 16, -1, -2, 15], [54, 21, -7, 9, -1], [56, -24, 7, 8, 5], [39, -12, -4, -5, 11], [2, -3, -9, 15, 21], [-8, 25, -1, -12, -5], [-26, -22, -2, 0, 0], [-24, 5, -9, 4, -7], [-30, 6, -4, -6, -4], [22, 10, -14, -2, 2], [-10, 25, -3, -6, -9], [6, 12, 8, 6, 0], [-25, 10, 22, -3, -31], [22, -18, -14, 6, -2], [12, 14, 12, 0, 6], [20, 7, 5, 17, 17], [14, 33, 8, -18, -18], [-10, 15, -1, -8, -9], [22, -24, -2, 18, 24], [-6, 8, -2, 4, -10], [-32, 22, -2, -6, -12], [2, -11, -7, -18, 7], [-10, -4, -10, 10, 16], [10, -2, -3, -10, 3], [-6, 14, -6, -20, -14], [-4, 11, 9, -8, -21], [-24, -2, -2, 0, -12], [8, 3, 7, 5, 3], [26, -29, -9, 6, 7], [36, -19, -3, 12, 31], [-10, 8, 0, -24, -38], [-31, -13, -1, 3, -2], [-30, 22, 14, -12, -2], [24, 18, 16, -14, -22], [-2, 2, -18, 4, 6], [-2, 18, 18, -12, -2], [24, 29, 11, -20, -15], [-6, 16, 4, 12, -12], [-14, 28, 20, -4, -22], [14, -25, 7, -1, 7], [-34, 1, -7, 6, -3], [48, -21, 1, 20, 9], [12, 23, 7, 0, -9], [-20, 12, 16, -6, -14], [-18, -8, -1, -2, 1], [2, 6, 8, 18, 6], [-13, 10, 8, 1, -9], [-30, 8, -20, -2, -14], [-36, 19, 14, -2, -2], [0, -10, 4, 8, 14], [-16, 34, 20, -14, -22], [-26, -2, -8, 14, 12], [30, -24, -8, -8, 24], [-8, -31, -15, 15, 27], [-26, 19, -13, -10, -5], [4, 8, 6, -10, -32], [6, 17, -3, 4, 7], [12, -30, -11, 22, 31], [26, -13, 3, -2, 25], [34, 10, -6, 0, 0], [14, -2, -1, 24, 33]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2960_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2960_2_a_z();".
// 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_2960_2_a_z(:prec:=5)
    chi := MakeCharacter_2960_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_2960_2_a_z();".
// 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_2960_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2960_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 8, 4, -8, -1, 1]>,<7,R![6, 28, 8, -14, -1, 1]>,<13,R![144, -284, 172, -28, -4, 1]>],Snew);
    return Vf;
end function;