
// Make newform 189.4.e.e in Magma, downloaded from the LMFDB on 02 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_189_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_189_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_189_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_189_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 := [1633284, 0, 578934, 0, 154089, 0, 15564, 0, 1147, 0, 40, 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, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [24978356640, 0, 24062075973, 0, 2135188674, 0, 179112079, 0, 6246280, 0, 173197, 0], [0, -90404596638, 0, -24062075973, 0, -2135188674, 0, -179112079, 0, -6246280, 0, -173197], [91892207808, 0, 38255600898, 0, 4262422452, 0, 245835571, 0, 7516849, 0, 108403, 0], [0, -10924950600, 0, -177732738, 0, -47305323, 0, -6257731, 0, -352129, 0, -12280], [1332538101, 0, -23157360, 0, -6163560, 0, -1315609, 0, -45880, 0, -1600, 0], [35784531648, 0, -223032383550, 0, -37517061303, 0, -2984596505, 0, -113590439, 0, -2443778, 0], [0, -1521805596156, 0, -405043584426, 0, -45990857349, 0, -3015043198, 0, -105145360, 0, -2193901], [0, 12437477316, 0, -455621058, 0, -121268043, 0, -22045039, 0, -902689, 0, -31480], [0, 328730303880, 0, 87494815980, 0, 7118068149, 0, 651289540, 0, 22712800, 0, 777199], [-52512120288, 0, -19137502476, 0, -2556628047, 0, -222205510, 0, -8654518, 0, -235927, 0]];
    Rf_basisdens := [1, 1, 65426239998, 65426239998, 14539164444, 1842992676, 153582723, 130852479996, 130852479996, 1842992676, 43617493332, 6231070476];
    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_189_e();"
function MakeCharacter_189_e()
    N := 189;
    order := 3;
    char_gens := [29, 136];
    v := [3, 2];
    // 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_189_e_Hecke();"
