
// Make newform 2736.2.a.c in Magma, downloaded from the LMFDB on 03 September 2025.
// 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_c();".
// 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_c();".
// 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 := 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]];
    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], [1], [3], [-4], [3], [-1], [0], [-6], [4], [2], [6], [1], [-3], [-12], [-6], [-1], [4], [6], [-7], [-8], [12], [-12], [8], [-6], [-14], [-18], [-16], [-6], [-2], [-15], [3], [13], [-21], [10], [14], [-20], [-18], [18], [-18], [2], [3], [-4], [-18], [-11], [-14], [10], [12], [5], [21], [15], [-10], [21], [0], [9], [-24], [16], [-19], [-6], [13], [12], [-20], [-3], [-10], [-6], [28], [32], [21], [17], [6], [15], [-8], [-4], [34], [12], [-15], [-7], [-12], [-4], [-12], [8], [-24], [2], [10], [-3], [0], [-37], [-9], [31], [-27], [-12], [-2], [12], [-5], [12], [0], [0], [-38], [-25], [28], [-21], [6], [24], [4], [11], [45], [42], [-36], [26], [-32], [29], [-9], [-44], [-11], [0], [13], [27], [39], [-30], [32], [-10], [42], [36], [-17], [-6], [26], [15], [19], [-22], [-11], [-24], [-32], [-25], [-33], [23], [6], [4], [12], [9], [16], [-33], [49], [12], [-16], [18], [26], [-18], [49], [18], [-22], [27], [-47], [18], [-8], [-6], [-20], [18], [-7], [18], [-36], [48], [40], [60], [-24], [-36], [34], [17], [20], [-9], [30], [-40], [-24], [26], [4], [-27], [-44], [-33], [-56], [-1], [19], [-24], [-58], [-6], [-57], [15], [-34], [-26], [50], [36], [-34], [-57], [-56], [18], [48], [-36], [5], [-46], [-30], [45], [-36], [10], [-40], [-10], [60], [-21], [7], [0], [-9], [-14], [2], [-18], [1], [60], [-66], [-10], [-32], [60], [-36], [33], [14], [-14], [-66], [7], [-42], [71], [6], [24], [-62], [3], [59], [52], [-68], [30], [55], [-45], [-31], [-27], [-24], [-60], [-54], [7], [40], [38], [-66], [21], [43], [0], [-32], [21], [50], [-51], [60], [-64], [9], [12], [29], [-26], [66], [-70], [46], [-54], [-13], [74], [9], [64], [-36], [-39], [22], [45], [32], [34], [17], [49], [32], [-56], [-21], [44], [-34], [15], [42], [4], [33], [-10], [49], [3], [-25], [36], [1], [-72], [42], [27], [-72], [-30], [26], [30], [-8], [9], [-48], [19], [-31], [-6], [25], [24], [-5], [20], [-12], [14], [-45], [74], [3], [30], [48], [58], [-48], [-16], [-3], [48], [-1], [3], [-62], [41], [-66], [16], [-6], [-52], [-20], [46], [90], [87], [71], [6], [64], [3], [61], [-51], [20], [-42], [59], [16], [80], [27], [-54], [64], [-6], [24], [2], [-26], [-72], [-9], [22], [-52], [-27], [-62], [-40], [-72], [48], [-12], [63], [78], [-55], [-42], [30], [48], [7], [-46], [78], [-74], [-16], [-12], [-74], [-15], [54], [-59], [65], [12], [-72], [11], [-75], [8], [78], [21], [43], [-27], [22], [96], [64], [-22], [7], [6], [-46], [54], [0], [55], [-30], [-22], [-20], [42], [-50], [-66], [-76], [-87], [40], [78], [-48], [43], [-19], [-66], [-14], [21], [8], [93], [18], [19], [50], [90], [-96], [28], [78], [18], [-72], [2], [-15], [18], [-52], [-24], [102], [93], [61], [45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2736_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2736_2_a_c();".
// 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_c(: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_c();".
// 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_c( : 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![-1, 1]>,<11,R![-3, 1]>,<13,R![4, 1]>],Snew);
    return Vf;
end function;