
// Make newform 136.4.a.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_136_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_136_4_a_d();".
// 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_136_4_a_d();".
// 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 := [20, 19, -15, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-2, -10, 1, 1], [-9, 3, 1, 0], [-8, -1, 1, 0]];
    Rf_basisdens := [1, 1, 1, 1];
    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_136_a();"
function MakeCharacter_136_a()
    N := 136;
    order := 1;
    char_gens := [103, 69, 105];
    v := [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_136_a_Hecke(Kf)
    return MakeCharacter_136_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 := 4;
    raw_aps := [[0, 0, 0, 0], [0, -1, 0, 0], [1, -1, -1, -2], [-4, -2, 0, 1], [18, 1, -2, 4], [27, 5, -5, 4], [-17, 0, 0, 0], [-20, -4, -8, -14], [34, 14, -14, 17], [83, -15, 21, -2], [26, 4, 10, -15], [75, -23, 1, -2], [48, -2, -26, 0], [-274, -12, -10, 0], [-198, 26, 14, 16], [130, -28, 24, -8], [-82, 48, -10, -32], [-221, 9, -23, -46], [-256, 58, 12, 50], [236, 24, 48, 49], [-378, 8, 36, -12], [210, -46, 34, -39], [34, 48, -38, 32], [283, 57, -29, -68], [-262, -28, -28, 148], [351, -71, 71, -116], [916, -16, -12, 24], [148, -71, 84, 14], [641, 31, 95, -62], [200, -258, 26, 20], [-456, 80, -96, 46], [520, -95, 56, -242], [5, -145, 189, -144], [50, 163, 118, 92], [-762, 208, -120, 40], [-272, 28, -48, -174], [-388, 126, -238, -92], [-798, -121, 166, -206], [88, -110, 12, 7], [2451, -207, 237, 90], [604, 316, -136, 114], [-1669, -215, -15, -146], [1134, -206, -86, 176], [1324, -90, -190, 24], [85, 307, -25, 566], [-2454, 86, -126, 211], [-2440, -141, 64, -2], [390, -134, 394, -170], [2126, -1, 362, -438], [-461, -195, -105, -120], [580, 46, 46, 136], [2802, -274, -90, -452], [4280, -54, 102, -148], [-2200, -354, 156, -58], [2319, -15, -261, 176], [852, 348, 12, -382], [2553, 119, 223, -26], [2374, -654, 210, 148], [-4173, 161, 285, 258], [400, -190, 398, 356], [-3646, 181, -98, -304], [2162, -540, -164, -168], [-1914, 74, 302, 520], [-2748, -370, -160, -557], [-1620, 434, 98, 196], [-2267, 883, -89, -134], [-5298, -176, 54, 492], [-230, 200, 528, -284], [-714, -321, -198, -966], [3054, 624, 236, -104], [-1008, 114, -66, 420], [1366, 78, -238, 66], [4172, -760, 696, 391], [275, -547, 683, 324], [3552, -77, 808, 340], [948, 736, 228, 662], [-3705, -839, 83, -928], [759, 157, 253, 1006], [-2168, -438, -402, -1348], [1542, 344, 368, 1432], [6444, 697, -452, 516], [2923, 389, 667, 580], [-1346, -386, 1142, -503], [3169, -609, -419, -908], [220, -460, -576, -435], [-1600, 1030, -700, 246], [-1606, -828, 628, -768], [5225, -449, -163, 740], [4294, 504, -428, -680], [2660, 636, -244, -88], [-8028, 108, 224, 826], [1106, 250, 954, 1263], [1376, 336, 596, 395], [644, 436, -488, 874], [40, -1489, 1040, -194], [-2624, 176, -892, 87], [4338, -92, 276, 1296], [-8796, 514, -1126, 1472], [1788, 126, 280, -1430], [4459, 545, -871, -442], [2584, -531, -616, -618], [-381, 1989, 131, 412], [2866, -1116, 1034, 408], [932, 1418, 950, 1572], [3132, 1329, -1500, 1852], [-2151, -605, 1729, -1472], [-4212, -432, 528, 1574], [12880, -258, -134, -204], [-6540, 884, -1532, -1808], [2114, 28, -696, -56], [-15182, 736, 578, 1121], [9466, 1060, -420, 1664], [-7424, -2070, -238, -1816], [11938, 63, 910, 398], [-1362, 646, -774, 1326], [12294, -1656, 2360, 916], [-13484, 2123, 1788, 872], [-3510, 678, -698, -1724], [-909, -1319, -851, 246], [11138, 710, 610, -240], [-4516, 262, -786, -340], [4158, 1512, -504, 2504], [-18955, -405, -201, 46], [-15204, -537, -852, 2520], [4834, -435, 438, 2028], [9323, -1619, -1141, -412], [-8209, 181, -727, 3166], [10000, -28, -2340, 169], [4878, 198, 1922, -1720], [-3996, -1090, 2398, -476], [11128, 612, -84, 2110], [3630, -1512, 646, -271], [-2884, -892, 1200, 1513], [-6777, 3161, -965, -472], [-1191, 2723, -103, 1776], [-15707, 583, -2411, -968], [2243, 221, -1985, 16], [5662, -45, -3678, 800], [5980, 2806, -186, 3092], [-16654, 96, 1444, -1516], [-2610, 349, 2298, -1586], [15921, -3625, -1765, -386], [23238, 1826, -290, 2365], [25060, 331, 988, -1078], [7632, 2874, -170, -1500], [2344, 2498, -380, 1141], [11005, -661, -1861, 1678], [14508, 178, 1106, 516], [-22206, -2220, -254, -3200], [-5896, -328, -2184, 2136], [-19611, 1835, -2997, -718], [854, -1428, -884, -1252], [-14072, -810, 1380, -270], [-10162, 3230, 174, 1971], [-21946, 1357, -2262, -1564], [9208, -790, -1516, -1851], [6474, 1490, -1738, -972], [5868, 2806, 442, -1468], [-8138, -1464, -2128, 1376], [16057, -569, -53, 1438], [-19186, 2619, -1854, -128], [18299, -431, 1547, -1092], [9746, -606, 1766, 870], [-22290, 348, -2858, -3100], [15524, -2934, 478, -2028], [6644, -3200, 328, -3967], [24192, -1692, -500, -231], [-1783, 647, -2413, -1386]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_136_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_136_4_a_d();".
// 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_136_4_a_d(:prec:=4)
    chi := MakeCharacter_136_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_136_4_a_d();".
// 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_136_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_136_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![2056, -40, -102, 2, 1]>],Snew);
    return Vf;
end function;