
    g                        d dl mZmZ d dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZ d dlZm[Z[ d dlZm\Z\ e]j^        Z_ G d de]          Z` G d de`          Zad	Zbd
ZcdZddecdeddZed4dZf efdddd          ea_g         efddecz   decz   dedz             ea_h         efddecz   decz   dedz             ea_i         efddecz   decz   d edz             ea_j         efd!d"ecz   d#ecz   d$edz             ea_k         efd%d&ecz   d'ecz   d(          ea_l         efd)eed*ecz   d+edz             ea_m        eajh        ea_n        eajj        ea_o        eajk        ea_p        eajq        ea_r         G d, d-ea          Zs G d. d/e`          ZteuetfZv G d0 d1e]          Zw	 d2d3lxZxexjy        z                    et           exj{        z                    ea           d3S # e|$ r Y d3S w xY w)5   )
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                       e Zd ZdZg Zd ZdS )	mpnumericzBase class for mpf and mpc.c                     t           N)NotImplementedError)clsvals     P/var/www/html/ai-engine/env/lib/python3.11/site-packages/mpmath/ctx_mp_python.py__new__zmpnumeric.__new__$   s    !!    N)__name__
__module____qualname____doc__	__slots__re    rf   rd   r^   r^   !   s.        %%I" " " " "rf   r^   c                      e Zd ZdZdgZefdZed             Zed             Z	ed             Z
 ed           Z ed           Z ed	           Z ed
           Z ed           Z ed           Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeZd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d+d(Z-d) Z.d* Z/d'S ),_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                 Z   | j         j        \  }}|rE|                    d|          }d|v rt          |d                   }|                    d|          }t	          |          | u r<|j        \  }}}}|s|r|S t          |           }	t          ||||||          |	_        |	S t	          |          t          u rt          |          dk    r4t          |           }	t          |d         |d         ||          |	_        |	S t          |          dk    rV|t          t          t          fvr(|\  }}}}t          |t          |          ||||          }t          |           }	||	_        |	S t          t          |           }	t!          |                     |||          ||          |	_        |	S )zA new mpf can be created from a Python float, an int, a
        or a decimal string representing a number in floating-point
        format.precdpsrounding       r      )context_prec_roundinggetr   typero   newr   tuplelenr   r   r    r!   r   
ValueErrorr#   mpf_convert_arg)
rb   rc   kwargsrq   rs   signmanexpbcvs
             rd   re   z_mpf.__new__/   s    3h 	8::fd++D"6%=11zz*h77H99!$D#sB S 
CAc3D(CCAGH#YY%3xx1}}HH&s1vs1vtXFF3xx1}}tUD111),&D#sB#D#c((CT8LLCHHCAc11#tXFFhWWAGHrf   c                    t          |t                    rt          |          S t          |t                    rt	          |          S t          |t
                    rt          |||          S t          || j        j                  r|	                    ||          S t          |d          r|j        S t          |d          rE| j                            |                    ||                    }t          |d          r|j        S t          |d          r!|j        \  }}||k    r|S t          d          t!          dt#          |          z             )Nro   _mpmath__mpi_z,can only create mpf from zero-width intervalcannot create mpf from )
isinstancer   r   floatr   r   r   rw   constantfunchasattrro   convertr   r   r~   	TypeErrorrepr)rb   xrq   rs   tabs          rd   r   z_mpf.mpf_convert_argR   s:   a##7HQKK%7a5
1!5a$$HXax-H-H&Ha-..MqvvdH7M7M0M1g.qw1j!! 	##AJJtX$>$>??Aq'"" w1g 	M7DAqAvvKLLL1DGG;<<<rf   c                 T   t          |t                    rt          |          S t          |t                    rt	          |          S t          |t
                    r| j                            |          S t          |t          j	                  r%|j
        \  }}t          ||| j        j                  S t          |d          r|j        S t          |d          rE| j                             |j        | j        j                   }t          |d          r|j        S |S t$          S )Nro   r   )r   r   r   r   r   complex_typesrw   mpcr[   mpq_mpq_r   rq   r   ro   r   r   rx   NotImplemented)rb   r   pqr   s        rd   mpf_convert_rhsz_mpf.mpf_convert_rhsd   s    a##7HQKK%7a5
