+
    i                     &   ^RI HtHt ^RIHtHtHtHtHtH	t	H
t
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t=H>t>H?t?H@t@HAtAHBtBHCtCHDtDHEtEHFtFHGtGHHtHHItIHJtJHKtKHLtLHMtMHNtNHOtOHPtPHQtQHRtRHStSHTtTHUtUHVtVHWtWHXtXHYtYHt ^RIZH[t[ ^RIZH\t\ ]]P                  t_ ! R R]]4      t` ! R R]`4      taR	tbR
tcRtdR]c: R]d: R2teR2R ltf]f! RRRR4      ]ang        ]f! RR]c,           R]c,           R]d,           4      ]anh        ]f! RR]c,           R]c,           R]d,           4      ]ani        ]f! RR]c,           R]c,           R]d,           4      ]anj        ]f! R R!]c,           R"]c,           R#]d,           4      ]ank        ]f! R$R%]c,           R&]c,           R'4      ]anl        ]f! R(]eR)]c,           R*]d,           4      ]anm        ]aP                  ]ann        ]aP                  ]ano        ]aP                  ]anp        ]aP                  ]anr         ! R+ R,]a4      ts ! R- R.]`4      tt]u]t3tv ! R/ R0]]4      tw ^ R1Ixtx]xP                  P                  ]t4       ]xP                  P                  ]a4       R1#   ]| d     R1# i ; i)3   )
basestringexec_)WMPZMPZ_ZEROMPZ_ONE	int_typesrepr_dpsround_floorround_ceilingdps_to_precround_nearestprec_to_dpsComplexResultto_pickablefrom_pickable	normalizefrom_int
from_floatfrom_npfloatfrom_Decimalfrom_strto_intto_floatto_strfrom_rationalfrom_man_expfonefzerofinffninffnanmpf_absmpf_posmpf_negmpf_addmpf_submpf_mulmpf_mul_intmpf_divmpf_rdiv_intmpf_pow_intmpf_modmpf_eqmpf_cmpmpf_ltmpf_gtmpf_lempf_gempf_hashmpf_randmpf_sumbitcountto_fixed
mpc_to_strmpc_to_complexmpc_hashmpc_posmpc_is_nonzerompc_negmpc_conjugatempc_absmpc_addmpc_add_mpfmpc_submpc_sub_mpfmpc_mulmpc_mul_mpfmpc_mul_intmpc_divmpc_div_mpfmpc_powmpc_pow_mpfmpc_pow_intmpc_mpf_divmpf_powmpf_pi
mpf_degreempf_empf_phimpf_ln2mpf_ln10	mpf_eulermpf_catalan	mpf_aperympf_khinchinmpf_glaishermpf_twinprimempf_mertensr   )rational)function_docsc                   .   a  ] tR t^!t o Rt. tR tRtV tR# )	mpnumericzBase class for mpf and mpc.c                    \         hN)NotImplementedError)clsvals   &&t/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/mpmath/ctx_mp_python.py__new__mpnumeric.__new__$   s    !!     N)	__name__
__module____qualname____firstlineno____doc__	__slots__re   __static_attributes____classdictcell____classdict__s   @rd   r^   r^   !   s     %I" "rg   r^   c                     a  ] tR t^'t o RtR.t]3R lt]R 4       t	]R 4       t
]R 4       t]! R 4      t]! R 4      t]! R	 4      t]! R
 4      t]! R 4      t]! R 4      tR tR tR tR tR tR tR tR tR tR tR t]tR tR t R t!R t"R t#R t$R t%R t&R  t'R! t(R" t)R# t*R$ t+R% t,R& t-R,R( lt.R) t/R* t0R+t1V t2R'# )-_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                   V P                   P                  w  r4V'       d>   VP                  RV4      pRV9   d   \        VR,          4      pVP                  RV4      p\	        V4      V J dA   VP
                  w  rVrxV'       g   V'       d   V# \        V 4      p	\        WVWxW44      V	n        V	# \	        V4      \        J d   \        V4      ^8X  d.   \        V 4      p	\        V^ ,          V^,          W44      V	n        V	# \        V4      ^8X  dF   V\        \        \        39  d   Vw  rVrx\        V\        V4      WxW44      p\        V 4      p	Wn        V	# \        h\        V 4      p	\!        V P#                  WV4      W44      V	n        V	# )z{A new mpf can be created from a Python float, an int, a
or a decimal string representing a number in floating-point
format.precdpsrounding)context_prec_roundinggetr   typeru   newr   tuplelenr   r   r    r!   r   
ValueErrorr#   mpf_convert_arg)
rb   rc   kwargsrw   ry   signmanexpbcvs
   &&,       rd   re   _mpf.__new__/   sF    33::fd+D"6%=1zz*h7H9!$DsS
