
// Make newform 135.4.e.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_135_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_135_e_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_135_4_e_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_135_4_e_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 := [9, -39, 52, -27, 16, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-4, 1, -1, 0, 0, 0], [9, -9, 10, -2, 1, 0], [-39, 88, -40, 30, -5, 2], [147, -334, 157, -117, 20, -8], [-81, 198, -92, 72, -12, 5]];
    Rf_basisdens := [1, 1, 1, 3, 3, 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_135_e();"
function MakeCharacter_135_e()
    N := 135;
    order := 3;
    char_gens := [56, 82];
    v := [2, 3];
    // 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_135_e_Hecke();"
function MakeCharacter_135_e_Hecke(Kf)
    N := 135;
    order := 3;
    char_gens := [56, 82];
    char_values := [[0, 0, 0, 1, 0, 0], [1, 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, -1, 0, 0, -1, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, -5, 0, 0], [14, -1, 0, 14, -1, 2], [0, 11, 0, 0, 11, 3], [0, 0, 1, 18, -13, -1], [56, -3, 1, 0, 0, 0], [-58, 7, 3, 0, 0, 0], [0, 0, -12, -60, -3, 12], [-107, -4, 0, -107, -4, -10], [0, 0, -11, -138, 51, 11], [126, 7, 17, 0, 0, 0], [0, 0, 23, -49, -17, -23], [198, 37, 0, 198, 37, -29], [202, 54, 0, 202, 54, 5], [220, 62, 8, 0, 0, 0], [0, 0, 36, 72, 118, -36], [473, 45, 0, 473, 45, -25], [0, 0, 7, -630, 48, -7], [2, 7, -83, 0, 0, 0], [-108, 20, -64, 0, 0, 0], [90, 48, 0, 90, 48, 64], [-242, 13, 0, -242, 13, -118], [-629, 88, 80, 0, 0, 0], [120, -58, 0, 120, -58, -20], [-68, -20, 0, -68, -20, 38], [0, 0, 19, -822, -113, -19], [-298, 179, -164, 0, 0, 0], [-429, -287, 41, 0, 0, 0], [0, 0, -84, -450, 178, 84], [-1018, 16, 15, 0, 0, 0], [0, 0, -240, 402, 108, 240], [-242, -368, 0, -242, -368, -70], [0, 0, 8, -152, -424, -8], [0, 0, 153, -1587, 143, -153], [600, -401, 0, 600, -401, 67], [0, 0, -22, 1672, -448, 22], [126, -191, -85, 0, 0, 0], [0, 0, 37, 2956, -236, -37], [-28, 86, 0, -28, 86, 106], [-1278, -53, 93, 0, 0, 0], [1319, 408, -102, 0, 0, 0], [404, -57, 0, 404, -57, -179], [0, 0, 363, -562, 369, -363], [1026, -1074, -36, 0, 0, 0], [-82, -209, -57, 0, 0, 0], [0, 0, 5, 40, -649, -5], [-500, -696, 0, -500, -696, 33], [-2020, 429, 0, -2020, 429, 133], [0, 0, 40, 489, 942, -40], [-530, -359, 347, 0, 0, 0], [0, 0, -336, -2766, -194, 336], [2909, -201, 0, 2909, -201, 239], [284, 1037, 115, 0, 0, 0], [0, 0, 152, 2498, -112, -152], [-1622, -397, 0, -1622, -397, 101], [-2007, 19, -189, 0, 0, 0], [-2582, 333, 73, 0, 0, 0], [1900, -533, 0, 1900, -533, 219], [-1881, -813, 0, -1881, -813, 375], [0, 0, -532, -1520, -179, 532], [0, 0, 343, 1228, -1223, -343], [-3208, 19, 216, 0, 0, 0], [0, 0, -723, -2916, 297, 723], [-3884, -1491, 0, -3884, -1491, 75], [-2056, -99, 0, -2056, -99, 151], [776, 1640, 0, 776, 1640, 14], [0, 0, 890, 82, -696, -890], [0, 0, 523, -2474, 887, -523], [761, 528, 0, 761, 528, -856], [5140, -236, 0, 5140, -236, -268], [1664, -475, -593, 0, 0, 0], [2786, -2413, 0, 2786, -2413, -595], [0, 0, 124, -2520, 1190, -124], [-3802, -974, -666, 0, 0, 0], [0, 0, -117, 6618, 183, 117], [1901, 857, 0, 1901, 857, -509], [-2546, -1032, -884, 0, 0, 0], [0, 0, 502, -3548, -1448, -502], [0, 0, 390, -1426, 1254, -390], [0, 0, -9, -2064, -1675, 9], [-1458, 2878, 0, -1458, 2878, -326], [4866, -42, -414, 0, 0, 0], [-2936, 2175, 151, 0, 0, 0], [-8298, 802, 0, -8298, 802, -296], [-3484, 1988, 0, -3484, 1988, -491], [-3892, 42, 844, 0, 0, 0], [122, -909, 0, 122, -909, 461], [3443, 2, 0, 3443, 2, -260], [0, 0, 287, -188, 985, -287], [-6330, 545, -1329, 0, 0, 0], [3986, 2174, 0, 3986, 2174, 130], [-4148, 3407, 943, 0, 0, 0], [0, 0, 178, -314, -4212, -178], [0, 0, -732, -5794, -2738, 732], [-3284, 2010, -553, 0, 0, 0], [0, 0, -196, 1997, 3132, 196], [2267, 1804, -818, 0, 0, 0], [12550, -3054, -587, 0, 0, 0], [12533, 2246, -882, 0, 0, 0], [-20, -3979, 0, -20, -3979, 456], [-354, 1488, 1404, 0, 0, 0], [0, 0, -139, -2872, 3440, 139], [7758, -4224, 0, 7758, -4224, -168], [0, 0, 1344, -6604, 72, -1344], [8196, -62, -784, 0, 0, 0], [9368, -5173, 0, 9368, -5173, -608], [2550, 5735, -1203, 0, 0, 0], [0, 0, 1546, 7558, 714, -1546], [3098, -3410, 0, 3098, -3410, -166], [0, 0, 2847, -3526, -2162, -2847], [10952, 127, -813, 0, 0, 0], [0, 0, -128, -5726, -2294, 128], [-366, 3599, 0, -366, 3599, 1135], [-9706, -2546, -792, 0, 0, 0], [-11133, 2037, 0, -11133, 2037, 1053], [0, 0, -15, 4952, 4742, 15], [12932, -3996, 43, 0, 0, 0], [0, 0, 561, 19914, -1759, -561], [-10970, -3534, 0, -10970, -3534, 548], [0, 0, -588, 12566, 1240, 588], [-444, -5613, 0, -444, -5613, -671], [14844, -1251, 0, 14844, -1251, -1209], [-4906, -3745, -1247, 0, 0, 0], [-3274, -834, 0, -3274, -834, -1822], [-7851, 971, 825, 0, 0, 0], [-4945, -3612, 0, -4945, -3612, -2206], [-14512, 2546, 316, 0, 0, 0], [-10410, 8, 0, -10410, 8, -431], [0, 0, -328, 18994, -2392, 328], [-22432, -2132, 414, 0, 0, 0], [0, 0, 1854, 4506, -3563, -1854], [0, 0, 519, -5206, 5467, -519], [14146, 249, 2893, 0, 0, 0], [0, 0, -568, -5881, -4078, 568], [0, 0, -1848, 17423, -1146, 1848], [11260, -7256, -1540, 0, 0, 0], [0, 0, -1383, -9766, -191, 1383], [0, 0, -2635, -10744, 5329, 2635], [19632, -1972, -1566, 0, 0, 0], [-24170, 4036, 556, 0, 0, 0], [17811, -7287, 0, 17811, -7287, -321], [0, 0, 27, 4502, 3264, -27], [-24160, -858, 319, 0, 0, 0], [14221, -3881, -971, 0, 0, 0], [-1066, -6213, 0, -1066, -6213, 2995], [-13848, 6915, 0, -13848, 6915, 1957], [2282, 3151, 0, 2282, 3151, -1541], [0, 0, 1279, -12318, -853, -1279], [3016, 6876, 1469, 0, 0, 0], [0, 0, -1657, 334, -4235, 1657], [-21489, 3103, 237, 0, 0, 0], [-17144, -4084, 1045, 0, 0, 0], [0, 0, 689, -9958, -1123, -689], [12688, 6808, 0, 12688, 6808, -1155], [-17480, -3360, 0, -17480, -3360, -2758], [35550, 410, -982, 0, 0, 0], [8346, 6550, 0, 8346, 6550, 438], [-7414, 2978, -24, 0, 0, 0], [0, 0, 4226, -4639, 5632, -4226], [4646, -364, 0, 4646, -364, -2543], [23616, -221, 3933, 0, 0, 0], [0, 0, -660, 10952, -2055, 660], [10158, -5169, 675, 0, 0, 0], [0, 0, -2447, -6068, -6907, 2447], [-20348, 1729, 0, -20348, 1729, -3634], [44, -8496, 354, 0, 0, 0], [1136, 2690, 0, 1136, 2690, -1816]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_135_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_135_4_e_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_135_4_e_b(:prec:=6)
    chi := MakeCharacter_135_e();
    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_135_4_e_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_135_4_e_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_135_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![9, 51, 292, -11, 18, 1, 1]>],Snew);
    return Vf;
end function;