1!5a''B0B0B)Ba&& 	97DAq As{'78881g.qw1j!! 	##JAJ0J$KLLAq'"" wHrf   c                     |                      |          }t          |          t          u r| j                            |          S |S r`   )r   rz   r|   rw   make_mpf)rb   r   s     rd   mpf_convert_lhsz_mpf.mpf_convert_lhst   sA    ""77e;''***rf   c                      | j         dd         S )Nr      ro   selfs    rd   <lambda>z_mpf.<lambda>{   s    DJqsO rf   c                     | j         d         S Nr   r   r   s    rd   r   z_mpf.<lambda>|       
1 rf   c                     | j         d         S )Nrt   r   r   s    rd   r   z_mpf.<lambda>}   r   rf   c                     | j         d         S )Nr   r   r   s    rd   r   z_mpf.<lambda>~   s    tz!} rf   c                     | S r`   rl   r   s    rd   r   z_mpf.<lambda>   s     rf   c                     | j         j        S r`   )rw   zeror   s    rd   r   z_mpf.<lambda>   s    !2 rf   c                     | S r`   rl   r   s    rd   r   z_mpf.<lambda>   s    T rf   c                 *    t          | j                  S r`   )r   ro   r   s    rd   __getstate__z_mpf.__getstate__   s    ;tz#:#::rf   c                 .    t          |          | _        d S r`   )r   ro   r   rc   s     rd   __setstate__z_mpf.__setstate__   s    mC.@.@rf   c                 |    | j         j        rt          |           S dt          | j        | j         j                  z  S )Nz	mpf('%s'))rw   prettystrr   ro   _repr_digitsss    rd   __repr__z_mpf.__repr__   s6    9 	q66MVAGQY-CDDDDrf   c                 @    t          | j        | j        j                  S r`   )r   ro   rw   _str_digitsr   s    rd   __str__z_mpf.__str__   s    6!'19+@AAArf   c                 *    t          | j                  S r`   )r3   ro   r   s    rd   __hash__z_mpf.__hash__   s    HQW---rf   c                 D    t          t          | j                            S r`   )intr   ro   r   s    rd   __int__z_mpf.__int__   s    3vag///rf   c                 D    t          t          | j                            S r`   )longr   ro   r   s    rd   __long__z_mpf.__long__   s    D111rf   c                 N    t          | j        | j        j        d                   S Nr   )rnd)r   ro   rw   rx   r   s    rd   	__float__z_mpf.__float__   s     Xag193KA3NOOOOrf   c                 :    t          t          |                     S r`   )complexr   r   s    rd   __complex__z_mpf.__complex__   s    wuQxx000rf   c                 "    | j         t          k    S r`   )ro   r   r   s    rd   __nonzero__z_mpf.__nonzero__   s    qw%//rf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )_ctxdatar"   ro   r   rb   r{   rq   rs   r   s         rd   __abs__z_mpf.__abs__   <    %&Z"S"4CHH!'422rf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )r   r#   ro   r   s         rd   __pos__z_mpf.__pos__   r   rf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )r   r$   ro   r   s         rd   __neg__z_mpf.__neg__   r   rf   c                     t          |d          r|j        }n |                     |          }|t          u r|S  || j        |          S Nro   )r   ro   r   r   )r   r   r   s      rd   _cmpz	_mpf._cmp   sT    1g 	AA!!!$$AN""tAGQrf   c                 8    |                      |t                    S r`   )r   r.   r   r   s     rd   __cmp__z_mpf.__cmp__   s    affQ000rf   c                 8    |                      |t                    S r`   )r   r/   r   s     rd   __lt__z_mpf.__lt__       QVVAv...rf   c                 8    |                      |t                    S r`   )r   r0   r   s     rd   __gt__z_mpf.__gt__   r   rf   c                 8    |                      |t                    S r`   )r   r1   r   s     rd   __le__z_mpf.__le__   r   rf   c                 8    |                      |t                    S r`   )r   r2   r   s     rd   __ge__z_mpf.__ge__   r   rf   c                 H    |                      |          }|t          u r|S | S r`   __eq__r   )r   r   r   s      rd   __ne__z_mpf.__ne__   (    HHQKKHurf   c                     | j         \  }}\  }}t          |          t          v r6 ||          }t          t	          |          | j        ||          |_        |S |                     |          }|t          u r|S || z
  S r`   )r   rz   r   r&   r   ro   r   r   r   r   rb   r{   rq   rs   r   s          rd   __rsub__z_mpf.__rsub__   s    %&Z"S"477iCAhqkk17D(CCAGHa  H1urf   c                     | j         \  }}\  }}t          |t                    r) ||          }t          || j        ||          |_        |S |                     |          }|t          u r|S || z  S r`   )r   r   r   r*   ro   r   r   r   s          rd   __rdiv__z_mpf.__rdiv__   s|    %&Z"S"4a## 	CA"1agtX>>AGHa  H1urf   c                 L    |                      |          }|t          u r|S || z  S r`   r   r   r   s     rd   __rpow__z_mpf.__rpow__   .    a  HAvrf   c                 L    |                      |          }|t          u r|S || z  S r`   r   r   s     rd   __rmod__z_mpf.__rmod__   .    a  H1urf   c                 6    | j                             |           S r`   )rw   sqrtr   s    rd   r   z	_mpf.sqrt   s    y~~a   rf   Nc                 <    | j                             | |||          S r`   rw   almosteqr   r   rel_epsabs_epss       rd   aez_mpf.ae       y!!!Q999rf   c                 ,    t          | j        |          S r`   )r7   ro   )r   rq   s     rd   r7   z_mpf.to_fixed   s    
