
// Make newform 8880.2.a.j in Magma, downloaded from the LMFDB on 27 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_j();".
// 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_j();".
// 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], [-3], [1], [3], [3], [7], [-3], [10], [-10], [-1], [-12], [12], [4], [9], [6], [2], [-10], [-2], [15], [-4], [-9], [-11], [8], [-6], [-12], [13], [-9], [6], [-13], [8], [2], [14], [-22], [-7], [12], [11], [11], [-1], [0], [2], [15], [22], [11], [0], [-18], [16], [16], [26], [-10], [-12], [10], [2], [7], [24], [21], [12], [-11], [17], [-17], [1], [-14], [-32], [4], [14], [28], [-1], [24], [-28], [-34], [0], [5], [-14], [-10], [-33], [18], [20], [13], [20], [39], [26], [-23], [21], [-16], [4], [6], [-28], [2], [-8], [-8], [29], [38], [-3], [17], [4], [-29], [0], [28], [33], [-9], [-12], [14], [-45], [30], [26], [16], [-24], [40], [35], [26], [34], [-22], [-20], [-20], [48], [5], [-27], [-16], [44], [21], [-29], [-13], [20], [-22], [-48], [17], [30], [50], [46], [22], [-38], [4], [-47], [-10], [-42], [-33], [38], [-2], [-39], [16], [-13], [51], [0], [-5], [-10], [23], [-7], [5], [-32], [40], [-40], [47], [30], [23], [24], [-20], [18], [-18], [-14], [-24], [10], [-18], [12], [7], [-38], [-40], [-3], [-2], [-36], [-46], [-50], [0], [-1], [45], [-58], [-40], [43], [16], [46], [52], [10], [-17], [-42], [-4], [-51], [-32], [49], [-64], [-44], [-14], [12], [27], [13], [-12], [-8], [8], [14], [44], [-21], [-14], [13], [16], [42], [12], [-34], [-55], [-39], [45], [20], [-14], [-24], [4], [-19], [63], [-3], [22], [50], [33], [-45], [2], [-31], [46], [-46], [-44], [-51], [-36], [60], [-52], [36], [50], [28], [-5], [52], [-56], [-42], [53], [38], [-14], [-40], [4], [47], [-53], [-55], [44], [15], [-10], [30], [50], [7], [-9], [-48], [-66], [28], [14], [-72], [-22], [10], [-11], [-38], [2], [24], [40], [42], [-9], [20], [-39], [-18], [-38], [18], [-51], [35], [-20], [8], [61], [-17], [3], [-34], [-53], [-30], [-30], [-62], [42], [-64], [44], [-22], [-54], [-54], [-54], [-19], [26], [-46], [-66], [-81], [32], [-54], [-55], [33], [48], [-76], [-26], [78], [24], [78], [17], [-20], [-20], [38], [-6], [-13], [36], [-29], [22], [32], [-77], [-18], [-57], [-11], [-38], [43], [9], [27], [52], [1], [36], [64], [-20], [80], [-41], [-66], [-28], [-72], [-14], [18], [-43], [24], [-10], [66], [-30], [24], [56], [82], [0], [-72], [36], [-74], [32], [66], [0], [22], [42], [29], [-68], [70], [58], [80], [-21], [18], [-16], [-64], [46], [6], [27], [20], [70], [78], [-56], [26], [18], [-4], [16], [-26], [29], [-34], [74], [9], [6], [-61], [15], [47], [-14], [79], [10], [58], [-20], [-64], [-95], [26], [-44], [-1], [5], [-50], [64], [-85], [-32], [-101], [-70], [60], [54], [-33], [64], [-73], [-16], [-30], [-6], [49], [73], [-72], [16], [4], [-71], [-71], [34], [-43], [72], [83], [48], [-13], [-26], [-16], [10], [-9], [14], [21], [-101], [42], [5], [-86], [22], [-92], [23], [40], [-25], [56], [-40], [-12], [-54], [26], [8], [-74], [13], [-47], [54], [-80], [-8], [-27], [-36], [48], [36], [40], [83], [-34], [-27], [108], [-18], [-8], [-32], [-84], [-42], [48], [-100], [-48], [-44], [17], [-73], [-2], [9], [-39], [64], [88], [44], [-34], [13], [56], [60], [-29], [-36], [92], [52], [107], [-24], [6], [97], [26], [8], [-73], [34], [114], [-20], [-111], [31], [86], [-56], [94], [18], [10], [48], [-54], [-69], [-100], [-60], [52], [6], [-22], [-67], [52], [-106], [-2], [-68], [13]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8880_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![3, 1]>,<11,R![-1, 1]>,<13,R![-3, 1]>,<23,R![3, 1]>],Snew);
    return Vf;
end function;