
// Make newform 8664.2.a.l in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8664_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_8664_2_a_l();".
// 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_8664_2_a_l();".
// 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_8664_a();"
function MakeCharacter_8664_a()
    N := 8664;
    order := 1;
    char_gens := [2167, 4333, 5777, 8305];
    v := [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_8664_a_Hecke(Kf)
    return MakeCharacter_8664_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], [1], [-3], [-5], [2], [-1], [0], [4], [6], [10], [0], [0], [-11], [9], [-10], [-4], [-5], [4], [-8], [13], [-4], [-4], [6], [-2], [-6], [-10], [-18], [8], [-6], [2], [-19], [-9], [-15], [-1], [-20], [-2], [-24], [-18], [18], [-6], [-18], [15], [16], [6], [-11], [8], [-4], [6], [-11], [-23], [11], [12], [-19], [16], [-23], [22], [20], [25], [22], [-7], [-12], [0], [-27], [6], [-24], [-32], [18], [21], [-27], [14], [-21], [-8], [16], [34], [6], [25], [-19], [-24], [-18], [12], [-26], [10], [-34], [30], [-7], [20], [35], [7], [-1], [-15], [-16], [-4], [24], [39], [0], [6], [-8], [38], [15], [10], [-5], [20], [-34], [24], [35], [-35], [-14], [-36], [44], [22], [5], [27], [-20], [-47], [26], [21], [-25], [-9], [-6], [28], [44], [2], [-34], [35], [42], [-34], [-17], [39], [-46], [-7], [44], [0], [35], [-1], [-37], [-24], [-16], [-40], [17], [14], [-9], [5], [-32], [-4], [-18], [26], [-12], [-15], [-28], [-18], [-37], [-31], [-56], [-10], [50], [16], [-34], [-3], [-42], [-36], [-12], [8], [12], [-30], [-12], [32], [-35], [-32], [-41], [-60], [-6], [-16], [46], [10], [-19], [20], [-33], [20], [23], [35], [-26], [30], [-36], [-21], [63], [14], [48], [-34], [24], [-46], [51], [-34], [56], [-60], [-26], [37], [58], [-22], [-63], [16], [40], [-20], [38], [12], [63], [-61], [0], [-61], [50], [-42], [-42], [-11], [28], [58], [-56], [8], [-40], [42], [21], [-20], [-48], [-30], [-1], [60], [-1], [-48], [-24], [12], [-17], [-45], [14], [22], [32], [51], [-61], [53], [1], [-4], [8], [-6], [23], [-20], [-76], [54], [53], [-17], [-24], [8], [77], [-54], [-3], [-4], [44], [33], [-12], [-7], [38], [-12], [-38], [-16], [-60], [-5], [-30], [73], [10], [34], [65], [76], [-19], [14], [16], [-35], [-35], [44], [8], [3], [-26], [32], [79], [-40], [64], [-35], [-32], [-31], [7], [11], [54], [17], [46], [-14], [-69], [50], [24], [12], [-26], [-20], [9], [42], [-37], [-31], [10], [53], [50], [27], [58], [-48], [10], [-25], [-22], [51], [6], [40], [-16], [64], [70], [69], [-6], [-13], [27], [-40], [37], [-50], [50], [46], [-48], [6], [60], [-16], [-69], [-17], [18], [-24], [-69], [-51], [-51], [62], [-6], [23], [24], [-28], [63], [30], [36], [-40], [-34], [18], [38], [30], [35], [-30], [52], [-71], [-30], [28], [-14], [-32], [44], [7], [30], [-31], [-6], [12], [-80], [7], [18], [66], [86], [-10], [-52], [66], [17], [-88], [-35], [53], [6], [24], [7], [69], [16], [-90], [-79], [63], [-51], [-22], [18], [24], [-22], [43], [90], [-16], [50], [0], [-57], [-60], [50], [-60], [-54], [-2], [46], [-92], [81], [14], [-14], [-16], [55], [-11], [-48], [-14], [33], [46], [13], [-50], [-65], [-6], [-38], [-66], [-68], [18], [58], [100], [-74], [53], [-38], [-16], [-98], [-46], [-63], [45], [-83], [-28], [9], [89], [56], [-73]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8664_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8664_2_a_l();".
// 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_8664_2_a_l(:prec:=1)
    chi := MakeCharacter_8664_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(3037) - 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_8664_2_a_l();".
// 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_8664_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8664_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, 1]>,<7,R![3, 1]>,<13,R![-2, 1]>,<29,R![-6, 1]>],Snew);
    return Vf;
end function;