
// Make newform 23.8.a.b in Magma, downloaded from the LMFDB on 09 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_23_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_23_8_a_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_23_8_a_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 := [-37372224, -73308944, -13424272, 678328, 203052, -1059, -832, 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, 1, 0, 0, 0, 0, 0, 0], [209986539079392, 643834185777144, 35455244110940, -11462075003394, -276596270045, 53704469932, 418096898, -70454057], [-899509368844512, -650464212986424, -32140230506300, 11462075003394, 276596270045, -53704469932, -418096898, 70454057], [1023998472172608, 1190002587517336, 41407347126700, -19245461052586, -385294374305, 81664904028, 632516202, -99425533], [20717221503936, -125938388791960, -11800181584396, 2172142308418, 95325842855, -9395550780, -155754618, 11355547], [178479916668432, 619014297569064, 38237191857700, -11272965745974, -294409331845, 51731639972, 447046798, -66289297], [-1206200714316672, -1660660428747704, -70814993032460, 29673399783434, 651322391125, -133842936252, -1061508378, 169439777]];
    Rf_basisdens := [1, 1, 3315013604640, 3315013604640, 3315013604640, 331501360464, 1657506802320, 3315013604640];
    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_23_a();"
function MakeCharacter_23_a()
    N := 23;
    order := 1;
    char_gens := [5];
    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;