D)))rf   c                 6    t          t          |           g|R  S r`   )roundr   )r   argss     rd   	__round__z_mpf.__round__   s    U4[[(4((((rf   NN)0rg   rh   ri   rj   rk   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  rl   rf   rd   rn   rn   '   sn        
 	I ! ! ! !F = = [="   [   [ h3344G
(--
.
.C
(--
.
.C	,,	-	-B8%%&&D82233D!!I:::@@@E E E
 BAA---///111OOO000///H            100............  	 	 		 	 	    ! ! !: : : :* * *) ) ) ) )rf   rn   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                    t           }|                    d|          }|                    d|          }|                    d|          }|                    d|           }i }t          |t                      |           ||          S )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         rd   	binary_opr    sw    D<<h//D<<h//D<<h//D<<$''D	B	$		2d8Orf   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                   >    e Zd ZdZddZd	dZed             Zd ZdS )
	_constantzRepresents a mathematical constant with dynamic precision.
    When printed or used in an arithmetic operation, a constant
    is converted to a regular mpf at the working precision. A
    regular mpf can also be obtained using the operation +x.r  c                     t                               |           }||_        ||_        t	          t
          |d          |_        |S )Nr  )objectre   r  r   getattrr\   rj   )rb   r   r  docnamer   s        rd   re   z_constant.__new__P  s9    NN3M7B77	rf   Nc                     | j         j        \  }}|s|}|s|}|rt          |          }| j                             |                     ||                    S r`   )rw   rx   r   r   r   )r   rq   rr   rs   prec2	rounding2s         rd   __call__z_constant.__call__W  s[    <6y!ET-I'{3''|$$TYYtX%>%>???rf   c                 L    | j         j        \  }}|                     ||          S r`   )rw   rx   r   )r   rq   rs   s      rd   ro   z_constant._mpf_^  s$    4hyyx(((rf   c                 b    d| j         d| j                             | d                    dS )N<z:    )rr   z~>)r  rw   nstrr   s    rd   r   z_constant.__repr__c  s5     "iii):):44B<<<)H)H)H)HIIrf   )r  )NNN)	rg   rh   ri   rj   re   r-  r  ro   r   rl   rf   rd   r%  r%  J  s{        @ @
   @ @ @ @ ) ) X)J J J J Jrf   r%  c                      e Zd ZdZdgZd!dZ ed           Z ed           Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZeZd Zed             Zd Zd Zd ZeZeZeZeZd Zd Zd Zd Z d Z!eZ"d Z#d Z$d Z%d Z&e Z'e%Z(d"d Z)dS )#_mpcz
    An mpc represents a complex number using a pair of mpf:s (one
    for the real part and another for the imaginary part.) The mpc
    class behaves fairly similarly to Python's complex type.
    _mpc_ru   c                 L   t                               |           }t          |t                    r|j        |j        }}nt          |d          r|j        |_        |S | j        	                    |          }| j        	                    |          }|j
        |j
        f|_        |S )Nr5  )r'  re   r   r   r  r  r   r5  rw   mpfro   )rb   r  r  r   s       rd   re   z_mpc.__new__p  s    NN3dM** 	DI$DDT7## 	jAGH{t$${t$$:tz*rf   c                 L    | j                             | j        d                   S )Nru   rw   r   r5  r   s    rd   r   z_mpc.<lambda>|      !6!6tz!}!E!E rf   c                 L    | j                             | j        d                   S r   r9  r   s    rd   r   z_mpc.<lambda>}  r:  rf   c                 j    t          | j        d                   t          | j        d                   fS Nru   r   )r   r5  r   s    rd   r   z_mpc.__getstate__  s)    4:a=));tz!}+E+EEErf   c                 d    t          |d                   t          |d                   f| _        d S r=  )r   r5  r   s     rd   r   z_mpc.__setstate__  s*    "3q6**M#a&,A,AA


