
// Make newform 2888.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2888_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_2888_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_2888_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_2888_a();"
function MakeCharacter_2888_a()
    N := 2888;
    order := 1;
    char_gens := [2167, 1445, 2529];
    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_2888_a_Hecke(Kf)
    return MakeCharacter_2888_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], [0], [-4], [5], [-5], [0], [-1], [-3], [-4], [-2], [5], [-11], [-5], [9], [-13], [-1], [5], [-1], [-9], [-17], [16], [-3], [13], [19], [0], [12], [-7], [-6], [-15], [-15], [-5], [15], [-17], [-16], [-13], [-4], [5], [5], [12], [-7], [-16], [-15], [10], [3], [-9], [11], [-12], [-22], [11], [12], [21], [-9], [25], [-19], [17], [29], [-30], [-15], [-15], [-10], [3], [12], [-5], [-27], [-20], [-3], [5], [-14], [-10], [5], [-5], [10], [12], [15], [-17], [35], [-11], [-7], [12], [29], [9], [25], [7], [15], [2], [10], [-1], [-20], [12], [27], [40], [9], [-35], [15], [5], [6], [29], [11], [-7], [-33], [-4], [18], [-4], [-2], [25], [35], [25], [34], [0], [-1], [3], [-20], [-29], [9], [5], [0], [-6], [-19], [29], [-30], [30], [0], [36], [23], [-17], [-27], [13], [-6], [37], [-29], [-31], [35], [38], [23], [25], [-20], [-42], [-42], [21], [11], [-5], [-15], [-30], [35], [-21], [-7], [-13], [36], [-47], [14], [55], [45], [35], [56], [-40], [7], [-17], [-39], [-35], [-15], [-23], [3], [-30], [-25], [55], [-25], [13], [15], [-52], [-55], [29], [-10], [-15], [-25], [19], [15], [56], [-25], [-5], [-36], [5], [5], [40], [22], [-35], [-1], [50], [56], [-59], [15], [-4], [-39], [-25], [-15], [-25], [-21], [30], [-24], [-15], [61], [-55], [-11], [-15], [15], [43], [21], [63], [-8], [-5], [51], [-36], [-35], [40], [-35], [-67], [10], [-32], [-25], [21], [40], [-7], [5], [-53], [15], [50], [-5], [7], [4], [-45], [17], [24], [10], [-16], [-3], [-58], [-6], [-3], [-51], [-49], [-20], [-25], [-15], [9], [0], [23], [45], [43], [-9], [-62], [-9], [-40], [65], [-29], [-57], [-21], [-20], [-3], [47], [-19], [15], [3], [-15], [-45], [68], [18], [26], [65], [39], [-50], [-28], [-45], [-32], [-55], [-15], [-52], [5], [5], [51], [-60], [36], [-77], [-10], [-47], [55], [54], [-7], [-23], [18], [-34], [8], [-51], [84], [85], [-78], [5], [15], [-45], [12], [-5], [45], [7], [-60], [69], [25], [-3], [-7], [-25], [66], [20], [83], [1], [60], [-27], [42], [-53], [-21], [-85], [-90], [35], [-77], [-19], [65], [-29], [-39], [-71], [20], [-45], [-29], [11], [-55], [-23], [36], [75], [-5], [-90], [-66], [46], [-32], [-31], [-25], [77], [-88], [1], [-93], [39], [33], [-41], [90], [-19], [-3], [11], [-24], [37], [10], [-15], [-39], [3], [-15], [-13], [-41], [-87], [0], [73], [1], [-50], [-29], [89], [-57], [52], [29], [57], [-23], [10], [47], [24], [31], [-17], [-55], [6], [-74], [-85], [15], [-72], [35], [-16], [23], [-5], [20], [65], [-35], [-12], [-53], [81], [-79], [-17], [42], [-65], [59], [85], [75], [-40], [85], [-59], [-35], [-5], [74], [-11], [-24], [-35], [-45], [0], [16], [-38], [-6], [-27], [40], [35], [-55], [37], [37], [-80], [-83], [-14], [18], [44], [27], [-44], [-103]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2888_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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