
// Make newform 8880.2.a.n in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8880_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_8880_2_a_n();".
// 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_8880_2_a_n();".
// 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_8880_a();"
function MakeCharacter_8880_a()
    N := 8880;
    order := 1;
    char_gens := [5551, 6661, 5921, 1777, 8401];
    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_8880_a_Hecke(Kf)
    return MakeCharacter_8880_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], [4], [-6], [2], [-6], [-2], [0], [6], [-8], [1], [-6], [-8], [-6], [6], [12], [8], [4], [0], [14], [16], [12], [6], [8], [0], [-14], [0], [20], [6], [4], [12], [-12], [4], [-12], [16], [14], [16], [-12], [6], [12], [-10], [0], [-16], [18], [4], [16], [4], [12], [26], [-24], [-24], [2], [0], [30], [6], [-24], [-8], [-10], [-30], [16], [-30], [4], [0], [-16], [-18], [-14], [-10], [12], [26], [30], [24], [28], [-22], [-20], [12], [-30], [-22], [18], [-10], [-6], [8], [0], [38], [-20], [12], [-18], [8], [-6], [34], [12], [24], [-2], [6], [-14], [-24], [0], [30], [-32], [8], [4], [18], [12], [-30], [16], [20], [-36], [12], [12], [-10], [-14], [2], [-12], [-32], [28], [18], [4], [-24], [18], [-6], [20], [26], [18], [-12], [40], [-6], [44], [36], [-38], [2], [16], [6], [-32], [-10], [6], [26], [30], [28], [42], [30], [-20], [24], [16], [-36], [-28], [24], [-10], [-42], [-14], [-30], [2], [-42], [-20], [6], [40], [-48], [4], [-42], [14], [-48], [36], [36], [46], [54], [42], [30], [-56], [26], [-10], [-42], [-12], [8], [-48], [62], [40], [42], [-50], [12], [-56], [-46], [46], [0], [14], [-42], [6], [-60], [-34], [4], [-58], [-48], [20], [-24], [-26], [36], [48], [-48], [38], [-46], [-12], [0], [-18], [40], [-22], [14], [6], [66], [-56], [36], [6], [28], [-28], [-30], [10], [24], [0], [-34], [58], [18], [36], [-6], [-22], [-56], [-54], [-2], [36], [-64], [-48], [36], [28], [36], [-46], [-8], [-32], [6], [28], [-30], [14], [-42], [-36], [0], [-60], [-38], [52], [20], [12], [0], [-2], [-12], [-32], [12], [-58], [18], [-54], [-46], [-6], [54], [-10], [28], [-42], [8], [46], [36], [14], [50], [-6], [40], [36], [-6], [-44], [6], [56], [-20], [56], [4], [2], [-20], [0], [68], [38], [36], [6], [-32], [18], [26], [-68], [12], [32], [42], [16], [78], [54], [36], [60], [-66], [14], [36], [64], [66], [48], [52], [-28], [-6], [16], [12], [-86], [20], [60], [-4], [72], [-22], [6], [24], [-66], [4], [-48], [-34], [-78], [24], [-70], [-30], [58], [50], [66], [-92], [48], [-70], [64], [76], [0], [54], [-10], [-30], [40], [60], [46], [-12], [26], [24], [86], [-20], [-82], [-12], [-18], [52], [-66], [48], [-34], [28], [-24], [90], [28], [-82], [-42], [70], [-58], [12], [-96], [-60], [-96], [-24], [26], [-78], [12], [-60], [-44], [-40], [42], [46], [2], [60], [22], [54], [48], [40], [74], [90], [-48], [14], [30], [-70], [6], [-54], [-2], [84], [-50], [-54], [16], [86], [4], [60], [14], [-66], [48], [-44], [-12], [2], [-44], [-6], [-68], [24], [-22], [66], [10], [-42], [-102], [40], [-82], [6], [-68], [54], [26], [30], [36], [10], [68], [36], [-60], [28], [-12], [48], [-90], [2], [54], [54], [74], [42], [-12], [42], [4], [24], [-58], [-36], [106], [-54], [62], [42], [-82], [86], [-68], [-92], [-84], [42], [-70], [24], [-46], [90], [4], [-84], [-70], [-10], [-32], [84], [48], [30], [-64], [78], [38], [0], [26], [72], [76], [40], [-48], [8], [40], [-64], [-80], [84], [114], [64], [94], [12], [-96], [-58], [6], [-58], [-66], [-92], [-78], [66], [-64], [102], [-58], [90], [-26], [-12], [-22], [60], [64], [16], [62], [18], [86], [-42], [-108], [-10], [16], [-18], [-56], [10], [-30], [22], [24], [46], [-94], [48], [-90], [88], [26], [-44]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8880_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8880_2_a_n();".
// 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_8880_2_a_n(:prec:=1)
    chi := MakeCharacter_8880_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(3643) - 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_8880_2_a_n();".
// 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_8880_2_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8880_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, 1]>,<11,R![6, 1]>,<13,R![-2, 1]>,<23,R![0, 1]>],Snew);
    return Vf;
end function;