CA3DCAGH#Y%3x1}H&s1vs1vtF3x1}tUD11),&Ds#D#c(CTLCHCAc11#XFWAGHrg   c                   \        V\        4      '       d   \        V4      # \        V\        4      '       d   \	        V4      # \        V\
        4      '       d   \        WV4      # \        WP                  P                  4      '       d   VP                  W#4      # \        VR 4      '       d   VP                  # \        VR4      '       dI   V P                  P                  VP                  W#4      4      p\        VR 4      '       d   VP                  # \        VR4      '       d"   VP                  w  rVWV8X  d   V# \        R4      h\!        R\#        V4      ,           4      h)ru   _mpmath__mpi_z,can only create mpf from zero-width intervalcannot create mpf from )
isinstancer   r   floatr   r   r   rz   constantfunchasattrru   convertr   r   r   	TypeErrorrepr)rb   xrw   ry   tabs   &&&&   rd   r   _mpf.mpf_convert_argR   s   a##HQK%7a
1!5a$$Xax-H&Ha--..qvvd7M0M1gqww1j!!##AJJt$>?Aq'""ww1g77DAvKLL1DG;<<rg   c                   \        V\        4      '       d   \        V4      # \        V\        4      '       d   \	        V4      # \        V\
        4      '       d   V P                  P                  V4      # \        V\        P                  4      '       d/   VP                  w  r#\        W#V P                  P                  4      # \        VR 4      '       d   VP                  # \        VR4      '       d^   V P                  P                  VP                   ! V P                  P"                  !  4      p\        VR 4      '       d   VP                  # V# \$        # )ru   r   )r   r   r   r   r   complex_typesrz   mpcr[   mpq_mpq_r   rw   r   ru   r   r   r{   NotImplemented)rb   r   pqr   s   &&   rd   mpf_convert_rhs_mpf.mpf_convert_rhsd   s    a##HQK%7a
