
// Make newform 3.19.b.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_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_3_19_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_3_19_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 := [16016, -1744, 123, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [59904, -11592, 216, -36], [229788, 201870, 22086, 882], [5911308, -139662, 1242, -4770]];
    Rf_basisdens := [1, 169, 169, 169];
    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_3_b();"
function MakeCharacter_3_b()
    N := 3;
    order := 2;
    char_gens := [2];
    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_3_b_Hecke();"
function MakeCharacter_3_b_Hecke(Kf)
    N := 3;
    order := 2;
    char_gens := [2];
    char_values := [[-1, 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 := 19;
    raw_aps := [[0, -1, 0, 0], [3969, 11, 1, 0], [0, 706, 45, -9], [-23936038, 0, -287, -287], [0, 3151562, -72135, 14427], [-1356555382, 0, 271492, 271492], [0, -45023208, 5174460, -1034892], [47854162370, 0, 5826567, 5826567], [0, 253636396, -75062610, 15012522], [0, -7721532154, -588630105, 117726021], [8932103771402, 0, 419221045, 419221045], [-118824958375558, 0, 147405468, 147405468], [0, 420913326988, -5946773490, 1189354698], [399901831143698, 0, -8960155673, -8960155673], [0, 564438621368, 43796122380, -8759224476], [0, 5144386753962, 61399629585, -12279925917], [0, 509087468002, -118883830635, 23776766127], [-551817186470998, 0, -222731765300, -222731765300], [-10332884019732478, 0, 96122514523, 96122514523], [0, -18502672209756, -2553691296870, 510738259374], [-11347488690614062, 0, 566482634352, 566482634352], [-44341346007473110, 0, 563620174117, 563620174117], [0, -110848762476802, 52215388155, -10443077631], [0, 476882969842068, 6310433389410, -1262086677882], [-872891133628690078, 0, -2928442015292, -2928442015292], [0, 1221980311235090, 1063295111925, -212659022385], [-312712740440063782, 0, 30953278602937, 30953278602937], [0, 128907588448890, -132923873425455, 26584774685091], [131287429846259210, 0, -16377895685508, -16377895685508], [0, -2449869469894616, 165513926636100, -33102785327220], [-4140723547582385398, 0, 95960394620013, 95960394620013], [0, -18538148030801834, 209429998000695, -41885999600139], [0, 3669864275362076, 417266690521590, -83453338104318], [24540703416544404530, 0, -103931941154093, -103931941154093], [0, 43529310940235770, -278545610751975, 55709122150395], [9552977312244579002, 0, 808579953774145, 808579953774145], [15225642144141578282, 0, 635078233563268, 635078233563268], [-2741904246957423262, 0, -1027563992374353, -1027563992374353], [0, 179969842349391892, -3947963797797390, 789592759559478], [0, -5171478240040834, 1682611707728115, -336522341545623], [0, -106570428063873234, 6372232771083795, -1274446554216759], [-171860324774953435558, 0, -3632869730927580, -3632869730927580], [0, -122555824716876832, 14209401255381360, -2841880251076272], [24573729861304252418, 0, 10826769575183632, 10826769575183632], [0, -319859350226796702, -30843584638017795, 6168716927603559], [-391125599800132992550, 0, -8179077900047343, -8179077900047343], [-164579627346349672798, 0, -16382252075526365, -16382252075526365], [-162318386178135763702, 0, 14291686381178917, 14291686381178917], [0, 2212288283094731654, 39368518236730575, -7873703647346115], [193167242116512693050, 0, 13010489555095492, 13010489555095492], [0, 2225049567066362028, 12326948870834430, -2465389774166886], [0, -660505849879273832, -64079722613414340, 12815944522682868], [1836936187777069647842, 0, 1281500597498560, 1281500597498560], [0, -4480380278210916030, -72538909376240475, 14507781875248095], [0, -247423777310925440, 88794795284478720, -17758959056895744], [0, -9758478964656702076, -210593533479981750, 42118706695996350], [0, 8361167139876665934, 120128985107648955, -24025797021529791], [6805362897468039833642, 0, 24666649220632725, 24666649220632725], [-5409943999785319055398, 0, -36522922948979012, -36522922948979012], [0, -7697387516302925644, 702573652316528370, -140514730463305674], [3396046772140553581778, 0, -19091333278926533, -19091333278926533], [0, 13316367627176827570, -210344745295823355, 42068949059164671], [-10900093244807902845598, 0, 502223739111708723, 502223739111708723], [0, 12927838434323271292, -226654920347710410, 45330984069542082], [-28881561374720809797742, 0, -166551822488134148, -166551822488134148], [0, -47550691792897185418, -253269078171193665, 50653815634238733], [37399173168246912552242, 0, -650603499509501405, -650603499509501405], [-73610358633467808263998, 0, -31524035917561292, -31524035917561292], [0, 18062343397195364338, 5844946742801613405, -1168989348560322681], [-27538746944245813357270, 0, 21834835904462452, 21834835904462452], [0, -79211382468227356528, 2742053850340574760, -548410770068114952], [0, 67860663345617451252, -1261398600479604510, 252279720095920902], [-46459436788421186313238, 0, 462396412270048933, 462396412270048933], [42567235221597466637018, 0, -939400720651674428, -939400720651674428], [139205299839257411767730, 0, -3106034802516238593, -3106034802516238593], [0, 198776400925514381248, -6171366740860689120, 1234273348172137824], [0, -259589782707540716542, -7285869620721732915, 1457173924144346583], [-31548161089176194051638, 0, 6856058653350613068, 6856058653350613068], [0, 313012519990963080280, 13273486829110979100, -2654697365822195820], [-199491181834792040875150, 0, -4382096274169540208, -4382096274169540208], [0, 321911758242694702054, -14103193517378054145, 2820638703475610829], [-471170514502689378761158, 0, -5292282201701685260, -5292282201701685260], [0, -191442016567211095944, 3072435671698768620, -614487134339753724], [-298228379583484941611902, 0, -11686038706944410028, -11686038706944410028], [624803965134351387013370, 0, -1626441004633242863, -1626441004633242863], [0, -1145168285208178496350, -14477653810131629355, 2895530762026325871], [0, -64896859089741003360, 51394062761465482800, -10278812552293096560], [-537524632559676887261998, 0, 17519604547378021648, 17519604547378021648], [0, -621316069044411566098, -53745049449884948085, 10749009889976989617], [582749647603319116861418, 0, 9668411053465292317, 9668411053465292317], [0, 1781243952434025735102, -42974665594324094565, 8594933118864818913], [0, -1299739736199554065744, 32827197212747793720, -6565439442549558744], [-957799582135918716035878, 0, -39134273513010310887, -39134273513010310887], [0, 911431016680114033978, 76293897863016739185, -15258779572603347837], [-181190898840680011096990, 0, -9777375104650692413, -9777375104650692413], [0, 2893499745794422554972, 36235347505057396710, -7247069501011479342], [0, -2382171897273994279658, -152191274289672177585, 30438254857934435517], [0, 1304673105030836138844, -5041048227689771370, 1008209645537954274], [1268352136376374353936338, 0, 2984092336391183127, 2984092336391183127], [4071831414396567851387882, 0, 37353247270136713020, 37353247270136713020], [-306779843964312468116638, 0, -49557098303894583857, -49557098303894583857], [0, -4657316222952603669570, 5559529475206851795, -1111905895041370359], [0, 5901504850282805850094, 91323169887719488275, -18264633977543897655], [0, 7077300526862772020324, 439282113942268013130, -87856422788453602626], [-4033694223300609386071918, 0, -88501312807366427045, -88501312807366427045], [3249719137967384717310242, 0, -146240007874343942652, -146240007874343942652], [0, -1656612926228796886294, -37192691161921626135, 7438538232384325227], [0, 4861574208051073912440, 530846265903167303820, -106169253180633460764], [0, -2979213493540320775220, -494955308250778003650, 98991061650155600730], [-10479892914319762987526158, 0, -131502279493480150160, -131502279493480150160], [2021540019975187262085962, 0, -200022175107657938387, -200022175107657938387], [3752163536825731028200058, 0, 305027684020938942252, 305027684020938942252], [0, 2200562997370148143852, -163850435699976045090, 32770087139995209018], [-5219076800595273853655950, 0, 183678062985273023347, 183678062985273023347], [-11647899045777682455694918, 0, 35906076187955065785, 35906076187955065785], [0, -1814816029101487185472, 714306997551834106560, -142861399510366821312], [-6230429945067970512951262, 0, 188119270309965536287, 188119270309965536287], [0, -13392342491080795347132, -243261899618365730070, 48652379923673146014], [0, -34294863995832756714098, 998348988536089636635, -199669797707217927327], [0, 52850980050040170624542, -756924606675203576085, 151384921335040715217], [12925756877622146841320282, 0, -397121828786085842420, -397121828786085842420], [29484894160445088836622818, 0, 374777666979413919172, 374777666979413919172], [0, 43492588718306382681074, -1223805164340286006875, 244761032868057201375], [0, 25668497793019781640858, 1490698106875467096705, -298139621375093419341], [-11680065853845816801012478, 0, -28443234306000206345, -28443234306000206345], [0, 18639476791964800995510, 265282970536933084575, -53056594107386616915], [-19323267873424773957815110, 0, 1367345818530777232252, 1367345818530777232252], [0, -69509232797721778480056, -1910383473846885638220, 382076694769377127644], [-6992011245667838285665798, 0, -514604092529140485287, -514604092529140485287], [32508436840070461498046378, 0, -1371073685821506911708, -1371073685821506911708], [-28224363964377398983872190, 0, -720113706291581408373, -720113706291581408373], [0, 24196102937630377454260, 2346960556017785344770, -469392111203557068954], [-14058276128587711585822678, 0, 1939730770888676265325, 1939730770888676265325], [-156907803368400766631427238, 0, -41107774503203044812, -41107774503203044812], [0, 63994574499108988215172, -2772193911902061638310, 554438782380412327662], [73610559433708770712485890, 0, 768619317411810129472, 768619317411810129472], [0, 28316743655244316888386, 8062580192323889185965, -1612516038464777837193], [132957192674464622812163522, 0, -1289196935549106692537, -1289196935549106692537], [0, 63196696570944122372998, 5490273963163105732455, -1098054792632621146491], [0, -70242628532021007421428, -9617767882508963234610, 1923553576501792646922], [117485344991017867396646162, 0, 2224631982215671531815, 2224631982215671531815], [0, 296227501219022970816554, 2903954096779635282705, -580790819355927056541], [100690247976723856328352698, 0, -1552255563592290572183, -1552255563592290572183], [0, -145087484355268494819486, 5956660368171462251925, -1191332073634292450385], [33666438779249702679595370, 0, -533448328610167525788, -533448328610167525788], [0, -276984726145862124970972, 2751775683221299547610, -550355136644259909522], [-69561677199334986284909542, 0, -3613423496113505957228, -3613423496113505957228], [0, -208198257172539023347180, -5677719889351911136830, 1135543977870382227366], [334477405176803823865727090, 0, -2721680101746341693393, -2721680101746341693393], [0, 493147753401490042583664, -4185692827825625865000, 837138565565125173000], [59060361042634266578677322, 0, 6370615148535362828068, 6370615148535362828068], [0, -302445935528745998180184, 3949617608310943682820, -789923521662188736564], [-337181016985849142851215742, 0, -2830454871845311243113, -2830454871845311243113], [0, -208982143656295530868964, 14911196011943586705990, -2982239202388717341198], [-29320328076113843637591598, 0, 2963519936830318263223, 2963519936830318263223], [0, -172969128155079028909528, 16648657560682728107940, -3329731512136545621588], [12166896526909249990501370, 0, 8115064276444221466377, 8115064276444221466377], [0, -337601203990860667423504, -36247553040968978793480, 7249510608193795758696], [-292394195312177247696210958, 0, 3765855098371575401868, 3765855098371575401868], [0, 931392826270835540555518, -1607033622353305194765, 321406724470661038953], [0, -882184771631354248615762, 23113923429812839588755, -4622784685962567917751], [0, 92675565059044172067492, 41761067218096679842410, -8352213443619335968482], [359722756199062494296253722, 0, 3392851732015707694873, 3392851732015707694873], [0, 349763543910165498022314, 17243346895215418228905, -3448669379043083645781], [0, 1085508615684852544919224, -16559055864122708430900, 3311811172824541686180], [0, 55324875618464723198348, -9757417040894797751970, 1951483408178959550394], [-1332260595794157591890195638, 0, -9156577827350648593395, -9156577827350648593395], [615491797929767059859312762, 0, 1379333793744892752268, 1379333793744892752268]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3_19_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_3_19_b_b(:prec:=4)
    chi := MakeCharacter_3_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 19));
    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_3_19_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_3_19_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,19,sign)));
    Vf := Kernel([<2,R![157480796160, 0, 1051056, 0, 1]>],Snew);
    return Vf;
end function;