{fHdZddlZddlZddlZdZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZ ej&ddZdZeej2dZeeej&Zeeej0Zeej4ej4Zeej6ej6Zeej8ej8Zeej:ej:Zeej<ej<Zeej>ej>Zeej@ej@Z eejBejBZ!eejDejDZ"eejFejFZ#eejHdZ$eejJdZ%eddZ&eddZ'dZ(dZ)dZ*dZ+d Z,ee*e,Z-ee)e+Z.d!Z/d"Z0d#Z1e1 Z2e1e1z Z3d$Z4e1d%d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8fZ5e6e5d9z Z7d:Z8d;Z9d<Z:d=Z;ee:e;ZZ=d?Z>d@Z?dAZ@gdBZAdCZBdDZCeeBeCZDgdEdddFZEgdGdddFZFdHZGdIZHdJZIdKZJdLZKdMZLgdNZMdOZNdZdPZOdZdQZPdZdRZQdSZRgdTZSgdUdddFZTgdVdddFZUgdWZVgdXZWdYZXy#eef$rej&Zej0ZYwxYw)[z This module complements the math and cmath builtin modules by providing fast machine precision versions of some additional functions (gamma, ...) and wrapping math/cmath functions so that they can be called with either real or complex arguments. Ng-DT! @giW @g;f?gw@gw?g9B.?gUk@gox?g]O?g m.fsn 7e !9  7g Q<  aA!9 :&  AQ<  sA"A-,A-__name__rrrs`` r _mathfun_realrs  AJ Hc8fd}j|_|S)Nct|tur|S t|S#ttf$rt|cYSwxYwr)rr rr r r s rrz_mathfun..f+sP 7g Q<  )%(# #:& )WQZ( ( )s- AArrs`` r_mathfunr*s)AJ Hrc8fd}j|_|S)Nc` d|DS#ttf$rd|DcYSwxYw)Nc32K|]}t|ywr)r.0r s r z(_mathfun_n..f..8s3E!H3c32K|]}t|ywrr rs rr z(_mathfun_n..f..:s8awqz8r!)r r )argsrrrs rrz_mathfun_n..f6s> :3d34 4:& :8489 9 :s --rrs`` r _mathfun_nr%5s: AJ HrgcL|dkr tdtj|SNzmath domain error)r mathlogr s rmath_logr,Bs# 801 1xx{rcL|dkr tdtj|Sr')r r)sqrtr+s r math_sqrtr/Fs# s701 1yy|rct||zSrr#)r ys rr2Ns GAJMrcttj|jtj|jSr)r r)floorrealimagzs rr2r2`s%gdjj($**QVV*<=rcttj|jtj|jSr)r r)ceilr5r6r7s rr2r2bs%gdii'166):;rcVtj|tj|fSr)r)cossinr+s rr2r2es488A; "rc |dzSNgUUUUUU?r+s rr2r2hs!d)rc |dzSrArBr7s rr2r2hsq4yrcpd|z } t||zS#ttf$rt||zcYSwxYwN?)rr r r r nrs rnthrootrJjs@ 1AQx1}  "qzQs 55c6|dkr t|  St|d\}}|tz}|dz}|dk(rtj|S|dk(rtj |S|dk(rtj| S|dk(rtj | SyNr?) _sinpi_realdivmodpir)r=r<rGs rrRrRqs1uQB !S>DAqGAFAAvdhhqk!Avdhhqk!Avtxx{l"Avtxx{l"vrc"|dkr| }t|d\}}|tz}|dz}|dk(rtj|S|dk(rtj| S|dk(rtj| S|dk(rtj|SyrL)rSrTr)r<r=rGs r _cospi_realrV|s1u B !S>DAqGAFAAvdhhqk!Avtxx{l"Avtxx{l"Avdhhqk!vrc|jdkr t|  St|jd\}}tt ||j z}|dz}|dk(rt j|S|dk(rt j|S|dk(rt j| S|dk(rt j| SyrL) r5_sinpi_complexrSrTr r6r?r=r<r8rHrIs rrXrXsvvzr""" !&&# DAq 71aff AFAAveiil"Aveiil"Avuyy|m#Avuyy|m#vrcr|jdkr| }t|jd\}}tt||jz}|dz}|dk(rt j |S|dk(rt j| S|dk(rt j | S|dk(rt j|SyrL)r5rSrTr r6r?r<r=rYs r_cospi_complexr[svvz B !&&# DAq 71aff AFAAveiil"Avuyy|m#Avuyy|m#Aveiil"vrc t|t|z S#t$r6t|jdkDrYyt|jdkrYywxYw)N ?)sinpicospi OverflowErrorr r6r+s rtanpircsRQx%(""  1:??R  1:??R  !AAAc t|t|z S#t$r6t|jdkDrYyt|jdkrYywxYw)Nr]r_r^)rar`rbr r6r+s rcotpirfsRQx%(""  1:??R  1:??R  rdggg?P5>ct|}||k(r"|dkr td|tkr t|S|dkr!tt |t d|z zz S|dz}td}tdtdzD]}|t|||zz z }|tzdz}d||dzzztj| z|zS)Nrzgamma function polerMrOrFrP' @) intZeroDivisionError_max_exact_gamma _exact_gammarTrR _gamma_real _lanczos_prange _lanczos_gr)exp)r _intxrIits rrprps FE z A:#$9: : $ $& &3w[^K!$4455 S qMq*Q,'A A!$ $A( NS &QsU3dhhrlBQFFrc|jstt|jS|jdkr!tt |t d|z zz S|dz}td}tdtdzD]}|t|||zz z }|tzdz}d||dzzztj| z|zS)NrMrOrFrrPrk) r6r rpr5rTrX_gamma_complexrqrrrsr?rt)r rIrvrws rryrys 66{166*++vv|^A&~ac'::;; S qMq*Q,'A A!$ $A( NS &QsU3eiimCaGGrcH dt|z S#t$r|dzcYSwxYw)NrFr()gammarmr+s rrgammar|s-%({ u s !!ct|dzSrE)r{r+s r factorialr~s 3<rct|turtjd|Stj|j|j S)Nr()rrr)atan2r6r5r+s rargrs8 Aw%zz#a  ::affQVV $$rcRt|ttfvr t|} |j }|j }|dkrt|dkr+tt|}|dk(r|j}|Sd|z } |j }|j }t|}|dk(rd}n |dkrd}nd}t dzt|zdt|z ztztt||z z t!|z dtz|z|zzS|dk(s|dk(r|dzSd} t|d kr"| t|z} |dz }t|d kr"d |dz t|zz|z } d|z } | | z} | d | zz } | | z} | d | zz } | | z} | d | zz } | | z} | d| zz } | | z} | d| zz } | | z} | d| zz } | | z} | d| zz } | | z} | d| zz } | | zS#ttf$rt|}YwxYw#t$r|}d}YwxYw#t$r|}d}YwxYw)Nr(rMrrOr^rFrg gdg?UUUUUU?gllfgJ?g88Cg#+K?g}<ٰj_gAAz?gSˆB)rrr r r r5r6AttributeErrorabsr*r{ conjugater4rTlogpir`loggamma) r xrealximagvr8reimrefloorimsignpsrIr2s rrrs Awug&& aA  s{ q6C<E!H AzKKMH aC BB) 9F #XFFBG $aF m4u< ai !"$,QK024R%-2FG GCx18s  A a&2+ SV  S a&2+ #s1v~-1A 1A 1B  ""AAGA "1 $$Aa2ga "1 $$Aa2ga "1 $$Aa2ga "1 $$Aa2ga "1 $$Aa2ga !! ##AQ"WQ  ""A q5LcI&  A   BB s4 G HH G>=G> HH H&%H&) rggAAp?gqg|?gYYrg^^^^^^ܿg柛n@gLQt:c$t|}||k(r|dkr td|dkrd|z }tt|z}nd}|dkr|d|z z}|dz }|dkr|dz}|}tD]}|||zz}|dkrn||z}|t |zd|z z S) Nrzpolygamma polerMrFr($@#B ;)rlrmrTrf _psi_coeffr,)r rurx2rwcs r _digamma_realr;s FE z A:#$45 53w E uQxK  d( SU  S d( BB A  QqS u9  R  x{?SU ""rc|jstt|jS|jdkrd|z }tt |z}nd}t |dkr|d|z z}|dz }t |dkr|dz}|}tD]}|||zz}t |dkrn||z}!|tj|zd|z z S)NrMrFr(rrr) r6r rr5rTrfrrr?r*)r rrrwrs r_digamma_complexrQs 66}QVV,--vv| E uQxK  a&4- SU  S a&4- BB A  QqS q6E>  R  uyy| c!e ##r) gS?g}^.@gCGb@g߸G?g1R5?gߵy?gLy~F?goO$y?gŕX3=?r) rFga o @ghr@g-@gF@gv#o?g,?gE㦰u?g󟿑?gan$hI?c4|d}|ddD] }|||zz} |S)NrrOrB)coeffsr rrs r_polyvalrs-q A ABZ !G Hrc||z}|x}}d}t|dkDrE|||z z}||||zdzz z}|dz }|||z z}||||zdzz z }|dz }t|dkDrEd|zS)NrOFFg  q5L q5Lrct|}||k7r|S|dkr t|  S|dk\r|dk\rydt|z St|S)z erf of a real number. r(rFrh)rerfrrr+s rrrsW aAAv3wQBxCx 8Yq\!! q>rct|}||k7r|S|dkr|dkrydt| z S|dkDr t|S|dk\r t|Sdt |z S)z erfc of a real number. r(grgg"@rF)rerfcrrrr+s rrrsk aAAv3w t848|3w1~Cx| Q r)*)gt?dsp?)gtr)g+K?rҹ?)g+Kr)gvV?5@}?)gvVr)gL?=Y?)gLr)gj ?{y?)gj r)gM&?u 85?)gM&r)g?N?)gr)gұ,n?T!~?)gұ,nr)gqE? sjΦ?)gqEr)gu=8| ?r?)gu=8| r)gY֮sj?ʴ?)gY֮sjr)gc#?1 ?)gc#r)g,?N@?)g,r)gԦV;?K?)gԦV;r)gW99?) ǰ?)gW99ݿr)gN%؟N?ۿ78a?)gN%؟Nٿr)gׄ ??)gׄ Կr)gQ'p_?,J?)gQ'p_пr)g^> ?KX?)g^> ǿr)g\S;S?QSβ?)g\S;Sr)g|?M _6?)g|ꢿrgD@cd|z }dx}}d} |||zz}||z }t|dkrn|dz }"|t|z|z }|rFt|tur|j}|j }n|}d}|dk(r|dkDr |t dzz }|St|tur6|j dkDr |t dzz }|j dkr |t dzz}|S)NrFrOgؗҜ  Q #a& A 7g FFEFFEEE C?g?g?) gA gpgp6g|Upg%gE3+Ӿgf{g'( gѲG]) rFg/" =g{%gh{srg9D"glXxkվg%ygծ*geuy-) g]u:=gh#%.Jg`5'>>g^ҹgU3 gPF; ?g2Mg=Ƨ_ΚcgviT{?g\?gH$?) ggI ;g.k^>gPNg/wogS' ?g7z2Mg)cg?g|ɐ?rMct|ttfs t|}|dk(r td|dk\rdd| zzd| zzSt|}||k(r|dk\r t|S|dzsy |d kr?d|zt|dz zztd |zztd|z ztd|z zS|dkr1|dkrtt||dz z Stt ||dz z Stt"|tt$|z }dd| zzd| zzd | z|zzS#ttf$rZ t |}|j s t t|jcYS t#ttf$rYtwxYwwxYw) z. Riemann zeta function, real argument rOz zeta(1) polerFrgg@rrPr(rMg@) isinstancerrlr r r r6zetar5NotImplementedError _zeta_intrTrRrpr_zeta_0_zeta_1_zeta_P_zeta_Q)rrHr8s rrrs a% & &aA Av((BwSA2Yr** AAAv 6Q< ACx1uR!A#Y{3q511+ac2BB4!9LLCx 8GA&!, ,"AaC((hwq11A r?SA2Y &r1 443I& & AJvv"4<00& % * % %   &s5 D!!F 14E/%F )F /F>F FF )F)Y__doc__operatorr)r?rTesqrt2sqrt5philn2ln10rcatalankhinchinaperyrrrr%r*r,r/r r r.powrtr<r=tanacosasinatancoshsinhtanhr4r:cos_sincbrtrJrRrVrXr[rar`rcrfrNINFNANEPSrolenrnrsrqrpryr{r|r~rrrrrdigammarrrrrrrrrrrrrrrrrrrrrBrrrs          DHHTN9:599% 5::&DHHeii(DHHeii(DHHeii(DHHeii( 5::& 5::&TYY +TYY +TYY +TYY +djj= ?TYY;= <> @#%89 # " $ # k>2k>2 t #gS#sCueVW Iz; m#%68J-/ |$Q& I G& H k>2 % 5n  #,$(  '7 8  $t %   $t %  #I   "* /X# 8 (#J   B$    B$    B  C 5m IxxH IsK K-,K-