rf   c                     | j         j        rt          |           S t          | j                  dd         }t          | j                  dd         }t          |           j        d|d|dS )Nrv   z(real=z, imag=))rw   r   r   r   r  r  rz   rg   )r   ris      rd   r   z_mpc.__repr__  sj    9 	q66MLL2LL2)-a)9)9)9111aaa@@rf   c                 F    dt          | j        | j        j                  z  S )Nz(%s))r8   r5  rw   r   r   s    rd   r   z_mpc.__str__  s    
17AI,ABBBBrf   c                 N    t          | j        | j        j        d                   S r   )r9   r5  rw   rx   r   s    rd   r   z_mpc.__complex__  s!    ag19+CA+FGGGGrf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )r   r;   r5  r   s         rd   r   z_mpc.__pos__  r   rf   c                     | j         j        \  }}t          | j         j                  }t	          | j        ||          |_        |S r`   )rw   rx   r{   r7  r?   r5  ro   )r   rq   rs   r   s       rd   r   z_mpc.__abs__  s;    1h	!'422rf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )r   r=   r5  r   s         rd   r   z_mpc.__neg__  r   rf   c                 n    | j         \  }}\  }} ||          }t          | j        ||          |_        |S r`   )r   r>   r5  r   s         rd   r  z_mpc.conjugate  s<    %&Z"S"4CHHx88rf   c                 *    t          | j                  S r`   )r<   r5  r   s    rd   r   z_mpc.__nonzero__  s    ag&&&rf   c                 *    t          | j                  S r`   )r:   r5  r   s    rd   r   z_mpc.__hash__  s       rf   c                 j    	 | j                             |          }|S # t          $ r
 t          cY S w xY wr`   )rw   r   r   r   )rb   r   ys      rd   mpc_convert_lhsz_mpc.mpc_convert_lhs  sH    	"##A&&AH 	" 	" 	"!!!!	"s    22c                     t          |d          s7t          |t                    rdS |                     |          }|t          u r|S | j        |j        k    o| j        |j        k    S )Nr5  F)r   r   r   rN  r   r  r  r   s     rd   r   z_mpc.__eq__  sk    q'"" 	!S!! u!!!$$AN""v4AFaf$44rf   c                 H    |                      |          }|t          u r|S | S r`   r   )r   r   r   s      rd   r   z_mpc.__ne__  r   rf   c                       t          d          )Nz3no ordering relation is defined for complex numbers)r   )r  s    rd   _comparez_mpc._compare  s    MNNNrf   c                 V   | j         \  }}\  }}t          |d          s^|                     |          }|t          u r|S t          |d          r. ||          }t	          | j        |j        ||          |_        |S  ||          }t          | j        |j        ||          |_        |S Nr5  ro   )r   r   rN  r   rA   r5  ro   r@   r   s          rd   r  z_mpc.__add__      %&Z"S"4q'"" 	!!!$$AN""q'"" CHH%agqwhGGCHH!'17D(;;rf   c                 V   | j         \  }}\  }}t          |d          s^|                     |          }|t          u r|S t          |d          r. ||          }t	          | j        |j        ||          |_        |S  ||          }t          | j        |j        ||          |_        |S rT  )r   r   rN  r   rC   r5  ro   rB   r   s          rd   r  z_mpc.__sub__  rU  rf   c                    | j         \  }}\  }}t          |d          st          |t                    r) ||          }t	          | j        |||          |_        |S |                     |          }|t          u r|S t          |d          r. ||          }t          | j        |j	        ||          |_        |S |                     |          } ||          }t          | j        |j        ||          |_        |S rT  )r   r   r   r   rF   r5  rN  r   rE   ro   rD   r   s          rd   r   z_mpc.__mul__  s    %&Z"S"4q'"" 	%!Y'' CHH%agq$AA!!!$$AN""q'"" CHH%agqwhGG!!!$$ACHH!'17D(;;rf   c                 V   | j         \  }}\  }}t          |d          s^|                     |          }|t          u r|S t          |d          r. ||          }t	          | j        |j        ||          |_        |S  ||          }t          | j        |j        ||          |_        |S rT  )r   r   rN  r   rH   r5  ro   rG   r   s          rd   r!  z_mpc.__div__   rU  rf   c                    | j         \  }}\  }}t          |t                    r) ||          }t          | j        |||          |_        |S |                     |          }|t          u r|S  ||          }t          |d          r"t          | j        |j	        ||          |_        n!t          | j        |j        ||          |_        |S r   )r   r   r   rK   r5  rN  r   r   rJ   ro   rI   r   s          rd   r#  z_mpc.__pow__  s    %&Z"S"4a## 	CA!!'1dH==AGHa  HCHH1g 	@!!'17D(CCAGGagqwh??AGrf   c                 L    |                      |          }|t          u r|S || z
  S r`   rN  r   r   s     rd   r   z_mpc.__rsub__   r   rf   c                     | j         \  }}\  }}t          |t                    r) ||          }t          | j        |||          |_        |S |                     |          }|t          u r|S || z  S r`   )r   r   r   rF   r5  rN  r   r   s          rd   __rmul__z_mpc.__rmul__&  s|    %&Z"S"4a## 	CA!!'1dH==AGHa  H1urf   c                 L    |                      |          }|t          u r|S || z  S r`   r[  r   s     rd   r   z_mpc.__rdiv__1  r   rf   c                 L    |                      |          }|t          u r|S || z  S r`   r[  r   s     rd   r   z_mpc.__rpow__7  r   rf   Nc                 <    | j                             | |||          S r`   r   r   s       rd   r  z_mpc.ae@  r  rf   )ru   ru   r	  )*rg   rh   ri   rj   rk   re   r  r  r  r   r   r   r   r   r   r   r   r  r   r  r   r
  rN  r   r   rR  r   r   r   r  r  r   r!  r#  __radd__r   r]  r   r   __truediv____rtruediv__r  rl   rf   rd   r4  r4  g  s-         	I
 
 
 
 8EEFFD8EEFFDF F FB B BA A AC C CH H H        ' ' ' H! ! ! " " ["5 5 5  O O O FFFF      &      H  	 	 	     KL: : : : : :rf   r4  c                       e Zd Zd Zd Zd Zd Zd Zd Z e	d e          Z
 e	d e          Zdd
