
// Make newform 6.15.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_6_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_6_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_6_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 := [51, -22, 23, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-960, 1984, -192, 128], [56832, -32500, 5340, -968], [77088, 9424, 6864, 608]];
    Rf_basisdens := [1, 27, 27, 27];
    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_6_b();"
function MakeCharacter_6_b()
    N := 6;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_6_b_Hecke();"
function MakeCharacter_6_b_Hecke(Kf)
    N := 6;
    order := 2;
    char_gens := [5];
    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 := 15;
    raw_aps := [[0, 1, 0, 0], [-819, -7, -1, 0], [0, 351, 38, -19], [-413518, -111, 148, 259], [0, -85071, 12830, -6415], [-62053030, -780, 1040, 1820], [0, 2236668, -17912, 8956], [-313016902, 155127, -206836, -361963], [0, -43220418, 1492132, -746066], [0, -120388323, -1523374, 761687], [12136121378, 2683845, -3578460, -6262305], [-57340274902, -11636436, 15515248, 27151684], [0, -405730710, 56996612, -28498306], [-118780954006, 410247, -546996, -957243], [0, 6692871900, 29988840, -14994420], [0, 10733013003, 38071838, -19035919], [0, -8598314571, 273042214, -136521107], [-2002126733446, -517172004, 689562672, 1206734676], [-1426624547302, 840366747, -1120488996, -1960855743], [0, -5260134918, 2352370636, -1176185318], [7033949980850, -378277776, 504370368, 882648144], [-20073013180798, 303345813, -404461084, -707806897], [0, 144414004035, 20943453402, -10471726701], [0, 60399863214, -34631630756, 17315815378], [44561041643714, -5945558604, 7927411472, 13872970076], [0, 285532092423, 9637097878, -4818548939], [30208006438514, -11434453623, 15245938164, 26680391787], [0, -1382042902623, -22773659602, 11386829801], [157281114405530, -2175280308, 2900373744, 5075654052], [0, 113627365980, 57406017336, -28703008668], [404599322799074, -76541048163, 102054730884, 178595779047], [0, -3835892204361, -21588921694, 10794460847], [0, 2820627112722, 126450744884, -63225372442], [389068788082346, -50859664509, 67812886012, 118672550521], [0, 12823129632675, -145778842226, 72889421113], [-774508703363374, 80646094161, -107528125548, -188174219709], [-3500954870695750, -112567860108, 150090480144, 262658340252], [558360266081114, -104838847329, 139785129772, 244623977101], [0, -48567054421182, 615961992348, -307980996174], [0, 2141487207345, -1769641245318, 884820622659], [0, 15231288079875, -57880334998, 28940167499], [4586060786485898, 153446541396, -204595388528, -358041929924], [0, 29824715972448, -737218003040, 368609001520], [-328824539893630, -1140864484464, 1521152645952, 2662017130416], [0, -26854219938945, 7431547052038, -3715773526019], [-1762948562377678, 1333276577409, -1777702103212, -3110978680621], [17414077061626298, 2541536825187, -3388715766916, -5930252592103], [26687489112050594, 427196028789, -569594705052, -996790733841], [0, 149122784808759, 15328377281586, -7664188640793], [-14872339153746262, 3474863383284, -4633151177712, -8108014560996], [0, -490083822981726, -8809319123740, 4404659561870], [0, -426676012231764, -10982182987128, 5491091493564], [-11688320381450206, -511922780544, 682563707392, 1194486487936], [0, -474356622611859, -30079076522554, 15039538261277], [0, -881416877137968, 9565863013248, -4782931506624], [0, 1516908547619082, -9880636709012, 4940318354506], [0, 891680931038793, 56669121448298, -28334560724149], [82374788929955330, -5744745652923, 7659660870564, 13404406523487], [-113899236898445878, -10234784731572, 13646379642096, 23881164373668], [0, 2394228677620398, -11832574447684, 5916287223842], [83927883328164170, 10400635582443, -13867514109924, -24268149692367], [0, -881597352666633, -30253274191754, 15126637095877], [69786483692151674, -31750624812429, 42334166416572, 74084791229001], [0, -1702067717153898, 159562958919188, -79781479459594], [-35949078726388654, -38073293605236, 50764391473648, 88837685078884], [0, 127739029043061, 188452697941282, -94226348970641], [-190495343630264278, 11333480189331, -15111306919108, -26444787108439], [312792642036086498, -23196420031836, 30928560042448, 54124980074284], [0, 2768033772828645, -63578759994282, 31789379997141], [-692293742152232134, -3953049633372, 5270732844496, 9223782477868], [0, 1218801004198296, -379166451551440, 189583225775720], [0, -2862899877667230, 276407802164028, -138203901082014], [118482814651958978, 41862301984341, -55816402645788, -97678704630129], [-352840658682877174, -53595664949004, 71460886598672, 125056551547676], [-489099572779741558, -23183620621473, 30911494161964, 54095114783437], [0, 3740771536863120, -271383455659456, 135691727829728], [0, 1765134699532767, 1112858750469094, -556429375234547], [-17658383759805094, 382100947606620, -509467930142160, -891568877748780], [0, -20092715915136372, 184478243588552, -92239121794276], [838884369509257490, -80248746749232, 106998328998976, 187247075748208], [0, 14669357631409527, 1549124543347026, -774562271673513], [2481114640350309674, -161403737818908, 215204983758544, 376608721577452], [0, 11040922867687260, -1484361235908824, 742180617954412], [-497605851910381534, -312672698382204, 416896931176272, 729569629558476], [-250255222997198062, 288265532346657, -384354043128876, -672619575475533], [0, -33099561677586291, 1325209916148198, -662604958074099], [0, 13850177836216824, 1507836373261152, -753918186630576], [-1793571248626980430, -546640827598512, 728854436798016, 1275495264396528], [0, -87915591116064759, -42933584779702, 21466792389851], [-2537547248431039870, -442816152091539, 590421536122052, 1033237688213591], [0, 43353968209146579, -494902832217574, 247451416108787], [0, -39856183874170152, 312080792378256, -156040396189128], [340645479459853682, 1060493972003049, -1413991962670732, -2474485934673781], [0, 11636062128411249, 1352947306423150, -676473653211575], [-112391007517490950, -1018705175406909, 1358273567209212, 2376978742616121], [0, -77384235880432026, -3253957604778060, 1626978802389030], [0, 25822391770844325, -2078183444269822, 1039091722134911], [0, 83976983224086642, 4693210352902900, -2346605176451450], [8533016427482647850, 13085201116215, -17446934821620, -30532135937835], [-7890269198453851462, -1155266599962612, 1540355466616816, 2695622066579428], [2437422614677257818, -1104756567573825, 1473008756765100, 2577765324338925], [0, 72503156945012865, 3423039065098810, -1711519532549405], [0, -28393503871362933, -5401621412203734, 2700810706101867], [0, 65244444279048846, 12313019634129868, -6156509817064934], [27635570399971876490, -753201691308597, 1004268921744796, 1757470613053393], [-23338480671746373886, -894121878988620, 1192162505318160, 2086284384306780], [0, -70934071063803399, -2000743415342594, 1000371707671297], [0, -101293727663891964, -13900784317087064, 6950392158543532], [0, 127028279588906766, -880470528655484, 440235264327742], [-14750308051456056430, 1040431122067824, -1387241496090432, -2427672618158256], [-7906231903914926686, 178142684628381, -237523579504508, -415666264132889], [-6048455921459455318, 921178097027964, -1228237462703952, -2149415559731916], [0, 177998404995405522, 24523346861540516, -12261673430770258], [-19121473159638572182, 4786147845615843, -6381530460821124, -11167678306436967], [-51361652827675480174, -882676441621911, 1176901922162548, 2059578363784459], [0, 210913359528890904, 4216265928643520, -2108132964321760], [56390891491883566106, 156137741514639, -208183655352852, -364321396867491], [0, 265546595195738874, 4772869919242668, -2386434959621334], [0, 91706512938425337, -1134136492316630, 567068246158315], [0, 917475764126937147, -11251749981186374, 5625874990593187], [20472132086492136650, 2682242821480284, -3576323761973712, -6258566583453996], [66182484393285441602, -3581531164091724, 4775374885455632, 8356906049547356], [0, 488831808101761719, -5078078514913226, 2539039257456613], [0, 32335179410263977, 29229583867506702, -14614791933753351], [-19317208001947919878, -5014220405600025, 6685627207466700, 11699847613066725], [0, -794748741423992187, 39269161435767266, -19634580717883633], [14460545699166880490, 10859217666968460, -14478956889291280, -25338174556259740], [0, 85379306992536564, 7816014987070488, -3908007493535244], [37839652676566657106, 14415802433317449, -19221069911089932, -33636872344407381], [2473666797371104826, 12784226712729876, -17045635616973168, -29829862329703044], [54691573188075691610, -17213149364375349, 22950865819167132, 40164015183542481], [0, -301646913570896142, -57468009112231044, 28734004556115522], [-176140978421291003710, 1521485602307133, -2028647469742844, -3550133072049977], [121579971172143777290, 16395331307513508, -21860441743351344, -38255773050864852], [0, -613275996000602514, 74263555477340460, -37131777738670230], [48287913592675490306, -24964302808368384, 33285737077824512, 58250039886192896], [0, -497694800580982929, 60141870940690086, -30070935470345043], [-68196329005595851846, 4902232999071159, -6536310665428212, -11438543664499371], [0, 3604434768826584765, -22270726359412014, 11135363179706007], [0, -969398931384734070, 23983974061553284, -11991987030776642], [277020933079518515306, 21416738861423943, -28555651815231924, -49972390676655867], [0, -3689185399380190341, -23458551980804450, 11729275990402225], [-366962926723316524270, 6106884016953945, -8142512022605260, -14249396039559205], [0, 1621722878261887749, 66421983139622566, -33210991569811283], [-9493117653403052422, -58416205092437292, 77888273456583056, 136304478549020348], [0, -2899291939867580262, 30323857344072780, -15161928672036390], [14310978229456969802, 2169485300258820, -2892647067011760, -5062132367270580], [0, -258713666886057450, -106602740182472868, 53301370091236434], [-52859330911831468726, 8231548274743695, -10975397699658260, -19206945974401955], [0, 6020429754453882504, -25675178029724720, 12837589014862360], [29774563010859597722, 43065693988714644, -57420925318286192, -100486619307000836], [0, -1533056537668730244, -314997117395153224, 157498558697576612], [326465974395365086586, -24702307811265273, 32936410415020364, 57638718226285637], [0, 5231791116904559814, 99503147872640756, -49751573936320378], [402081625519646695466, 8820810269879511, -11761080359839348, -20581890629718859], [0, -2260189917185992908, 147360558802781112, -73680279401390556], [314166291405946180562, 15648376521888441, -20864502029184588, -36512878551073029], [0, 981106984343000928, 107421137542218192, -53710568771109096], [-701844276720662408590, -35501087079818724, 47334782773091632, 82835869852910356], [0, -4282833350148330975, -1549452661448198, 774726330724099], [0, -2355745202939451021, -552576101445225750, 276288050722612875], [0, 5754356693684321742, 216303400507889292, -108151700253944646], [-647751530061008993998, -121045847108695767, 161394462811594356, 282440309920290123], [0, -3607166014248420495, 238793892753009342, -119396946376504671], [0, -3666569063534124756, 385586805583276264, -192793402791638132], [0, -3259814692841485794, -414549853394097212, 207274926697048606], [-158046527595828216670, 155671867201623165, -207562489602164220, -363234356803787385], [-76861976737397885014, -104364475336048932, 139152633781398576, 243517109117447508]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6_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_6_15_b_a(:prec:=4)
    chi := MakeCharacter_6_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_6_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_6_15_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,15,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;