
// Make newform 9350.2.a.bq in Magma, downloaded from the LMFDB on 23 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_9350_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_9350_2_a_bq();".
// 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_9350_2_a_bq();".
// 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;
    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_9350_a();"
function MakeCharacter_9350_a()
    N := 9350;
    order := 1;
    char_gens := [8977, 3401, 3301];
    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_9350_a_Hecke( : Kf := Kf)
    return MakeCharacter_9350_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], [1, 1], [0, 0], [0, -1], [1, 0], [3, 0], [1, 0], [-3, 0], [-2, 1], [1, -4], [-7, 2], [0, -6], [-4, 5], [2, -2], [-1, -6], [3, 5], [-3, -7], [-7, 0], [4, 7], [-5, -6], [-3, 1], [-4, -4], [4, 7], [-5, 0], [-3, 2], [-14, -1], [10, 2], [2, 0], [11, 6], [-7, -8], [-15, 1], [6, 5], [2, -4], [0, -11], [12, -2], [-2, 2], [-6, 2], [8, 6], [-2, 6], [10, 1], [6, 12], [6, 2], [-8, -7], [-20, 2], [4, 2], [-1, 2], [6, 8], [-3, -8], [21, 0], [2, 4], [-11, 11], [-4, 5], [10, -2], [-12, 0], [-6, -13], [9, 1], [7, -13], [-18, 7], [-2, -7], [-19, 1], [-17, -8], [-1, 0], [16, -5], [-8, -12], [-12, 12], [-2, -3], [-11, 7], [-21, 1], [9, 12], [-12, -8], [-6, 12], [2, 12], [10, 1], [-8, -10], [-4, -2], [13, -16], [-22, -3], [-10, -11], [0, -1], [15, -7], [18, -12], [8, 12], [-8, 16], [-26, -3], [-6, -4], [-6, -15], [0, 15], [-20, 1], [6, -4], [-5, -18], [18, 11], [19, 11], [-30, 6], [17, -10], [-2, 4], [12, 0], [-2, -9], [-4, 14], [2, 19], [-4, -16], [5, 0], [37, 0], [-10, 3], [-17, 7], [-18, -4], [4, -18], [18, 4], [-12, -7], [-22, -9], [6, 19], [-6, -18], [3, 2], [-17, 8], [-12, 9], [-44, -2], [18, 19], [8, 28], [11, 16], [12, -7], [-15, -6], [-6, -5], [-5, 29], [-14, -5], [-19, -7], [-2, 29], [20, -9], [-7, -7], [3, 8], [5, 0], [0, -24], [11, 18], [4, -21], [5, 32], [17, 3], [8, -6], [17, 5], [-22, 20], [-15, -8], [-6, -16], [-38, 6], [10, 4], [-3, 20], [18, 5], [30, 8], [-10, 27], [-21, 0], [30, 4], [-7, 31], [-3, 17], [-18, 16], [40, -5], [-22, -17], [14, -12], [0, 5], [-15, -9], [-26, 20], [8, 25], [2, 27], [-20, 12], [11, 20], [23, -5], [-2, 35], [-16, 20], [-3, -1], [-16, -25], [-14, 19], [-45, -8], [-42, 6], [-8, -30], [6, 12], [5, -20], [-24, 23], [-5, -1], [-34, 10], [-6, 0], [8, -23], [-26, -16], [43, 13], [-25, -21], [16, -19], [31, 10], [-18, 8], [-12, -2], [-16, 8], [18, 12], [-38, 1], [-16, 13], [-8, 11], [-24, 8], [0, -6], [20, 0], [33, 6], [23, -11], [-38, 9], [-19, -34], [28, -10], [2, 11], [-6, 21], [55, 5], [21, -3], [8, 6], [23, -15], [-6, -22], [31, 7], [-8, 16], [40, -10], [16, -4], [-12, -28], [-26, -27], [-59, 9], [-33, 23], [-26, -19], [-8, -23], [64, -3], [-23, -17], [16, -39], [-27, -15], [19, -9], [38, -18], [13, 3], [-2, 9], [35, -19], [16, 30], [-2, -35], [-10, -44], [4, -18], [-15, 30], [29, -30], [-17, -29], [24, -10], [-5, 43], [22, 8], [-60, 3], [19, -9], [42, -4], [20, 26], [0, 47], [20, 16], [-16, 33], [44, -11], [33, -21], [30, -22], [-30, -8], [-22, 21], [15, 1], [-31, 13], [-2, 4], [60, -1], [24, -4], [-25, 15], [15, -14], [20, -24], [15, 0], [-10, 8], [-21, -8], [15, -6], [-53, -9], [-54, -2], [36, 29], [-36, 1], [32, -9], [-16, 23], [24, 4], [12, -35], [-29, -16], [-20, 16], [-10, -18], [-27, -14], [9, 50], [24, -4], [-1, -15], [8, 48], [-4, 47], [40, -16], [-6, -52], [-31, 2], [-42, -15], [52, -4], [75, -3], [-5, 52], [-4, 4], [35, -26], [26, -10], [12, 17], [-28, -24], [26, -40], [-21, 0], [4, 4], [0, -24], [-29, -9], [-3, 43], [-1, 37], [14, 35], [12, -18], [2, 28], [-57, 16], [38, -27], [-17, -41], [64, 0], [22, -37], [28, -26], [-21, -20], [-25, -9], [-1, 49], [-4, -53], [-40, 34], [-2, 40], [-17, -5], [10, 15], [-33, 2], [24, -2], [18, 12], [-18, -33], [18, -35], [-41, -21], [45, -17], [-5, 45], [64, -16], [18, -32], [7, 53], [-24, 35], [-21, 26], [-24, 33], [8, -28], [31, -31], [13, -6], [-34, -17], [53, -25], [-8, -32], [18, 17], [60, 14], [46, 2], [-30, -12], [-6, 26], [12, -7], [0, 0], [24, -27], [-6, 16], [70, -3], [6, 28], [-27, 15], [-6, 7], [1, -26], [-6, -42], [-12, -22], [62, -2], [28, 26], [-18, 24], [35, -11], [48, -5], [-50, 10], [-12, -54], [-32, 2], [44, 19], [-4, 26], [14, -25], [-40, -30], [-14, 55], [-46, 16], [63, 2], [-34, -29], [24, -6], [20, -32], [80, 4], [10, 20], [-24, -26], [46, 2], [79, 3], [-24, 5], [-49, 29], [20, 21], [-6, -26], [-54, -7], [34, -9], [30, 23], [-22, -27], [29, 1], [-10, 21], [39, -13], [-14, -14], [57, -25], [-32, -6], [30, -4], [-57, 5], [36, -39], [-38, 18], [-30, 10], [-34, -4], [-1, 4], [68, -8], [-40, -16], [20, -38], [-19, 23], [-6, -7], [-10, -30], [4, 42], [-42, -21], [-4, -52], [-32, -25], [-30, 26], [-68, 8], [-22, -18], [23, -19], [-19, 48], [-28, -20], [36, -14], [-21, 13], [30, 28], [-26, -46], [38, -26], [63, -9], [23, -6], [48, -11], [60, 16], [-20, -23], [21, 5], [10, -60], [6, 20], [57, -34], [65, -3], [18, 44], [44, 22], [26, -18], [-15, -36], [-25, -24], [-27, 15], [16, 2], [-72, 9], [-5, 1], [-56, -32], [43, 6], [59, 12], [22, -32], [16, 18], [74, 12], [57, -12], [-26, 11], [-20, -18], [8, -42], [40, 31], [-66, -8], [-54, -3], [-44, -33], [52, -9], [0, 60], [2, -21], [72, -24], [76, -18], [-12, -10], [-38, -7], [-36, -13], [57, 6], [29, -50], [9, 1], [-30, -5], [14, 0], [-78, 1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9350_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9350_2_a_bq();".
// 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_9350_2_a_bq(:prec:=2)
    chi := MakeCharacter_9350_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(3229) - 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_9350_2_a_bq();".
// 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_9350_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -2, 1]>,<7,R![-2, 0, 1]>,<13,R![-3, 1]>,<19,R![3, 1]>],Snew);
    return Vf;
end function;