
// Make newform 4560.2.a.bm in Magma, downloaded from the LMFDB on 19 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_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_4560_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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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], [0, 1], [0, -1], [-2, 1], [-2, -2], [1, 0], [-4, 0], [2, -1], [0, 0], [-2, -1], [2, -1], [0, -1], [-4, 0], [-2, 0], [-8, 0], [-2, 4], [-4, 2], [-8, 0], [-6, 2], [-8, -2], [-8, 0], [10, -1], [-2, -1], [2, -2], [-4, 2], [-4, 0], [14, 0], [2, 2], [-12, 0], [-8, 1], [6, 6], [-4, 2], [10, 2], [-8, 4], [2, 0], [0, 1], [0, 2], [6, 2], [0, 4], [6, -4], [-16, -1], [6, -7], [-14, 4], [8, -6], [-4, 8], [4, -6], [4, -2], [-2, -8], [6, -2], [-8, -7], [-22, 0], [0, 3], [-6, 6], [-4, -2], [10, 3], [0, -6], [-14, 0], [-6, 5], [0, -3], [-2, -2], [12, -2], [-16, -5], [2, 0], [-18, 0], [20, 2], [6, 3], [-16, 4], [6, -4], [-26, 2], [0, 3], [8, -5], [14, 1], [-4, -2], [-8, 8], [10, -8], [-6, -8], [10, 1], [10, 6], [16, 7], [-10, -2], [-16, -6], [-10, -3], [-8, 10], [8, -2], [26, 3], [-6, 4], [2, -10], [0, -5], [16, 2], [0, 7], [12, 2], [-16, -3], [-4, 2], [20, 6], [2, 13], [-14, 1], [-4, -8], [-10, 0], [12, -2], [-6, -8], [4, -6], [18, 7], [12, 6], [2, 0], [8, -6], [22, -6], [16, -6], [-14, -2], [-12, -2], [18, 8], [-26, -6], [44, 2], [0, 8], [26, -1], [8, 13], [12, -2], [2, 8], [24, 6], [-18, 4], [-18, 11], [-2, 0], [-20, -8], [4, -2], [-6, 10], [14, 0], [-8, 9], [8, 3], [-14, -6], [-12, 4], [-48, 0], [-24, 0], [26, -2], [2, 14], [18, 8], [6, 8], [-12, -12], [-42, -2], [-22, 4], [-4, -16], [34, -2], [-16, -1], [4, -2], [46, 0], [16, -8], [26, 10], [-6, -8], [36, -4], [-16, -8], [6, 1], [-22, 10], [0, 9], [-16, 8], [-12, 4], [-32, 8], [0, -4], [-6, -16], [2, 2], [2, -13], [8, 8], [-14, -2], [24, -9], [0, -18], [18, -12], [24, -2], [-8, -6], [42, 4], [10, 12], [18, 4], [16, 6], [38, 2], [-40, -1], [2, -20], [-32, -2], [34, -8], [12, -6], [42, -2], [-36, 2], [14, 8], [-8, 9], [24, -6], [-18, -7], [18, 10], [-4, -20], [10, -14], [6, -1], [-28, 0], [-6, -10], [0, 17], [-18, 9], [-8, -14], [52, 0], [-22, -1], [8, -14], [-6, -6], [-6, 12], [-22, 10], [-2, 18], [-20, 0], [10, -5], [48, 2], [54, 5], [42, -4], [-8, 5], [-14, 16], [0, 20], [28, 10], [-14, -6], [4, -12], [58, 0], [-38, -4], [-16, -1], [-28, 10], [32, -2], [-14, -6], [8, -1], [42, -11], [0, 18], [-6, 8], [38, -6], [24, -8], [10, 7], [-32, -3], [-20, -2], [6, 0], [18, 6], [0, 10], [-12, -4], [24, 17], [10, 14], [-12, -6], [-24, 2], [10, -1], [32, -9], [-12, -12], [26, -4], [-6, -16], [40, 5], [32, 2], [-4, -12], [4, 0], [-16, 1], [22, 12], [-38, 0], [-16, -3], [-8, 17], [8, -12], [-28, -18], [-4, 10], [2, -10], [34, -8], [36, 10], [-38, 2], [-6, -4], [48, -5], [22, -16], [4, -4], [-66, 0], [10, -2], [36, -10], [-44, -8], [22, -12], [-2, -3], [14, -10], [-44, 10], [10, -1], [10, 16], [20, 8], [2, -16], [-74, 2], [-76, -2], [-6, -2], [-16, 2], [6, -21], [8, -21], [-24, 16], [-26, 8], [-30, -2], [0, 9], [-48, 8], [-24, 20], [-20, -20], [-2, 10], [-32, 15], [-8, 3], [-62, -4], [-42, -4], [40, 4], [34, 11], [-46, 10], [-24, 12], [-46, 4], [-16, -18], [-2, 1], [-30, 8], [-56, -6], [18, 12], [-16, 16], [0, -21], [-22, 6], [-10, 0], [8, 20], [4, 6], [36, -6], [-2, 7], [4, -4], [-18, -10], [-16, -21], [-30, -18], [44, -12], [2, 0], [58, 9], [-52, -6], [-4, -18], [-30, 0], [64, 9], [-72, 0], [-22, -8], [-14, -18], [52, -10], [42, -10], [-30, 3], [4, 8], [-10, 6], [26, 20], [-44, 4], [-44, -16], [8, 6], [-38, 4], [14, -20], [-10, 0], [32, 2], [16, 4], [36, 10], [-64, 0], [-10, -22], [34, 12], [-62, -8], [-16, -15], [-50, 9], [-18, -2], [-62, 5], [0, -16], [6, -12], [-48, -2], [-34, -4], [-20, 6], [0, -10], [-30, -16], [28, 2], [14, -11], [-6, 12], [-4, 6], [46, -12], [-38, -12], [0, -27], [56, 7], [38, -10], [24, 20], [-38, -4], [-22, 14], [-56, -4], [32, 18], [32, -3], [6, 17], [-38, 4], [-60, 6], [-14, -22], [24, -7], [-52, -4], [36, 2], [-62, 1], [0, 0], [42, 16], [24, 0], [-24, -11], [66, -4], [74, -4], [6, 23], [-30, 21], [-42, 6], [-16, -17], [94, -2], [-20, -22], [56, -10], [-72, -6], [2, -20], [-16, -23], [-40, 6], [-30, 2], [-2, 16], [-48, 19], [48, -11], [-56, 10], [-18, 29], [-8, 28], [2, -15], [-4, 14], [-38, 8], [6, 10], [30, 6], [44, -16], [-14, -22], [34, 11], [72, 4], [10, -4], [26, -9], [4, 6], [32, -9], [-74, 3], [50, -8], [-60, -4], [4, 2], [-6, 18], [10, 14], [40, -6], [44, 12], [30, 14], [-88, 0], [2, -23], [62, 5], [12, -4], [24, -4], [-34, 25], [6, -10], [-44, -8], [26, 4], [-28, -2], [48, 17]];
    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_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_4560_2_a_bm(: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_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_4560_2_a_bm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, 0, 1]>,<11,R![-8, 0, 1]>,<13,R![-4, 4, 1]>,<17,R![-28, 4, 1]>],Snew);
    return Vf;
end function;