
// Make newform 2736.2.a.x in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2736_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_2736_2_a_x();".
// 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_2736_2_a_x();".
// 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_2736_a();"
function MakeCharacter_2736_a()
    N := 2736;
    order := 1;
    char_gens := [1711, 2053, 1217, 1009];
    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_2736_a_Hecke(Kf)
    return MakeCharacter_2736_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], [4], [0], [6], [2], [4], [1], [-6], [10], [-8], [-10], [-6], [4], [-6], [2], [-4], [10], [12], [-12], [-6], [4], [-14], [-6], [-2], [0], [-4], [4], [-6], [-14], [0], [6], [-12], [4], [16], [4], [2], [20], [-8], [-10], [12], [-22], [6], [18], [-12], [-24], [12], [20], [-8], [10], [16], [30], [6], [2], [6], [-2], [14], [8], [-6], [-2], [-4], [-2], [-16], [-14], [14], [-18], [32], [-18], [-18], [14], [4], [-2], [-16], [-26], [24], [28], [20], [-2], [-30], [-2], [30], [-22], [12], [10], [-28], [-26], [-18], [34], [-24], [16], [26], [-34], [-16], [-2], [20], [6], [-10], [2], [-20], [-26], [8], [-32], [-16], [-26], [28], [-10], [-14], [24], [-16], [-46], [0], [-22], [12], [-28], [8], [-30], [-20], [-38], [-24], [24], [14], [18], [26], [44], [12], [0], [6], [-46], [-16], [22], [-4], [12], [4], [-22], [28], [38], [14], [-44], [-18], [24], [0], [8], [-40], [-28], [42], [-12], [54], [2], [52], [-36], [46], [20], [52], [8], [-52], [-8], [8], [0], [-22], [-26], [-10], [14], [0], [-16], [26], [56], [40], [-38], [14], [-24], [20], [38], [-46], [-26], [-48], [-32], [-20], [-24], [56], [14], [40], [16], [58], [-42], [-46], [56], [50], [52], [38], [10], [-50], [-26], [-16], [-6], [6], [-30], [-14], [-26], [16], [6], [-30], [-56], [-14], [38], [14], [56], [40], [-60], [-12], [-8], [-26], [-20], [-24], [52], [28], [42], [0], [2], [-60], [44], [42], [20], [18], [8], [72], [66], [6], [4], [-56], [70], [18], [56], [48], [-30], [76], [-30], [18], [-52], [-58], [-36], [-36], [28], [-8], [-42], [30], [-42], [56], [40], [40], [42], [2], [-32], [-30], [-10], [12], [-10], [-74], [8], [18], [-58], [-44], [-72], [-50], [54], [48], [52], [18], [40], [64], [36], [6], [-4], [-10], [32], [-74], [-24], [10], [70], [26], [-30], [-36], [-24], [70], [54], [-44], [26], [30], [14], [-40], [46], [8], [-62], [-18], [28], [-2], [-28], [-20], [-68], [-80], [-60], [70], [82], [-40], [44], [12], [-2], [-48], [-46], [10], [6], [-66], [-20], [-54], [40], [-30], [30], [46], [16], [-70], [68], [20], [42], [-38], [4], [68], [-2], [-40], [-4], [-52], [-48], [50], [-22], [16], [-82], [60], [-30], [-2], [-6], [-26], [-80], [22], [-76], [10], [32], [-78], [-32], [-38], [60], [0], [-48], [52], [6], [-12], [-24], [-50], [66], [-34], [42], [52], [36], [-10], [-60], [-12], [52], [28], [-62], [56], [-48], [-94], [18], [-48], [18], [-22], [80], [46], [48], [-46], [-14], [-56], [-18], [42], [24], [32], [-24], [-4], [60], [-32], [10], [52], [24], [-2], [66], [30], [-44], [84], [-74], [16], [94], [-76], [-28], [70], [-64], [-36], [6], [86], [40], [-34], [-18], [-32], [22], [34], [60], [64], [4], [26], [48], [48], [-56], [28], [-84], [-70], [38], [-30], [-96], [10], [102], [84], [56], [100], [-54]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2736_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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