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