
// Make newform 6008.2.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6008_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_6008_2_a_a();".
// 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_6008_2_a_a();".
// 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_6008_a();"
function MakeCharacter_6008_a()
    N := 6008;
    order := 1;
    char_gens := [1503, 3005, 1505];
    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_6008_a_Hecke(Kf)
    return MakeCharacter_6008_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], [-2], [-4], [0], [-1], [-6], [3], [-9], [-10], [-8], [11], [0], [-4], [-3], [-1], [-13], [3], [8], [-8], [-4], [6], [6], [-5], [-3], [-10], [-2], [9], [-7], [-12], [-17], [11], [-14], [15], [-7], [-12], [2], [8], [-21], [-16], [4], [-2], [7], [23], [23], [11], [21], [0], [26], [15], [-19], [-4], [-28], [6], [14], [28], [18], [-28], [8], [-18], [-32], [0], [8], [-3], [-4], [-28], [-6], [8], [9], [-16], [-36], [-12], [-5], [-8], [12], [34], [-16], [-39], [31], [36], [-21], [-38], [-26], [27], [28], [6], [-26], [7], [-15], [4], [-10], [3], [-24], [-34], [-7], [24], [-2], [-24], [5], [-38], [-10], [4], [46], [18], [-38], [-4], [-8], [-34], [18], [-42], [-18], [22], [-22], [14], [-45], [15], [31], [6], [-44], [-38], [-32], [-46], [8], [29], [-28], [42], [-38], [-30], [-8], [2], [5], [40], [1], [22], [-35], [-2], [4], [4], [-7], [30], [38], [-10], [24], [9], [-40], [-54], [7], [-18], [-4], [-10], [2], [7], [27], [-12], [12], [-37], [-4], [21], [-58], [-35], [-28], [14], [-58], [24], [6], [-4], [-38], [-17], [22], [-13], [32], [-14], [50], [-34], [25], [5], [-58], [30], [-16], [50], [47], [-48], [-38], [-48], [18], [-21], [46], [-4], [41], [8], [21], [6], [7], [-45], [-48], [6], [-17], [48], [-17], [-39], [-66], [-12], [58], [13], [-23], [-42], [65], [-36], [-27], [-68], [-6], [-54], [42], [43], [9], [52], [44], [61], [-72], [9], [-20], [33], [0], [19], [12], [-37], [-63], [-5], [-67], [36], [12], [38], [-33], [-30], [-72], [-48], [18], [-16], [-20], [-9], [65], [-56], [10], [38], [62], [-8], [53], [42], [33], [-48], [47], [60], [-75], [-26], [-8], [29], [41], [9], [-42], [-40], [14], [7], [39], [3], [10], [52], [45], [-47], [-44], [-24], [22], [31], [46], [-22], [-68], [-16], [-48], [26], [-61], [-33], [56], [-32], [24], [40], [4], [-48], [30], [-8], [-46], [-63], [58], [68], [-26], [44], [-74], [36], [50], [15], [48], [13], [40], [58], [46], [64], [-46], [-44], [31], [-21], [-60], [10], [-38], [48], [-28], [-53], [64], [-35], [60], [-10], [18], [-70], [32], [-3], [33], [1], [22], [-30], [-46], [-56], [36], [34], [-18], [-16], [75], [14], [24], [42], [-71], [43], [50], [12], [29], [72], [12], [-26], [-3], [57], [56], [37], [-72], [-23], [-5], [-2], [17], [43], [-6], [-54], [-30], [90], [74], [-34], [22], [67], [-36], [-22], [41], [36], [-24], [-1], [-52], [21], [-2], [34], [-50], [-47], [-9], [-53], [-15], [28], [34], [0], [78], [17], [-35], [-60], [80], [62], [40], [-42], [-88], [-24], [9], [12], [-2], [62], [-64], [-67], [21], [-65], [-80], [-15], [-54], [59], [38], [9], [16], [55], [-6], [-28], [76], [64], [48], [-76], [33], [-20], [37], [-33], [-94], [-14], [58], [-8], [0], [54], [42], [-6], [-82], [36], [-51], [-99], [62], [-74]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6008_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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