
// Make newform 8880.2.a.d in Magma, downloaded from the LMFDB on 08 December 2025.
// 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_d();".
// 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_d();".
// 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 := 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]];
    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], [-1], [5], [2], [1], [-6], [0], [9], [-3], [-1], [9], [-1], [0], [9], [10], [-5], [-16], [0], [12], [12], [-2], [-2], [17], [-12], [4], [-18], [-5], [-13], [0], [-10], [-14], [19], [14], [-18], [7], [-1], [-20], [-7], [16], [14], [-11], [-2], [14], [12], [5], [5], [7], [0], [-8], [21], [-18], [24], [-18], [15], [24], [16], [-8], [-2], [28], [19], [30], [25], [-18], [-7], [8], [6], [-12], [0], [1], [-6], [23], [26], [-16], [0], [19], [18], [-6], [6], [-20], [30], [-15], [36], [27], [-2], [24], [1], [35], [-26], [21], [24], [-2], [36], [44], [-4], [24], [3], [0], [-10], [-17], [18], [-13], [38], [-35], [2], [-3], [-30], [4], [-7], [-6], [-23], [-10], [11], [13], [-15], [19], [-24], [-12], [32], [-11], [-44], [-6], [-33], [1], [-6], [-17], [-10], [18], [-47], [7], [-1], [-40], [22], [33], [22], [27], [-36], [40], [-24], [44], [-42], [-40], [3], [-17], [-54], [-26], [-33], [14], [-39], [47], [41], [9], [35], [-4], [8], [56], [-1], [56], [-22], [-1], [-4], [-36], [-29], [-27], [49], [31], [6], [-43], [6], [42], [59], [1], [-20], [14], [38], [22], [2], [43], [44], [-8], [-48], [40], [-9], [45], [-66], [-3], [7], [6], [4], [18], [48], [-22], [40], [-54], [46], [-20], [-16], [30], [4], [-22], [-38], [43], [-11], [-5], [-10], [-10], [62], [20], [-27], [-47], [-23], [46], [30], [43], [-9], [-10], [-56], [6], [-69], [-60], [-50], [-15], [32], [-52], [2], [-24], [-20], [-5], [42], [67], [20], [26], [-62], [18], [39], [-50], [46], [-18], [48], [69], [20], [32], [13], [6], [-27], [-8], [-64], [-7], [-6], [8], [46], [33], [26], [66], [43], [46], [-2], [-43], [-73], [10], [-48], [52], [11], [-78], [1], [40], [12], [-24], [-46], [46], [-55], [-26], [-15], [-74], [-43], [-54], [-62], [73], [-30], [-32], [-65], [-33], [-60], [-76], [6], [9], [-23], [72], [36], [75], [-20], [-46], [5], [71], [18], [14], [-78], [-20], [-72], [-15], [-18], [-60], [48], [52], [59], [27], [34], [-38], [-36], [48], [-44], [21], [-22], [2], [-24], [7], [-44], [-10], [0], [16], [2], [-89], [29], [-76], [12], [5], [-59], [42], [39], [62], [-14], [-47], [60], [-58], [14], [-14], [-82], [14], [0], [54], [-22], [-78], [45], [18], [66], [28], [-46], [-23], [-23], [45], [-40], [-63], [-12], [34], [-86], [43], [-22], [-66], [-92], [-10], [62], [30], [50], [38], [-77], [70], [82], [26], [84], [-34], [-77], [42], [95], [-97], [-24], [-48], [24], [-88], [-64], [93], [26], [68], [-32], [-38], [3], [82], [6], [93], [-36], [-53], [84], [38], [97], [-84], [68], [-32], [27], [65], [16], [-26], [-85], [18], [-86], [-90], [56], [-76], [-81], [-16], [-7], [32], [71], [105], [26], [-13], [4], [46], [-67], [68], [-6], [22], [-24], [-12], [-63], [52], [-3], [24], [59], [-60], [-31], [58], [-14], [14], [8], [-42], [-33], [-4], [-34], [28], [51], [-14], [42], [-44], [108], [32], [107], [-53], [-78], [4], [54], [-63], [-26], [-58], [-99], [-27], [-5], [0], [-54], [-42], [30], [-79], [91], [94], [43], [105], [61], [-100], [-84], [110], [-76], [-4], [-68], [-51], [68], [43], [26], [-98], [-81], [13], [27], [49], [40], [72], [-27], [-48], [-32], [-68], [-82], [28], [40], [-94], [-27], [-66], [-102], [30], [54], [28], [80], [-26], [-44], [-67], [110], [-18], [56], [6], [68], [-113], [32], [-10], [27]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8880_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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