
// Make newform 1183.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1183_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_1183_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_1183_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 := [1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 1]];
    Rf_basisdens := [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_1183_a();"
function MakeCharacter_1183_a()
    N := 1183;
    order := 1;
    char_gens := [339, 1016];
    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_1183_a_Hecke(Kf)
    return MakeCharacter_1183_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, -1, 0], [0, 0, 1], [1, 0, -1], [-1, 0, 0], [3, -1, 0], [0, 0, 0], [2, -2, -1], [0, 1, 4], [-2, 3, 1], [-3, 2, -2], [3, 2, -1], [3, 3, 0], [2, -4, 0], [5, -2, -2], [6, 1, 2], [0, 1, -1], [1, -1, -3], [4, 2, -2], [-4, 0, -2], [3, 5, -2], [-4, 3, -4], [5, -2, 4], [-1, 4, 5], [0, 3, -2], [8, -9, -2], [2, 2, -5], [6, 6, -2], [-3, 1, 7], [3, 3, -2], [-4, 7, 3], [-1, -5, -3], [4, -8, -2], [11, 3, -2], [4, 4, 1], [1, 7, 8], [-7, 1, 6], [2, -4, -3], [8, -4, 2], [0, -11, 0], [8, 8, 1], [-1, 8, 8], [0, 6, 5], [-13, -1, -3], [6, -10, -8], [-2, 8, 4], [-6, -4, -3], [0, 1, 1], [-3, -6, -7], [10, 2, -2], [-11, -7, -3], [-9, -4, 8], [0, -6, 8], [11, 0, 11], [8, -8, 1], [-12, -2, 5], [3, -6, -4], [2, -8, 8], [-14, 10, 6], [1, -12, -2], [-7, 3, -8], [14, -6, 0], [20, 1, 4], [3, -4, -1], [-4, -6, -15], [-20, 10, 1], [-4, 2, -6], [12, -6, -6], [2, 5, 5], [10, -14, 0], [8, -5, -8], [19, -9, -9], [7, 5, -4], [-10, 6, -5], [-15, -5, 1], [-7, -1, -14], [24, -4, -4], [-3, -5, 7], [20, -5, -2], [2, 4, 4], [-22, 1, 2], [-4, 10, 11], [-1, -9, 2], [-4, -6, -2], [-12, 14, 4], [-2, -12, 2], [2, 11, 1], [0, 12, 10], [17, -1, 6], [22, 0, 2], [23, -9, 2], [8, 12, 7], [-13, 10, 1], [-18, 2, 0], [-15, -7, 1], [3, 13, 8], [16, 6, 10], [10, 3, -10], [-6, -2, -14], [2, -8, -16], [-27, 3, 2], [2, -3, 5], [18, 2, 2], [-8, 14, 8], [7, -12, -14], [-30, 11, 5], [12, 10, -6], [-9, 16, 1], [11, 14, -1], [3, -12, -8], [6, 6, 12], [14, 0, 11], [-12, 16, 0], [16, -12, -8], [-10, 18, -2], [-16, -2, -2], [-13, -10, -6], [-18, 22, 12], [26, 6, 7], [-2, 0, 14], [-14, 1, -21], [-1, 20, 9], [-4, 3, -11], [8, 0, 5], [-14, 8, 6], [-18, -15, 2], [23, -2, 4], [-7, 1, 20], [14, -4, -13], [0, 4, 10], [-5, 0, -11], [-1, -1, 0], [0, 2, 10], [-15, 10, 2], [-13, 10, 4], [-15, 8, -1], [23, 6, 7], [14, 0, 8], [9, -16, -1], [-18, -14, 8], [-7, 0, -2], [0, -20, 10], [8, -14, 16], [5, 5, -11], [20, -4, -14], [-24, 6, -1], [-22, -6, -16], [-15, 4, -7], [-24, -2, 8], [-6, 2, 0], [-20, 0, -16], [9, -19, -16], [2, 16, 22], [-13, -9, -31], [2, -6, -4], [-8, 9, 7], [9, -4, -10], [10, -22, -16], [-11, -4, -7], [-24, 4, -5], [-41, 4, 1], [-16, -14, 0], [1, -16, 12], [1, 1, -24], [-40, 10, 8], [45, 3, 6], [0, -3, 12], [-3, 25, 5], [-10, 22, 8], [19, -31, -10], [-18, 2, -3], [-15, -13, -8], [14, 0, -6], [8, 7, 1], [-11, 3, 22], [32, -8, -2], [26, 0, 6], [-6, -14, -8], [-8, -16, 14], [-2, 22, 3], [-26, 18, 13], [8, 22, -8], [6, 2, 9], [15, 9, -17], [-2, 3, 14], [-27, 3, -2], [38, 8, -3], [22, 11, -7], [-13, 6, 9], [8, -10, -8], [-12, 9, 10], [-24, -8, -27], [20, -12, -2], [2, 3, -1], [27, -6, -11], [0, -5, 13], [12, -10, -19], [-15, 3, 4], [-11, 16, -14], [17, -2, 9], [18, 14, -14], [-27, 5, 2], [28, -6, 13], [36, -29, -14], [-20, -4, -12], [-2, 1, 0], [42, -2, -12], [17, -20, -7], [-21, 24, 22], [37, 9, 0], [-16, 2, 2], [-37, 4, 8], [24, -24, 5], [-8, 16, -4], [-12, 8, 10], [-15, 2, -13], [35, -26, -3], [-27, -10, -10], [4, 0, 2], [28, -4, -2], [5, -9, 24], [-18, 13, -1], [1, 11, -7], [32, 6, 16], [8, -12, -4], [22, -22, -6], [6, -13, 17], [16, -6, 4], [21, 20, -4], [-8, 0, 15], [-17, -11, -30], [13, 3, 21], [-30, 12, 11], [12, -18, -2], [31, 5, -7], [-6, 6, -2], [-28, 15, 14], [22, -4, -6], [42, -4, -4], [-46, 5, -11], [26, -22, -22], [-18, -6, -22], [-2, 12, 6], [8, 2, -20], [-48, 14, 0], [25, -18, -5], [10, -32, 9], [18, 25, -14], [9, 24, -9], [-9, -21, -36], [-42, 13, 1], [-16, 36, 0], [-14, 20, 26], [6, -20, -26], [50, 4, 2], [-34, 4, 4], [-18, -16, 18], [23, 0, 6], [-16, -12, -30], [4, 8, -14], [-21, 16, 19], [30, -29, -3], [-13, -22, 8], [16, 7, -12], [6, 0, -3], [6, -24, 2], [-22, -24, 16], [-12, 18, 28], [40, 7, 16], [5, 3, 0], [-25, 13, 3], [-26, -18, 7], [13, 25, 10], [-34, -8, -22], [-38, 17, 23], [-12, 4, 27], [-10, 2, -20], [-29, 33, 22], [-17, 29, -6], [36, -10, -14], [-32, -2, -16], [8, 16, -28], [46, -32, -20], [-52, 0, 0], [-22, -27, -8], [33, -21, -7], [-7, 22, -4], [23, -8, 10], [-4, 24, 20], [-24, -4, -12], [-28, 8, -19], [0, -11, 35], [24, -20, -14], [4, -10, -2], [8, -19, 26], [-4, -29, 5], [-20, -14, 8], [0, 24, 40], [28, 0, 12], [28, 2, 9], [-15, -20, 13], [-16, -22, -13], [-3, -11, 22], [12, -27, 1], [12, -35, -7], [-14, 21, 27], [31, 9, 40], [-9, 15, 9], [-24, 36, 29], [16, 14, 22], [-20, 17, -5], [-26, -12, 9], [-39, 3, 16], [-25, 1, -19], [33, 0, -6], [1, 5, -16], [18, -4, 26], [21, -36, -11], [-17, 3, -38], [-11, 20, 15], [23, -38, -6], [-2, 44, -8], [18, -12, -6], [-14, 22, -5], [10, 16, 14], [16, 14, 34], [-2, -12, -35], [-30, 12, 20], [1, 2, 11], [27, -5, -5], [-31, 3, -1], [-65, 7, 6], [-4, -27, -23], [16, -26, -17], [26, 33, -24], [13, 1, 26], [0, 25, 22], [37, -9, -16], [-12, 18, 18], [-11, 13, -7], [-32, 6, 24], [-17, -1, 14], [25, 7, 23], [-33, -17, -25], [-33, 15, 19], [35, 17, 20], [-1, -5, -31], [-24, -4, -13], [33, -39, -6], [2, -1, 14], [10, 16, 1], [-38, -1, 14], [-5, -1, -20], [-63, -3, -12], [-72, 10, 2], [-11, -9, -33], [4, 22, -9], [-3, -2, -5], [15, -28, -9], [-51, -1, -21], [5, -15, -16], [30, 2, -12], [26, -24, 6], [15, -36, -26], [51, 3, -14], [32, -20, 15], [-35, 26, -6], [-39, -8, 15], [49, 1, 8], [12, 13, 3], [25, 21, -9], [-20, -10, 15], [21, -17, -4], [-35, 30, 30], [20, -38, 9], [3, 4, 12], [4, -24, -2], [-37, 15, 25], [-9, 11, -37], [-2, -26, -20], [2, -44, 8], [25, -48, -19], [-18, 12, -26], [-41, -5, -18], [33, -9, 18], [32, 3, 0], [-3, -10, 23], [11, 33, -10], [4, -14, 20], [31, 9, 12], [-2, 4, 27], [-46, 6, 16], [-47, 18, 21], [-72, -4, 10], [0, -8, 18], [-28, 44, 24], [20, -25, -39], [14, 2, -14], [20, -18, -14], [-39, -4, -18], [14, -8, -30], [20, 9, 18], [-58, 43, 15], [-9, -19, 12], [29, 10, 37], [-50, -21, -4], [22, 16, -27], [-44, 12, -6], [-1, 21, 2], [44, -5, -10], [8, -1, -6], [8, -6, -36], [-16, -21, -7], [18, -35, -11], [25, -23, -17], [22, 11, 33], [-8, 10, 35], [4, -38, -24], [4, 8, 30], [4, 14, 14], [54, -14, 1], [4, 17, 25], [-61, -13, 7], [-13, 11, -8], [8, 8, -33], [14, 0, 18], [28, 13, -6], [-3, -26, 18], [-2, 26, -8], [-18, 45, 12], [-24, 34, 38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1183_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1183_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_1183_2_a_j(:prec:=3)
    chi := MakeCharacter_1183_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_1183_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_1183_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1183_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, -2, -2, 1]>,<11,R![-10, 18, -8, 1]>],Snew);
    return Vf;
end function;