
// Make newform 6160.2.a.bp in Magma, downloaded from the LMFDB on 25 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_bp();".
// 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_bp();".
// 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], [0, 1, 0], [-2, -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_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, -2], [-3, 3, 2], [2, 0, 2], [1, 3, -3], [0, -2, -2], [6, -2, -1], [-1, 3, 1], [0, 2, 1], [-1, 1, -3], [5, -1, 4], [1, 1, -5], [4, -4, -1], [-2, 2, 1], [3, 1, -3], [2, -6, 2], [-1, -3, 2], [-3, -3, -7], [6, 4, 4], [8, -4, -4], [-2, 2, 2], [-6, -4, -3], [9, 5, 0], [6, 2, -2], [8, 2, 4], [6, -4, -2], [6, -10, 0], [8, -4, 0], [-1, -1, -3], [-2, 10, 4], [4, -2, 4], [3, -1, -7], [-12, -4, 2], [13, 3, 3], [-6, -4, -10], [-3, -1, 8], [6, -6, 2], [-8, 12, 6], [8, 8, -2], [-9, -1, -9], [3, 3, -1], [2, 4, 11], [-2, -2, 4], [5, -3, -8], [12, 4, 0], [2, -8, -2], [5, -7, -1], [-2, 10, 12], [-2, -8, -9], [-4, 0, -7], [-2, -10, -8], [-6, -6, 0], [-2, -6, 0], [14, -6, -4], [1, -3, 3], [2, 4, 0], [14, -6, -2], [3, -3, 12], [-8, -2, 4], [-10, 0, -13], [-16, 10, 6], [6, -4, 8], [2, 10, 4], [-25, -5, -1], [11, -15, -7], [4, 4, 3], [-4, 6, 2], [-5, 7, 11], [27, 1, 2], [5, 5, -3], [6, 6, 6], [-7, 1, 6], [-2, 0, -14], [-2, -2, 0], [-6, 4, 8], [14, -18, -1], [-8, -14, 1], [9, -17, -13], [-15, 5, -3], [12, 6, 4], [-8, 12, 2], [-5, -3, 11], [13, -9, 3], [-9, -5, 11], [4, -10, -11], [-33, 1, 1], [19, -5, 0], [-16, -2, -12], [13, -21, -7], [-21, 7, -5], [-16, -8, 4], [-10, -8, 4], [16, -10, -4], [8, -8, 2], [-12, -6, 4], [20, -18, -12], [-8, 12, 10], [-17, 3, -15], [4, -4, 6], [8, 2, 12], [-6, -6, 4], [-16, -8, 4], [17, -7, -14], [-1, 11, -6], [0, -12, -4], [-2, -8, -5], [10, 12, -2], [-7, 13, -1], [19, -17, -7], [10, -12, 9], [0, -20, -4], [23, 1, -7], [-7, 19, -6], [-3, -1, 18], [18, -16, -6], [5, 9, 7], [-18, 18, 6], [-5, -17, 7], [17, -7, 4], [13, 11, 7], [14, -20, -5], [18, 4, -6], [-2, -20, -8], [8, 6, -9], [-7, -5, -6], [-7, 3, -22], [12, 8, -8], [-26, 6, -10], [6, 18, -4], [-24, 14, -4], [20, -4, 17], [2, 4, 17], [-18, 26, 14], [-16, 12, 6], [4, -12, -14], [-8, 6, 6], [18, 16, 4], [10, -8, 6], [11, -7, -7], [-3, -1, 11], [26, 12, 8], [-16, 18, -1], [7, -5, -10], [13, -1, -4], [6, 2, 7], [-25, 17, -5], [13, -11, -17], [4, -4, 10], [15, -15, -3], [-22, -10, -4], [17, -25, -19], [-2, -18, 6], [-14, 6, 20], [12, -8, -22], [-37, -9, -6], [-2, 2, 9], [13, 7, 25], [-3, 21, -5], [-37, 1, 9], [-12, 18, 19], [-6, 8, 22], [37, 11, -4], [0, 4, -10], [-41, 25, 10], [-6, 12, -10], [-2, -10, 10], [46, 6, 4], [10, -2, 26], [27, -13, -3], [15, -5, -11], [8, 6, 25], [4, 10, -12], [-11, 13, -3], [5, 11, 7], [-42, -4, -8], [-20, -14, -9], [9, -9, 5], [-4, -14, -28], [-32, -2, 12], [-1, -5, 28], [-3, 11, -9], [4, 8, 18], [35, -5, -11], [-27, -9, -6], [-2, 16, 16], [-32, 22, 14], [-14, 20, 14], [0, 16, -16], [-4, 24, -2], [-8, -4, -12], [13, -29, -5], [-38, -10, 8], [4, 14, -22], [15, 3, 13], [-21, 7, 18], [2, -10, 12], [-18, 28, 2], [-22, 8, -4], [-14, 24, -2], [8, 0, -11], [30, 18, 3], [6, 24, -16], [2, 6, -15], [-10, -22, 24], [4, -2, 16], [8, -24, -9], [-13, 3, -7], [-14, 20, -6], [-23, 7, 21], [21, -5, -20], [-4, -14, -16], [-22, -6, -26], [-35, 3, 15], [-6, -8, -7], [-5, -19, 1], [-6, -4, -2], [38, -8, 2], [-12, 10, -4], [39, -31, -15], [1, 7, -1], [18, -8, 10], [-54, 4, -2], [10, 24, -10], [28, -4, -8], [-34, 2, 8], [19, 3, -3], [-1, -9, -19], [-12, -20, -12], [-4, 16, -20], [-12, 30, 22], [-5, -31, 8], [-12, -2, -14], [28, 10, 20], [-37, 35, 7], [26, -22, -14], [-54, 4, 1], [45, -21, -9], [20, 0, 2], [45, 7, 18], [17, -17, -15], [19, 11, 0], [46, -4, 12], [-5, -27, 12], [-4, -26, 13], [32, -36, -20], [-22, -10, 8], [11, 3, 11], [-10, -10, 7], [5, -17, 5], [-10, -14, -6], [-13, 21, 16], [-8, 12, 0], [7, -15, 27], [-8, 18, 14], [0, 18, 34], [-41, -13, 8], [-17, 33, 25], [-16, -32, 20], [-4, -2, -35], [-7, 7, 16], [6, -18, -16], [-26, -20, -15], [-25, 33, 19], [4, -10, -24], [-21, 33, 29], [-9, -13, 23], [-16, -2, 18], [37, 3, 11], [-8, 26, -8], [36, 4, 24], [3, 1, 22], [-25, -1, 26], [21, -13, -5], [-24, 14, 18], [-2, -4, 6], [-36, 8, -18], [18, -24, -2], [36, 16, 22], [-68, -2, 2], [-34, 46, 11], [12, -30, 10], [52, -8, -4], [57, -31, -17], [-23, 33, -3], [14, -28, -5], [24, 4, 7], [-7, -13, -31], [17, 9, 10], [-29, 27, 5], [-22, -18, -24], [-23, 17, 21], [28, 10, -11], [10, 26, -5], [4, -32, -36], [18, 18, -12], [8, -28, -2], [11, 3, -6], [53, 13, 5], [15, -5, 33], [-43, 15, 5], [22, 2, -4], [-17, 11, -7], [29, -9, -23], [-36, 6, 14], [18, -22, 10], [5, 17, -9], [28, -20, -20], [46, -16, -6], [14, 24, 16], [-21, -11, -3], [-13, 21, 17], [0, -6, -21], [50, -20, -7], [-38, 6, -8], [6, 0, 26], [-2, 8, -38], [-10, -6, 22], [-26, -12, 22], [16, 8, -33], [15, 21, -13], [27, -41, -33], [22, -32, -8], [-12, 16, -10], [-19, 13, -14], [-41, -7, -31], [35, -37, -15], [16, 10, -16], [7, -37, -19], [14, -24, 8], [30, 2, 12], [-21, -21, 13], [3, -27, -8], [-53, -11, -13], [-37, 3, 8], [-8, -14, 30], [18, 32, -20], [0, 26, 44], [-21, -9, -27], [-4, 20, 17], [-18, 30, 36], [8, -6, 38], [8, 16, 28], [-2, -34, 0], [-23, 15, 1], [22, -8, 4], [2, 40, -10], [-4, -22, 8], [-31, -3, -17], [14, 32, -14], [-44, 22, 18], [4, 22, 14], [25, -23, -14], [20, -2, 21], [-34, -22, 6], [5, 13, -11], [51, 17, -9], [-1, -25, 11], [16, -46, -11], [-17, 41, 7], [13, -7, 5], [-15, -25, 2], [-57, 7, 9], [49, -21, 4], [-6, 18, -28], [6, -4, -36], [-16, 40, -12], [30, -6, 33], [22, 10, -28], [40, 14, 42], [20, -2, -22], [17, -19, 23], [10, 28, -3], [43, 11, -11], [9, -25, 14], [28, 8, 19], [-31, -5, -30], [34, -16, 16], [-43, 9, 15], [3, 1, 9], [11, 19, 9], [54, -12, -22], [21, 33, 16], [18, -14, -20], [-18, 20, 4], [-30, -14, 0], [-41, 31, 14], [-3, 23, -9], [4, -24, 8], [50, -38, -20], [15, -29, -24], [10, 22, -20], [49, -39, -23], [-40, 44, 14], [-18, 52, 4], [-10, -18, 16], [44, 2, 24], [-28, -14, -31], [8, 6, -14], [-36, 20, 28], [46, -40, -28], [62, -8, -3], [40, -36, -24], [-42, 12, 8], [-26, 32, 26], [25, -23, 12], [-26, -8, 11], [41, -23, -16], [37, 17, -11], [13, -29, -33], [49, -7, 1], [13, 13, -11], [48, 16, -4], [68, -4, 0], [-43, 13, -6], [-14, 0, 36], [28, 8, 24], [-14, -16, -32], [65, 7, 22], [11, -11, 9], [-24, 22, 18], [-12, 10, 26], [0, -40, 12], [55, 17, 17], [56, -6, 18], [18, -6, -19], [-62, 40, 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_bp();".
// 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_bp(: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_bp();".
// 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_bp( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 2, -4, 1]>,<13,R![-38, -10, 4, 1]>,<17,R![-122, -22, 6, 1]>,<19,R![40, -4, -6, 1]>,<23,R![428, -72, -6, 1]>],Snew);
    return Vf;
end function;