
// Make newform 289.4.b.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_289_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_289_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_289_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_289_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 := [2, -14, 49, -2, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [799, 0, -4, 28, 25, 4], [98, -684, 7, -49, -1, -7], [299, 0, 1, -7, 8, -1], [344, -2394, 49, -1, -7, -49], [1720, -11970, 587, -5, -35, -245]];
    Rf_basisdens := [1, 171, 342, 57, 171, 171];
    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_289_b();"
function MakeCharacter_289_b()
    N := 289;
    order := 2;
    char_gens := [3];
    v := [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_289_b_Hecke();"
function MakeCharacter_289_b_Hecke(Kf)
    N := 289;
    order := 2;
    char_gens := [3];
    char_values := [[-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, 0, 0], [0, 0, 1, 0, 1, -1], [0, 0, 0, 0, -1, -1], [0, 0, -1, 0, -3, -2], [0, 0, 11, 0, 5, -1], [12, 1, 0, -7, 0, 0], [0, 0, 0, 0, 0, 0], [-24, -15, 0, 7, 0, 0], [0, 0, -39, 0, -23, -2], [0, 0, 16, 0, -71, -15], [0, 0, -39, 0, 41, -8], [0, 0, 28, 0, 51, 25], [0, 0, -52, 0, 59, -30], [-204, 27, 0, 29, 0, 0], [228, -46, 0, 2, 0, 0], [-98, -62, 0, 54, 0, 0], [-212, 65, 0, -65, 0, 0], [0, 0, -64, 0, 1, 39], [292, 78, 0, 54, 0, 0], [0, 0, -185, 0, -55, -36], [0, 0, -16, 0, 137, 8], [0, 0, -267, 0, 69, 90], [756, 23, 0, 105, 0, 0], [-20, -193, 0, 83, 0, 0], [0, 0, -140, 0, -25, -60], [388, 65, 0, 33, 0, 0], [792, 150, 0, 74, 0, 0], [0, 0, 53, 0, -267, 49], [0, 0, 420, 0, -171, -31], [0, 0, 68, 0, 249, -94], [-1804, 89, 0, 151, 0, 0], [0, 0, 185, 0, -407, 89], [812, 35, 0, -357, 0, 0], [0, 0, 163, 0, 333, -285], [-34, 416, 0, 128, 0, 0], [-884, 141, 0, -213, 0, 0], [-550, -156, 0, -232, 0, 0], [0, 0, 167, 0, 101, -223], [0, 0, 235, 0, -283, 270], [0, 0, -420, 0, -55, 337], [-648, 209, 0, -217, 0, 0], [0, 0, -220, 0, 1437, 55], [-796, 412, 0, 40, 0, 0], [0, 0, -776, 0, 255, -6], [0, 0, 372, 0, -129, -67], [0, 0, -1203, 0, 65, 210], [0, 0, -271, 0, 1597, -203], [-1776, 557, 0, -49, 0, 0], [0, 0, -21, 0, 333, -279], [-168, -141, 0, -669, 0, 0], [0, 0, 916, 0, -1349, -210], [3412, -110, 0, 458, 0, 0], [0, 0, -708, 0, -1743, 234], [-564, 310, 0, -1226, 0, 0], [-2880, 183, 0, 423, 0, 0], [-2964, 607, 0, 281, 0, 0], [0, 0, 480, 0, 1211, -569], [2044, -638, 0, 98, 0, 0], [0, 0, -652, 0, -471, -719], [190, -352, 0, -356, 0, 0], [0, 0, -533, 0, 429, 731], [-202, -1160, 0, 848, 0, 0], [-1248, 886, 0, -386, 0, 0], [0, 0, -257, 0, -2307, 1178], [0, 0, 528, 0, -121, -338], [0, 0, 376, 0, -2421, 269], [-3196, -661, 0, -523, 0, 0], [0, 0, 1412, 0, 1129, -248], [0, 0, 1579, 0, 609, -183], [918, 190, 0, 418, 0, 0], [850, -352, 0, -956, 0, 0], [4952, -11, 0, -1, 0, 0], [0, 0, 1607, 0, 1905, -484], [-3356, -419, 0, -915, 0, 0], [0, 0, 2353, 0, -147, 35], [4612, 115, 0, -675, 0, 0], [-528, -1369, 0, -553, 0, 0], [0, 0, 2132, 0, -1363, -77], [0, 0, 316, 0, -3085, 1270], [-1450, -2424, 0, 744, 0, 0], [0, 0, 2025, 0, -535, 151], [-5988, -431, 0, 905, 0, 0], [0, 0, 309, 0, -207, 270], [5024, -1437, 0, 1439, 0, 0], [0, 0, 703, 0, 513, 168], [28, -226, 0, -1378, 0, 0], [0, 0, 1064, 0, -4227, -740], [1784, 3227, 0, -153, 0, 0], [4966, -2962, 0, -990, 0, 0], [4488, -2756, 0, 60, 0, 0], [-5640, 81, 0, -633, 0, 0], [0, 0, -1323, 0, -6015, 614], [0, 0, -1473, 0, -2683, -156], [-8112, -1263, 0, 1399, 0, 0], [0, 0, 2525, 0, -5639, -743], [0, 0, -3045, 0, 5049, 212], [6974, -1952, 0, -1176, 0, 0], [0, 0, -1100, 0, -4773, 478], [4948, 2382, 0, -514, 0, 0], [0, 0, 324, 0, 1887, 609], [0, 0, -1083, 0, 4205, 837], [4716, 1633, 0, 1849, 0, 0], [-11252, 437, 0, -541, 0, 0], [11090, 4016, 0, -1156, 0, 0], [0, 0, 1505, 0, 3165, 415], [11580, -717, 0, -365, 0, 0], [3360, -2371, 0, -1997, 0, 0], [586, 896, 0, 964, 0, 0], [13072, -1360, 0, -392, 0, 0], [0, 0, 4812, 0, 1471, -2620], [0, 0, 2165, 0, 7077, 1108], [-10514, 3564, 0, 1884, 0, 0], [0, 0, -2972, 0, -1985, 2730], [0, 0, 515, 0, 1685, 25], [-1216, 567, 0, 3693, 0, 0], [0, 0, 5324, 0, -61, 104], [0, 0, 4481, 0, 1701, -2421], [-372, -2934, 0, 2, 0, 0], [0, 0, -3672, 0, -4677, -553], [-2968, -1402, 0, -26, 0, 0], [7146, 1254, 0, -3506, 0, 0], [0, 0, -104, 0, -3507, 1016], [0, 0, -2388, 0, -6759, -789], [0, 0, 837, 0, 85, -953], [0, 0, -2857, 0, 5877, 1203], [4380, 2325, 0, -2571, 0, 0], [0, 0, -3320, 0, -4723, 2213], [0, 0, 4167, 0, -547, -1048], [-4988, -558, 0, 2010, 0, 0], [-302, -770, 0, -3898, 0, 0], [16528, -1587, 0, 3835, 0, 0], [0, 0, -1991, 0, 9325, -276], [0, 0, 3651, 0, 10957, 1704], [-16808, 2607, 0, -4145, 0, 0], [5524, -1945, 0, 2175, 0, 0], [-5724, 4615, 0, 3047, 0, 0], [-2832, 507, 0, 5723, 0, 0], [0, 0, -77, 0, -11643, -477], [9986, -1810, 0, -1306, 0, 0], [0, 0, 3016, 0, -14631, -256], [0, 0, -605, 0, -4887, -3067], [0, 0, 3036, 0, 2685, 1367], [0, 0, 9013, 0, -1599, -1830], [0, 0, -3999, 0, -3939, -1203], [5018, -4648, 0, -2788, 0, 0], [0, 0, -1973, 0, 2685, 2570], [0, 0, 3384, 0, 3343, -2901], [0, 0, 7040, 0, 9231, 1966], [39732, 909, 0, -853, 0, 0], [2704, 7772, 0, -2476, 0, 0], [0, 0, 12380, 0, -199, -1835], [0, 0, 6044, 0, -7239, -564], [-4404, -924, 0, 6744, 0, 0], [0, 0, -1335, 0, 4689, 250], [0, 0, -1773, 0, 5105, 1075], [0, 0, -461, 0, -3483, 2658], [3780, -36, 0, -4728, 0, 0], [0, 0, 2508, 0, 4095, -5014], [-4502, 6924, 0, 2020, 0, 0], [0, 0, 9636, 0, 4215, -903], [0, 0, -2101, 0, -10107, -2165], [11620, -1945, 0, 6651, 0, 0], [-7752, -1261, 0, 2393, 0, 0], [-32628, -2563, 0, 971, 0, 0], [7370, 6772, 0, 824, 0, 0], [0, 0, -2089, 0, -4543, 2052], [0, 0, 8103, 0, 2877, 744], [0, 0, -8540, 0, -109, -4375]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_289_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_289_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_289_4_b_b(:prec:=6)
    chi := MakeCharacter_289_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_289_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_289_4_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_289_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-32, -24, 1, 1]>],Snew);
    return Vf;
end function;