
// Make newform 1560.2.a.q in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1560_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_1560_2_a_q();".
// 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_1560_2_a_q();".
// 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 := [-4, -7, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-5, 0, 1], [5, 2, -1]];
    Rf_basisdens := [1, 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_1560_a();"
function MakeCharacter_1560_a()
    N := 1560;
    order := 1;
    char_gens := [391, 781, 521, 937, 1081];
    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_1560_a_Hecke(Kf)
    return MakeCharacter_1560_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, 0, 0], [1, 0, 0], [0, 0, 1], [2, 1, 0], [-1, 0, 0], [2, -2, -1], [2, 1, 1], [0, 0, -1], [4, 1, -1], [0, -2, 0], [4, 1, 0], [0, 1, 0], [0, -2, -2], [-4, -2, 0], [0, -1, 2], [4, 2, -2], [0, 1, -2], [-4, 2, 2], [-6, 1, 0], [8, -1, 1], [6, -1, 0], [0, 2, -2], [4, -1, 0], [2, 0, 3], [-12, -3, 1], [-8, 2, 2], [-2, -3, -2], [8, 1, 1], [0, 1, -1], [-4, 4, 2], [-2, -1, 3], [2, 0, 0], [6, -3, 0], [4, -1, 0], [-4, 0, -4], [2, -4, 0], [-2, -1, -2], [-12, 2, 2], [-6, 0, 0], [-6, 1, -3], [4, -1, -4], [0, 0, -4], [10, 4, 1], [2, 2, -4], [12, 2, 2], [-4, 4, 4], [-18, -1, 1], [0, -2, 0], [4, -1, 1], [-2, -4, -1], [-2, 3, -2], [2, -4, -4], [6, 3, 5], [-8, -3, -5], [-14, 1, -1], [-12, 1, 1], [0, -6, -4], [2, 4, -4], [-14, -2, 2], [-16, -2, 2], [-6, 2, 0], [-6, -3, 0], [-16, -4, 0], [22, 2, 2], [-14, 2, 0], [-10, 3, 1], [-14, 4, 2], [10, 3, 4], [0, 1, 5], [-14, 0, 0], [-12, 2, -2], [0, -2, -2], [-10, 2, 4], [-2, -1, -5], [-16, 0, -2], [-12, -3, 1], [-12, 5, 4], [-6, -2, -6], [14, -2, -2], [6, -5, -1], [-20, -5, 3], [8, 4, -4], [10, 0, -2], [6, -5, -6], [10, -1, -4], [16, 1, 8], [2, 4, 3], [-12, -1, -6], [-4, -2, -5], [6, 9, 2], [18, 5, -2], [-20, -6, 1], [2, -7, -1], [-2, 3, 3], [-14, -3, -1], [-16, 1, 2], [14, 2, 6], [-4, 0, 0], [0, 5, -1], [-4, 0, -4], [-2, -4, 4], [18, -1, 0], [18, 4, 6], [2, -1, 4], [-10, -2, 1], [24, -2, 0], [2, 8, 2], [-8, -8, 0], [16, -5, 2], [8, -2, 2], [8, -5, -8], [10, 8, 4], [14, 7, -1], [24, 2, 2], [-10, 2, 4], [-30, 1, 0], [8, -4, 1], [-2, -6, 2], [-14, -3, 7], [-12, 7, 3], [2, -4, -8], [12, -11, -4], [24, 6, 2], [-22, -7, 1], [-4, 1, 1], [0, 5, 1], [12, 2, -2], [-8, -6, -4], [-12, 9, 4], [6, -5, -5], [8, 4, 6], [6, 3, 6], [14, 6, 8], [18, 2, -6], [-2, -2, 4], [10, 2, 4], [8, 4, 0], [20, -3, 2], [34, 0, -4], [14, 7, 1], [16, 1, -4], [0, 2, -2], [4, 0, 6], [-18, 4, 4], [30, -5, -2], [24, -5, 0], [-6, 2, 1], [-6, -5, -2], [8, 0, -2], [10, 8, -8], [-18, -10, 6], [4, -8, -4], [-4, 6, 3], [-28, 4, 2], [12, 2, -2], [34, 5, 2], [28, 3, 4], [10, 8, -8], [-12, 3, 4], [0, -10, -2], [18, 2, 3], [2, 5, -5], [-2, -9, -7], [10, -8, 2], [-20, -2, -10], [26, 1, -4], [-2, 6, 4], [2, -4, 8], [16, 3, 10], [-16, 4, 8], [-4, 3, -3], [20, -6, 2], [14, -2, 9], [-6, -15, 0], [-38, 4, 2], [-30, 1, -3], [12, 3, -4], [44, 0, 0], [18, 2, 6], [16, 0, 5], [10, 5, -1], [10, 4, 12], [-2, 10, 10], [-16, 0, 2], [0, 11, 7], [-18, -10, 4], [-26, -1, 8], [-6, -4, -10], [18, 1, 6], [-2, 2, -4], [32, -2, -4], [-10, -7, 6], [8, 5, -8], [8, 2, -10], [-2, -8, 1], [-34, 6, -2], [2, 12, -4], [-30, -8, 2], [-4, -6, 5], [-2, -8, -4], [50, 5, -2], [-20, -11, 2], [-20, -11, 2], [-18, -5, 4], [-40, -9, 4], [-24, -6, -4], [0, 2, 6], [4, -5, -4], [10, 3, -10], [-30, -4, -10], [4, 5, 3], [4, 0, -12], [44, -4, -2], [-24, 12, 8], [-2, 2, 4], [-12, -12, -4], [-26, -10, -2], [-24, -12, 2], [14, 4, -4], [24, -11, -8], [28, 12, -6], [10, -6, 2], [10, 1, 3], [-22, 11, 4], [-28, 3, -4], [-10, 0, -5], [-48, 0, 2], [-24, 2, 4], [2, 5, 8], [-34, -6, 0], [18, -1, -2], [-12, 8, 8], [-14, 8, 6], [12, -4, 10], [32, 8, 6], [-14, 12, 2], [54, 4, 0], [-22, -3, -11], [-36, -6, -2], [-32, 6, 6], [26, -5, -6], [12, 0, -12], [-28, 11, 7], [10, 16, -2], [-24, 0, 4], [30, -9, 1], [6, 3, 10], [-18, -5, -3], [2, 1, -9], [-26, -2, 6], [18, -2, 6], [-12, -2, -4], [12, -3, 6], [-12, 1, -6], [2, 1, -2], [6, -4, 12], [-2, -1, 10], [2, -4, 4], [18, -12, -1], [40, 10, -4], [-6, -9, 10], [-8, -15, -7], [22, -2, -8], [6, 2, -2], [-22, -5, -8], [0, -3, 2], [-20, 11, 4], [-2, -1, 4], [14, -2, 6], [26, 14, 2], [2, 13, 6], [14, 14, -7], [24, 0, 0], [-14, 12, 0], [-28, -2, -7], [-20, 8, 8], [-28, 3, 7], [42, -8, -2], [50, -3, -3], [20, 6, 1], [-16, -10, 2], [-38, -3, -5], [4, 11, 5], [12, 14, 10], [4, 14, 2], [34, -8, -10], [42, -6, -4], [-20, 0, -10], [38, 6, 0], [-24, 3, 7], [12, 0, -8], [50, -8, -2], [8, -4, -8], [18, -4, -8], [-8, 3, 9], [-12, 14, 2], [-56, 3, 4], [-22, -7, 7], [6, -13, -2], [-18, -10, -6], [42, 10, 0], [30, -1, 0], [-10, 9, -8], [-4, -8, 4], [58, 4, 1], [-62, -1, 2], [-16, 13, 12], [16, 4, -4], [-2, -6, -8], [-8, 4, 3], [-10, 4, -8], [62, -2, 2], [4, 8, 4], [40, 8, 0], [-28, 1, 6], [30, -13, -4], [-46, -11, 8], [-40, 3, 1], [22, 10, -4], [16, -14, -2], [-8, -5, 5], [-8, -1, -3], [12, -6, 3], [-58, -6, 6], [24, 3, 6], [14, -17, -9], [-38, 5, 0], [36, -2, 13], [-14, 16, 16], [48, 1, 7], [8, 3, -16], [64, 4, -4], [-12, -20, -4], [-18, -9, 9], [8, -2, 12], [-56, -7, 3], [-10, -14, 8], [14, -2, 14], [-28, 20, 10], [-4, 9, 2], [-14, -18, 5], [-28, 11, 12], [60, -2, -2], [6, -16, -8], [10, 1, 7], [-32, -7, -14], [10, -11, -16], [28, -2, 10], [64, -1, 8], [-2, -9, -17], [2, 4, -15], [16, 5, 8], [40, 10, -8], [-8, -7, 4], [-4, 7, 5], [-2, 3, 6], [20, -2, 14], [12, -1, -7], [4, 18, 0], [66, 0, -4], [-18, 10, 12], [-22, 5, 7], [-8, 0, 4], [-20, -12, 2], [26, 0, -6], [34, 6, 12], [20, -10, -9], [4, -15, 6], [14, 11, 7], [-32, 18, 14], [4, 2, -6], [12, -19, -5], [-38, 1, 12], [62, -6, 0], [-46, -7, 2], [-4, -2, 8], [6, 14, 1], [-30, -12, -2], [-50, 10, 2], [10, 2, 6], [10, 12, 8], [54, -1, -7], [6, 14, 18], [10, -11, -1], [24, 0, 4], [-28, 4, -6], [-18, 6, 4], [28, 14, 2], [12, -2, 9], [30, 18, -8], [-50, 0, -12], [-30, 9, -4], [-44, 12, 0], [2, -3, -4], [-18, -6, 10], [16, -18, -4], [-38, -8, -4], [-30, 11, -2], [14, -20, -12], [-32, 5, -9], [26, 6, -11], [-8, 8, -5], [-62, -4, -6], [-28, -9, 2], [6, -9, 14], [46, -6, -2], [34, 6, -10], [-6, 9, -2], [26, 13, 6], [-18, 6, 2], [-52, -3, -10], [-14, 3, 8], [6, 9, 0], [10, 12, 16], [20, -3, 3], [42, -3, -2], [-20, -4, -2], [-30, 0, -2], [40, -4, -7], [20, -3, -5], [72, -1, -2], [40, 8, 12], [-34, -5, 9], [8, -5, -19], [10, -14, -4], [6, 9, 14], [32, 9, 4], [-10, 3, 11], [-36, -2, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1560_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1560_2_a_q();".
// 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_1560_2_a_q(:prec:=3)
    chi := MakeCharacter_1560_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_1560_2_a_q();".
// 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_1560_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![40, -20, -1, 1]>,<11,R![32, -8, -5, 1]>,<17,R![356, -52, -7, 1]>],Snew);
    return Vf;
end function;