
// Make newform 6160.2.a.bc 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_bc();".
// 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_bc();".
// 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, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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], [-1, 0], [-2, 1], [-2, 1], [0, 0], [2, -4], [2, -2], [-2, -1], [-8, -2], [-4, -3], [-2, -4], [4, -1], [-4, 2], [-6, -3], [-4, -1], [10, 4], [4, 6], [2, -1], [-6, -6], [4, 8], [2, 2], [-6, 4], [-4, 3], [-4, 5], [0, 0], [-2, 2], [-6, -8], [-4, -4], [-4, -8], [-12, -2], [0, 10], [-2, 8], [2, 14], [-10, 6], [6, 4], [8, 6], [-2, -9], [-8, -8], [-6, -4], [12, 4], [8, -6], [-4, -10], [-2, 3], [-4, 8], [0, -7], [-12, -4], [6, 6], [0, -12], [8, -12], [12, 1], [2, 15], [-10, 10], [4, 12], [-14, 12], [12, 2], [0, -2], [2, 2], [4, -8], [-2, -7], [8, -6], [-14, -1], [2, -16], [-18, 12], [4, 0], [-4, -4], [-10, 12], [-12, 15], [6, 16], [-2, 14], [4, 19], [8, 14], [-8, 2], [-8, -13], [2, 4], [6, 2], [-6, 0], [4, -3], [-30, -1], [-12, 0], [-22, -2], [-14, -18], [-8, -14], [-10, -14], [-8, -4], [-8, 14], [8, 21], [6, 12], [4, 3], [0, 4], [10, -16], [-6, 10], [-12, -18], [12, 0], [-2, -2], [10, -12], [-4, 2], [-2, 8], [36, 0], [4, -2], [-36, -6], [-14, -10], [12, -8], [18, 4], [-28, 7], [30, 5], [-8, 2], [-4, 25], [0, -2], [12, -4], [-12, -2], [-18, -15], [-8, 0], [12, 8], [-12, 17], [12, 9], [-2, -32], [-38, -6], [22, -2], [-12, 12], [-2, 13], [-14, 2], [10, -9], [2, -10], [-18, 0], [-10, -11], [12, 13], [10, 25], [12, 28], [28, -12], [24, 2], [-6, -4], [28, -11], [-32, -5], [30, 0], [-32, 10], [-18, -10], [46, 0], [0, -2], [26, 12], [42, -6], [-14, 0], [6, 4], [-30, 5], [18, -3], [26, 11], [-30, -1], [18, -6], [-12, -28], [2, -12], [-2, -34], [20, 18], [30, -4], [12, 10], [32, 12], [-18, -28], [-6, 1], [-16, 7], [18, -14], [12, 18], [18, -12], [-14, 5], [26, 20], [-20, -9], [-4, -10], [-2, -25], [-18, -8], [14, -24], [-36, -4], [-42, 10], [18, -22], [44, 0], [10, 19], [-22, -2], [-2, 22], [28, 16], [8, 12], [4, -13], [54, 2], [-32, 4], [18, 4], [-18, 15], [38, -2], [-38, -8], [-4, 6], [-48, 9], [-14, -10], [-8, -10], [-34, 14], [20, -24], [40, -10], [-10, 18], [-46, 8], [38, 14], [-2, 2], [8, -14], [-38, 13], [-16, -2], [-14, -24], [-8, 6], [38, -10], [0, 33], [-14, -25], [-62, -4], [42, -7], [48, 8], [-14, -12], [-38, 5], [4, -16], [-22, 6], [30, -2], [0, -9], [4, 36], [38, 18], [54, -12], [-12, -33], [-10, -20], [-50, 4], [-22, 10], [-24, -12], [-28, 24], [6, 2], [-20, -2], [18, -10], [-26, -6], [-32, -4], [4, 18], [-18, 14], [-16, 18], [40, 0], [24, -24], [38, 4], [56, -11], [-16, 20], [6, 30], [44, 18], [-8, 22], [-14, 9], [54, 4], [56, -6], [-24, 1], [-64, -4], [-26, 27], [28, -30], [48, -7], [-6, -5], [4, -12], [12, -40], [-12, -2], [36, -11], [34, 0], [2, -22], [10, 1], [-20, 12], [-4, -28], [28, -8], [-54, 8], [22, 19], [10, -40], [-36, -28], [-36, -19], [10, -9], [-10, 14], [34, 17], [4, 36], [-46, -2], [-18, -32], [16, 44], [-34, -4], [14, 44], [42, -14], [24, 20], [22, 23], [-8, 41], [-22, -2], [34, -8], [6, 40], [20, -34], [28, 18], [52, -10], [-36, -8], [-20, -23], [-28, -28], [-40, 18], [-16, 2], [32, 22], [18, 7], [8, 11], [16, -28], [-56, 15], [-44, -4], [24, -26], [-32, 18], [-8, -31], [18, -9], [-54, 8], [-28, -6], [-8, -18], [18, -7], [36, -32], [42, -18], [30, 4], [36, -14], [-44, 26], [2, 42], [2, -4], [20, 4], [56, 10], [12, 48], [10, 48], [-6, 30], [38, 22], [2, 24], [-48, 3], [-10, 5], [8, -24], [42, -6], [-2, 2], [20, 4], [-22, 32], [-52, 11], [-54, 22], [-48, 30], [22, -12], [-16, -46], [-44, 15], [42, -16], [-24, 40], [70, 8], [24, -38], [-8, -30], [-36, 14], [22, -2], [-64, -11], [28, -12], [22, -17], [-26, -24], [20, -16], [2, -36], [12, 18], [-12, -47], [-16, -12], [2, 40], [-36, 0], [14, -28], [6, -4], [-8, -26], [-2, -54], [16, 0], [-48, 18], [26, -24], [-12, -4], [18, -8], [2, -65], [-50, 7], [-16, 4], [-4, -6], [-6, 14], [44, -34], [32, 25], [-38, -14], [46, -34], [-16, 45], [20, -14], [6, -49], [12, -32], [-38, -28], [-12, -10], [22, -35], [-60, 0], [-30, 44], [0, 22], [28, -30], [-10, -39], [-46, 14], [2, 17], [0, 7], [50, 29], [2, -52], [-40, -22], [-30, 16], [48, 6], [16, 24], [12, 25], [-16, 48], [38, 4], [-16, -4], [16, -51], [-16, -8], [-22, -44], [4, -18], [28, -21], [-16, 36], [-8, 12], [60, -10], [14, -12], [60, 30], [-10, -10], [-72, -3], [-34, 4], [-40, -16], [6, 44], [-76, 3], [-36, -48], [22, 32], [62, 12], [-12, -47], [-10, -5], [26, 9], [44, -24], [26, -10], [-42, 6], [8, 44], [-6, 18], [24, -44], [36, 3], [-58, -12], [16, -32], [-18, -12], [-10, 29], [30, 28], [-48, -10], [62, -20], [-14, 8], [-62, 24], [22, 10], [-26, -11], [-20, 4]];
    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_bc();".
// 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_bc(:prec:=2)
    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_bc();".
// 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_bc( : 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, 0, 1]>,<13,R![2, 4, 1]>,<17,R![2, 4, 1]>,<19,R![0, 1]>,<23,R![-28, -4, 1]>],Snew);
    return Vf;
end function;