
// Make newform 9216.2.a.bl in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9216_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_9216_2_a_bl();".
// 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_9216_2_a_bl();".
// 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, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -2, 0, 1], [-2, 0, 1, 0], [0, 4, 0, -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_9216_a();"
function MakeCharacter_9216_a()
    N := 9216;
    order := 1;
    char_gens := [8191, 2053, 4097];
    v := [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_9216_a_Hecke(Kf)
    return MakeCharacter_9216_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, 0, 0], [0, 0, 1, -1], [2, 0, 0, 1], [0, -1, 0, -1], [-2, 2, 1, 0], [0, -1, -2, -1], [0, 1, -2, 1], [-4, 0, 0, 0], [0, 2, -1, 1], [2, 2, 0, -1], [-2, -2, 1, 2], [0, -3, 2, 1], [0, -3, 2, 1], [-4, 0, 4, 0], [0, -2, 1, 3], [-4, 2, -4, -2], [-6, -2, -1, -2], [-4, 0, -4, -4], [-4, 0, -4, 2], [-2, 4, -2, 0], [6, 0, 4, 3], [0, 1, 4, 1], [2, 4, 4, 0], [-4, -2, -4, -2], [-4, 0, -5, -1], [6, 6, -4, 1], [-4, -2, -8, 2], [-6, 2, -5, 0], [2, 0, -4, 0], [10, -2, 0, -5], [4, -6, 0, 2], [0, 3, 2, 3], [-4, -2, 8, -2], [-8, 0, -5, 1], [6, -6, -4, -3], [-2, 2, 3, -2], [8, -5, -2, -5], [-8, 4, 8, 2], [-12, -2, -1, -1], [-4, 0, 4, 4], [-6, -2, 1, 0], [-8, -4, 4, -6], [4, 0, -6, 4], [-8, 2, 9, 3], [2, 2, 12, -1], [-4, 2, 0, 2], [2, 4, 4, -7], [8, 5, 4, -3], [-2, 2, 3, -4], [2, 0, 8, -4], [0, -4, 4, 6], [12, -6, -6, -2], [8, 1, 0, 1], [6, 0, -4, -4], [-8, 4, -4, -8], [-12, 8, 5, 5], [-6, 0, 12, 1], [-2, 2, -5, 8], [-2, -8, 0, 4], [4, 2, -4, -2], [-16, -2, -7, 3], [4, 4, -4, 8], [0, 4, -4, -4], [4, 0, 2, -4], [4, -8, -1, 7], [4, -2, 0, 6], [-6, 0, -6, -12], [0, 3, 4, -5], [-2, -2, -3, 6], [10, -4, -16, 0], [4, 4, 12, -2], [-6, 2, -8, -1], [-2, 2, 7, 2], [-16, 3, 2, -1], [8, 8, -4, 10], [-20, -6, 3, -1], [-10, -2, 3, 6], [8, 1, -6, 1], [4, 2, 8, -6], [-8, -9, 4, -1], [-10, 6, -5, -4], [4, 0, 20, -4], [-4, -4, 12, -4], [-14, 2, 4, 7], [-8, -1, 4, 7], [-8, -5, 2, -9], [-4, -2, 4, -10], [4, -6, 13, 1], [2, -2, 8, 7], [8, 1, -12, 1], [12, -4, -8, -2], [-10, -4, -8, -5], [-4, 4, 4, 12], [-12, -6, 4, -10], [-4, 4, -12, 2], [-8, 6, 5, -5], [0, -3, 14, -7], [16, -3, -10, -3], [-26, -2, -1, -4], [8, 7, 14, -5], [-8, 0, -17, -7], [-8, 5, -16, -3], [-16, 9, 2, 5], [4, -2, -12, -6], [-10, -8, 10, -4], [-4, -2, 4, -10], [-14, 4, -4, -12], [20, 4, 8, -4], [-2, -4, 10, 0], [-14, -10, 0, 3], [-2, -2, -9, 6], [6, 0, 4, 8], [12, 12, 0, -4], [-10, 4, 0, -1], [0, -1, -6, 7], [-8, 1, 10, 1], [4, -4, -8, -12], [-20, -6, 21, -3], [-20, -8, -4, 0], [2, -2, -19, 2], [12, 0, -4, 0], [0, 16, -5, -3], [16, 1, 12, -7], [16, 3, 14, -5], [-12, 4, -3, -3], [2, 2, 17, 8], [28, 4, -8, 2], [2, -2, -12, 7], [10, -6, -3, 0], [-20, -2, -4, 10], [-8, -8, 8, 6], [2, -4, -12, -11], [-6, 6, 9, 4], [8, 11, -6, -1], [4, 4, -10, -8], [4, -8, -5, 3], [0, -7, 6, -11], [-8, 8, 5, 7], [-8, -1, -2, -5], [-8, 9, -10, 5], [4, -4, 9, 9], [14, 0, 8, 3], [-20, -4, 8, 0], [-22, -6, -5, 8], [4, 12, -4, -10], [22, 2, 7, -10], [24, 1, -2, 1], [-16, -3, 2, 5], [-16, -12, 4, -2], [10, 10, -1, 10], [22, -4, 12, -8], [-24, -3, 10, -7], [0, 8, -4, -16], [8, 1, -14, 1], [-8, 8, -12, -2], [-2, 8, -8, 7], [-16, 1, 6, 13], [-2, 0, 0, -16], [4, 6, -19, -3], [-28, -8, 12, -4], [0, -15, -10, 5], [10, 0, 16, -11], [24, 3, -4, 11], [0, -19, -2, 9], [-8, 12, 4, 12], [-6, 4, 4, 1], [-2, -14, 1, -14], [4, -14, 8, -6], [-4, 6, 19, 7], [12, 8, -4, 8], [2, -6, 1, -10], [-32, -8, 0, 6], [2, 0, 0, 8], [-22, 8, -4, -7], [-2, 4, -8, 8], [12, -10, -4, 2], [8, -12, -13, 5], [26, -2, -4, 3], [-2, 10, -11, -10], [14, -12, -4, 3], [24, 5, 12, 5], [34, 2, 15, -12], [14, 0, 0, 12], [-8, -16, -4, -2], [-4, 2, -13, -13], [-18, 10, -9, -12], [-4, 6, 12, 10], [-20, 10, 6, 6], [8, 4, -8, 16], [6, 0, 20, 0], [4, -10, -12, 2], [28, 6, -4, -6], [12, -6, -1, -9], [-36, 6, 0, -2], [22, 4, 4, -12], [-10, 0, -22, -4], [14, 6, -1, 16], [-26, 12, 0, -8], [8, -4, 4, 8], [0, 4, 23, 9], [22, -2, 0, 1], [26, 6, -17, 4], [-6, 8, 18, 4], [-16, 3, -16, -5], [32, -14, -1, 5], [-6, -4, -12, 17], [8, -7, 8, 17], [10, 8, -20, -8], [32, 3, -2, 7], [20, 4, 14, 0], [16, 8, -21, 5], [18, 6, 4, -1], [-12, 2, -12, 22], [28, -8, 4, 10], [4, 4, 0, -4], [2, -2, 16, -5], [8, -1, -2, 19], [-8, -4, 8, 10], [8, -12, -1, -7], [18, 6, -1, -4], [-2, 4, -8, 7], [8, 1, 14, 1], [46, -4, -12, -1], [-24, 17, 4, 1], [-10, -18, -1, 10], [-22, 8, 0, 8], [28, -12, -8, 6], [10, 8, 16, -15], [44, 4, -12, -4], [10, -10, 3, -20], [32, -9, -18, -5], [34, 6, 8, -1], [-2, 12, -16, 0], [-24, -5, -10, 7], [-4, 16, 16, 14], [12, -14, 12, 2], [16, 16, -13, 1], [0, -7, -28, -7], [-36, 4, -16, 0], [16, -19, -8, 5], [-4, -12, -12, 0], [18, -18, -4, -5], [-30, -2, 9, 2], [30, 0, 20, 0], [4, 4, -4, 14], [2, 4, 4, -15], [-28, -10, 0, 10], [-4, 0, 4, 12], [-40, 4, -16, 4], [38, 14, -15, 8], [-14, 16, 12, 0], [-4, -12, 24, -8], [-10, 8, 12, 8], [24, 6, 21, 7], [-4, -12, 32, 0], [-10, -2, 5, 0], [-36, 0, -16, 8], [24, 14, -29, 5], [12, -4, -20, 12], [22, -6, 0, -7], [12, 6, 4, -14], [-10, 18, -3, -4], [-6, -18, 9, 2], [-16, 1, -6, -11], [28, 4, -4, -16], [8, 12, -3, 11], [-6, 12, 4, -4], [24, 13, 6, 1], [-8, -4, 11, -3], [14, 10, 21, -14], [-36, -12, 8, 4], [10, 0, -12, -16], [14, -2, 8, -15], [10, 24, -16, -8], [6, -8, 0, -1], [8, -13, -8, -21], [6, -2, -5, 6], [-2, 4, -30, 0], [-12, 0, 0, 4], [-4, 4, 0, 6], [18, -2, 12, 19], [-12, -8, -8, 16], [-10, -10, 15, -10], [16, -19, -10, -7], [-24, 8, 0, 8], [-4, -18, 10, 10], [8, -12, -7, -25], [-6, -8, 16, 5], [26, -8, 16, 20], [-12, 10, -11, -3], [20, -8, -4, -4], [10, 12, -16, -4], [-12, 16, 4, 20], [42, -2, 23, 2], [12, -6, -27, -7], [14, 16, -12, 3], [-20, 4, 19, 11], [-32, 1, 0, -7], [16, -7, -34, -3], [4, 12, 22, -8], [28, 6, 23, -21], [-14, 0, -20, 13], [12, 28, 8, -12], [16, -3, 26, -15], [28, -6, 26, 14], [-24, -19, 0, -11], [34, 22, -3, -4], [28, -4, 4, -10], [-30, -6, -11, 18], [-16, 12, 28, -2], [-28, 4, -13, 3], [0, -1, 26, 7], [24, 3, 18, -9], [-8, 24, -4, 0], [14, 0, -20, -8], [-28, -14, 28, 2], [-12, 24, -8, -2], [-22, 0, 2, -20], [26, -8, 20, 12], [-12, 14, 20, -6], [20, -12, 6, 16], [8, 10, -9, 17], [10, 2, -8, -5], [-24, -7, -10, -7], [-12, -2, 24, 14], [0, -1, -30, -13], [0, -11, -22, 1], [-16, -8, 8, -12], [-4, -6, 1, -3], [-2, 22, -7, -8], [-8, 16, -1, 5], [-14, -4, 4, -11], [-28, 10, -32, -10], [-20, -6, 8, 18], [-24, 9, 8, -7], [-22, 6, 1, 18], [2, 16, 16, 24], [2, 20, 18, 0], [14, 0, 20, 27], [34, -22, -11, -2], [-8, -19, -6, -27], [-24, 6, 11, -15], [-14, 24, 0, 5], [-8, 18, -11, -1], [-24, 13, 16, 5], [-14, -6, -9, 12], [-28, 4, 12, -16], [-20, 8, -16, 18], [32, -2, 11, 21], [8, -7, 38, 13], [-12, 6, -16, 6], [-8, 18, -1, 5], [-14, -12, -12, -11], [26, -14, -11, -18], [14, 32, 12, -20], [56, 8, -4, 2], [4, -26, 20, 14], [48, 11, 10, -13], [-8, -24, 28, 0], [30, -6, 1, -10], [-14, -8, -4, -4], [8, 4, 28, 10], [8, 5, -16, 13], [12, 16, 24, 0], [2, 4, -26, 8], [-4, -4, 7, -33], [10, 12, -16, 9], [4, 0, -16, -16], [48, 1, 8, -15], [0, -25, -6, -13], [-32, 0, -24, 4], [16, 10, 25, -1], [-14, 14, -36, -9], [-30, 2, 5, -16], [16, -3, -24, -3], [-32, 4, -4, -6], [-46, 16, 20, 0], [0, -7, 18, 13], [-20, -10, 22, 2], [12, 14, 23, -9], [-24, 7, -6, -21], [-26, -6, 12, -3], [30, 28, -32, 4], [16, 1, -14, -7], [48, -4, 0, -10], [-22, -24, -12, 13], [30, -2, 35, 12], [-44, -2, -32, 14], [28, -4, -12, 12], [6, 16, 20, 0], [20, 6, -13, 7], [12, 6, 24, -18], [24, -7, -2, 9], [-24, 12, -8, -10], [-20, 6, 4, 14], [-50, -14, 0, 5], [88, -3, 2, 5], [-24, -11, -18, 29], [-12, 10, 17, -11], [-30, -6, -15, -6], [-64, -3, 2, 9], [30, 12, -36, 11], [0, 5, 18, 1], [-28, 16, 17, 1], [6, -18, 28, 9], [-10, -14, -7, -20], [-8, 9, 42, -7], [40, -15, 14, 17], [-16, 13, 8, 5], [26, 0, -10, 12], [48, -4, 1, 7], [-24, 25, 24, 1], [40, 5, 10, 17], [18, -20, 26, 16], [4, -4, -1, -1], [16, -8, -12, 14], [-30, 8, -8, -15], [-32, 9, -42, -11], [-12, 24, 12, -10], [-32, 4, -11, -25], [-30, -22, -11, 6], [0, 8, -32, -8], [56, 9, 4, -15], [-12, 12, -6, -16], [68, 0, 7, -5], [-16, -5, 20, -5], [-30, -8, -28, 20], [-24, 3, -10, -9], [52, 4, 16, 0], [-20, 2, -6, 14], [4, -32, -16, 16], [-8, 7, 30, -1], [12, -20, 8, 10], [50, 2, -9, 6], [-24, -15, 2, -15], [18, -28, -6, 16], [-42, -14, 17, -6], [8, 19, 10, 7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9216_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9216_2_a_bl();".
// 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_9216_2_a_bl(:prec:=4)
    chi := MakeCharacter_9216_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(3067) - 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_9216_2_a_bl();".
// 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_9216_2_a_bl( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9216_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 16, -12, 0, 1]>,<7,R![-8, 0, 16, -8, 1]>,<11,R![32, 0, -16, 0, 1]>,<13,R![-188, -176, -12, 8, 1]>,<17,R![-32, 64, -32, 0, 1]>,<19,R![-32, 64, -32, 0, 1]>,<67,R![-7936, -2304, -96, 16, 1]>],Snew);
    return Vf;
end function;