
// Make newform 8008.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8008_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_8008_2_a_c();".
// 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_8008_2_a_c();".
// 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_8008_a();"
function MakeCharacter_8008_a()
    N := 8008;
    order := 1;
    char_gens := [6007, 4005, 3433, 4369, 4929];
    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_8008_a_Hecke(Kf)
    return MakeCharacter_8008_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], [-1], [-3], [-1], [-1], [-1], [0], [0], [-7], [0], [-7], [-7], [-4], [-2], [0], [-10], [-9], [-12], [-7], [1], [6], [-8], [6], [-13], [-11], [8], [-16], [0], [-6], [1], [-6], [-10], [3], [6], [22], [0], [-13], [12], [-14], [2], [-9], [-23], [7], [6], [10], [-12], [22], [5], [2], [-1], [-18], [0], [6], [17], [14], [26], [-10], [4], [-12], [-4], [-10], [-12], [32], [0], [-31], [3], [15], [20], [8], [-24], [-17], [18], [23], [-4], [11], [9], [25], [-2], [-14], [-30], [-36], [18], [18], [-17], [12], [-9], [9], [-12], [-8], [-19], [17], [8], [-29], [26], [-4], [0], [-21], [-21], [14], [14], [16], [16], [34], [-10], [16], [17], [4], [-34], [-24], [-28], [-38], [-26], [-2], [-11], [-37], [-37], [27], [-23], [3], [24], [17], [18], [42], [-24], [-1], [-24], [-11], [3], [3], [30], [6], [10], [-1], [22], [10], [-16], [-30], [38], [23], [-6], [-24], [52], [41], [18], [7], [9], [-26], [28], [-35], [-48], [-44], [-53], [36], [12], [8], [32], [-6], [-18], [-36], [8], [5], [24], [-38], [-53], [43], [-19], [-16], [-8], [2], [-51], [52], [38], [-48], [4], [25], [-13], [-46], [-55], [26], [-46], [-36], [18], [-51], [24], [-7], [-18], [-40], [28], [0], [26], [-13], [-56], [-29], [-18], [42], [-59], [4], [39], [48], [-36], [30], [-44], [10], [44], [-15], [3], [11], [-24], [50], [-44], [12], [-15], [-39], [12], [-4], [-49], [-40], [-10], [-48], [21], [10], [-40], [67], [53], [-30], [20], [6], [16], [-12], [-48], [-59], [2], [50], [10], [-35], [-24], [-7], [-26], [-23], [-15], [51], [56], [0], [43], [24], [60], [-56], [48], [44], [2], [-76], [44], [37], [-70], [-2], [-6], [70], [28], [-29], [16], [-38], [70], [34], [-66], [46], [44], [-3], [-51], [50], [14], [-77], [-69], [-26], [-14], [-14], [17], [3], [-46], [46], [-84], [26], [-27], [-12], [-52], [-68], [-69], [-54], [32], [-25], [-12], [5], [12], [42], [-48], [44], [38], [-3], [1], [-36], [-16], [46], [-32], [28], [-60], [-55], [-7], [-83], [-45], [60], [-52], [-6], [-46], [10], [31], [6], [-38], [-3], [-60], [50], [-60], [-86], [-73], [-30], [21], [-22], [61], [-65], [73], [28], [24], [-80], [14], [10], [66], [-2], [35], [-1], [24], [-33], [44], [-5], [27], [54], [57], [69], [-52], [-47], [23], [-34], [21], [-14], [1], [18], [26], [18], [-62], [-93], [0], [-70], [17], [-16], [-2], [13], [-46], [11], [-19], [-72], [54], [2], [-1], [92], [-74], [-4], [38], [29], [56], [-80], [-64], [-50], [-80], [94], [-27], [-80], [62], [-4], [-3], [-40], [59], [66], [19], [11], [7], [-51], [91], [-13], [44], [32], [42], [32], [24], [10], [29], [62], [-50], [42], [12], [-2], [100], [-4], [-35], [-68], [30], [-44], [-22], [30], [-93], [24], [59], [102], [-18], [-81], [-92], [-64], [40], [-6], [75], [53], [28], [-59], [-22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8008_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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