1!5a''0B)Ba&&77DA s{{'7'7881gqww1j!!##AJJ0J0J$KLAq'""wwHrg   c                    V P                  V4      p\        V4      \        J d   V P                  P	                  V4      # V# r`   )r   r}   r   rz   make_mpf)rb   r   s   &&rd   mpf_convert_lhs_mpf.mpf_convert_lhst   s8    "7e;;''**rg   c                (    V P                   R ,          # ):r      Nru   selfs   &rd   <lambda>_mpf.<lambda>{   s    DJJsOrg   c                (    V P                   ^,          # r   r   r   s   &rd   r   r   |       

1rg   c                (    V P                   ^,          # )   r   r   s   &rd   r   r   }   r   rg   c                (    V P                   ^,          # )r   r   r   s   &rd   r   r   ~   s    tzz!}rg   c                    V # r`   rh   r   s   &rd   r   r      s    rg   c                .    V P                   P                  # r`   )rz   zeror   s   &rd   r   r      s    !2!2rg   c                    V # r`   rh   r   s   &rd   r   r      s    Trg   c                ,    \        V P                  4      # r`   )r   ru   r   s   &rd   __getstate___mpf.__getstate__   s    ;tzz#::rg   c                &    \        V4      V n        R # r`   )r   ru   r   rc   s   &&rd   __setstate___mpf.__setstate__   s    mC.@rg   c                    V P                   P                  '       d   \        V 4      # R \        V P                  V P                   P
                  4      ,          # )z	mpf('%s'))rz   prettystrr   ru   _repr_digitsss   &rd   __repr___mpf.__repr__   s;    99q6MVAGGQYY-C-CDDDrg   c                V    \        V P                  V P                  P                  4      # r`   )r   ru   rz   _str_digitsr   s   &rd   __str___mpf.__str__   s    6!''199+@+@AArg   c                ,    \        V P                  4      # r`   )r3   ru   r   s   &rd   __hash___mpf.__hash__   s    HQWW--rg   c                >    \        \        V P                  4      4      # r`   )intr   ru   r   s   &rd   __int___mpf.__int__   s    3vagg//rg   c                >    \        \        V P                  4      4      # r`   )longr   ru   r   s   &rd   __long___mpf.__long__   s    D11rg   c                f    \        V P                  V P                  P                  ^,          R7      # r   )rnd)r   ru   rz   r{   r   s   &rd   	__float___mpf.__float__   s!    Xagg1993K3KA3NOOrg   c                *    \        \        V 4      4      # r`   )complexr   r   s   &rd   __complex___mpf.__complex__   s    wuQx00rg   c                (    V P                   \        8g  # r`   )ru   r   r   s   &rd   __nonzero___mpf.__nonzero__   s    qww%//rg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )_ctxdatar"   ru   r   rb   r~   rw   ry   r   s   &     rd   __abs___mpf.__abs__   3    %&ZZ""4H!''42rg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )r   r#   ru   r   s   &     rd   __pos___mpf.__pos__   r   rg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )r   r$   ru   r   s   &     rd   __neg___mpf.__neg__   r   rg   c                    \        VR 4      '       d   VP                  pMV P                  V4      pV\        J d   V# V! V P                  V4      # r   )r   ru   r   r   )r   r   r   s   &&&rd   _cmp	_mpf._cmp   sF    1gA!!!$AN"AGGQrg   c                .    V P                  V\        4      # r`   )r   r.   r   r   s   &&rd   __cmp___mpf.__cmp__   s    affQ00rg   c                .    V P                  V\        4      # r`   )r   r/   r   s   &&rd   __lt___mpf.__lt__       QVVAv..rg   c                .    V P                  V\        4      # r`   )r   r0   r   s   &&rd   __gt___mpf.__gt__   r   rg   c                .    V P                  V\        4      # r`   )r   r1   r   s   &&rd   __le___mpf.__le__   r   rg   c                .    V P                  V\        4      # r`   )r   r2   r   s   &&rd   __ge___mpf.__ge__   r   rg   c                J    V P                  V4      pV\        J d   V# V'       * # r`   __eq__r   )r   r   r   s   && rd   __ne___mpf.__ne__   #    HHQKHurg   c                    V P                   w  r#w  rE\        V4      \        9   d0   V! V4      p\        \	        V4      V P
                  WE4      Vn        V# V P                  V4      pV\        J d   V# W,
          # r`   )r   r}   r   r&   r   ru   r   r   r   r   rb   r~   rw   ry   r   s   &&     rd   __rsub___mpf.__rsub__   si    %&ZZ""47iCAhqk177DCAGHa Hurg   c                    V P                   w  r#w  rE\        V\        4      '       d&   V! V4      p\        WP                  WE4      Vn        V# V P                  V4      pV\        J d   V# W,          # r`   )r   r   r   r*   ru   r   r   r  s   &&     rd   __rdiv___mpf.__rdiv__   sd    %&ZZ""4a##CA"1ggt>AGHa Hurg   c                L    V P                  V4      pV\        J d   V# W,          # r`   r   r   r   s   &&rd   __rpow___mpf.__rpow__   &    a Hvrg   c                L    V P                  V4      pV\        J d   V# W,          # r`   r  r   s   &&rd   __rmod___mpf.__rmod__   &    a Hurg   c                8    V P                   P                  V 4      # r`   )rz   sqrtr   s   &rd   r  	_mpf.sqrt   s    yy~~a  rg   Nc                :    V P                   P                  WW#4      # r`   rz   almosteqr   r   rel_epsabs_epss   &&&&rd   ae_mpf.ae       yy!!!99rg   c                .    \        V P                  V4      # r`   )r7   ru   )r   rw   s   &&rd   r7   _mpf.to_fixed   s    

D))rg   c                .    \        \        V 4      .VO5!  # r`   )roundr   )r   argss   &*rd   	__round___mpf.__round__   s    U4[(4((rg   r   NN)3ri   rj   rk   rl   rm   rn   r   re   classmethodr   r   r   propertyman_expr   r   r   realimag	conjugater   r   r   r   r   r   r   r   r   r   __bool__r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r#  r7   r+  ro   rp   rq   s   @rd   rt   rt   '   s!    
 	I !F = ="     34G
-
.C
-
.C	,	-B%&D23D!I:@E
 B-/1O0/H  1....		!:*) )rg   rt   a  
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) 
c                     \         pVP                  R V4      pVP                  RV4      pVP                  RV4      pVP                  RV 4      p/ p\        V\        4       V4       WP,          # )z
%WITH_INT%z
%WITH_MPC%z
%WITH_MPF%z%NAME%)mpf_binary_opreplacer   globals)namewith_mpfwith_intwith_mpccodenps   &&&&  rd   	binary_opr@    sa    D<<h/D<<h/D<<h/D<<$'D	B	$	28Org   r  zreturn 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)c                   N   a  ] tR tRt o RtR	R ltR
R lt]R 4       tR t	Rt
V tR# )	_constantiJ  zRepresents 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.c                t    \         P                  V 4      pW$n        Wn        \	        \
        VR 4      Vn        V#  )objectre   r:  r   getattrr\   rm   )rb   r   r:  docnamer   s   &&&& rd   re   _constant.__new__P  s/    NN3M7B7	rg   Nc                    V P                   P                  w  rEV'       g   TpV'       g   TpV'       d   \        V4      pV P                   P                  V P	                  W4      4      # r`   )rz   r{   r   r   r   )r   rw   rx   ry   prec2	rounding2s   &&&&  rd   __call___constant.__call__W  sL    <<66ETI{3'||$$TYYt%>??rg   c                T    V P                   P                  w  rV P                  W4      # r`   )rz   r{   r   )r   rw   ry   s   &  rd   ru   _constant._mpf_^  s"    44yy((rg   c           	     l    R V P                   : RV P                  P                  V ! ^R7      4      : R2# )<z: )rx   z~>)r:  rz   nstrr   s   &rd   r   _constant.__repr__c  s$    "ii):):4B<)HIIrg   rh   rJ  )NNN)ri   rj   rk   rl   rm   re   rS  r/  ru   r   ro   rp   rq   s   @rd   rH  rH  J  s6     @
