
// Make newform 8400.2.a.cz in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8400_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_8400_2_a_cz();".
// 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_8400_2_a_cz();".
// 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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_8400_a();"
function MakeCharacter_8400_a()
    N := 8400;
    order := 1;
    char_gens := [3151, 2101, 2801, 5377, 3601];
    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_8400_a_Hecke(Kf)
    return MakeCharacter_8400_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], [0, 0], [1, 0], [2, 0], [0, -1], [-2, 1], [-2, 0], [4, 0], [-4, 1], [-4, -1], [2, 1], [-8, -1], [2, 1], [2, -1], [-2, 0], [0, 0], [-8, -1], [6, 1], [-8, 1], [-12, -1], [0, 2], [4, 2], [-4, 3], [-8, -1], [0, -1], [4, -2], [0, 0], [6, -2], [-6, 2], [4, 0], [4, 4], [2, -4], [-6, -2], [-8, 1], [0, -4], [4, 3], [10, -3], [6, -1], [-12, 0], [14, -2], [12, -1], [4, -3], [-4, 2], [2, -4], [-16, 1], [-8, 4], [12, -2], [8, 4], [-4, 5], [-6, -2], [-20, -1], [6, 4], [-24, 0], [-10, 3], [4, 0], [8, -5], [-20, 1], [-10, 3], [-6, -2], [8, -2], [-16, 2], [20, 0], [-16, 0], [12, -3], [2, 2], [-16, 4], [20, 2], [4, -6], [12, -3], [-22, -1], [0, 3], [-8, 4], [-6, -5], [-12, -4], [2, 5], [-16, -3], [12, 1], [2, 4], [10, 4], [4, 0], [-2, 2], [8, -3], [-8, 3], [-36, -1], [-28, 2], [-18, -2], [0, -2], [-8, 1], [-8, 6], [-28, -2], [16, 0], [-4, -4], [-10, -2], [-12, -4], [-26, 3], [-24, -3], [4, 3], [-16, -2], [-14, 2], [6, -7], [-14, -2], [8, -6], [-6, 0], [28, 4], [-20, 1], [-24, -2], [-10, -7], [4, 5], [22, 0], [4, 2], [-6, -3], [30, -4], [6, 4], [-32, -2], [-42, 0], [-16, -2], [2, 9], [-10, -2], [30, 4], [8, -9], [-4, 4], [-20, -4], [-32, -4], [22, -6], [4, 1], [18, -4], [0, 2], [-28, -2], [28, 5], [20, 0], [-24, -6], [0, 6], [26, -1], [-20, 1], [10, 2], [8, -2], [36, 0], [-28, 0], [2, 6], [-22, -2], [-12, -7], [24, 2], [12, 10], [8, 1], [-24, 2], [36, 1], [30, 3], [30, 2], [-8, -6], [-18, 7], [32, 1], [6, 5], [-18, -3], [6, 5], [12, -3], [-8, -10], [-12, -7], [-16, -7], [40, 1], [-16, 0], [-18, 0], [8, -4], [16, -4], [26, -6], [-30, -1], [48, -2], [28, 5], [2, -8], [-28, 0], [26, 0], [12, 7], [-4, 3], [-4, 10], [-44, 1], [-20, 5], [16, -8], [-16, -3], [-4, 6], [-24, -7], [4, -2], [-32, 0], [42, -1], [6, 13], [-44, 4], [16, 9], [34, 5], [8, 6], [-2, 0], [-16, 10], [40, -1], [8, 0], [12, 0], [-24, 7], [0, 4], [38, 5], [2, -8], [-26, -3], [22, 7], [-6, -3], [-8, -5], [0, 5], [0, -7], [34, 2], [8, 4], [8, 6], [-28, 9], [4, 10], [30, 0], [-34, 6], [-12, -12], [32, -3], [-8, 4], [28, -6], [8, -10], [2, 2], [52, -4], [40, 3], [-44, -4], [-34, 6], [10, 8], [8, -7], [34, 2], [36, -2], [-8, 2], [-14, -4], [-26, -9], [-20, -11], [-40, -4], [54, 2], [-10, -7], [46, 0], [-40, 4], [6, -4], [-4, -4], [6, -3], [2, 0], [-6, -8], [30, 2], [16, 2], [48, -4], [38, -8], [48, 0], [-38, -6], [-14, 1], [-16, -2], [-4, 14], [52, -4], [32, 0], [32, -6], [46, -1], [32, 7], [-16, 6], [14, -2], [-16, 6], [30, -2], [-10, -6], [8, -2], [-32, 2], [-16, 11], [16, -10], [60, 2], [-16, -1], [32, 9], [2, -17], [6, 14], [0, -5], [-28, -5], [26, -9], [-46, -4], [-60, 3], [6, -1], [-36, 9], [-16, -14], [-12, 5], [-24, 8], [-8, 8], [-6, -4], [-18, 4], [48, 4], [2, 11], [24, 2], [-50, -3], [56, 5], [-32, 10], [-48, -5], [8, -2], [30, 0], [4, 3], [28, -11], [-40, 7], [32, 4], [-14, 14], [20, -8], [6, 1], [48, -3], [12, 9], [-52, 6], [32, -4], [-52, 0], [24, 1], [14, -2], [24, 0], [40, 4], [60, 0], [24, 4], [-8, -8], [0, -1], [8, 13], [-54, 3], [34, 11], [-20, 9], [10, 0], [38, -7], [40, 2], [10, 2], [4, 0], [48, -5], [-40, -5], [-18, -2], [6, -6], [12, 4], [8, -1], [0, -16], [34, 0], [6, -8], [44, 0], [-52, -4], [48, -6], [-42, -4], [-18, 0], [-18, 10], [40, -5], [-20, 4], [16, -4], [-20, -4], [34, 2], [-14, 1], [10, -6], [-24, -8], [-46, -9], [14, 16], [40, -1], [48, -8], [-14, 4], [-38, 10], [-28, 5], [42, 3], [8, -10], [-72, -2], [-22, -6], [-48, 2], [-36, 1], [16, 4], [-38, -2], [-14, -9], [-56, 6], [-20, 0], [18, -6], [44, 0], [34, 7], [-16, -3], [-4, 12], [-2, 12], [-20, -12], [-40, -10], [-44, -10], [76, 2], [-26, 0], [2, 0], [-10, 2], [12, 0], [36, 7], [44, -7], [-34, -5], [-4, 0], [-48, -1], [0, -5], [20, 15], [8, 13], [-48, 3], [2, -2], [-20, 8], [54, 2], [50, -6], [34, 13], [0, -10], [28, -3], [14, -15], [-34, -3], [-18, 12], [-16, 16], [-42, 4], [-4, -4], [48, -3], [16, 0], [8, 11], [24, 1], [20, 16], [0, -5], [24, 5], [30, 4], [28, -10], [-6, -15], [8, -11], [40, 3], [22, -1], [-34, -6], [-16, -2], [80, -4], [16, -19], [-62, 2], [-4, 6], [-24, 4], [20, 2], [72, -5], [-44, 3], [40, 0], [18, -5], [-10, -7], [-24, 1], [-8, -5], [64, -6], [24, -12], [-20, 1], [-8, 6], [20, 2], [14, 2], [-46, 4], [32, 6], [-70, 0], [-2, -4], [-16, 12], [18, -19], [20, 3], [56, -5], [22, -8], [-10, 0], [-22, 15], [-44, -7], [8, 6], [-30, -6], [26, -16], [28, 7], [-10, 2], [34, 0], [40, 6], [-22, -5], [58, 6], [-8, 15], [-42, 3], [-32, -2], [-44, -2], [8, -1], [68, -8], [24, -9], [6, 4], [32, 4], [40, 13], [30, -12], [36, 8], [-80, 0], [-10, -12], [-10, 2], [80, 2], [-4, 22], [8, 10], [-4, -12], [-2, 12], [-22, 4], [-4, -18], [-12, -10], [24, 10], [38, -4], [-82, -4], [4, -1], [-64, -1], [-72, -9], [34, -3], [-14, -6], [-48, 5], [36, -5], [-76, 3], [88, 5], [-48, -4], [-64, 4], [-30, -10], [28, 12], [-34, 0], [16, 4], [16, 1], [26, -3], [-34, 4], [-28, 10], [-34, -6], [-12, 13], [-28, -8], [-18, -6], [12, 21], [-12, 20], [-20, -9], [-16, -16], [74, 0], [-72, -6], [58, 7], [46, 5], [32, 6], [-28, 3], [-62, 3], [-48, 2], [16, -12], [56, -2], [76, -3], [-26, 10], [40, 8], [4, 6], [-24, -7], [-48, 9], [24, -11], [20, -10], [2, -9], [4, -12], [22, -4], [-8, 2], [-42, -10], [-60, -8], [0, -3], [12, 2], [-36, 6], [-64, 3], [40, 18], [86, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8400_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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