Zd Zd Zd Zd ZddZddZddZddZed             Zd Zd Zd ZdS )PythonMPContextc                    dt           g| _        t          dt          fi           | _        t          dt
          fi           | _        | j        t          | j        g| j        _        | j        t          | j        g| j        _        | | j        _	        | | j        _	        t          dt          fi           | _        | j        t          | j        g| j        _        | | j        _	        d S )N5   r7  r   r   )r   rx   rz   rn   r7  r4  r   r{   r   rw   r%  r   ctxs    rd   __init__zPythonMPContext.__init__I  s     -0utgr**utgr**GS#*<=GS#*<=Jb99!$#s/A B"rf   c                 <    t          | j                  }||_        |S r`   )r{   r7  ro   ri  r   r   s      rd   r   zPythonMPContext.make_mpfU      LLrf   c                 <    t          | j                  }||_        |S r`   )r{   r   r5  rl  s      rd   make_mpczPythonMPContext.make_mpcZ  rm  rf   c                 D    dx| _         | j        d<   d| _        d| _        d S )Nrg  ru   r1  F)_precrx   _dpstrap_complexrh  s    rd   defaultzPythonMPContext.default_  s+    ,..	C&q) rf   c                     t          dt          |                    x| _        | j        d<   t	          |          | _        d S )Nr   ru   )maxr   rq  rx   r   rr  ri  ns     rd   	_set_preczPythonMPContext._set_precd  s5    ,/3q66NN:	C&q)q>>rf   c                     t          |          x| _        | j        d<   t          dt	          |                    | _        d S r=  )r   rq  rx   rv  r   rr  rw  s     rd   _set_dpszPythonMPContext._set_dpsh  s5    ,7NN:	C&q)q#a&&>>rf   c                     | j         S r`   )rq  rh  s    rd   r   zPythonMPContext.<lambda>l  s    	 rf   c                     | j         S r`   )rr  rh  s    rd   r   zPythonMPContext.<lambda>m  s    sx rf   Tc                    t          |          | j        v r|S t          |t                    r"|                     t          |                    S t          |t                    r"|                     t          |                    S t          |t                    r;| 	                    t          |j
                  t          |j                  f          S t          |          j        dk    r|                     |          S t          |t          j                  rAt!          j        t%          |j                  t%          |j                            }n#  Y nxY w| j        \  }}t          |t           j                  r.|j        \  }}|                     t/          |||                    S |rLt          |t0                    r7	 t3          |||          }|                     |          S # t4          $ r Y nw xY wt7          |d          r|                     |j                  S t7          |d          r| 	                    |j                  S t7          |d          r)|                     |                    ||                    S t          |          j        dk    r+|                     tA          |||                    S #  Y nxY w| !                    ||          S )a  
        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')

        numpyro   r5  r   decimal)"rz   typesr   r   r   r   r   r   r   ro  r  r  rh   	npconvertnumbersRationalr[   r   r   	numeratordenominatorrx   r   r   r   r   r~   r   ro   r5  r   r   r   _convert_fallback)ri  r   stringsrq   rs   r   r   ro   s           rd   r   zPythonMPContext.converto  s   , 77cia##ECLL!,E,E%EaCZ]](C(C!Ca!! 	J<<AF!3!3Z5G5G HIII77((q1A1A*Aa)** 	\#ak"2"2C4F4FGGDD+ha&& 	;7DAq<<aD 9 9::: 	z!Z00 	 D(33||E***   1g<s||AG'<'< <1g<s||AG'<'< <1j!! 	;;;qzz$99:::77**\!T8%D%DEEEDD$$Q000s*   9E E	%G/ /