@ ) )J Jrg   rH  c                     a  ] tR tRt o RtR.tR"R lt]! R 4      t]! R 4      t	R t
R tR	 tR
 tR tR tR tR tR tR t]tR t]R 4       tR tR tR t]t]t]t]tR tR tR t R t!R t"]t#R t$R t%R t&R t']!t(]&t)R#R  lt*R!t+V t,R# )$_mpcig  z
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_c                |   \         P                  V 4      p\        V\        4      '       d   VP                  VP
                  r!M%\        VR 4      '       d   VP                  Vn        V# V P                  P                  V4      pV P                  P                  V4      pVP                  VP                  3Vn        V# r]  )rL  re   r   r   r1  r2  r   r]  rz   mpfru   )rb   r1  r2  r   s   &&& rd   re   _mpc.__new__p  s    NN3dM**DII$T7##jjAGH{{t${{t$::tzz*rg   c                Z    V P                   P                  V P                  ^ ,          4      #     rz   r   r]  r   s   &rd   r   _mpc.<lambda>|      !6!6tzz!}!Erg   c                Z    V P                   P                  V P                  ^,          4      # r   re  r   s   &rd   r   rf  }  rg  rg   c                r    \        V P                  ^ ,          4      \        V P                  ^,          4      3# rc  )r   r]  r   s   &rd   r   _mpc.__getstate__  s'    4::a=);tzz!}+EEErg   c                X    \        V^ ,          4      \        V^,          4      3V n        R# rd  N)r   r]  r   s   &&rd   r   _mpc.__setstate__  s     "3q6*M#a&,AA
rg   c                    V P                   P                  '       d   \        V 4      # \        V P                  4      ^R p\        V P
                  4      ^R p\        V 4      P                  : RV: RV: R2# )   z(real=z, imag=))rz   r   r   r   r1  r2  r}   ri   )r   ris   &  rd   r   _mpc.__repr__  sZ    99q6ML2L2)-a)9)91a@@rg   c                d    R \        V P                  V P                  P                  4      ,          # )z(%s))r8   r]  rz   r   r   s   &rd   r   _mpc.__str__  s"    
177AII,A,ABBBrg   c                f    \        V P                  V P                  P                  ^,          R7      # r   )r9   r]  rz   r{   r   s   &rd   r   _mpc.__complex__  s"    agg199+C+CA+FGGrg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )r   r;   r]  r   s   &     rd   r   _mpc.__pos__  r   rg   c                    V P                   P                  w  r\        V P                   P                  4      p\	        V P
                  W4      Vn        V# r`   )rz   r{   r~   r`  r?   r]  ru   )r   rw   ry   r   s   &   rd   r   _mpc.__abs__  s<    11		!''42rg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )r   r=   r]  r   s   &     rd   r   _mpc.__neg__  r   rg   c                n    V P                   w  rw  r4V! V4      p\        V P                  W44      Vn        V# r`   )r   r>   r]  r   s   &     rd   r3  _mpc.conjugate  s3    %&ZZ""4H8rg   c                ,    \        V P                  4      # r`   )r<   r]  r   s   &rd   r   _mpc.__nonzero__  s    agg&&rg   c                ,    \        V P                  4      # r`   )r:   r]  r   s   &rd   r   _mpc.__hash__  s      rg   c                l     V P                   P                  V4      pV#   \         d
    \        u # i ; ir`   )rz   r   r   r   )rb   r   ys   && rd   mpc_convert_lhs_mpc.mpc_convert_lhs  s5    	"##A&AH 	"!!	"s    33c                   \        VR 4      '       g6   \        V\        4      '       d   R# V P                  V4      pV\        J d   V# V P
                  VP
                  8H  ;'       d    V P                  VP                  8H  # )r]  F)r   r   r   r  r   r1  r2  r   s   &&rd   r  _mpc.__eq__  sd    q'""!S!!!!!$AN"vv44AFFaff$44rg   c                J    V P                  V4      pV\        J d   V# V'       * # r`   r  )r   r   r   s   && rd   r  _mpc.__ne__  r	  rg   c                     \        R 4      h)z3no ordering relation is defined for complex numbers)r   )r*  s   *rd   _compare_mpc._compare  s    MNNrg   c                f   V P                   w  r#w  rE\        VR 4      '       g`   V P                  V4      pV\        J d   V# \        VR4      '       d1   V! V4      p\	        V P
                  VP                  WE4      Vn        V# V! V4      p\        V P
                  VP
                  WE4      Vn        V# r]  ru   )r   r   r  r   rA   r]  ru   r@   r  s   &&     rd   rA  _mpc.__add__      %&ZZ""4q'""!!!$AN"q'""H%aggqwwGH!''177D;rg   c                f   V P                   w  r#w  rE\        VR 4      '       g`   V P                  V4      pV\        J d   V# \        VR4      '       d1   V! V4      p\	        V P
                  VP                  WE4      Vn        V# V! V4      p\        V P
                  VP
                  WE4      Vn        V# r  )r   r   r  r   rC   r]  ru   rB   r  s   &&     rd   rB  _mpc.__sub__  r  rg   c                    V P                   w  r#w  rE\        VR 4      '       g   \        V\        4      '       d'   V! V4      p\	        V P
                  WV4      Vn        V# V P                  V4      pV\        J d   V# \        VR4      '       d1   V! V4      p\        V P
                  VP                  WE4      Vn        V# V P                  V4      pV! V4      p\        V P
                  VP
                  WE4      Vn        V# r  )r   r   r   r   rF   r]  r  r   rE   ru   rD   r  s   &&     rd   rC  _mpc.__mul__  s    %&ZZ""4q'""!Y''H%aggqA!!!$AN"q'""H%aggqwwG!!!$AH!''177D;rg   c                f   V P                   w  r#w  rE\        VR 4      '       g`   V P                  V4      pV\        J d   V# \        VR4      '       d1   V! V4      p\	        V P
                  VP                  WE4      Vn        V# V! V4      p\        V P
                  VP
                  WE4      Vn        V# r  )r   r   r  r   rH   r]  ru   rG   r  s   &&     rd   rD  _mpc.__div__   r  rg   c                   V P                   w  r#w  rE\        V\        4      '       d'   V! V4      p\        V P                  WV4      Vn        V# V P                  V4      pV\        J d   V# V! V4      p\        VR 4      '       d)   \        V P                  VP                  WE4      Vn        V# \        V P                  VP                  WE4      Vn        V# r   )r   r   r   rK   r]  r  r   r   rJ   ru   rI   r  s   &&     rd   rF  _mpc.__pow__  s    %&ZZ""4a##CA!!''1H=AGHa HH1g!!''177DCAG  aggqww?AGrg   c                L    V P                  V4      pV\        J d   V# W,
          # r`   r  r   r   s   &&rd   r  _mpc.__rsub__   r  rg   c                    V P                   w  r#w  rE\        V\        4      '       d'   V! V4      p\        V P                  WV4      Vn        V# V P                  V4      pV\        J d   V# W,          # r`   )r   r   r   rF   r]  r  r   r  s   &&     rd   __rmul___mpc.__rmul__&  sf    %&ZZ""4a##CA!!''1H=AGHa Hurg   c                L    V P                  V4      pV\        J d   V# W,          # r`   r  r   s   &&rd   r  _mpc.__rdiv__1  r  rg   c                L    V P                  V4      pV\        J d   V# W,          # r`   r  r   s   &&rd   r  _mpc.__rpow__7  r  rg   Nc                :    V P                   P                  WW#4      # r`   r  r   s   &&&&rd   r#  _mpc.ae@  r%  rg   r_  )rd  rd  r-  )-ri   rj   rk   rl   rm   rn   re   r/  r1  r2  r   r   r   r   r   r   r   r   r3  r   r4  r   r.  r  r  r  r  r   r   r  rA  rB  rC  rD  rF  __radd__r  r  r  r  __truediv____rtruediv__r#  ro   rp   rq   s   @rd   r\  r\  g  s      	I
 EFDEFDFBACH' H! " "5O FFFF&  H	 KL: :rg   r\  c                      a  ] tR tRt o R tR tR tR tR tR t	]
