
// Make newform 8880.2.a.ci in Magma, downloaded from the LMFDB on 04 May 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_ci();".
// 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_ci();".
// 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
        poly := [10, 3, -8, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-4, -2, 1, 0], [5, -4, -3, 1]];
    Rf_basisdens := [1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, -1, 0, -1], [-3, 1, 0, 0], [0, -1, 0, 1], [-1, 0, -1, 2], [-1, 0, 1, 0], [-2, 1, 0, -1], [1, 2, 0, 1], [-4, 1, 1, 0], [-1, 0, 0, 0], [0, 1, 1, -2], [-3, 0, -2, -1], [0, 1, -3, 2], [-4, 4, -1, -1], [-3, -1, 1, -1], [2, -1, 3, -2], [1, 0, 0, 1], [-3, 2, 2, 1], [-1, 1, -4, 2], [-3, -3, 1, 1], [-5, -3, 0, 0], [-6, -1, 0, -1], [-2, -5, 1, -4], [3, 4, 0, 3], [-4, -3, 1, 2], [0, -2, -1, -1], [-1, -2, -3, 0], [-1, -1, 3, 1], [3, 1, 2, 6], [-6, -1, -3, 4], [-5, 2, 2, -1], [1, -4, -4, 1], [-2, -1, 3, -2], [-4, 3, -4, 3], [-2, 1, 1, -4], [0, -2, -1, 3], [-3, -4, 1, 0], [8, -5, -2, 3], [-8, 1, 3, -2], [-1, -3, 1, -7], [-10, 6, 1, 3], [4, 0, 2, -2], [-4, -3, -4, -1], [-10, 1, -5, -4], [-3, -3, 3, -5], [-2, 1, 3, 4], [-8, 0, 0, 4], [4, 4, 0, -2], [4, 5, 1, -4], [-8, 1, 3, -2], [-1, 1, 1, 1], [-7, -4, 0, -3], [-3, -6, 1, -4], [-11, 2, 2, 3], [10, 1, 0, -5], [-10, 0, 0, -2], [-4, 0, -7, 1], [7, 2, 3, -4], [1, 0, -1, -6], [14, -5, 0, -5], [-2, -3, -3, 2], [-4, 2, 6, 0], [-3, 0, 2, 3], [0, 4, 8, -6], [9, 0, 4, -5], [-6, -3, 2, -9], [-6, 4, 4, -2], [1, 2, 6, -1], [18, -1, -3, -2], [-2, 1, -1, -8], [3, 2, -1, -6], [-7, 4, -6, 1], [9, 0, 4, -3], [9, 3, -2, -2], [2, -6, 2, -8], [-8, 5, 5, -6], [6, 6, -3, 1], [-5, 8, 0, 9], [-12, 2, -1, 5], [6, -9, -5, 2], [8, -10, -1, -1], [-1, 2, -3, -6], [16, -10, -6, 4], [-6, -3, 7, -4], [-1, -1, -1, 9], [-4, 4, -4, 8], [18, -1, 5, 2], [10, 8, -6, 10], [-9, 5, 1, 3], [6, -11, 0, 3], [9, 7, -5, 7], [-8, 1, -6, 1], [-4, 4, -3, -3], [4, 4, 0, -8], [18, -10, 1, -1], [-1, 0, 0, -3], [-5, 7, 3, 7], [4, -1, -4, 7], [8, 4, 1, -5], [-13, 1, 3, 3], [-21, -2, 2, -1], [5, -4, -1, 0], [2, -3, 1, 6], [1, 2, -2, 9], [-24, 1, 3, 2], [-8, -3, -1, -2], [6, 3, 1, 4], [-4, 6, 5, -1], [14, -3, 3, 2], [12, -6, 6, 2], [-19, 3, 1, -5], [18, -4, 0, 6], [3, 3, -1, 3], [0, 9, -7, 6], [-15, 9, 4, 2], [-6, 8, 1, 9], [-6, -2, -8, -2], [-16, 13, -3, -2], [-8, -1, -4, 7], [3, 2, 11, -4], [-1, -2, -3, 14], [2, 10, -6, -2], [14, -1, -1, -2], [10, 2, -8, 10], [-10, 12, -9, -1], [12, -7, -11, 4], [23, -6, -8, 7], [22, -1, -3, -6], [5, 4, -4, 1], [25, -13, -1, -5], [-15, -9, 3, 1], [-27, 2, 1, 0], [1, 3, -5, 7], [17, 2, 4, -7], [-12, 14, -5, -3], [21, -5, -3, 3], [6, -7, -5, 10], [-29, 3, 6, -6], [3, 8, -6, 1], [14, 3, 4, 5], [12, 8, -3, -5], [2, 3, 1, -8], [-6, -8, 1, 5], [-2, -11, 1, 2], [6, -2, -11, 13], [-36, 7, 0, -3], [12, -2, -9, 13], [15, -15, -1, -5], [-11, 5, 11, -3], [3, -2, -2, -15], [6, -3, 4, -1], [-12, 3, 5, -4], [16, 10, -1, -1], [-2, -11, -1, -12], [26, -2, 2, -10], [-6, 10, 2, 4], [-21, -4, 2, 3], [9, -19, 3, -1], [-2, 2, -2, 6], [-2, 4, 6, -12], [17, 5, 1, -9], [-8, -9, -1, -14], [-43, 3, 4, -2], [11, -4, -6, 3], [-35, 1, -3, 1], [-7, -13, 0, 2], [20, -17, -3, 0], [-2, -17, 7, -8], [-6, -5, -5, 18], [15, 7, -3, 13], [-23, 12, -6, -1], [11, -1, -2, 10], [-1, -1, 6, -12], [-18, -5, 1, 10], [36, -12, -6, -4], [20, -9, 0, -1], [4, -2, 6, 8], [8, -7, 3, 4], [-3, 0, -4, 19], [-17, 13, 7, -3], [28, -7, -2, -3], [-30, 10, 2, 4], [3, 6, 14, -7], [9, -2, 1, -2], [-1, 0, -12, -3], [33, -4, 5, 4], [-3, 3, -3, 1], [-46, 3, 5, 0], [7, -3, -5, -3], [26, 8, 0, 2], [3, 1, 4, 10], [52, 2, -1, 3], [-15, -9, 11, -7], [-8, 2, 2, -4], [-23, -6, -6, 15], [53, 2, 0, -3], [11, -14, 12, -3], [9, -5, -10, 10], [-9, -3, -11, 13], [12, -4, 7, -7], [12, 5, 1, 10], [-10, -8, -4, 4], [-8, -13, 11, -14], [-4, 0, 0, -14], [-16, -4, -13, 1], [17, -16, -5, 6], [-12, -1, -4, -11], [8, -9, 9, 2], [-12, -3, -7, 0], [29, -11, 3, -7], [6, -14, -8, -6], [-5, 13, -6, 10], [11, 2, 3, -18], [-2, -12, -7, -5], [-20, 4, -8, 2], [2, -9, -7, 10], [-40, 6, 7, -5], [-12, 19, -2, -5], [1, -16, -6, 1], [-10, 3, 0, 1], [5, -7, 9, 7], [0, 7, 9, -20], [-25, -10, 12, -15], [-13, 15, 10, -12], [0, -5, -3, 10], [23, -8, -2, 1], [-21, 4, 2, 9], [-18, -2, -2, -2], [48, -4, 0, -10], [7, 7, 11, 7], [29, 1, 2, 0], [-26, -11, 13, -16], [4, -17, -7, 6], [-16, 13, -13, 0], [27, -16, -5, -2], [-42, 9, 7, -6], [11, 10, -10, 19], [-28, 1, -9, -2], [-20, 18, -6, -8], [-8, -13, 8, -3], [-6, 22, -9, 1], [3, 7, -14, 8], [-26, 7, -3, 0], [22, 8, -1, 15], [-27, 13, 1, 3], [21, -2, 10, -3], [13, 1, 11, -1], [14, 1, 6, -3], [-9, -3, -4, 18], [21, -2, -2, -9], [6, 6, -6, 16], [-2, 7, 11, -16], [-8, 7, -3, 16], [-5, 14, -2, -15], [17, -12, -2, -19], [-15, 11, -3, 15], [5, -14, -13, 14], [7, -5, -11, 13], [-46, -4, 0, -12], [-18, 1, 3, -8], [25, -9, -3, 9], [26, 1, 11, 2], [11, 5, -2, -4], [10, 8, 12, -2], [18, -14, 7, 1], [1, -3, 1, 11], [2, -3, 5, -18], [-16, -6, -2, 14], [37, -1, 6, -6], [6, -5, 2, -25], [4, 5, -5, 2], [-32, -4, -4, -8], [-43, 16, -1, 0], [12, -12, 1, -1], [-44, 9, -6, 3], [-16, 14, 0, -14], [-18, 12, 3, 17], [0, 14, 4, -6], [-4, -5, 13, -4], [-4, -9, -1, -8], [6, 5, 11, 6], [13, 11, -3, 13], [30, -19, -5, 8], [-18, 13, 5, 18], [53, -7, -1, -1], [-7, 9, 9, 7], [7, 8, 8, -9], [-3, -16, -7, -10], [10, 19, -7, 14], [-3, 13, -1, 11], [23, 5, 3, 21], [31, 4, 3, 14], [0, 4, 6, -12], [4, 3, 11, -8], [6, 13, -10, 13], [-14, -9, -4, 7], [-32, 15, -3, -2], [-4, -12, 0, -12], [13, 13, -1, 15], [-3, -14, 4, -23], [-10, 9, -5, -20], [14, -2, 24, -8], [18, 5, -8, -7], [27, -26, -4, -7], [19, -7, -3, 15], [21, -16, 12, 1], [-34, 12, -10, 4], [16, -7, 14, 5], [23, -3, -5, -1], [40, 7, 4, -5], [16, 10, -6, 10], [14, 12, -4, 18], [-7, 8, 1, 4], [-19, 16, 14, -11], [16, -10, -5, 1], [4, 13, 4, 21], [-29, 1, -3, 1], [3, -3, -14, 12], [28, 7, 2, 3], [-26, -2, 9, -7], [24, 1, 1, -2], [-23, -1, -6, -14], [3, -1, -25, 19], [-4, 1, -3, 22], [4, 5, -13, -2], [-10, 0, -4, -6], [6, 8, 11, -13], [-19, -4, 14, -11], [-20, 6, 16, -4], [-11, 4, 12, -17], [-2, 18, 0, 20], [-23, -7, -5, 7], [23, -15, -6, 0], [14, -6, 6, 6], [1, 22, -8, -7], [-5, -9, 17, -23], [-12, -9, -7, 4], [-21, 0, 18, -19], [16, 1, 1, 6], [3, -20, 0, -29], [-27, -2, 6, -13], [66, 1, 3, 0], [9, 4, 8, -29], [-20, 16, 2, -2], [24, 16, -14, 24], [-23, -5, -19, 7], [17, -20, 10, -1], [45, -13, -13, 11], [-31, 25, 3, 7], [-44, 24, 5, 1], [-22, 9, -19, 0], [-8, 18, 2, 6], [19, 9, 5, 5], [-1, -12, 2, -27], [2, -9, 4, -19], [-54, 10, -4, 8], [-10, -16, 0, -22], [9, 15, -1, 21], [35, -6, 12, -9], [7, 9, 9, 17], [1, 24, -11, -4], [4, -6, 6, 16], [-3, 14, -2, 5], [11, -9, -3, -19], [3, 8, 4, 17], [-31, -5, 7, 7], [-16, -9, 9, -4], [27, 3, 3, -9], [21, -3, 7, -3], [-8, 3, -11, 24], [23, 6, 9, 16], [-18, -7, -3, 6], [-13, 19, -5, 17], [1, -5, -2, 0], [10, 0, 6, -12], [18, -7, -6, 11], [14, 2, -17, 23], [-32, 14, 1, -13], [14, -3, -1, -2], [10, 16, -3, 3], [-14, 3, 1, -22], [7, 4, -12, 19], [22, -9, 15, 4], [-18, 20, -6, -18], [30, -12, -9, -5], [22, -1, 1, 10], [-10, -3, 3, -16], [-45, 2, 3, -6], [-11, -8, 15, -28], [14, 14, 6, 0], [13, -30, 8, -9], [6, 5, 16, -21], [17, 0, 10, -9], [6, -3, 2, -1], [-11, -22, 2, 9], [-15, -2, 2, 7], [10, -7, -11, 2], [-2, 3, -8, 1], [-2, -3, -7, 8], [2, 11, 2, 1], [5, -5, -11, 1], [6, -21, 5, 14], [56, -11, -9, 4], [-34, 8, 11, -5], [-48, 11, 10, -9], [13, 6, 22, -5], [-7, -21, -9, 13], [47, -12, -4, 5], [44, -19, 8, 7], [4, -11, -10, 25], [15, -13, 1, 17], [34, -27, 12, 5], [-28, -8, 0, -12], [-20, 14, 17, -3], [7, -17, 7, -9], [0, -11, 4, -7], [-6, 9, -7, -22], [53, -4, -14, 11], [-22, 4, -4, -4], [12, 15, -20, 17], [-11, -5, 7, -1], [-22, -11, 2, -17], [24, 11, 0, -7], [-6, 10, -2, 0], [-8, 5, -12, 13], [62, -11, -1, -14], [-19, -10, 14, -19], [20, -5, 1, -10], [-46, -7, -6, 19], [4, 14, -18, 4], [-2, 31, -8, 15], [-22, 17, 1, -8], [-5, -15, -13, -5], [-11, 13, 11, 9], [-4, -17, 5, 8], [0, -9, -3, -4], [-27, 10, -4, -13], [-19, -22, 6, -11], [21, 12, 11, -2], [39, 12, 1, -16], [12, -4, -24, 22], [-8, 19, 13, -18], [-32, 13, -3, -18], [-67, 11, -6, 0], [-19, 9, 1, -7], [8, -16, 4, -8], [24, 13, 17, -14], [20, -4, 10, 24], [0, -9, -18, 5], [-9, -11, 19, -15], [-10, 13, -4, 15], [15, 9, 15, -9], [-10, -3, -15, -10], [28, -11, -15, -6], [26, 10, 4, 10], [2, 2, 2, -10], [27, 5, -3, -15], [-66, 4, -8, -2], [-46, 1, -5, 12], [-10, 3, 1, 4], [-60, -4, 4, -16], [-4, 5, 14, -13], [-34, -5, 2, 3], [39, 20, -8, 11], [55, -25, -14, 0], [29, 2, -7, -2], [-19, 9, 3, -3], [18, 2, 6, 14], [23, -18, 2, 13], [33, 10, 10, -15], [24, 16, 1, 31], [-27, 25, 3, 9], [-8, -14, 4, 16], [-33, 1, 4, 14], [-5, -21, 1, -13], [-54, 9, -5, 0], [-31, -10, 6, -5], [-45, -7, 10, -8], [58, -24, -8, -2], [-1, -20, 10, -13], [-6, 15, 6, 21], [-20, -21, -3, -16], [9, 8, -16, 19], [-73, 6, -1, -10], [-19, 12, -6, 9], [25, 9, -5, -13], [-14, 10, 26, -14], [-10, 26, -15, -1], [30, 3, 8, -1], [22, -5, -7, 22], [40, -11, -15, -2], [19, -21, -1, -11], [-29, 3, -7, 25], [-33, 26, 0, 7], [-34, -10, -14, -2], [-26, -15, 19, -10], [-9, -10, 1, -8], [36, 11, 11, -2], [-35, 16, 4, 3], [-23, 6, 6, -5], [-3, 29, -13, 15], [-9, 9, -11, 13], [-15, -21, 8, -6], [-65, 11, -13, -1], [16, -15, -9, 12], [22, 7, -1, 10], [3, 19, -3, 15], [39, -28, 5, 2]];
    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_ci();".
// 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_ci(:prec:=4)
    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_ci();".
// 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_ci( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8880_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![40, -9, -17, 1, 1]>,<11,R![-26, 9, 28, 10, 1]>,<13,R![-10, -63, -19, 3, 1]>,<23,R![32, -17, -13, 5, 1]>],Snew);
    return Vf;
end function;