
// Make newform 4560.2.a.e in Magma, downloaded from the LMFDB on 19 September 2025.
// 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_e();".
// 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_e();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [-1], [-1], [0], [4], [-2], [-2], [-1], [-8], [6], [8], [-10], [-2], [8], [8], [-6], [8], [-10], [-4], [-16], [-6], [16], [-4], [6], [14], [10], [-12], [12], [-2], [-18], [-12], [12], [-2], [-12], [-14], [8], [2], [16], [-16], [10], [0], [-26], [-20], [-18], [10], [-24], [-12], [-4], [-12], [-10], [-10], [-12], [-30], [12], [14], [16], [22], [-32], [18], [-18], [-24], [-14], [-12], [-12], [-14], [18], [28], [6], [-20], [22], [14], [-20], [-16], [-10], [-12], [24], [-38], [26], [38], [-14], [36], [-26], [24], [14], [16], [-12], [-2], [-38], [-22], [-40], [-12], [12], [-20], [-12], [20], [-24], [-2], [30], [-4], [-10], [20], [18], [-28], [6], [28], [-14], [44], [-10], [16], [2], [36], [2], [6], [20], [-40], [6], [16], [24], [18], [-16], [22], [6], [42], [-36], [36], [-46], [-26], [12], [-16], [-30], [44], [16], [-40], [26], [-22], [2], [-22], [-44], [42], [-6], [12], [-22], [-16], [12], [-18], [56], [-6], [22], [-20], [48], [-34], [2], [32], [24], [-28], [-16], [40], [10], [34], [30], [20], [54], [-40], [24], [-18], [-40], [40], [-22], [50], [-6], [32], [-2], [-20], [2], [48], [2], [20], [-30], [-4], [14], [-16], [-48], [-2], [22], [-40], [-14], [-58], [20], [-14], [52], [14], [36], [-28], [30], [4], [6], [-46], [-54], [-42], [-48], [-66], [16], [22], [50], [60], [-30], [-16], [36], [-6], [4], [58], [42], [-24], [28], [-8], [-46], [-32], [-10], [40], [2], [6], [-8], [-26], [-32], [-20], [6], [-26], [-56], [4], [-4], [-6], [-52], [-24], [-58], [64], [0], [50], [-54], [-36], [-24], [-4], [20], [-56], [30], [-18], [12], [-8], [0], [-20], [72], [34], [-30], [64], [-14], [-14], [-12], [30], [28], [42], [-22], [44], [12], [-42], [54], [-42], [20], [30], [26], [44], [-6], [14], [-28], [42], [8], [-26], [24], [-20], [46], [-62], [12], [0], [48], [32], [-26], [8], [-4], [-30], [-86], [32], [54], [-22], [-68], [54], [0], [-58], [-30], [-16], [-6], [24], [48], [-38], [-30], [8], [-36], [60], [62], [12], [46], [4], [-30], [16], [2], [-10], [36], [24], [42], [-28], [-24], [-22], [-6], [68], [58], [70], [-52], [-74], [18], [4], [20], [0], [10], [-82], [82], [-40], [12], [36], [-28], [-66], [30], [58], [8], [-26], [-58], [22], [-40], [-94], [-72], [6], [-36], [-80], [42], [-4], [30], [-22], [60], [-10], [38], [-84], [36], [-42], [72], [26], [-62], [72], [-48], [-16], [-34], [-14], [52], [82], [36], [-20], [64], [6], [-64], [-86], [-64], [60], [-62], [10], [-26], [6], [46], [-8], [30], [12], [-16], [40], [-94], [32], [56], [-38], [74], [-12], [32], [-48], [46], [-32], [-90], [28], [74], [62], [6], [68], [-10], [62], [104], [-38], [-50], [-68], [-60], [62], [42], [-36], [68], [-38], [66], [-72], [-20], [-58], [104], [-10], [38], [-40], [64], [-58], [-54], [-28], [-54], [-52], [4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4560_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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