! R ]4      t]
! R	 ]	4      tRR
 ltR tR tR tR tRR ltRR ltRR ltRR lt]R 4       tR tR tR tRtV tR# )PythonMPContextiG  c                   ^5\         .V n        \        R\        3/ 4      V n        \        R\
        3/ 4      V n        V P                  \        V P                  .V P                  n        V P                  \        V P                  .V P                  n        W P                  n	        W P                  n	        \        R\        3/ 4      V n        V P                  \        V P                  .V P                  n        W P                  n	        R# )5   r`  r   r   N)r   r{   r}   rt   r`  r\  r   r~   r   rz   rH  r   ctxs   &rd   __init__PythonMPContext.__init__I  s     -0utgr*utgr*GGS#*<*<=GGS#*<*<=Jb9!$#s/A/A B"rg   c                <    \        V P                  4      pWn        V# r`   )r~   r`  ru   r  r   r   s   && rd   r   PythonMPContext.make_mpfU      Lrg   c                <    \        V P                  4      pWn        V# r`   )r~   r   r]  r  s   && rd   make_mpcPythonMPContext.make_mpcZ  r  rg   c                N    ^5;V n         V P                  ^ &   ^V n        RV n        R# )r  FN)_precr{   _dpstrap_complexr  s   &rd   defaultPythonMPContext.default_  s(    ,..	C&&q) rg   c                x    \        ^\        V4      4      ;V n        V P                  ^ &   \	        V4      V n        R# )r   N)maxr   r  r{   r   r  r  ns   &&rd   	_set_precPythonMPContext._set_precd  s.    ,/3q6N:	C&&q)q>rg   c                x    \        V4      ;V n        V P                  ^ &   \        ^\	        V4      4      V n        R# rl  )r   r  r{   r  r   r  r  s   &&rd   _set_dpsPythonMPContext._set_dpsh  s.    ,7N:	C&&q)q#a&>rg   c                    V P                   # r`   )r  r  s   &rd   r   PythonMPContext.<lambda>l  s    		rg   c                    V P                   # r`   )r  r  s   &rd   r   r  m  s    sxxrg   c                   \        V4      V P                  9   d   V# \        V\        4      '       d   V P	                  \        V4      4      # \        V\        4      '       d   V P	                  \        V4      4      # \        V\        4      '       d:   V P                  \        VP                  4      \        VP                  4      34      # \        V4      P                  R8X  d   V P                  V4      # \        V\        P                  4      '       d>   \         P"                  ! \%        VP&                  4      \%        VP(                  4      4      pV P*                  w  r4\        V\         P"                  4      '       d*   VP,                  w  rVV P	                  \/        WVV4      4      # V'       d5   \        V\0        4      '       d    \3        WV4      pV P	                  V4      # \7        VR4      '       d   V P	                  VP8                  4      # \7        VR4      '       d   V P                  VP:                  4      # \7        VR4      '       d!   V P=                  VP?                  W44      4      # \        V4      P                  R8X  d   V P	                  \A        WV4      4      # V PC                  W4      #     ELj; i  \4         d     Li ; i    L.; i)a3  
