
// Make newform 1134.2.a.a in Magma, downloaded from the LMFDB on 19 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_a();".
// 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_a();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-3], [1], [-6], [2], [6], [-7], [3], [6], [2], [2], [0], [2], [0], [6], [0], [5], [8], [3], [2], [5], [12], [0], [2], [9], [-10], [-12], [-10], [15], [17], [-9], [6], [5], [-6], [23], [-13], [2], [0], [-6], [18], [-25], [-9], [17], [18], [14], [8], [-28], [-15], [-1], [9], [-15], [8], [3], [18], [-21], [-9], [-28], [-16], [-27], [-19], [-3], [-25], [12], [-10], [18], [26], [-22], [-24], [26], [-18], [-3], [8], [14], [2], [-18], [24], [26], [3], [32], [15], [-10], [12], [14], [8], [18], [33], [29], [-33], [-13], [12], [-6], [29], [18], [32], [12], [30], [24], [-13], [38], [32], [-24], [-33], [-18], [32], [-4], [-3], [0], [-24], [14], [-22], [8], [42], [-7], [-7], [27], [-4], [0], [-36], [42], [5], [-37], [42], [-6], [47], [-18], [-52], [-36], [8], [29], [26], [36], [-31], [26], [-42], [14], [-51], [20], [3], [-30], [-16], [-24], [8], [36], [-34], [0], [35], [54], [-4], [9], [-22], [0], [-34], [24], [32], [15], [11], [0], [38], [21], [-24], [42], [17], [-15], [6], [18], [-40], [-55], [-22], [15], [-30], [23], [-3], [-19], [56], [-60], [-58], [-60], [-22], [29], [35], [0], [14], [54], [-9], [-30], [-46], [-37], [11], [-60], [-52], [-18], [20], [-21], [30], [-60], [41], [56], [6], [0], [18], [14], [53], [-4], [63], [45], [14], [-36], [30], [-31], [11], [30], [-4], [-33], [60], [2], [-67], [12], [-24], [-36], [20], [14], [-15], [-16], [48], [56], [24], [-51], [8], [-12], [-40], [-7], [-19], [-6], [-73], [-54], [68], [-42], [0], [-42], [24], [20], [-4], [26], [18], [-24], [26], [-33], [-40], [-33], [68], [0], [-27], [-16], [6], [36], [50], [-49], [-51], [-52], [-64], [-60], [-10], [29], [-12], [-4], [6], [-48], [-4], [-24], [14], [20], [32], [80], [-22], [8], [84], [14], [14], [-75], [0], [-16], [-6], [65], [11], [69], [-19], [12], [74], [-6], [36], [39], [21], [12], [-10], [3], [-22], [-33], [-36], [68], [-64], [24], [-61], [36], [-58], [-1], [48], [5], [-12], [-34], [18], [-66], [78], [-46], [21], [-40], [-9], [-45], [-70], [-6], [44], [-13], [6], [23], [-3], [20], [-16], [8], [21], [54], [2], [-60], [-28], [9], [2], [33], [-82], [-18], [26], [20], [14], [15], [-78], [-19], [-36], [30], [83], [8], [-30], [-90], [23], [5], [72], [-28], [-28], [6], [-90], [69], [45], [0], [56], [90], [12], [60], [-64], [-19], [42], [8], [41], [-60], [56], [-87], [0], [14], [-82], [63], [33], [32], [30], [8], [-69], [9], [-97], [39], [53], [-72], [8], [-31], [2], [0], [2], [-3], [42], [-1], [60], [-25], [-88], [-66], [-70], [-66], [5], [57], [32], [-24], [-57], [-58], [-70], [-3], [89], [-36], [-28], [-18], [12], [14], [-31], [63], [24], [-10], [-42], [24], [-90], [77], [33], [39], [-16], [-66], [24], [-75], [11], [66]];
    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_a();".
// 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_a(:prec:=1)
    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_a();".
// 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_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1134_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 1]>,<11,R![6, 1]>,<13,R![-2, 1]>],Snew);
    return Vf;
end function;