
// Make newform 507.4.b.j in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_507_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_507_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_507_4_b_j();".
// 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_507_4_b_j();".
// 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 := [26460736, 0, 98825392, 0, 88861676, 0, 36483705, 0, 8187552, 0, 1077128, 0, 84743, 0, 3906, 0, 97, 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, 0, 0, 0, 0, 0], [-8026346248675856, 0, -16763165801556616, 0, -9241389068385025, 0, -2361773027576816, 0, -331625699797868, 0, -27119085320007, 0, -1282598456190, 0, -32409147909, 0, -337699465, 0], [737331060496, 0, 2222661123176, 0, 1625999513091, 0, 515475085464, 0, 85165499404, 0, 7852438557, 0, 406207162, 0, 11006175, 0, 121443, 0], [68875575658864, 0, 201330790700376, 0, 135335190850367, 0, 40202257268304, 0, 6268182584692, 0, 548115320953, 0, 27024992866, 0, 701380891, 0, 7448055, 0], [1370659636381776, 0, 4772771090255464, 0, 3244115832008405, 0, 960793610862192, 0, 150391865567196, 0, 13287339141715, 0, 664217725590, 0, 17499465577, 0, 188631741, 0], [9755605735118032, 0, 31988356125916840, 0, 22343189096813149, 0, 6755156424533136, 0, 1068362441422492, 0, 94654984523819, 0, 4721212524742, 0, 123712051601, 0, 1323696165, 0], [-14900353096451568, 0, -55490691953015384, 0, -41498747524208055, 0, -13283953183925968, 0, -2201649168060372, 0, -202505950969409, 0, -10408004776370, 0, -279441123251, 0, -3050639663, 0], [13515449077320592, 0, 52361748095856680, 0, 42166270146463569, 0, 14231034832637808, 0, 2439521061414028, 0, 229305534031671, 0, 11960996341246, 0, 324617832117, 0, 3573406425, 0], [6412202646705808, 0, 21590892721723936, 0, 15415225572368783, 0, 4746736528581776, 0, 761940543186028, 0, 68407025915321, 0, 3455510144330, 0, 91675637363, 0, 992878663, 0], [0, 539827731169710160, 0, -2212811911313403192, 0, -1197016910942859347, 0, -237678070706066768, 0, -23696031437175140, 0, -1251532031668421, 0, -31724147958522, 0, -208707089855, 0, 3209941781], [0, -172360206360464, 0, -1138737236947544, 0, -858748244111397, 0, -271203833596304, 0, -44299174758284, 0, -4029427467139, 0, -205573324326, 0, -5495758441, 0, -59877421], [0, -8046782297326415024, 0, -18271690600947015544, 0, -11306587343182945427, 0, -3196817380717218256, 0, -484880217302035364, 0, -41789072921757573, 0, -2044423654485946, 0, -52805876911935, 0, -558686229419], [0, 3280107605088258352, 0, 10547456021361190152, 0, 6876718512538540175, 0, 1933724913832608336, 0, 287691647489885188, 0, 24325107163287433, 0, 1172453572398322, 0, 29976384016219, 0, 315204832455], [0, -107041765798830680, 0, -296950452372422394, 0, -196976172587530637, 0, -58227877578500516, 0, -9097205719378862, 0, -801712561391267, 0, -39989575616904, 0, -1052085600443, 0, -11333387329], [0, 5684373809732825040, 0, 17148017724805012136, 0, 13400283268170213229, 0, 4461287830305744432, 0, 758707381954452540, 0, 70989668581658555, 0, 3693649529292390, 0, 100119548308961, 0, 1101606689877], [0, 233817678421072, 0, 1138737236947544, 0, 858748244111397, 0, 271203833596304, 0, 44299174758284, 0, 4029427467139, 0, 205573324326, 0, 5495758441, 0, 59877421], [0, -2487752893111838384, 0, -13554839283108738888, 0, -10492000269817653159, 0, -3336298632724181392, 0, -542479073677032164, 0, -48821950667583473, 0, -2457315743140546, 0, -64734895114835, 0, -694871382623], [0, -8020854297444374000, 0, -20613625375714780344, 0, -14208123848162280847, 0, -4377908729532953616, 0, -708458911096852628, 0, -64109174355542825, 0, -3258010330423586, 0, -86802481993355, 0, -942769046151]];
    Rf_basisdens := [1, 84345031640064, 11028377568, 499083027456, 6488079356928, 42172515820032, 84345031640064, 84345031640064, 21086257910016, 108467710689122304, 56729974209792, 108467710689122304, 54233855344561152, 1694807979517536, 108467710689122304, 4727497850816, 54233855344561152, 54233855344561152];
    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_507_b();"
