
// Make newform 8.10.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_8_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_8_10_b_a();".
// 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_8_10_b_a();".
// 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 := [251007534, -16074123, 1261649, -92091, -315, -313, 59, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [58, 2, 4, 0, 0, 0, 0, 0], [-529423278, 10915961, -742730, 49989, 70006, 2947, -318, -1], [120340126, 55540095, 4878490, -3365165, -188326, -22875, -2258, -55], [7650083474, -600770151, 49386870, 17893, 273462, -30237, 770, -545], [79996934, -14934797, 501650, -123529, -4078, 1377, 22, -11], [4806907090, -114709831, -59013834, -14156923, 642294, -39357, 10306, 703]];
    Rf_basisdens := [1, 1, 1, 8912896, 4456448, 8912896, 131072, 8912896];
    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_8_b();"
function MakeCharacter_8_b()
    N := 8;
    order := 2;
    char_gens := [7, 5];
    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_8_b_Hecke();"
function MakeCharacter_8_b_Hecke(Kf)
    N := 8;
    order := 2;
    char_gens := [7, 5];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [-1, 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 := 10;
    raw_aps := [[-2, -1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 0], [-2, 6, -1, 0, 1, 0, 0, 0], [597, 17, 4, 2, 1, 1, -2, -1], [144, -607, -56, 1, 0, 12, 0, -8], [-294, 1066, -115, 24, 3, -8, 0, -16], [-11052, -6792, 104, 186, 30, -96, -68, -30], [3920, -15595, 40, -267, 128, 220, 0, 24], [418639, 30099, -1460, -970, -141, 547, -166, 141], [-25166, 93482, 985, -5312, -89, -1472, 0, 128], [79812, 85668, 1232, -1192, 84, 1444, 280, -84], [14542, -25730, -8761, 38664, 361, 1448, 0, -1200], [-335642, 265968, 6960, -2836, 516, 4384, 1416, -516], [-87904, 368653, 5456, 9165, -14080, -5832, 0, -1232], [1112078, -778938, -25256, 7036, -1866, -12634, -5164, 1866], [236934, -526522, 53347, 346552, -2835, 9240, 0, 7216], [-100608, 400189, 33408, -15811, 4224, -7808, 0, 5376], [24898, -866190, -34623, -749160, -10289, 3448, 0, -6416], [794960, -3156435, -99288, -30963, -55552, 49052, 0, -22120], [69175533, 3457401, -7452, -42654, 10713, 74793, -46578, -10713], [-64782312, -2639768, 205272, 96374, 13010, -57344, 50596, -13010], [-32064430, 3888362, 31784, -42924, 11914, 78666, -31764, -11914], [1352576, -4564535, 628416, -26167, -198784, 22368, 0, 61376], [93645000, -3402648, -927656, -274794, -119886, -84864, 15716, 119886], [-5335308, 17344952, 517288, -139702, 54478, 303136, 40732, -54478], [3564910, -15433554, 337367, -1700520, 172345, 180792, 0, 72816], [353374337, -20636483, 1073140, 865962, 204701, -251859, -282234, -204701], [-4017168, 18426809, 509560, 1977433, -423936, -276396, 0, 12232], [7820426, -28103614, -1688891, 4436832, 738683, 584416, 0, -135744], [93516970, 5225184, -947872, -477544, -147384, 35392, 115600, 147384], [-2060043072, 4096496, 43264, -246544, -101792, -58832, 428800, 101792], [15046640, -61091867, 3207288, -4738939, 637952, 632148, 0, 549320], [-82685314, -91611696, -2977136, 524548, -389940, -1694368, 71192, 389940], [4811680, -6130819, 915664, 11310909, -527360, 180984, 0, 55472], [-21259914, 71521358, 1430011, -13879184, -1626459, -1347792, 0, -28064], [4017495327, -37801565, 4437132, 1679318, 243971, -947405, 1242682, -243971], [54497490, -205061678, -3167671, 5433576, -4512729, 3074824, 0, -1097200], [-64226144, 242405737, 533840, -10043607, -2415104, -3702088, 0, -268752], [8123517241, -13944219, 5424468, 1662314, 397269, -470507, 1123158, -397269], [7981386, -67274326, -1906811, -28660952, 6452331, 835656, 0, 649360], [-4967968, 58204705, 10348272, 25681505, -4706944, -1201944, 0, 805904], [127213094, -440612722, 12523795, 40283904, -3352339, 6039808, 0, 1310208], [-18379207768, 134013432, 5516832, -648512, 551208, 2302136, 553584, -551208], [302948340, 343695928, -11552472, -12031894, -2529490, 4443424, 4341724, 2529490], [-74368162, 360401974, -23628177, 94225040, 3019505, -2324016, 0, -2944096], [19895781357, -272591383, -10016540, 78098, -1911047, -5811239, 2635918, 1911047], [-96124512, 422900929, -12515632, 75306369, 16831104, -3778376, 0, 616496], [-23803744996, -504350724, -24528720, 5206440, -233844, -5907972, -11328984, 233844], [217516928, -1006725999, -51323968, -109430895, 8042240, 16069408, 0, -6183104], [88675150, -310191322, 36370279, 5589072, 2288761, 2419344, 0, 5522720], [-9768212760, -323671512, 1640344, -1634970, -4249182, -11112576, 17816900, 4249182], [-26062619978, 284591934, -39610504, -18012868, -4406562, 4793182, -2179004, 4406562], [15744596516, 940655928, -38575320, -27794454, -3508050, 17270304, -5255460, 3508050], [-100397888, -42943315, -10562720, -409270739, 16352896, -4174256, 0, 827168], [-4821545366, 609900192, 82826528, 26166536, 14655384, 17799616, -17208272, -14655384], [25371737861, -609662895, 538052, 10905586, 78417, -10670335, -44642, -78417], [13541626, 373737794, 15375805, 392718832, -22268957, -1229648, 0, -984736], [-40088978022, -1771192286, 40030920, 41528564, 2927762, -32745278, 8304412, -2927762], [515580438, -2593934698, -121405781, -464771400, 21796005, 38180120, 0, -14229968], [-7990042216, -101675736, -7627880, -3947162, -2667870, -4056448, 6857540, 2667870], [-425930256, 1047306385, -27152776, -594300879, -9217152, -22089068, 0, -5195704], [-298135250, 790242950, 104422999, -467996336, -10122359, -24423536, 0, 13471520], [254542032, -882165435, -102379800, 255196197, 64870272, 24028284, 0, -5358504], [-46284395213, 1483978839, -113814116, -85587634, -25157529, 10115047, 43723058, 25157529], [14788002870, -922403856, -77146576, 7046060, 572484, -5328608, -40863224, -572484], [-635530718, 2566639962, -72099823, 214670016, 62716015, -27668544, 0, -1340544], [388800560, -626563175, -3071848, 745521081, -154839808, 15675012, 0, -22558808], [4760144618, 1502034656, 329745632, 82547448, 36971752, 28367808, 16985808, -36971752], [-766175456, 2341801989, -91080304, -574687803, -16279424, -36705576, 0, -15337104], [-805621294, 2458476250, -67440727, -510664560, 115164599, -35369520, 0, 6817696], [-8491533022, 5383309440, -11450624, -70504640, 14360640, 113586560, -63167872, -14360640], [-171072278943, -2854025379, -222195340, -8978262, -16824963, -41496627, -43797818, 16824963], [180039575286, 860014126, 432035448, 126003884, 47544254, 16628878, 25840708, -47544254], [967879462, -3002990698, 48377971, 709426344, -10961795, 49880520, 0, 5345168], [1810770656, -6898345051, 535081840, -470739483, -169055872, 55669672, 0, 52289424], [233758112944, -8210588496, -258011200, 7844000, -57706896, -180964688, 101821984, 57706896], [-784836322, 3920355982, 541747695, 272908040, -142240447, -87942744, 0, 57072464], [-2493516550, 9536661362, -203716355, 165280224, 164032067, -117468320, 0, -5669184], [60833472244, 4580966136, 215007464, -96643366, -25151106, 21190048, 208108156, 25151106], [-217404936714, -17988574096, 371642800, 445223564, 45562852, -308535008, 3569992, -45562852], [4411369744, -16294663315, 90027016, 496616653, -311611904, 226280044, 0, -31654984], [-4183187538, 14243925782, -157656233, -1617648480, 294626409, -209446624, 0, 19567168], [298034563662, -536978154, 260114520, 104198220, 34172886, -1679562, -6634284, -34172886], [318320074212, -10355277768, -331725016, 87214058, -28674642, -173237984, -51163940, 28674642], [-265905093117, 24446549095, 27786204, -459725842, -19467529, 401323255, 91763218, 19467529], [-4417282736, 18856358345, -685864664, 2492667817, 246294400, -186640676, 0, -62795752], [-433165575516, -5787106824, -74770200, 49992666, -23532162, -120589152, 56743548, 23532162], [64000206246, -3787859856, -226072144, -122686324, -89954844, -147178208, 246783304, 89954844], [3070645914, -8010272158, -299518835, 4846509040, 715430163, 220375728, 0, 59415904], [251149681026, -12597704038, -961309208, -129169804, -126243206, -249559814, 24318220, 126243206], [-5140171856, 19608161949, -172409512, -219303747, 15545728, -272633244, 0, -22409112], [-105697921540, 6233908380, 1433601584, 441008296, 204152172, 171448220, -99807896, -204152172], [108354815777, -6477336243, -1496749452, -494845542, -232256547, -201924099, 180651462, 232256547], [-7648792384, 26116203301, 28847712, -3869085787, -233815552, -436271856, 0, -29281120], [6566294720, -32383099959, -1586865312, -5044379319, 481145984, 497234768, 0, -157959904], [72831548091, -19089979377, 935973180, 611871918, 86801199, -351468321, 120781794, -86801199], [-2790873438, 16233756290, -993277775, 5471286664, -826010241, -116878296, 0, -259898288], [418199008542, 11019186000, 2250149136, 793481124, 389816748, 375969120, -434192424, -389816748], [-3260377296, 2601826617, -225242088, -9987159207, -111667968, -169474620, 0, -48130008], [-1044356654, 3721542946, 55852937, -95077512, 317868103, -49395496, 0, 53388720], [2705121744, -3527821315, 2696718952, 4072569309, -660472320, -68547460, 0, 290892376], [-7738936374, 32737161626, 3798919429, -1451198120, -908372469, -737338824, 0, 412935280], [-1925475312, -633783691, -473921912, -8250862379, -581487744, -96194196, 0, -150772808], [-1039992439474, -45442917552, 1158749968, 1281825316, 187430700, -719533216, -170347816, -187430700], [-7108221680, 31729990553, -337014008, 5467893753, 1186266496, -323754708, 0, 121321784], [-1652348806582, 11063851168, -177150560, -49966680, 94498808, 333463104, -466570512, -94498808], [-1128114736, -7747506959, 2404326504, -13613191471, 632476160, -209312388, 0, 433828952], [2402907454818, 55836438336, 687048000, -787416624, 57433968, 959718528, 113788128, -57433968], [2275163377543, 55304884731, 64695724, -1032019402, -39657813, 913045963, 190979114, 39657813], [-784958807208, 58129813416, 1421684120, -417298330, 234467106, 1120699648, -227026364, -234467106], [-2364334856932, -67401573556, 1901618864, 1878286776, 251471596, -1123871988, -55076952, -251471596], [29897209166, -122071134922, -1228570073, -3168178272, 1719435161, 1816942624, 0, 70123584], [1707011205160, 16884804264, -5222356328, -2340358234, -765821214, 42894592, 452106692, 765821214], [354821968, -4660082271, -7206310104, 4498263681, 1739718400, 603485212, 0, -780941672], [1446414063627, -122575407841, -3485126276, 743117006, -535438529, -2349432593, 399190978, 535438529], [-3030883806124, -7848133704, -4541802072, -1424284022, -544245618, -208452832, -93918564, 544245618], [-24144315312, 94415457421, -478677592, -128615571, -1151171328, -1352840996, 0, -232835560], [2706097034421, 17013706497, -1213204092, -481094766, -12966975, 442193841, -554734146, 12966975], [14730796986, -43735282270, 870495901, 13000557328, 212403651, 764628048, 0, 154699936], [25509996480, -85285833127, 2683647712, 12927032281, 1420316544, 1281894672, 0, 586280608], [19220893110, -99418517378, -4966422949, -19711740384, 762436197, 1452827296, 0, -600569536], [-4056934452348, 104762372856, -1732096792, -2616432166, -310728066, 1684247968, 376863868, 310728066], [-16449188594, 39285124574, 1873315687, -25265303384, 1112642953, -1003499576, 0, 426565520], [15763838592, -30620612459, 3867051840, 25416791957, -2120054784, 515421664, 0, 249571008], [-15206964192, 44348458001, -3278344688, -13066868271, -1180861056, -657523432, 0, -637029392], [-7532386814, 55766002866, -1215011551, 27720599064, 223512175, -322809864, 0, -141642768], [-2896628226, -24581379442, -4142721569, -34424803800, -2313254895, 43189064, 0, -922282352], [340439545602, 149254228602, 5582034920, -371152812, 853794618, 2932536666, -624161012, -853794618], [-1760525691945, -12575576309, -2718492180, -844739242, -399376453, -353390117, 238259722, 399376453], [53593203282, -204053039798, -7068569047, 13684971840, 3542365527, 3622868032, 0, -503743360], [17251097920, -59729175647, 11687220896, -6621008607, -4303354112, -47175184, 0, 1054838112], [-2105117814911, -154275624723, -1870803468, 1769893658, -389709507, -2939022179, 623436294, 389709507], [948462883158, -175385050050, 4511988728, 3598867676, -40490178, -3720338210, 2417955076, 40490178], [55767783750, -216657653538, 12534242787, -12931873680, -2612651331, 2099230512, 0, 1417370208], [-2940934015754, 134884736496, -488715728, -2512122196, -45949116, 2374274848, -60561400, 45949116], [-8103669289788, -124915530376, -4207653272, 1493842490, -81278306, -1737677408, -1778713412, 81278306], [43072238942, -155883953778, -2273850097, 10332325320, -3514842463, 2415842152, 0, -826956080], [3428711840, 51301493217, -1708383024, 60468568737, -6116574592, 69790136, 0, -1117851088], [-27475431022, 82284028690, -7370075991, -18654961048, -442411321, -1017534840, 0, -1116069616], [1615183775910, -179309731344, 1485230640, 2190814380, -649233084, -4138513632, 3339547656, 649233084], [42892485712, -80692603967, 2246327720, 88563216033, 4754471680, 2411133404, 0, 1000114200], [43904774726, -138637424970, -9507286525, 40394425128, 154194413, 3124364872, 0, -1336156016], [-8555517545037, 174658664727, 11928176540, 1658746766, 1779662439, 3680240551, -1154561486, -1779662439], [2150676400, -97368460111, -9020858024, -80457923375, 884857984, 798942436, 0, -1162285720], [-86555762686, 344414333282, 10614235489, -4986412920, -4015800625, -5726170328, 0, 942633552], [-5351215954723, 308553768441, -562732636, -7430825006, -1096859031, 4140247913, 4106069806, 1096859031], [-116158361738, 526982618070, 9145262043, 61982590872, -5902740299, -7340711048, 0, 463217392], [-6241084363186, -31742133552, 3738612880, 1217447044, 95175756, -931919776, 1488603416, -95175756], [68395645920, -269504952491, 4490574320, -9269507691, -2062227840, 3397168360, 0, 346906640], [953177885964, -43008801780, -1547260560, -2641927320, -1801922820, -2763841140, 6434061000, 1801922820], [-9855467702, -3181170382, -18925245083, -23086372272, 2389631611, 899103888, 0, -2362230496], [12525586771722, -271846126368, -10006890272, -286896648, -2110371864, -6044218944, 3438042320, 2110371864], [-5101935440, -42976335059, 18709644248, -77846534835, 1094351488, -1576417372, 0, 2829142248], [-629926840901, -183087536289, -948716740, 5461744574, 1340072079, -1441528337, -5834646686, -1340072079], [98448174336, -453642974875, -18055594880, -58706792091, -3686643456, 6612732992, 0, -3106034048], [209051195978, -542469974094, 1476613768, 12578261236, 1617983298, -7724311342, -5733626308, -1617983298], [-5433803210337, -264813481661, -27056698740, -5400163978, -3660372157, -5580952493, 1113139258, 3660372157], [-10512100299436, 539897263416, -8214958296, -12036295958, -837221970, 9524630048, -758591268, 837221970], [3696428485704, -391020578136, -999995368, 5840537222, -501089022, -7343804288, 1504358404, 501089022], [30881516394, -103795626622, 2888022709, 20583576256, 7342611915, 1800725952, 0, 1461519232], [-188542210416, 619226737301, -1193923640, -119968837643, -7602612864, -10690977972, 0, -1256648072], [-5377921281426, 215887465680, -8645829744, -6545702076, -914592372, 3801924960, -664545384, 914592372], [-5558518956051, 147129893001, 37908030692, 11029646642, 4866430905, 3569646073, -511708274, -4866430905], [-63132313728, 94642349285, 2274733504, -142810496027, 10874538240, -3238302432, 0, 1878467392], [10843093403524, -26079537096, 21829130536, 7106371178, 2131338030, -712357088, 2389213148, -2131338030], [17501654689559, -125758939029, -38818349332, -12555442058, -5448331845, -3789553477, 2384152714, 5448331845], [6711390226092, 468611101116, -42851500048, -22173115912, -4691784708, 8097761788, -2658611192, 4691784708], [-210220461074, 792174087006, -5125326249, -14577620664, 6929099353, -11037855512, 0, 257681872]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8_10_b_a();".
// 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_8_10_b_a(:prec:=8)
    chi := MakeCharacter_8_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_8_10_b_a();".
// 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_8_10_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;