
// Make newform 4560.2.a.bn in Magma, downloaded from the LMFDB on 23 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_bn();".
// 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_bn();".
// 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_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], [2, 1], [2, 1], [0, 2], [-1, 0], [2, -2], [0, 5], [2, -2], [2, -3], [0, -7], [-4, 5], [6, 2], [0, -6], [4, 2], [4, 4], [0, -8], [12, -2], [-6, 4], [8, -4], [2, -4], [-8, 3], [2, -7], [2, 2], [8, 8], [8, -4], [-6, -10], [-4, 8], [0, -4], [6, 9], [10, -4], [0, -2], [-10, -4], [2, 2], [10, 10], [8, -11], [6, -8], [0, 8], [16, 2], [6, -10], [18, 3], [6, -5], [8, -10], [12, 2], [-20, 0], [0, 8], [-6, 4], [-16, 4], [10, -4], [22, 3], [18, 4], [10, 3], [12, 0], [2, 0], [-4, -13], [0, -2], [-2, 16], [-12, 13], [-12, -3], [-4, -4], [-16, 10], [2, -15], [6, -14], [12, -10], [-2, -10], [22, 3], [-10, 8], [-6, 0], [-18, -8], [2, 11], [-12, 9], [-10, 5], [-18, -6], [12, -16], [-18, 12], [-6, -16], [0, -13], [-2, 2], [-14, -11], [6, 16], [8, 10], [-10, 3], [-16, -8], [2, 18], [4, 13], [2, -10], [18, 8], [-12, 9], [14, -2], [-10, -3], [-4, 14], [-6, -13], [-16, -10], [18, 8], [-12, -5], [-8, -11], [-4, 14], [-2, 8], [0, -6], [18, 4], [-6, 4], [-4, -27], [-12, 10], [-18, 6], [-2, -18], [22, 16], [0, -12], [26, -14], [-8, -18], [-10, -2], [16, -22], [-12, 6], [8, 20], [24, -5], [36, -5], [-14, -8], [-4, 10], [-12, -12], [-18, -22], [10, 3], [32, -2], [-24, -8], [-28, 14], [6, 12], [-20, 0], [-6, 3], [-20, 3], [-22, -8], [4, 8], [4, 32], [30, -10], [-18, 6], [-34, 4], [-6, 20], [-20, -18], [4, -2], [16, 8], [-42, 8], [-36, 12], [-2, 14], [24, -19], [-2, 4], [-26, -18], [-20, 10], [6, 2], [0, 18], [8, 0], [12, -32], [-22, -17], [-26, -6], [40, -3], [16, 4], [-16, -26], [-12, 16], [12, -28], [-34, -14], [-10, 14], [12, 3], [-10, 20], [20, -12], [16, -1], [-44, 0], [12, 6], [18, -24], [16, -4], [2, 18], [-18, 12], [-6, 0], [-20, 10], [30, -8], [6, 15], [26, -12], [-24, 16], [30, -14], [-28, -2], [30, 14], [-24, 10], [-30, -8], [-4, 27], [-12, 28], [-34, -1], [32, -8], [30, 18], [-6, -12], [-50, 5], [4, 10], [10, -6], [22, -27], [-26, 17], [-10, -2], [-4, -24], [-32, -1], [22, -6], [36, 20], [-12, -28], [-26, 0], [4, 10], [-14, 14], [-16, -21], [40, 0], [-42, -5], [26, 16], [-66, -3], [40, -18], [8, -8], [38, -8], [10, 2], [-60, 4], [-30, -18], [-22, -30], [20, 25], [-14, 28], [-36, -6], [50, 2], [36, -3], [-40, 1], [-34, -12], [20, -30], [-46, 8], [-10, 6], [-16, 27], [24, 11], [-14, -36], [2, -8], [0, 16], [8, -6], [-4, -32], [-26, 5], [34, -10], [18, -34], [-8, -4], [-8, 27], [-32, -25], [-42, -10], [-8, -24], [-26, -12], [22, -27], [12, 22], [0, 12], [-28, -24], [-4, -27], [-26, 34], [40, -22], [-38, 9], [48, -1], [-24, -28], [18, 6], [-14, -28], [-42, 10], [-6, 36], [38, 12], [42, -10], [60, -2], [-10, -9], [-40, 4], [8, -32], [-36, 2], [-18, 40], [-8, -12], [28, 36], [-6, -16], [34, -13], [12, 18], [-6, 38], [0, 19], [-58, 6], [28, -12], [28, -18], [-10, 36], [24, 16], [46, 22], [4, -6], [-10, -9], [40, 19], [26, -12], [-22, 2], [-2, -10], [-42, -17], [-52, 4], [12, -16], [-54, -10], [30, -4], [4, 23], [26, -11], [-14, -8], [32, 18], [24, -16], [4, -19], [-10, -34], [34, 28], [4, 10], [20, 6], [46, 25], [2, -14], [-32, -24], [8, 54], [20, 40], [32, 11], [42, 20], [64, -6], [52, 0], [-2, 8], [16, 30], [-26, -13], [12, -20], [26, 44], [-54, 17], [22, -10], [2, -6], [-6, 4], [16, 7], [-8, 30], [34, -28], [18, 8], [-10, -43], [-40, -12], [74, 6], [14, -40], [-14, 38], [34, 22], [40, -13], [36, -14], [0, -22], [74, -4], [20, 0], [-36, -38], [-30, 0], [8, -14], [34, -24], [24, 42], [24, -42], [14, -12], [16, 14], [-30, -8], [26, 8], [20, -42], [20, 36], [28, -15], [-54, -17], [-58, -4], [40, -21], [18, 34], [24, 10], [0, 12], [12, 44], [12, 4], [8, -44], [-10, 36], [30, -34], [2, 3], [34, 14], [-72, -14], [54, 10], [-4, -50], [-30, 9], [-2, 21], [52, 6], [44, 0], [2, -4], [-14, -16], [-36, -12], [40, -26], [72, -3], [-30, -31], [18, 16], [84, 10], [34, -22], [10, -7], [12, -52], [10, -16], [-48, 15], [20, 12], [-50, 18], [12, 40], [14, 13], [18, -20], [-34, -10], [78, -1], [40, -37], [-12, 50], [28, -21], [-70, 4], [2, -22], [-26, -32], [-4, 54], [-10, 24], [0, 23], [-18, 36], [18, -38], [-56, 2], [10, 13], [64, -21], [16, -2], [-10, -39], [-54, 26], [28, 25], [-10, -30], [-18, 12], [-6, 56], [28, 34], [16, -10], [-60, 20], [-68, -7], [44, 16], [-46, -14], [-44, 33], [40, -18], [-6, -51], [-26, 5], [8, -38], [-4, -20], [-12, 14], [42, -16], [46, 0], [52, 12], [4, 32], [-26, -4], [12, -8], [56, -31], [-46, 19], [18, 30], [12, -12], [38, -5], [16, 4], [-72, 4], [-6, 16], [-68, 10], [-50, 21]];
    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_bn();".
// 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_bn(: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_bn();".
// 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_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, 0, 1]>,<11,R![2, -4, 1]>,<13,R![2, -4, 1]>,<17,R![-8, 0, 1]>],Snew);
    return Vf;
end function;