Converts *x* to an ``mpf`` or ``mpc``. If *x* is of type ``mpf``,
``mpc``, ``int``, ``float``, ``complex``, the conversion
will be performed losslessly.

If *x* is a string, the result will be rounded to the present
working precision. Strings representing fractions or complex
numbers are permitted.

    >>> 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')

numpyru   r]  r   decimal)"r}   typesr   r   r   r   r   r   r   r  r1  r2  rj   	npconvertnumbersRationalr[   r   r   	numeratordenominatorr{   r   r   r   r   r   r   ru   r]  r   r   r   _convert_fallback)r  r   stringsrw   ry   r   r   ru   s   &&&     rd   r   PythonMPContext.converto  s   , 7ciia##CLL!,E%EaZ](C!Ca!!<<AFF!3Z5G HII7(q1A*Aa))**\\#akk"2C4FG++a&&77DA<<aD 9::z!Z00 (3||E** 1gs||AGG'< <1gs||AGG'< <1j!!;;qzz$9::7*\!8%DEE$$Q00% D   Ds*   =J9 
K K 9J>KKKc                   ^ RI p\        WP                  4      '       d$   V P                  \	        \        V4      4      4      # \        WP                  4      '       d   V P                  \        V4      4      # \        WP                  4      '       d:   V P                  \        VP                  4      \        VP                  4      34      # \        R\        V4      ,           4      h)zF
Converts *x* to an ``mpf`` or ``mpc``. *x* should be a numpy
scalar.
Nr   )r  r   integerr   r   r   floatingr   complexfloatingr  r1  r2  r   r   )r  r   r?  s   && rd   r  PythonMPContext.npconvert  s    
 	a$$S\\(3q6:J-K&Ka%%cll<?.K'Ka++,,<<aff!5|AFF7K LMM1DG;<<rg   c                   \        VR4      '       d   VP                  \        8H  # \        VR4      '       d   \        VP                  9   # \	        V\
        4      '       g!   \	        V\        P                  4      '       d   R# V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  V4      # \        R4      h)a:  
Return *True* if *x* is a NaN (not-a-number), or for a complex
number, whether either the real or complex part is NaN;
otherwise return *False*::

    >>> from mpmath import *
    >>> isnan(3.14)
    False
    >>> isnan(nan)
    True
    >>> isnan(mpc(3.14,2.72))
    False
    >>> isnan(mpc(3.14,nan))
    True

ru   r]  Fzisnan() needs a number as input)r   ru   r!   r]  r   r   r[   r   r   isnanr   )r  r   s   &&rd   r  PythonMPContext.isnan  s    " 1g77d?"1g177?"a##z!X\\'B'BKKN1g'!W"5"599Q<9::rg   c                   \        VR4      '       d   VP                  \        \        39   # \        VR4      '       d5   VP                  w  r#V\        \        39   ;'       g    V\        \        39   # \        V\        4      '       g!   \        V\        P                  4      '       d   R# V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  V4      # \        R4      h)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

ru   r]  Fzisinf() needs a number as input)r   ru   r   r    r]  r   r   r[   r   r   isinfr   )r  r   reims   &&  rd   r  PythonMPContext.isinf  s    ( 1g77tUm++1gWWFB$&=="u*==a##z!X\\'B'BKKN1g'!W"5"599Q<9::rg   c                V   \        VR4      '       d   \        VP                  ^,          4      # \        VR4      '       dY   VP                  w  r#\        V^,          4      p\        V^,          4      pV\        8X  d   V# V\        8X  d   V# T;'       d    T# \        V\        4      '       g!   \        V\        P                  4      '       d   \        V4      # V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  V4      # \        R4      h)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
ru   r]  z"isnormal() needs a number as input)r   boolru   r]  r   r   r   r[   r   r   isnormalr   )r  r   r  r  	re_normal	im_normals   &&    rd   r  PythonMPContext.isnormal  s    0 1g
##1gWWFBRUIRUIU{9,U{9,***a##z!X\\'B'B7NKKN1g'!W"5"5<<?"<==rg   c                   \        V\        4      '       d   R# \        VR4      '       d;   VP                  ;w  r4rVp\	        T;'       d    V^ 8  ;'       g
    V\
        8H  4      # \        VR4      '       d   VP                  w  rVw  rrV	w  rppT;'       d    V^ 8  ;'       g
    V\
        8H  pV'       d-   T;'       d    V^ 8  ;'       g
    V	\
        8H  pT;'       d    T# T;'       d
    V	\
        8H  # \        V\        P                  4      '       d   VP                  w  ppVV,          ^ 8H  # V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  W4      # \        R4      h)ar  
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

