
// Make newform 8820.2.a.bf 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_bf();".
// 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_bf();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 3]];
    Rf_basisdens := [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], [-1, 0], [0, 0], [0, 1], [1, -1], [0, 1], [7, 0], [0, 1], [6, -1], [1, 2], [-1, 1], [0, -1], [-1, 1], [-6, 0], [0, -2], [-6, -1], [4, -2], [-1, -1], [0, 3], [-5, -1], [11, 0], [-6, -1], [-6, -1], [-8, 2], [-12, 1], [13, 1], [0, -3], [-1, -2], [18, 0], [-7, 1], [6, 2], [0, -1], [7, 2], [12, 0], [14, 2], [-2, 2], [8, 0], [6, 3], [-12, -2], [6, 0], [13, 0], [-6, 0], [11, -1], [12, 1], [-2, -2], [14, 2], [16, -2], [6, -5], [7, 0], [-6, -2], [6, -4], [4, 0], [-6, -3], [6, 1], [0, 2], [6, -2], [-2, 6], [5, 3], [-12, -4], [-11, -3], [12, -4], [1, -1], [0, 5], [-11, -3], [12, 3], [17, 0], [-1, -3], [24, 0], [10, 0], [-6, -1], [-6, 1], [-23, -3], [5, 3], [5, -6], [0, 6], [0, 5], [13, -1], [12, -2], [-17, 0], [-6, -2], [23, 2], [6, -6], [-29, -1], [10, 0], [-12, -2], [6, 0], [11, 5], [6, 3], [23, -3], [6, -4], [12, 0], [-25, -3], [-24, 2], [11, 2], [-18, -2], [6, -6], [12, -6], [1, 1], [-7, -8], [8, 6], [30, 0], [-6, 0], [12, 7], [5, -8], [-17, 1], [24, 5], [-18, 5], [24, 2], [-5, 2], [25, 1], [20, -6], [18, 2], [-5, 4], [8, 0], [-30, -1], [7, 3], [6, 1], [-6, -1], [-24, -4], [19, -4], [17, 3], [0, 3], [-12, -5], [7, -8], [-30, 5], [-28, -2], [18, 2], [-5, 1], [-23, 5], [-7, -2], [6, -5], [11, 8], [26, -4], [42, 1], [-5, 0], [-18, 7], [-20, -2], [-36, 1], [6, -8], [22, -8], [24, -7], [-22, -4], [-18, -6], [-11, 0], [30, -1], [13, 3], [0, 1], [22, 0], [30, -2], [-10, 0], [24, 4], [-7, 3], [-6, 5], [-43, 3], [-30, -5], [17, 4], [24, 3], [-11, 7], [-18, -7], [-18, 5], [36, -2], [-31, -1], [36, 4], [30, -5], [-12, -7], [-19, 8], [13, 3], [-19, 2], [-24, -9], [-24, 2], [4, 0], [30, -1], [-1, 13], [1, -4], [-12, -12], [-7, -2], [-6, 10], [-20, 4], [1, 8], [47, -3], [6, -9], [11, 1], [-24, -6], [-6, 8], [-36, -2], [14, -2], [-29, -3], [-1, 2], [12, 1], [-11, -3], [30, -1], [-40, 0], [-12, 0], [0, 9], [12, 1], [23, 0], [-28, -6], [18, 6], [-48, -3], [30, -2], [-29, 6], [22, 6], [28, -6], [0, 11], [30, -6], [16, 8], [18, 8], [60, 2], [34, 0], [-31, 3], [-6, -5], [-16, -2], [-12, 4], [-18, -5], [19, 10], [-16, 4], [24, 4], [0, -6], [42, -4], [-1, 8], [-29, 4], [48, -3], [-16, 12], [-6, 10], [8, -10], [-60, 0], [-6, -6], [43, -3], [-36, 1], [5, -5], [-20, 12], [-49, -2], [60, 3], [13, 11], [-6, 1], [-5, -6], [-54, 3], [12, 0], [0, 3], [-18, -3], [19, 12], [31, 7], [-40, 4], [0, -6], [-12, -2], [-5, 7], [36, -1], [-10, 8], [36, -8], [-25, 9], [-48, 4], [-18, -12], [25, -2], [-48, -2], [-54, 1], [35, 8], [1, -7], [-42, 3], [-2, -12], [-19, -9], [-24, 10], [-5, 4], [-29, 7], [18, 6], [1, 8], [-36, -1], [18, 8], [-22, 0], [-42, -3], [31, -10], [-34, 0], [19, -1], [-19, -10], [10, -2], [-8, -14], [18, -9], [11, -8], [17, -12], [0, 0], [24, -10], [-13, -2], [6, 0], [7, -14], [-8, 14], [12, 15], [-31, -5], [6, -9], [55, -2], [-24, 11], [48, -2], [-12, 10], [6, -17], [6, 9], [23, -1], [18, 12], [7, -2], [-24, -13], [-36, -5], [-29, -3], [-14, 0], [42, -2], [26, 4], [12, -4], [-61, -2], [35, 7], [-66, 4], [67, -2], [12, 2], [-7, 15], [-24, 11], [-12, -7], [-60, 5], [-4, -14], [36, -10], [43, 2], [0, -7], [18, 9], [13, -3], [-12, -5], [-11, 14], [-13, -15], [6, 2], [35, -3], [-18, -8], [37, 8], [35, 4], [-41, 1], [-12, 4], [-54, -6], [-43, 2], [30, -7], [-11, -12], [-42, 7], [-1, -2], [54, -6], [-28, -10], [36, 7], [-23, 14], [-35, 3], [-7, -1], [12, 11], [-60, 6], [-37, 4], [-54, 3], [-30, 0], [37, -8], [-40, 4], [12, -11], [6, -10], [10, 6], [2, 0], [42, -6], [-8, -12], [-19, -10], [6, -4], [6, 12], [12, -2], [12, 16], [-6, 3], [44, -2], [36, 13], [-54, -2], [-78, 0], [31, 15], [-16, 6], [-24, -9], [-13, -9], [-16, 14], [72, -2], [7, -14], [54, -5], [-36, 7], [-5, -6], [23, 17], [6, -7], [-60, 4], [-38, -2], [18, -11], [-17, 1], [-36, 0], [-12, 15], [-16, -12], [0, -4], [-50, 0], [72, -2], [-31, 8], [-14, -12], [-25, -15], [30, 1], [77, 0], [-42, 7], [6, 9], [-65, 3], [0, -13], [-16, 14], [-44, -12], [-6, 14], [-25, -8], [30, -12], [-32, 12], [-48, 1], [26, -4], [-6, 21], [0, -19], [49, 10], [-10, -14], [0, 14], [-53, 1], [48, 8], [-2, 4], [-48, -2], [60, -1], [-52, 4], [-49, 11], [-24, -5], [24, 9], [-17, 9], [-36, 4], [12, -22], [-48, 6], [25, -7], [-60, -7], [30, 6], [-2, -6], [18, 3], [-6, -12], [24, -12], [-20, -12], [-30, -1], [7, -18], [-6, -13], [5, 2], [6, -7], [-5, 3], [0, 0], [-25, 4], [23, -10], [-37, -7], [-50, 8], [-72, -1], [60, 4], [71, -2], [18, 0], [-8, -4], [-24, 8], [70, -4], [6, -6], [-32, 0], [25, 2], [-49, -5], [-42, -6], [-30, -8], [60, -6], [-1, 7], [18, -15], [-25, -10], [0, -19], [22, 0], [-84, -4], [14, -10], [-13, 4], [6, 9], [-37, -6], [22, -4], [-34, -10], [47, 10], [24, -7], [-24, 1], [19, -12], [29, 7], [0, 18], [-12, 0], [35, 6], [72, -4], [-26, 6], [18, -18], [-5, -6], [72, -7], [-12, 0], [-41, 5], [-6, -11], [7, -19], [18, -15], [4, 2], [-30, 3], [-37, 2], [48, 8], [52, 8], [14, -6], [-14, -14], [-12, 12], [-43, -10], [-30, 12], [-6, -15], [-35, -2], [-29, -13], [-12, -7], [49, -2], [35, -4], [0, -2], [25, 15], [-102, -1], [59, 7], [50, -6], [0, 12], [36, -9], [25, -8], [59, 3], [28, 14], [-42, 2], [-48, 9], [-23, 13], [-6, -10], [2, 6], [-43, 9], [30, -3], [25, -18], [-30, 2], [85, -3], [77, 3], [-58, -12], [-18, 3], [18, -11], [25, -2], [24, -15], [-35, -3], [12, 4], [54, -4], [-42, -1], [80, 0], [12, 10], [77, -7], [84, 4], [-14, 14], [-30, 0], [25, 9], [30, 6], [17, -20], [65, 5], [-18, -3], [-24, 20], [-47, 4], [-24, 14], [24, 18], [-10, 6], [77, 1], [-66, -7], [7, 7], [108, 0], [54, -9], [-56, 6], [-48, 12], [54, 5], [54, 1], [-5, 16], [8, -4]];
    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_bf();".
// 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_bf(:prec:=2)
    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_bf();".
// 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_bf( : 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, 0, 1]>,<13,R![-17, -2, 1]>,<17,R![-18, 0, 1]>,<31,R![-71, -2, 1]>],Snew);
    return Vf;
end function;