G<;G<$#K Kc                    ddl }t          ||j                  r/|                     t	          t          |                              S t          ||j                  r"|                     t          |                    S t          ||j                  r;| 	                    t          |j
                  t          |j                  f          S t          dt          |          z             )z^
        Converts *x* to an ``mpf`` or ``mpc``. *x* should be a numpy
        scalar.
        ru   Nr   )r  r   integerr   r   r   floatingr   complexfloatingro  r  r  r   r   )ri  r   r  s      rd   r  zPythonMPContext.npconvert  s    
 	a$$KS\\(3q66:J:J-K-K&Ka%%Kcll<??.K.K'Ka+,, 	N<<af!5!5|AF7K7K LMMM1DGG;<<<rf   c                    t          |d          r|j        t          k    S t          |d          rt          |j        v S t	          |t
                    st	          |t          j                  rdS |                     |          }t          |d          st          |d          r| 	                    |          S t          d          )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

        ro   r5  Fzisnan() needs a number as input)r   ro   r!   r5  r   r   r[   r   r   isnanr   )ri  r   s     rd   r  zPythonMPContext.isnan  s    " 1g 	#7d?"1g 	#17?"a## 	z!X\'B'B 	5KKNN1g 	 '!W"5"5 	 99Q<<9:::rf   c                    t          |d          r|j        t          t          fv S t          |d          r*|j        \  }}|t          t          fv p|t          t          fv S t          |t                    st          |t          j                  rdS | 	                    |          }t          |d          st          |d          r| 
                    |          S t          d          )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

        ro   r5  Fzisinf() needs a number as input)r   ro   r   r    r5  r   r   r[   r   r   isinfr   )ri  r   reims       rd   r  zPythonMPContext.isinf  s    ( 1g 	,7tUm++1g 	>WFB$&="u*==a## 	z!X\'B'B 	5KKNN1g 	 '!W"5"5 	 99Q<<9:::rf   c                 H   t          |d          rt          |j        d                   S t          |d          rR|j        \  }}t          |d                   }t          |d                   }|t          k    r|S |t          k    r|S |o|S t          |t                    st          |t          j                  rt          |          S | 	                    |          }t          |d          st          |d          r| 
                    |          S t          d          )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
        ro   r   r5  z"isnormal() needs a number as input)r   boolro   r5  r   r   r   r[   r   r   isnormalr   )ri  r   r  r  	re_normal	im_normals         rd   r  zPythonMPContext.isnormal  s   0 1g 	$
###1g 	+WFBRUIRUIU{{9,U{{9,**a## 	z!X\'B'B 	77NKKNN1g 	#'!W"5"5 	#<<??"<===rf   Fc                 |   t          |t                    rdS t          |d          r.|j        x\  }}}}}t	          |r|dk    p
|t
          k              S t          |d          rQ|j        \  }}	|\  }
}}}|	\  }}}}|r|dk    p
|t
          k    }|r|r|dk    p
|	t
          k    }|o|S |o
|	t
          k    S t          |t          j                  r|j	        \  }}||z  dk    S | 
                    |          }t          |d          st          |d          r|                     ||          S t          d          )a
  
        Return *True* if *x* is integer-valued; otherwise return
        *False*::

            >>> from mpmath import *
            >>> isint(3)
            True
            >>> isint(mpf(3))
            True
            >>> isint(3.2)
            False
            >>> isint(inf)
            False

        Optionally, Gaussian integers can be checked for::

            >>> isint(3+0j)
            True
            >>> isint(3+2j)
            False
            >>> isint(3+2j, gaussian=True)
            True

        Tro   ru   r5  zisint() needs a number as input)r   r   r   ro   r  r   r5  r[   r   r   r   isintr   )ri  r   gaussianr   r   r   r   xvalr  r  rsignrmanrexprbcisignimaniexpibcre_isintim_isintr   r   s                         rd   r  zPythonMPContext.isint  sm   2 a## 	41g 	=()/D#sB);dem<<<1g 	,WFB%'"E4s%'"E4s*:rU{H - .TQY>2;,H,+e+a&& 	7DAqq5A:KKNN1g 	*'!W"5"5 	*99Q)))9:::rf   c                    | j         \  }}g }g }|D ]}dx}	}
t          |d          r|j        }	njt          |d          r|j        \  }	}
nO|                     |          }t          |d          r|j        }	n"t          |d          r|j        \  }	}
nt
          |
r|r|rG|                    t          |	|	                     |                    t          |
|
                     t          |	|
fd|dz             \  }	}
|                    |	           |                    |
           |r'|                    t          |	|
f|                     D|                    |	           |                    |
           p|rt          |	|	          }	n|rt          |	          }	|                    |	           t          ||||          }|r'|                     |t          |||          f          }n|                     |          }|S )aX  
        Calculates a sum containing a finite number of terms (for infinite
        series, see :func:`~mpmath.nsum`). The terms will be converted to
        mpmath numbers. For len(terms) > 2, this function is generally
        faster and produces more accurate results than the builtin
        Python function :func:`sum`.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fsum([1, 2, 0.5, 7])
            mpf('10.5')

        With squared=True each term is squared, and with absolute=True
        the absolute value of each term is used.
        ru   ro   r5  rt   
   )rx   r   ro   r5  r   ra   appendr'   rK   r?   r"   r5   ro  r   )ri  termsabsolutesquaredrq   r   r  r  termrevalimvalr   s               rd   fsumzPythonMPContext.fsum@  s;     &	c !	# !	#DEEtW%% .
w'' 	.#zuu{{4((4)) . JEET7++ .#':LE55-- # ' +GE%$8$8999GE%$8$89999'2E%=47'K'KuE***E**** 'KKut < <====KK&&&KK&&&& +#E511EE +#ENNEE""""D$X.. 	 atS!9!9:;;AAQArf   Nc           	         |t          ||          }| j        \  }}g }g }t          }| j        | j        f}	|D ]H\  }
}t          |
          |	vr|                     |
          }
