
// Make newform 8730.2.a.q in Magma, downloaded from the LMFDB on 27 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_8730_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_8730_2_a_q();".
// 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_8730_2_a_q();".
// 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 := [-6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_8730_a();"
function MakeCharacter_8730_a()
    N := 8730;
    order := 1;
    char_gens := [3881, 1747, 3691];
    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_8730_a_Hecke( : Kf := Kf)
    return MakeCharacter_8730_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], [-1, 0], [-2, 0], [2, 0], [2, 1], [2, 1], [-6, 1], [2, 3], [2, 2], [2, 0], [-2, 3], [2, -1], [-4, 2], [0, 2], [0, -4], [6, -2], [-2, 0], [-2, 1], [10, 1], [0, -4], [2, -4], [2, -4], [-6, 2], [-1, 0], [0, 4], [4, 0], [2, -2], [6, 2], [-2, 6], [-18, 0], [14, 0], [2, -3], [-14, -3], [6, -4], [8, 4], [-2, -5], [0, 4], [-4, 0], [-6, 4], [10, -6], [-10, 1], [16, -2], [2, -4], [-14, 0], [-2, -2], [10, 7], [14, 0], [2, 8], [6, 4], [-18, -1], [-2, 11], [0, 8], [6, 4], [6, -1], [-10, -9], [6, 0], [22, -2], [6, -7], [10, -5], [20, 0], [-10, 0], [12, 6], [6, 1], [10, -4], [-10, -2], [10, -9], [-10, -10], [14, -2], [22, 3], [-6, -2], [10, 5], [2, 10], [-2, -7], [12, -4], [-18, -1], [14, 8], [2, 6], [30, -3], [-34, 0], [16, -8], [10, -4], [8, 0], [22, -6], [10, 0], [-6, 6], [10, -12], [-2, 4], [12, -8], [-10, 0], [22, 0], [-12, -4], [-30, 4], [-12, -8], [-6, -5], [-12, 0], [-24, 4], [-10, 12], [14, -7], [18, -5], [-8, -14], [-14, 0], [-6, -2], [14, -3], [-12, 2], [18, 4], [-22, 0], [-22, 8], [-30, -1], [10, 0], [-8, 0], [14, 8], [2, 10], [10, 3], [12, -8], [-6, 7], [4, 14], [0, -8], [6, -8], [-26, -2], [-2, -2], [16, 8], [4, -8], [-8, -8], [28, -2], [-18, -8], [-10, -5], [22, 1], [-2, 4], [22, 6], [26, -7], [-4, 14], [-20, -8], [-14, -1], [6, 9], [-10, 2], [0, 8], [-20, -12], [-2, 20], [6, 4], [4, 16], [18, -6], [20, 12], [38, 0], [14, -14], [18, -5], [-26, 5], [6, -18], [-26, 7], [42, -3], [-22, 14], [6, -10], [34, -3], [22, -5], [6, -1], [22, 15], [-2, -2], [42, 5], [-20, -12], [-6, 8], [18, -10], [2, -23], [-42, 0], [42, 8], [30, -3], [-10, -3], [-6, 18], [18, 0], [-10, 8], [38, 8], [32, 0], [-22, -9], [32, 4], [6, -2], [-26, -6], [-2, -10], [8, -20], [30, 8], [18, -8], [-14, 10], [6, 0], [-12, 8], [2, 7], [14, 17], [28, -2], [38, 0], [22, -6], [14, -9], [8, -8], [-30, -1], [-28, 0], [18, 12], [-38, -5], [-10, -20], [-22, 6], [-2, 9], [14, 0], [-10, 4], [10, -16], [18, -3], [0, 20], [18, 14], [-6, 2], [40, 0], [32, -12], [-2, 20], [14, 12], [-40, 8], [-18, -3], [2, 1], [-8, 20], [-30, -12], [-10, -4], [18, 0], [14, -1], [-2, 18], [-18, -16], [-34, -6], [12, -10], [-10, -16], [-34, 1], [-26, -12], [-2, 3], [-8, 0], [-34, -4], [-38, 3], [18, 2], [-36, 0], [-16, 0], [28, 8], [-26, -16], [20, 8], [-46, -12], [-18, 5], [22, -17], [-20, -8], [-30, 12], [42, -8], [-2, -4], [-2, -5], [26, 0], [22, -11], [44, -8], [2, -22], [6, -6], [18, 7], [18, -6], [10, -22], [16, 10], [24, 8], [-54, 5], [6, -18], [-30, -13], [-22, -2], [4, 20], [6, 26], [-58, -7], [-36, 14], [-24, 20], [12, 12], [-34, 0], [30, 8], [50, -9], [10, -4], [-14, -20], [-40, 0], [22, 0], [30, 2], [14, 11], [-50, 0], [30, -13], [4, -2], [10, 10], [-10, 16], [20, -12], [-14, 8], [30, 12], [18, -4], [18, 8], [10, 28], [-38, -7], [52, 0], [36, 14], [-42, 10], [-12, 22], [42, -13], [18, 20], [-18, -4], [50, 12], [-50, 1], [42, -8], [-26, -12], [-34, 0], [18, 12], [-38, 3], [-20, 16], [-20, 20], [10, -28], [-18, 8], [-40, -6], [-52, -4], [-54, 12], [14, 10], [-58, 4], [-34, -11], [14, -4], [-10, 4], [-6, -10], [-40, 2], [-46, 2], [-10, 9], [-22, -12], [10, 30], [46, -3], [56, -14], [62, 6], [44, -4], [-22, 9], [14, -18], [-30, -1], [60, -2], [-36, 16], [18, 14], [6, 16], [54, -3], [4, -4], [34, 5], [-22, -27], [-40, 18], [30, 24], [-2, 1], [-40, -8], [-10, -24], [2, -4], [14, 15], [30, -20], [-22, 25], [34, 11], [-4, 24], [-58, 10], [-14, 22], [-6, 0], [2, -2], [14, -26], [-30, -6], [8, 8], [2, -19], [-26, -21], [6, -23], [-6, -6], [-12, 24], [-50, 0], [22, 12], [-26, 20], [-58, 8], [-18, -28], [22, -3], [-46, -16], [2, 8], [56, -8], [-42, -8], [10, -28], [-68, 6], [78, 0], [-2, -9], [-8, -12], [6, 2], [-10, -10], [-62, 0], [10, -4], [30, -11], [-54, -7], [12, -20], [-2, -28], [-2, -14], [58, 2], [-6, 9], [-14, -28], [30, 1], [62, 16], [14, 16], [38, 1], [10, -22], [58, -5], [22, -23], [-36, -4], [6, 0], [-34, 9], [64, 6], [-18, -11], [6, 4], [34, 16], [-42, -4], [-4, 22], [-14, -7], [-24, 0], [12, -32], [-14, 17], [6, 35], [-14, -32], [30, 20], [-50, -17], [-78, 6], [10, 2], [-48, -12], [56, 4], [-42, -10], [-6, -10], [18, 11], [-60, 4], [50, -16], [-64, -4], [46, 16], [2, 15], [62, 0], [-6, 28], [0, 2], [38, -18], [-34, -17], [-6, 3], [12, -28], [-26, -21], [-18, 1], [-6, -24], [38, -4], [34, -4], [84, 0], [30, 19], [52, 0], [-24, 2], [30, -16], [-12, -20], [8, 18], [72, 14], [-34, -21], [50, 13], [34, 14], [10, 20], [-42, -15], [-2, -32], [22, 14], [10, -3], [-78, -1], [-14, 19], [38, 2], [-66, 14], [-38, 7], [-18, 13], [-58, 12], [6, -13], [-38, 1], [14, -31], [-54, -20], [-18, -18], [-56, 12], [-54, 12], [-26, 35], [-60, -12], [66, -5], [6, -23], [38, -7], [-44, 20], [-36, 4], [-10, -14], [8, -34], [-38, -14], [-30, 20], [18, -4], [-94, 2], [92, 4], [62, -18], [36, 4], [-4, 12], [18, -2], [-54, 16], [2, -26], [-60, 8], [32, -20], [-24, -16], [44, -8], [-10, -16], [34, 8], [52, 16], [10, -4], [10, 10], [-28, 20], [-14, 5], [44, -12], [70, -9], [-10, 30], [6, -12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8730_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8730_2_a_q();".
// 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_8730_2_a_q(:prec:=2)
    chi := MakeCharacter_8730_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(3517) - 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_8730_2_a_q();".
// 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_8730_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8730_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![-2, 1]>,<13,R![-2, -4, 1]>],Snew);
    return Vf;
end function;