
// Make newform 9610.2.a.j in Magma, downloaded from the LMFDB on 23 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9610_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_9610_2_a_j();".
// 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_9610_2_a_j();".
// 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 := [-3, 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_9610_a();"
function MakeCharacter_9610_a()
    N := 9610;
    order := 1;
    char_gens := [5767, 7691];
    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_9610_a_Hecke(Kf)
    return MakeCharacter_9610_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+1)]];
    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], [-1, 0], [0, 2], [1, -1], [3, 1], [4, 0], [2, -2], [4, 2], [1, 1], [0, 0], [5, -1], [-6, -2], [-5, -1], [0, 2], [7, 1], [2, -2], [3, 7], [-2, -6], [0, 8], [-6, -6], [-14, 2], [3, -1], [6, 4], [4, 0], [-10, 4], [-4, -4], [4, 0], [-12, 2], [8, 0], [2, -8], [2, -6], [0, -12], [-5, 5], [4, 10], [2, 2], [-6, 8], [-6, 2], [0, 10], [-2, 0], [13, -1], [-3, -7], [-2, 0], [2, -8], [-23, -1], [20, 0], [20, -4], [-10, 0], [-10, 2], [5, -11], [4, -12], [6, -2], [-4, -14], [-5, -15], [10, -4], [-6, 12], [9, 5], [2, -2], [15, -7], [10, 0], [6, -2], [0, 10], [-4, 12], [20, 4], [-8, 12], [20, -2], [15, 1], [22, 6], [1, -11], [-32, -2], [6, -6], [-26, 4], [32, 2], [-8, -10], [10, 10], [2, 0], [-21, 3], [-8, -14], [4, -2], [12, 2], [6, 6], [8, -14], [6, -12], [4, 12], [22, 0], [-28, 4], [-12, 10], [-8, 4], [29, 1], [0, -6], [20, 8], [0, 0], [10, 0], [-17, 1], [-7, 7], [-4, -20], [21, 5], [-2, -4], [25, -3], [-4, 10], [-14, 10], [-15, 7], [18, 6], [-12, 10], [-13, 9], [-12, 4], [5, -11], [8, 0], [14, -8], [-22, 4], [12, 0], [-1, 9], [22, -8], [-5, -3], [10, 6], [0, -2], [-37, -5], [-18, 0], [-6, 4], [18, -2], [8, -14], [-16, 12], [-9, -11], [-12, -16], [16, 12], [34, -4], [-11, -11], [12, -8], [16, -12], [-28, -6], [-29, -3], [-6, -16], [6, 8], [15, 17], [-4, -2], [22, -10], [25, -13], [-1, -5], [-3, 23], [-8, -14], [-6, 6], [13, 13], [38, -8], [11, -13], [13, -7], [-26, -12], [-38, 8], [-18, 4], [9, -17], [18, 8], [28, 10], [6, -24], [11, -5], [-12, -22], [4, -8], [24, 4], [-20, -12], [12, 6], [-26, -4], [39, -9], [5, -3], [-24, 4], [26, 8], [-48, 0], [22, -12], [10, -16], [-20, -4], [8, 18], [0, 10], [-21, -11], [19, -3], [11, -21], [30, -12], [8, 24], [-34, -4], [2, -20], [32, 0], [18, -4], [16, -4], [-29, 11], [-8, -12], [27, 5], [-40, -2], [30, -6], [-32, -14], [11, 23], [10, 28], [36, -8], [8, -26], [52, 4], [-14, 18], [-2, -30], [-7, 15], [45, -3], [-4, 12], [-14, 6], [-2, 28], [-24, -6], [30, -12], [12, 18], [8, -14], [-16, 12], [-2, -20], [18, -14], [-56, -4], [29, 11], [22, -4], [-3, -15], [-30, 2], [4, 24], [52, 8], [5, 5], [40, -2], [6, -22], [-24, -4], [6, 6], [-32, -10], [-46, 10], [-30, 12], [-26, -12], [25, 9], [-12, 20], [-6, -10], [28, -4], [18, 10], [-31, -19], [18, 16], [50, -2], [8, -26], [0, -16], [25, -9], [-28, 16], [14, 8], [18, -24], [23, -9], [32, -18], [-54, 8], [30, -4], [23, -7], [16, -12], [-12, -16], [-13, -23], [-28, 26], [-7, 33], [2, -26], [36, -20], [4, -18], [-9, 5], [43, 17], [24, 24], [-4, -26], [-18, -6], [-16, 6], [6, 42], [38, 8], [-4, -24], [-8, 6], [-23, -11], [-18, 0], [-22, 16], [40, 2], [35, 7], [-9, 3], [-22, 0], [68, 0], [-12, -4], [-32, -6], [-26, 0], [0, -20], [8, 10], [14, 16], [35, 11], [34, -18], [24, 20], [-16, 0], [16, 28], [30, -2], [-35, -3], [-18, -16], [9, -21], [-68, -2], [32, 8], [0, 0], [8, -26], [-4, 20], [-6, -34], [-48, -8], [21, 3], [-18, -4], [2, -24], [6, -36], [-12, 20], [-46, 2], [-16, 4], [25, -13], [-39, 21], [-38, 10], [0, -26], [-5, 5], [33, 25], [-28, 0], [-1, 5], [12, -24], [-42, -10], [-7, 3], [52, -8], [1, 5], [20, 18], [2, -14], [-22, 0], [22, -36], [13, -11], [30, -12], [-23, -27], [-24, -36], [-46, 24], [51, 21], [18, -18], [0, -16], [-66, 8], [1, -33], [-4, -16], [24, -6], [-52, 14], [-84, 0], [-28, -26], [50, -14], [-62, -6], [-18, 16], [1, 35], [-56, -2], [-24, 26], [20, -4], [-9, 23], [4, 36], [46, 2], [31, -9], [-10, -8], [-42, -8], [-16, 26], [-7, 39], [48, 8], [-47, -11], [32, 20], [38, -4], [6, -2], [8, -26], [-21, 23], [26, -34], [30, -16], [27, 5], [28, 0], [36, 26], [-16, -30], [28, -6], [-66, 2], [14, 38], [-21, -7], [-12, -16], [-52, 2], [-54, 20], [-6, -24], [-16, -30], [-6, -14], [42, -14], [-6, -30], [-48, 2], [40, -10], [-6, -20], [38, 6], [-30, -26], [-32, -28], [0, 34], [-30, -32], [-39, 11], [-23, 19], [40, -8], [38, 4], [-18, -24], [-16, -32], [-45, -21], [-20, 32], [-74, 12], [18, -22], [37, -21], [52, -24], [8, 8], [25, 19], [61, -15], [28, 22], [-14, -32], [33, -25], [-46, 6], [64, 4], [72, -8], [64, 12], [-70, 6], [-30, -32], [45, -29], [5, 45], [5, -15], [-58, 4], [40, -16], [-24, 36], [-7, -19], [-26, 4], [-14, -24], [-52, 14], [-35, -15], [-61, 13], [2, -18], [68, 14], [-39, -31], [35, -35], [22, -20], [66, -8], [20, 28], [-12, -50], [-28, -16], [76, 4], [-51, -7], [49, -1], [-18, 32], [14, -6], [26, -12], [53, 3], [18, -38], [54, 12], [-71, -5], [50, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9610_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9610_2_a_j();".
// 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_9610_2_a_j(:prec:=2)
    chi := MakeCharacter_9610_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_9610_2_a_j();".
// 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_9610_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9610_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -2, 1]>,<7,R![-12, 0, 1]>,<11,R![-2, -2, 1]>],Snew);
    return Vf;
end function;