
// Make newform 8400.2.a.co in Magma, downloaded from the LMFDB on 30 September 2025.
// 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_co();".
// 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_co();".
// 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_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 := 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]];
    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], [0], [1], [0], [6], [-2], [8], [8], [-2], [-4], [2], [-6], [4], [8], [-10], [-4], [-2], [4], [12], [2], [-8], [-4], [-6], [18], [-10], [8], [-12], [-18], [-6], [8], [-20], [10], [0], [14], [-8], [14], [12], [8], [-6], [24], [-2], [-4], [-18], [-18], [4], [20], [-24], [-4], [22], [18], [4], [-6], [12], [6], [16], [14], [-12], [-14], [18], [-4], [-14], [12], [-24], [10], [-2], [12], [14], [-20], [14], [-18], [36], [-8], [10], [4], [-32], [30], [22], [18], [-22], [12], [-26], [-28], [2], [-28], [12], [-30], [-18], [-2], [-24], [28], [-32], [-16], [0], [-20], [-8], [-2], [10], [20], [-18], [-12], [-2], [4], [42], [36], [2], [12], [30], [4], [18], [8], [18], [-30], [0], [0], [-6], [28], [24], [22], [0], [38], [-26], [-46], [12], [0], [-2], [-26], [-8], [16], [-26], [-20], [-48], [-8], [10], [-54], [26], [-30], [28], [-54], [18], [0], [-42], [-16], [-12], [-42], [0], [30], [-18], [40], [0], [58], [-30], [4], [16], [28], [-36], [0], [-14], [2], [-18], [20], [2], [-8], [-20], [10], [-16], [24], [-2], [18], [34], [-32], [-58], [-52], [-10], [36], [26], [-20], [-18], [32], [22], [32], [20], [-54], [38], [8], [22], [-38], [44], [26], [8], [-14], [20], [-20], [-34], [-60], [54], [18], [2], [22], [8], [-18], [44], [-10], [10], [28], [10], [36], [-4], [-62], [-24], [-10], [22], [-56], [-44], [0], [2], [8], [-30], [-32], [22], [-26], [-44], [-6], [64], [-12], [-58], [-34], [-4], [8], [0], [-14], [-8], [32], [34], [-12], [-40], [-30], [-2], [-48], [0], [44], [48], [-56], [-50], [22], [64], [40], [12], [60], [-64], [-38], [18], [24], [-38], [42], [56], [-42], [-68], [34], [-70], [-56], [20], [22], [-2], [-34], [-16], [78], [-70], [28], [-2], [6], [-52], [-70], [-8], [-30], [16], [52], [-34], [10], [-44], [-24], [-16], [-48], [62], [4], [-68], [54], [6], [-28], [50], [-18], [-36], [-62], [-12], [34], [78], [-28], [26], [-84], [44], [34], [-42], [-16], [-60], [-12], [78], [52], [14], [28], [42], [72], [-90], [18], [84], [-40], [34], [-20], [12], [50], [-78], [64], [-82], [-66], [-80], [-38], [-70], [-36], [76], [-48], [-42], [46], [-74], [-76], [-12], [-20], [12], [-82], [54], [-46], [-8], [10], [-78], [70], [8], [54], [-64], [70], [-20], [-40], [-30], [8], [14], [30], [-64], [22], [-90], [-24], [36], [58], [64], [-6], [42], [24], [72], [44], [-34], [18], [-8], [-38], [72], [-40], [-24], [-34], [-84], [58], [60], [-84], [-46], [50], [82], [-18], [50], [64], [-78], [56], [-24], [-8], [-34], [-36], [-24], [-46], [-22], [-24], [28], [-20], [-10], [-12], [-70], [36], [-58], [86], [-6], [-32], [-2], [-90], [-52], [-54], [50], [20], [36], [26], [70], [-36], [20], [-26], [14], [20], [-32], [-82], [96], [54], [-98], [8], [-4], [26], [42], [-4], [-54], [104], [48], [-102], [-48], [44], [64], [14], [50], [10], [-42], [-20], [-4], [76], [90], [86], [-108], [18], [66], [44], [72], [10], [78], [-52], [0], [84], [-6], [38], [-10], [-66], [-60], [54], [-14], [-60], [-8], [0], [-26], [12], [-50], [16], [-52], [-38], [-16], [0], [-36], [72], [-46], [-40], [14], [-82], [52], [48], [-74], [114], [-70], [-22], [22], [56], [-36], [110], [-52], [112], [-40], [-98], [-24], [-86], [-78], [-24], [86], [-92], [78], [-52], [-116], [-90], [-72], [-70], [48], [-62], [62], [-24], [-20], [58], [-36], [-36], [64], [106], [22], [-116], [-98], [-74], [22], [76], [-32], [10], [84], [122], [16], [10], [108], [74], [106], [-12], [30], [-88], [66]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8400_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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