
// Make newform 2736.2.a.bd in Magma, downloaded from the LMFDB on 23 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_bd();".
// 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_bd();".
// 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 := [8, -10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-8, 1, 1]];
    Rf_basisdens := [1, 1, 2];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_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, 0], [0, 0, 0], [0, -1, 0], [-1, 0, 1], [-2, 1, 0], [1, 1, -1], [-1, 0, -1], [1, 0, 0], [-3, 1, -3], [3, 1, 1], [0, 0, 0], [-2, 0, 0], [-4, 2, -2], [-4, -3, 2], [0, 1, 2], [-1, 3, 1], [-7, -1, 1], [2, -1, 2], [-5, -1, -1], [-2, -4, 2], [3, -2, 3], [-10, 2, -2], [-2, 2, 2], [-4, -4, 2], [-2, -2, 0], [-10, 4, -4], [2, -4, -2], [-1, 1, -1], [-1, -1, -3], [2, -4, 4], [-6, 4, -2], [-4, -3, 2], [-13, 4, -5], [0, -3, -2], [12, -3, 0], [2, -4, -2], [14, 0, 0], [0, 4, -4], [-12, -2, 0], [-2, -4, 4], [-8, 2, -8], [-10, 4, 0], [-3, 8, -5], [2, 2, 4], [4, -2, 2], [11, 0, 5], [11, 1, 3], [6, -4, 2], [9, 1, -3], [-2, 5, -6], [-10, 1, -6], [-3, -4, 3], [-12, 2, 2], [-2, -5, 4], [4, 4, 2], [16, -3, 2], [2, -2, 4], [-5, -1, 3], [8, -1, 4], [-12, 2, 6], [2, -1, 0], [9, 1, 3], [-4, 4, 0], [-11, 2, -1], [-17, 5, -3], [5, -1, -5], [9, -3, 5], [4, -4, 6], [-6, -1, 0], [2, -3, -2], [-11, 3, 7], [11, -6, 9], [4, 4, -4], [3, -13, 9], [15, -3, -1], [-14, 2, 2], [-10, 1, -2], [-4, -1, 8], [-12, -4, 2], [16, -8, 10], [-8, 4, -4], [13, -3, 3], [10, 2, -6], [-10, 8, -4], [4, 2, -8], [10, -9, 0], [-18, 6, -4], [19, -4, -1], [8, -3, 12], [-20, -1, 2], [18, -1, 0], [-4, 8, -4], [6, -4, 10], [-12, -8, 0], [0, -5, 2], [-3, 5, -11], [22, -2, 0], [8, -4, -10], [-19, -5, -3], [-14, -9, 2], [-12, 0, 0], [16, 9, -4], [-4, 6, -4], [-20, -4, 2], [4, 8, -8], [9, 2, -3], [4, -7, -6], [-2, -4, 8], [0, 0, 8], [4, 2, 10], [10, -14, 10], [2, -7, -2], [14, 7, -2], [-14, 6, 6], [-8, -7, 2], [-10, -2, 4], [-10, 11, -4], [21, 0, -5], [24, -3, -4], [11, 1, -5], [23, -5, 5], [16, 2, -10], [13, -5, 3], [-12, 0, 0], [-14, 1, -4], [-8, -2, 6], [2, -8, 4], [9, 8, -1], [-13, -2, -7], [0, 6, -6], [-16, 5, -10], [-8, 4, -8], [24, 0, 8], [38, 3, -2], [-1, 4, -1], [-17, 12, -5], [9, 7, -1], [-9, 7, 3], [-5, -9, 5], [-3, -16, 9], [13, 17, -7], [-8, 13, -12], [17, 2, 3], [-7, 13, -3], [-1, 11, 5], [-20, -2, -8], [-22, 8, -4], [16, 2, -6], [6, -9, 12], [-14, 0, -2], [43, -3, -3], [-6, 7, 10], [-6, 3, 8], [42, -4, 6], [21, 5, -7], [-12, -10, 8], [-39, 1, 1], [-19, -17, 7], [-21, -2, -5], [7, -7, -3], [-12, 0, 8], [14, -6, 12], [-8, 8, -8], [20, 0, 0], [28, 0, 2], [30, 2, -2], [-8, 6, 4], [-8, 11, -4], [4, 12, -10], [-8, 13, -12], [-17, -19, 7], [-7, -7, 7], [-8, 8, -8], [21, 7, -5], [8, -4, -16], [-22, 5, -2], [20, -16, 8], [18, -1, -2], [12, 4, -12], [-4, 9, -4], [-19, 8, -5], [39, 3, 3], [22, 8, -8], [24, -2, 10], [5, -12, 11], [-18, 11, -22], [7, -11, 1], [16, -10, 0], [-2, 0, -4], [-11, 5, -11], [-6, -16, 8], [-28, 11, -2], [16, -4, -4], [-15, -9, -1], [32, 0, -4], [-4, 0, -6], [-37, 2, -5], [8, -10, 18], [31, 9, -7], [-37, 8, -11], [22, -6, 8], [28, -14, 8], [-15, -7, 7], [-16, 6, -18], [-10, 2, 2], [4, -3, 0], [-1, 14, 5], [33, -3, -3], [9, -2, 9], [27, 17, -5], [-1, -15, -3], [-24, -6, 6], [-12, 9, 6], [-13, 3, -17], [-32, 2, 12], [14, -4, 4], [-41, -5, -1], [-34, 2, -12], [-10, -2, 14], [-26, 1, -10], [-14, 20, -12], [10, 16, -2], [-34, 12, -24], [-5, -6, 17], [27, -3, 3], [-26, 11, -18], [-2, 0, 8], [-34, 10, 6], [6, -8, 18], [-38, 5, -4], [10, -5, 2], [-37, 15, -17], [-24, 0, -8], [-50, 8, -8], [-18, 5, 16], [-25, 10, 5], [-10, 5, -2], [-28, 3, -12], [-42, 6, 10], [20, 4, -4], [-28, 6, -12], [14, -19, 16], [-7, 5, -7], [-31, -1, 11], [-8, 6, -14], [28, -19, 22], [-40, 15, -26], [36, 0, -8], [-4, 12, -8], [9, 6, 11], [38, -12, 0], [-1, -2, -5], [25, 1, 1], [2, 6, 4], [-48, -5, 0], [-2, -6, -14], [-2, -11, 10], [4, -10, 20], [22, 0, -4], [-10, 4, 12], [0, 10, -12], [20, 6, 4], [52, -3, 4], [-27, 15, -9], [46, -11, 18], [15, 7, 11], [-23, 13, -13], [-17, 10, 11], [-11, -1, -3], [22, -19, 22], [1, 9, -17], [1, 19, 1], [43, 6, -5], [13, -2, -9], [30, -6, -8], [-11, 1, -11], [-22, 5, -4], [-23, -3, -1], [12, -2, 10], [36, -5, 6], [-6, -12, -2], [-9, 15, -1], [-27, 6, 7], [-51, 3, -1], [-48, 1, 6], [8, -17, 6], [11, 0, -9], [-6, 14, -12], [-43, -2, 7], [-2, -10, -4], [18, 0, -16], [4, 15, -2], [-22, 2, -16], [20, 6, 12], [30, -12, 0], [12, 6, -14], [18, 2, 2], [-10, 9, -2], [-29, 3, -17], [-10, -15, -8], [-18, 5, -2], [-27, -17, 11], [-17, 0, 9], [-19, -3, 1], [4, 7, -18], [54, 6, -8], [-31, 9, 13], [19, -19, -11], [-24, 15, -2], [-4, 10, -18], [40, 7, -10], [-2, 0, 12], [62, -10, 12], [4, 2, 20], [48, -16, 16], [4, -8, 22], [-22, 15, -8], [-26, 18, -2], [17, 22, -3], [-6, -9, 10], [-19, -9, 13], [-3, -8, -3], [43, -15, 25], [-34, -22, 6], [43, 5, -3], [18, 26, -12], [-1, -1, 11], [9, -1, -23], [-24, -2, 4], [0, -27, 12], [-56, -3, -8], [37, 3, 3], [-1, -13, 7], [-34, 9, 8], [-6, 7, 8], [12, 1, -14], [43, -9, 17], [8, -18, 2], [5, -10, -15], [-11, 17, -19], [3, -5, 25], [19, 12, -5], [-37, 1, 1], [-34, 10, -2], [-49, 17, -11], [28, -4, -8], [22, 12, 8], [13, -21, 13], [-10, 22, -10], [28, -7, 8], [-32, 18, -24], [-2, 34, -16], [20, -5, -4], [-20, 6, -16], [-10, 10, -4], [12, 20, 2], [-55, -3, 1], [-12, -24, 0], [-13, 8, -5], [-6, -12, -10], [-12, 15, -24], [18, -4, -4], [2, -28, 6], [-39, 9, 5], [6, -27, 16], [0, -22, 14], [-34, -16, 4], [-14, 8, -26], [-6, -18, -4], [22, 18, -6], [5, -5, -11], [25, -6, 3], [43, 5, 9], [12, -3, 6], [4, -1, 16], [51, -5, 7], [-8, 16, 0], [22, -13, -6], [9, 16, -11], [32, 24, -6], [34, 12, 0], [22, -23, 10], [9, 12, -1], [42, 5, -10], [27, 1, 19], [-10, 14, -2], [49, -19, 25], [28, -6, 14], [-18, 5, 0], [16, -14, 4], [-6, -16, 8], [-27, 11, 11], [42, -14, 14], [18, 1, 12], [-36, 14, -8], [-22, 8, -16], [-18, -18, 14], [24, -6, -14], [-44, 6, 4], [-60, -10, 2], [10, -6, 0], [-42, 13, -6], [-6, 10, -22], [-36, 6, -10], [-2, 18, -8], [27, 22, -15], [-2, -3, -14], [-16, -2, -6], [-15, 11, -15], [28, 9, 10], [56, -4, 18], [46, 5, -2], [-19, 19, 5], [26, -11, -4], [-25, 25, -3], [-12, 26, -14], [-2, 14, -2], [0, -24, 8], [31, -27, 33], [48, -6, -4], [-54, 14, -20], [-9, -3, -23], [15, 8, 9], [27, 5, -5], [-62, 6, -12], [-11, 17, 15], [13, -13, 13], [-41, -2, 11], [8, -11, 6], [-27, 10, -33]];
    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_bd();".
// 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_bd(:prec:=3)
    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_bd();".
// 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_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2736_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-8, -10, 1, 1]>,<7,R![-16, -5, 4, 1]>,<11,R![-8, -2, 5, 1]>,<13,R![8, -2, -5, 1]>],Snew);
    return Vf;
end function;