Tru   r]  zisint() needs a number as input)r   r   r   ru   r  r   r]  r[   r   r   r   isintr   )r  r   gaussianr   r   r   r   xvalr  r  rsignrmanrexprbcisignimaniexpibcre_isintim_isintr   r   s   &&&                   rd   r  PythonMPContext.isint  sO   2 a##1g()/Ds));;dem<<1gWWFB%'"E%'"Es**::rU{H ..TQY>>2;,,H,++e+a&&77DAqq5A:KKN1g'!W"5"599Q))9::rg   c                   V P                   w  rE. p. pV EF  p^ ;r\        VR4      '       d   VP                  p	Mx\        VR4      '       d   VP                  w  rMWV P	                  V4      p\        VR4      '       d   VP                  p	M'\        VR4      '       d   VP                  w  rM\
        hV
'       d   V'       d{   V'       d7   VP                  \        W4      4       VP                  \        W4      4       K  \        W3^V^
,           4      w  rVP                  V	4       VP                  V
4       EK(  V'       d    VP                  \        W3V4      4       EKO  VP                  V	4       VP                  V
4       EKt  V'       d   \        W4      p	MV'       d   \        V	4      p	VP                  V	4       EK  	  \        WdWR4      pV'       d    V P                  V\        WtV4      34      pV# V P                  V4      pV# )a  
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.
ru   r]  )r{   r   ru   r]  r   ra   appendr'   rK   r?   r"   r5   r  r   )r  termsabsolutesquaredrw   r   r1  r2  termrevalimvalr   s   &&&&        rd   fsumPythonMPContext.fsum@  s     &&	DEtW%%

w''#zzu{{4(4)) JJET7++#'::LE5--GE$89GE$89'2E=47'KE*E*KKt <=KK&KK&#E1E#ENEE"C D D.aS!9:;A  QArg   Nc           	        Ve   \        W4      pV P                  w  rE. p. p\        pV P                  V P                  3p	V EFD  w  r\        V
4      V	9  d   V P                  V
4      p
\        V4      V	9  d   V P                  V4      pV! V
R4      pV! VR4      pV'       d:   V'       d2   VP                  \        V
P                  VP                  4      4       K  V! V
R4      pV! VR4      pV'       dp   V'       dh   V
P                  pVP                  w  ppV'       d   \        V4      pVP                  \        VV4      4       VP                  \        VV4      4       EK$  V'       d]   V'       dU   V
P                  w  ppVP                  pVP                  \        VV4      4       VP                  \        VV4      4       EK  V'       d   V'       d   V
P                  w  ppVP                  w  ppV'       d   \        V4      pVP                  \        VV4      4       VP                  \        \        VV4      4      4       VP                  \        VV4      4       VP                  \        VV4      4       EKA  \        h	  \        WdV4      pV'       d    V P                  V\        WtV4      34      pV# V P                  V4      pV# )aN  
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')

