
// Make newform 8001.2.a.b in Magma, downloaded from the LMFDB on 02 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_b();".
// 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_b();".
// 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_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 := [[-2], [0], [-1], [-1], [0], [-1], [-6], [-4], [-9], [-5], [-3], [1], [-10], [-4], [-12], [-3], [-3], [-3], [12], [-6], [-7], [0], [9], [-1], [14], [15], [16], [-12], [4], [-10], [1], [-6], [-21], [2], [24], [-4], [22], [-13], [-8], [-14], [16], [-8], [-6], [4], [-12], [-11], [15], [-10], [-18], [-20], [29], [7], [18], [12], [-3], [-26], [24], [11], [-24], [-10], [16], [-18], [22], [-15], [-16], [10], [-20], [-18], [23], [-4], [-12], [-24], [-7], [-22], [12], [-24], [12], [-13], [13], [-30], [36], [18], [0], [38], [-10], [-14], [-28], [-29], [-14], [-19], [-9], [34], [-14], [-24], [-26], [0], [0], [4], [33], [-32], [-26], [20], [-8], [0], [16], [-37], [-14], [-23], [-19], [-12], [13], [-2], [-13], [8], [-20], [34], [-28], [9], [2], [-15], [49], [3], [2], [36], [-6], [39], [-46], [-36], [-16], [-5], [-11], [41], [28], [-7], [-3], [46], [48], [39], [48], [-44], [19], [-31], [-24], [-15], [-8], [25], [4], [-51], [-50], [-31], [38], [-3], [-43], [-47], [-13], [48], [45], [-30], [-8], [14], [12], [-56], [14], [16], [-16], [-30], [-48], [26], [-25], [34], [-15], [-4], [50], [-25], [-10], [-5], [37], [54], [32], [-2], [7], [15], [-60], [54], [34], [-61], [18], [-11], [26], [-18], [-36], [8], [-26], [12], [-2], [36], [-62], [59], [-30], [-45], [7], [11], [-3], [-30], [-35], [-58], [-7], [-32], [-58], [28], [48], [-2], [-14], [-56], [54], [30], [-12], [53], [44], [-44], [-36], [43], [69], [-8], [-2], [-69], [-36], [32], [0], [37], [-38], [45], [4], [30], [-52], [-45], [-8], [-6], [0], [-41], [36], [40], [-9], [-25], [-21], [-30], [30], [54], [-28], [-16], [-23], [-10], [0], [-24], [49], [36], [4], [-9], [-20], [-68], [-64], [-22], [-46], [81], [55], [20], [57], [50], [-28], [-6], [68], [32], [2], [50], [-68], [-28], [82], [-2], [38], [-35], [-25], [-40], [8], [-76], [-36], [-72], [-26], [-48], [-34], [-66], [-42], [-68], [-24], [56], [10], [-6], [20], [-40], [-40], [7], [-1], [-63], [-29], [-6], [-20], [-68], [20], [-46], [-19], [18], [24], [48], [-88], [34], [-37], [-62], [-61], [70], [-85], [18], [-31], [90], [23], [-2], [-72], [-85], [-62], [84], [-63], [9], [31], [33], [-14], [-62], [74], [44], [44], [30], [33], [-43], [-30], [-82], [9], [87], [-50], [-3], [-32], [-48], [13], [-48], [14], [58], [-15], [58], [71], [52], [-36], [77], [-54], [-28], [36], [35], [74], [-15], [14], [-13], [18], [44], [-64], [60], [28], [43], [-40], [63], [-47], [-81], [-45], [-60], [-16], [66], [28], [-70], [0], [-46], [-72], [25], [-37], [-26], [-27], [-23], [91], [-12], [-20], [-42], [32], [-40], [-47], [84], [87], [34], [67], [30], [-41], [-13], [-22], [91], [-50], [22], [1], [36], [26], [-38], [-54], [38], [64], [15], [-35], [86], [-8], [15], [-48], [34], [-47], [48], [-38], [-82], [52], [47], [-76], [-45]];
    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_b();".
// 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_b(:prec:=1)
    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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8001_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 1]>,<5,R![1, 1]>],Snew);
    return Vf;
end function;