
// Make newform 8820.2.a.bq in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8820_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_8820_2_a_bq();".
// 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_8820_2_a_bq();".
// 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 := [-1, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-4, 0, 1], [3, 3, -1]];
    Rf_basisdens := [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_8820_a();"
function MakeCharacter_8820_a()
    N := 8820;
    order := 1;
    char_gens := [4411, 7841, 7057, 1081];
    v := [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_8820_a_Hecke(Kf)
    return MakeCharacter_8820_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, 0, 0], [1, 0, 0], [0, 0, 0], [1, 0, -1], [-2, 0, 1], [0, 1, -1], [0, -1, 0], [-2, 1, 1], [-5, -2, 1], [-1, 0, 0], [-3, 1, 1], [3, -2, -1], [-1, -1, 1], [4, 2, 0], [0, 2, -2], [-5, 0, -1], [1, 1, 0], [-2, 0, 1], [-7, 0, 1], [-5, -1, -1], [-6, -3, 2], [-2, -1, 3], [-1, -2, 3], [-5, -1, 2], [-3, 0, -3], [-3, 3, -1], [-4, -1, -1], [2, 1, 2], [-10, 0, -2], [2, 2, 1], [8, 0, -2], [-8, 1, 1], [0, 3, -4], [-6, 0, 0], [1, -1, -4], [2, 2, -2], [6, 4, -2], [4, 1, 1], [4, 2, 0], [-2, -2, 4], [8, -1, -2], [-10, 2, -4], [5, -3, -3], [-18, 1, -1], [3, 1, 4], [9, -3, 2], [-4, -4, 4], [-16, -3, 1], [-7, -4, 4], [-16, -4, 2], [-10, 4, 0], [3, -3, 2], [9, 6, -3], [0, -5, -1], [-2, -4, 0], [-10, 2, 2], [17, 1, 2], [-7, 1, -1], [-20, 2, 0], [-7, -3, -3], [18, 2, -2], [8, 2, 1], [-17, -2, 1], [-13, 3, -3], [-14, 3, -1], [1, 4, 0], [2, -4, 1], [14, -2, 0], [2, 2, -2], [-8, 1, 1], [-15, -2, -1], [14, -4, 1], [12, 4, 1], [1, 6, -2], [16, -2, -2], [-13, 0, -5], [5, 5, 1], [-8, -6, 2], [13, 6, -2], [16, -2, -2], [10, 5, 2], [2, 2, 2], [2, 0, 3], [5, -7, -2], [-10, 4, 0], [-22, 2, -4], [8, 2, 1], [-3, -4, 7], [-14, 2, -1], [12, -2, 2], [-10, -4, -4], [2, -6, 3], [-2, -2, -2], [-1, -2, 2], [-12, 0, 0], [-8, 6, 2], [-6, 4, 2], [-28, 2, 1], [-21, -4, 6], [14, -2, -4], [-14, 0, -4], [-6, 4, -10], [-17, 4, 1], [-24, -1, 0], [-4, -4, 1], [-6, -5, 5], [-8, -5, 7], [18, 6, -6], [2, 7, 2], [10, -2, 3], [17, 1, 2], [-4, 0, -8], [-13, 0, 6], [18, -8, -2], [-17, -4, -3], [-22, 2, 1], [-2, 9, -1], [10, 5, -3], [-4, -8, 0], [10, -5, 6], [-32, -2, 3], [6, 9, -3], [12, 1, 5], [23, 2, 4], [-19, -8, 3], [1, 7, -6], [8, -4, 2], [29, 7, -7], [-34, -4, 1], [-4, -7, -2], [0, -9, 3], [-17, 2, 2], [10, -2, 6], [-17, -2, 1], [8, -7, -2], [-2, -5, -5], [-2, 4, 6], [6, 3, 9], [-12, 6, 0], [-7, -9, 0], [-21, 6, 3], [27, 3, -4], [14, 6, -2], [4, -7, -4], [-29, -4, 3], [-1, -3, -9], [22, -5, 1], [-13, 7, 2], [-6, -10, -2], [4, -4, 2], [18, 4, -4], [-15, 5, -9], [8, 3, 7], [3, 1, 1], [9, 6, -3], [5, 6, -6], [-17, -6, -1], [-13, -3, 3], [-3, -8, 5], [-6, -5, 5], [-2, 4, -2], [15, 9, -7], [14, -4, -4], [-12, 3, 9], [10, -1, -3], [8, 11, -8], [23, 9, -9], [-1, -10, 4], [-22, 1, -9], [10, -4, 6], [5, 9, 0], [3, 0, 9], [18, -4, 9], [-5, -4, -4], [30, 8, -8], [17, -4, 4], [-22, -4, 2], [6, 10, -8], [29, 14, -8], [-19, 3, 3], [-27, -6, 3], [-28, 0, -9], [-12, -2, -10], [34, 4, -2], [26, -4, 2], [-18, -6, 2], [-31, 3, -3], [2, -1, 4], [21, -6, 9], [-30, -4, -3], [20, 7, -3], [-8, -8, 12], [-4, 0, -8], [36, 3, -3], [16, 1, 7], [-17, -14, 6], [-13, -13, 10], [-14, 10, -2], [14, 3, -5], [-10, -14, 6], [9, -2, -2], [8, -2, 8], [-1, 1, -10], [-7, 14, -1], [18, -2, -4], [10, 8, -10], [54, 0, 0], [12, 0, 6], [27, -5, -2], [-8, 12, 1], [33, 6, 3], [-54, 0, 2], [-14, -10, 6], [-7, 8, -1], [30, -5, -2], [8, 2, 10], [28, 4, 4], [10, 12, -4], [28, 10, -2], [-4, -3, -12], [-16, -3, 6], [29, -10, -1], [32, -2, 2], [-2, -10, 6], [9, -5, 10], [-28, 4, 0], [2, -6, 10], [23, -1, 7], [25, -4, -9], [33, 15, -7], [2, -8, 2], [38, 5, -2], [15, 6, -3], [-21, 3, -7], [30, -3, 3], [19, -2, 12], [-6, 13, 5], [44, -6, 4], [-49, -8, 3], [22, 15, -7], [20, -3, 18], [-24, 8, 9], [9, 15, -10], [-6, 0, 12], [38, 2, 2], [29, 9, 3], [-3, 6, -9], [-37, -3, 0], [44, 0, -2], [20, -16, -5], [-26, 16, 4], [22, 4, -2], [4, -15, 4], [32, 2, 2], [35, 4, 3], [2, 9, -6], [44, -4, 7], [14, -13, -1], [20, 4, -10], [-3, -7, 15], [28, -6, 2], [27, -6, -4], [2, 6, -3], [14, 2, -4], [-7, 0, -6], [5, -4, 5], [-14, 8, -12], [-19, -7, -8], [10, -5, -11], [48, 5, -6], [11, -5, -4], [-25, -3, -3], [7, 6, 4], [-28, 6, 0], [-62, -4, 2], [62, -3, 1], [29, -12, -6], [2, -11, -4], [-16, -2, 12], [10, -12, 2], [14, -9, -12], [-44, -2, -8], [16, 3, -8], [30, -8, -2], [-5, -8, 1], [19, 1, -3], [0, 3, 9], [-12, 1, -2], [-11, -14, 7], [-14, 16, -2], [16, -10, -12], [32, -5, 15], [35, 0, 1], [-19, 7, -13], [24, 0, -12], [38, -1, -2], [-24, -1, -11], [-25, 2, -1], [33, 1, 7], [-22, 10, -10], [-2, 2, 12], [-25, -7, 4], [28, -8, 4], [9, 10, -8], [56, 4, -1], [26, 0, -2], [33, 2, -6], [28, 16, -2], [16, 2, 11], [18, -3, 3], [-15, 12, -9], [-25, 4, 3], [22, -4, 2], [44, 2, 2], [29, 12, 0], [-1, 2, -7], [7, -8, 7], [2, 10, -1], [29, -6, -11], [25, -2, 0], [-13, -1, 13], [-46, -6, 10], [-52, -2, 5], [-18, 0, 6], [12, -5, 10], [44, 3, -6], [-46, 4, -1], [-30, 2, -14], [-18, -18, 6], [-23, 2, 2], [-4, -7, 17], [-31, 8, -2], [-16, 5, 11], [-40, 9, 0], [-8, 16, -8], [-5, 13, 6], [-46, -7, 11], [26, 5, 10], [35, 9, -9], [50, 8, -5], [34, 3, -7], [40, 4, -2], [45, -2, 4], [-24, -21, 15], [4, 0, 20], [38, 13, -10], [26, 2, 4], [-19, 14, -7], [4, 4, 4], [19, 5, -4], [-34, -14, 14], [20, 2, -10], [-16, -6, -6], [-38, -3, 4], [-8, 10, 10], [2, -4, -16], [-10, -14, 6], [18, 6, 0], [2, 5, 5], [1, -7, 2], [-15, -20, 5], [-22, -6, 10], [0, -4, -8], [-12, -24, 5], [13, 13, -6], [-38, 9, 5], [-3, -3, -7], [15, -3, 2], [8, -4, 14], [-10, -13, -2], [10, -3, -7], [-1, 2, -19], [-29, -10, 8], [-34, 8, 1], [-29, -16, 9], [28, 10, 4], [-30, -14, -2], [-3, 12, -3], [3, 11, -9], [46, -6, 8], [38, 7, -9], [32, -14, 2], [-44, 4, 10], [-43, 1, 2], [40, -2, 4], [-1, -2, -4], [-10, 0, 12], [22, 2, -13], [0, 11, 13], [-7, -6, -6], [-4, -11, -3], [11, -2, 15], [55, 9, 1], [-63, -10, 1], [19, -17, 6], [36, 0, -4], [-54, 2, -2], [2, 1, 14], [-12, -12, 12], [11, -17, -4], [10, 13, -5], [-25, -1, -8], [-58, -7, 11], [-37, -2, 9], [53, 8, -2], [-2, 2, -22], [-4, 8, 2], [-56, 6, -5], [16, 10, 4], [-46, 6, -6], [-24, -18, 6], [30, 15, -3], [-18, 0, 2], [-4, -6, 9], [-27, -16, 19], [-21, 0, -21], [30, 8, 3], [-10, -10, 8], [-8, 2, 0], [-12, 8, 10], [-37, -3, -9], [-30, -3, -15], [60, 4, 2], [20, -14, 8], [-16, -11, 15], [-18, 4, 2], [-4, 2, -4], [44, 8, -8], [23, 6, -5], [53, 14, -14], [-3, 6, 9], [9, -10, -6], [-40, 11, -7], [-26, -8, -9], [-48, 0, 0], [52, 5, -4], [11, -4, 16], [-9, 11, -15], [-15, 7, -20], [-62, 1, -11], [-40, -10, 8], [-23, 14, -4], [-6, -2, -4], [-29, -7, 14], [-48, -12, 12], [-7, 17, -8], [-24, -16, 22], [7, -5, 12], [26, 3, -12], [1, 13, -15], [10, 4, -2], [-16, -10, -4], [8, 14, -10], [-20, 2, 5], [-19, -4, -13], [-22, 3, -12], [-21, 10, 5], [-10, 16, 8], [-2, 2, -6], [-31, 5, -2], [-28, 5, -8], [53, -4, 11], [-3, -4, -6], [7, 19, 0], [12, -2, -20], [16, 7, -18], [40, -11, -5], [-15, -16, -5], [20, 7, -4], [-16, 0, -3], [-30, -16, 10], [8, 4, -12], [-2, 3, 16], [66, 8, -8], [-40, -18, 12], [16, 4, -2], [-7, -8, 8], [26, -5, -3], [-6, 18, -6], [3, -23, 1], [25, 10, -11], [-61, 3, 3], [-23, 16, 1], [8, 8, -20], [-30, 21, 9], [74, -1, 4], [-8, 10, 4], [-36, 0, -16], [-47, 7, 0], [40, 2, 8], [-18, -18, 6], [-24, -7, -6], [38, 20, -16], [-1, -6, -17], [41, -6, 12], [39, 5, 9], [-8, 7, -11], [14, -7, -2], [11, 0, 0], [-38, 8, 6], [-11, 11, 11], [-8, 11, -21], [-4, 0, 15], [-58, -2, 2], [48, 8, 10], [-24, 13, -13], [20, -13, -14], [-46, 0, 9], [-44, -2, -6], [-38, -8, 10], [-27, -4, 1], [-1, 21, 3], [50, 2, -10], [5, 7, 8], [12, -2, -5], [23, 2, 17], [59, 12, 0], [-78, 2, -2], [-41, -5, 9], [5, -1, -11], [23, -17, -10], [-19, 12, 1], [-12, -3, -9], [-1, 8, -8], [3, -16, 1], [18, 0, 17], [-22, -2, 0], [44, -10, -4], [35, 4, 15], [-4, -20, 8], [-16, -6, 4], [57, 23, -15], [-26, 12, -4], [18, 16, -8], [-38, -24, 8], [17, 15, -9], [8, -22, 2], [32, 5, 10], [-27, -13, 21], [15, 2, 25], [-16, 8, 2], [-35, -8, 18], [-28, 2, -4], [4, 20, 6], [-7, -23, 2], [74, 0, 3], [94, 5, -3], [31, 3, -5], [-26, 10, 4], [-1, 6, -11], [-44, -10, 14], [-12, 8, -20], [-12, -19, -5], [-27, -24, 3], [1, 10, -6], [-58, -4, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8820_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8820_2_a_bq();".
// 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_8820_2_a_bq(:prec:=3)
    chi := MakeCharacter_8820_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(4027) - 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_8820_2_a_bq();".
// 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_8820_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8820_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-18, -18, -2, 1]>,<13,R![3, -11, 5, 1]>,<17,R![18, -24, 2, 1]>,<31,R![1, 1]>],Snew);
    return Vf;
end function;