
    [h                        S SK JrJr  S SKJrJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrFJGrGJHrHJIrIJJrJJKrKJLrLJMrMJNrNJOrOJPrPJQrQJRrRJSrSJTrTJUrUJVrVJWrWJXrXJYrYJr  S SKZJ[r[  S SKZJ\r\  \]R                  r_ " S S\]5      r` " S S\`5      raS	rbS
rcSrdS\c< S\d< S3reS3S jrf\f" SSSS5      \alg        \f" SS\c-   S\c-   S\d-   5      \alh        \f" SS\c-   S\c-   S\d-   5      \ali        \f" SS\c-   S\c-   S\d-   5      \alj        \f" S S!\c-   S"\c-   S#\d-   5      \alk        \f" S$S%\c-   S&\c-   S'5      \all        \f" S(\eS)\c-   S*\d-   5      \alm        \aR                  \aln        \aR                  \alo        \aR                  \alp        \aR                  \alr         " S+ S,\a5      rs " S- S.\`5      rt\u\t4rv " S/ S0\]5      rw S1S2Kxrx\xR                  R                  \t5        \xR                  R                  \a5        g2! \| a     g2f = f)4   )
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                   "    \ rS rSrSr/ rS rSrg)	mpnumeric!   zBase class for mpf and mpc.c                     [         eN)NotImplementedError)clsvals     L/var/www/auris/envauris/lib/python3.13/site-packages/mpmath/ctx_mp_python.py__new__mpnumeric.__new__$   s    !!     N)__name__
__module____qualname____firstlineno____doc__	__slots__rf   __static_attributes__ri   rh   re   r^   r^   !   s    %I"rh   r^   c                   |   \ rS rSrSrS/r\4S jr\S 5       r	\S 5       r
\S 5       r\" S 5      r\" S	 5      r\" S
 5      r\" S 5      r\" S 5      r\" S 5      rS rS rS rS rS rS rS rS rS rS rS r\rS rS r S r!S r"S r#S r$S r%S  r&S! r'S" r(S# r)S$ r*S% r+S& r,S' r-S-S) jr.S* r/S+ r0S,r1g()._mpf'   z
An mpf instance holds a real-valued floating-point number. mpf:s
work analogously to Python floats, but support arbitrary-precision
arithmetic.
_mpf_c                    U R                   R                  u  p4U(       a8  UR                  SU5      nSU;   a  [        US   5      nUR                  SU5      n[	        U5      U L a>  UR
                  u  pVpxU(       d	  U(       a  U$ [        U 5      n	[        XVXxX45      U	l        U	$ [	        U5      [        L a  [        U5      S:X  a%  [        U 5      n	[        US   US   X45      U	l        U	$ [        U5      S:X  aD  U[        [        [        4;  a  Uu  pVpx[        U[        U5      XxX45      n[        U 5      n	Xl        U	$ [        e[        U 5      n	[!        U R#                  XU5      X45      U	l        U	$ )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       r      )context_prec_roundinggetr   typert   newr   tuplelenr   r   r    r!   r   
ValueErrorr#   mpf_convert_arg)
rc   rd   kwargsrv   rx   signmanexpbcvs
             re   rf   _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Hrh   c                    [        U[        5      (       a  [        U5      $ [        U[        5      (       a  [	        U5      $ [        U[
        5      (       a  [        XU5      $ [        XR                  R                  5      (       a  UR                  X#5      $ [        US5      (       a  UR                  $ [        US5      (       aG  U R                  R                  UR                  X#5      5      n[        US5      (       a  UR                  $ [        US5      (       a   UR                  u  pVXV:X  a  U$ [        S5      e[!        S[#        U5      -   5      e)Nrt   _mpmath__mpi_z,can only create mpf from zero-width intervalcannot create mpf from )
isinstancer   r   floatr   r   r   r|   constantfunchasattrrt   convertr   r   r   	TypeErrorrepr)rc   xrv   rx   tabs          re   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;<<rh   c                    [        U[        5      (       a  [        U5      $ [        U[        5      (       a  [	        U5      $ [        U[
        5      (       a  U R                  R                  U5      $ [        U[        R                  5      (       a.  UR                  u  p#[        X#U R                  R                  5      $ [        US5      (       a  UR                  $ [        US5      (       a[  U R                  R                  UR                   " U R                  R"                  6 5      n[        US5      (       a  UR                  $ U$ [$        $ )Nrt   r   )r   r   r   r   r   complex_typesr|   mpcr[   mpq_mpq_r   rv   r   rt   r   r   r}   NotImplemented)rc   r   pqr   s        re   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rh   c                     U R                  U5      n[        U5      [        L a  U R                  R	                  U5      $ U$ ra   )r   r   r   r|   make_mpf)rc   r   s     re   mpf_convert_lhs_mpf.mpf_convert_lhst   s8    "7e;;''**rh   c                      U R                   SS $ )Nr      rt   selfs    re   <lambda>_mpf.<lambda>{   s    DJJqOrh   c                      U R                   S   $ Nr   r   r   s    re   r   r   |       

1rh   c                      U R                   S   $ )Nry   r   r   s    re   r   r   }   r   rh   c                      U R                   S   $ )Nr   r   r   s    re   r   r   ~   s    tzz!}rh   c                     U $ ra   ri   r   s    re   r   r      s    rh   c                 .    U R                   R                  $ ra   )r|   zeror   s    re   r   r      s    !2!2rh   c                     U $ ra   ri   r   s    re   r   r      s    Trh   c                 ,    [        U R                  5      $ ra   )r   rt   r   s    re   __getstate___mpf.__getstate__   s    ;tzz#::rh   c                 $    [        U5      U l        g ra   )r   rt   r   rd   s     re   __setstate___mpf.__setstate__   s    mC.@rh   c                     U R                   R                  (       a  [        U 5      $ S[        U R                  U R                   R
                  5      -  $ )Nz	mpf('%s'))r|   prettystrr   rt   _repr_digitsss    re   __repr___mpf.__repr__   s8    99q6MVAGGQYY-C-CDDDrh   c                 V    [        U R                  U R                  R                  5      $ ra   )r   rt   r|   _str_digitsr   s    re   __str___mpf.__str__   s    6!''199+@+@AArh   c                 ,    [        U R                  5      $ ra   )r3   rt   r   s    re   __hash___mpf.__hash__   s    HQWW--rh   c                 >    [        [        U R                  5      5      $ ra   )intr   rt   r   s    re   __int___mpf.__int__   s    3vagg//rh   c                 >    [        [        U R                  5      5      $ ra   )longr   rt   r   s    re   __long___mpf.__long__   s    D11rh   c                 X    [        U R                  U R                  R                  S   S9$ Nr   )rnd)r   rt   r|   r}   r   s    re   	__float___mpf.__float__   s!    Xagg1993K3KA3NOOrh   c                 *    [        [        U 5      5      $ ra   )complexr   r   s    re   __complex___mpf.__complex__   s    wuQx00rh   c                 (    U R                   [        :g  $ ra   )rt   r   r   s    re   __nonzero___mpf.__nonzero__   s    qww%//rh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )_ctxdatar"   rt   r   rc   r   rv   rx   r   s         re   __abs___mpf.__abs__   3    %&ZZ""4H!''42rh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )r   r#   rt   r   s         re   __pos___mpf.__pos__   r   rh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )r   r$   rt   r   s         re   __neg___mpf.__neg__   r   rh   c                     [        US5      (       a  UR                  nOU R                  U5      nU[        L a  U$ U" U R                  U5      $ Nrt   )r   rt   r   r   )r   r   r   s      re   _cmp	_mpf._cmp   sF    1gA!!!$AN"AGGQrh   c                 .    U R                  U[        5      $ ra   )r   r.   r   r   s     re   __cmp___mpf.__cmp__   s    affQ00rh   c                 .    U R                  U[        5      $ ra   )r   r/   r   s     re   __lt___mpf.__lt__       QVVAv..rh   c                 .    U R                  U[        5      $ ra   )r   r0   r   s     re   __gt___mpf.__gt__   r   rh   c                 .    U R                  U[        5      $ ra   )r   r1   r   s     re   __le___mpf.__le__   r   rh   c                 .    U R                  U[        5      $ ra   )r   r2   r   s     re   __ge___mpf.__ge__   r   rh   c                 H    U R                  U5      nU[        L a  U$ U(       + $ ra   __eq__r   )r   r   r   s      re   __ne___mpf.__ne__   #    HHQKHurh   c                     U R                   u  p#u  pE[        U5      [        ;   a/  U" U5      n[        [	        U5      U R
                  XE5      Ul        U$ U R                  U5      nU[        L a  U$ X-
  $ ra   )r   r   r   r&   r   rt   r   r   r   r   rc   r   rv   rx   r   s          re   __rsub___mpf.__rsub__   si    %&ZZ""47iCAhqk177DCAGHa Hurh   c                     U R                   u  p#u  pE[        U[        5      (       a%  U" U5      n[        XR                  XE5      Ul        U$ U R                  U5      nU[        L a  U$ X-  $ ra   )r   r   r   r*   rt   r   r   r  s          re   __rdiv___mpf.__rdiv__   sd    %&ZZ""4a##CA"1ggt>AGHa Hurh   c                 B    U R                  U5      nU[        L a  U$ X-  $ ra   r   r   r   s     re   __rpow___mpf.__rpow__   &    a Hvrh   c                 B    U R                  U5      nU[        L a  U$ X-  $ ra   r  r   s     re   __rmod___mpf.__rmod__   &    a Hurh   c                 8    U R                   R                  U 5      $ ra   )r|   sqrtr   s    re   r  	_mpf.sqrt   s    yy~~a  rh   Nc                 :    U R                   R                  XX#5      $ ra   r|   almosteqr   r   rel_epsabs_epss       re   ae_mpf.ae       yy!!!99rh   c                 .    [        U R                  U5      $ ra   )r7   rt   )r   rv   s     re   r7   _mpf.to_fixed   s    

D))rh   c                 ,    [        [        U 5      /UQ76 $ ra   )roundr   )r   argss     re   	__round___mpf.__round__   s    U4[(4((rh   r   NN)2rj   rk   rl   rm   rn   ro   r   rf   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-  rp   ri   rh   re   rr   rr   '   s   
 	I !F = ="     34G
-
.C
-
.C	,	-B%&D23D!I:@E
 B-/1O0/H  1....		!:*)rh   rr   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                     [         nUR                  SU5      nUR                  SU5      nUR                  SU5      nUR                  SU 5      n0 n[        U[        5       U5        XP   $ )Nz
%WITH_INT%z
%WITH_MPC%z
%WITH_MPF%z%NAME%)mpf_binary_opreplacer   globals)namewith_mpfwith_intwith_mpccodenps         re   	binary_oprB    sa    D<<h/D<<h/D<<h/D<<$'D	B	$	28Orh   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                   B    \ rS rSrSrS	S jrS
S jr\S 5       rS r	Sr
g)	_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    [         R                  U 5      nX$l        Xl        [	        [
        US5      Ul        U$ )N )objectrf   r<  r   getattrr\   rn   )rc   r   r<  docnamer   s        re   rf   _constant.__new__P  s/    NN3M7B7	rh   Nc                     U R                   R                  u  pEU(       d  UnU(       d  UnU(       a  [        U5      nU R                   R                  U R	                  X5      5      $ ra   )r|   r}   r   r   r   )r   rv   rw   rx   prec2	rounding2s         re   __call___constant.__call__W  sL    <<66ETI{3'||$$TYYt%>??rh   c                 T    U R                   R                  u  pU R                  X5      $ ra   )r|   r}   r   )r   rv   rx   s      re   rt   _constant._mpf_^  s"    44yy((rh   c           	      f    SU R                   < SU R                  R                  U " SS95      < S3$ )N<z:    )rw   z~>)r<  r|   nstrr   s    re   r   _constant.__repr__c  s$    "ii):):4B<)HIIrh   ri   )rL  )NNN)rj   rk   rl   rm   rn   rf   rT  r1  rt   r   rp   ri   rh   re   rJ  rJ  J  s-    @
@ ) )Jrh   rJ  c                      \ rS rSrSrS/rS"S jr\" S 5      r\" S 5      r	S r
S rS	 rS
 rS rS rS rS rS rS r\rS r\S 5       rS rS rS r\r\r\r\rS rS rS r S r!S r"\r#S r$S r%S r&S r'\!r(\&r)S#S  jr*S!r+g)$_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                 x   [         R                  U 5      n[        U[        5      (       a  UR                  UR
                  p!O$[        US5      (       a  UR                  Ul        U$ U R                  R                  U5      nU R                  R                  U5      nUR                  UR                  4Ul        U$ )Nr_  )rM  rf   r   r   r3  r4  r   r_  r|   mpfrt   )rc   r3  r4  r   s       re   rf   _mpc.__new__p  s    NN3dM**DII$T7##jjAGH{{t${{t$::tzz*rh   c                 R    U R                   R                  U R                  S   5      $ )Nrz   r|   r   r_  r   s    re   r   _mpc.<lambda>|      !6!6tzz!}!Erh   c                 R    U R                   R                  U R                  S   5      $ r   rd  r   s    re   r   re  }  rf  rh   c                 b    [        U R                  S   5      [        U R                  S   5      4$ Nrz   r   )r   r_  r   s    re   r   _mpc.__getstate__  s'    4::a=);tzz!}+EEErh   c                 F    [        US   5      [        US   5      4U l        g ri  )r   r_  r   s     re   r   _mpc.__setstate__  s     "3q6*M#a&,AA
rh   c                     U R                   R                  (       a  [        U 5      $ [        U R                  5      SS n[        U R
                  5      SS n[        U 5      R                  < SU< SU< S3$ )Nr{   z(real=z, imag=))r|   r   r   r   r3  r4  r   rj   )r   ris      re   r   _mpc.__repr__  sW    99q6ML2L2)-a)9)91a@@rh   c                 \    S[        U R                  U R                  R                  5      -  $ )Nz(%s))r8   r_  r|   r   r   s    re   r   _mpc.__str__  s"    
177AII,A,ABBBrh   c                 X    [        U R                  U R                  R                  S   S9$ r   )r9   r_  r|   r}   r   s    re   r   _mpc.__complex__  s"    agg199+C+CA+FGGrh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )r   r;   r_  r   s         re   r   _mpc.__pos__  r   rh   c                     U R                   R                  u  p[        U R                   R                  5      n[	        U R
                  X5      Ul        U$ ra   )r|   r}   r   ra  r?   r_  rt   )r   rv   rx   r   s       re   r   _mpc.__abs__  s<    11		!''42rh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )r   r=   r_  r   s         re   r   _mpc.__neg__  r   rh   c                 n    U R                   u  pu  p4U" U5      n[        U R                  X45      Ul        U$ ra   )r   r>   r_  r   s         re   r5  _mpc.conjugate  s3    %&ZZ""4H8rh   c                 ,    [        U R                  5      $ ra   )r<   r_  r   s    re   r   _mpc.__nonzero__  s    agg&&rh   c                 ,    [        U R                  5      $ ra   )r:   r_  r   s    re   r   _mpc.__hash__  s      rh   c                 j     U R                   R                  U5      nU$ ! [         a	    [        s $ f = fra   )r|   r   r   r   )rc   r   ys      re   mpc_convert_lhs_mpc.mpc_convert_lhs  s5    	"##A&AH 	"!!	"s    22c                     [        US5      (       d2  [        U[        5      (       a  gU R                  U5      nU[        L a  U$ U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ )Nr_  F)r   r   r   r  r   r3  r4  r   s     re   r  _mpc.__eq__  sa    q'""!S!!!!!$AN"vv4AFFaff$44rh   c                 H    U R                  U5      nU[        L a  U$ U(       + $ ra   r  )r   r   r   s      re   r	  _mpc.__ne__  r  rh   c                      [        S5      e)Nz3no ordering relation is defined for complex numbers)r   )r,  s    re   _compare_mpc._compare  s    MNNrh   c                 `   U R                   u  p#u  pE[        US5      (       d]  U R                  U5      nU[        L a  U$ [        US5      (       a0  U" U5      n[	        U R
                  UR                  XE5      Ul        U$ U" U5      n[        U R
                  UR
                  XE5      Ul        U$ Nr_  rt   )r   r   r  r   rA   r_  rt   r@   r  s          re   rC  _mpc.__add__      %&ZZ""4q'""!!!$AN"q'""H%aggqwwGH!''177D;rh   c                 `   U R                   u  p#u  pE[        US5      (       d]  U R                  U5      nU[        L a  U$ [        US5      (       a0  U" U5      n[	        U R
                  UR                  XE5      Ul        U$ U" U5      n[        U R
                  UR
                  XE5      Ul        U$ r  )r   r   r  r   rC   r_  rt   rB   r  s          re   rD  _mpc.__sub__  r  rh   c                    U R                   u  p#u  pE[        US5      (       d  [        U[        5      (       a&  U" U5      n[	        U R
                  XU5      Ul        U$ U R                  U5      nU[        L a  U$ [        US5      (       a0  U" U5      n[        U R
                  UR                  XE5      Ul        U$ U R                  U5      nU" U5      n[        U R
                  UR
                  XE5      Ul        U$ r  )r   r   r   r   rF   r_  r  r   rE   rt   rD   r  s          re   rE  _mpc.__mul__  s    %&ZZ""4q'""!Y''H%aggqA!!!$AN"q'""H%aggqwwG!!!$AH!''177D;rh   c                 `   U R                   u  p#u  pE[        US5      (       d]  U R                  U5      nU[        L a  U$ [        US5      (       a0  U" U5      n[	        U R
                  UR                  XE5      Ul        U$ U" U5      n[        U R
                  UR
                  XE5      Ul        U$ r  )r   r   r  r   rH   r_  rt   rG   r  s          re   rF  _mpc.__div__   r  rh   c                    U R                   u  p#u  pE[        U[        5      (       a&  U" U5      n[        U R                  XU5      Ul        U$ U R                  U5      nU[        L a  U$ U" U5      n[        US5      (       a(  [        U R                  UR                  XE5      Ul        U$ [        U R                  UR                  XE5      Ul        U$ r   )r   r   r   rK   r_  r  r   r   rJ   rt   rI   r  s          re   rH  _mpc.__pow__  s    %&ZZ""4a##CA!!''1H=AGHa HH1g!!''177DCAG  aggqww?AGrh   c                 B    U R                  U5      nU[        L a  U$ X-
  $ ra   r  r   r   s     re   r  _mpc.__rsub__   r  rh   c                     U R                   u  p#u  pE[        U[        5      (       a&  U" U5      n[        U R                  XU5      Ul        U$ U R                  U5      nU[        L a  U$ X-  $ ra   )r   r   r   rF   r_  r  r   r  s          re   __rmul___mpc.__rmul__&  sf    %&ZZ""4a##CA!!''1H=AGHa Hurh   c                 B    U R                  U5      nU[        L a  U$ X-  $ ra   r  r   s     re   r  _mpc.__rdiv__1  r  rh   c                 B    U R                  U5      nU[        L a  U$ X-  $ ra   r  r   s     re   r  _mpc.__rpow__7  r  rh   Nc                 :    U R                   R                  XX#5      $ ra   r   r"  s       re   r%  _mpc.ae@  r'  rh   )r_  )rz   rz   r/  ),rj   rk   rl   rm   rn   ro   rf   r1  r3  r4  r   r   r   r   r   r   r   r   r5  r   r6  r   r0  r  r  r	  r  r   r  r  rC  rD  rE  rF  rH  __radd__r  r  r  r  __truediv____rtruediv__r%  rp   ri   rh   re   r^  r^  g  s     	I
 EFDEFDFBACH' H! " "5O FFFF&  H	 KL:rh   r^  c                       \ rS rSrS rS rS rS rS rS r	\
" S \5      r\
" S	 \	5      rSS
 jrS rS rS rS rSS jrSS jrSS jrSS jr\S 5       rS rS rS rSrg)PythonMPContextiG  c                    S[         /U l        [        S[        40 5      U l        [        S[
        40 5      U l        U R                  [        U R                  /U R                  l        U R                  [        U R                  /U R                  l        X R                  l	        X R                  l	        [        S[        40 5      U l        U R                  [        U R                  /U R                  l        X R                  l	        g )N5   ra  r   r   )r   r}   r   rr   ra  r^  r   r   r   r|   rJ  r   ctxs    re   __init__PythonMPContext.__init__I  s     -0utgr*utgr*GGS#*<*<=GGS#*<*<=Jb9!$#s/A/A B"rh   c                 <    [        U R                  5      nXl        U$ ra   )r   ra  rt   r  r   r   s      re   r   PythonMPContext.make_mpfU      Lrh   c                 <    [        U R                  5      nXl        U$ ra   )r   r   r_  r  s      re   make_mpcPythonMPContext.make_mpcZ  r  rh   c                 L    S=U l         U R                  S'   SU l        SU l        g )Nr  rz   rZ  F)_precr}   _dpstrap_complexr  s    re   defaultPythonMPContext.default_  s(    ,..	C&&q) rh   c                 v    [        S[        U5      5      =U l        U R                  S'   [	        U5      U l        g )Nr   rz   )maxr   r  r}   r   r  r  ns     re   	_set_precPythonMPContext._set_precd  s.    ,/3q6N:	C&&q)q>rh   c                 v    [        U5      =U l        U R                  S'   [        S[	        U5      5      U l        g ri  )r   r  r}   r  r   r  r  s     re   _set_dpsPythonMPContext._set_dpsh  s.    ,7N:	C&&q)q#a&>rh   c                     U R                   $ ra   )r  r  s    re   r   PythonMPContext.<lambda>l  s    		rh   c                     U R                   $ ra   )r  r  s    re   r   r  m  s    sxxrh   c                    [        U5      U R                  ;   a  U$ [        U[        5      (       a  U R	                  [        U5      5      $ [        U[        5      (       a  U R	                  [        U5      5      $ [        U[        5      (       a9  U R                  [        UR                  5      [        UR                  5      45      $ [        U5      R                  S:X  a  U R                  U5      $ [        U[        R                  5      (       a=  [         R"                  " [%        UR&                  5      [%        UR(                  5      5      nU R*                  u  p4[        U[         R"                  5      (       a)  UR,                  u  pVU R	                  [/        XVU5      5      $ U(       a3  [        U[0        5      (       a   [3        XU5      nU R	                  U5      $ [7        US5      (       a  U R	                  UR8                  5      $ [7        US5      (       a  U R                  UR:                  5      $ [7        US5      (       a   U R=                  UR?                  X45      5      $ [        U5      R                  S:X  a  U R	                  [A        XU5      5      $ U RC                  X5      $ !    GNc= f! [4         a     Nf = f!    N-= f)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')

numpyrt   r_  r   decimal)"r   typesr   r   r   r   r   r   r   r  r3  r4  rk   	npconvertnumbersRationalr[   r   r   	numeratordenominatorr}   r   r   r   r   r   r   rt   r_  r   r   r   _convert_fallback)r  r   stringsrv   rx   r   r   rt   s           re   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*   =J, J4  K ,J14
K KKc                    SSK n[        XR                  5      (       a#  U R                  [	        [        U5      5      5      $ [        XR                  5      (       a  U R                  [        U5      5      $ [        XR                  5      (       a9  U R                  [        UR                  5      [        UR                  5      45      $ [        S[        U5      -   5      e)zF
Converts *x* to an ``mpf`` or ``mpc``. *x* should be a numpy
scalar.
rz   Nr   )r  r   integerr   r   r   floatingr   complexfloatingr  r3  r4  r   r   )r  r   rA  s      re   r  PythonMPContext.npconvert  s    
 	a$$S\\(3q6:J-K&Ka%%cll<?.K'Ka++,,<<aff!5|AFF7K LMM1DG;<<rh   c                    [        US5      (       a  UR                  [        :H  $ [        US5      (       a  [        UR                  ;   $ [	        U[
        5      (       d  [	        U[        R                  5      (       a  gU R                  U5      n[        US5      (       d  [        US5      (       a  U R                  U5      $ [        S5      e)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

rt   r_  Fzisnan() needs a number as input)r   rt   r!   r_  r   r   r[   r   r   isnanr   )r  r   s     re   r  PythonMPContext.isnan  s    " 1g77d?"1g177?"a##z!X\\'B'BKKN1g'!W"5"599Q<9::rh   c                    [        US5      (       a  UR                  [        [        4;   $ [        US5      (       a3  UR                  u  p#U[        [        4;   =(       d    U[        [        4;   $ [        U[        5      (       d  [        U[        R                  5      (       a  gU R                  U5      n[        US5      (       d  [        US5      (       a  U R                  U5      $ [        S5      e)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

rt   r_  Fzisinf() needs a number as input)r   rt   r   r    r_  r   r   r[   r   r   isinfr   )r  r   reims       re   r  PythonMPContext.isinf  s    ( 1g77tUm++1gWWFB$&="u*==a##z!X\\'B'BKKN1g'!W"5"599Q<9::rh   c                 ,   [        US5      (       a  [        UR                  S   5      $ [        US5      (       aM  UR                  u  p#[        US   5      n[        US   5      nU[        :X  a  U$ U[        :X  a  U$ U=(       a    U$ [        U[        5      (       d  [        U[        R                  5      (       a  [        U5      $ U R                  U5      n[        US5      (       d  [        US5      (       a  U R                  U5      $ [        S5      e)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
rt   r   r_  z"isnormal() needs a number as input)r   boolrt   r_  r   r   r   r[   r   r   isnormalr   )r  r   r  r  	re_normal	im_normals         re   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<<?"<==rh   c                    [        U[        5      (       a  g[        US5      (       a8  UR                  =u  p4pVn[	        U=(       a    US:  =(       d	    U[
        :H  5      $ [        US5      (       ay  UR                  u  pUu  ppU	u  pnnU=(       a    US:  =(       d	    U[
        :H  nU(       a)  U=(       a    US:  =(       d	    U	[
        :H  nU=(       a    U$ U=(       a	    U	[
        :H  $ [        U[        R                  5      (       a  UR                  u  nnUU-  S:H  $ U R                  U5      n[        US5      (       d  [        US5      (       a  U R                  X5      $ [        S5      e)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

Trt   rz   r_  zisint() needs a number as input)r   r   r   rt   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                         re   r  PythonMPContext.isint  s7   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::rh   c                    U R                   u  pE/ n/ nU GH  nS=p[        US5      (       a  UR                  n	Ou[        US5      (       a  UR                  u  pOUU R	                  U5      n[        US5      (       a  UR                  n	O&[        US5      (       a  UR                  u  pO[
        eU
(       a  U(       au  U(       a6  UR                  [        X5      5        UR                  [        X5      5        M  [        X4SUS-   5      u  pUR                  U	5        UR                  U
5        GM  U(       a  UR                  [        X4U5      5        GMC  UR                  U	5        UR                  U
5        GMh  U(       a  [        X5      n	OU(       a  [        U	5      n	UR                  U	5        GM     [        XdXR5      nU(       a  U R                  U[        XtU5      45      nU$ U R                  U5      nU$ )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.
rz   rt   r_  ry   
   )r}   r   rt   r_  r   rb   appendr'   rK   r?   r"   r5   r  r   )r  termsabsolutesquaredrv   r   r3  r4  termrevalimvalr   s               re   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rh   Nc           	         Ub  [        X5      nU R                  u  pE/ n/ n[        nU R                  U R                  4n	U GH8  u  p[        U
5      U	;  a  U R                  U
5      n
[        U5      U	;  a  U R                  U5      nU" U
S5      nU" US5      nU(       a8  U(       a1  UR                  [        U
R                  UR                  5      5        M  U" U
S5      nU" US5      nU(       am  U(       af  U
R                  nUR                  u  nnU(       a  [        U5      nUR                  [        UU5      5        UR                  [        UU5      5        GM  U(       a[  U(       aT  U
R                  u  nnUR                  nUR                  [        UU5      5        UR                  [        UU5      5        GM  U(       a  U(       a  U
R                  u  nnUR                  u  nnU(       a  [        U5      nUR                  [        UU5      5        UR                  [        [        UU5      5      5        UR                  [        UU5      5        UR                  [        UU5      5        GM5  [        e   [        XdU5      nU(       a  U R                  U[        XtU5      45      nU$ U R                  U5      nU$ )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')

rt   r_  )zipr}   r   ra  r   r   r   r  r'   rt   r_  r$   rb   r5   r  r   )r  ABr5  rv   r   r3  r4  hasattr_r  r   r   a_realb_real	a_complex	b_complexavalbrebimareaimbvalr   s                          re   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rh   c                    ^ ^^^ U UUU4S jnTR                   SS m[        R                  R                  TSU-  5      Ul        U$ )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                   > [        U 5      TR                  ;  a  TR                  U 5      n TR                  u  p#U(       a8  UR	                  SU5      nSU;   a  [        US   5      nUR	                  SU5      n[        U S5      (       a#   TR                  T" U R                  X#5      5      $ [        U S5      (       a"  TR                  T" U R                  X#5      5      $ [        T< S[        U 5      < 35      e! [         a=    TR                  (       a  e TR                  T" U R                  [        4X#5      5      s $ f = f)Nrv   rw   rx   rt   r_  z of a )r   r  r   r}   r~   r   r   r   rt   r   r  r  r   r_  rb   )r   r   rv   rx   r  mpc_fmpf_fr<  s       re   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   !C; ;AEEr{   NzComputes the %s of x)rj   r\   __dict__r~   rn   )r  r  r  mpi_fdocr  r<  s   ```   @re   _wrap_libmp_function$PythonMPContext._wrap_libmp_function  sF    	F 	F( ~~ab!!**..t5Kc5QR	rh   c                    ^ U(       a  U4S jnOTn[         R                  R                  UTR                  5      Ul        [	        XU5        g )Nc                    > U R                   nU Vs/ s H
  oC" U5      PM     nnU R                  n U =R                  S-  sl        T" U /UQ70 UD6nXPl        U7$ s  snf ! XPl        f = f)Nr  )r   rv   )r  r,  r   r   r   rv   retvalr  s          re   	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))r\   r  r~   rn   setattr)rc   r<  r  wrapr"  s     `  re   _wrap_specfunPythonMPContext._wrap_specfun  s;    	 I)2266tQYYG	9%rh   c                    [        US5      (       a  UR                  u  p#U[        :w  a  US4$ GOF[        US5      (       a  UR                  nGO'[	        U5      [
        ;   a  [        U5      S4$ S n[        U[        5      (       a  Uu  pEOd[        US5      (       a  UR                  u  pEOD[        U[        5      (       a/  SU;   a)  UR                  S5      u  pE[        U5      n[        U5      nUb#  UW-  (       d  XE-  S4$ U R                  XE5      S4$ U R                  U5      n[        US5      (       a  UR                  u  p#U[        :w  a  US4$ O"[        US5      (       a  UR                  nOUS4$ Uu  pgpU(       ad  US	:  aI  U(       a  U* nUS
:  a  [        U5      U-  S4$ US	:  a#  [        U5      SU* -  pTU R                  XE5      S4$ U R                  U5      nUS4$ U(       d  gUS4$ )Nr_  Crt   Zr   /QUrz   r   R)rz   r*  )r   r_  r   rt   r   r   r   r   r   r   r   splitr   r   r   )
r  r   r   r  r   r   r   r   r   r   s
             re   _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}1u63;&wwq|S((AAq'"";c6M G$$GG#v3by$C!8s8s?C//"9s8a3$iq771<,,QAc6Mc6Mrh   c                     Uu  p#pEU(       a  XE-   $ U[         :X  a  U R                  $ U[        :X  d
  U[        :X  a  U R                  $ U R
                  $ ra   )r   ninfr   r    infnan)r  r   r   r   r   r   s         re   _mpf_magPythonMPContext._mpf_mag9  sE    36M:88O9U
77Nwwrh   c                 :   [        US5      (       a  U R                  UR                  5      $ [        US5      (       aq  UR                  u  p#U[        :X  a  U R                  U5      $ U[        :X  a  U R                  U5      $ S[        U R                  U5      U R                  U5      5      -   $ [        U[        5      (       a'  U(       a  [        [        U5      5      $ U R                  $ [        U[        R                  5      (       aD  UR                  u  pEU(       a#  S[        [        U5      5      -   [        U5      -
  $ U R                  $ U R                  U5      n[        US5      (       d  [        US5      (       a  U R                  U5      $ [!        S5      e)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)

rt   r_  r   zrequires an mpf/mpc)r   r7  rt   r_  r   r  r   r   r6   absr4  r[   r   r   r   magr   )r  r   rp  rq  r   r   s         re   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6rh   ri   )T)F)FF)NF)NNz<no doc>)rj   rk   rl   rm   r  r   r  r  r  r  r1  rv   rw   r   r  r  r  r  r  r  r  r  r0  r&  r1  r7  r;  rp   ri   rh   re   r  r  G  s    
#

!
"" )95D
'
2C01d
=;8;@&>P-;^:xUn F & &"/b,7rh   r  rz   N)rL  rL  rL  )}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   rL  r[   r\   rM  rf   r   r^   rr   r9  
return_mpf
return_mpcmpf_pow_samerB  r  rC  rD  rE  rF  rG  rH  r  r  r  r  r  rJ  r^  r   r   r  r  ComplexregisterRealImportErrorri   rh   re   <module>rF     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   	:I II