
// Make newform 4.15.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_4_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_4_15_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_4_15_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 := [982333440, 21572352, 325632, -1824, 88, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-1, 4, 0, 0, 0, 0], [-52022784, 1274304, -116112, 14692, -253, 1], [477, -64, 16, 0, 0, 0], [-30471680, -798016, -12112, 596, 119, -3], [18836992, 291264, -1424, 100, 3, 1]];
    Rf_basisdens := [1, 1, 196608, 1, 2048, 1024];
    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_4_b();"
function MakeCharacter_4_b()
    N := 4;
    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_4_b_Hecke();"
function MakeCharacter_4_b_Hecke(Kf)
    N := 4;
    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 := 15;
    raw_aps := [[-15, 1, 0, 0, 0, 0], [0, -1, 1, 0, 0, 0], [1363, 62, 0, -3, 1, 0], [-600, -1794, -42, 40, 8, -4], [-34256, -102439, 831, -720, -144, -440], [-13330889, 395798, 0, 897, -299, -1664], [-19693924, 997740, 0, -10494, 3498, -3136], [581904, 1663419, 88269, -11760, -2352, 5784], [5797208, 17918266, -558222, -32040, -6408, 63620], [-1324329461, 45071342, 0, 21381, -7127, -182784], [-37573824, -102230424, -9678024, -360640, -72128, -452384], [5218198335, -10269914, 0, -2437863, 812621, 243584], [13651689734, -730386792, 0, 1251108, -417036, 2829440], [355926432, 1003107705, 61198167, -533600, -106720, 4007024], [131493520, 424076948, -6819660, -22673520, -4534704, -103208], [14179007655, 4185562774, 0, 13230273, -4410091, -17907584], [709108160, 2791293853, -546697917, -117080640, -23416128, -190816], [1032026495719, -8969021962, 0, 13189713, -4396571, 34925440], [7139475600, 22564537239, -1427452239, 187034000, 37406800, 94307800], [-2324968248, -7719530850, 805631430, -32308920, -6461784, -28696404], [-4979827917204, 1972003948, 0, -134328318, 44776106, 3229376], [-4606467504, -8638783044, -4855786644, -254552240, -50910448, -70280584], [-19227358976, -61868726269, 4480550013, -70444800, -14088960, -223455872], [-30171664582948, -30627930036, 0, -1615544622, 538514874, 257091776], [-57706577018604, -393968566340, 0, 2389807866, -796602622, 1383852224], [82063904434391, 396032177526, 0, -2939595759, 979865253, -1346508160], [87139596264, 222866402742, 40994993214, -3206889880, -641377976, 764282716], [-322434658224, -962668460127, -9013839225, 7513027920, 1502605584, -3134703240], [165207130285995, -307401846674, 0, -1824052155, 608017385, 1385939456], [-208652058236750, 615864695264, 0, 206320848, -68773616, -2490476544], [935238339360, 2954833931952, -176410119456, 15566748960, 3113349792, 11724456624], [-595782581776, -1683443721833, -115691334303, 17336156400, 3467231280, -5548845592], [-346309942112426, 3831021639032, 0, 15193906548, -5064635516, -16646702976], [160287147744, -20225924655, 506384522655, -6650071840, -1330014368, 1352917072], [-269265689381429, 393734998670, 0, 17624349429, -5874783143, -3044062464], [1892049891672, 5395677683034, 177724527954, 75899436760, 15179887352, 26848027268], [-490358674755857, -5922202835482, 0, -78960905031, 26320301677, 30337596544], [1640220471648, 5861450896503, -850295549895, -101949962400, -20389992480, 11456030736], [-836349471544, -3703577566154, 1246371633198, -39551899320, -7910379864, -12290582356], [-2986777840479665, 6683123722214, 0, 112192392633, -37397464211, -36151672704], [-4063878511968, -10794613187637, -1568321109627, 203165281440, 40633056288, -31866520080], [-4716710543657965, 19345929246462, 0, -161613373923, 53871124641, -64280801280], [13488015708256, 41184161353184, -1220700617136, 324454209120, 64890841824, 176132179600], [3900305297590468, 660009654236, 0, 575050595370, -191683531790, -50379070784], [-4848186184895845, -29531883711954, 0, -213247956123, 71082652041, 136301237504], [-6894963543384, -17432616168018, -3006707194458, -156209724120, -31241944824, -89357543556], [-22650120956640, -74343815676237, 6107643619293, 507445110560, 101489022112, -221635923536], [-29394999647808, -89720669987496, 2809644220296, -878074733120, -175614946624, -395898443104], [-2384255553536, -14229386673385, 8257075201257, -1077450117120, -215490023424, -103005071360], [3719438731688107, 53924634168974, 0, -277261739787, 92420579929, -193552442624], [-5525535876700900, -76649305131636, 0, -176022983502, 58674327834, 322438206656], [24821640374384, 61012627504180, 13013182247940, 146710830960, 29342166192, 292400540072], [-23860888696579748, -200281139058580, 0, -327479937150, 109159979050, 831522320320], [61619628732096, 199002376786317, -10956537174573, -3631332582720, -726266516544, 444379167264], [-68276551030338398, 353348374272704, 0, 1534954901280, -511651633760, -1546468978176], [-117324208568888, -324445412691634, -27344694634602, 1074974427720, 214994885544, -1257492808148], [59797069730758787, 365574866806974, 0, -1060599459267, 353533153089, -1380143820544], [220181898154608, 668092488178812, -10788397914948, 690862754160, 138172550832, 2550741445800], [7573482974912055, -162967167748874, 0, 3633873689937, -1211291229979, 352879965824], [26400134272636372, -613128324995620, 0, -1147656016470, 382552005490, 2557616664000], [228804869053392, 645495029665917, 38648340021099, -307175917360, -61435183472, 2578413390520], [-65421348680566853, 141335356657262, 0, 314940707781, -104980235927, -593751531264], [-273615576641712, -815278230924093, 3884137641189, -5925864627120, -1185172925424, -3526772015112], [121089392043992, 313999498005442, 50339525107242, -2285816627880, -457163325576, 1214969647172], [220169490947398438, 166342513006616, 0, -6193270623900, 2064423541300, -154009049984], [-53989963911223877, 1811609825243918, 0, -3708614607051, 1236204869017, -6967731419136], [868741781351376, 2535283571892921, 59919868628271, 1074158487760, 214831697552, 9947745045176], [-5128058638092918, 1036614525942064, 0, -18144810696120, 6048270232040, -2657115548416], [-520034228584864, -1733432406071915, 194678418165147, -14423048641440, -2884609728288, -6925649206384], [-16909500027470877, 1705941540811198, 0, 22329945286077, -7443315095359, -8704526412544], [-123939574990577878, 419663027474352, 0, 26831473308936, -8943824436312, -3912370050304], [-773508849844632, -2126866906556106, -179046790841346, -5439725458200, -1087945091640, -9173126678244], [-2281478670969072, -6531652300573020, -272756516668188, -13173190526960, -2634638105392, -26854005139048], [-744476593700842017, 4177149996629926, 0, -8928150468135, 2976050156045, -16034678260864], [-1172528041973472, -3819815615267235, 263539295261235, 48592793221920, 9718558644384, -9900599136336], [1619964137724800, 5197756628516128, -364345157324640, 7540963447680, 1508192689536, 18939978535232], [-528788965142966785, -1423720741079514, 0, -6664884219495, 2221628073165, 6270930448256], [1389850961656503003, 2206698796978318, 0, -20855286405771, 6951762135257, -7131283311616], [-1322828731311608372, -4463939149593076, 0, -57405880713486, 19135293571162, 22692077714880], [74404365873252982, 7036611005078264, 0, 8848895428788, -2949631809596, -28993928422784], [-1642940073401968, -4917825566073905, -39025630554375, 43627027585680, 8725405517136, -15596051163304], [-258085184630876045, -620131015062658, 0, 3900228069597, -1300076023199, 2166772295680], [-981117732877200, -4003091143248156, 1021589980435284, 46052426548080, 9210485309616, -7904462366808], [-2900509615438552020, -3210353614860596, 0, -821915151342, 273971717114, 12961204262336], [5311401551388120, 15477938263279842, 528627557706762, -123982847470760, -24796569494152, 51621680648516], [25565088985648, 619768900642997, -466952094097821, -71382808627920, -14276561725584, -4738730960312], [-2653349292454079772, -7984731032407652, 0, 39261094991562, -13087031663854, 28808574575296], [1664856476960846710, -10047127830266824, 0, 100040782214292, -33346927404764, 32046659964544], [2447489917074894227, 4062585297582750, 0, -28381216350195, 9460405450065, -13960000641280], [4982279271948240, 14160506447190492, 633815920753164, 89586838039760, 17917367607952, 62928609861304], [1999517217639024, 4619731446003867, 1371232447550109, -14137944731280, -2827588946256, 21725704094376], [-7126418445073856, -20670948899586088, -463013865972408, -153496047614400, -30699209522880, -91796522048672], [413092349801928, 4008667177985286, -2911659095441442, 128519922866760, 25703984573352, 13749043995180], [-2272213111982080, -5603008244971943, -883912326122073, -283896371496960, -56779274299392, -45822393355264], [4339823497564416, 13622640633579147, -736964252165643, 78917816295680, 15783563259136, 54876294984064], [3636987849859128, 6834062785300770, 3817005631219962, 204180295744440, 40836059148888, 55714837312212], [89818950491669807, -53121503565268506, 0, 54264183559353, -18088061186451, 208835517155456], [8051751184551796422, 33408972746048920, 0, 42692889258660, -14230963086220, -137716033965440], [15975404386514064, 49420611168253833, -1925869104720705, 233482505969040, 46696501193808, 197988590040024], [-3500902706509678953, 103574806661165590, 0, 7976635727745, -2658878575915, -416625129047680], [10488417826433808, 33585650339529519, -1326982200408999, -852536177181680, -170507235436336, 59121517362584], [-2567938622526379897, -3255571414241802, 0, -400030790971311, 133343596990437, 46276604127104], [3952678344426704, 13625325845340355, -2724452808707163, 852203581321680, 170440716264336, 104958415325240], [4424671012827688774, -23542796750220328, 0, 473636172242436, -157878724080812, 55238216294016], [-41598917315411088, -125791770985087755, 1529709075847875, -57896029087120, -11579205817424, -476794007906264], [-3981740849244807798, -6034378955697296, 0, -766068451845720, 255356150615240, 87817109613824], [36480432792330928, 102947615326459241, 5555665577116143, 489013852106160, 97802770421232, 449003621311240], [3998726729306489522, -137684406171392928, 0, 197358408306576, -65786136102192, 536568938686976], [-5411385565369672, -27226406187901574, 10256396491931106, 744866768080440, 148973353616088, -9013768218988], [-20678879352474243812, 130923844035326924, 0, -79185932419566, 26395310806522, -519226244037440], [25270275071996448, 82105043092966632, -7496064324883416, 854482084328480, 170896416865696, 347364363577648], [16766272022407017395, 181861884247917054, 0, -303939837520227, 101313279173409, -705142413410304], [-8792255533443050060, -146074943690606884, 0, 975435307925802, -325145102641934, 505686535449024], [-32801020418683536, -95411905270683471, -1531204177712121, -1015655399734160, -203131079946832, -444296407920856], [-5434732342030536, -39317866274166078, 22197652617424602, 820002078972600, 164000415794520, -3985448322732], [6355447562535799348, 153095587425608444, 0, -121148030361126, 40382676787042, -604786592228160], [48464981788500240, 145944533826744231, -2054331816033567, 891214792282640, 178242958456528, 613528562507416], [5312358383369544, 34874005587348846, -20200044545239242, 1123584746502600, 224716949300520, 139529361496428], [-21332320461400976941, -21313833749710050, 0, 256236603221709, -85412201073903, 64330430855936], [21574995928492480, 55201048176549683, 9391275149252013, -105101098482240, -21020219696448, 237765558157984], [39443182439908680643, 17548036149933854, 0, -954576271847091, 318192090615697, 8754511920640], [18199374706383099940, -172056119998888036, 0, 1184593417377738, -394864472459246, 592668765889216], [65673116600386607, -32598110317674426, 0, 329716821422025, -109905607140675, 103550050903424], [-122084418066238464, -365247283501779255, 2255959459980087, -1751225432509440, -350245086501888, -1510704724406784], [135759331828602912, 394284310134749451, 11620462895931141, -158341356447200, -31668271289440, 1531563811575344], [-84899796463256837737, -58513355049789546, 0, -1543247789326911, 514415929775637, 363080894360960], [25988998949943946495, -25250354739393754, 0, -2669184445139175, 889728148379725, 322945782887296], [96687522904677648, 288764940991788732, -3206350375832628, 3181131101126160, 636226220225232, 1322846996950680], [123637635859100088, 396165143017484058, -22656714829201470, -3737191609613000, -747438321922600, 1141670998630676], [-49928875404588000933, -631216726048852658, 0, 875216321677461, -291738773892487, 2462365148865536], [-62197370783657856, -202715028117451305, 17231669602982505, -375509202003840, -75101840400768, -733244634500928], [130992964996160456, 410586770356359238, -18795351405279330, -281264052068280, -56252810413656, 1468740089469740], [-8026616044412112, -70053925353910764, 45233420087510916, 777117237397040, 155423447479408, -36460104233528], [50724171263335272107, 357848807380728654, 0, -3021301315278315, 1007100438426105, -1186379840153856], [76521538237283034214, -869702856200123752, 0, -2910419317002972, 970139772334324, 3734343462188160], [38408143192189232068, 389169875505231068, 0, 2652287127961002, -884095709320334, -1783067507964224], [-70654315691879603569, 266466435414446598, 0, 5344182909184617, -1781394303061539, -1513706354233984], [-173264496885821856, -556002774379115997, 46635811549167885, -7900954903776160, -1580190980755232, -2525572923741296], [-107230432280565115745, -820612635932391034, 0, 111465092037417, -37155030679139, 3286381622611584], [8350336509461813222, -73569893460736296, 0, 6834687321835908, -2278229107278636, -271808478676864], [219485310390162864, 646493927507812161, 18761121480270231, -8681610173443920, -1736322034688784, 1882492355850120], [19451761906838607871, -70992342569222554, 0, 3749249644492281, -1249749881497427, -26072891902080], [-370955483540489640, -1055345298418143870, -62594300850514518, 8677203444725720, 1735440688945144, -3604054797536252], [-187098882215075184, -687043687031222331, 122000061161163651, 5486550467095440, 1097310093419088, -1739571242262312], [87706030427469603887, 1371489462135868134, 0, -770148275280327, 256716091760109, -5444068531914624], [-289345024725792152, -857809077223628242, 8849552818666758, -14748443261642520, -2949688652328504, -4327106510772452], [248622787297391062935, 705123978982931254, 0, 566124826292913, -188708275430971, -2878810811484544], [-5113459344344319770, 1698359921225180696, 0, -2809123372219548, 936374457406516, -6587569095847296], [-129902197194933600, -440566898660042187, 52773125983977243, -407917906303840, -81583581260768, -1504901002432016], [-96766094781699840, -301035717492431208, -14798963825843736, 24882898390882560, 4976579678176512, 653498582292864], [203808196855620761059, -50387099101947778, 0, 15677045908648413, -5225681969549471, -1098815996024576], [135007179733190222346, -938070978835114064, 0, -9790613726554104, 3263537908851368, 4579961161381120], [352199498448340080, 1075128602470048803, -9579603506482155, -12100252833125520, -2420050566625104, 3149749214579112], [588201580303812056, 1885499581967777362, -135391760747629926, 7298591852755800, 1459718370551160, 7198327838532932], [78670072558572672, 267975122181529185, -56230527906370593, 21833384147459200, 4366676829491840, 2432239253100224], [-818156584590629840, -2617609851542477572, 167522658655182108, 4591201982445360, 918240396489072, -8973762867039416], [281060120306872728, 1041549541715884602, -179358372903317358, -20743218840747240, -4148643768149448, 1732410948798180], [187309619866633120324, 3250904812297939292, 0, 31864756083306, -10621585361102, -13058487351768384], [165533646611544192060, -459036919238684084, 0, -19751450549868078, 6583816849956026, 3482865718618304], [-330675976618938778853, -1457974881466564210, 0, -16777178341191435, 5592392780397145, 7247804152012800], [-404349026117772272, -1483183189651685821, 288907163906255301, -13243138040087280, -2648627608017456, -5527914567799016], [818076337983048769334, 890225216893338360, 0, 23386444141319604, -7795481380439868, -5516245230845824], [762232234850664936, 2424589356910577166, -153295438603430682, 6297377438386280, 1259475487677256, 9105408806462044], [-658958902409862720, -1629018695920893999, -313019183915714289, -25550508579324480, -5110101715864896, -9288318813655392], [660613506257837736284, -5738215181309993748, 0, -10577722854931902, 3525907618310634, 23922977725482944], [-982822883838741128, -2471923169809124038, -451650597015444606, -12823003917482760, -2564600783496552, -12071880774171980], [390423405602361312, 599925065746194216, 551200528765690056, 14674133294853600, 2934826658970720, 5470489000346064], [-546271352177000836817, -2799447730144954042, 0, -8538062380029111, 2846020793343037, 11951409716193664]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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