
// Make newform 2960.2.a.s in Magma, downloaded from the LMFDB on 17 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_s();".
// 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_s();".
// 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, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -2, 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_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, -1, 0], [1, 0, 0], [0, 1, 0], [-2, 0, -1], [0, 0, 0], [0, 0, 0], [-2, -1, 1], [-4, 0, 0], [-2, 0, -2], [-2, 1, 1], [1, 0, 0], [0, -2, -1], [-4, 0, -2], [0, 1, 4], [4, 2, 3], [2, 1, 3], [-2, -4, 0], [-10, -1, -3], [-6, 2, -1], [0, 2, -3], [-2, 1, -3], [-4, 5, -2], [-2, 4, 4], [6, 0, 0], [2, -6, -3], [-4, 6, 0], [-2, 3, 5], [-6, -4, 0], [-4, -4, 2], [0, -5, 4], [2, -1, -1], [2, -4, 0], [4, 4, 4], [2, 2, 1], [-4, -6, -2], [-4, -6, -7], [-4, -2, 2], [4, 2, -4], [12, -2, -1], [-6, 1, -5], [2, -2, 7], [-2, -5, 1], [6, 4, 2], [0, -2, 1], [-2, -3, 1], [18, 2, 5], [16, -3, 0], [-12, -2, -2], [-4, 6, 7], [-6, 0, 0], [2, -9, -5], [-18, -4, -6], [-10, 3, 5], [12, 4, -2], [4, -1, 2], [-8, -4, -6], [10, -6, -5], [4, 4, 6], [-6, 8, 0], [-4, -2, -6], [-10, 0, 0], [-4, 3, 2], [10, 5, 3], [-10, 8, 0], [14, 4, 4], [2, 5, 3], [0, -10, -7], [-8, 4, 0], [-24, -4, -2], [18, 0, 4], [6, 0, 1], [2, 1, -1], [-16, -2, -5], [-18, 0, -1], [0, -4, -2], [6, 8, 6], [8, -2, 1], [10, -4, 4], [2, 0, 6], [-2, 8, 7], [-2, 0, -6], [10, -7, 3], [-8, -2, -5], [10, 1, -5], [4, -11, -6], [14, 0, 0], [-10, -8, 4], [-2, -8, -12], [16, -8, -6], [8, -6, 8], [-18, -1, -3], [8, -2, -6], [-4, -12, -8], [-22, 7, -1], [4, -4, 0], [-20, 2, 5], [6, -6, -3], [12, 0, 2], [-6, 8, 0], [-16, 16, 0], [16, 0, -8], [-16, -4, 0], [26, 4, 0], [-6, -6, -7], [0, 8, -4], [-4, -8, -10], [-4, 2, -11], [14, 8, 1], [-8, -4, 6], [28, -4, 0], [4, 6, 1], [20, -22, -5], [-6, 10, -3], [10, -1, -5], [2, -6, 9], [4, 6, 10], [0, 12, 10], [6, -16, -4], [-10, 2, -9], [-10, -12, -12], [16, 6, -3], [8, 10, -5], [24, -4, 0], [0, -14, 2], [14, 8, -6], [-14, 16, 2], [2, -4, 7], [24, -16, -2], [12, 2, 1], [-14, -10, -3], [12, -11, -6], [14, 0, 1], [10, 12, 14], [-8, 2, 5], [-10, 0, -6], [8, -2, 1], [-16, -3, 4], [0, 8, 0], [-2, 4, -2], [-6, 10, 9], [-20, 10, -3], [10, 5, 11], [-4, -6, 2], [18, 12, 6], [-24, -4, -4], [-26, -4, -14], [6, 0, -4], [-22, -3, -1], [6, 3, -11], [-18, -8, -8], [20, -4, -10], [-28, -2, 2], [8, -21, -12], [-16, -14, -8], [-22, -5, -9], [-10, 3, 9], [30, 0, 0], [-32, -10, -9], [12, 4, 10], [4, 10, 6], [-20, -10, -5], [4, 6, 16], [4, 4, -4], [18, 4, 2], [8, 7, 4], [-6, 3, -1], [-14, 12, 10], [2, 14, 3], [22, -4, 10], [2, 7, 19], [-18, 16, 6], [-26, 27, 9], [28, -10, 1], [-6, 14, -9], [-14, 12, -4], [26, 9, -1], [0, -4, -6], [-32, -7, -12], [-6, 8, -16], [12, -8, -4], [2, 15, -5], [20, 0, 4], [10, -12, 6], [6, -13, 5], [-24, 18, 1], [-20, -2, 11], [4, 12, -2], [-22, 20, 4], [-30, 4, -9], [12, 0, 16], [14, 11, 21], [50, 1, 7], [-20, 2, -11], [20, 11, 18], [-8, 14, -9], [-6, -16, 10], [-8, 12, -6], [12, 18, 17], [12, -10, -8], [6, -8, 6], [-14, -10, -1], [-34, 12, -4], [-14, 10, 5], [-8, -22, -22], [-12, 16, 8], [24, 4, 12], [14, 7, 5], [-30, -8, 6], [10, 14, 9], [-16, -12, 10], [-22, 24, 2], [-8, -12, 10], [26, 1, -5], [22, 5, 1], [-22, 10, 13], [-4, 0, 4], [26, -8, 10], [24, -6, 6], [6, 12, -8], [-34, 10, -7], [-10, -2, 9], [18, 2, -7], [12, -12, 4], [36, -3, -2], [-18, 8, -8], [-2, 20, 4], [-46, 0, 3], [12, 7, -18], [-22, 25, 3], [12, -26, 1], [-42, 8, -1], [2, 12, 15], [16, 2, 5], [-28, 13, 6], [0, -9, -8], [-10, 24, 4], [-4, 4, 22], [2, -13, -13], [-2, 21, 17], [20, -16, -2], [30, -7, 5], [-16, -7, -24], [22, 4, 10], [-30, 24, 8], [6, 21, 1], [20, -14, -4], [38, 3, 17], [-46, 10, 5], [-48, -6, -10], [-32, 4, -14], [-24, 12, -2], [2, 17, -9], [-34, -12, -22], [-14, 12, -10], [-14, -6, -27], [8, -14, -7], [6, -25, 5], [-20, 22, 15], [-6, -8, 0], [-32, 28, 6], [20, -8, -2], [30, -8, 12], [-6, -8, 0], [24, -12, -14], [-14, -12, -7], [-2, 14, -13], [-18, -4, 16], [-36, -5, 2], [-8, -12, -22], [-10, 24, 0], [-28, 2, -6], [32, -8, 4], [-30, -1, -9], [-6, 4, 24], [-6, 13, -5], [-10, 23, -3], [2, 0, 18], [-16, -10, 15], [-22, -13, -13], [-36, 19, 2], [-34, 7, 1], [-10, -1, 1], [12, -6, 21], [12, 6, 6], [-38, 4, 3], [32, -20, -6], [-18, 12, 12], [6, -9, 17], [34, -8, -2], [30, 4, -6], [12, -4, -6], [0, 22, -9], [30, -22, -13], [4, -2, -1], [32, 14, 15], [6, 16, 21], [-38, 8, 8], [-18, 11, -7], [4, 3, 2], [34, 16, -8], [0, 14, 15], [42, 4, -5], [-4, 24, 2], [-22, -9, -17], [8, 16, 8], [-56, -8, 4], [18, -16, -2], [46, 6, 17], [16, 12, -14], [-12, 29, 14], [30, -18, -5], [-26, -18, -13], [-56, -7, -16], [-28, -12, -16], [30, -16, -14], [14, -2, 19], [-2, -21, 13], [12, 22, 3], [46, 8, 6], [-22, 31, 3], [-28, 6, 9], [34, -32, -4], [-54, 5, -5], [-36, -6, 3], [-18, -12, -30], [-40, 26, 6], [0, 10, -4], [0, -20, -2], [-6, -4, 8], [-24, -6, -11], [10, -24, 12], [62, -5, -3], [-16, 0, -20], [10, -25, -17], [-18, -5, -7], [16, 18, -7], [-44, 2, 1], [6, -16, 0], [10, 17, 3], [-56, 14, 7], [-16, 22, 5], [6, -28, -14], [-10, 1, -23], [10, 4, 18], [-14, -7, 19], [20, 18, 1], [20, 21, 30], [-26, -11, 5], [12, -26, 1], [56, -14, -2], [52, -14, -3], [26, -20, -2], [0, 22, 10], [-44, 20, 10], [-2, 4, -12], [-22, -5, -25], [6, 9, -11], [-4, -10, -23], [4, -22, -4], [4, -20, -14], [-52, 2, 1], [20, 6, -4], [42, 7, -9], [-4, 11, 14], [-18, 0, 24], [28, 16, -12], [-24, 2, -6], [50, 0, -2], [2, 3, 19], [10, 1, -21], [10, -3, -5], [40, -12, 14], [-14, 3, -9], [0, -14, -25], [64, 2, 2], [14, 6, 5], [-14, 8, -8], [-18, -8, -20], [-20, 6, 19], [-42, -12, 6], [8, 20, 22], [8, -4, -10], [-10, -16, -12], [6, 11, 1], [32, 11, 24], [38, -18, 9], [-34, -4, -2], [4, -12, 6], [-24, -14, -6], [12, -18, -21], [-50, 12, -10], [50, -1, 7], [12, -14, -18], [-54, 6, 7], [-38, 12, 8], [-10, -17, 9], [-52, 10, -7], [-50, -4, -1], [-14, 0, 16], [10, 22, 11], [-10, 20, 26], [36, 12, 12], [-2, -12, 18], [42, -8, 2], [22, -18, -3], [14, -24, 16], [-26, -16, -8], [-34, 27, 9], [14, -16, -5], [-40, 6, -11], [-24, 2, 5], [-24, 18, 12], [-10, -29, -27], [30, 0, 16], [-20, -4, 26], [0, 20, -20], [0, 11, -8], [22, -12, 12], [12, 8, -12], [-34, 12, 4], [6, 0, 8], [26, 9, 23], [-30, 4, -27], [42, 4, -12], [64, 10, 13], [2, 21, -25], [16, -6, 17], [16, 22, 10], [42, -23, -13]];
    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_s();".
// 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_s(:prec:=3)
    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_s();".
// 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_s( : 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, -6, 1, 1]>,<7,R![-2, -6, -1, 1]>,<13,R![0, 1]>],Snew);
    return Vf;
end function;