
// Make newform 6160.2.a.bh 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_bh();".
// 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_bh();".
// 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], [0, 0, -1], [-1, 0, 0], [1, 0, 0], [-1, 0, 0], [0, 0, -1], [-2, 4, 1], [0, 2, 4], [3, -5, -1], [-4, -2, -2], [-3, 3, 0], [-1, -5, 3], [-3, -3, 2], [7, 1, 3], [-6, 4, 3], [-7, 1, 1], [5, -1, -2], [3, 5, 0], [7, 3, -3], [2, -2, 2], [-2, -4, -5], [-3, -3, -1], [-4, 6, -2], [-8, 0, 4], [-4, 8, 4], [1, -3, 4], [4, -4, 3], [6, -2, -6], [-2, 4, 6], [-2, 0, -6], [2, -2, -4], [-4, -4, 4], [-1, -1, -1], [4, -8, 2], [6, -12, -6], [-1, -5, -5], [0, -4, 10], [-7, -3, -9], [-2, 0, -6], [-8, 2, -3], [2, 2, -2], [10, 2, -4], [-10, 10, 4], [1, -5, -11], [-19, 3, 1], [-13, 7, 0], [-2, -2, 4], [-16, -4, -5], [16, -4, 0], [8, -2, 4], [-7, 7, 3], [6, -6, 8], [-13, -1, 4], [3, -11, -10], [-6, -6, 0], [-6, 6, 8], [-4, 12, -2], [-12, 12, 6], [1, -9, 3], [2, -8, -4], [-6, 2, -10], [-4, 6, -5], [-8, 10, 12], [-5, -9, -8], [8, -6, -6], [-22, 8, 0], [-8, 4, -6], [-7, -5, -11], [15, -7, -1], [1, -13, -2], [-12, 6, 6], [-1, 3, 9], [4, -10, -3], [3, 1, -5], [-6, 10, -6], [-18, 6, -5], [-6, 8, 10], [10, 6, 0], [10, 8, 12], [-3, -5, -12], [-7, 5, -6], [-11, -5, 5], [-7, -11, -5], [-2, 0, -10], [10, 2, -8], [5, 9, 13], [-23, -5, 1], [-11, -1, -11], [-31, 13, 6], [-13, -5, -11], [-24, -8, 5], [-6, 8, -10], [23, -17, -5], [3, -1, 1], [0, -8, -4], [-12, -2, -18], [6, 4, -6], [-14, 2, 4], [20, -10, -4], [-2, -12, 6], [24, -12, -2], [3, 13, -11], [-2, -6, -8], [2, 8, 2], [14, 14, -4], [2, 10, -6], [2, -10, 3], [-12, 4, 7], [8, 8, -12], [11, 7, 16], [-10, 0, -18], [-3, -5, -17], [3, -17, -5], [5, 1, 16], [4, 4, 12], [19, -27, -13], [-12, -2, 3], [12, 10, 23], [-26, 0, -2], [41, -3, 1], [2, 22, -2], [-19, -9, 9], [14, -14, 1], [9, 5, 15], [-1, 3, 0], [-28, -2, -4], [26, 4, 8], [27, 3, -2], [-12, 2, 19], [-2, 4, -3], [-8, -12, 8], [-2, 2, 6], [12, -8, 18], [-20, 10, -8], [-9, 17, 14], [21, 5, 4], [4, -4, -4], [2, 18, -8], [8, -12, -10], [-20, 22, 2], [18, 16, -8], [-8, 22, 16], [3, -17, 1], [9, 15, -3], [26, -8, -8], [11, 7, -6], [-12, 0, -5], [-20, -6, -11], [9, 15, -4], [-15, 1, -3], [-11, 15, -5], [2, -6, -8], [19, 7, 21], [-8, -12, -2], [3, -9, 7], [-10, -2, 2], [-2, 2, 0], [10, 6, 24], [-20, 4, -5], [31, 1, -8], [-9, -5, -9], [-7, -17, -1], [-29, 21, 11], [3, -17, -10], [-6, -12, -14], [-26, 20, 15], [-2, -10, -12], [-22, 24, 15], [24, -22, -12], [4, -16, 4], [2, -14, -16], [26, -18, -10], [11, 3, 19], [-17, -3, 5], [-19, -15, 2], [-6, 4, -14], [9, -15, 3], [-3, -5, -11], [16, 22, -14], [7, -5, -2], [11, -13, 3], [18, 4, 10], [-24, 22, -4], [22, -6, 11], [-35, 5, -9], [-2, 22, 0], [-1, -19, 21], [-36, 6, -1], [26, -4, 0], [-8, -6, -22], [8, 10, -12], [4, -12, 8], [18, -10, -16], [-44, 16, 4], [21, 3, -3], [26, -2, 8], [28, 10, -10], [7, 3, -25], [20, -20, -5], [16, -4, 22], [12, 10, -4], [6, 16, 20], [36, 6, 12], [7, -7, -14], [17, -1, 24], [-18, 12, 16], [-25, 5, 20], [6, 6, -4], [-34, 16, -2], [1, -13, -18], [19, -11, 1], [-24, -6, 4], [-9, 11, -5], [-18, 32, 23], [-14, 0, 22], [-26, 2, 10], [13, 3, -7], [9, -27, -20], [-1, 7, 5], [2, 0, -26], [20, -2, -4], [-10, -28, 18], [-21, 13, 3], [1, -27, -21], [-18, -8, -2], [0, 22, -12], [8, 6, 8], [-20, 36, 4], [16, -12, 18], [27, -5, -17], [7, -21, -13], [4, -8, -20], [-20, 8, -4], [56, -10, -6], [2, 28, 13], [-30, 12, 4], [-22, 12, 18], [-3, -33, 9], [-26, -18, 18], [-23, 25, 20], [-7, 5, 19], [26, -2, 12], [-16, 30, 11], [41, 11, 3], [-18, -18, -5], [22, -16, -8], [-50, 0, 13], [-39, -11, -6], [8, 4, -24], [-6, 26, 8], [25, 3, 21], [9, -9, -24], [15, 7, 11], [34, -6, -10], [4, -26, -33], [-4, 0, 16], [-13, -7, -19], [26, -16, -24], [-28, 2, -14], [-6, 6, -5], [-1, 21, -5], [-16, -8, 8], [9, 13, 26], [-20, 2, -11], [18, 10, 32], [57, -15, -12], [3, 1, -11], [-46, 8, 6], [15, -27, -1], [-15, -13, -3], [-32, -14, -2], [-11, -31, 3], [2, 4, -2], [-12, -20, -44], [14, -4, -21], [18, 18, 21], [13, 29, -25], [60, -2, 2], [4, -30, 16], [6, 26, 12], [-26, -4, -6], [38, -10, -8], [30, -8, 16], [-23, -21, -16], [2, -12, -8], [0, 4, -12], [-11, 21, 25], [23, -23, -13], [7, 7, 12], [-23, 11, 14], [-3, 35, 15], [-38, 6, 11], [-21, 13, -27], [-20, 16, -2], [11, -11, -9], [41, -7, -2], [41, 7, 8], [14, -2, -10], [4, 12, -2], [26, -14, -8], [-20, -24, 19], [-53, -3, 3], [-9, -13, -41], [-5, 7, -1], [-36, 12, 14], [31, -25, -9], [-41, 43, 15], [4, -22, -22], [-6, 14, 2], [13, -1, 3], [0, 8, 16], [2, -20, -2], [-14, 12, 24], [11, -13, -7], [-37, 9, -13], [-1, -21, 14], [57, 5, 12], [-34, 26, 4], [4, 14, 32], [0, 6, 24], [62, -10, -2], [14, 0, -30], [5, 15, 26], [33, -7, -27], [29, -9, 13], [2, -20, -28], [-26, -6, -24], [54, -6, -5], [43, -3, 11], [31, -7, 9], [-22, 36, 10], [-25, 23, 19], [-10, -12, -36], [4, 20, -26], [-45, 51, 23], [30, -4, -15], [-53, 1, 9], [-18, 14, -13], [-8, 18, -2], [-48, 22, 10], [-44, 22, 0], [-41, -9, -33], [-17, 13, 10], [-36, 0, 6], [-48, -2, 2], [-4, 12, -8], [-24, -4, 6], [-29, 19, 3], [-2, -12, -8], [8, 10, -20], [38, 0, -22], [-27, -19, 5], [-22, -12, -10], [-2, 0, 36], [-52, 34, 10], [-8, -28, 9], [45, -19, -18], [18, -6, 2], [23, -11, -21], [-31, -3, -11], [-23, 27, 21], [-3, -35, -6], [33, 9, 37], [73, -3, 3], [0, -18, 15], [-5, -5, 15], [-44, -2, -7], [34, 14, 4], [-54, 4, -4], [16, 12, 4], [-1, -15, 0], [-22, 2, -16], [-4, -22, -6], [-60, 34, 18], [-43, -19, -11], [-15, 21, -16], [-61, -21, 11], [-10, 4, 25], [1, -13, -26], [-26, 0, 5], [-18, 16, 16], [9, 1, 13], [-29, 21, 11], [-73, 9, 9], [-16, 18, 16], [-80, 8, 11], [-52, 12, 2], [-14, 4, 24], [-10, -22, 0], [2, -14, -7], [61, -17, 1], [-22, 10, 14], [32, -52, -10], [-32, 20, -23], [-8, -20, 6], [3, 37, -5], [30, 30, -20], [10, -8, 28], [32, 24, 30], [70, -28, -6], [21, 29, -2], [56, -22, -14], [20, 20, 20], [2, 20, 32], [-11, 33, 28], [32, 20, -8], [2, 16, 24], [-12, 26, -16], [-56, -16, 3], [-5, 11, 32], [-50, -2, 13], [19, -3, -1], [-23, 17, 39], [1, -39, -21], [47, 5, -13], [4, -12, 12], [-8, 0, 0], [30, 22, 35], [10, 24, 8], [-12, 16, 20], [18, 16, -32], [18, -28, 21], [7, -1, 5], [-48, 22, 2], [-8, -34, -34], [-10, -38, 14], [-25, -9, -35], [28, -18, 14], [-13, -23, -28], [-8, 14, 32]];
    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_bh();".
// 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_bh(: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_bh();".
// 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_bh( : 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, -4, 0, 1]>,<13,R![-2, -4, 0, 1]>,<17,R![-134, -48, 2, 1]>,<19,R![200, -60, -2, 1]>,<23,R![268, -72, -4, 1]>],Snew);
    return Vf;
end function;