
// Make newform 9522.2.a.bq in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9522_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_9522_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_9522_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 := [-1, 3, 3, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [-2, 0, 1, 0, 0], [0, -3, 0, 1, 0], [2, 0, -4, 0, 1]];
    Rf_basisdens := [1, 1, 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_9522_a();"
function MakeCharacter_9522_a()
    N := 9522;
    order := 1;
    char_gens := [2117, 1063];
    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_9522_a_Hecke(Kf)
    return MakeCharacter_9522_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, 0, 0, 0], [0, 0, 0, 0, 0], [-1, 0, 0, -1, 1], [2, 0, 1, -1, 1], [-2, 0, 2, -1, 0], [-2, 1, -1, 2, -2], [-2, 1, 0, 1, 1], [2, 2, -1, -1, 1], [0, 0, 0, 0, 0], [-1, 1, -4, 2, -5], [1, -5, 3, -4, 1], [2, 1, 0, 0, -1], [3, -3, 3, 0, -1], [2, 0, 4, 1, 3], [6, -4, -1, 1, 4], [-5, 2, -8, 4, -2], [4, -1, 4, -2, -1], [5, -7, 3, -8, 2], [5, -6, -1, -1, 6], [0, 7, -2, 6, -4], [-1, 4, -7, -3, -1], [0, -4, 0, 5, -3], [0, -7, 5, -7, 5], [-1, 0, 0, -3, -4], [-8, 8, -7, 5, -11], [-3, -4, -2, -1, 0], [-9, 7, -8, -1, -6], [-1, -4, -2, -2, 6], [1, 2, 0, 4, 4], [-3, 3, -1, 8, -4], [6, -1, 3, 4, 6], [-8, 11, 3, 4, -3], [-5, 2, 3, -1, 4], [-4, 0, 4, -2, -5], [2, -5, -2, 4, -3], [-8, 4, -3, 0, -9], [-10, 1, -1, 7, -4], [1, -1, 6, 5, 0], [6, 5, -2, -5, -2], [-12, 3, -6, 11, -4], [6, -5, 7, -4, -1], [-6, 1, -6, 11, 0], [-4, 1, 3, 3, -3], [1, -6, 15, 2, 5], [-3, 4, -1, -4, -8], [-2, -6, 1, -8, 5], [-1, 13, -6, 7, -7], [1, -3, 6, -7, -7], [4, -13, 4, -5, 9], [-2, -8, 7, -3, -1], [-7, -3, -1, 15, -6], [5, -8, 3, -10, 10], [-4, 5, 0, -3, 1], [-8, 12, -5, 11, -8], [8, -5, 11, -10, 16], [-15, 9, -7, 8, -13], [8, -14, 3, -12, 3], [21, -7, 10, -13, 8], [-7, 3, -5, 8, -9], [-10, 13, -19, 10, -13], [-13, 7, 3, 5, 2], [-1, 12, -2, 9, -1], [3, -3, 6, 2, -1], [4, -7, 3, -18, 6], [-1, -5, 1, -7, -2], [8, -1, 1, 3, 11], [3, -3, -11, 5, -1], [-5, -1, -9, 7, 7], [9, 8, -1, 4, -3], [-11, -2, -4, -5, 6], [-1, 3, -8, -13, 2], [4, 4, 7, -2, -2], [-11, 9, 0, 14, 2], [-27, 13, -11, 9, -14], [8, -9, 2, 4, -4], [-7, 0, 0, 7, 5], [8, -16, 3, -11, 8], [-10, 14, -14, 12, -15], [-9, 3, 0, -2, -3], [-12, 9, 3, -6, -8], [0, 3, 9, -11, 3], [8, -9, 7, -5, 13], [4, -16, 9, -18, 15], [-10, -8, -6, 8, -6], [-19, 12, -12, 15, -6], [-2, 1, 3, -5, 9], [2, 6, 10, -2, 11], [7, -1, 2, -9, 11], [3, 7, 5, -5, 1], [8, -15, 6, -8, 1], [2, 1, 3, 5, 14], [-8, 4, -13, 16, -3], [3, -5, 12, -8, 24], [2, -8, 6, -3, 10], [-10, 12, 4, 19, -6], [-12, -1, -10, 7, -15], [-14, 17, -11, 3, -6], [-5, 1, -20, 1, -6], [-1, 11, -5, 5, -5], [-9, -2, -16, 4, 3], [0, -11, -1, -10, 2], [-1, 1, 8, -12, -12], [3, -12, 20, -1, 6], [5, -13, 21, 6, 7], [-13, 18, -13, 8, -16], [-15, 18, 0, -6, -1], [21, -9, 16, -7, 13], [9, -11, -11, 1, -7], [9, 3, 7, 5, 0], [-15, 2, -22, 3, 4], [13, -12, 12, -9, 3], [-11, -5, 6, -3, 1], [-22, 8, -20, 2, -6], [-3, 1, 7, 14, 3], [-3, 21, 6, 8, -11], [-10, 7, -1, 16, 9], [-9, -19, 9, 0, -5], [-9, 14, -20, 9, -12], [-4, -4, 4, -13, -18], [-10, -2, -2, -1, 9], [-12, 7, -26, 7, -1], [8, -23, 2, -11, 19], [3, -15, -5, -9, 8], [8, -9, -13, -1, 1], [-8, 9, 1, 8, 1], [-14, 21, -7, 9, -15], [2, -19, 7, -17, -5], [-10, -21, 9, -3, 3], [-5, 4, 1, -15, -4], [-17, 0, 15, 4, 11], [-3, -14, -3, 13, 0], [-13, 5, -16, 13, -11], [-9, -15, -9, 2, 4], [-12, 6, -12, 4, -16], [-14, 7, -14, 2, 7], [-7, 4, 0, 7, 12], [23, -3, 3, -11, 14], [9, -27, 13, -5, 9], [3, -14, 14, -18, 5], [-1, 3, -13, 9, -27], [5, 11, -5, -7, 12], [17, -23, 23, -16, 16], [-9, -1, 0, -4, 3], [-1, -20, 20, -3, 14], [17, -27, 18, -5, 21], [1, 10, -9, -13, 14], [-7, 12, -19, 8, -20], [-9, 12, -15, 17, 10], [6, -13, 3, 13, -16], [-24, 26, -20, 32, -27], [3, -3, -9, -7, -4], [5, -11, -14, 8, -5], [9, 0, 7, -16, -6], [16, -10, 11, -7, 9], [1, 16, -6, 3, -4], [-37, 0, 9, -1, 6], [-3, 13, -10, 9, 16], [7, 13, 0, 8, -20], [9, -14, 14, -8, 24], [11, -11, 15, -5, 20], [7, 1, -6, 2, -1], [19, 3, 15, -12, 0], [12, 7, 7, -9, 9], [-1, -17, 6, -2, 13], [-31, 15, -2, 1, -4], [-14, 1, 10, -11, 15], [-6, 7, -4, 10, -16], [10, -4, 11, -13, 10], [2, -8, -8, -12, -10], [3, 2, 7, -8, 35], [-26, 3, -4, -8, -8], [28, -14, 1, 3, 11], [-10, -12, 19, -12, 6], [8, -12, 6, -14, 12], [16, -21, -3, -1, 5], [-2, -1, -1, 10, 10], [-14, -9, -2, -8, 12], [17, 14, -19, -2, -8], [0, 1, 3, -3, -10], [-2, 1, -9, -7, 11], [11, 9, 3, -5, 4], [-12, -4, -9, -8, 14], [20, 6, -3, 2, -12], [-14, -4, -17, 14, -26], [-27, -1, -13, -1, 3], [2, 5, -4, -6, -16], [14, 16, -5, 4, 23], [6, 4, 10, -25, 21], [4, 3, 14, -20, 5], [-9, -13, -23, 9, 8], [-18, 25, -2, -4, 0], [3, 19, -14, 3, -13], [24, -4, 12, -11, -9], [6, 12, 8, -9, 24], [-27, 15, -21, -10, -15], [-5, -7, 5, 6, -13], [13, 2, 25, -11, 9], [-7, -14, 17, 1, 11], [-8, -4, 12, 3, 14], [5, -21, 43, -14, 23], [18, -7, -8, 8, 15], [-7, -4, 1, 1, 17], [11, 19, -20, 15, 0], [-14, 14, -35, 10, -32], [3, -17, 6, -16, 6], [-4, 19, 4, -9, 1], [29, -21, 19, -14, 19], [-19, -15, -13, 28, -21], [-2, -4, 10, -15, -17], [-5, 21, 6, 10, -11], [-4, -13, 11, -4, -20], [25, -23, 13, -23, 12], [-7, 18, -1, 7, -32], [-30, -8, -3, 0, -7], [7, 5, -7, 10, 6], [19, -1, -7, 12, -17], [16, -7, 14, -26, 27], [-6, -2, -22, 20, 7], [-19, 22, -5, 24, 12], [-19, 8, 16, 7, -7], [13, -25, 18, -8, 3], [-8, -3, 0, 4, 5], [-17, -4, 23, -4, 17], [20, -3, -6, 13, 6], [-1, -24, -17, 1, 14], [-1, 9, 18, -12, -2], [-6, -23, -1, 1, -23], [-10, 13, 6, 18, -4], [-3, -20, 25, -8, 6], [9, 7, -36, 5, -14], [4, 20, -31, 14, -31], [35, 13, 9, -12, 10], [16, 7, 9, -8, -6], [-11, 19, 0, 15, -5], [0, 17, -19, 13, -6], [-37, 21, 8, 19, -5], [23, -19, 17, -4, 13], [21, -2, -16, 0, -10], [-5, -3, 0, -14, 4], [-18, 38, -12, 30, -29], [-25, -24, 11, -8, 14], [18, -2, 5, 14, -9], [-13, -16, -4, 1, 6], [19, 14, -3, -4, -16], [-29, 5, -6, -12, -14], [-39, 15, -2, 22, -5], [-16, 3, -25, 16, -21], [-37, 17, -19, 37, -4], [-10, 30, -8, 32, -33], [-2, -17, 12, -12, -13], [-5, 11, -29, -17, -11], [-6, 11, -27, 9, 5], [-32, 6, -15, 9, -19], [-4, 18, -18, 21, -33], [-34, -15, 5, -2, -7], [-7, 14, -5, -19, 25], [41, -15, -7, 9, 21], [7, -5, -12, 12, -16], [9, 27, 2, 7, -13], [7, 17, 25, -11, 9], [16, -38, 20, -20, 23], [-22, -17, 9, -14, -22], [12, -8, 35, -6, 38], [10, 16, 19, -12, 23], [-8, 19, -27, -11, 4], [20, 16, 16, -7, -4], [22, 20, -8, -1, 18], [-18, 17, 20, 20, -6], [43, -22, 22, -15, 27], [-37, 14, -30, 18, -22], [-9, 7, -25, -17, -14], [32, 26, -4, -6, -2], [16, -26, 27, -20, 4], [10, -1, -21, -2, -2], [8, -36, 18, -24, 25], [7, -7, -1, 3, 10], [28, 8, -4, 0, 6], [-23, 17, -9, 19, -5], [42, -18, 8, -11, 19], [1, 22, -7, -23, 13], [-6, 22, 4, -24, 1], [26, -6, 11, 0, 4], [-29, -4, -2, 12, -5], [17, 2, -8, -2, 2], [-8, 28, -24, 21, -5], [6, 14, 17, -5, 22], [-20, 40, -43, 37, -41], [-5, -11, -11, 1, -14], [-35, -3, -7, 12, -5], [23, 16, 9, 0, 4], [-23, 8, 16, 9, -16], [-8, 25, -20, -9, 0], [-8, -19, 33, -7, -5], [17, -19, 32, -1, 8], [-21, 20, 5, -17, -3], [40, -14, -7, -11, -3], [33, 4, 6, -6, -6], [18, -8, 13, 26, 11], [-39, 10, -14, 14, 14], [43, -27, 37, -41, 28], [-1, -15, 5, -31, -14], [16, 10, -32, 15, -26], [32, -7, 20, -26, 2], [-22, 33, -20, 38, -28], [19, 7, -7, -9, 2], [1, -11, 16, -13, 36], [4, 11, -12, 23, -10], [-1, 3, 8, 22, 21], [8, 2, -15, 17, -46], [-3, 4, -1, 15, 12], [-5, -8, 23, -16, 44], [11, 13, 12, 10, -33], [19, -19, 5, -54, 14], [-5, 8, 32, -6, -6], [-16, 22, -25, 31, -26], [57, -13, 46, -42, 37], [-1, 0, -16, -1, -30], [-15, -8, -3, -3, 2], [10, -9, 22, -3, 16], [-29, -4, -7, 16, -19], [-4, 29, -17, 15, -19], [-23, 17, -10, 20, -21], [27, -27, 6, 10, 5], [-31, 13, -9, 28, -27], [17, -2, 38, -20, 33], [43, 3, -4, -20, -2], [-13, 38, -44, 21, -34], [6, 11, -9, -10, 21], [-4, 18, -9, -5, 18], [48, 0, 9, -16, 15], [23, -10, 26, 0, 9], [3, -26, -4, -3, 28], [-5, 31, -13, 21, -19], [-24, -23, 3, -19, 20], [46, -26, -3, -34, 5], [45, -11, 15, 24, 0], [-6, 52, -17, 20, -24], [59, -3, 19, -17, 25], [-29, 15, -18, 3, -24], [5, -2, 4, 16, -14], [-12, 21, 1, 23, -10], [-41, 4, -1, -3, 32], [-8, 13, -17, 30, -19], [3, 1, 9, 2, 9], [-6, 56, -41, 30, -33], [-32, 52, -27, 31, -46], [-22, 17, -19, 34, -23], [21, -22, 30, 1, 4], [-43, -8, -17, 2, 5], [28, 8, -10, 18, 12], [30, 0, 10, -30, 16], [-28, -7, -25, 30, -23], [44, -5, 9, 19, 20], [-35, 12, -14, 29, -2], [-22, 14, -16, 33, -10], [32, -29, -2, -18, 17], [15, -22, -16, 2, -28], [-7, 6, -9, -5, -33], [26, -27, 36, -13, 32], [-12, 28, -31, 34, -29], [24, -5, -8, -16, 10], [-10, -10, -7, -2, -53], [-8, -5, -15, -1, -22], [47, -27, 26, -34, 22], [15, 14, 3, 27, -4], [18, -8, 6, 2, -40], [10, 17, 17, -5, 12], [14, 3, -21, 16, -24], [23, 10, 21, 14, -13], [41, -26, 12, -40, 13], [-21, 18, -33, 38, -6], [16, 22, -22, 31, 22], [21, 0, 17, -16, 48], [-21, 29, 12, -19, -5], [26, -17, 3, 4, 21], [21, -3, 24, -21, 28], [8, -21, 15, -1, 4], [-15, -12, 5, -39, 1], [38, 9, -13, 19, -23], [-3, -6, -4, -6, -2], [-26, 24, -21, 0, -32], [9, 18, -1, -10, 1], [-29, 13, -13, -38, 5], [24, -8, 26, 5, 34], [-51, 18, -36, 26, -31], [41, -25, 43, 4, 33], [15, -9, 4, 19, -1], [-22, 24, -35, 7, -2], [-19, -4, -8, 0, -27], [-1, 4, 42, -12, -1], [53, -4, 14, 0, -12], [-21, 21, -2, -15, -34], [22, -29, 45, -30, 19], [16, 12, -14, 32, -21], [-20, -14, -28, -3, 28], [33, -11, 28, 9, -7], [-24, -26, 11, -8, 8], [-6, 31, -17, 26, -54], [21, -28, 2, -4, 24], [24, 24, -28, -4, -6], [35, -15, 23, -44, 48], [-5, 9, -46, 4, -33], [-28, -8, -7, 45, -16], [-14, -30, -27, 17, -10], [-30, 4, -28, -1, -1], [11, -2, 1, 0, 11], [15, -34, 20, -2, 25], [10, 34, 5, 8, 12], [-41, 14, 0, -4, -12], [13, -31, 1, -30, 46], [7, 30, -22, 24, 5], [16, -26, 37, -40, 12], [7, -5, 17, -36, -19], [-1, -34, 62, -11, 22], [0, -48, 13, -21, 10], [33, -16, 42, -39, 18], [27, -41, 32, -53, 2], [-39, 35, -24, 12, -22], [3, -33, -4, 19, -13], [48, -18, 4, -10, 17], [18, 17, -6, -36, 12], [-22, 15, -25, -26, 5], [19, -12, 13, -29, 5], [-35, 32, -46, 40, -38], [23, 2, 4, -34, 2], [-50, 37, -24, 29, -44], [17, -8, 23, -33, 7], [22, -8, 48, -31, 23], [45, -23, 23, -16, 26], [-26, 9, 8, 25, -9], [46, -17, 24, -25, 31], [9, 21, -21, 28, -16], [10, -15, 29, -49, -10], [19, 24, -15, 15, 13], [6, 29, -11, 13, -14], [-34, 35, 3, 12, -39], [-4, 0, -35, 17, -41], [4, 12, -4, 36, -35], [21, 21, -24, 15, -14], [-64, 26, -32, 4, -39], [-31, -17, 36, 13, 3], [27, 0, 7, 22, -43], [32, -33, 2, 14, 16], [32, 6, -26, 0, -6], [28, 7, 9, -14, 26], [17, -47, 43, -12, 27], [-13, 37, 13, -20, -15], [-3, -1, -27, -14, -20], [10, 27, -8, -12, -6], [-11, -25, -10, 15, 7], [38, 5, -10, -25, -1], [27, 9, 16, -16, 46], [-37, 2, -1, 7, -14], [-25, 9, 40, 1, 25], [-35, 15, -28, -22, 2], [-5, -1, 6, -13, -11], [25, -8, 9, -25, 10], [-46, 23, -40, 31, -31], [-25, -27, -22, 15, 1], [38, -21, 29, -22, 17], [20, 16, 3, -21, 45], [-33, 0, -13, -34, 30], [62, -9, 32, -33, 35], [-10, -7, 21, -6, 20], [-17, 12, 14, -20, -1], [-32, 18, 6, 26, -28]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9522_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9522_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_9522_2_a_bq(:prec:=5)
    chi := MakeCharacter_9522_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(3313) - 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_9522_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_9522_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9522_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-23, -35, -6, 13, 7, 1]>,<7,R![23, -35, 6, 13, -7, 1]>,<11,R![-1, 15, 53, 50, 13, 1]>,<29,R![-1693, 1164, 413, -75, -7, 1]>],Snew);
    return Vf;
end function;