
// Make newform 8330.2.a.cf in Magma, downloaded from the LMFDB on 16 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8330_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_8330_2_a_cf();".
// 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_8330_2_a_cf();".
// 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 := [14, 8, -7, -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, -1, 1, 0], [0, -4, -1, 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_8330_a();"
function MakeCharacter_8330_a()
    N := 8330;
    order := 1;
    char_gens := [1667, 2551, 2451];
    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_8330_a_Hecke( : Kf := Kf)
    return MakeCharacter_8330_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 := [[1, 0, 0, 0], [0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [-1, 2, 0, -1], [-3, 0, -1, 1], [-1, 0, 0, 0], [-1, -1, 0, 1], [-3, 1, 0, 1], [0, 0, -1, -1], [0, 0, -1, -1], [-3, 1, 1, -2], [-1, -1, -2, 1], [-2, -2, 0, 2], [-3, -1, 5, -2], [-1, 0, 7, -1], [4, 0, -2, -2], [-2, 0, -3, 1], [0, -2, 2, 2], [0, 1, -3, 3], [-4, 0, -1, -1], [-2, 3, 4, 0], [-4, 2, -5, 1], [-2, -1, 3, 0], [-6, 2, 2, 0], [-4, 0, 3, 3], [-6, 0, 4, -2], [-8, 1, 1, -1], [0, 0, -2, -2], [-4, 0, -8, 0], [5, -1, 1, 2], [3, -3, -1, 0], [2, -5, -7, 2], [2, 3, 3, 1], [4, 3, -2, 1], [4, 0, 5, -1], [-5, 6, -1, -3], [2, 2, 3, -3], [-7, 4, -9, -2], [-11, 1, 1, 2], [1, -5, 4, -1], [0, 2, 11, -3], [10, 0, 5, 1], [-4, 0, -4, -4], [3, 1, -1, 0], [-4, 3, 0, 2], [-3, -5, -3, 4], [10, 2, 4, -2], [8, 3, -5, -1], [0, -2, 0, 6], [-2, -8, -1, 3], [6, -6, -2, -4], [-19, 1, 0, -3], [-1, 3, -2, 3], [4, 1, -4, 3], [-6, 4, -10, 0], [2, -2, 13, -1], [-10, -4, -9, 3], [-10, -6, 2, 0], [-1, -2, 16, -2], [0, -11, -8, 4], [-9, -6, 3, 1], [-18, 4, 2, 0], [0, -3, 1, -1], [-8, 0, 9, -7], [-4, -8, -2, 2], [11, -3, 4, 1], [22, -6, 4, 6], [-10, -6, 9, -5], [-10, 4, 2, -2], [12, -13, 4, 3], [6, -2, 2, 4], [5, 2, 5, 0], [20, -7, 3, 2], [11, 0, -2, 3], [-5, -9, -9, 6], [6, -1, -6, 3], [0, 4, -10, 2], [3, -3, 8, -3], [2, 7, -13, 2], [-7, 4, -8, 1], [10, 6, 1, -1], [-8, 1, 10, 2], [-14, -2, 5, -5], [2, -5, -3, 1], [-8, -12, -2, 2], [3, -9, -8, 7], [-4, -8, -13, 3], [8, -5, -1, -2], [11, 1, 3, -10], [-2, 10, 3, -5], [-16, 12, -5, -5], [-6, 5, 11, 1], [0, -6, -14, 6], [-14, 9, -1, -9], [12, -9, -9, -3], [-6, -6, -5, 5], [19, -13, 6, 5], [20, -6, -9, -3], [-2, -8, -5, -1], [-4, 5, -9, -1], [-25, 2, 5, 1], [18, 6, 6, -4], [29, -8, 0, 4], [22, -12, -10, -2], [-6, 3, 17, -6], [4, -4, 5, 7], [-22, -3, 5, 2], [0, -2, -11, 7], [0, 6, -12, -2], [-29, 2, -1, 0], [-13, -10, -5, 5], [-10, 6, 1, -5], [-1, 2, 10, -1], [-6, -4, 5, -3], [-27, 5, 2, -5], [4, -5, 0, -2], [17, 5, -19, 6], [15, -1, -9, -6], [4, -4, 14, 6], [-20, 12, 7, 3], [-10, 2, 11, -3], [1, 3, -3, -8], [-28, 5, 3, 3], [4, 2, 14, -8], [-12, 5, -13, 2], [-10, 0, 2, -10], [4, -11, -9, 7], [-19, 13, 3, -4], [-5, 4, -9, -1], [35, 1, -2, -1], [-11, 8, -7, -4], [2, 1, -2, 0], [-10, 13, -1, -2], [5, 6, -2, -6], [-15, 2, 4, 8], [-13, 4, -5, 9], [2, 4, -4, 8], [10, 5, 15, -4], [11, -21, -2, 5], [9, 2, -10, 1], [0, -6, -1, -7], [4, -5, -5, 13], [16, 5, -6, -4], [-16, 9, -5, -8], [-10, 14, -5, 1], [23, 5, 9, -2], [18, 0, 1, 1], [-8, 6, 8, -16], [-13, 3, 1, -12], [5, 3, -17, 6], [-3, 3, -14, -3], [32, -6, 1, -1], [-2, 11, -11, 3], [-14, 12, -4, 4], [-6, 4, 6, 2], [18, -8, 4, 10], [-11, 9, 6, 7], [4, 12, 21, -7], [12, 10, 10, 0], [-6, 7, -1, -5], [-14, 15, 5, 2], [-26, 0, 14, -4], [7, -1, 14, -5], [-20, 16, -1, -9], [-13, 6, 21, 4], [20, 1, -3, 1], [16, -18, 0, 2], [-5, -17, -4, 3], [9, -11, 11, 4], [12, -8, -6, 2], [2, -7, 8, 11], [16, 9, 14, -4], [24, 9, -13, 2], [34, -8, 15, 3], [-2, 18, -10, 4], [-31, 14, -14, -11], [-12, -12, -5, 3], [5, -9, 3, 0], [-14, 5, 5, 8], [-21, 17, 5, -4], [-5, 5, -9, 8], [-31, 11, 1, 0], [14, -13, -4, 3], [-5, 11, 15, -2], [-8, -7, -13, 2], [-5, 7, 23, 2], [22, -2, -20, 6], [3, -9, 0, 15], [4, -5, 4, -4], [-8, 8, -7, 9], [8, 13, 22, -6], [13, -9, 18, 1], [6, 1, -15, 12], [6, 11, 29, -7], [18, 2, -12, 2], [1, 7, -22, 1], [-8, 4, -10, 6], [-20, -8, 16, -4], [-6, 0, -16, -2], [26, -6, -21, -7], [14, -11, -17, -1], [20, -19, 3, 0], [-31, 3, -1, -2], [8, 0, 22, -6], [-21, 11, 12, -5], [4, -4, -6, 6], [4, 0, -17, 1], [13, -17, -20, 3], [-37, -5, -18, 3], [8, 2, -2, -4], [12, -10, 0, -10], [-20, 2, 8, 14], [30, 8, -12, -2], [-22, -1, -4, 6], [1, 15, 2, 1], [3, -1, -33, -6], [13, 6, 16, -10], [-15, -2, -23, -2], [-9, -6, -19, 9], [-30, 13, 16, 9], [24, -1, -8, 0], [29, -17, 13, 8], [9, -16, -15, 4], [-8, 14, -6, 10], [4, -2, 4, 2], [-34, 10, -6, -8], [-30, 6, 11, -11], [13, -11, -15, 2], [-10, 9, -9, 9], [31, -8, -1, 3], [-11, -10, -14, -1], [-38, 2, -2, 0], [5, 16, 0, -6], [-18, -6, -11, 5], [2, -8, 28, -6], [0, -14, 12, -2], [-41, 9, 15, 4], [-3, 19, 27, -6], [24, 18, -9, 1], [10, -12, 26, 6], [-13, 3, 12, -7], [-6, -24, -24, 10], [0, 19, -5, -8], [-2, 10, -9, -3], [-6, 1, 4, -14], [-5, 18, -3, 0], [-5, 17, 11, -8], [44, 6, 0, 4], [9, 9, -29, 4], [8, -3, -11, -2], [-7, -7, -10, 3], [-19, -11, -11, 10], [7, -3, 0, -15], [4, 3, 33, 2], [13, -7, -10, -3], [-40, 0, 7, 7], [4, -10, -10, 4], [-9, 1, -27, -2], [-2, -8, -6, 18], [23, 3, -12, -9], [-12, -2, 35, 1], [-24, 20, 11, 7], [-4, -12, -2, 2], [14, -8, -7, -3], [1, -11, 6, -11], [-10, 11, 10, -11], [-5, 28, 4, -4], [-2, 9, -11, -9], [-21, -21, -14, 9], [-52, 8, 0, 0], [10, 6, -29, -1], [4, 7, 9, -16], [16, -12, 17, 11], [-2, -13, 20, -9], [5, 5, 19, -12], [-8, 14, -10, 6], [24, 13, 5, 0], [-5, 24, 2, -4], [11, -11, -8, 13], [-15, 11, 7, -16], [32, 2, -8, -2], [-17, -16, -23, 16], [-2, -11, -17, 8], [-22, 0, -2, 14], [-26, 12, -10, -16], [-20, 6, -16, -2], [9, 1, 13, -2], [0, -8, 23, -7], [7, 1, -31, -2], [2, 2, 16, -22], [-8, 27, 20, -10], [-28, 23, 11, 4], [5, -9, 27, -10], [1, -19, -13, 8], [-14, 16, -13, -1], [4, -14, 3, 5], [26, -21, 5, 14], [27, -7, -29, 0], [12, 14, 0, 0], [-44, 10, 12, 6], [21, -2, -17, 19], [56, -3, 14, -2], [-10, 21, 14, -16], [40, -3, 7, -5], [0, 10, -7, 11], [26, -14, 14, 8], [10, 8, 4, -12], [12, 2, -4, 8], [-1, 14, 13, -5], [13, -11, -34, -5], [0, 10, 26, 0], [32, 6, 0, 2], [-2, 0, 13, -15], [-7, -15, -27, 10], [-9, 10, 8, -10], [-7, 9, 24, -1], [-10, -7, 2, 8], [20, -2, 21, -1], [44, -18, 6, 12], [18, 20, 26, -10], [22, -10, -10, 0], [12, -8, -17, -1], [-13, 3, -5, -2], [-24, -8, 25, -7], [-51, 3, -5, -6], [1, -9, -15, 0], [2, -1, -46, 0], [-42, 4, 8, 8], [-4, -2, 0, -2], [6, 18, 17, -5], [4, 2, -16, -14], [2, -2, -19, 7], [36, -18, 25, 11], [-11, -8, 14, 1], [12, -1, 15, -13], [10, -17, 2, -11], [-12, 22, -11, -5], [-31, -1, 20, -5], [-23, -11, 17, 2], [52, -9, -1, 6], [-6, -5, 18, -7], [12, -2, 3, -3], [-8, -4, -21, 13], [36, 1, -3, 8], [44, 11, -11, -1], [28, 14, 18, -12], [36, -4, 7, 1], [18, 3, -5, -9], [-45, 9, 13, -10], [19, -17, 14, 7], [16, -10, -5, 17], [-2, 27, 7, -2], [-41, -13, -4, -1], [-14, -9, -4, 1], [16, -3, -25, 10], [-22, -4, 29, 1], [4, 25, 11, -3], [0, -10, 34, -8], [-8, -14, -6, 10], [-29, 5, -3, 2], [48, -14, 8, 6], [22, 6, 24, -6], [1, -17, -9, -2], [-6, 2, -41, 3], [-28, 7, -31, -4], [-21, 21, 13, -10], [35, -1, -15, -8], [23, 5, 4, 1], [21, 1, -30, -3], [-9, -7, -27, 2], [-40, -1, -19, -1], [-8, 19, -8, 13], [-26, 24, 14, -8], [-4, 2, 22, -4], [-3, -2, -36, 1], [-22, -3, 5, 1], [-6, -11, -15, 4], [-38, 9, 11, 0], [6, 9, 12, -7], [-32, 14, 2, -8], [30, -13, -16, 11], [-21, -9, 40, -17], [4, -24, -23, 17], [23, -23, -19, 10], [-11, 13, 34, -17], [-12, 18, -16, 8], [-11, 13, 26, 3], [26, -1, -21, 7], [10, 18, 14, -8], [-38, 10, 10, 0], [0, -6, 8, -22], [36, 10, 12, -12], [-16, 12, 31, -11], [30, 2, -16, 14], [30, -24, -6, 14], [-38, 10, -6, -8], [-37, 6, -10, 8], [-57, 22, -18, -11], [28, 5, 5, 4], [-38, 4, 17, 1], [10, -17, -9, -8], [-45, 1, 13, -8], [-2, 10, 45, -5], [-6, 7, 5, -12], [-44, 29, -1, -15], [-9, -5, -14, 17], [46, -13, -11, -14], [-18, 10, -41, -9], [43, -11, 21, 10], [-26, 22, -4, 6], [16, -13, -7, -18], [10, -18, -5, -5], [-29, -4, 6, 19], [-32, 19, 14, -15], [-26, 6, -17, -7], [38, -13, 32, 8], [-11, 20, -25, 4], [22, 2, 13, 7], [25, -3, 25, -2], [12, 17, -10, -5], [-29, 33, -5, -12], [-36, -7, -11, 17], [0, -6, -28, 24], [8, 18, 18, 4], [41, 0, -25, 7], [36, 2, -24, 18], [-13, 5, 14, -17], [13, -5, 8, 3], [8, -25, 7, -1], [-18, 5, -29, -2], [-9, 5, -14, -1], [-9, 6, -10, 9], [5, 17, 14, -17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8330_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8330_2_a_cf();".
// 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_8330_2_a_cf(:prec:=4)
    chi := MakeCharacter_8330_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(3023) - 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_8330_2_a_cf();".
// 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_8330_2_a_cf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8330_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![14, -8, -7, 2, 1]>,<11,R![47, -44, -36, 0, 1]>,<13,R![-1, 8, 36, 12, 1]>,<19,R![4, -20, -5, 6, 1]>],Snew);
    return Vf;
end function;