function MakeCharacter_189_e_Hecke(Kf)
    N := 189;
    order := 3;
    char_gens := [29, 136];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 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]];
    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, -1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0], [-5, 0, -5, 0, 0, 0, -1, 1, 0, 0, 0, 2], [0, 4, 0, 0, 0, 2, 0, 0, 0, -1, 0, 0], [6, 0, 0, 0, -5, 0, -3, 0, 0, 0, 0, -5], [0, -4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0], [11, 0, -3, 0, -11, 0, 11, -11, 0, 0, 0, 11], [0, 0, 0, 10, 0, 0, 0, 0, -6, 0, -4, 0], [0, -2, 0, -2, 0, -2, 0, 0, -9, -9, -2, 0], [15, 0, 26, 0, -24, 0, -11, -2, 0, 0, 0, 13], [-12, 0, -197, 0, 12, 0, -12, 11, 0, 0, 0, -13], [0, -52, 0, -52, 0, -4, 0, 0, -15, -15, -4, 0], [-255, 0, 0, 0, 8, 0, 10, 0, 0, 0, 0, 8], [0, 0, 0, -26, 0, 0, 0, 0, 29, 0, -14, 0], [0, 26, 0, 0, 0, -12, 0, 0, 0, 8, 0, 0], [0, -40, 0, 0, 0, 26, 0, 0, 0, -23, 0, 0], [-1, 0, 126, 0, 1, 0, -1, -62, 0, 0, 0, -64], [396, 0, 342, 0, 35, 0, 54, -73, 0, 0, 0, 19], [0, -12, 0, -12, 0, 18, 0, 0, -51, -51, 18, 0], [423, 0, 443, 0, -75, 0, -20, -35, 0, 0, 0, 55], [-64, 0, 101, 0, 64, 0, -64, 3, 0, 0, 0, -125], [0, -318, 0, -318, 0, 14, 0, 0, -28, -28, 14, 0], [0, 0, 0, -174, 0, 0, 0, 0, -51, 0, -26, 0], [-117, 0, 0, 0, 72, 0, -82, 0, 0, 0, 0, 72], [0, -156, 0, 0, 0, -18, 0, 0, 0, -23, 0, 0], [10, 0, -493, 0, -10, 0, 10, 3, 0, 0, 0, 23], [0, 0, 0, 246, 0, 0, 0, 0, 66, 0, -38, 0], [349, 0, 302, 0, 188, 0, 47, 94, 0, 0, 0, -141], [0, 58, 0, 58, 0, 12, 0, 0, 161, 161, 12, 0], [456, 0, 0, 0, 3, 0, -202, 0, 0, 0, 0, 3], [0, 0, 0, 24, 0, 0, 0, 0, 38, 0, 90, 0], [0, 422, 0, 0, 0, -32, 0, 0, 0, 6, 0, 0], [171, 0, 0, 0, -120, 0, -85, 0, 0, 0, 0, -120], [0, 0, 0, 172, 0, 0, 0, 0, -9, 0, 56, 0], [1187, 0, 1186, 0, 80, 0, 1, 78, 0, 0, 0, -79], [-1870, 0, -1950, 0, 126, 0, 80, -34, 0, 0, 0, -46], [-126, 0, -1167, 0, 126, 0, -126, 274, 0, 0, 0, 22], [0, 94, 0, 94, 0, 102, 0, 0, -46, -46, 102, 0], [0, 0, 0, 656, 0, 0, 0, 0, 30, 0, 30, 0], [0, -474, 0, 0, 0, 74, 0, 0, 0, 45, 0, 0], [-616, 0, 0, 0, 38, 0, 161, 0, 0, 0, 0, 38], [0, 0, 0, -732, 0, 0, 0, 0, -149, 0, 20, 0], [1350, 0, 1510, 0, -359, 0, -160, -39, 0, 0, 0, 199], [0, 100, 0, 100, 0, 56, 0, 0, -26, -26, 56, 0], [205, 0, 230, 0, -136, 0, -25, -86, 0, 0, 0, 111], [-2949, 0, 0, 0, 118, 0, -84, 0, 0, 0, 0, 118], [1106, 0, 0, 0, 2, 0, 500, 0, 0, 0, 0, 2], [0, 146, 0, 0, 0, -8, 0, 0, 0, 0, 0, 0], [487, 0, -1222, 0, -487, 0, 487, -744, 0, 0, 0, 230], [0, 0, 0, -572, 0, 0, 0, 0, 28, 0, 150, 0], [0, 768, 0, 768, 0, 52, 0, 0, -437, -437, 52, 0], [-745, 0, -809, 0, -124, 0, 64, -252, 0, 0, 0, 188], [0, 1606, 0, 1606, 0, -52, 0, 0, 124, 124, -52, 0], [0, 0, 0, 518, 0, 0, 0, 0, 220, 0, -62, 0], [0, 226, 0, 0, 0, -184, 0, 0, 0, -139, 0, 0], [0, -832, 0, 0, 0, -120, 0, 0, 0, -34, 0, 0], [-651, 0, 1488, 0, 651, 0, -651, 1138, 0, 0, 0, -164], [3977, 0, 4116, 0, -114, 0, -139, 164, 0, 0, 0, -25], [0, 1094, 0, 1094, 0, -144, 0, 0, 157, 157, -144, 0], [2049, 0, 2151, 0, 146, 0, -102, 350, 0, 0, 0, -248], [0, 314, 0, 314, 0, -100, 0, 0, 315, 315, -100, 0], [2433, 0, 0, 0, 16, 0, -168, 0, 0, 0, 0, 16], [0, 380, 0, 0, 0, -46, 0, 0, 0, -281, 0, 0], [253, 0, 1313, 0, -253, 0, 253, -315, 0, 0, 0, 191], [0, 0, 0, -1946, 0, 0, 0, 0, 101, 0, 28, 0], [271, 0, -3163, 0, -271, 0, 271, -201, 0, 0, 0, 341], [-5188, 0, 0, 0, -700, 0, -901, 0, 0, 0, 0, -700], [0, -1068, 0, 0, 0, -8, 0, 0, 0, 332, 0, 0], [-3060, 0, 0, 0, 43, 0, 222, 0, 0, 0, 0, 43], [0, -164, 0, 0, 0, 80, 0, 0, 0, 452, 0, 0], [0, 0, 0, -1462, 0, 0, 0, 0, -754, 0, -226, 0], [-3755, 0, -3337, 0, -493, 0, -418, 343, 0, 0, 0, 75], [321, 0, -5581, 0, -321, 0, 321, -585, 0, 0, 0, 57], [4539, 0, 0, 0, 348, 0, 767, 0, 0, 0, 0, 348], [0, 0, 0, 490, 0, 0, 0, 0, -390, 0, 146, 0], [0, 908, 0, 0, 0, 202, 0, 0, 0, -372, 0, 0], [27, 0, 1762, 0, -27, 0, 27, -298, 0, 0, 0, -244], [0, 0, 0, 400, 0, 0, 0, 0, 513, 0, 86, 0], [3270, 0, 4096, 0, -1823, 0, -826, -171, 0, 0, 0, 997], [0, -1362, 0, -1362, 0, -386, 0, 0, 751, 751, -386, 0], [2804, 0, 0, 0, -402, 0, -783, 0, 0, 0, 0, -402], [0, -406, 0, 0, 0, -324, 0, 0, 0, -367, 0, 0], [1245, 0, 0, 0, -44, 0, 222, 0, 0, 0, 0, -44], [-1088, 0, 5020, 0, 1088, 0, -1088, 1016, 0, 0, 0, -1160], [0, 0, 0, -572, 0, 0, 0, 0, 560, 0, 178, 0], [0, 738, 0, 738, 0, 174, 0, 0, -249, -249, 174, 0], [-328, 0, -2757, 0, 328, 0, -328, -722, 0, 0, 0, -1378], [0, -2098, 0, -2098, 0, 36, 0, 0, 415, 415, 36, 0], [2804, 0, 0, 0, 74, 0, -73, 0, 0, 0, 0, 74], [0, 0, 0, -218, 0, 0, 0, 0, 49, 0, -60, 0], [0, -1200, 0, 0, 0, -96, 0, 0, 0, -335, 0, 0], [3153, 0, 2643, 0, 809, 0, 510, -211, 0, 0, 0, -299], [0, 902, 0, 902, 0, -130, 0, 0, -582, -582, -130, 0], [-1556, 0, 651, 0, 1556, 0, -1556, 1768, 0, 0, 0, -1344], [0, -690, 0, -690, 0, 168, 0, 0, 786, 786, 168, 0], [0, 0, 0, -454, 0, 0, 0, 0, 640, 0, -218, 0], [0, -2626, 0, 0, 0, -210, 0, 0, 0, 1292, 0, 0], [-507, 0, 4584, 0, 507, 0, -507, 1723, 0, 0, 0, 709], [-667, 0, -1519, 0, 667, 0, -667, 39, 0, 0, 0, -1295], [9633, 0, 0, 0, -410, 0, -666, 0, 0, 0, 0, -410], [0, 2584, 0, 0, 0, -260, 0, 0, 0, 1, 0, 0], [0, -974, 0, 0, 0, 144, 0, 0, 0, -582, 0, 0], [0, 0, 0, 2778, 0, 0, 0, 0, -1043, 0, 152, 0], [-217, 0, -263, 0, -1981, 0, 46, -2073, 0, 0, 0, 2027], [-4742, 0, -5076, 0, -305, 0, 334, -973, 0, 0, 0, 639], [0, 226, 0, 226, 0, 766, 0, 0, 99, 99, 766, 0], [0, 0, 0, 1390, 0, 0, 0, 0, -173, 0, 552, 0], [0, 1868, 0, 0, 0, 554, 0, 0, 0, -476, 0, 0], [-12597, 0, 0, 0, 618, 0, -646, 0, 0, 0, 0, 618], [-2061, 0, 731, 0, 2061, 0, -2061, 2109, 0, 0, 0, -2013], [4915, 0, 5622, 0, -2462, 0, -707, -1048, 0, 0, 0, 1755], [0, 900, 0, 900, 0, 142, 0, 0, -137, -137, 142, 0], [-412, 0, 90, 0, -915, 0, -502, 89, 0, 0, 0, 413], [-2802, 0, 0, 0, -103, 0, 718, 0, 0, 0, 0, -103], [0, 212, 0, 0, 0, 184, 0, 0, 0, -1413, 0, 0], [-615, 0, 0, 0, 770, 0, -380, 0, 0, 0, 0, 770], [0, -2532, 0, 0, 0, -268, 0, 0, 0, -390, 0, 0], [0, 0, 0, 2206, 0, 0, 0, 0, 24, 0, -64, 0], [0, -2106, 0, -2106, 0, -586, 0, 0, 431, 431, -586, 0], [8009, 0, 6525, 0, 177, 0, 1484, -2791, 0, 0, 0, 1307], [-1360, 0, 0, 0, 836, 0, 3665, 0, 0, 0, 0, 836], [0, 0, 0, -968, 0, 0, 0, 0, -922, 0, 928, 0], [0, 2750, 0, 0, 0, 204, 0, 0, 0, -169, 0, 0], [1568, 0, 5693, 0, -1568, 0, 1568, -2856, 0, 0, 0, 280], [0, -2316, 0, -2316, 0, -234, 0, 0, 66, 66, -234, 0], [1013, 0, -6242, 0, -1013, 0, 1013, 554, 0, 0, 0, 2580], [0, 0, 0, -428, 0, 0, 0, 0, -1199, 0, 534, 0], [-6684, 0, 0, 0, -697, 0, -2024, 0, 0, 0, 0, -697], [1345, 0, -13178, 0, -1345, 0, 1345, -190, 0, 0, 0, 2500], [-19571, 0, -19429, 0, 734, 0, -142, 1018, 0, 0, 0, -876], [0, 2934, 0, 2934, 0, 610, 0, 0, -299, -299, 610, 0], [-2661, 0, 4311, 0, 2661, 0, -2661, 3259, 0, 0, 0, -2063], [-11388, 0, 0, 0, 1049, 0, -1226, 0, 0, 0, 0, 1049], [0, 0, 0, -2684, 0, 0, 0, 0, 1008, 0, -604, 0], [-7906, 0, 0, 0, -528, 0, -1305, 0, 0, 0, 0, -528], [0, -2268, 0, 0, 0, 1322, 0, 0, 0, -486, 0, 0], [-12519, 0, -11889, 0, 1070, 0, -630, 2330, 0, 0, 0, -1700], [0, 682, 0, 682, 0, 984, 0, 0, -1579, -1579, 984, 0], [0, 3002, 0, 0, 0, 222, 0, 0, 0, 2018, 0, 0], [-22960, 0, 0, 0, -102, 0, 270, 0, 0, 0, 0, -102], [0, 0, 0, 338, 0, 0, 0, 0, 1338, 0, -1050, 0], [20535, 0, 18488, 0, 3222, 0, 2047, -872, 0, 0, 0, -1175], [0, -1368, 0, -1368, 0, -648, 0, 0, -1548, -1548, -648, 0], [1755, 0, 37, 0, 403, 0, 1718, -3033, 0, 0, 0, 1315], [0, 6838, 0, 6838, 0, -986, 0, 0, 960, 960, -986, 0], [3176, 0, 0, 0, -582, 0, -1533, 0, 0, 0, 0, -582], [0, 1270, 0, 0, 0, 728, 0, 0, 0, 1799, 0, 0], [3316, 0, 16649, 0, -3316, 0, 3316, -2988, 0, 0, 0, 3644], [0, 0, 0, -9512, 0, 0, 0, 0, -1934, 0, 102, 0], [-119, 0, -3540, 0, 119, 0, -119, 502, 0, 0, 0, 264], [0, 3114, 0, 3114, 0, -36, 0, 0, -2178, -2178, -36, 0], [6164, 0, 0, 0, -2454, 0, -2505, 0, 0, 0, 0, -2454], [0, 0, 0, 2534, 0, 0, 0, 0, 172, 0, 718, 0], [11732, 0, 13474, 0, -1549, 0, -1742, 1935, 0, 0, 0, -193], [0, -3606, 0, -3606, 0, -514, 0, 0, -2065, -2065, -514, 0], [-1923, 0, -8524, 0, 1923, 0, -1923, 2412, 0, 0, 0, -1434], [0, 0, 0, -1630, 0, 0, 0, 0, 2007, 0, -450, 0], [-11493, 0, 0, 0, 1296, 0, 4121, 0, 0, 0, 0, 1296], [0, 10926, 0, 0, 0, -320, 0, 0, 0, 1391, 0, 0], [0, 0, 0, 3344, 0, 0, 0, 0, -1203, 0, 1584, 0], [0, -1558, 0, -1558, 0, -488, 0, 0, 296, 296, -488, 0], [-924, 0, 0, 0, 4165, 0, 471, 0, 0, 0, 0, 4165], [0, 0, 0, -1724, 0, 0, 0, 0, 2248, 0, -294, 0], [0, -2170, 0, 0, 0, -778, 0, 0, 0, -308, 0, 0], [0, -1060, 0, 0, 0, -38, 0, 0, 0, -633, 0, 0], [8098, 0, 7885, 0, -1599, 0, 213, -2025, 0, 0, 0, 1812], [635, 0, -222, 0, 2382, 0, 857, 668, 0, 0, 0, -1525]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_189_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_189_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_189_4_e_e(:prec:=12)
    chi := MakeCharacter_189_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_189_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_189_4_e_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_189_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1633284, 0, 578934, 0, 154089, 0, 15564, 0, 1147, 0, 40, 0, 1]>,<13,R![-35818, -3211, -26, 1]>],Snew);
    return Vf;
end function;