
// Make newform 136.4.b.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_136_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_136_b_Hecke();"
// 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_b_b();".
// 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_b_b();".
// 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 := [1152, 0, 1780, 0, 756, 0, 95, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0, 0, 0], [0, -3402, 0, -2159, 0, -284, 0, -3], [17420, 0, 6158, 0, 327, 0, 3, 0], [0, 47900, 0, 33588, 0, 5485, 0, 59], [-22844, 0, -20634, 0, -3781, 0, -41, 0], [0, -15160, 0, -48702, 0, -9989, 0, -109], [35292, 0, 28386, 0, 4217, 0, 45, 0]];
    Rf_basisdens := [1, 1, 172, 172, 1032, 172, 1032, 172];
    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_b();"
function MakeCharacter_136_b()
    N := 136;
    order := 2;
    char_gens := [103, 69, 105];
    v := [2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_136_b_Hecke();"
function MakeCharacter_136_b_Hecke(Kf)
    N := 136;
    order := 2;
    char_gens := [103, 69, 105];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1, 0, 0, 0], [0, -1, -1, 0, -1, 0, 0, 0], [0, 0, -2, 0, 1, 0, 1, 0], [5, 0, 0, 0, 0, 0, 0, 1], [4, -2, -1, 1, -2, 0, 1, 0], [4, 0, 0, -2, 0, -1, 0, 1], [0, -5, 0, 0, 0, 0, 1, 0], [0, 0, 18, 0, 5, 0, -2, 0], [0, 5, 14, 0, -4, 0, 3, 0], [0, 4, -28, 0, 1, 0, 0, 0], [0, 4, 2, 0, -16, 0, -6, 0], [2, 0, 0, -2, 0, 3, 0, -1], [42, 0, 0, 2, 0, 1, 0, -3], [60, 0, 0, 6, 0, -7, 0, -3], [-10, 0, 0, 2, 0, -3, 0, 1], [0, -16, -74, 0, 5, 0, -6, 0], [-76, 0, 0, -6, 0, 1, 0, -9], [0, 29, -31, 0, 27, 0, -6, 0], [0, 20, -6, 0, -26, 0, 6, 0], [0, -5, -64, 0, -16, 0, -11, 0], [298, 0, 0, 2, 0, -15, 0, 9], [23, 0, 0, 8, 0, 22, 0, 1], [0, -24, 140, 0, -22, 0, 16, 0], [161, 0, 0, -8, 0, 2, 0, -9], [152, 0, 0, 0, 0, -16, 0, -16], [0, -30, 15, 0, -4, 0, 2, 0], [0, -4, 2, 0, -69, 0, 18, 0], [0, -20, 74, 0, 58, 0, -6, 0], [156, 0, 0, 0, 0, -40, 0, -4], [0, 6, 91, 0, 64, 0, 10, 0], [-541, 0, 0, 0, 0, -17, 0, 22], [0, -4, -26, 0, 21, 0, 9, 0], [966, 0, 0, 32, 0, 26, 0, 2], [-648, 0, 0, 28, 0, 38, 0, -22], [1524, 0, 0, -10, 0, -3, 0, 17], [0, 26, -152, 0, -15, 0, 7, 0], [0, 11, 311, 0, 59, 0, -40, 0], [0, 36, -224, 0, -65, 0, -60, 0], [2344, 0, 0, 22, 0, 23, 0, -3], [0, 4, 54, 0, 5, 0, 22, 0], [810, 0, 0, 46, 0, -17, 0, -1], [0, 20, -202, 0, -72, 0, -22, 0], [0, 148, -58, 0, 161, 0, 6, 0], [0, 19, -132, 0, -116, 0, -43, 0], [0, -62, -221, 0, 20, 0, -22, 0], [-2446, 0, 0, 2, 0, -79, 0, 21], [0, -34, 308, 0, -135, 0, 35, 0], [-2551, 0, 0, -16, 0, -48, 0, 5], [0, 184, -200, 0, 88, 0, 36, 0], [182, 0, 0, -2, 0, -25, 0, -53], [0, 72, -104, 0, 158, 0, 36, 0], [1640, 0, 0, -26, 0, 67, 0, 17], [-2681, 0, 0, -24, 0, -23, 0, -52], [-388, 0, 0, 32, 0, -32, 0, 92], [0, 104, -522, 0, -19, 0, -78, 0], [378, 0, 0, -34, 0, -33, 0, -1], [0, -140, -410, 0, 25, 0, 142, 0], [2094, 0, 0, 0, 0, 13, 0, -7], [0, 236, 250, 0, -15, 0, -27, 0], [4206, 0, 0, -64, 0, 12, 0, -68], [1842, 0, 0, -30, 0, -63, 0, -15], [0, -5, -49, 0, -429, 0, -24, 0], [0, -344, -112, 0, -302, 0, 80, 0], [0, -56, -222, 0, 117, 0, 78, 0], [-3870, 0, 0, 94, 0, 99, 0, -97], [0, -28, -406, 0, -322, 0, -14, 0], [0, 150, 544, 0, 97, 0, 27, 0], [3012, 0, 0, -2, 0, -57, 0, -61], [5326, 0, 0, 96, 0, 53, 0, -7], [-7422, 0, 0, 58, 0, 45, 0, 33], [0, 49, 169, 0, -73, 0, 30, 0], [4369, 0, 0, -24, 0, 50, 0, 87], [0, 500, 349, 0, 220, 0, -200, 0], [6388, 0, 0, 100, 0, 186, 0, 114], [-1647, 0, 0, 8, 0, -2, 0, -109], [0, -244, -112, 0, 387, 0, 12, 0], [0, 128, 512, 0, 38, 0, 44, 0], [-2464, 0, 0, -22, 0, -272, 0, -88], [0, -60, 37, 0, 392, 0, -12, 0], [1593, 0, 0, -40, 0, 118, 0, 19], [0, 107, -208, 0, -328, 0, 101, 0], [-7933, 0, 0, 32, 0, 46, 0, 93], [0, -391, -1271, 0, 367, 0, 74, 0], [-284, 0, 0, 42, 0, 189, 0, -133], [0, 4, -646, 0, 480, 0, -186, 0], [-5193, 0, 0, -264, 0, 34, 0, 109], [1820, 0, 0, -42, 0, -209, 0, 107], [-736, 0, 0, 60, 0, -194, 0, -62], [1848, 0, 0, -254, 0, -167, 0, 83], [0, -285, -396, 0, -396, 0, 113, 0], [0, -455, -467, 0, 267, 0, 198, 0], [7548, 0, 0, -26, 0, -225, 0, 73], [0, 230, 483, 0, 672, 0, -118, 0], [0, -111, -303, 0, -489, 0, 98, 0], [5094, 0, 0, 136, 0, 94, 0, 22], [0, -380, -122, 0, -68, 0, 94, 0], [-3108, 0, 0, 62, 0, 83, 0, -155], [0, -372, -202, 0, -233, 0, -2, 0], [0, 582, -757, 0, 576, 0, 74, 0], [6469, 0, 0, 0, 0, -118, 0, -21], [1366, 0, 0, -126, 0, -243, 0, -103], [-6044, 0, 0, -46, 0, -71, 0, -107], [0, 76, -1651, 0, 236, 0, -200, 0], [2895, 0, 0, 144, 0, 257, 0, -44], [1632, 0, 0, -262, 0, 281, 0, -37], [-996, 0, 0, -142, 0, -135, 0, -315], [-11384, 0, 0, -208, 0, -200, 0, 72], [0, -184, 2704, 0, 328, 0, 84, 0], [0, 33, 1150, 0, -632, 0, 179, 0], [-4434, 0, 0, 120, 0, -14, 0, 234], [0, 80, -1676, 0, 128, 0, 184, 0], [0, -122, 1424, 0, 89, 0, -269, 0], [-8098, 0, 0, 286, 0, 39, 0, 155], [0, 176, 4, 0, -594, 0, -272, 0], [0, 60, 157, 0, 504, 0, -324, 0], [13374, 0, 0, -14, 0, -167, 0, -7], [0, 200, -444, 0, 1369, 0, 84, 0], [-7030, 0, 0, 170, 0, 21, 0, 37], [1662, 0, 0, 48, 0, -508, 0, -124], [0, -692, -990, 0, -528, 0, -386, 0], [0, -572, 16, 0, 525, 0, 332, 0], [0, 564, -859, 0, -540, 0, -248, 0], [0, 432, -710, 0, -1391, 0, 209, 0], [-3403, 0, 0, 160, 0, 542, 0, -193], [0, 408, 2276, 0, 351, 0, 412, 0], [0, -575, -1643, 0, -685, 0, -102, 0], [-3034, 0, 0, -306, 0, -329, 0, 147], [478, 0, 0, 128, 0, 538, 0, 34], [12132, 0, 0, -178, 0, -369, 0, -15], [0, 281, 370, 0, 1060, 0, -493, 0], [0, -59, 109, 0, 991, 0, -414, 0], [-16639, 0, 0, -176, 0, -42, 0, -29], [-7789, 0, 0, -280, 0, 295, 0, 294], [8383, 0, 0, 184, 0, 127, 0, -166], [5577, 0, 0, -416, 0, -416, 0, 69], [0, -84, 34, 0, 957, 0, -327, 0], [-5034, 0, 0, -328, 0, 290, 0, 282], [0, 440, -256, 0, 486, 0, 160, 0], [0, -726, 16, 0, -1019, 0, -125, 0], [0, -524, 1384, 0, -975, 0, 292, 0], [0, 163, 1180, 0, 380, 0, -99, 0], [0, 382, 2771, 0, 660, 0, -146, 0], [-11436, 0, 0, 318, 0, -261, 0, 327], [0, -193, 1667, 0, -709, 0, -460, 0], [0, -960, -404, 0, -453, 0, 516, 0], [0, 176, -1260, 0, 250, 0, -52, 0], [-6598, 0, 0, -166, 0, 549, 0, 205], [-4356, 0, 0, 600, 0, 260, 0, -240], [0, 988, -2978, 0, 495, 0, -66, 0], [0, -1356, -1238, 0, -1330, 0, -62, 0], [-13208, 0, 0, 278, 0, -201, 0, 61], [0, 687, 2312, 0, 156, 0, -71, 0], [0, 64, -1462, 0, 501, 0, 477, 0], [0, 491, -917, 0, -601, 0, -712, 0], [11482, 0, 0, -66, 0, 919, 0, 15], [0, -1128, 1828, 0, -146, 0, -464, 0], [14576, 0, 0, -278, 0, 38, 0, 94], [0, 1380, 2296, 0, 875, 0, -620, 0], [0, -556, -3758, 0, 989, 0, -183, 0], [-8425, 0, 0, 288, 0, -2, 0, -271], [-8854, 0, 0, 198, 0, -253, 0, -205], [20770, 0, 0, 42, 0, 549, 0, -155], [7492, 0, 0, 602, 0, 133, 0, -223], [0, 1365, -1235, 0, -177, 0, -386, 0], [0, -463, -1963, 0, 355, 0, 50, 0], [0, -308, -2194, 0, 629, 0, -458, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_136_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_136_4_b_b();".
// 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_b_b(:prec:=8)
    chi := MakeCharacter_136_b();
    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_b_b();".
// 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_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_136_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![373248, 0, 106624, 0, 8760, 0, 174, 0, 1]>],Snew);
    return Vf;
end function;