
// Make newform 9200.2.a.ck in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9200_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_9200_2_a_ck();".
// 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_9200_2_a_ck();".
// 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, -2, -5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-1, -4, 0, 1], [-3, -1, 1, 0], [-1, 5, 1, -1]];
    Rf_basisdens := [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_9200_a();"
function MakeCharacter_9200_a()
    N := 9200;
    order := 1;
    char_gens := [1151, 6901, 2577, 1201];
    v := [1, 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_9200_a_Hecke(Kf)
    return MakeCharacter_9200_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 := [[0, 0, 0, 0], [-1, 1, 0, 0], [0, 0, 0, 0], [-2, 0, -1, 0], [-1, 1, 0, -1], [3, 1, 0, 0], [3, 0, -1, 1], [1, 0, 0, 1], [1, 0, 0, 0], [0, 1, -1, -1], [-2, 1, -3, 1], [2, -2, 1, -2], [-5, 4, -2, 0], [1, -4, 0, 1], [-2, 0, -3, 3], [0, 0, -2, -2], [-1, 1, -1, 1], [-3, 2, 0, -3], [0, 0, -1, 0], [3, 2, -4, 2], [6, -2, 1, 3], [-7, 0, -2, 1], [-3, 6, -3, -1], [-3, 0, -2, 3], [6, 2, -3, 0], [-4, 0, -2, 2], [1, 0, 3, -1], [3, 2, 2, -3], [-1, 2, -2, 1], [-2, 0, -1, 0], [-11, 3, 0, 4], [3, 2, 4, 2], [-10, 4, -2, -2], [13, -4, 2, -2], [2, -2, 4, 0], [0, -1, 1, -3], [3, 4, -4, 3], [7, -1, 0, 2], [11, -3, 1, -3], [3, 1, 5, -1], [4, 5, -3, -1], [-5, 3, 0, 3], [0, -7, 2, 2], [18, -2, -1, -1], [-2, -2, 3, -5], [1, -5, 6, 1], [0, 0, 2, -2], [6, -4, 2, 4], [-6, -2, -3, -4], [17, -2, 4, -5], [4, 4, -1, 1], [8, -7, 1, 3], [-10, 5, 0, 0], [4, 3, 6, -4], [1, 3, 4, 0], [-5, 4, 4, 1], [3, 0, -2, -4], [-10, 8, 0, -6], [11, 3, 0, -4], [5, 1, 4, -1], [1, 4, -1, 1], [-8, 2, -4, 0], [9, 5, 5, 3], [6, -1, 1, 5], [22, -2, 0, -2], [-15, 1, -1, 1], [1, 0, -6, 8], [7, -2, -2, 3], [0, 2, -4, -2], [-7, -4, -4, -4], [8, 4, 3, -3], [1, 0, -6, -3], [1, -4, -5, -5], [-1, 4, -13, 7], [16, 0, 8, 0], [15, 2, -4, 3], [4, 0, -4, 0], [-1, 5, -12, 2], [10, -5, 6, 0], [-9, 0, -2, 6], [-7, 0, -6, -5], [17, -1, 2, 3], [-3, -4, 4, 3], [-1, 8, 3, -5], [9, 0, -4, -4], [10, 0, 7, -7], [13, -1, -5, -5], [1, -6, 1, -1], [-2, -13, 3, -1], [2, 6, 0, -4], [4, 0, 0, 6], [-22, 5, -4, 6], [4, -2, 3, -11], [-9, 4, -2, 0], [-8, 3, -1, -7], [0, 0, 0, 6], [-24, -3, 1, -3], [20, 4, 8, 0], [0, -2, 1, -10], [5, -2, -6, 10], [10, -14, 3, 5], [-17, -4, -8, 7], [10, -8, -2, -6], [18, -11, 0, -4], [-12, -1, 6, 4], [5, 11, -4, 2], [1, 1, -4, -4], [-12, 0, -2, -6], [9, 1, 5, -5], [-16, -5, -13, 3], [1, -5, 1, 1], [7, 2, 13, -7], [9, 0, 0, 7], [6, 0, -4, 14], [21, -14, 2, 3], [5, -8, 2, 7], [9, -10, 11, 5], [-9, 9, 6, 0], [5, -3, 4, 8], [-20, -1, -10, -4], [8, -10, -4, -2], [26, -4, 5, 11], [14, -6, -6, 4], [5, 11, -2, 0], [2, -12, 4, -2], [-19, -5, 2, -1], [5, 3, -6, -5], [4, -10, 10, 4], [-9, 12, -5, -5], [7, -6, -5, 9], [13, 0, 12, -10], [-9, 4, -5, 1], [13, -10, 4, -1], [-8, 2, -1, -8], [3, 4, 2, 0], [-4, -3, -10, 10], [9, -10, 4, -3], [6, -2, -8, 6], [11, 0, 4, -3], [2, 12, 8, 0], [-18, 5, -5, -11], [14, -4, 0, -6], [-3, -9, -10, -2], [-38, 4, -6, 2], [-22, 4, -2, 8], [9, -11, -4, -9], [23, 1, 5, 1], [20, -16, 1, -5], [6, -3, -11, 7], [-15, -11, 10, -2], [5, -13, 1, 1], [-4, 1, -12, 8], [5, -1, 3, 9], [-10, -4, -5, 3], [33, 6, 4, -5], [-35, 12, -6, 5], [-23, 1, 4, -5], [11, -6, 2, 4], [22, 4, 11, -6], [-12, 19, -4, -4], [9, -9, 0, 2], [-10, 4, 2, 0], [9, -13, 10, -10], [-8, -6, 12, -10], [22, 12, 11, -2], [2, -6, 10, -8], [2, -6, 6, 0], [5, -5, -3, 7], [-33, 8, 2, -1], [-18, -8, -1, 3], [-3, -7, -12, 13], [13, 4, -2, 6], [4, 3, 4, -4], [20, 4, 16, -8], [-13, 2, -8, 4], [-9, 1, -6, 1], [-3, 10, -16, 4], [-12, -3, 3, -1], [1, -10, -6, -9], [20, -17, 4, -4], [-5, 13, -8, -2], [1, 2, 4, -1], [16, -18, 9, 3], [37, -5, 1, 3], [-15, -8, -9, -7], [4, -3, 16, -12], [-22, 12, 4, 8], [-9, 8, 4, -15], [11, -12, 8, -10], [24, -4, -8, -2], [17, 5, -4, -2], [-9, 5, 7, -1], [-14, 1, 4, -4], [-24, 6, -6, 0], [-21, 8, 5, 3], [-17, -6, 12, -5], [-5, 1, 2, -17], [-6, -10, 20, -10], [4, -6, -4, -4], [28, 2, 1, 7], [18, 0, 16, 2], [9, 1, 5, -1], [-5, -1, 4, 4], [5, -21, -4, -3], [4, -4, 16, -4], [-22, 14, -1, -3], [7, 11, 6, -5], [2, -10, -3, -5], [-25, 2, -12, -8], [26, 1, -11, -3], [19, -9, 0, 10], [13, -14, -6, 10], [11, -4, 8, 7], [-26, -6, 6, 0], [-17, 9, 9, -1], [11, -10, 10, 13], [-2, 6, -7, 3], [-14, -7, 5, 9], [3, -14, -5, -1], [-23, 13, 2, 6], [48, -15, 5, -1], [-7, -11, -2, -3], [-3, -12, -10, -6], [4, 4, 3, 6], [36, 0, 13, -7], [0, 3, -13, 9], [26, 2, 17, -18], [8, 1, 7, 1], [-16, 12, -14, 14], [-35, -3, 5, -3], [-46, 14, -6, 14], [-1, 9, -2, -3], [6, 15, -6, 0], [9, 7, 15, 1], [-36, -2, -10, 4], [-10, 16, -9, 8], [-12, 14, 4, -4], [-36, -8, 5, -4], [26, -5, 19, -23], [-19, 12, 6, 8], [-34, 2, -4, -2], [8, -7, 7, -7], [-8, -4, 17, -7], [1, -18, 12, 6], [-15, -7, -11, 5], [-10, -11, 9, -11], [-34, 12, -13, 3], [-8, 8, -20, 18], [26, 2, 2, 12], [-37, 4, -15, 11], [-21, -6, -21, 9], [28, -3, -4, 10], [4, 2, -14, 10], [-21, -7, -2, 5], [-23, 17, -15, 5], [5, 8, -8, -8], [-37, 13, -8, -5], [13, -10, 17, 5], [15, 7, -14, 2], [11, 1, 6, -6], [-34, 16, -8, -6], [11, -4, -4, 19], [-1, -9, 15, -7], [14, -8, -5, 0], [22, -18, 12, 0], [-5, -24, -2, 7], [-41, 19, -12, 11], [1, -6, 24, -9], [-1, 12, -20, 17], [9, 5, -6, -6], [5, 24, 10, -4], [12, -8, -12, -14], [-19, 4, -4, -7], [-9, 19, 2, 5], [24, -2, -1, -7], [-4, 6, -17, 11], [10, -4, 18, 14], [6, -2, 10, -20], [6, -15, -2, 8], [-38, 14, -8, -2], [38, -18, 9, 17], [-12, -5, -16, 6], [0, -18, 11, 8], [26, -14, 18, 12], [2, 4, -6, -2], [30, 12, 10, 2], [30, -26, 4, 12], [-37, -8, 0, 5], [-20, 20, -10, -10], [22, -28, 6, 0], [-32, 12, -12, -14], [-9, -12, -15, -7], [14, 2, 6, 14], [21, -26, 6, -3], [-22, 14, 7, -5], [32, 4, -6, 6], [-38, 21, 0, 2], [13, -21, -8, -4], [3, -16, -8, 10], [-18, 8, -19, 5], [18, -32, 3, 8], [-27, -8, 22, -1], [36, -11, 18, -16], [3, 1, 4, -4], [26, 14, 6, -2], [36, -16, 9, -1], [12, 16, 4, -8], [30, -2, -10, 14], [-14, -7, -26, -8], [-38, 6, -2, 14], [-5, -21, -2, 6], [-21, -20, -10, 11], [-24, -17, 8, 4], [0, 8, 7, -9], [-9, -10, -8, 5], [11, -21, 20, 1], [-17, -4, -4, -14], [4, 11, -19, 9], [-24, 14, -12, 20], [0, -7, 13, -5], [1, -22, 4, -1], [-2, 24, -17, -4], [45, 0, 8, -12], [-3, 7, 11, 7], [3, -20, -1, -5], [-26, 18, 2, -6], [26, -9, 8, -8], [31, -19, -4, -8], [62, -10, 7, 6], [-31, 14, -11, -13], [-13, 18, 10, 8], [-32, -2, 3, -7], [14, -3, 9, 9], [-20, 18, -3, 5], [21, 6, 2, -7], [18, 4, -21, 11], [2, 19, -28, 12], [-42, -4, -7, 8], [-5, -18, 8, 0], [-25, -18, 10, -1], [-40, -2, 3, -15], [-31, 20, 0, -19], [12, 2, 24, -2], [-8, -2, 2, -22], [39, -40, 13, -1], [34, -28, 6, 10], [-3, 16, -18, -2], [-5, 21, -5, 5], [-52, 4, -10, 10], [5, 6, 5, 5], [-13, -10, 4, -4], [34, -6, 3, 17], [-13, 5, -11, 15], [-16, 2, 18, -6], [-22, 9, -22, -6], [1, 3, -3, -1], [12, 7, 8, -8], [16, -9, -8, -10], [-20, -8, -9, 1], [3, 21, 3, -1], [23, -18, -5, 11], [-26, 19, -13, 1], [-59, 1, 4, 0], [30, 1, -12, 0], [-24, 4, 1, -1], [0, 10, -23, -7], [-38, 28, -1, 1], [22, 4, 5, -10], [6, 24, 2, -8], [-15, -6, -16, 6], [38, 6, 6, 6], [35, 5, 4, 14], [-14, -19, 24, -10], [2, 30, 0, -2], [-15, -5, -16, -4], [18, -13, -7, 19], [-7, 23, -24, 1], [62, -6, 4, -8], [16, 2, -10, 16], [24, 2, -13, 13], [-38, -9, -10, -8], [-25, 6, -20, -3], [16, -4, -6, 2], [8, -4, -1, -5], [-3, 3, -10, 15], [32, -12, 1, -1], [18, -9, 19, 5], [45, -35, 17, -11], [-5, -12, 19, -5], [-41, -2, -1, -11], [32, -13, 12, 12], [9, -15, 5, 21], [-16, -23, -1, 3], [43, -13, 5, 13], [-21, -19, 12, 5], [43, -6, 9, -9], [-13, -10, -18, 21], [-9, 5, -18, 1], [70, -5, 8, 14], [-56, 10, -4, 2], [0, -23, 9, 1], [-34, 6, -17, 17], [14, -2, -1, 16], [-41, 28, -1, 9], [-10, -7, 21, 3], [5, -6, 6, -14], [29, -16, 12, -5], [-38, 17, -9, 23], [16, -24, -5, 6], [-1, -5, 11, -25], [56, 8, 9, -7], [20, 4, 17, -5], [-12, -18, -19, 4], [8, -14, 16, -10], [39, -28, 8, 9], [-27, 10, 2, -2], [11, -1, -25, 23], [-39, 1, -7, 7], [-17, 10, -18, 7], [-17, 6, -18, 7], [1, 17, -4, 11], [-19, -16, -2, -11], [-4, -2, 24, -18], [14, -14, 10, 16], [32, -32, 9, -11], [38, 8, 3, -5], [-35, 4, -6, 19], [-9, 19, -11, -5], [10, -13, -1, -11], [46, 1, 3, 7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9200_2_a_ck();".
// 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_9200_2_a_ck(:prec:=4)
    chi := MakeCharacter_9200_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_9200_2_a_ck();".
// 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_9200_2_a_ck( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![5, -6, -6, 2, 1]>,<7,R![-4, -12, 4, 6, 1]>,<11,R![-28, -44, -16, 2, 1]>],Snew);
    return Vf;
end function;