function MakeCharacter_23_a_Hecke(Kf)
    return MakeCharacter_23_a();
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 := 8;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [5, -1, 1, 0, 0, 0, 0, 0], [56, 12, 0, -1, 0, -1, -1, -1], [183, 9, -1, -4, 5, -1, -6, 0], [947, -77, 17, -16, -3, 9, 12, -24], [2490, -236, 4, 0, 33, -17, 14, 28], [5250, -260, 100, -31, -106, 1, -53, -91], [142, -512, 108, 40, 118, 80, -38, 28], [-12167, 0, 0, 0, 0, 0, 0, 0], [-12789, -2949, 29, -417, -154, 71, -287, -429], [37750, -2910, -866, 655, -441, 206, 639, 239], [35540, -256, -1828, -987, 328, 729, -47, 1397], [165989, 19589, -541, -1645, 282, 255, -1491, -1953], [255528, -8814, 3170, 1498, -830, 1702, 1652, 1638], [82608, 7200, 3104, 2817, -1167, 2314, 3025, 4705], [25002, 17466, -1926, 5432, 3266, 1016, 4790, 3348], [-93948, 61040, 10160, 3414, -3092, -1458, 2914, -3490], [10142, 20410, -8014, -4066, 6030, -5326, -156, 3554], [401711, 65011, -135, 5878, 1881, 7451, 10738, 38], [-615753, 67997, 14683, -3292, 12026, -5498, 4324, 5084], [1371992, 6062, -39470, 6028, -9447, 7543, 13494, -4040], [531554, -176542, -7482, -16146, 17060, -1214, -27234, 13814], [75131, -15025, 2205, -166, 6895, -26759, -2854, -12318], [519558, -30612, -26172, 29862, -12754, -10628, 20670, 22478], [2333908, -172766, -2098, 19163, 34760, -7787, 6381, 28583], [-6043017, -35397, 63661, 7665, -40297, 29232, 21833, -26255], [1332567, 293797, -97925, -13586, -12635, 3497, -50748, -32894], [-859916, -582830, -13590, 41180, -57852, -11634, 10490, -27696], [726972, 799756, 21104, 13332, -27854, -5200, 37438, 50656], [-1423754, -324548, 50332, -51695, 29622, -17187, -22521, -35235], [-13054, 138822, -287238, -59269, 29725, -68844, -63745, -36061], [-12105544, -175508, -215468, -30367, 72145, 66426, 69481, 55577], [15181966, 496264, 26800, -2240, -3062, 37418, -71760, 20416], [-3587766, 1285682, -196786, 141373, -45835, 34122, 95525, 143653], [16207200, -716540, -12192, -207220, 117304, -91794, -90922, 67160], [-22894243, 388519, 66209, -166834, -22748, -17486, -151770, -230202], [24200250, 193546, 104938, 53456, -63176, 107986, 54874, 175716], [4656363, -1276775, -268633, -58928, 159104, -66864, -289312, -122816], [19972844, -1447836, -138164, 40086, 7356, 105750, 75434, 9486], [5162947, -1645837, 9197, 169191, 56843, -126542, -80921, -51769], [4615114, -1409610, 305282, 48291, 78569, -124340, 26083, 220811], [20739162, 1019638, 385038, 28483, -114042, 40201, 96163, -81629], [-26012957, -1325219, 4795, 413054, -176697, 2891, -50012, -67126], [8447101, -914463, -460897, 314705, 294080, -84641, -179481, -158011], [23381181, 2804049, -153641, 303687, 4308, -172207, 396893, 288803], [35930259, 1887701, -1270365, -390698, 135435, -237569, 16180, -455246], [-49122114, -989314, 1598242, 310036, 227734, -286018, -357864, 692812], [-58639993, 6035309, -1266901, 219645, -252819, -120002, -431903, 332077], [-4070091, 1124033, 1876291, 10074, -411551, 141115, 956186, -248742], [-36965754, 2161954, 7786, -95886, -399492, 881944, 459836, -5522], [58846966, -4495572, -1278212, -196442, 859645, -570691, -293112, -20894], [-134671019, -5941825, -31703, 499976, -1266284, 205048, -21188, -60504], [112796344, -300674, -483550, 259539, -373214, 114691, 461329, -484329], [49979245, -15120123, 54119, 842460, -633475, 163345, 808804, 653684], [79785642, -7323628, 697212, -1863806, -530767, 133041, -507032, -613034], [-161229736, -7596880, -956768, 1871764, 257358, 195134, 1512624, 718532], [79745054, 5794740, -1434324, -651524, 1447947, -155499, 112138, 201384], [-64380792, 7703664, 752304, 156144, 987408, 499376, -359712, 1526624], [-119324393, 2050767, 1766697, 865977, -3074618, 1013037, 2685927, -704971], [141953760, 7599450, 4554222, 1802677, -993812, -565133, 126055, -697311], [12057995, 9886019, 4606449, -171028, -1674175, -39727, -7552, -2208372], [-177083630, -2838422, -1812662, -2533360, 668816, -1300134, -1258550, -2962076], [302818726, -13935910, -252290, 2806108, 337806, 510266, 1028700, 1168748], [-359989632, 5177792, -5217328, 1740099, 496693, -124644, 1647727, 1554203], [136503916, 16395466, 2208126, 3073952, -1349992, 759468, 2378660, 2109616], [-39735375, 7064261, 4556555, -461129, -2043487, 1786156, 82811, -831793], [-41644188, 11322528, -2886480, -1357209, 2445439, -985418, -957705, -1634769], [467066050, 33125440, -2670752, -2603102, -398878, 130212, 40242, 833866], [179844503, 29913357, -1883805, 1451069, -1755987, 1091978, 3788861, -46219], [135395662, -28024836, 6520708, -1227870, 3128011, 489311, -974428, 2578870], [-13811018, -9127068, 5567956, -4506130, 2080867, -278033, -4828748, 2754], [421657388, 5836816, 1883224, 4543104, 2680502, -887738, 1894544, 2242328], [869686799, -37474599, -2466945, -1844806, 1148745, -2538107, -2550964, -444002], [264902416, -5214532, 3275792, -2729475, 2826432, -2971327, -4909247, -200107], [592851788, -5490958, -7833590, 2230072, -1337070, -562484, 2290362, -1167620], [-64314662, -582410, -2651670, -370542, 2224146, 2066420, 1781538, 4534610], [-755308482, 9442250, -7908014, 1714468, 2151744, -174230, 872106, 1233232], [195664708, -39392254, -581418, 510084, -925721, -3207651, -4466634, 607880], [-683543836, 9245698, 3198686, -62701, -8318510, 4074227, 2704401, -3526961], [386773000, 12205370, -8481250, 2145100, 199573, 1596231, 312794, 4595648], [-65592186, -13969592, 5780100, 8475674, -9316200, 3893284, 7354604, 469198], [-507142504, -52981988, -584368, 2116069, 583710, 949491, 2863157, 5330013], [256007116, 8037952, -3100200, 4890430, -1778752, -1602994, -4151138, 3706758], [-16090058, -22043536, -12111632, -4714967, 3932856, -1271041, -1411689, -6214267], [170797781, 30219551, 834985, -3801574, -3811134, 5415024, -4162394, -498534], [-700349853, -71774431, -9635329, -10333280, 5829578, -1425554, 1168340, -5742712], [313959366, -72429688, -18374512, -5356796, 1143732, -4052844, -4192912, -2054772], [1011800062, 57448272, 26297888, 1073509, -2100602, -2645355, -2240977, -6538399], [-404768984, 87114386, 4798702, -3079688, 2744697, 6121587, -1610502, 5200524], [172206223, 102167437, 13240939, 671869, -1238707, 229806, -6600111, 726445], [811190178, 12494524, 3309200, -2442560, -1288342, 3564532, 11130698, -8167996], [344125889, 8729987, 854141, 5174780, -856813, -1190027, -3094590, 2474960], [-615523817, 10862805, 27569059, 5721800, -6987388, -4488688, 8166676, -6717000], [-267342892, 12262684, 10750460, -14537269, -7820745, -610818, -5089641, -9364149], [-463087284, -32567636, -26057828, 565439, 3233317, 731788, -2812121, 6961431], [-38811978, 39452358, -6584574, 13347858, -7348400, 5326706, 24047010, 6871498], [-1829249841, -7076153, 16567137, -10675471, 4389086, 2802629, 5605463, -1093779], [2192706908, -67713350, -11287954, 10343108, -6912772, 3090052, 5952024, -5124796], [544972059, -84076985, -27041371, 15949338, -12273353, -2932207, 15344314, -171734], [2561568156, -231413610, -8619878, -11002064, 8080953, 1011315, -3425574, 904884], [-225372920, 120523116, -16529452, 18377195, -20365869, 6865830, 8101731, 3355203], [-914240188, 98128636, 39513184, 4823786, 8413198, -7141698, -4636496, 6264998], [-951432816, 14112482, -52282574, -16772546, -1061194, -1032802, -7833192, -1463622], [-492570042, 7173832, 21874840, -6546735, 1726016, 10185951, 8784719, -86579], [230758387, 33791159, 1485077, 8541080, -9780509, -14039161, 3092820, 5705848], [904284821, 182428861, -15406229, 4736585, 1445588, 790663, -8930933, 6727397], [-2299368439, 7976095, -28681639, -22478134, -9497656, 9876826, 1903554, -19051510], [1399955339, 79402303, -13122559, -25118317, 3148683, 2227590, -13105269, -9150477], [456670388, 171258220, 18695140, -3895020, -39513428, 5738936, 17020076, -17242844], [2474286354, -6893556, 22430996, 14775216, -10103625, 4443069, 1512142, -15133500], [197856356, -48854740, 6509028, 3157818, 12576992, 8322286, 1417950, -36862], [-1649467454, -17405074, 54430214, -4203641, 5529680, -22428277, -32236453, -9430521], [444194706, -77636488, 67054552, 36047422, 7312160, -338230, 9518922, 9905790], [259017796, -70947274, -141682, 21433808, 7067590, -20506636, 9410958, -13405844], [1097052084, 60832124, -63685756, 3449266, -3051296, -9599378, -13866946, -3489102], [422848238, -829704, 13432000, -25202458, 7917850, -1244796, -37698374, -2804122], [-3280861245, -241681445, -19884903, -14086766, -6782571, 12277063, -7286126, -8269694], [-489453593, 13167813, -16032125, -44063502, 564406, -13527948, -34549354, -33714142], [1633337331, -28531097, 63181929, -7870607, -1421556, -2397229, -22417049, -15968707], [-3949805597, -129348545, 41307229, 27266386, 11836935, 3681585, 17470506, 8152146], [-265678858, -11731134, -51226854, -30940498, 21332462, -13961014, 5694716, 11194098], [1264485370, -69491844, 21438420, -25357184, -415123, -4644665, -7734590, -27020836], [-2669484574, -638198254, -45388494, 6332698, -3186606, 15155694, 945820, 7830054], [597874658, 178966106, 85908278, 9876375, -18681419, -427640, 12941875, 1404807], [2274949410, -204995974, 17374454, -32144898, 31335562, 12766952, 22325950, 28080670], [724844574, -510686574, 49548066, 19018401, -4165364, -8406619, 27719481, 8741161], [-1887291966, -275405894, -35731454, -24270397, 26229032, -5332533, -35061917, 26426179], [-3677646966, -35098386, -7598270, -10397070, -2626554, -18873688, -17913166, 19690802], [-681704399, 62630183, -18553151, -29643154, 33924105, -6855479, -59366768, 32393962], [2386721614, 210144502, 12228646, 42292387, -16830000, 14153603, 37789971, 57879515], [-2420380053, -175453839, 78349487, 14083806, -16624436, -24954874, 34056154, 7722406], [1356532873, -30866125, -30510499, 29109238, 23902379, -29214981, 15643808, 35994298], [1208715490, 49185150, 714514, -36473052, 19524150, 40106550, 4967696, 2325732], [2456783158, 345749818, 56757546, 8958595, 9185726, 4485073, 17908435, 18602363], [3301549195, -516615885, 22365805, 18831369, -16671130, 22975385, 24690587, -17519739], [-1407045622, 98332532, -22004772, 18664577, -11100976, 8839847, 27081767, 22862421], [7813089510, 15956042, -35255934, -24809448, -23053804, 5551114, -32554986, -73908796], [-2343140062, 597903120, -175728300, 22363350, 5784924, 26840448, 20009316, 10849938], [2011825898, -522334522, 3245638, -28881104, -43983118, 2868492, 19750938, 29577604], [-4747889823, -8952515, 116642139, -110533771, -5936683, -25512322, -26188039, -17503155], [1426465463, -22670999, -113937265, -24967534, -74200166, 20239528, 2045790, -58535382], [-866740311, 400511273, 42925487, 90990709, 19937397, -4254642, 46895033, 33412653], [5635989131, -23813327, 26383687, -1588800, -22761186, -15125866, -31842496, -56285704], [8395389628, 134770770, -57928534, -64694700, 41625442, -22467184, -65445362, -18465656], [-4109378297, -130601177, -11997991, 47266869, -73971869, -14092340, 36891529, 5392413], [6057481317, 199821623, -178386391, 60219172, 25117319, -32725319, 23097410, 68509520], [-9404104881, -589997829, -76937731, 79166797, 11415787, 17624152, 20879549, 36693981], [2909917302, -892965732, 67337356, 52163478, 82871477, 17525973, 9228296, 100593970], [-2669685, -684913575, 46650023, 102878628, 1373762, -31743134, 22812304, -28850500], [-1216409623, -313591397, 93752493, -23147398, -78372774, 13959128, -7377514, -12185494], [-6229943061, 215803459, 173769565, -39769595, 15737491, -12209476, -30356055, -20527955], [-1707161700, 341771622, -134125630, 47776053, 9037656, 72049783, 98468191, 15134737], [-7425136834, -235359426, -6803854, 88326398, -7071330, 54889796, 45697446, 69150206], [-1423172059, 411957279, 89201369, -10716270, -103277720, 6816562, -12654158, -63745542], [-13329896408, 530020818, 19164354, 43338580, -8500252, -18657950, -39850706, 96300656], [4569561240, 34738252, -391604, 98153462, 13622, 62404360, 43569058, 79773950], [-12389449451, -166106261, 56480381, -52006050, -39445685, -2378465, -27467708, -43187238], [-5986601835, 1165390173, 98554843, 92908077, 3727986, -77909851, -50402101, 47651393], [-1242544784, -1062214, 56980254, -65429207, 65315482, -101208463, -134146169, 16228573], [3001077062, 591147766, -87060266, -57384469, 155403468, -75042953, -185879765, 49817755], [-5236909464, 45647104, -38024920, -57543845, -16139375, 9852644, -2607949, -99446381], [2521487946, -480153828, -70005188, 104656330, -75488552, 83526666, 120508818, 67972802], [484687180, 502961140, -107446276, -65946723, -25582313, 64355848, 5489737, -147292011], [5260814944, -686894342, -126058854, -120345208, -7508108, -3036082, -37570294, 74515588], [15342852466, -677615636, -76094812, -29344519, -42720716, 88097595, 59180727, -5211379], [-22648496558, 115771058, 87412054, 13583236, -86693400, 75935064, 11168928, -86231076], [-15631611018, 272533546, 302458646, 6846594, 148668298, -34766260, -130132046, 99359746], [2513804501, -478559703, -314596073, -9189795, 9914737, -24628514, -107132515, -80134707]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_23_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_23_8_a_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_23_8_a_b(:prec:=8)
    chi := MakeCharacter_23_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_23_8_a_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_23_8_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_23_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![-37372224, -73308944, -13424272, 678328, 203052, -1059, -832, 0, 1]>],Snew);
    return Vf;
end function;