
// Make newform 1134.2.a.m in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1134_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_1134_2_a_m();".
// 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_1134_2_a_m();".
// 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_1134_a();"
function MakeCharacter_1134_a()
    N := 1134;
    order := 1;
    char_gens := [407, 325];
    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_1134_a_Hecke(Kf)
    return MakeCharacter_1134_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], [-2, 1], [-1, 0], [-1, -3], [-3, -2], [-7, 0], [-1, 1], [-1, 3], [-5, 2], [3, 3], [2, 5], [-6, 2], [2, -2], [-3, -1], [6, 2], [1, -3], [-3, 4], [-5, -1], [-10, 2], [10, -1], [3, -7], [-1, -9], [-3, -4], [4, 4], [-2, -4], [2, -6], [0, 0], [-2, 3], [4, 1], [12, 0], [-14, 2], [10, -1], [-5, 1], [-9, 0], [-11, 3], [-1, 0], [-10, -2], [7, -3], [-8, 1], [-3, 3], [-6, -6], [-3, 5], [5, 8], [5, -12], [-7, -7], [-19, 1], [-22, -2], [12, 4], [1, -2], [8, -3], [-9, 11], [-16, 1], [3, 11], [-3, -2], [15, -5], [10, -9], [3, -13], [2, -12], [8, 3], [-2, 10], [-12, 5], [-8, -8], [-5, -3], [10, 9], [21, 6], [2, 6], [-6, -6], [-18, -2], [-2, 2], [18, 0], [4, 4], [-1, 7], [-20, 8], [-5, -13], [8, -16], [10, 2], [-21, 0], [12, -13], [26, -5], [6, 2], [-12, 7], [18, -2], [14, 1], [6, 10], [17, -1], [-2, -8], [7, -8], [-14, 12], [-17, 9], [1, 9], [-1, 13], [-13, 9], [-30, 2], [25, -3], [-21, -11], [-18, -8], [30, 0], [2, 18], [12, -5], [-21, -1], [-17, -4], [8, -16], [-18, -3], [-21, -1], [16, 5], [-13, -1], [-9, 18], [3, 7], [14, 3], [-9, -9], [6, 12], [14, -15], [4, -16], [5, -5], [-10, -17], [-25, 9], [-6, 6], [6, 14], [26, 6], [1, -8], [-1, -10], [-36, 0], [-12, 8], [-28, 0], [-17, -6], [-16, 7], [6, 2], [34, 10], [30, 10], [-15, 1], [30, 6], [-36, 8], [0, 12], [-37, 0], [-20, 9], [-8, 7], [-18, -6], [0, 17], [-20, -7], [13, 3], [-19, -4], [-20, 12], [6, 10], [-14, 0], [2, -2], [-22, -16], [3, 8], [14, 6], [-5, 7], [-14, -13], [-6, -14], [-1, -5], [27, 17], [-36, 0], [-18, -14], [1, 15], [3, 28], [14, -23], [22, 7], [22, 14], [26, 9], [5, -5], [-21, 7], [-30, -16], [-24, -20], [-19, -5], [17, 14], [11, -8], [6, -8], [10, 10], [-5, -18], [-21, -21], [27, 12], [18, 10], [-2, 6], [36, -8], [5, 2], [2, -2], [-19, 12], [18, 10], [20, -20], [-20, -11], [10, 22], [28, 0], [60, -1], [18, -7], [-25, -3], [30, 6], [-33, -15], [4, 15], [6, 6], [1, -15], [56, 1], [-48, 0], [26, -2], [29, 2], [22, -4], [-27, 18], [27, 1], [15, 14], [-45, 3], [-10, 10], [36, 17], [15, 19], [30, 20], [41, -7], [-21, -19], [-18, 16], [-28, -16], [-34, 0], [4, 11], [6, -14], [-32, -4], [12, -8], [26, -12], [-14, 10], [-67, 2], [-34, 6], [-43, -6], [-8, -3], [49, -3], [-42, -9], [22, 2], [6, -34], [-22, -9], [38, 10], [-56, 4], [12, -16], [-57, 9], [-36, 7], [-14, -6], [19, 25], [-24, 19], [11, -35], [-12, 28], [16, -13], [18, 18], [27, 21], [-11, -21], [-1, 25], [35, -11], [20, -12], [-36, 8], [38, -22], [21, -17], [30, -14], [-22, -6], [14, -30], [21, -15], [10, 27], [15, 10], [0, -20], [-2, -27], [-10, -29], [-19, -1], [8, -9], [9, -21], [-26, 13], [-22, 16], [-35, -1], [31, 9], [7, -20], [-50, 16], [6, -2], [7, -3], [-21, -14], [-5, -8], [-26, -2], [-3, -6], [-21, 6], [-43, -11], [30, 8], [-22, -26], [22, 1], [24, 32], [-43, 15], [-24, -17], [-5, 16], [-18, 22], [-21, 21], [-15, -17], [-18, 6], [5, 14], [51, 13], [-10, -30], [-69, -4], [38, -14], [-49, 11], [21, 28], [6, -18], [9, -23], [24, -33], [43, 15], [2, -31], [6, -19], [-31, 9], [18, 1], [-12, 0], [6, -26], [-20, 31], [-6, 0], [-26, -6], [30, -22], [-25, 15], [2, -6], [-56, 4], [-34, 8], [59, 3], [26, 3], [-6, -18], [34, 26], [46, 1], [-43, -23], [16, 12], [2, 4], [-39, -11], [-8, -20], [2, 17], [-18, -28], [29, 23], [22, -10], [12, -19], [25, -13], [22, -12], [-22, 9], [-16, 16], [64, 8], [5, 25], [-10, -2], [-34, 8], [17, 20], [-15, 17], [68, 4], [64, 8], [-11, 5], [36, -29], [1, 30], [-10, -44], [13, 21], [44, -3], [18, 24], [0, -27], [-42, -14], [27, -34], [45, -9], [5, -28], [-34, 10], [-18, 2], [6, 9], [8, 16], [47, -2], [-27, 10], [24, 4], [-8, 37], [59, 14], [4, 4], [48, 4], [-22, 4], [20, -4], [40, 27], [-67, 14], [22, -26], [68, -12], [-77, -3], [41, 18], [-6, -40], [3, -11], [10, -10], [44, 8], [-8, -40], [36, -24], [49, 20], [40, -28], [28, 33], [-57, 3], [14, -30], [28, -19], [26, -8], [-40, -1], [0, -25], [52, -17], [-38, -6], [-18, 9], [-53, 1], [22, -2], [23, -35], [-5, -2], [37, -3], [11, 29], [35, 6], [-48, 29], [-7, 35], [-34, 26], [-41, -9], [45, 24], [-23, -31], [-7, 26], [30, 14], [-7, 14], [-43, -26], [60, 20], [-86, 10], [-17, -50], [42, -23], [-19, 37], [34, 39], [-48, -13], [-7, 35], [-4, 4], [-50, 25], [-19, -18], [-13, -27], [-45, -29], [-1, -26], [-28, -43], [23, 19], [37, -11], [-15, -20], [-71, 19], [2, 8], [-22, -6], [50, -18], [-39, 17], [38, -29], [-38, 19], [7, 37], [18, -9], [-78, 6], [-43, -21]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1134_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1134_2_a_m();".
// 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_1134_2_a_m(:prec:=2)
    chi := MakeCharacter_1134_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_1134_2_a_m();".
// 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_1134_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1134_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 4, 1]>,<11,R![-26, 2, 1]>,<13,R![-3, 6, 1]>],Snew);
    return Vf;
end function;