
// Make newform 9747.2.a.v in Magma, downloaded from the LMFDB on 21 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_9747_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_9747_2_a_v();".
// 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_9747_2_a_v();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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_9747_a();"
function MakeCharacter_9747_a()
    N := 9747;
    order := 1;
    char_gens := [6860, 2890];
    v := [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_9747_a_Hecke( : Kf := Kf)
    return MakeCharacter_9747_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, 1, 0], [0, 0, 0], [1, 0, 1], [-3, 1, -1], [3, -1, -1], [3, 0, -1], [1, 4, -4], [0, 0, 0], [-1, 1, 0], [-2, -3, 1], [0, -3, 5], [9, 2, -2], [-7, 0, -1], [-6, -2, -1], [2, 1, 3], [-2, -3, 4], [-1, 1, -3], [-3, -3, 4], [3, 1, 0], [-1, 1, 6], [-6, 1, -4], [0, -7, -2], [0, 3, 0], [-11, 5, 0], [1, -7, 8], [5, -2, 6], [0, -3, -1], [-3, 6, 3], [7, -1, 5], [-3, -1, -4], [10, -4, 2], [1, 5, 6], [-1, -13, 4], [-12, 4, 5], [-11, -3, 4], [-5, 0, -3], [0, -9, 1], [9, 5, 0], [-5, -3, -8], [-1, 12, -7], [-3, 3, -6], [7, -1, -7], [0, -5, 4], [0, 9, -10], [-18, -5, 4], [-6, -12, 7], [3, -12, -1], [-9, 0, -7], [12, 15, -9], [-12, 0, 4], [-17, 5, -12], [6, -2, 4], [9, 1, 0], [11, -5, 3], [-14, -4, 3], [-5, -10, 6], [5, 0, 8], [-7, -2, 4], [-16, 6, 0], [-14, -14, 5], [-4, 1, -5], [12, -5, 1], [4, 2, -1], [6, -1, -1], [-22, -5, 7], [-5, 1, 8], [-3, 2, -11], [-12, 14, 4], [-2, 12, 1], [-3, -5, -4], [-24, 6, -12], [-5, 6, 7], [9, 5, 3], [16, -3, -9], [6, 9, -7], [8, -10, 1], [11, 16, -3], [0, -1, -9], [-16, -7, 13], [-8, -1, -4], [-18, -13, 14], [7, -7, 17], [-20, -3, -8], [-3, -6, 8], [9, 7, 6], [-1, 5, -17], [-9, -5, 4], [15, -10, 15], [-14, -16, 3], [-9, 5, 9], [3, -15, -3], [-4, -5, 9], [-5, 18, -3], [4, -17, -4], [-18, 11, -21], [14, 18, -16], [1, 16, -16], [0, 5, 2], [24, 4, -3], [-9, 1, -13], [6, -16, 16], [-28, 3, -4], [18, -2, -8], [-3, -12, 9], [15, 7, -16], [17, 9, -3], [13, -13, 3], [5, -14, 6], [-23, -5, 2], [-3, 11, -11], [-3, 23, -5], [5, 13, -14], [2, 5, 19], [9, 3, -17], [-15, 11, -3], [-19, 2, 13], [3, -12, -2], [6, -19, 5], [-3, 15, 9], [19, 4, -7], [25, 2, 8], [6, 17, -5], [3, 8, -10], [9, 7, 7], [-31, -15, 9], [-14, 18, -14], [15, -5, 20], [13, 2, -15], [-3, 20, -12], [8, -6, 15], [6, -6, 16], [8, -15, 23], [9, -9, 23], [-9, -4, 6], [-3, -14, 4], [-6, 0, 1], [16, -9, -2], [6, -5, 24], [-27, 13, 4], [33, 7, -5], [4, 8, -4], [-4, -3, -22], [-19, 7, -5], [-5, 15, -26], [-3, 17, 13], [-28, -6, 2], [42, -6, 13], [-25, 11, -26], [18, 1, -16], [9, 19, 1], [9, 8, -2], [-30, 1, 7], [-3, 1, 11], [13, -15, 25], [-2, 14, -28], [-18, 4, 4], [-15, 3, 1], [-8, 8, -3], [-21, 10, -28], [25, 23, -9], [-8, 23, -30], [5, 7, -18], [-9, 21, -2], [-7, 2, -11], [-30, 6, 3], [2, 15, 2], [24, 0, 2], [3, -20, -13], [-8, 5, -34], [8, 26, -23], [3, 24, -27], [3, -7, 10], [-32, 4, -16], [-24, -19, 3], [18, 1, 15], [-22, -2, 9], [-15, 0, -23], [-5, 34, -13], [-12, 2, -11], [24, -15, -5], [8, -14, 28], [-6, 16, 10], [21, -9, -1], [-1, -17, 6], [9, 1, 16], [6, 14, -28], [4, 8, 2], [12, 20, -14], [10, 24, -9], [-24, -10, -4], [-30, -1, -17], [17, -7, 28], [12, 13, 3], [-16, -17, 12], [-22, -7, -2], [31, 6, 1], [-4, 19, -26], [15, 3, 1], [-33, 16, -17], [-33, -20, 13], [-5, -3, -17], [-32, 5, 2], [15, -7, 7], [18, -20, -18], [10, 3, 16], [-7, -16, 16], [-28, 1, -17], [-2, 37, -22], [-11, 35, -9], [15, -12, 26], [27, 2, 15], [11, 5, -5], [0, -39, 25], [1, -2, -7], [-3, -3, 9], [-18, -35, 15], [-22, 13, -8], [-33, -19, 17], [-12, 5, 20], [-29, 17, -6], [-21, -13, -5], [-15, 19, -24], [-1, 24, -31], [-18, -23, 32], [-43, -11, 0], [27, 5, 18], [0, 2, 2], [-16, 15, 17], [-20, -16, 20], [15, -23, 43], [3, 4, 35], [0, -1, 7], [28, -9, -9], [9, 26, 5], [11, 12, 18], [1, -38, 44], [-15, 13, -19], [-15, 32, -4], [19, -19, -6], [-32, 19, -7], [11, -28, -23], [-10, -12, 21], [15, 36, -17], [-9, 5, -32], [-13, 1, -9], [33, 13, -14], [-31, -26, 22], [4, -20, -22], [48, -12, 8], [8, -10, -20], [-33, 13, 8], [13, 21, -11], [3, -29, 40], [22, 2, 20], [-47, 5, -12], [35, 23, -14], [-6, 5, 24], [9, -9, 44], [2, -19, 40], [-51, 1, -7], [6, 12, -22], [11, -32, -9], [-6, 17, -12], [15, 19, -15], [5, 2, 13], [-18, 22, 0], [-27, 13, -11], [9, 5, 32], [-15, -5, -18], [-25, 12, 17], [-9, 37, 6], [1, 33, -9], [5, 25, -29], [-19, 9, -12], [9, -20, 12], [-18, -5, 29], [33, 24, -30], [15, 1, 0], [-9, 6, 5], [2, 43, -36], [-12, -34, 26], [47, -3, -6], [-40, 12, -40], [-3, 7, 9], [-7, 37, -41], [-7, 33, -28], [39, -2, -7], [31, 8, -9], [15, 6, -29], [33, -23, -5], [-6, -22, -22], [63, -10, -1], [31, -27, 19], [3, -29, 34], [-24, 35, 1], [12, 39, -6], [22, -1, -25], [16, -6, -5], [-34, -3, -4], [27, -25, 12], [-19, 25, -29], [-13, -33, -7], [30, 8, 6], [12, -19, 35], [0, 21, -11], [6, 42, -10], [-2, 44, -42], [-15, -25, 13], [23, 35, -32], [-36, 16, -4], [18, -4, -13], [22, 16, -25], [4, -8, 17], [24, -9, -19], [-26, -2, 32], [10, 9, -6], [17, -29, 63], [23, -38, 18], [-18, 34, -22], [-30, 0, 12], [-39, 21, 8], [-12, 10, -13], [13, 57, -32], [21, -14, 3], [-13, 32, -5], [21, 9, 14], [-12, -1, 13], [-3, -34, 13], [-1, 4, 6], [14, -32, -9], [-3, 26, -21], [29, 19, -30], [-1, 13, 13], [18, -4, -7], [23, -38, 4], [14, 15, 14], [3, 25, 18], [-54, -5, -2], [-36, 11, 3], [63, 22, -13], [31, -22, -1], [-2, -2, -1], [-20, 17, -42], [19, 0, -36], [16, -18, 49], [-22, -11, 21], [-1, -2, 22], [16, 17, -13], [-7, -41, 39], [-33, -5, 19], [-24, 25, -18], [18, -37, 1], [-10, -35, 15], [55, 3, -6], [1, -16, 8], [-18, -14, 16], [58, 8, 0], [-11, -34, 9], [-7, -4, 16], [1, -26, 23], [-19, 1, -8], [-1, -4, 22], [28, 24, -14], [0, -27, 39], [29, -17, 49], [-8, -10, -16], [9, -6, -9], [12, 18, -40], [27, 28, -9], [68, -2, 12], [-27, 14, -17], [1, 37, -37], [-1, -29, 36], [-39, -47, 23], [24, 62, -36], [32, 1, 30], [0, 25, -38], [-37, -29, -5], [8, 53, -29], [60, 19, -12], [18, -29, 55], [-21, -53, 34], [-25, -56, 31], [52, -27, -14], [9, -10, 28], [-19, -15, -10], [30, -22, 60], [-49, 10, 4], [11, 28, -23], [0, -3, 21], [-3, -41, 3], [-28, -19, 13], [-12, -1, -7], [9, -4, 15], [-59, 0, -17], [19, -25, -13], [-51, -24, -4], [-45, 13, -14], [12, 12, 32], [4, 3, 1], [-6, 0, -55], [22, -29, 44], [19, 27, -18], [-1, -43, -11], [-32, -16, 33], [-15, 15, -8], [-51, 25, 20], [-6, -31, 5], [-8, -19, -25], [6, -6, -30], [12, -28, -20], [56, 2, 4], [-45, -19, 17], [51, 0, 4], [-13, -3, -33], [42, -7, 38], [-23, -29, -1], [-35, 15, 15], [-1, -1, 43], [16, -34, -18], [11, 10, -21], [-18, 44, -11], [-9, 30, -30], [-65, 3, -11], [-51, -12, 11], [18, -53, -5], [-39, 3, -3], [-41, -27, 1], [33, -26, 2], [-77, 2, -9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9747_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9747_2_a_v();".
// 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_9747_2_a_v(:prec:=3)
    chi := MakeCharacter_9747_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(2999) - 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_9747_2_a_v();".
// 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_9747_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9747_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, 0, 3, 1]>,<5,R![3, 0, -3, 1]>,<7,R![19, 24, 9, 1]>,<13,R![-19, 24, -9, 1]>],Snew);
    return Vf;
end function;