function MakeCharacter_507_b()
    N := 507;
    order := 2;
    char_gens := [170, 340];
    v := [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_507_b_Hecke();"
function MakeCharacter_507_b_Hecke(Kf)
    N := 507;
    order := 2;
    char_gens := [170, 340];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 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+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], [-3, 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, 2, 0, -1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 1, 0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, -2, -2, -2, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [17, -2, -3, -2, 3, -1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -7, -2, 5, 2, 0, 2, -2, 2, 0], [-25, 0, -1, -3, 0, -2, -2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-55, -6, 3, 5, 1, 3, 5, 4, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -8, 3, 10, -6, 0, 2, -4, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -17, -2, -2, -4, 9, 10, -9, 12], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -46, 6, -5, 10, 3, -5, 0, 1], [-22, 1, 17, 10, 7, -1, -8, 2, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -11, 14, 17, -6, 2, -2, 10, -2, -16], [165, -4, -7, 16, 4, -4, -4, 6, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 13, -6, -5, 16, -14, 29, -16, -7], [233, -2, 19, 4, -11, 29, -7, 4, -21, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -59, -10, -27, 10, -30, -3, 5, -31], [0, 0, 0, 0, 0, 0, 0, 0, 0, -39, 67, -41, -13, -8, 10, -19, 23, 11], [0, 0, 0, 0, 0, 0, 0, 0, 0, -16, -80, -16, 23, 12, 22, -6, 4, -6], [-34, 7, 34, 10, -26, -16, 7, -7, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -6, -44, 38, 7, 8, -37, -21, -7, -37], [0, 0, 0, 0, 0, 0, 0, 0, 0, -14, 37, 20, -39, 32, -20, 47, -3, 7], [0, 0, 0, 0, 0, 0, 0, 0, 0, -4, -71, -34, -26, 4, 22, -11, -7, 11], [28, -36, 19, -6, -11, 1, 31, -21, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [347, -36, 7, 37, 33, 21, 37, 65, -54, 0, 0, 0, 0, 0, 0, 0, 0, 0], [9, -12, -24, -26, 4, -32, -4, -27, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -57, 62, 16, 41, -48, 105, -29, -4, 87], [-379, -13, -14, -14, 4, -8, -73, -18, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-329, 49, 0, 5, -62, 50, -9, 21, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0], [355, -93, 100, -12, 55, -75, -4, 36, -33, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 51, -73, -166, 44, -3, 112, -11, 48], [-316, -28, 10, 5, 59, -41, 29, 91, -65, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -37, 0, -42, -64, -36, -68, -20, 26, 13], [0, 0, 0, 0, 0, 0, 0, 0, 0, 83, -51, 91, 36, 52, -3, -104, -29, -51], [94, 67, -175, -12, 13, 11, -60, -36, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 82, -121, 24, 21, -26, -14, -57, -41, -65], [0, 0, 0, 0, 0, 0, 0, 0, 0, -32, 143, -39, 88, -94, 121, -48, -7, 6], [-237, 56, -105, -23, 33, 87, -17, 52, -83, 0, 0, 0, 0, 0, 0, 0, 0, 0], [482, 46, -220, 4, -65, 69, -81, -100, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-147, -21, -118, -69, 21, 63, -38, -19, -8, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1019, -41, -294, -87, -3, -103, 26, -23, 108, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 204, -443, 87, 8, -16, 111, 118, -23, 122], [0, 0, 0, 0, 0, 0, 0, 0, 0, -14, 4, -42, 19, -118, 115, -187, 39, 151], [-1184, -52, -32, -29, 86, -74, 56, 46, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-232, -41, 85, -83, 70, 62, -29, -7, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -17, -508, 68, 171, -68, 129, -97, 14, -9], [0, 0, 0, 0, 0, 0, 0, 0, 0, 64, -113, 90, 76, -46, 112, -21, -25, 243], [0, 0, 0, 0, 0, 0, 0, 0, 0, -39, -9, 217, 183, -92, -130, -9, 39, 7], [1201, -82, -1, -72, 145, -63, -49, 38, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -201, 165, -6, -54, 48, -15, -116, -19, -118], [0, 0, 0, 0, 0, 0, 0, 0, 0, -84, 585, 9, -123, 20, 163, -66, 7, 96], [-1454, 56, -83, -13, 88, -10, -6, 46, -65, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1739, -27, 192, 171, 11, -33, 8, 5, -52, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-223, -107, -78, -47, 135, -41, 146, 129, -86, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-478, -120, -180, -61, -70, 50, 22, -71, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 97, -235, -119, 106, -62, 54, -133, -45, 111], [1094, 76, -28, -203, -287, 197, -39, -195, 229, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -266, -276, -13, 25, -76, 103, 61, 226, 101], [-739, 116, -19, -72, 41, 115, 175, -58, 175, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 109, -541, -5, -100, -36, -181, 382, -73, -33], [0, 0, 0, 0, 0, 0, 0, 0, 0, 359, 225, -85, -71, -110, -230, -13, 65, -103], [-97, -181, 406, -41, -27, -199, 306, 225, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1674, -6, -136, 133, 66, -90, 2, -53, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 432, 206, 432, 120, 14, -374, -127, -252], [0, 0, 0, 0, 0, 0, 0, 0, 0, 297, -400, -128, 5, 80, -167, 19, 204, -141], [1451, -112, -99, 171, -139, -11, 51, -108, -49, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-864, -17, -42, -97, 201, 177, 14, 74, -31, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 20, -154, -44, -336, 276, -320, 98, 14, -66], [0, 0, 0, 0, 0, 0, 0, 0, 0, 236, 303, 222, -71, 96, -182, -313, 127, -87], [0, 0, 0, 0, 0, 0, 0, 0, 0, 376, -507, 94, 103, 286, 24, 71, -85, -147], [-338, 343, -98, -92, 4, -22, -315, -177, 306, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1364, 138, -20, -107, 279, -93, -7, -17, -259, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -91, 913, -150, 40, -6, 91, 108, -105, 186], [0, 0, 0, 0, 0, 0, 0, 0, 0, 180, -165, 96, 163, 10, -602, -153, -107, -383], [-205, 8, 251, 64, -28, -298, -30, -65, 214, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -511, -48, -195, 122, -160, 440, 124, 282, 400], [0, 0, 0, 0, 0, 0, 0, 0, 0, 361, 669, -161, -181, 402, -112, 219, 177, -83], [0, 0, 0, 0, 0, 0, 0, 0, 0, -175, -529, -213, -54, 116, -315, -138, -12, -442], [-1685, 12, -245, -222, -322, -154, -104, -207, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 557, -1028, -113, -184, 244, -26, -206, 354, -130], [0, 0, 0, 0, 0, 0, 0, 0, 0, -52, -283, -176, -49, -6, 10, -239, 173, -263], [1196, -7, 157, 74, -130, 148, 91, 41, -249, 0, 0, 0, 0, 0, 0, 0, 0, 0], [831, -331, -223, -100, -1, -41, -164, 167, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-932, -31, -121, -94, -44, 348, 75, -259, 391, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -241, -1236, -385, -184, 6, -74, 186, 276, 26], [0, 0, 0, 0, 0, 0, 0, 0, 0, -345, -195, -173, -324, -312, -31, -148, -273, 19], [0, 0, 0, 0, 0, 0, 0, 0, 0, -553, -110, 9, -131, -176, 341, -655, 407, -77], [0, 0, 0, 0, 0, 0, 0, 0, 0, -156, 856, -548, -204, -220, 508, 104, 392, 268], [-1929, -47, -426, -207, 54, -72, -269, -85, -118, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 473, -769, 334, 384, -52, -795, 234, -571, -548], [0, 0, 0, 0, 0, 0, 0, 0, 0, -124, -1173, 304, -164, 318, 324, -87, 249, 391], [3411, 43, -46, -449, -188, -114, 135, -86, 301, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -130, 1682, 196, 440, 156, -110, 8, -486, -124], [2157, 648, -95, -439, 78, 264, -88, -467, 438, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -118, 756, -178, -246, 292, -208, -108, 442, -126], [962, 53, -115, -238, -441, 403, -164, 262, 270, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3321, -240, -137, -223, -96, 342, -96, -81, -156, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -179, -234, -174, -433, 152, 211, 453, 344, 399], [2277, 161, -1252, -64, -142, 340, -523, -650, 175, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -231, -941, 779, -29, -346, -154, -141, -187, -19], [-4644, -623, -943, -137, -103, -343, 38, 85, 411, 0, 0, 0, 0, 0, 0, 0, 0, 0], [372, 372, 240, -137, 311, -749, -153, -141, 541, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1693, -4, -469, -41, 212, 298, -360, -261, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -920, 2308, 208, -771, 48, 659, 151, -63, 137], [0, 0, 0, 0, 0, 0, 0, 0, 0, -651, -829, 506, 329, -560, 508, 425, -643, -22], [0, 0, 0, 0, 0, 0, 0, 0, 0, 330, -586, 968, 546, 332, -394, -292, -276, -954], [-2109, 403, -672, -453, 73, -183, 578, 59, 832, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3321, 228, 925, 494, -150, -6, -484, -185, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1395, 163, 1271, 702, 91, 1019, 138, -45, -565, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 715, 1835, -290, -42, -352, 219, -240, -263, 44], [0, 0, 0, 0, 0, 0, 0, 0, 0, 942, 792, -658, -666, 436, -182, 454, -342, -138], [0, 0, 0, 0, 0, 0, 0, 0, 0, -747, 618, 217, -124, -488, 250, -982, -162, 696], [0, 0, 0, 0, 0, 0, 0, 0, 0, -320, -1168, 388, 261, -674, 51, -1159, 199, 221], [-2867, 634, -437, -79, 66, -282, 312, 197, 822, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -799, -978, -93, -204, -424, -58, 34, 218, 398], [7116, 302, -164, -187, 415, 831, 59, -127, -285, 0, 0, 0, 0, 0, 0, 0, 0, 0], [8358, 387, -992, -606, -546, -318, -101, -665, 1620, 0, 0, 0, 0, 0, 0, 0, 0, 0], [6149, 194, -1506, -958, -474, 82, -280, -751, 1401, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -832, 2431, 530, 1073, 344, 26, -477, -55, -1179], [1121, -42, -380, 808, -498, -342, 142, 407, -439, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-5756, -277, -50, -395, 99, -453, -352, -206, -241, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 820, 4708, 790, 809, -8, -378, -400, -352, -168], [0, 0, 0, 0, 0, 0, 0, 0, 0, 249, -164, -370, -887, -176, -315, 1047, 148, 261], [492, -84, -382, -353, -475, 537, 165, -13, 211, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 375, -1489, -95, -443, -104, -1356, 77, -171, -1177], [-3438, -722, 294, 444, -414, 10, -204, 128, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-6472, -387, 708, 225, -15, 615, -94, -92, -427, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -106, -1275, -678, -323, 272, 552, -181, 29, -153], [0, 0, 0, 0, 0, 0, 0, 0, 0, -315, 3277, 376, 428, -34, 939, -1076, 179, 516], [0, 0, 0, 0, 0, 0, 0, 0, 0, 399, 5134, 223, -4, 870, -36, 44, 94, -992], [8, 231, 667, -339, -225, -69, 164, -482, -376, 0, 0, 0, 0, 0, 0, 0, 0, 0], [3966, -368, 350, -703, 661, -859, -431, -187, 639, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1654, 2869, 736, 687, 316, -1488, -205, -199, -1497], [0, 0, 0, 0, 0, 0, 0, 0, 0, 650, -28, 160, 268, 1156, -674, 510, -122, -668], [0, 0, 0, 0, 0, 0, 0, 0, 0, 555, 1049, -245, 720, -884, 415, -784, -304, 218], [0, 0, 0, 0, 0, 0, 0, 0, 0, 515, -118, 120, 623, -208, 879, 267, -164, 205], [2583, 1017, -2736, -510, -705, 1281, -174, -1287, 984, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5142, -221, 1637, 668, 499, -33, 914, 766, -812, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -629, -1948, -41, 392, -8, -6, 800, 92, 118], [0, 0, 0, 0, 0, 0, 0, 0, 0, -403, 342, 1155, 611, 6, 388, -896, -388, -344], [10436, -392, -861, -76, -581, -91, -635, -307, 1402, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -424, -2722, -153, 1032, -504, 352, 52, 68, 721], [-1217, -300, 1099, 861, -954, -246, -376, -245, -160, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -390, -1933, 623, -34, -462, -345, -1330, 787, -572], [0, 0, 0, 0, 0, 0, 0, 0, 0, 588, -898, -1465, -711, 4, 1591, 1437, -540, 935], [-12950, 156, -872, 388, 500, -240, -928, -282, -1066, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3967, -58, 1063, 1187, -1168, 466, 302, 301, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1773, -3346, -1075, -1816, -294, 48, 660, -174, 1992], [0, 0, 0, 0, 0, 0, 0, 0, 0, -2140, 2251, -1295, -268, -40, 691, -1336, 549, 272], [5991, 166, 643, 686, 293, -267, -193, 252, -1017, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-7971, 354, -523, -1130, 75, 189, -229, -1130, 1393, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1582, -403, 1311, 751, -556, -730, -725, 603, -423, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-5314, -368, 2132, -711, 187, -517, 485, 799, -343, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-11848, 1041, 409, -81, -820, 1190, -569, 59, 459, 0, 0, 0, 0, 0, 0, 0, 0, 0], [7463, 310, -503, -26, -1604, 248, -748, -920, 803, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -914, 11, -425, -810, -404, 2091, 994, 135, 1090], [-11902, -196, 1878, 721, -226, -734, -766, 940, -1834, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1328, -393, -192, 206, 570, 415, -346, -1001, 711], [0, 0, 0, 0, 0, 0, 0, 0, 0, 319, -7282, 293, -45, -1138, 424, 1130, -534, 700], [-7979, -943, 722, -317, 443, -77, -140, 995, 216, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -20, 4164, 530, -55, -834, -973, -451, 602, 614], [5865, -930, -669, -592, 582, -802, 74, 177, -930, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 2161, -2777, 816, 68, 14, -1745, 790, -1307, -820], [0, 0, 0, 0, 0, 0, 0, 0, 0, -1768, 2707, 506, 545, -290, 2066, 303, 199, 681], [4577, -1192, 873, 534, 1274, -962, 1388, 1048, -1183, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-3761, -521, 468, 439, 499, -1375, 4, 653, -858, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_507_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_507_4_b_j();".
// 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_507_4_b_j(:prec:=18)
    chi := MakeCharacter_507_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_507_4_b_j();".
// 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_507_4_b_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_507_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![89567296, 0, 182579488, 0, 137234244, 0, 51496229, 0, 10831309, 0, 1349342, 0, 101051, 0, 4432, 0, 104, 0, 1]>,<5,R![252800110296721, 0, 3556793465272632, 0, 2993277342270618, 0, 477991112299211, 0, 10183773140289, 0, 93726274635, 0, 456756349, 0, 1231596, 0, 1737, 0, 1]>],Snew);
    return Vf;
end function;