
// Make newform 114.4.e.e in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_114_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_114_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_114_4_e_e();".
// 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_114_4_e_e();".
// 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 := [1, -7, 50, 5, 8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-2525, 70, -500, 116, -80, 10], [161, -1936, -544, -184, 23, -52], [-8, -2750, -344, -440, 55, -56], [-289, -1978, -244, -568, 71, -58], [-148, -52840, -6364, -8140, 821, -1036]];
    Rf_basisdens := [1, 131, 393, 393, 393, 393];
    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_114_e();"
function MakeCharacter_114_e()
    N := 114;
    order := 3;
    char_gens := [77, 97];
    v := [3, 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_114_e_Hecke();"
function MakeCharacter_114_e_Hecke(Kf)
    N := 114;
    order := 3;
    char_gens := [77, 97];
    char_values := [[1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 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 := [[2, 0, 0, 2, 0, 0], [3, 0, 0, 3, 0, 0], [-1, 1, 0, -1, 0, -1], [-6, 1, 2, 0, -2, 0], [-18, 2, -1, 0, 1, 0], [2, 0, 2, 23, 4, 0], [16, -3, -2, 18, -1, 3], [48, -2, -2, 58, 3, -3], [-10, 0, -10, -71, -20, -5], [13, 0, 13, -16, 26, -1], [33, 8, 3, 0, -3, 0], [94, 23, 13, 0, -13, 0], [-30, -4, -52, 22, -26, 4], [90, 7, -36, 126, -18, -7], [18, 0, 18, -278, 36, -14], [-13, 0, -13, -17, -26, 28], [-291, 9, 48, -339, 24, -9], [-2, 0, -2, -121, -4, 30], [-5, 0, -5, 34, -10, 26], [-336, 31, -2, -334, -1, -31], [-75, 14, -80, 5, -40, -14], [144, 18, 86, 58, 43, -18], [-709, -21, 17, 0, -17, 0], [-1, 0, -1, 381, -2, 24], [-470, 7, -14, -456, -7, -7], [59, 0, 59, 16, 118, -5], [-580, -5, 46, 0, -46, 0], [-137, -67, -81, 0, 81, 0], [148, -7, 2, 146, 1, 7], [-56, 44, 51, 0, -51, 0], [-28, 0, -28, 910, -56, -94], [880, -39, 130, 750, 65, 39], [-9, 0, -9, -1846, -18, 53], [-28, 0, -28, 1132, -56, 5], [181, -81, -188, 369, -94, 81], [860, -84, -126, 0, 126, 0], [-1905, -149, -18, -1887, -9, 149], [521, -66, 33, 0, -33, 0], [120, 0, 120, -3, 240, 63], [-2138, 105, -110, -2028, -55, -105], [545, 159, -112, 0, 112, 0], [-119, 0, -119, -1464, -238, 49], [680, -170, 15, 0, -15, 0], [657, 17, 430, 227, 215, -17], [784, -76, 57, 0, -57, 0], [223, 0, 223, 776, 446, 126], [-442, 47, 24, -466, 12, -47], [3282, 54, -70, 3352, -35, -54], [-3260, 166, 185, 0, -185, 0], [-1101, 42, -332, 0, 332, 0], [1418, 159, 458, 960, 229, -159], [-2452, 6, 107, 0, -107, 0], [82, 0, 82, 2667, 164, -200], [288, 0, 288, -1436, 576, 82], [297, 0, 297, -191, 594, -272], [-3716, 33, -86, -3630, -43, -33], [761, 30, -562, 1323, -281, -30], [-4664, -164, -104, -4560, -52, 164], [1195, -55, -29, 0, 29, 0], [30, 0, 30, 125, 60, -1], [-620, 80, -256, -364, -128, -80], [-1250, 480, 508, 0, -508, 0], [244, -61, -910, 1154, -455, 61], [-3607, -191, 24, 0, -24, 0], [-255, 0, -255, 1826, -510, -165], [220, 0, 220, 3699, 440, 219], [3136, -123, -574, 0, 574, 0], [4141, 79, 22, 4119, 11, -79], [-2661, 278, -538, -2123, -269, -278], [1267, -388, -98, 0, 98, 0], [-1053, 489, 72, 0, -72, 0], [-868, -228, 440, -1308, 220, 228], [239, 0, 239, 5268, 478, -284], [-3121, 441, -369, 0, 369, 0], [8286, 163, 266, 0, -266, 0], [171, 398, 1154, -983, 577, -398], [179, 0, 179, -885, 358, 132], [-2841, 552, 1604, -4445, 802, -552], [-10865, 122, 42, -10907, 21, -122], [85, 0, 85, 5670, 170, -161], [-3904, 588, 11, 0, -11, 0], [-10292, 297, 186, -10478, 93, -297], [-368, 0, -368, -5274, -736, 564], [-223, 0, -223, 8555, -446, 99], [2098, -363, -1416, 3514, -708, 363], [55, 0, 55, 12536, 110, -67], [10679, 151, -129, 0, 129, 0], [-3222, -99, -155, 0, 155, 0], [8781, -296, 394, 8387, 197, 296], [-2160, 557, 510, 0, -510, 0], [4996, 400, 686, 0, -686, 0], [125, 0, 125, 5138, 250, -889], [7402, -346, -656, 0, 656, 0], [-1948, 109, 42, -1990, 21, -109], [-5672, -110, 190, -5862, 95, 110], [133, 0, 133, -16068, 266, 147], [-290, 0, -290, 6330, -580, -726], [5289, -91, 338, 0, -338, 0], [-479, 0, -479, 7028, -958, -552], [-111, 0, -111, -3691, -222, 675], [782, 0, 782, 2298, 1564, 463], [-395, 0, -395, -9550, -790, 287], [3785, 51, -379, 0, 379, 0], [-8400, -380, 370, 0, -370, 0], [10991, -306, 327, 0, -327, 0], [7241, -897, 231, 0, -231, 0], [-9575, 213, -680, -8895, -340, -213], [-413, 0, -413, 6635, -826, 74], [1503, 0, 1503, -2907, 3006, -96], [3024, -235, 897, 0, -897, 0], [4289, 228, 513, 0, -513, 0], [-9122, 295, -2006, -7116, -1003, -295], [-138, 0, -138, -13035, -276, 513], [-10411, -700, 473, 0, -473, 0], [-780, 0, -780, -4288, -1560, 501], [-1044, -816, 564, -1608, 282, 816], [5728, 664, 178, 5550, 89, -664], [-3641, -733, -669, 0, 669, 0], [1673, -237, 497, 0, -497, 0], [-195, 0, -195, 1849, -390, -1082], [-932, 0, -932, 8214, -1864, -56], [-14280, 513, 181, 0, -181, 0], [-1840, -2, 894, 0, -894, 0], [-6538, 40, 633, 0, -633, 0], [3600, 820, -580, 0, 580, 0], [1513, -1541, -784, 2297, -392, 1541], [-1068, 0, -1068, -8495, -2136, -148], [-2241, 1325, 1904, -4145, 952, -1325], [-14516, 334, 790, -15306, 395, -334], [-5127, 799, 1769, 0, -1769, 0], [-4636, -1050, -230, -4406, -115, 1050], [-5511, -902, 862, -6373, 431, 902], [-786, 0, -786, 13610, -1572, 777], [3371, -1868, -1720, 5091, -860, 1868], [5958, -486, -1437, 0, 1437, 0], [858, 0, 858, -5145, 1716, 1378], [-490, 0, -490, 14364, -980, 984], [-24919, 680, 1637, 0, -1637, 0], [-22141, 825, -961, 0, 961, 0], [15455, 429, 38, 0, -38, 0], [-46, 0, -46, 2050, -92, 1676], [897, 0, 897, 8892, 1794, 159], [-1440, 0, -1440, -6574, -2880, 1182], [257, 0, 257, -11336, 514, -473], [1903, -554, -1050, 0, 1050, 0], [19189, 1246, 2906, 16283, 1453, -1246], [-4227, -1873, -2870, -1357, -1435, 1873], [-938, -396, -4136, 3198, -2068, 396], [1315, 0, 1315, -6414, 2630, -866], [-27394, 288, -1408, 0, 1408, 0], [-6227, 1273, 1054, -7281, 527, -1273], [39985, -393, 790, 0, -790, 0], [36, 0, 36, -426, 72, 553], [1452, 0, 1452, 16913, 2904, 395], [-11732, 1512, 240, -11972, 120, -1512], [9876, -276, -1590, 0, 1590, 0], [21650, 351, 1464, 0, -1464, 0], [8969, -395, 1596, 7373, 798, 395], [-1959, 0, -1959, 5621, -3918, 285], [-1250, 0, -1250, 36536, -2500, 746], [36368, -465, 182, 36186, 91, 465], [-933, 295, -4664, 3731, -2332, -295], [-27420, 998, 3610, -31030, 1805, -998], [-98, 2320, 3104, -3202, 1552, -2320], [3010, -1600, 2274, 0, -2274, 0], [-2365, 84, 3758, -6123, 1879, -84], [542, -188, 3314, -2772, 1657, 188], [973, 0, 973, 19947, 1946, -2441]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_114_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_114_4_e_e();".
// 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_114_4_e_e(:prec:=6)
    chi := MakeCharacter_114_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_114_4_e_e();".
// 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_114_4_e_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_114_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![1871424, -410400, 87264, -3336, 304, 2, 1]>],Snew);
    return Vf;
end function;