
// Make newform 245.12.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_245_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_245_12_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_245_12_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 := [-151, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    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_245_a();"
function MakeCharacter_245_a()
    N := 245;
    order := 1;
    char_gens := [197, 101];
    v := [1, 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_245_a_Hecke(Kf)
    return MakeCharacter_245_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 := 12;
    raw_aps := [[-10, 3], [110, -16], [3125, 0], [0, 0], [-309088, -26400], [-1707130, 12864], [-658970, -126528], [-2662660, -274560], [29471970, 33456], [47070190, 2298240], [-122271732, 7207200], [10501610, 19033728], [372871658, 22651200], [314975050, -13909104], [701030770, 20505072], [569160290, -186753984], [-3658757780, -175817280], [758212838, 53568000], [7867145070, -91691472], [16469235772, -54804000], [14991424430, -339617856], [-1651411560, -575636160], [-6649551210, 1100818224], [6337385430, 1455281280], [1540351870, -4545870528], [-43118460702, 3110524800], [4872759910, -3654504816], [148271607750, -183016272], [-8108731270, -11929614720], [-229226954470, 257790336], [-152862492410, -1101738672], [431249652768, 5448434400], [-30837648990, 1305424128], [21666125980, -19927638720], [924273719650, 5294505600], [868794124252, -15359968800], [-795446852450, 7245651072], [779038591130, -19604361264], [1633753407930, -56160730128], [-749035993170, -42989091456], [-142249751860, 72119893440], [2024990248018, 86883744000], [-3737955510308, 28562215200], [3465547847450, 12549343296], [-2308525846470, 51990212928], [-2645579186200, 61141939200], [4053832556912, 118450279200], [-5176459851170, -66224908656], [-5954557006390, -83377644528], [-3605577513990, -344103690240], [-113554278390, -425644309824], [-1480945470280, -135591199680], [5118617279858, 319363176000], [-8499532462752, 138265380000], [6031088410950, 246841414272], [-11466739254470, 21306333936], [12876374355190, -1026939183360], [-1058656645372, -504941344800], [26175460828290, -165926143872], [27178583660982, -814851019200], [9299004926190, 24859282224], [22935790250550, 1819739330304], [3547753353650, 980033377872], [42944218312188, -1252070896800], [-26762254375130, -2236486590336], [50932617480370, 1026952936128], [9539232167832, 2887732106400], [28249674994210, -4366650982272], [55676928860030, 3437400137328], [30880259434850, 2765028192000], [41944029649710, -590754873216], [-19505926968120, 7216768366080], [147988652664930, 1934584338672], [6304516136770, 3144863619456], [174951505636540, 4351892480640], [-107087900001810, 3333236023824], [-217099562743230, 2972897214720], [6813364590470, -1818740680128], [-49300384860798, 2511006297600], [315044811955570, 4967912886720], [-371786087869660, -5820041511360], [-395507050960478, 196324444800], [-99646338864468, -9334308194400], [434573403047390, 5095099593024], [-32093314391320, -3810912145920], [154460651669850, 7273236798096], [278766447290150, -15745261588800], [259329563665450, -17919073462272], [15644846809338, 14606092348800], [200520869270730, -7209626598864], [619557688080530, 4794202888272], [-308612783574840, 26368223386560], [-72805954563490, -10362037588272], [300174480066592, -25567649181600], [695424367984900, -16707565075200], [547411997009510, -21453730719216], [1096427185874770, -16468257646080], [-208453684250122, -11863397068800], [615747463502030, -13284105957456], [1195136775326742, 522596553600], [-84926225889770, -67623254925072], [633793458946650, 7353513529728], [425917167217470, 19053318234864], [-207058311595890, 31149223114560], [-439184274871528, 66626551562400], [-462730429250090, 88184700809472], [1007598778754490, -76705722737328], [-1002412880460850, -87878966493696], [1054192307502400, 33045374088000], [1113459935079898, -80206501512000], [-2810806823305150, -4011006720528], [-2879403210701270, -43730777619264], [-508630992912630, -38118424107072], [940111201298740, 135544934423040], [2729136620643532, -21611989264800], [-1495393658151858, 33595214347200], [-438447096269250, -121759533975696], [1914550262232370, 8564056458672], [1277925799623490, 141693585738816], [757551780381980, 22777650626880], [2944713244585838, -19914642796800], [575896550741970, -58454490250944], [-440497844973690, -59387484731328], [259006655391210, -106193148403824], [4202996166280808, 97804614496800], [1096032534452602, -77201380771200], [3424880494195030, 27791132830080], [1125729986746440, -132422753597760], [-998777606209190, 227994083173872], [6088126720024990, -87068161022976], [-4530310531234580, 266381990214720], [-5508934195095550, -67029114759504], [402106419657652, -26747732167200], [-6358661705048750, 27876049360128], [-6114091486087962, -100832786419200], [-3509957552231810, -360436951743360], [-8346713263588170, -11393989985856], [-1666188982550710, -416125359074928], [10515532289392670, -170266142104128], [7928743033849930, 110708601262080], [-13175778647288112, 259652899485600], [15276928441267122, 204788075683200], [-7962692451983230, 247167092270256], [-5070125214041410, -242113676963472], [3998578876123110, 181198969205760], [-9269145734351920, 161353097974080], [3519205024610310, 37371894561984], [19084895335263550, 89329083199872], [-2183194093990180, 276656015488320], [-2758517311676270, 360481001786736], [2832260906338290, -77300117398272], [4892535016086418, 313811345227200], [20498884353986210, 53903671880976], [12516801470275290, 594093628319472], [28106562176703150, -160222348470672], [-14622622353980188, -251452407578400], [-11794170715568240, -39325229317440], [-6785946428311990, -806453868968640], [17099516572041990, -145193604548928], [3647871907970858, -1270379557209600], [21935476044890430, 995518654567728], [-5784594199913110, 449881918626816], [1548045950206670, 1213527007186128], [7358602534659528, 1337357871746400], [17777563250648690, -1378898547655872], [16416451484239590, 711503608366224], [-10650329825322508, -1268843710576800], [-11650817390732130, -1132952514356928], [1344895397702930, 54901734564480], [-22920738243797530, 731726373824064], [-28752190619486340, 407024795218560], [11438057504327978, -1623772724505600], [20296052760225732, 962626719808800], [-37990719042441390, -199287556386624], [2538151313061680, -2264103478149120], [-37020906381385050, 1497917126140800], [12817358597804952, 932494842160800], [-6996142125460338, 2494112369280000], [17520165162066670, 1843671560253264], [11669452202102390, 1623564798397440], [29095667890462910, -584324664085872], [-38438888110716592, 1541548856200800], [-8058478351657550, 1926861694504896], [-21057085197620530, -2972549448395328], [-24214553161567710, 1654997844975216], [-49998599374803830, 250120562651520], [30659507731307370, -1058321190579072], [45925865994226430, 556369270360944], [-42611539065023410, 1281655519890240], [-50231175769039652, -103719230124000], [9644740362868310, -36948931689216], [55933324200027530, -1728510974020464], [-89933320469635128, -1489100685540000], [96655890250318918, 340229132716800], [-61764022917562890, 3920711565862128], [47287286680815350, 1418496349946304], [33679025948127502, -473225005598400], [-19205895886020270, -4489884101772864], [-52489396432617570, -1758713948540928], [33946326136055030, -716848472918256], [-8276988032589810, 686542868096640], [-20095526561610732, -842567463962400], [-99080277055113810, -473151355931328], [-60368688067714450, 1003154575641600], [30115936138467420, -1083903653993280], [59649621733540110, 3837510801468672], [16739386851120160, 4192895305080960], [142515502102412210, 1399355390082576], [-99840713298221430, -5606208202634880], [135968123042214808, -1323624602676000], [133409406148953530, -382169215313472], [-67856426287010002, -928040440118400], [-13982233441711110, 9656626545039216], [173765920558221850, -1190057394439728], [-69591948923786160, 4937863484571840], [148909192587529978, -4341841975992000], [-100716240845075210, -2759637157041072], [58163009184226638, 7794674674675200], [55567480766220070, 3687266742557328], [3589561608212970, 8850322955297856], [218474046198997282, 2088697139731200], [72970807079000800, -1373325626155200], [136490964856432530, -1902938929787520], [-111400836492017030, -4462623446740944], [-228371136362752390, 6149968937152272], [267141858512108690, -3413950770984960], [34862746842268590, -427938751536576], [-26795440232814080, 4239556085973120], [52139426695456370, 653053047565872], [-138291347136562248, -8095698941858400], [-77672393840105910, -8181170733134784], [65352575670953420, -6752873599927680], [60454935385117772, -6570168953704800], [-223053678752641018, 10156189594958400], [-170701960145663810, 14537269775333424], [-391825819668986310, -5456339444645328], [-407547549393862470, -3946357267408320], [-183110645415536750, 2851392459324096], [-85119735200206500, 5890751291520000], [55908646113487788, 3314209350088800], [162780423053112570, 19329497277976656], [-17699737690974432, 7770119348752800], [334415348904157550, 6263224166084304], [-218234434829482050, -7232861790240000], [-4182777083145090, 2480865342240384], [-333397860442817480, 1115059382248320], [-300583547508288470, -1828035720773328], [-312783258208896872, -4754800178191200], [97043550314525540, -10625655731232960], [-613212721968247990, -2376243858012624], [-77976262311727670, 11922723884564928], [69218103885260398, -23845223369664000], [211185564602543550, 17950310672837328], [-234505729881124830, -11008002142716480], [-445934066973997330, -13416680844807936], [-230872226174118540, 948081372591360], [-79775444247950978, -24075507632649600], [-62336167038283790, -22678111868479728], [391484274378837390, 14815658120652672], [520500312081419350, -901931163491328], [-505454841502337870, -10389563671173264], [-35192083894886330, -26497622119926672], [-240823639458279110, 1514161676490240], [305319598587328950, 16553693116917504], [-862345678698583530, -11346284889236928], [332708942000523500, 5635791623577600], [426373783329230, -5268861864107520], [-80127450075428122, -13217758312646400], [483431825816098970, 18183966721178256], [411057339539030810, -29921001297623424], [381751855934532058, 28396930264070400], [-638339305357403570, 19724058034020528], [-534484638805636490, -16412651504001216], [18833092065212880, 26047788139802880], [363169810935531510, 28512835377257472], [617152002071431390, -9472409104451376], [782576990205628110, 19706669394559728], [463141251504123870, 26044633992654720], [310539286668291702, -30014351287147200], [149119069937567088, -29799818249700000], [735615475045829630, -21583535778057456], [198412238619254932, -27303692999186400], [-485400963335371630, 11241566716439472], [-319791131827228062, -6200608984435200], [-527968694598090870, 14711002851045072], [1040649858146469972, 15091105920088800], [-335518278875657030, 39054012489569856], [634289589504195690, 14916174296046528], [-714676533796865840, 13901182707389760], [778936800433613130, -5593888690633920], [206897838177168202, 53170052203497600], [229531184465437850, -20335202625113328], [-916380909535892670, 42525163036115136], [841545484328221968, 11444995162682400], [-1881080532414646990, 5032397335627776], [-734956994417102250, 38790068479785600], [-1809890937983844452, -12238689380076000], [-252169142383598970, 36425339905215744], [737280274291895460, -60978950981187840], [584154484042678690, 32524400172846672], [-60069462432566850, -3500026820599296], [-169178638678623070, -43133668174169472], [1107722414409614200, 50999381467454400], [-24412959824520510, 61734358805523216], [-958059587789554688, -9673965335997600], [199825050945946370, 60628638664907328], [-2201571029485902210, -7277756856601872], [273268032838337410, 14785147733688960], [-171534726023444280, 14749730756929920], [321351739581867690, -54703095344237184], [687241859454735870, 90769753659899664], [-2049678183927870090, 7630091797052160], [139577903146024482, -81033380865004800], [1802598835445282210, 64674528744901776], [1212514985005411510, 19106880920093328], [-27848321994076570, -24287463337326720], [1057716538742439900, 100844979403401600], [32107373415442212, -123900570346788000], [1431750738705557670, 2000320609640064], [1117533563058863190, 22639523788021440], [-424049569747390232, -7121850157317600], [-1594005617920035790, 76659529917174528], [-1074049365894093242, 13728630060249600], [1630056487571546650, 54970013656520496], [81806714162727090, 9907577508038016], [625092194049819938, -104651150758929600], [415670631278356340, -131655216616124160], [-3573546006571493290, -2894182264313616], [711206699048733150, -102908170184101872], [-595135672254637870, 49870854989919936], [-2698250448700758678, -22112402953891200], [828457166184103010, 50126943035017728], [605579117017346680, 11044230455292480], [1818875232578001350, -27338534794546896], [1433307232109131952, -45262641274893600], [1975301409173306330, -109581358592378928], [-2727512961772356790, -46536063593331840], [-796735166746535770, 89119283147986944], [1937652943154696218, 4479879112689600], [1514681182030051290, 165917323749585072], [-2763775602955676150, 20503600408490496], [-2266999281303306470, 75332334297942528], [1136618748906996270, -88258825922935680], [1583259782979171612, 114559356503618400], [26707694969005610, 164361122568576], [1514285423033408820, -149012032601153280], [1816301078129933758, -2193701737920000], [3144188545774790830, -123547319508381072], [-5997097014506631252, 14419572955495200], [3079160961738942950, 92360960042868672], [711163932013231728, -150142294796282400], [3307264445915030490, 88016731340512128], [1460789939971191082, 25656442216204800], [-124780734978598810, 276112475106511824], [-368594772024326730, 253031857039326720], [-4404510544396246050, -89061952313599296], [1114892133801996200, -233907239821502400], [-2338609405084935912, 104316259766623200], [431111478222111570, 175024102582360128], [636482875072825970, -28735702204900944], [-2775907010522705390, -194620639695127872], [422044408225397158, -102398597006016000], [4434835616530994430, -45372447719020272], [136887175947885380, 170016095081705280], [-3860153851383814070, -186758006228018928], [1258430406018350170, 7726972847950656], [-1003270794200980890, -40152858103134528], [-5439580038205304310, 45436136949269616], [4716851334276067622, 155565630224164800], [-1294607561861721168, -25003941302892000], [1998057868357518180, -94941219592869120], [-3408918332917165750, -199959758246698704], [-309054451409985150, -353588244218755200], [6889231132136414148, -49087865848773600], [2536708340061003850, -35835961659991872], [-6910743972292285940, -20711586797763840], [-3758397013725730908, -155139379591168800], [-188907277494837650, -309389594189623296], [-6798280713519743430, 15751082155168320], [-414490082431949170, -36338115251046528], [2801423871618856778, 221611207540531200], [7694549809821932610, -63868468717540224], [6375045893470975630, -72891471255210672], [-6049029058437983150, -87267511575958272], [-4365995659167181380, 75426176079976320], [1127801008940763070, 103007851929491664], [-8182286395345044628, -149522307342252000], [7639591770973813510, -53584150484396928], [-421243770480225990, -110072454990202224], [5718322548308106690, 200146774920959472], [455695918725227670, -230556713812610880], [1502982776259830350, -166786643921709696], [-5170730652236021500, 253703981418878400], [-5984113436923656350, 133235188826795472], [6359639390666547212, -1533360888487200], [1757149480745382530, -1846697602443264], [11274957442794398440, 64936134081762240], [-9401045041244559690, 26731425472911360], [5200597409395109632, 147217358736991200], [-5437195010267239758, -102707005464364800], [1987743517353624950, -257719434919593600], [-518496947981673510, -415926758125694784], [-1378586812718164130, 590742246592013328], [3627109988650674110, 476857277226012672], [1606649866946336030, -480517118226577920], [6358758112295886308, -232945980112620000], [-889599889295111470, 295746862299870528], [-8840267608241443598, 167343176130067200], [2541143366423384310, -157228516943556816], [3301659897448118340, 495252281455227840], [2918222542217694990, 460923206003946624], [-4079713136545913190, 528363782226188928], [-4473838910357452750, -347318397739635504], [10281229969358876352, 20886849116340000], [13737872931119598050, -39882678741588672], [-9668464697300802662, -173082550219958400], [15692502154944219040, -86476932690399360], [12855301346147733290, 275597050161263472], [-3290364350093604930, 405518962116555072], [8481165300134895710, -448520409972922416], [-2955374294859337670, 109558205859598080], [-384755773992905770, 3174918756881472], [9846428385721768590, 232553687023546128], [2371552422927629980, 300641544089359680], [2193317332320246310, 83376965004163584], [5051786386468031950, -408068829442028928], [-3550678569224692670, 384032048277720336], [2664164089948816110, 479993868132375360], [6797016619519406728, 487597261808296800], [-8992226965380601400, 362489861736547200]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_245_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_245_12_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_245_12_a_b(:prec:=2)
    chi := MakeCharacter_245_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_245_12_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_245_12_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_245_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![-5336, 20, 1]>,<3,R![-142524, -220, 1]>],Snew);
    return Vf;
end function;