
// Make newform 8001.2.a.h in Magma, downloaded from the LMFDB on 04 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8001_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_8001_2_a_h();".
// 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_8001_2_a_h();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_8001_a();"
function MakeCharacter_8001_a()
    N := 8001;
    order := 1;
    char_gens := [3557, 1144, 7750];
    v := [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_8001_a_Hecke( : Kf := Kf)
    return MakeCharacter_8001_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, 0], [-1, -1], [-1, 0], [2, -2], [-1, -1], [-4, 0], [-4, 0], [3, -1], [-5, 1], [5, -1], [-3, 1], [-2, -2], [2, 2], [10, 0], [1, 3], [1, 3], [-7, 1], [2, 2], [12, 0], [-7, 1], [-4, 4], [-3, 3], [-13, 3], [-12, -2], [-9, 3], [4, 4], [-4, 0], [-2, 4], [-4, -6], [1, 0], [18, 0], [-9, 1], [-10, -2], [-6, 4], [2, -6], [14, 0], [15, 1], [-8, 8], [-10, -4], [8, 4], [12, 2], [8, 4], [14, -4], [-4, -2], [1, -1], [3, -3], [-2, -6], [-6, -4], [8, -6], [-3, 7], [-25, 3], [-24, -2], [-10, 0], [-3, 5], [-8, 0], [-4, 0], [-13, -3], [-4, 6], [-6, 6], [-12, 0], [6, 4], [6, -2], [5, -1], [2, 4], [-10, -2], [12, -12], [16, 6], [-1, 7], [-18, -4], [-8, 4], [8, -2], [5, 7], [14, 0], [22, -2], [12, 6], [4, 2], [23, -5], [-3, -1], [-2, 4], [-14, 0], [0, 2], [-10, -6], [-18, 4], [-10, 18], [-8, 12], [-6, 0], [-1, -5], [-14, 0], [9, -5], [-9, 17], [10, -8], [-4, 12], [4, 14], [24, 0], [16, -2], [-4, -12], [8, 12], [-3, 15], [-24, 10], [12, -8], [-2, -8], [20, 0], [12, -22], [2, -10], [19, 3], [-2, 4], [-15, 13], [-15, -11], [-18, -4], [9, -1], [12, -6], [15, -7], [6, -18], [14, 2], [42, 2], [-16, 4], [9, -17], [-2, -4], [33, -11], [-15, 1], [7, -1], [-4, -16], [24, 10], [32, 4], [11, 9], [26, -4], [12, -22], [-2, -6], [7, 15], [-27, -5], [9, -11], [-8, 0], [25, 1], [25, -15], [-10, 8], [-6, -18], [19, 9], [6, -18], [28, -18], [-17, 9], [-27, 15], [0, -16], [-19, 13], [-10, 8], [-3, -17], [6, -20], [-15, 9], [44, 0], [5, -3], [18, -20], [-3, -15], [-3, 19], [-35, 7], [27, -3], [-32, 4], [29, -9], [-18, 8], [28, -14], [6, -6], [20, -10], [-18, 16], [22, -10], [-30, 20], [-44, 10], [-18, 8], [8, -16], [-14, 0], [43, 3], [-2, -10], [29, -19], [10, 4], [-12, -12], [59, -1], [-2, 10], [7, 11], [-27, 3], [18, 2], [24, -12], [-14, 28], [-41, -3], [35, -15], [-8, -14], [-44, -4], [48, -8], [-13, -9], [12, -10], [17, 15], [-26, 12], [-46, 12], [-20, 6], [-52, -6], [-8, 0], [-60, 0], [-22, -6], [-6, -10], [34, -8], [-13, 3], [-2, 10], [7, 1], [-5, -19], [31, 13], [33, -3], [12, 10], [-7, -9], [6, 12], [13, 7], [6, 22], [-28, 2], [12, 8], [16, 18], [20, 8], [-32, -8], [-24, 18], [16, 2], [-4, -14], [44, -8], [33, -3], [-8, -6], [-16, -14], [-20, 22], [-45, 1], [-11, 19], [16, -24], [24, -26], [35, -21], [-16, -12], [30, -14], [-24, 8], [-11, -3], [38, 12], [-19, 11], [0, 0], [-6, 24], [-20, 0], [-13, -19], [-16, 2], [38, 2], [48, 10], [-9, -15], [52, -14], [8, -20], [-17, 9], [7, -25], [-5, -21], [-18, 28], [-40, -8], [20, 2], [-22, 10], [28, 14], [-7, 1], [-34, 16], [16, -2], [-4, 2], [-23, -3], [4, 18], [-14, -16], [-33, -11], [-16, 8], [-46, 4], [26, -10], [-4, -4], [-14, -8], [-11, -11], [31, 11], [-54, 10], [-43, 7], [-4, -16], [52, 0], [-34, 24], [-6, 8], [20, 4], [54, 4], [20, -4], [-56, -6], [-30, 22], [-50, -2], [-34, 32], [4, 6], [-15, 7], [-5, 29], [32, 4], [44, -10], [36, -10], [38, 14], [-64, 10], [2, -12], [16, 6], [-22, 30], [-10, 20], [-6, 14], [-6, -4], [34, 4], [-28, -10], [-42, 0], [-8, 24], [-32, 16], [30, 10], [30, 20], [11, 29], [-53, 19], [-3, -13], [31, 13], [-14, 30], [36, 4], [-28, -6], [22, -14], [-34, -20], [-39, 21], [-30, 32], [14, 0], [46, -12], [-60, 14], [58, -2], [51, -9], [-26, 0], [-1, 1], [-48, 0], [11, -25], [10, 2], [29, -5], [24, -14], [-37, 7], [-50, -2], [14, -20], [-49, -5], [-54, -2], [56, -8], [-55, -3], [33, 15], [19, -29], [-35, 35], [-76, -4], [2, -12], [20, 8], [-24, -12], [0, 22], [34, -32], [17, -15], [-7, 35], [-18, 8], [64, 10], [-39, 25], [-1, -19], [-4, -14], [49, 5], [30, -20], [-12, -16], [73, 3], [-30, 34], [-54, 26], [-46, -12], [-31, 3], [32, 8], [-5, 15], [48, -28], [-16, -18], [37, -13], [20, -34], [40, 10], [24, 14], [-29, 19], [64, 8], [57, 5], [-8, -4], [-25, 23], [42, -10], [-24, -24], [-30, -24], [28, -14], [-24, -12], [19, 27], [-66, -12], [-41, 5], [-7, 21], [23, -11], [-41, 35], [-20, 46], [-22, -14], [48, -2], [-10, 14], [-62, 10], [-32, 32], [2, -4], [36, 24], [-31, 19], [35, -7], [-24, -26], [53, -21], [-23, -17], [63, 3], [6, 10], [28, -8], [28, -40], [-80, 0], [26, 4], [85, -9], [70, 10], [-49, 25], [-26, 28], [-33, -5], [-66, 18], [83, -7], [35, -21], [-4, 20], [-1, -35], [16, 10], [-70, 6], [-27, -9], [-66, 0], [14, 0], [-6, -18], [-4, -28], [-30, 2], [-50, -16], [39, 15], [-19, -11], [-44, 20], [54, 6], [-37, 17], [-40, 18], [54, -28], [21, -3], [64, -10], [-6, -16], [-24, -4], [50, 2], [19, -11], [-80, 8], [-37, -7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8001_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8001_2_a_h();".
// 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_8001_2_a_h(:prec:=2)
    chi := MakeCharacter_8001_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_8001_2_a_h();".
// 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_8001_2_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8001_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-4, 1, 1]>,<5,R![-2, 3, 1]>],Snew);
    return Vf;
end function;