ru   r]  )zipr{   r   r`  r   r}   r   r  r'   ru   r]  r$   ra   r5   r  r   )r  ABr3  rw   r   r1  r2  hasattr_r  r   r   a_realb_real	a_complex	b_complexavalbrebimareaimbvalr   s   &&&&                   rd   fdotPythonMPContext.fdot|  s(   N =A	A&&	#''"DAAwe#QQAwe#QQa)Fa)F&GAGGQWW56 G,I G,I)ww77S!#,CGD#./GD#./I77SwwGC./GC./y77S77S!#,CGC-.GGC$567GC-.GC-.))C D D$aS!9:;A  QArg   c                   a aaa V VVV3R lpSP                   R,          o\        P                  P                  SRV,          4      Vn        V# )a  
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                   < \        V 4      SP                  9  d   SP                  V 4      p SP                  w  r#V'       d>   VP	                  R V4      pRV9   d   \        VR,          4      pVP	                  RV4      p\        V R4      '       d$    SP                  S! V P                  W#4      4      # \        V R4      '       d#   SP                  S! V P                  W#4      4      # \        S: R\        V 4      : 24      h  \         d?    SP                  '       d   h SP                  S! T P                  \        3Y#4      4      u # i ; i)rw   rx   ry   ru   r]  z of a )r}   r  r   r{   r|   r   r   r   ru   r   r  r  r   r]  ra   )r   r   rw   ry   r  mpc_fmpf_fr:  s   &,  rd   f/PythonMPContext._wrap_libmp_function.<locals>.f  s   Awcii'KKN //NDzz&$/F?&ve}5D!::j(;q'""Q<<aggt(FGG G$$||E!''4$BCC%dDG&DEE % Q'''<<qww.>(OPP	Qs   !D E!)EE:ro  NNzComputes the %s of x)ri   r\   __dict__r|   rm   )r  r  r  mpi_fdocr  r:  s   fff&& @rd   _wrap_libmp_function$PythonMPContext._wrap_libmp_function  sD    	F 	F( ~~b!!**..t5Kc5QR	rg   c                   a V'       d   V3R  lpMSp\         P                  P                  VSP                  4      Vn        \	        WV4       R# )c                    < V P                   pV Uu. uF
  qC! V4      NK  	  ppV P                  p V ;P                  ^
,          un        S! V .VO5/ VB pWPn        V5# u upi   YPn        i ; i)
   )r   rw   )r  r*  r   r   r   rw   retvalr  s   &*,    rd   	f_wrapped0PythonMPContext._wrap_specfun.<locals>.f_wrapped  sm    ++,01Dq
D1xx$HHNHs4T4V4F#Hw 2  $Hs   A%A$ $A,N)r\   r  r|   rm   setattr)rb   r:  r  wrapr$  s   &&f& rd   _wrap_specfunPythonMPContext._wrap_specfun  s;    	 I)2266tQYYG	9%rg   c                ,   \        VR 4      '       d    VP                  w  r#V\        8w  d   VR3# EMY\        VR4      '       d   VP                  pEM9\	        V4      \
        9   d   \        V4      R3# Rp\        V\        4      '       d   Vw  rEMg\        VR4      '       d   VP                  w  rEMF\        V\        4      '       d1   RV9   d*   VP                  R4      w  rE\        V4      p\        V4      pVe-   VX,          '       g   WE,          R3# V P                  WE4      R3# V P                  V4      p\        VR 4      '       d   VP                  w  r#V\        8w  d   VR3# M#\        VR4      '       d   VP                  pMVR3# Vw  rgrV'       dq   VR
8  dU   V'       d   V) pV^ 8  d   \        V4      V,          R3# VR
8  d(   \        V4      ^V) ,          rTV P                  WE4      R3# V P                  V4      pVR	3# V'       g   R# VR3# )r]  Cru   ZNr   /QUR)rd  r,  )r   r]  r   ru   r}   r   r   r   r   r   r   splitr   r   r   )
r  r   r   r  r   r   r   r   r   r   s
   &&        rd   _convert_paramPythonMPContext._convert_param  s   1gGGEAU{#v Q  AAw)#1vs{"A!U##1G$$ww1Az**saxwws|FF}1uu63;&wwq|S((AAq'"";c6M G$$GG#v3by$C!8s8s?C//"9s8a3$iq771<,,QAc6MMc6Mrg   c                    Vw  r#rEV'       d	   WE,           # V\         8X  d   V P                  # V\        8X  g   V\        8X  d   V P                  # V P
                  # r`   )r   ninfr   r    infnan)r  r   r   r   r   r   s   &&    rd   _mpf_magPythonMPContext._mpf_mag9  sE    36M:88O9U
77Nwwrg   c                f   \        VR4      '       d   V P                  VP                  4      # \        VR4      '       dx   VP                  w  r#V\        8X  d   V P                  V4      # V\        8X  d   V P                  V4      # ^\        V P                  V4      V P                  V4      4      ,           # \        V\        4      '       d)   V'       d   \        \        V4      4      # V P                  # \        V\        P                  4      '       dN   VP                  w  rEV'       d,   ^\        \        V4      4      ,           \        V4      ,
          # V P                  # V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  V4      # \!        R4      h)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)

ru   r]  zrequires an mpf/mpc)r   r9  ru   r]  r   r  r   r   r6   absr6  r[   r   r   r   magr   )r  r   rr  rs  r   r   s   &&    rd   r=  PythonMPContext.magC  s5   * 1g<<((Q  77DAEz||A&Ez||A&Sa#,,q/:::9%%A''88O8<<((77DA8CF++hqk9988OAAq'""ga&9&9wwqz! 566rg   rh   )T)F)FF)NF)NNz<no doc>)ri   rj   rk   rl   r  r   r  r  r  r  r/  rw   rx   r   r  r  r  r  r  r  r  r  r.  r(  r3  r9  r=  ro   rp   rq   s   @rd   r  r  G  s     
#

!
"" )95D
'
2C01d
=;8;@&>P-;^:xUn F & &"/b,7 ,7rg   r  N)rK  rK  rK  )}libmp.backendr   r   libmpr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   rK  r[   r\   rL  re   r~   r^   rt   r7  
return_mpf
return_mpcmpf_pow_samer@  r  rA  rB  rC  rD  rE  rF  r  r  r  r  r  rH  r\  r   r   r  r  ComplexregisterRealImportErrorrh   rg   rd   <module>rH     sx   -                      .  nn" "C)9 C)J< =
<
 : *9;
 /*<:ZG3j@B
 /*<:ZG8:EG
 /*<4zA3j@B
 /*<:ZG3j@B
 /*<:ZG13
 4zA8:EG
 << MM J J:Z:9 Z:z $h7f h7b	OOT"LL$ 		s   	:J JJ