
// Make newform 8400.2.a.dj in Magma, downloaded from the LMFDB on 24 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_dj();".
// 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_dj();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-4, -2, 2]];
    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_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, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0], [-2, 0, 0], [-2, 0, 1], [0, 0, -1], [-2, 0, -1], [-1, 1, 0], [0, -2, 0], [0, 2, 1], [-2, -2, -2], [1, 1, 2], [-2, -2, 2], [-2, 2, 0], [4, -2, -1], [-6, -2, 2], [-2, 0, -2], [-2, 2, 0], [-2, 0, 0], [-6, 0, -1], [-4, 0, -2], [-2, 2, 2], [5, 1, 0], [-6, 4, 1], [-7, 1, -2], [0, 0, -2], [-11, -1, -2], [-4, -2, -2], [2, 0, 3], [4, 0, -2], [-6, 2, -2], [10, -4, -1], [-8, -2, 1], [-2, 4, 4], [-8, 0, 2], [-6, 0, 1], [-12, 0, 2], [-8, -4, 2], [8, 4, 1], [-10, 0, 0], [-4, -2, 2], [-2, -4, 0], [-6, -2, 4], [4, 2, 1], [6, 4, 3], [-4, 4, 4], [-4, -4, -4], [4, -4, -2], [4, 2, 2], [10, 0, -3], [10, 4, 0], [-8, -2, 0], [-18, 2, 2], [4, 0, 1], [9, -1, 0], [-9, -5, -2], [-4, -6, -1], [6, 6, 2], [4, -6, -4], [8, 4, 2], [4, 0, -1], [-4, 0, -6], [-4, -4, -6], [-14, -4, -5], [8, 2, 3], [-12, 4, 0], [12, 4, 0], [9, 3, -2], [-6, 4, 2], [8, 8, 1], [18, 0, 4], [16, 0, 4], [16, 0, 0], [-4, 0, -2], [18, 2, 2], [-8, 2, -4], [-10, -8, -1], [-16, 2, -4], [-12, 6, 4], [-18, -2, -4], [-24, 2, 2], [6, 0, 4], [-6, -4, -1], [18, 0, -1], [-3, -1, -6], [-6, 0, -8], [-12, 0, -2], [-3, 1, 0], [-12, 0, 2], [4, -4, -2], [4, 4, 2], [10, 2, 6], [-2, 0, 0], [-16, -4, 2], [-10, -2, -2], [-3, 1, 6], [-27, 1, -2], [4, 0, 0], [8, 6, -2], [18, -2, 0], [12, 6, -5], [22, 6, 4], [-12, -2, 4], [-12, -8, 0], [2, -12, -5], [-6, 10, 8], [-8, -8, 3], [2, -8, -4], [2, 4, 0], [-4, -4, 4], [0, 4, 2], [26, 0, -3], [-20, 2, 5], [-8, -4, 2], [-4, 2, -8], [-24, -4, 6], [-8, -4, 2], [32, -2, 3], [6, 4, 8], [2, -4, -10], [-2, -2, 6], [-12, 0, -7], [13, -1, 2], [-4, -2, -1], [8, -2, 8], [-2, -4, 4], [4, 0, 2], [-4, 4, -6], [-2, 8, 1], [-8, 4, -4], [-9, 1, -4], [-8, 4, -8], [28, 4, 8], [15, -5, 4], [2, -4, -4], [0, -4, 7], [4, 8, 8], [-16, -4, 1], [2, -4, -4], [12, 10, -3], [-30, -4, 4], [-12, -8, 2], [29, 7, -2], [24, 2, 2], [0, 4, 0], [14, 8, -1], [20, 0, 9], [2, 0, 1], [-5, -3, 8], [12, 0, -10], [15, -1, 4], [16, 0, -4], [-6, -2, -12], [0, -16, -4], [14, 4, 8], [-20, -8, 0], [-1, -13, -8], [6, 4, -3], [19, 3, -4], [19, -7, -2], [26, -8, -5], [-6, -2, -12], [-6, -2, 8], [-2, 4, -7], [24, 0, 0], [20, 8, -4], [2, -12, -5], [10, 8, 0], [-4, 8, -5], [-30, 4, 0], [10, 8, -6], [10, -4, -4], [-30, -2, -8], [22, -8, 1], [39, 3, 2], [-4, -4, -6], [8, 2, 8], [-4, 12, 6], [18, 0, 14], [2, -10, -8], [-10, -6, -4], [14, 10, 4], [-8, 8, 5], [29, 3, 0], [3, 3, -6], [4, 0, 6], [-4, 0, -4], [-14, -4, 8], [-8, -4, 2], [-34, 0, 5], [33, -5, 2], [12, 0, 2], [11, 7, -8], [11, 9, 14], [24, 0, -1], [2, 0, 0], [2, -2, 8], [-4, 0, -3], [12, -8, -6], [18, 4, 4], [38, -4, -5], [-34, -12, 7], [12, -14, -4], [-22, 6, 4], [-16, 12, 1], [6, 8, 13], [9, 3, -10], [6, 8, 8], [-6, -16, -7], [-28, -8, -10], [5, -15, -6], [-8, -8, 4], [-22, -2, 10], [-4, 0, 8], [2, -12, 0], [-26, -2, -2], [-3, 5, 0], [1, 15, 4], [8, 14, 11], [14, -4, -4], [28, 6, 9], [-2, 8, 4], [4, -4, 0], [8, -4, 0], [-6, 16, 12], [-12, -8, 1], [14, 4, -8], [-40, 8, 6], [-18, -8, 12], [20, -4, -8], [22, 8, -9], [8, 8, -10], [34, -4, -4], [-12, 8, 2], [32, 8, -8], [-4, -2, -12], [-24, -2, -15], [6, -8, -12], [36, 0, -6], [23, -3, 2], [12, 10, -3], [-36, 4, 0], [14, -16, -8], [12, -8, -7], [52, 0, -4], [-20, -4, 6], [-30, 2, -4], [-28, 4, 6], [27, 5, 4], [12, -8, -10], [-19, 5, 12], [-19, 3, 4], [-16, 2, -8], [-24, -4, -5], [14, 8, -8], [-50, -4, 4], [24, 4, 18], [-32, 12, 3], [-22, 4, 3], [-8, 20, 14], [41, -5, -6], [-16, 14, 2], [-54, 8, 5], [24, 0, -9], [-24, 10, 3], [-2, 0, 4], [25, -3, -6], [10, 6, -12], [12, -6, 3], [30, -12, -6], [14, 14, -2], [18, 4, 1], [40, -4, 0], [-26, 0, 1], [-12, -12, 2], [-15, -5, 6], [-44, 6, -2], [12, 2, -10], [46, -14, -6], [28, -12, -8], [32, 4, 2], [-16, -16, 8], [-22, 0, -2], [-36, 0, -12], [-6, 8, 8], [0, 12, 2], [-20, -10, -1], [0, 2, -15], [-5, 7, 0], [58, 4, 8], [26, 6, -6], [-18, 4, -7], [-6, -14, -12], [20, 4, 12], [13, 1, 4], [2, -12, -3], [-16, -8, -11], [38, 10, -6], [28, 8, 0], [-26, -4, -11], [-8, 14, -5], [20, -4, 0], [35, 9, -2], [68, 0, 0], [24, 16, -4], [-9, -3, -6], [-28, -6, 6], [34, 4, -8], [-26, -14, 4], [-8, 8, 4], [40, 6, 0], [-16, -14, -4], [-24, 0, -4], [27, -3, -8], [-32, 6, 4], [-30, 18, 10], [30, -12, -4], [18, 4, 1], [-40, -6, 0], [14, -4, 13], [-42, 6, -2], [39, 11, -4], [44, 4, 0], [22, 8, 13], [20, -6, 4], [-8, -20, -4], [16, -4, 6], [-35, -5, -4], [-32, 2, 1], [28, 10, 18], [12, -14, -5], [12, 10, 11], [-38, 10, 4], [-8, -8, -18], [-26, -2, -12], [-2, -8, 4], [20, 8, 7], [0, 6, 4], [8, 0, 10], [36, -4, 0], [62, 4, 5], [19, 7, 22], [20, 12, 6], [-40, -18, 7], [10, -8, 0], [12, 2, 10], [12, 4, -8], [8, 12, 10], [-36, -8, 11], [-18, 16, 7], [-26, -2, 6], [38, 16, -12], [-20, -4, 8], [0, 14, -10], [24, 16, 9], [-48, -12, 6], [-6, 18, 18], [22, 4, 15], [3, 5, 12], [36, -4, -8], [7, 7, 10], [-1, 1, 8], [14, -4, -8], [40, -12, -4], [-22, 2, 6], [-40, -8, -1], [38, -14, -8], [36, 10, 22], [6, 24, 4], [-34, -4, -7], [19, -11, 0], [10, 16, 0], [44, -6, 3], [-22, 10, -2], [-38, 2, -14], [-18, -4, -8], [26, -12, -5], [-27, -7, -6], [-6, -16, -9], [-43, -19, 10], [50, 0, 7], [66, 2, -6], [14, -8, 1], [-48, -10, -19], [-14, -14, 6], [-20, -16, -4], [42, 12, 5], [6, 2, 16], [6, 18, 4], [-30, 4, 0], [20, 4, 17], [-58, -4, -4], [8, 4, -10], [-46, -4, -12], [-12, 4, -4], [2, 4, 1], [15, 7, 0], [-20, 0, -4], [28, -6, -12], [38, 4, -6], [-14, -24, -5], [-54, 6, 4], [4, 24, 11], [-53, -13, -4], [-50, -8, 1], [78, 6, -2], [-50, -12, 4], [-4, -24, -4], [6, -6, 18], [6, -20, 5], [-48, 10, 5], [-19, -1, 6], [16, 0, -16], [14, -6, -4], [-21, 7, 6], [-6, 4, -8], [8, 16, -10], [40, 0, -11], [-6, -2, 0], [24, -14, -8], [-26, 8, -9], [7, -7, 12], [-34, -14, 8], [-6, -4, 19], [-4, -8, -13], [67, 1, -6], [28, -2, -16], [-20, -2, 11], [-12, 16, 4], [24, 10, 16], [30, -4, -4], [8, -8, -6], [-50, -10, -2], [-50, -4, -11], [-23, 1, -10], [26, 12, 8], [-20, 2, 14], [-2, 18, 20], [2, -4, 1], [-38, -6, 4], [-32, -2, 4], [12, -10, -14], [38, 8, -16], [-76, -2, -4], [74, 4, 1], [-32, 12, 12], [40, 16, 16], [14, 8, 12], [20, 18, 14], [48, -20, -10], [24, -4, -12], [-9, -11, 6], [13, -19, -16], [-54, -6, -18], [-18, -16, -20], [56, -2, -2], [-54, -10, -6], [14, 20, -1], [-10, -12, -21], [12, 8, 26], [-8, -16, 12], [2, 0, 16], [-6, 16, 16], [-16, 12, 8], [-44, 12, 0], [8, -12, 4], [-48, -4, 4], [-8, 22, -4], [-28, -18, 7], [-18, -14, -16], [33, 3, -10], [-12, 0, -16], [-34, -16, -8], [14, 12, -12], [-10, -4, -13], [-12, -6, 4], [-28, 10, -13], [-34, -10, -6], [4, 6, -1], [58, 8, -9], [13, 9, 14], [-42, -4, 3], [-63, 5, 0], [-20, -20, -22], [-13, 17, 2], [44, 10, 2], [-38, 10, 2], [-2, -16, -1], [-20, -12, -4], [30, 4, 29], [-32, -12, -10], [-28, -6, 6], [-28, 12, 3], [-14, -20, -12], [-38, -20, -10], [-8, -12, -18], [0, -2, 9], [60, -14, -5], [-8, -20, -8], [44, -18, -4], [0, 0, -2], [-54, 12, 5], [26, 10, 14], [-26, -6, -16], [-8, 16, 15], [3, 21, -8], [16, 2, 9], [18, 6, -12], [-28, 8, -6], [10, -2, -20], [-72, 4, 0], [-18, 0, 3], [-60, -14, 9], [-4, 20, 14], [-14, -10, 12], [-35, -7, -6], [2, 24, 6], [-42, 0, 4], [16, -16, -16], [10, -10, -8], [8, 20, -6], [-54, -12, -8], [23, 1, 0], [46, -12, 8], [14, -10, -18], [-22, 8, -9], [24, -8, 11], [-51, -17, 10], [13, -11, -2], [30, 6, 18], [-66, 12, 9]];
    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_dj();".
// 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_dj(:prec:=3)
    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_dj();".
// 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_dj( : 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![-8, -4, 6, 1]>,<17,R![-16, -16, 0, 1]>,<19,R![-40, -4, 6, 1]>,<23,R![-16, -8, 4, 1]>],Snew);
    return Vf;
end function;