
// Make newform 1183.2.a.e in Magma, downloaded from the LMFDB on 15 January 2025.
// 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_e();".
// 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_e();".
// 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_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]];
    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, 1], [1, -1], [0, 1], [-1, 0], [-3, -1], [0, 0], [-6, 1], [-2, 0], [3, -1], [-3, 0], [1, 3], [7, 0], [0, -3], [5, 3], [-6, 4], [-3, 4], [-9, -1], [-10, -3], [1, -3], [-6, 0], [-2, -3], [11, -3], [-3, -3], [-6, 4], [4, 6], [-6, 1], [-4, 6], [6, 8], [-2, -6], [3, -6], [8, -6], [0, 2], [-15, -4], [5, 9], [3, -2], [-2, 0], [-4, -3], [-11, 3], [-9, -9], [12, 2], [0, 4], [-10, -9], [3, -1], [-5, 0], [-12, 0], [2, 0], [-7, -3], [10, 0], [3, 5], [4, -6], [12, 8], [21, 3], [16, -3], [-12, -6], [-6, -7], [3, 1], [12, 4], [-11, -3], [17, 0], [-3, 6], [5, -3], [6, 3], [-11, -9], [3, 1], [8, -12], [3, -2], [1, 15], [11, 0], [9, 1], [4, -12], [-12, 5], [-12, 4], [-1, -3], [-1, 6], [-11, 9], [3, -5], [-27, -2], [-2, -12], [-3, -8], [22, 3], [-27, 3], [1, -18], [-18, -10], [2, 9], [-1, -9], [6, -10], [12, 0], [-11, 0], [0, -9], [-11, -9], [3, -13], [-3, -1], [-20, 12], [18, 6], [13, -15], [-3, 9], [-12, 1], [-12, 7], [2, 18], [25, 6], [23, 3], [-9, 20], [9, -11], [36, -4], [-4, -12], [-38, 3], [-6, 6], [-12, -17], [30, -8], [-4, 15], [-4, 6], [7, 6], [-39, 6], [1, 21], [-8, -12], [15, -8], [-20, -12], [0, -26], [-24, 8], [18, -6], [28, -3], [-13, 18], [-30, -4], [-12, 2], [10, 6], [0, -12], [1, 18], [-9, -1], [-10, 18], [-8, 9], [-20, 12], [18, 6], [41, 3], [-16, 0], [-24, 10], [16, 18], [6, -4], [13, 15], [-24, 6], [9, 4], [1, -9], [-18, -8], [-10, 18], [-9, -15], [-16, -9], [18, 0], [10, 9], [-18, 7], [-13, -3], [15, 13], [1, 12], [-24, -9], [-1, 27], [-6, -10], [-1, 9], [12, 0], [2, 24], [-30, 13], [-46, 3], [42, 8], [9, 1], [6, 18], [-29, 15], [-18, 20], [3, 20], [0, -10], [-7, -15], [-10, -3], [10, -6], [0, -7], [-9, 11], [22, 9], [-30, -16], [1, -12], [-13, 9], [12, -27], [28, -18], [3, 2], [-10, 6], [8, 30], [19, 3], [12, 0], [-13, 0], [-30, 4], [12, -4], [6, 1], [-16, 0], [46, 0], [19, -12], [6, -22], [32, 9], [9, -3], [2, 18], [36, 4], [3, -23], [-12, -8], [1, -6], [-37, 18], [6, -9], [-6, 32], [27, -22], [-4, 6], [-14, 9], [-10, 3], [-12, 18], [-18, 19], [-11, -15], [-3, -13], [21, -6], [-28, 0], [-43, 12], [-12, -6], [32, -6], [-30, 4], [36, 2], [28, -9], [5, 33], [6, 37], [-6, -26], [-6, 24], [5, -18], [-2, -12], [-9, 10], [-2, -18], [-18, 18], [5, -6], [0, -1], [48, 4], [-16, -6], [-42, -2], [23, 12], [38, -18], [-11, -15], [21, 4], [59, -3], [-36, -10], [-8, -24], [-15, 4], [-6, -12], [3, 3], [33, 5], [47, -3], [-22, -18], [-29, -12], [-48, 3], [-21, -1], [19, -15], [-24, -16], [-23, -9], [-6, 0], [34, 6], [12, -2], [-48, -4], [-10, -9], [18, -32], [-36, 16], [-34, 0], [28, -12], [-36, -18], [40, -9], [-10, -18], [6, -30], [-26, -15], [-64, -3], [-54, -1], [-19, 15], [30, -6], [-30, -3], [22, 0], [-45, -20], [-10, 27], [16, 12], [-62, -3], [50, 0], [38, 0], [-59, 3], [21, -5], [-17, 12], [49, 18], [-6, 20], [-30, -14], [40, -18], [21, -15], [-14, 21], [46, -18], [-6, -4], [-61, 0], [-15, 12], [-20, 24], [-30, -27], [-6, 16], [-24, -8], [33, -8], [51, -3], [14, -6], [-6, 1], [-10, 0], [6, 3], [78, 2], [-17, 9], [-40, 3], [33, -14], [-40, 0], [60, 0], [-4, -6], [7, 18], [-36, -8], [38, -9], [-3, 7], [-7, 30], [66, 2], [18, -22], [51, 14], [5, -21], [-6, 36], [68, -3], [27, -15], [15, -37], [-44, -18], [-27, 0], [11, -27], [46, 0], [24, 33], [-26, 6], [18, -4], [14, 15], [34, 12], [-35, 9], [9, -1], [3, 42], [1, 42], [3, -26], [8, 18], [-42, 20], [-20, -12], [54, 0], [-35, -12], [42, -8], [-2, 3], [41, 21], [-8, -12], [-63, 6], [-6, 15], [5, -9], [60, -8], [27, 33], [14, 39], [-38, 6], [-33, -27], [0, 32], [-68, -12], [-14, 18], [-27, 12], [-55, 3], [59, -12], [18, 3], [12, -44], [60, -16], [-9, -46], [6, 36], [1, 18], [-36, 29], [36, -14], [27, 37], [14, 18], [44, -12], [0, 24], [49, 3], [29, 0], [42, 16], [59, 9], [0, 34], [3, 30], [5, -33], [-7, -42], [-12, -22], [15, 9], [-74, 0], [-18, -7], [-82, 9], [-36, 20], [-21, -18], [25, -9], [0, 8], [-29, 39], [-36, -34], [-17, 45], [32, -18], [-59, -3], [3, 21], [-23, -6], [-90, 1], [57, -1], [17, -15], [-39, 7], [-4, -24], [-5, -9], [-6, 24], [-25, -39], [-51, -4], [22, -24], [-12, -16], [-32, 24], [-36, 7], [42, -1], [-85, 9], [64, -12], [-27, 12], [49, -3], [0, 4], [62, -21], [9, -34], [60, 24], [-52, -6], [-13, 18], [-6, 47], [0, -50], [11, -27], [-48, 18], [15, -13], [57, 4], [16, 21], [-42, 18], [-3, 15], [-8, 18], [18, -19], [-21, 17], [9, 0], [-2, -24], [-57, -23]];
    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_e();".
// 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_e(:prec:=2)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1183_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, 0, 1]>,<11,R![6, 6, 1]>],Snew);
    return Vf;
end function;