
// Make newform 4560.2.a.bk in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4560_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_4560_2_a_bk();".
// 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_4560_2_a_bk();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_4560_a();"
function MakeCharacter_4560_a()
    N := 4560;
    order := 1;
    char_gens := [1711, 1141, 3041, 2737, 1921];
    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_4560_a_Hecke(Kf)
    return MakeCharacter_4560_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], [1, 0], [-1, 0], [-1, -1], [1, 1], [-1, 1], [0, -2], [1, 0], [-2, 2], [-5, 1], [-4, 0], [-3, -1], [-3, 3], [-1, -1], [-2, 2], [-4, -2], [6, -2], [0, -2], [2, -2], [4, -4], [4, 2], [4, 4], [0, 0], [-11, 3], [-7, -5], [-8, -2], [-6, 6], [0, -4], [-4, -2], [-10, 4], [-4, 0], [3, 3], [-6, 4], [14, 2], [-8, -2], [0, -4], [-4, -6], [1, -7], [-16, -4], [-14, -4], [10, 2], [-8, 2], [-7, 1], [-9, 1], [-4, 6], [6, -2], [-4, 8], [6, -6], [-20, 4], [0, -2], [-14, -4], [-9, -1], [6, -4], [5, -3], [2, -8], [-4, -8], [-1, -3], [-6, 2], [20, 2], [3, 1], [5, -3], [-6, 4], [2, -2], [-15, 1], [22, 4], [-8, 10], [-8, 8], [9, 3], [8, -8], [10, 4], [14, 8], [9, 1], [-15, 1], [-1, 1], [24, 0], [8, 8], [14, -4], [12, 10], [-29, 1], [0, 14], [-3, -3], [14, 0], [-14, 10], [11, -11], [4, -4], [2, 10], [5, -13], [10, -8], [-16, 6], [5, 13], [-22, 2], [25, -7], [18, 6], [15, -1], [10, -10], [-4, -8], [5, 11], [15, -11], [4, 8], [22, 0], [-22, 6], [-2, -12], [-4, -12], [-7, -17], [2, -10], [18, 0], [-26, 6], [-14, 12], [6, -10], [20, -6], [2, 6], [-12, 10], [16, -10], [-14, 6], [-8, -16], [1, 15], [-19, -11], [-20, -8], [-24, 2], [16, 0], [44, -2], [-11, 7], [4, 6], [20, 0], [-22, -10], [-16, 6], [0, -2], [11, 3], [9, 1], [-6, -8], [16, 4], [-4, -12], [4, 8], [14, 4], [-16, 14], [34, 0], [4, -10], [20, 0], [-30, 4], [14, -4], [32, -4], [4, 2], [-11, -3], [-36, 4], [-4, -2], [4, 20], [6, -4], [-4, 10], [16, 4], [-12, -12], [3, -19], [8, -2], [5, 13], [-8, 0], [48, 4], [0, -8], [48, 0], [14, 12], [-8, 14], [3, -7], [8, -16], [-6, 8], [5, -3], [24, 0], [20, -14], [0, 12], [-24, -8], [32, 6], [-26, 4], [-6, 8], [32, 0], [-2, 0], [25, 9], [-22, -8], [16, -16], [18, -8], [-6, -10], [-4, 2], [18, 14], [-2, 0], [11, -5], [8, -8], [-5, -3], [-18, 12], [-30, -10], [20, 2], [-11, 15], [-24, 4], [-28, -6], [-21, -13], [-41, -7], [46, -2], [4, 16], [-13, 1], [-14, 10], [-30, -16], [-4, -10], [42, 8], [28, 10], [-10, -14], [23, -11], [-36, 12], [-9, 1], [-18, -12], [-1, -1], [-16, 2], [12, 4], [-16, 0], [-12, -6], [20, 8], [-30, 0], [30, -12], [-35, 5], [-16, 0], [14, 14], [12, 18], [17, 17], [43, 9], [-24, -20], [-48, -6], [-18, 16], [20, -8], [49, -1], [35, -5], [-4, 12], [46, -8], [2, 0], [34, -6], [12, -8], [3, 3], [-34, -4], [-4, 4], [-20, -20], [-59, 3], [-33, 7], [26, 6], [-36, 6], [74, 0], [-53, -5], [30, -2], [-28, 8], [24, -4], [7, 7], [16, -22], [48, 6], [3, 27], [35, -13], [26, 2], [20, -4], [-28, 0], [-26, -12], [-6, -24], [-12, 0], [-24, -10], [16, 26], [49, 9], [24, -10], [12, 0], [-32, 10], [-36, -14], [-38, 14], [-8, -12], [54, 0], [-1, -15], [-28, 2], [0, 8], [-37, -7], [6, -28], [-48, 12], [0, 2], [38, 8], [30, 18], [-8, 6], [-58, -2], [-7, -13], [-35, -11], [-56, 0], [-12, 30], [4, 26], [15, 15], [0, -16], [0, 24], [-10, 18], [34, 4], [11, -13], [-67, 5], [-42, 4], [-56, 10], [4, 20], [41, 15], [-32, -18], [-12, 4], [52, 2], [-8, -24], [15, 1], [26, 24], [-60, -4], [36, 14], [-30, -22], [-65, -9], [-16, -18], [-16, 18], [-16, 0], [-20, -12], [14, 10], [-27, -9], [-12, -16], [30, -16], [25, 9], [6, 36], [-14, 22], [50, -16], [43, -7], [-70, 6], [20, 8], [-54, -8], [7, -17], [20, 12], [42, 8], [16, -18], [-32, 8], [36, 10], [-29, 25], [-36, 8], [-16, 6], [-10, -12], [-24, 4], [12, 8], [-52, -16], [64, 10], [62, 0], [-52, -10], [-22, 2], [-36, 12], [6, 18], [-32, 8], [-34, -8], [-4, -22], [-56, -6], [35, -13], [59, -3], [22, 8], [41, -1], [-80, 4], [-32, -6], [16, 32], [36, 10], [6, 26], [22, -26], [-38, -8], [-12, 28], [-49, -15], [-82, 4], [-46, 14], [-40, 18], [-24, 6], [-25, -1], [-3, 5], [16, -18], [-4, 4], [-12, -30], [20, 18], [52, 12], [-16, -8], [-39, 17], [-37, 5], [6, -4], [22, 18], [-40, 6], [55, 7], [-28, 8], [12, 8], [-11, -37], [-36, -20], [0, -2], [-18, -34], [-45, -13], [-10, -12], [-38, 24], [-35, -9], [5, -21], [-44, -6], [45, -3], [-14, 20], [-68, -4], [-32, 28], [-66, 6], [32, -18], [65, 1], [20, 24], [24, 14], [32, -22], [17, 33], [77, -3], [46, -18], [19, -11], [-4, -24], [-5, 1], [60, -12], [22, 20], [-50, 16], [4, -30], [36, 16], [-22, 0], [-45, -7], [52, 20], [-48, 22], [17, 15], [-14, -26], [-7, -7], [-23, 19], [-68, 6], [24, 20], [-10, -22], [-36, 10], [12, 2], [42, -6], [-8, -20], [42, -4], [64, 0], [-27, -5], [-49, 1], [38, -14], [-50, 14], [-57, 9], [-66, 8], [40, 28], [-26, -4], [-10, -30], [39, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4560_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4560_2_a_bk();".
// 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_4560_2_a_bk(:prec:=2)
    chi := MakeCharacter_4560_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_4560_2_a_bk();".
// 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_4560_2_a_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, 2, 1]>,<11,R![-4, -2, 1]>,<13,R![-4, 2, 1]>,<17,R![-20, 0, 1]>],Snew);
    return Vf;
end function;