t          |          |	vr|                     |          } ||
d          } ||d          }|r0|r.|                    t          |
j	        |j	                              ||
d          } ||d          }|rl|rj|
j	        }|j
        \  }}|rt          |          }|                    t          ||                     |                    t          ||                     "|r[|rY|
j
        \  }}|j	        }|                    t          ||                     |                    t          ||                     |r|r|
j
        \  }}|j
        \  }}|rt          |          }|                    t          ||                     |                    t          t          ||                               |                    t          ||                     |                    t          ||                     Ct          t          |||          }|r'|                     |t          |||          f          }n|                     |          }|S )a.  
        Computes the dot product of the iterables `A` and `B`,

        .. math ::

            \sum_{k=0} A_k B_k.

        Alternatively, :func:`~mpmath.fdot` accepts a single iterable of pairs.
        In other words, ``fdot(A,B)`` and ``fdot(zip(A,B))`` are equivalent.
        The elements are automatically converted to mpmath numbers.

        With ``conjugate=True``, the elements in the second vector
        will be conjugated:

        .. math ::

            \sum_{k=0} A_k \overline{B_k}

        **Examples**

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> A = [2, 1.5, 3]
            >>> B = [1, -1, 2]
            >>> fdot(A, B)
            mpf('6.5')
            >>> list(zip(A, B))
            [(2, 1), (1.5, -1), (3, 2)]
            >>> fdot(_)
            mpf('6.5')
            >>> A = [2, 1.5, 3j]
            >>> B = [1+j, 3, -1-j]
            >>> fdot(A, B)
            mpc(real='9.5', imag='-1.0')
            >>> fdot(A, B, conjugate=True)
            mpc(real='3.5', imag='-5.0')

        Nro   r5  )ziprx   r   r7  r   rz   r   r  r'   ro   r5  r$   ra   r5   ro  r   )ri  ABr  rq   r   r  r  hasattr_r  r   r   a_realb_real	a_complex	b_complexavalbrebimareaimbvalr   s                          rd   fdotzPythonMPContext.fdot|  s   N =Aq		A&	c#'" !	* !	*DAqAwwe##QQAwwe##QQXa))FXa))F & GAGQW55666 G,,I G,,I *) *w7S '!#,,CGD#..///GD#..//// *I *7SwGC..///GC..//// *y *7S7S '!#,,CGC--...GGC$5$566777GC--...GC--....))D$$$ 	 atS!9!9:;;AAQArf   <no doc>c                       fd}j         dd         t          j                            d|z            |_        |S )aO  
        Given a low-level mpf_ function, and optionally similar functions
        for mpc_ and mpi_, defines the function as a context method.

        It is assumed that the return type is the same as that of
        the input; the exception is that propagation from mpf to mpc is possible
        by raising ComplexResult.

        c                    t          |           j        vr                    |           } j        \  }}|rE|                    d|          }d|v rt          |d                   }|                    d|          }t          | d          rj	                      | j        ||                    S # t          $ r7 j
        r                      | j        t          f||                    cY S w xY wt          | d          r%                     | j        ||                    S t          dt          |                     )Nrq   rr   rs   ro   r5  z of a )rz   r  r   rx   ry   r   r   r   ro   r   rs  ro  r   r5  ra   )r   r   rq   rs   ri  mpc_fmpf_fr  s       rd   fz/PythonMPContext._wrap_libmp_function.<locals>.f  sd   Awwci''KKNN /ND( <zz&$//F??&ve}55D!::j(;;q'"" 	DQ<<agtX(F(FGGG$ Q Q Q' <<qw.>h(O(OPPPPP	Q
 G$$ D||EE!'4$B$BCCC%dddDGGG&DEEEs   $B4 4>C54C5rv   NzComputes the %s of x)rg   r\   __dict__ry   rj   )ri  r  r  mpi_fdocr  r  s   ```   @rd   _wrap_libmp_functionz$PythonMPContext._wrap_libmp_function  sm    	F 	F 	F 	F 	F 	F 	F 	F( ~abb!!*..t5Kc5QRR	rf   c                     |rfd}n}t           j                            |j                  |_        t	          | ||           d S )Nc                     | j         fd|D             }| j        }	 | xj        dz  c_         | g|R i |}|| _        n# || _        w xY w|
 S )Nc                 &    g | ]} |          S rl   rl   ).0r   r   s     rd   
<listcomp>zDPythonMPContext._wrap_specfun.<locals>.f_wrapped.<locals>.<listcomp>  s!    111q

