K iddlmZmZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZddlZm[Z[ddlZm\Z\e]jZ_Gdde]Z`Gdde`Zad Zbd Zcd Zdd ecd eddZed3dZfefddddea_gefddeczdeczdedzea_hefddeczdeczdedzea_iefddeczdeczdedzea_jefd d!eczd"eczd#edzea_kefd$d%eczd&eczd'ea_lefd(eed)eczd*edzea_meajea_neajea_oeajea_peajea_rGd+d,eaZsGd-d.e`ZteuetfZvGd/d0e]Zw d1d2lxZxexjjetexjjeay2#e|$rYy2wxYw)4) basestringexec_)WMPZMPZ_ZEROMPZ_ONE int_typesrepr_dps round_floor round_ceiling dps_to_prec round_nearest prec_to_dps ComplexResult to_pickable from_pickable normalizefrom_int from_float from_npfloat from_Decimalfrom_strto_intto_floatto_str from_rational from_man_expfonefzerofinffninffnanmpf_absmpf_posmpf_negmpf_addmpf_submpf_mul mpf_mul_intmpf_div mpf_rdiv_int mpf_pow_intmpf_modmpf_eqmpf_cmpmpf_ltmpf_gtmpf_lempf_gempf_hashmpf_randmpf_sumbitcountto_fixed mpc_to_strmpc_to_complexmpc_hashmpc_posmpc_is_nonzerompc_neg mpc_conjugatempc_absmpc_add mpc_add_mpfmpc_sub mpc_sub_mpfmpc_mul mpc_mul_mpf mpc_mul_intmpc_div mpc_div_mpfmpc_pow mpc_pow_mpf mpc_pow_int mpc_mpf_divmpf_powmpf_pi mpf_degreempf_empf_phimpf_ln2mpf_ln10 mpf_euler mpf_catalan mpf_apery mpf_khinchin mpf_glaisher mpf_twinprime mpf_mertensr)rational) function_docsceZdZdZgZdZy) mpnumericzBase class for mpf and mpc.ctN)NotImplementedError)clsvals Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpmath/ctx_mp_python.py__new__zmpnumeric.__new__$s!!N)__name__ __module__ __qualname____doc__ __slots__rerfrdr^r^!s%I"rfr^cpeZdZdZdgZefdZedZedZ edZ e dZ e dZ e d Ze d Ze d Ze d Zd ZdZdZdZdZdZdZdZdZdZdZeZdZdZdZ dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d+d(Z-d)Z.d*Z/y'),_mpfz An mpf instance holds a real-valued floating-point number. mpf:s work analogously to Python floats, but support arbitrary-precision arithmetic. _mpf_c |jj\}}|r6|jd|}d|vrt|d}|jd|}t ||ur9|j \}}}}|s|r|St |} t||||||| _| St |turt|dk(r&t |} t|d|d||| _| St|dk(rG|tttfvr |\}}}}t|t|||||}t |} || _| Stt |} t!|j#|||||| _| S)zA new mpf can be created from a Python float, an int, a or a decimal string representing a number in floating-point format.precdpsroundingr)context_prec_roundinggetr typeronewrtuplelenrrr r!r ValueErrorr#mpf_convert_arg) rbrckwargsrqrssignmanexpbcvs rdrez _mpf.__new__/sb33h ::fd+D"6%=1zz*h7H 9 !$ D#sBS CAc3D(CAGH #Y% 3x1}H&s1vs1vtXF3x1}tUD11),&D#sB#D#c(CT8LCH CAc11#tXFhWAGHrfcbt|tr t|St|tr t |St|t r t |||St||jjr|j||St|dr |jSt|drC|jj|j||}t|dr |jSt|dr!|j\}}||k(r|Stdt!dt#|z)Nro_mpmath__mpi_z,can only create mpf from zero-width intervalcannot create mpf from ) isinstancerrfloatrrrrwconstantfunchasattrroconvertrrr~ TypeErrorrepr)rbxrqrstabs rdrz_mpf.mpf_convert_argRs a #HQK%7 a  1 !5 a $Xax-H&H a-- .qvvdH7M0M 1g qww 1j ! ##AJJtX$>?Aq'"ww 1g 77DAqAvKL L1DG;<z _mpf.{sDJJqOrfc |jdSNrrrs rdrz _mpf.| 1 rfc |jdS)Nrtrrs rdrz _mpf.}rrfc |jdS)Nrrrs rdrz _mpf.~stzz!}rfc|Sr`rlrs rdrz _mpf.srfc.|jjSr`)rwzerors rdrz _mpf.s!2!2rfc|Sr`rlrs rdrz _mpf.sTrfc,t|jSr`)rrors rd __getstate__z_mpf.__getstate__s;tzz#::rfc$t||_yr`)rrorrcs rd __setstate__z_mpf.__setstate__s mC.@rfc|jjr t|Sdt|j|jj zS)Nz mpf('%s'))rwprettystrrro _repr_digitsss rd__repr__z _mpf.__repr__s8 99  q6MVAGGQYY-C-CDDDrfcVt|j|jjSr`)rrorw _str_digitsrs rd__str__z _mpf.__str__s6!''199+@+@AArfc,t|jSr`)r3rors rd__hash__z _mpf.__hash__sHQWW--rfc>tt|jSr`)intrrors rd__int__z _mpf.__int__s3vagg//rfc>tt|jSr`)longrrors rd__long__z _mpf.__long__sD11rfc^t|j|jjdSNr)rnd)rrorwrxrs rd __float__z_mpf.__float__s!Xagg1993K3KA3NOOrfc*tt|Sr`)complexrrs rd __complex__z_mpf.__complex__swuQx00rfc(|jtk7Sr`)rorrs rd __nonzero__z_mpf.__nonzero__sqww%//rfct|j\}}\}}||}t|j|||_|Sr`)_ctxdatar"rorrbr{rqrsrs rd__abs__z _mpf.__abs__9%&ZZ"S"4 H!''42rfct|j\}}\}}||}t|j|||_|Sr`)rr#rors rd__pos__z _mpf.__pos__rrfct|j\}}\}}||}t|j|||_|Sr`)rr$rors rd__neg__z _mpf.__neg__rrfct|dr |j}n|j|}|tur|S||j|SNro)rrorr)rrrs rd_cmpz _mpf._cmpsC 1g A!!!$AN"AGGQrfc.|j|tSr`)rr.rrs rd__cmp__z _mpf.__cmp__saffQ00rfc.|j|tSr`)rr/rs rd__lt__z _mpf.__lt__QVVAv..rfc.|j|tSr`)rr0rs rd__gt__z _mpf.__gt__rrfc.|j|tSr`)rr1rs rd__le__z _mpf.__le__rrfc.|j|tSr`)rr2rs rd__ge__z _mpf.__ge__rrfc>|j|}|tur|S| Sr`__eq__r)rrrs rd__ne__z _mpf.__ne__# HHQK  Hu rfc|j\}}\}}t|tvr0||}tt ||j |||_|S|j |}|tur|S||z Sr`)rrzrr&rrorrrrrbr{rqrsrs rd__rsub__z _mpf.__rsub__sq%&ZZ"S"4 7i CAhqk177D(CAGH  a   H1u rfc|j\}}\}}t|tr'||}t||j|||_|S|j |}|t ur|S||z Sr`)rrrr*rorrrs rd__rdiv__z _mpf.__rdiv__sk%&ZZ"S"4 a #CA"1aggtX>AGH  a   H1u rfcB|j|}|tur|S||zSr`rrrs rd__rpow__z _mpf.__rpow__(  a   HAv rfcB|j|}|tur|S||zSr`rrs rd__rmod__z _mpf.__rmod__(  a   H1u rfc8|jj|Sr`)rwsqrtrs rdrz _mpf.sqrtsyy~~a  rfNc>|jj||||Sr`rwalmosteqrrrel_epsabs_epss rdaez_mpf.aeyy!!!Q99rfc.t|j|Sr`)r7ro)rrqs rdr7z _mpf.to_fixeds D))rfc,tt|g|Sr`)roundr)rargss rd __round__z_mpf.__round__sU4[(4((rfNN)0rgrhrirjrkrre classmethodrrrpropertyman_exprrrrealimag conjugaterrrrrrrrrr__bool__rrrrrrrrrrrrrrrrr7rrlrfrdrnrn's  I!F=="   34G - .C - .C , -B % &D 2 3D!I:@E B-/1O0/H    1....    !:*)rfrna  def %NAME%(self, other): mpf, new, (prec, rounding) = self._ctxdata sval = self._mpf_ if hasattr(other, '_mpf_'): tval = other._mpf_ %WITH_MPF% ttype = type(other) if ttype in int_types: %WITH_INT% elif ttype is float: tval = from_float(other) %WITH_MPF% elif hasattr(other, '_mpc_'): tval = other._mpc_ mpc = type(other) %WITH_MPC% elif ttype is complex: tval = from_float(other.real), from_float(other.imag) mpc = self.context.mpc %WITH_MPC% if isinstance(other, mpnumeric): return NotImplemented try: other = mpf.context.convert(other, strings=False) except TypeError: return NotImplemented return self.%NAME%(other) z-; obj = new(mpf); obj._mpf_ = val; return objz-; obj = new(mpc); obj._mpc_ = val; return objzD try: val = mpf_pow(sval, tval, prec, rounding) z except ComplexResult: if mpf.context.trap_complex: raise mpc = mpf.context.mpc val = mpc_pow((sval, fzero), (tval, fzero), prec, rounding)  ct}|jd|}|jd|}|jd|}|jd|}i}t|t|||S)Nz %WITH_INT%z %WITH_MPC%z %WITH_MPF%z%NAME%) mpf_binary_opreplacerglobals)namewith_mpfwith_intwith_mpccodenps rd binary_oprsc D << h /D << h /D << h /D <<$ 'D B $ 2 d8Orfrzreturn mpf_eq(sval, tval)z$return mpf_eq(sval, from_int(other))z3return (tval[1] == fzero) and mpf_eq(tval[0], sval)__add__z)val = mpf_add(sval, tval, prec, rounding)z4val = mpf_add(sval, from_int(other), prec, rounding)z-val = mpc_add_mpf(tval, sval, prec, rounding)__sub__z)val = mpf_sub(sval, tval, prec, rounding)z4val = mpf_sub(sval, from_int(other), prec, rounding)z2val = mpc_sub((sval, fzero), tval, prec, rounding)__mul__z)val = mpf_mul(sval, tval, prec, rounding)z.val = mpf_mul_int(sval, other, prec, rounding)z-val = mpc_mul_mpf(tval, sval, prec, rounding)__div__z)val = mpf_div(sval, tval, prec, rounding)z4val = mpf_div(sval, from_int(other), prec, rounding)z-val = mpc_mpf_div(sval, tval, prec, rounding)__mod__z)val = mpf_mod(sval, tval, prec, rounding)z4val = mpf_mod(sval, from_int(other), prec, rounding)z+raise NotImplementedError("complex modulo")__pow__z.val = mpf_pow_int(sval, other, prec, rounding)z2val = mpc_pow((sval, fzero), tval, prec, rounding)c6eZdZdZddZddZedZdZy) _constantzRepresents a mathematical constant with dynamic precision. When printed or used in an arithmetic operation, a constant is converted to a regular mpf at the working precision. A regular mpf can also be obtained using the operation +x.cxtj|}||_||_t t |d|_|S)N)objectrerrgetattrr\rj)rbrrdocnamers rdrez_constant.__new__Ps3 NN3 M7B7 rfNc|jj\}}|s|}|s|}|r t|}|jj|j ||Sr`)rwrxr rr)rrqrrrsprec2 rounding2s rd__call__z_constant.__call__WsP<<66yETI {3'||$$TYYtX%>??rfcX|jj\}}|j||Sr`)rwrxr)rrqrss rdroz_constant._mpf_^s&44hyyx((rfchd|jd|jj|ddS)N)rrwnstrrs rdrz_constant.__repr__cs$"ii):):4B<)HIIrf)r&)NNN) rgrhrirjrer-r rorrlrfrdr$r$Js-@ @))Jrfr$ceZdZdZdgZd dZedZedZdZ dZ dZ d Z d Z d Zd Zd ZdZdZeZdZedZdZdZdZeZeZeZeZdZdZdZdZ dZ!eZ"dZ#dZ$dZ%dZ&e Z'e%Z(d!dZ)y)"_mpcz An mpc represents a complex number using a pair of mpf:s (one for the real part and another for the imaginary part.) The mpc class behaves fairly similarly to Python's complex type. _mpc_cftj|}t|tr|j|j }}nt |dr|j|_|S|jj|}|jj|}|j|jf|_|S)Nr5) r'rerrr rrr5rwmpfro)rbr rrs rdrez _mpc.__new__ps NN3  dM *DII$D T7 #jjAGH{{t${{t$::tzz*rfcR|jj|jdS)Nrurwrr5rs rdrz _mpc.|!6!6tzz!}!ErfcR|jj|jdSrr9rs rdrz _mpc.}r:rfcbt|jdt|jdfSNrur)rr5rs rdrz_mpc.__getstate__s'4::a=);tzz!}+EEErfcFt|dt|df|_yr=)rr5rs rdrz_mpc.__setstate__s "3q6*M#a&,AA rfc|jjr t|St|jdd}t|j dd}t |jd|d|dS)Nrvz(real=z, imag=))rwrrrr rrzrg)rris rdrz _mpc.__repr__sW 99  q6M L2  L2 )-a)9)91a@@rfc\dt|j|jjzS)Nz(%s))r8r5rwrrs rdrz _mpc.__str__s" 177AII,A,ABBBrfc^t|j|jjdSr)r9r5rwrxrs rdrz_mpc.__complex__s"agg199+C+CA+FGGrfct|j\}}\}}||}t|j|||_|Sr`)rr;r5rs rdrz _mpc.__pos__rrfc|jj\}}t|jj}t |j |||_|Sr`)rwrxr{r7r?r5ro)rrqrsrs rdrz _mpc.__abs__s@11h  !''42rfct|j\}}\}}||}t|j|||_|Sr`)rr=r5rs rdrz _mpc.__neg__rrfct|j\}}\}}||}t|j|||_|Sr`)rr>r5rs rdrz_mpc.conjugates9%&ZZ"S"4 Hx8rfc,t|jSr`)r<r5rs rdrz_mpc.__nonzero__sagg&&rfc,t|jSr`)r:r5rs rdrz _mpc.__hash__s  rfch |jj|}|S#t$r tcYSwxYwr`)rwrrr)rbrys rdmpc_convert_lhsz_mpc.mpc_convert_lhss5 " ##A&AH "! ! "s 11ct|ds,t|try|j|}|tur|S|j |j k(xr|j |j k(S)Nr5F)rrrrNrr rrs rdrz _mpc.__eq__s[q'"!S!!!!$AN"vv4AFFaff$44rfc>|j|}|tur|S| Sr`r)rrrs rdrz _mpc.__ne__rrfctd)Nz3no ordering relation is defined for complex numbers)r)rs rd_comparez _mpc._comparesMNNrfcR|j\}}\}}t|dsX|j|}|tur|St|dr1||}t |j |j |||_|S||}t|j |j |||_|SNr5ro)rrrNrrAr5ror@rs rdrz _mpc.__add__%&ZZ"S"4q'"!!!$AN"q'"H%aggqwwhG H!''177D(;rfcR|j\}}\}}t|dsX|j|}|tur|St|dr1||}t |j |j |||_|S||}t|j |j |||_|SrT)rrrNrrCr5rorBrs rdrz _mpc.__sub__rUrfc|j\}}\}}t|dst|tr'||}t |j ||||_|S|j |}|tur|St|dr1||}t|j |j|||_|S|j |}||}t|j |j |||_|SrT) rrrrrFr5rNrrErorDrs rdrz _mpc.__mul__s%&ZZ"S"4q'"!Y'H%aggq$A!!!$AN"q'"H%aggqwwhG!!!$A H!''177D(;rfcR|j\}}\}}t|dsX|j|}|tur|St|dr1||}t |j |j |||_|S||}t|j |j |||_|SrT)rrrNrrHr5rorGrs rdr z _mpc.__div__rUrfc|j\}}\}}t|tr'||}t|j||||_|S|j |}|t ur|S||}t|dr)t|j|j|||_|St|j|j|||_|Sr) rrrrKr5rNrrrJrorIrs rdr"z _mpc.__pow__s%&ZZ"S"4 a #CA!!''1dH=AGH  a   H H 1g !!''177D(CAGaggqwwh?AGrfcB|j|}|tur|S||z Sr`rNrrs rdrz _mpc.__rsub__ rrfc|j\}}\}}t|tr'||}t|j||||_|S|j |}|t ur|S||zSr`)rrrrFr5rNrrs rd__rmul__z _mpc.__rmul__&sk%&ZZ"S"4 a #CA!!''1dH=AGH  a   H1u rfcB|j|}|tur|S||z Sr`r[rs rdrz _mpc.__rdiv__1rrfcB|j|}|tur|S||zSr`r[rs rdrz _mpc.__rpow__7rrfNc>|jj||||Sr`rrs rdrz_mpc.ae@rrf)rurur )*rgrhrirjrkrer r rrrrrrrrrrrrrr rNrrrRrrrrrrr r"__radd__rr]rr __truediv__ __rtruediv__rrlrfrdr4r4gs  I  E FD E FDFBACH    'H!""5 OF F F F  &  H   KL:rfr4ceZdZdZdZdZdZdZdZe deZ e deZ dd Z d Z d Zd Zd ZddZddZddZddZedZdZdZdZy)PythonMPContextcdtg|_tdtfi|_tdt fi|_|jt|jg|j_|j t|jg|j _||j_ ||j _ tdtfi|_ |jt|jg|j_||j_ y)N5r7rr) r rxrzrnr7r4rr{rrwr$rctxs rd__init__zPythonMPContext.__init__Is -0utgr*utgr*GGS#*<*<=GGS#*<*<=J b9 !$#s/A/A B " rfc>t|j}||_|Sr`)r{r7rorirrs rdrzPythonMPContext.make_mpfU Lrfc>t|j}||_|Sr`)r{rr5rls rdmake_mpczPythonMPContext.make_mpcZrmrfcLdx|_|jd<d|_d|_y)Nrgrur1F)_precrx_dps trap_complexrhs rddefaultzPythonMPContext.default_s(,.. C&&q) rfcvtdt|x|_|jd<t ||_y)Nrru)maxrrqrxrrrrins rd _set_preczPythonMPContext._set_precds.,/3q6N: C&&q)q>rfcvt|x|_|jd<tdt ||_yr=)r rqrxrvrrrrws rd_set_dpszPythonMPContext._set_dpshs.,7N: C&&q)q#a&>rfc|jSr`)rqrhs rdrzPythonMPContext.ls  rfc|jSr`)rrrhs rdrzPythonMPContext.ms sxxrfc4t||jvr|St|tr|j t |St|t r|j t|St|tr9|jt|jt|jfSt|jdk(r|j|St|tjr>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> mpmathify(3.5) mpf('3.5') >>> mpmathify('2.1') mpf('2.1000000000000001') >>> mpmathify('3/4') mpf('0.75') >>> mpmathify('2+3j') mpc(real='2.0', imag='3.0') numpyror5rdecimal)"rztypesrrrrrrrror rrh npconvertnumbersRationalr[rr numerator denominatorrxrrrrr~rror5rrr_convert_fallback)rirstringsrqrsrrros rdrzPythonMPContext.convertos, 7cii  a #CLL!,E%E a  Z](C!C a !<<AFF!3Z5G HI I 7   (q1A*A a)) *\\#akk"2C 4FG++h a &77DAq<< aD 9: : z!Z0  D(3||E** 1g s||AGG'< < 1g s||AGG'< < 1j !;;qzz$9: : 7   * \!T8%DEE$$Q00% D   Ds*:>> from mpmath import * >>> isnan(3.14) False >>> isnan(nan) True >>> isnan(mpc(3.14,2.72)) False >>> isnan(mpc(3.14,nan)) True ror5Fzisnan() needs a number as input) rror!r5rrr[rrisnanr)rirs rdrzPythonMPContext.isnans" 1g 77d? " 1g 177? " a #z!X\\'B KKN 1g '!W"599Q< 9::rfct|dr|jttfvSt|dr-|j\}}|ttfvxs|ttfvSt |t st |tjry|j|}t|ds t|dr|j|Std)a Return *True* if the absolute value of *x* is infinite; otherwise return *False*:: >>> from mpmath import * >>> isinf(inf) True >>> isinf(-inf) True >>> isinf(3) False >>> isinf(3+4j) False >>> isinf(mpc(3,inf)) True >>> isinf(mpc(inf,3)) True ror5Fzisinf() needs a number as input) rrorr r5rrr[rrisinfr)rirreims rdrzPythonMPContext.isinfs( 1g 77tUm+ + 1g WWFB$&="u *= = a #z!X\\'B KKN 1g '!W"599Q< 9::rfct|drt|jdSt|drG|j\}}t|d}t|d}|tk(r|S|tk(r|S|xr|St |t st |tjr t|S|j|}t|ds t|dr|j|Std)a Determine whether *x* is "normal" in the sense of floating-point representation; that is, return *False* if *x* is zero, an infinity or NaN; otherwise return *True*. By extension, a complex number *x* is considered "normal" if its magnitude is normal:: >>> from mpmath import * >>> isnormal(3) True >>> isnormal(0) False >>> isnormal(inf); isnormal(-inf); isnormal(nan) False False False >>> isnormal(0+0j) False >>> isnormal(0+3j) True >>> isnormal(mpc(2,nan)) False rorr5z"isnormal() needs a number as input) rboolror5rrrr[rrisnormalr)rirrr re_normal im_normals rdrzPythonMPContext.isnormals0 1g  # # 1g WWFBRU IRU IU{9,U{9,* * a #z!X\\'B7N KKN 1g '!W"5<<? "<==rfcVt|tryt|dr0|jx\}}}}}t |xr|dk\xs |t k(St|drZ|j \}} |\} } } } | \}}}}| xr| dk\xs |t k(}|r|xr|dk\xs | t k(}|xr|S|xr | t k(St|tjr|j\}}||zdk(S|j|}t|ds t|dr|j||Std)a  Return *True* if *x* is integer-valued; otherwise return *False*:: >>> from mpmath import * >>> isint(3) True >>> isint(mpf(3)) True >>> isint(3.2) False >>> isint(inf) False Optionally, Gaussian integers can be checked for:: >>> isint(3+0j) True >>> isint(3+2j) False >>> isint(3+2j, gaussian=True) True Trorur5zisint() needs a number as input) rrrrorrr5r[rrrisintr)rirgaussianrrrrxvalrrrsignrmanrexprbcisignimaniexpibcre_isintim_isintrrs rdrzPythonMPContext.isints32 a # 1g () / D#sB);dem< < 1g WWFB%' "E4s%' "E4s*:rU{H .TQY>2;,H,+e + a &77DAqq5A:  KKN 1g '!W"599Q) )9::rfc|j\}}g}g}|D]o}dx} } t|dr |j} nht|dr|j\} } nL|j |}t|dr |j} n"t|dr|j\} } nt | r|rq|r7|j t| | |j t| | t| | fd|dz\} } |j | |j | |r|j t| | f||j | |j | C|r t| | } n |r t| } |j | rt||||} |r |j| t|||f} | S|j| } | S)aX Calculates a sum containing a finite number of terms (for infinite series, see :func:`~mpmath.nsum`). The terms will be converted to mpmath numbers. For len(terms) > 2, this function is generally faster and produces more accurate results than the builtin Python function :func:`sum`. >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> fsum([1, 2, 0.5, 7]) mpf('10.5') With squared=True each term is squared, and with absolute=True the absolute value of each term is used. ruror5rt )rxrror5rraappendr'rKr?r"r5ror) ritermsabsolutesquaredrqrr rtermrevalimvalrs rdfsumzPythonMPContext.fsum@s && c! #D EEtW% w'#zz u{{4(4) JJET7+#'::LE5-- GE%$89 GE%$89'2E%=47'K u E* E*KKu t <=KK&KK&#E51E#ENE E"C! #D D$X .  atS!9:;A QArfNc  | t||}|j\}}g}g}t}|j|jf} |D]\} } t | | vr|j | } t | | vr|j | } || d} || d} | r2| r0|jt| j| j|| d}|| d}| ra|r_| j}| j\}}|r t|}|jt|||jt||| rU|rS| j\}}| j}|jt|||jt||U|r|r| j\}}| j\}}|r t|}|jt|||jtt|||jt|||jt||tt|||}|r |j|t|||f}|S|j|}|S)a. Computes the dot product of the iterables `A` and `B`, .. math :: \sum_{k=0} A_k B_k. Alternatively, :func:`~mpmath.fdot` accepts a single iterable of pairs. In other words, ``fdot(A,B)`` and ``fdot(zip(A,B))`` are equivalent. The elements are automatically converted to mpmath numbers. With ``conjugate=True``, the elements in the second vector will be conjugated: .. math :: \sum_{k=0} A_k \overline{B_k} **Examples** >>> from mpmath import * >>> mp.dps = 15; mp.pretty = False >>> A = [2, 1.5, 3] >>> B = [1, -1, 2] >>> fdot(A, B) mpf('6.5') >>> list(zip(A, B)) [(2, 1), (1.5, -1), (3, 2)] >>> fdot(_) mpf('6.5') >>> A = [2, 1.5, 3j] >>> B = [1+j, 3, -1-j] >>> fdot(A, B) mpc(real='9.5', imag='-1.0') >>> fdot(A, B, conjugate=True) mpc(real='3.5', imag='-5.0') ror5)ziprxrr7rrzrrr'ror5r$rar5ror)riABrrqrr rhasattr_rrra_realb_real a_complex b_complexavalbrebimareaimbvalrs rdfdotzPythonMPContext.fdot|s7N =Aq A&& c#''"! *DAqAwe#QQAwe#QQa)Fa)F& GAGGQWW56 G,I G,I)ww77S!#,C GD#./ GD#./I77Sww GC./ GC./y77S77S!#,C GC-. GGC$567 GC-. GC-.))C! *D D$ $  atS!9:;A QArfcfd}jddtjjd|z|_|S)aO Given a low-level mpf_ function, and optionally similar functions for mpc_ and mpi_, defines the function as a context method. It is assumed that the return type is the same as that of the input; the exception is that propagation from mpf to mpc is possible by raising ComplexResult. c\t|jvrj|}j\}}|r6|j d|}d|vrt |d}|j d|}t |dr$ j|j||St |dr#j|j||Stdt|#t$r9jrj|jtf||cYSwxYw)Nrqrrrsror5z of a )rzrrrxryr rrrorrsrorr5ra)rrrqrsrimpc_fmpf_frs rdfz/PythonMPContext._wrap_libmp_function..fsAwcii'KKN //ND(zz&$/F?&ve}5D!::j(;q'"Q<<aggtX(FGG G$||E!''4$BCC%dDG&DE E%Q''<<qww.>h(OPP Qs>"C))?D+*D+rvNzComputes the %s of x)rgr\__dict__ryrj)rirrmpi_fdocrrs``` @rd_wrap_libmp_functionz$PythonMPContext._wrap_libmp_functions@ F(~~ab!!**..t5Kc5QR rfc|rfd}n}tjj|j|_t |||y)Nc|j}|Dcgc] }|| }}|j} |xjdz c_|g|i|}||_|Scc}w#||_wxYw)Nr)rrq)rirrrrrqretvalrs rd f_wrappedz0PythonMPContext._wrap_specfun..f_wrappedsp++,01q 11xx$HHNHs4T4V4F#CHw2 $CHsA!A A))r\rryrjsetattr)rbrrwraprs ` rd _wrap_specfunzPythonMPContext._wrap_specfuns=  I)2266tQYYG T9%rfctt|dr|j\}}|tk7r&|dfSt|dr|j}nt |t vr t |dfSd}t|tr|\}}nZt|dr|j\}}n>t|tr.d|vr*|jd\}}t |}t |}| |zs||zdfS|j||dfS|j|}t|dr|j\}}|tk7r!|dfSt|dr |j}n|dfS|\}}}} |r^|d k\rD|r| }|d k\rt ||zdfS|d k\r%t |d | z}}|j||dfS|j|}|d fS|sy |dfS)Nr5CroZr/QUrurR)rur)rr5rrorzrrrr|rrsplitrrr) rirrrrrrrrrs rd_convert_paramzPythonMPContext._convert_params 1g GGEArU{#v Q AAw)#1vs{"A!U#1G$ww1Az*saxwws|1FF}1u63;&wwq|S(( AAq'"2;c6MG$GG#v c3 by$C!8s8s?C//"9s8a3$iqA771Q<,, QAc6Mc6Mrfc|\}}}}|r||zS|tk(r |jS|tk(s |tk(r |jS|j Sr`)rninfrr infnan)rirrrrrs rd_mpf_magzPythonMPContext._mpf_mag9sKc3 r6M :88O 9U 77Nwwrfct|dr|j|jSt|drp|j\}}|tk(r|j|S|tk(r|j|Sdt |j||j|zSt |tr"|rtt|S|jSt |tjr@|j\}}|r#dtt|zt|z S|jS|j|}t|ds t|dr|j|St!d)a Quick logarithmic magnitude estimate of a number. Returns an integer or infinity `m` such that `|x| <= 2^m`. It is not guaranteed that `m` is an optimal bound, but it will never be too large by more than 2 (and probably not more than 1). **Examples** >>> from mpmath import * >>> mp.pretty = True >>> mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2))) (4, 4, 4, 4) >>> mag(10j), mag(10+10j) (4, 5) >>> mag(0.01), int(ceil(log(0.01,2))) (-6, -6) >>> mag(0), mag(inf), mag(-inf), mag(nan) (-inf, +inf, +inf, nan) ror5rzrequires an mpf/mpc)rrror5rrvrrr6absrr[rrrmagr)rirrBrCrrs rdrzPythonMPContext.magCs'* 1g <<( ( Q 77DAqEz||A&Ez||A&Sa#,,q/:: : 9 %A''88O 8<< (77DAq8CF++hqk9988O AAq'"ga&9wwqz! 566rf)T)F)FF)NF)NNz)rgrhrirjrrortryr{r rqrrrrrrrrrrrr rrrrrlrfrdrereGs #  ! "" )9 5D ' 2C01d =;8;@&>P-;^:xUn F&&"/b,7rfreruN)r&r&r&)} libmp.backendrrlibmprrrrr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr&r[r\r'rer{r^rnr return_mpf return_mpc mpf_pow_samerrrrrr r!r"rar]rbrrcr$r4rrrerComplexregisterReal ImportErrorrlrfrdrsx-. nn"" C)9C)J <= < : *9; /*<:ZG3j@B /*<:ZG8:EG /*<4zA3j@B /*<:ZG3j@B /*<:ZG13 4zA8:EG     <<MMJJ:Z:9Z:z$ h7fh7b  OOT" LL$  s:II I