
// Make newform 6160.2.a.bm in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6160_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_6160_2_a_bm();".
// 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_6160_2_a_bm();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-2, 0, 1], [2, 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_6160_a();"
function MakeCharacter_6160_a()
    N := 6160;
    order := 1;
    char_gens := [5391, 1541, 3697, 5281, 5601];
    v := [1, 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_6160_a_Hecke(Kf)
    return MakeCharacter_6160_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, -1, 0], [-1, 0, 0], [-1, 0, 0], [1, 0, 0], [-1, -1, 0], [1, 1, 0], [2, 0, 2], [-2, 1, 1], [0, -2, 0], [-1, -2, -1], [-2, -1, 1], [1, -2, -1], [2, 3, -1], [1, -3, -2], [2, -3, -1], [5, 0, -1], [-3, 0, -3], [6, 1, -3], [-2, 2, 0], [3, -3, 2], [2, -5, -1], [6, 0, -2], [-6, 0, 4], [4, -4, -2], [-1, -2, 1], [5, 3, 0], [0, -2, 6], [-8, 6, 0], [6, 2, 2], [4, -4, 0], [8, 0, 0], [6, -1, -3], [6, -4, -2], [-2, 2, -2], [6, 1, -3], [-10, 6, 2], [6, 3, 3], [0, -2, 6], [-5, 5, 2], [12, -2, 2], [4, 0, 2], [0, 4, -4], [2, -1, 1], [6, -1, 1], [9, -4, -5], [8, 2, 2], [13, 1, 2], [4, 0, -4], [-12, 6, 0], [12, 1, -3], [-8, -2, -6], [-7, 2, -5], [-1, -6, -5], [10, -4, 0], [8, 0, 0], [-8, 4, 2], [2, 4, 10], [10, -1, 5], [-4, 0, -2], [4, 4, 0], [9, -9, 2], [8, 0, -4], [9, -6, -3], [-14, 4, -4], [18, 8, -4], [-4, -2, -6], [12, -3, -7], [10, -5, -1], [5, -4, -7], [-6, 6, 2], [-2, 1, 5], [1, 1, 2], [-6, 9, 3], [-6, 2, 0], [-9, -9, 2], [10, 0, 4], [-6, 10, 2], [22, 0, 4], [-29, 4, 3], [-15, 0, -1], [-2, 11, 1], [6, 11, 3], [-12, 2, -4], [10, 10, -4], [-8, 1, -5], [2, 11, -7], [10, -5, -3], [1, -2, -9], [-2, 9, 9], [3, 11, -6], [10, 2, 8], [-2, 1, 9], [10, 5, 1], [2, 12, 6], [-30, 2, 0], [-8, 6, 4], [0, 14, 0], [24, -6, -6], [6, 2, 6], [-24, 2, 2], [2, 1, -13], [2, 10, 4], [0, -2, 12], [24, -6, -6], [0, -4, -6], [-9, -5, -2], [-5, 5, -2], [-2, 8, -6], [1, -10, -1], [-8, 2, -6], [8, 5, 1], [-18, 3, 1], [15, -8, 1], [-28, 0, 4], [2, 5, -1], [-1, 5, -8], [-13, -13, 6], [10, 18, -6], [-2, 3, -1], [-18, -8, 0], [-8, 1, -7], [-13, 3, -8], [4, 5, -5], [-7, 12, -5], [-4, 12, -2], [10, -8, -12], [-1, 18, -1], [-9, -13, 2], [17, 5, 12], [-4, -12, -4], [8, 14, -6], [-26, 2, 8], [-2, 8, 16], [-9, -20, 7], [-9, -2, 9], [16, 0, 6], [-10, -4, -2], [46, 2, -2], [10, -2, 2], [-12, -2, 10], [18, -4, -8], [4, 3, -7], [14, -15, -11], [-18, -16, 4], [-33, 4, 5], [-1, 5, 10], [-5, 5, 10], [3, 6, 11], [0, -7, 7], [16, 17, -3], [-8, -2, -8], [8, -13, -7], [30, 8, 2], [-14, -7, 1], [2, -2, 8], [-12, -2, -10], [-16, 8, -2], [7, -13, -4], [17, -6, 7], [8, 7, 5], [10, -1, -15], [10, -1, 15], [31, -6, -1], [18, 6, 2], [-3, -15, -2], [14, -16, 2], [-21, 1, -2], [-18, 8, -4], [-12, 16, 2], [24, -14, 2], [2, 4, -16], [-18, 1, 5], [-16, 3, -1], [-3, 10, 1], [4, -10, -16], [34, -25, -9], [34, 3, 5], [2, 4, 6], [-41, -6, -3], [-12, -17, -3], [18, 12, -2], [-2, -4, -4], [25, -13, 2], [20, 9, -5], [-16, -20, 10], [6, -7, -1], [-1, 15, 6], [-16, 12, -2], [-8, -12, -8], [4, 16, -2], [8, 8, -4], [-26, 28, 10], [6, -4, 4], [22, -15, 5], [18, -12, 0], [16, -14, 8], [-2, -9, -7], [-13, -5, 16], [10, 18, 4], [14, 12, 4], [4, 12, -12], [0, 14, -4], [-33, -10, -3], [3, 2, -9], [-18, -10, -2], [-3, 6, -7], [28, -12, -4], [-54, 6, 2], [-11, 12, -5], [8, -5, -17], [20, -8, 6], [4, 15, -3], [-7, 13, 6], [38, 0, 6], [-2, -14, 6], [34, -3, 1], [3, -8, 3], [2, 1, -19], [18, -30, -6], [-16, -4, -6], [-6, 14, 12], [18, 1, 3], [36, -19, -1], [-28, -10, 2], [-32, -16, 6], [4, 20, -6], [-12, 8, -4], [-10, 16, -6], [-2, 25, 1], [-14, -1, 5], [-8, 26, -2], [-12, 4, -8], [-2, 18, -14], [7, -1, 6], [-10, 20, -6], [-16, -20, 6], [34, 3, -7], [-2, -2, 16], [-41, 28, 13], [10, 7, 19], [-22, -8, -10], [-21, 5, 4], [18, -21, 5], [-7, 15, 6], [-4, -2, 10], [11, 1, -8], [-3, 4, 7], [48, 8, 4], [-4, 4, 0], [-6, 3, 9], [27, 16, -1], [14, 1, -7], [-50, 12, 4], [49, -19, -4], [-4, -16, -8], [-14, 9, -1], [10, 16, -6], [-6, -10, 2], [5, 3, -2], [18, 15, 7], [4, -20, -4], [-43, -8, 1], [7, -25, -12], [-2, -16, -16], [-9, -22, 7], [42, 1, -1], [-8, 6, 4], [26, -5, -17], [-12, 9, -15], [-2, 4, -16], [-30, 15, 3], [-24, 22, 4], [36, -4, 0], [-13, -5, -20], [5, -7, 2], [12, 1, 15], [22, 10, -2], [-6, 16, -8], [26, 22, -8], [0, -4, 0], [-2, 4, 6], [18, 18, 0], [19, -22, -3], [-14, -12, -18], [-26, 12, 6], [18, -31, -1], [-18, 29, 11], [-3, -22, 9], [5, 12, 9], [-14, -13, -3], [-25, -3, 12], [8, 11, 15], [50, 4, 2], [-42, 9, -9], [-55, -2, 7], [-37, 20, -3], [-8, -2, 16], [-10, 18, -8], [18, -12, 2], [35, 19, 0], [8, -9, 23], [-6, -7, 9], [30, -7, -11], [-54, 2, 0], [2, 19, -11], [24, 3, 1], [22, 2, 2], [-8, -6, 14], [34, -21, -7], [32, -30, -18], [42, -24, -12], [-4, 8, -10], [8, -25, -11], [10, -5, 19], [-29, 34, 9], [-21, 4, 9], [24, -22, -2], [-48, -6, 8], [-12, -12, -6], [8, -16, -8], [-14, -10, 18], [-23, -8, 17], [-20, 1, 3], [-10, 7, -3], [14, 2, 26], [-2, 24, 14], [47, -1, -6], [34, -25, -1], [28, -13, -1], [-38, 18, 10], [2, 7, 29], [28, 16, 0], [-38, 34, 4], [14, 5, -19], [-13, 7, -6], [66, 1, -1], [21, 7, -14], [-50, 22, 6], [-10, 22, 16], [30, -40, -8], [-6, 3, -11], [15, -6, -7], [32, -2, -14], [54, 10, -10], [-24, -4, 8], [-8, 6, -8], [30, -27, 1], [-24, 24, 4], [-44, 6, 0], [-2, 8, 6], [34, -7, 15], [18, -4, -24], [-18, 2, 12], [14, -6, 6], [-19, -11, -4], [9, -20, 3], [28, -6, 2], [-22, -11, -13], [-20, 9, 19], [-46, 11, -7], [41, -12, -15], [12, 21, -9], [-6, 7, -17], [15, 19, 10], [6, -37, 9], [-29, 13, -14], [8, -8, -24], [-34, -4, -8], [22, 0, 6], [17, 22, -11], [-4, 8, -4], [-22, 6, -10], [-20, -4, 20], [82, -7, -5], [23, 24, -15], [-22, -19, -3], [9, 11, -10], [-23, 40, 1], [17, -25, 10], [62, 14, -2], [50, 1, 7], [58, 7, -9], [70, -3, -9], [-22, 8, -6], [-39, 31, 8], [-60, 38, 14], [-54, -4, -4], [-24, 24, 12], [17, 17, -2], [30, 19, 5], [12, -14, 0], [-26, -6, -20], [-9, 7, -22], [20, -22, -22], [32, 23, -21], [10, -16, 14], [10, -6, 6], [-10, -26, 16], [24, -30, -12], [29, -6, -17], [42, -38, -18], [8, -28, 4], [-18, 2, -22], [-17, 6, 1], [-32, 2, -2], [42, -4, -8], [18, 16, 0], [-63, -3, 2], [13, -18, -3], [3, 31, -4], [20, -1, -5], [8, -3, -17], [14, 3, 15], [-24, -25, 3], [38, -14, -2], [20, -28, 0], [7, -15, -16], [10, -18, -14], [4, 40, -12], [50, -4, -8], [17, 3, -2], [62, -23, -7], [0, -26, 14], [-46, 6, 2], [-4, -2, 4], [10, -19, -3], [48, 2, 8], [-3, -10, 17], [50, -28, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6160_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6160_2_a_bm();".
// 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_6160_2_a_bm(:prec:=3)
    chi := MakeCharacter_6160_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_6160_2_a_bm();".
// 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_6160_2_a_bm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![4, -4, -2, 1]>,<13,R![-4, 0, 4, 1]>,<17,R![4, 0, -4, 1]>,<19,R![160, -16, -8, 1]>,<23,R![-16, -8, 4, 1]>],Snew);
    return Vf;
end function;