111rf   r  )r   rq   )ri  r  r   rq   retvalr   r  s        @rd   	f_wrappedz0PythonMPContext._wrap_specfun.<locals>.f_wrapped  s}    +1111D111x$HHNHHQs4T444V44F#CHHtCHOOOOws   A 	A)r\   r  ry   rj   setattr)rb   r  r  wrapr  s     `  rd   _wrap_specfunzPythonMPContext._wrap_specfun  se     		 	 	 	 	 	 I)266tQYGG	T9%%%%%rf   c                    t          |d          r|j        \  }}|t          k    r|dfS nHt          |d          r	|j        }n/t	          |          t
          v rt          |          dfS d }t          |t                    r|\  }}njt          |d          r|j	        \  }}nOt          |t                    r:d|v r6|                    d          \  }}t          |          }t          |          }|$||z  s||z  dfS |                     ||          dfS |                     |          }t          |d          r|j        \  }}|t          k    r|dfS nt          |d          r|j        }n|dfS |\  }}}}	|rq|d	k    rR|r| }|d
k    rt          |          |z  dfS |d	k    r-t          |          d| z  }}|                     ||          dfS |                     |          }|dfS |sdS |dfS )Nr5  Cro   Zr   /QUru   r   R)ru   r  )r   r5  r   ro   rz   r   r   r   r|   r   r   splitr   r   r   )
ri  r   r   r  r   r   r   r   r   r   s
             rd   _convert_paramzPythonMPContext._convert_param  sB   1g 	GEArU{{#v Q   	AAAww)##1vvs{"A!U## 11G$$ w11Az** saxxwws||1FFFF}1u '63;&wwq||S((AAq'"" 2;;c6M G$$ G#vc3 	byy $C!88s88s?C//"99s88a3$iqA771Q<<,,QAc6M 	6c6Mrf   c                     |\  }}}}|r||z   S |t           k    r| j        S |t          k    s|t          k    r| j        S | j        S r`   )r   ninfr   r    infnan)ri  r   r   r   r   r   s         rd   _mpf_magzPythonMPContext._mpf_mag9  sP    c3 	r6M::8O99U

7Nwrf   c                 Z   t          |d          r|                     |j                  S t          |d          r|j        \  }}|t          k    r|                     |          S |t          k    r|                     |          S dt          |                     |          |                     |                    z   S t          |t                    r%|rt          t          |                    S | j
        S t          |t          j                  rB|j        \  }}|r/dt          t          |                    z   t          |          z
  S | j
        S |                     |          }t          |d          st          |d          r|                     |          S t!          d          )a  
        Quick logarithmic magnitude estimate of a number. Returns an
        integer or infinity `m` such that `|x| <= 2^m`. It is not
        guaranteed that `m` is an optimal bound, but it will never
        be too large by more than 2 (and probably not more than 1).

        **Examples**

            >>> from mpmath import *
            >>> mp.pretty = True
            >>> mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2)))
            (4, 4, 4, 4)
            >>> mag(10j), mag(10+10j)
            (4, 5)
            >>> mag(0.01), int(ceil(log(0.01,2)))
            (-6, -6)
            >>> mag(0), mag(inf), mag(-inf), mag(nan)
            (-inf, +inf, +inf, nan)

        ro   r5  r   zrequires an mpf/mpc)r   r  ro   r5  r   rv  r   r   r6   absr  r[   r   r   r   magr   )ri  r   rB  rC  r   r   s         rd   r  zPythonMPContext.magC  sz   * 1g 	7<<(((Q   	77DAqEzz||A&Ezz||A&Sa#,,q//::::9%% 	7 (A'''8O8<(( 
	77DAq :8CFF+++hqkk998OAAq'"" 7ga&9&9 7wwqzz! 5666rf   )T)F)FF)NF)NNr  )rg   rh   ri   rj  r   ro  rt  ry  r{  r  rq   rr   r   r  r  r  r  r  r  r  r  r
  r  r  r  r  rl   rf   rd   re  re  G  s       
# 
# 
#  
  
! ! !
" " "" " " 8))955D
(''
2
2C01 01 01 01d
= 
= 
=; ; ;8; ; ;@&> &> &>P-; -; -; -;^: : : :xU U U Un       F & & [&"/ / /b  ,7 ,7 ,7 ,7 ,7rf   re  ru   N)r  r  r  )}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   r  r[   r\   r'  re   r{   r^   rn   r  
return_mpf
return_mpcmpf_pow_samer  r   r  r  r   r!  r"  r#  ra  r]  rb  r   rc  r%  r4  r   r   re  r  ComplexregisterRealImportErrorrl   rf   rd   <module>r     s   - , , , , , , ,                                                                                                                                                                                 .            n" " " " " " " "C) C) C) C) C)9 C) C) C)J< =
<

 zz:::    i*9; ;
 y/*<:ZG3j@B B
 y/*<:ZG8:EG G
 y/*<4zA3j@B B
 y/*<:ZG3j@B B
 y/*<:ZG13 3
 y4zA8:EG G
 < M J J J J J J J J:Z: Z: Z: Z: Z:9 Z: Z: Z:z $h7 h7 h7 h7 h7f h7 h7 h7b	NNNOT"""L$ 	 	 	DD	s   8I II