
// Make newform 8640.2.a.ck in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8640_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_8640_2_a_ck();".
// 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_8640_2_a_ck();".
// 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 := [-3, -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_8640_a();"
function MakeCharacter_8640_a()
    N := 8640;
    order := 1;
    char_gens := [2431, 3781, 6401, 3457];
    v := [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_8640_a_Hecke(Kf)
    return MakeCharacter_8640_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, 0], [-1, 0], [-1, -1], [1, -1], [-3, 1], [-2, -1], [0, -1], [3, 0], [-5, -1], [2, -1], [-2, 0], [-1, 1], [-3, -1], [2, -2], [2, 1], [-5, -1], [-3, -2], [-8, -2], [-11, -1], [9, -1], [8, -1], [3, 0], [-3, 3], [8, 0], [-12, 0], [4, 0], [0, 0], [7, 0], [-8, 2], [12, -2], [6, 0], [6, -3], [-4, 0], [-5, 5], [0, 4], [7, -3], [2, 0], [3, 0], [0, -3], [-14, 2], [7, 0], [-2, -4], [11, 3], [12, -3], [-6, -2], [2, 3], [10, 0], [-19, -2], [-1, 2], [-18, 0], [8, -2], [21, 2], [6, -6], [12, 3], [10, 2], [-4, -2], [-6, 7], [11, 5], [-9, 3], [7, 1], [18, 3], [-6, -4], [-3, -3], [2, 6], [4, -1], [22, -2], [3, -1], [16, -4], [3, -8], [0, -6], [-12, -6], [-1, -1], [18, -2], [18, -1], [-3, 6], [-15, 3], [9, 1], [-30, 0], [5, 0], [5, -5], [9, 4], [-15, -3], [-3, -7], [-24, 1], [-3, 6], [13, -7], [-6, 2], [0, 6], [8, 2], [5, -2], [27, -3], [19, -3], [20, -2], [-24, -1], [-17, -4], [-4, -8], [-25, 1], [27, -1], [26, -4], [-3, -1], [12, 6], [24, 0], [27, 3], [-4, -9], [17, 3], [21, 0], [-4, 7], [19, -1], [11, 6], [-21, 1], [0, -8], [6, -9], [14, -6], [-12, -5], [-24, 0], [-5, -5], [-31, -2], [-2, -7], [-17, -1], [6, -8], [7, -5], [0, 6], [-9, 0], [6, -1], [-26, -4], [-6, -8], [6, 12], [-14, 6], [-32, 0], [12, 5], [20, 4], [12, -5], [-24, -2], [-21, -9], [41, 0], [-6, -3], [-21, 5], [-2, 11], [47, 1], [28, 4], [-30, 0], [7, -3], [-41, 2], [20, 2], [-26, 2], [-22, 2], [-20, -7], [-12, 5], [-23, 2], [17, 11], [-29, -1], [5, -3], [9, -6], [16, 4], [-13, -5], [-12, 4], [23, 1], [34, -2], [-14, -4], [39, 0], [-2, 8], [-50, 0], [-18, 0], [-8, 2], [21, -6], [40, 3], [-7, -13], [-31, 6], [4, 5], [12, 0], [-45, -2], [21, 9], [4, 16], [36, 7], [3, 3], [4, 7], [-27, 9], [7, 9], [-18, 4], [25, 3], [26, -2], [6, -8], [32, -2], [-3, -12], [32, 4], [-49, -1], [-42, 2], [-1, 6], [-7, 1], [-6, -4], [13, -4], [-20, -11], [-4, 4], [-45, 0], [26, 1], [-9, 2], [14, 2], [24, 6], [4, -16], [-27, 3], [50, 2], [2, 8], [-9, -4], [-51, -3], [54, 0], [-14, -6], [-23, -10], [-60, 0], [-4, 0], [11, -9], [-41, 5], [-52, -4], [-8, 8], [0, 12], [-13, -6], [15, 1], [-12, -12], [1, 14], [-36, 3], [-6, 4], [10, 3], [-21, -9], [9, -17], [-1, -8], [-23, -12], [-42, 9], [-11, -1], [-12, -2], [12, 0], [-19, 11], [6, -7], [-32, 0], [-14, 8], [23, 3], [-9, 6], [-5, -14], [-8, 5], [-6, 12], [9, -9], [-24, 0], [58, 1], [24, 10], [23, 8], [36, 6], [-52, -2], [22, -6], [25, 5], [-4, 0], [-19, 4], [0, -2], [-8, 14], [15, 6], [-5, -2], [10, -7], [-12, 12], [-9, -8], [-13, 3], [-6, -3], [29, 9], [-39, 7], [-13, 10], [-23, 0], [8, -4], [12, 3], [12, -16], [44, 4], [-22, -8], [26, -12], [44, -2], [-23, 0], [-24, 14], [-19, -9], [14, -13], [1, 7], [-35, -3], [27, 6], [-37, 8], [-11, 16], [-3, 15], [40, -4], [-54, 7], [13, -10], [-19, 8], [52, -8], [-3, 21], [-48, 2], [30, 0], [-8, -9], [-12, 12], [-20, -4], [-1, -14], [30, 12], [-36, 6], [-35, -9], [6, 6], [34, 3], [-30, 0], [12, -12], [35, -9], [-23, -5], [32, 7], [0, -8], [-21, 0], [-48, 5], [-49, -3], [-12, -12], [-17, -6], [-27, 3], [5, -1], [27, 6], [-18, -18], [-30, 6], [-7, -15], [-35, -4], [-27, -10], [48, 0], [21, -9], [1, 1], [-30, 0], [-22, 3], [-34, -6], [2, 10], [-18, 10], [-12, -3], [-54, 8], [8, 21], [-42, 2], [-48, 0], [-52, 1], [2, -4], [2, 4], [28, 0], [-58, 10], [50, 6], [32, 16], [-17, 6], [-22, -5], [-4, -18], [11, -7], [-42, 10], [-28, -11], [39, -9], [2, 5], [-28, 10], [39, -3], [1, 24], [66, 2], [-6, -6], [34, -1], [-8, 16], [16, -2], [-53, -1], [-30, -2], [8, 2], [54, -9], [-23, 5], [45, 9], [12, -6], [53, 10], [27, -5], [-8, -10], [-30, -6], [-8, -10], [2, 18], [-9, -13], [-12, -9], [2, 20], [14, -12], [0, -6], [64, -5], [35, -2], [-15, 3], [-10, 11], [-6, -2], [-26, -16], [-42, -12], [47, 9], [0, -18], [24, -10], [22, -10], [18, -3], [-39, 13], [14, 19], [-26, -2], [-34, 10], [46, 9], [25, -3], [-11, 7], [-24, 0], [-38, 4], [-46, 1], [-2, 8], [-22, 12], [56, -2], [11, -15], [-2, 9], [-39, -3], [0, -7], [18, -6], [-6, 4], [-12, -6], [9, 25], [62, -8], [37, 5], [42, -5], [-62, 0], [20, -14], [22, 22], [57, 9], [-26, -8], [-12, 9], [67, 2], [82, 1], [-4, -18], [23, 7], [-32, 2], [-24, -8], [-78, -3], [25, 20], [10, 2], [36, 10], [69, 0], [-20, 14], [20, 18], [-10, 7], [-25, 22], [-6, -12], [-46, 3], [-25, -11], [0, 2], [-43, -11], [36, 11], [23, -2], [-13, 23], [38, 10], [23, 12], [19, -12], [44, 0], [16, 9], [49, 8], [80, -2], [-39, -8], [-3, -3], [14, -24], [-4, 13], [-46, 6], [-30, -6], [-11, -20], [21, 4], [-31, -3], [8, -20], [-33, 6], [38, -2], [-34, -6], [24, -6], [51, 16], [-48, -12], [64, 12], [-54, 9], [-80, -5], [-60, 4], [75, 3], [-41, 6], [-18, 20], [44, 12], [66, 1], [-28, -20], [49, 11], [-26, -14], [69, 1], [18, -18], [63, -3], [9, 2], [42, 18], [13, -21], [-31, 1], [-40, -16], [0, 12], [-34, -11], [90, 2], [8, -2], [-6, 14]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8640_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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