
// Make newform 9386.2.a.f in Magma, downloaded from the LMFDB on 16 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_9386_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_9386_2_a_f();".
// 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_9386_2_a_f();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_9386_a();"
function MakeCharacter_9386_a()
    N := 9386;
    order := 1;
    char_gens := [1445, 3251];
    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_9386_a_Hecke( : Kf := Kf)
    return MakeCharacter_9386_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], [3], [-1], [1], [-2], [1], [-3], [0], [-4], [-2], [-4], [-3], [0], [-5], [13], [-12], [10], [-8], [2], [5], [-10], [4], [0], [-6], [-14], [4], [8], [4], [-19], [-2], [-16], [-1], [12], [7], [-18], [9], [-10], [-4], [0], [-20], [9], [0], [10], [16], [9], [-10], [-23], [21], [24], [-15], [-11], [9], [-18], [0], [15], [12], [24], [13], [12], [26], [4], [-7], [-14], [18], [-1], [18], [4], [-23], [-9], [7], [4], [24], [-10], [4], [-16], [-27], [-30], [-22], [-24], [-4], [21], [5], [-33], [-7], [22], [-39], [26], [10], [-21], [16], [20], [-3], [16], [-5], [-32], [-14], [-34], [-39], [36], [17], [-37], [33], [-11], [-31], [33], [18], [-28], [-22], [2], [35], [-6], [26], [16], [4], [-5], [2], [14], [-38], [24], [12], [10], [-37], [36], [44], [-8], [-12], [38], [-22], [-14], [-43], [12], [47], [-24], [-12], [6], [0], [-11], [-32], [42], [-9], [28], [-25], [54], [-30], [38], [-56], [49], [-46], [20], [11], [39], [21], [-47], [8], [9], [54], [24], [-36], [-42], [-25], [-18], [-23], [23], [15], [30], [31], [30], [-10], [-2], [-22], [-54], [-21], [-32], [40], [-18], [7], [44], [-2], [-28], [20], [24], [-28], [26], [22], [-44], [46], [2], [-18], [4], [-24], [-13], [-12], [11], [-62], [-23], [-18], [-16], [-32], [-28], [34], [9], [28], [-41], [-25], [-56], [18], [55], [60], [-54], [3], [38], [42], [44], [-34], [-39], [8], [-44], [-53], [-52], [9], [-52], [49], [60], [31], [-21], [2], [1], [72], [50], [-18], [-2], [-4], [-72], [-19], [-7], [-31], [-50], [-11], [72], [70], [30], [-29], [-24], [-17], [-14], [48], [35], [-4], [-26], [-54], [-61], [-22], [19], [49], [4], [10], [12], [10], [0], [34], [44], [33], [53], [-70], [-24], [-55], [5], [-28], [12], [12], [8], [2], [18], [-4], [-14], [48], [38], [30], [-52], [69], [-32], [75], [-70], [-14], [-36], [10], [-79], [19], [-31], [70], [12], [11], [-24], [-14], [26], [60], [-6], [-28], [-13], [14], [-1], [-59], [-30], [-44], [-11], [40], [-19], [84], [52], [-60], [48], [5], [81], [44], [23], [-53], [-42], [16], [56], [86], [52], [-32], [0], [61], [-16], [-34], [74], [-48], [32], [44], [10], [16], [-28], [-24], [-16], [56], [-2], [-20], [0], [62], [9], [51], [-7], [-58], [67], [89], [46], [-80], [49], [6], [50], [2], [-33], [-32], [-66], [-42], [27], [-66], [3], [33], [-26], [6], [-26], [4], [-52], [95], [21], [-40], [-9], [-51], [-13], [17], [-30], [-24], [-18], [-18], [-54], [-52], [-22], [-70], [-18], [86], [-12], [82], [56], [3], [-51], [32], [-46], [28], [54], [-13], [54], [-1], [39], [23], [45], [91], [12], [75], [29], [-46], [53], [8], [3], [-22], [-23], [-72], [-46], [48], [71], [-18], [103], [-53], [65], [-36], [-87], [-88], [42], [-6], [-68], [50], [72], [-21], [28], [-46], [25], [72], [88], [46]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9386_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9386_2_a_f();".
// 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_9386_2_a_f(:prec:=1)
    chi := MakeCharacter_9386_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_9386_2_a_f();".
// 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_9386_2_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9386_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>,<5,R![1, 1]>,<7,R![-1, 1]>,<29,R![2, 1]>],Snew);
    return Vf;
end function;