
<Zc           @   s=  d  Z  d d l 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. d d l/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 d d l8 m9 Z9 m: Z: m; Z; m< Z< d   Z= e e f Z> e e f Z? d   Z@ d   ZA d	   ZB d
   ZC d   ZD d   ZE d d  ZF d d  ZG d   ZH d   ZI d   ZJ d d  ZK d d  ZL d   ZM d   ZN d d  ZO d d  ZP d   ZQ d   ZR d   ZS d   ZT d   ZU d   ZV d   ZW d    ZX d!   ZY d"   ZZ d#   Z[ d$   Z\ d%   Z] d&   Z^ d'   Z_ d(   Z` d)   Za d*   Zb ec d+ d, d- d.  Zd d/   Ze d0   Zf d d1  Zg d2   Zh d3   Zi d4   Zj d5   Zk d6   Zl d7   Zm d8   Zn d9   Zo d:   Zp d;   Zq d<   Zr d=   Zs d>   Zt d?   Zu d@   Zv e dA  Zw e dB  Zx ew ex f Zy e dC  Zz e dD  Z{ dE   Z| d dF  Z} d dG  Z~ dH   Z dI   Z dJ   Z dK   Z dL   Z dM   Z dN S(O   s3   
Computational functions for interval arithmetic.

i   (   t   xrange(+   t   ComplexResultt
   round_downt   round_upt   round_floort   round_ceilingt   round_nearestt   prec_to_dpst   repr_dpst   dps_to_prect   bitcountt
   from_floatt   fnant   finft   fninft   fzerot   fhalft   fonet   fnonet   mpf_signt   mpf_ltt   mpf_let   mpf_gtt   mpf_get   mpf_eqt   mpf_cmpt   mpf_min_maxt	   mpf_floort   from_intt   to_intt   to_strt   from_strt   mpf_abst   mpf_negt   mpf_post   mpf_addt   mpf_subt   mpf_mult   mpf_mul_intt   mpf_divt	   mpf_shiftt   mpf_pow_intt   from_man_expt   MPZ_ONE(   t   mpf_logt   mpf_expt   mpf_sqrtt   mpf_atant	   mpf_atan2t   mpf_pit   mod_pi2t   mpf_cos_sin(   t	   mpf_gammat
   mpf_rgammat   mpf_loggammat   mpc_loggammac         C   s<   |  \ } } t  |  d } d t | |  t | |  f S(   Ni   s   [%s, %s](   R   R   (   t   st   prect   sat   sbt   dps(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_str   s    c         C   s
   |  | k S(   N(    (   R8   t   t(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_eq)   s    c         C   s
   |  | k S(   N(    (   R8   R>   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_ne,   s    c         C   sB   |  \ } } | \ } } t  | |  r+ t St | |  r> t Sd  S(   N(   R   t   TrueR   t   Falset   None(   R8   R>   R:   R;   t   tat   tb(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_lt/   s      c         C   sB   |  \ } } | \ } } t  | |  r+ t St | |  r> t Sd  S(   N(   R   RA   R   RB   RC   (   R8   R>   R:   R;   RD   RE   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_le6   s      c         C   s   t  | |   S(   N(   RF   (   R8   R>   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_gt=   s    c         C   s   t  | |   S(   N(   RG   (   R8   R>   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_ge>   s    i    c   	      C   sv   |  \ } } | \ } } t  | | | t  } t  | | | t  } | t k rW t } n  | t k rl t } n  | | f S(   N(   R#   R   R   R   R   R   (	   R8   R>   R9   R:   R;   RD   RE   t   at   b(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_add@   s     	 	c   	      C   sv   |  \ } } | \ } } t  | | | t  } t  | | | t  } | t k rW t } n  | t k rl t } n  | | f S(   N(   R$   R   R   R   R   R   (	   R8   R>   R9   R:   R;   RD   RE   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_subI   s     	 	c         C   s   |  \ } } t  | | | t  S(   N(   R$   R   (   R8   R9   R:   R;   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt	   mpi_deltaR   s    c         C   s(   |  \ } } t  t | | | t  d  S(   Ni(   R(   R#   R   (   R8   R9   R:   R;   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_midV   s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R"   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_posZ   s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R!   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_neg`   s    c   	      C   s   |  \ } } t  |  } t  |  } | d k rW t | | t  } t | | t  } n{ | d k r t } t |  } t | |  r t | | t  } q t | | t  } n$ t | | t  } t | | t  } | | f S(   Ni    (   R   R"   R   R   R   R!   R   (	   R8   R9   R:   R;   t   sast   sbsRJ   RK   t   negsa(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_absf   s    c         C   s   t  |  | | f |  S(   N(   t   mpi_mul(   R8   R>   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_mul_mpf}   s    c         C   s   t  |  | | f |  S(   N(   t   mpi_div(   R8   R>   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_div_mpf   s    c         C   s  |  \ } } | \ } } t  |  } t  |  } t  |  }	 t  |  }
 | | k o_ d k n r | t k s| | t k r t t f St t f S|	 |
 k o d k n r | t k s | t k r t t f St t f S| d k r|	 d k rGt | | | t  } t | | | t  } | t k r/t } n  | t k rt } qq|
 d k rt | | | t  } t | | | t  } | t k rt } n  | t k rt } qqt | | | t  } t | | | t  } | t k rt } n  | t k rt } qn| d k r*|	 d k rpt | | | t  } t | | | t  } | t k rXt } n  | t k r't } q'q|
 d k rt | | | t  } t | | | t  } | t k rt } n  | t k r't } q'qt | | | t  } t | | | t  } | t k rt } n  | t k rt } qn t | |  t | |  t | |  t | |  g } t | k r|t t } } n6 t |  \ } } t	 | | t  } t	 | | t  } | | f S(   Ni    (
   R   R   R   R   R%   R   R   R   R   R"   (   R8   R>   R9   R:   R;   RD   RE   RR   RS   t   tast   tbsRJ   RK   t   cases(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyRV      s~    



 	  	  	  	  	  	 6c         C   s   |  \ } } t  | t  rH t | | | t  } t | | | t  } n{ t | t  r t | | | t  } t | | | t  } n? t |  } t | | g  \ } } t } t | | | t  } | | f S(   N(   R   R   R%   R   R   R   R!   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt
   mpi_square   s    c         C   s  |  \ } } | \ } } t  |  } t  |  } t  |  }	 t  |  }
 | | k o_ d k n r |	 d k  r| |
 d k s |	 d k s |
 d k r t t f St t f S|	 d k  r |
 d k r t t f S|	 d k  r t t |   t |  |  S|	 d k r| d k  r | d k r t t f S|	 |
 k r6t t f S| d k r`t | | | t  } t } n  | d k rt } t | | | t  } qn| d k rt | | | t  } t | | | t  } | t	 k rt } n  | t	 k rt } qn | d k rSt | | | t  } t | | | t  } | t	 k r;t } n  | t	 k rt } qnT t | | | t  } t | | | t  } | t	 k rt } n  | t	 k rt } n  | | f S(   Ni    (
   R   R   R   R   RX   RQ   R'   R   R   R   (   R8   R>   R9   R:   R;   RD   RE   RR   RS   RZ   R[   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyRX      s\    0




	 	  	  	 	c         C   s(   t  |  t  } t  |  t  } | | f S(   N(   R1   R   R   (   R9   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_pi  s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R-   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_exp  s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R,   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_log  s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R.   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_sqrt$  s    c         C   s:   |  \ } } t  | | t  } t  | | t  } | | f S(   N(   R/   R   R   (   R8   R9   R:   R;   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_atan+  s    c   	      C   s  |  \ } } | d k  r? t  t t f t |  | | d  |  S| d k rU t t f S| d k re |  S| d k r~ t |  |  S| d @r t | | | t  } t | | | t  } n t |  } t |  } | d k rt | | | t  } t | | | t  } n | d k r?t | | | t  } t | | | t  } nN t } t	 |  } t
 | |  rxt | | | t  } n t | | | t  } | | f S(   Ni    i   i   i   (   RX   R   t   mpi_pow_intR]   R)   R   R   R   R   R!   R   (	   R8   t   nR9   R:   R;   RJ   RK   RR   RS   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyRc   1  s4    '

c         C   s   | \ } } | | k rt | t  t f k rt | t t |   k rX t |  t |  |  S| t k rt t |  |  Sn  t |  | d  } t | | | d  } t	 | |  S(   Ni   (
   R   R   R   R   Rc   R   Ra   R`   RV   R_   (   R8   R>   R9   RD   RE   t   ut   v(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_powV  s    c         C   s   t  |  |  r |  S| S(   N(   R   (   t   xt   y(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   MINa  s    c         C   s   t  |  |  r |  S| S(   N(   R   (   Rh   Ri   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   MAXf  s    c         C   s   |  \ } } } } |  t  k r+ t t  d f St |  |  \ } } t | | | | d  \ } }	 }
 | ru d |	 }	 n  | | |	 f S(   Ni    i   i(   R   R   R3   R2   (   Rh   t   wpt   signt   mant   expt   bct   cR8   R>   Rd   t   wp_(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   cos_sin_quadrantk  s    "c            s6  |  \ } } | | k o# t  k n r> t t f t  t  f f St |  k sV t |  k rl t t f t t f f S d } t | |  \ } } } t | |  \ } }	 }
 t | | g  \ } } t | |	 g  \ } }	 | |
 k r n |
 | d k rt t f t t f f S| d |
 d k r(t } n  | d d |
 d d k rMt } n  | d d |
 d d k rrt }	 n  | d d |
 d d k rt } n  t t | >t d >|   t t | >t d >|        f d   } | | t	  } | | t
  } | | t	  } | |	 t
  }	 | | f | |	 f f S(   Ni   i   i   i   i   i
   c            st   t  |  d  | t k k r%  } n   } t |  |  |  }  |  \ } } } } | | d k rp | rl t St S|  S(   Ni    i   (   t   boolR   R%   R   R   (   Rf   t   roundingt   pRm   Rn   Ro   Rp   (   t   lesst   moreR9   (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   finalize  s    	(   R   R   R   R   R   Rs   R   R*   R+   R   R   (   Rh   R9   RJ   RK   Rl   t   caR:   t   nat   cbR;   t   nbRy   (    (   Rw   Rx   R9   s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_cos_sinv  s<    
				c         C   s   t  |  |  d S(   Ni    (   R~   (   Rh   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_cos  s    c         C   s   t  |  |  d S(   Ni   (   R~   (   Rh   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_sin  s    c         C   s)   t  |  | d  \ } } t | | |  S(   Ni   (   R~   RX   (   Rh   R9   t   cost   sin(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_tan  s    c         C   s)   t  |  | d  \ } } t | | |  S(   Ni   (   R~   RX   (   Rh   R9   R   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_cot  s    c   	      C   s   | d } t  |  | t  } t  |  | t  } t  | | t  } t | t  sU t  | r t t t |  t |   | | t  } t	 | t
 d  | t  } n  t | | | t  } t | | | t  } | | f S(   Ni   id   (   R   R   R   R   R   t   AssertionErrorR%   Rk   R    R'   R   R$   R#   (	   Rh   Ri   t   percentR9   Rl   t   xat   xbRJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_from_str_a_b  s    
*c   
      C   s  t  d |   } |  j d d  }  | d } d |  k r` |  j d  \ } } t | | t |  Sd |  k r|  d d k s d |  k r |  n  |  j d d  }  t } d	 |  k r |  d
 d	 k r |  n  t } |  j d	 d  }  n  |  j d  \ } } t | | | |  Sd |  k rZd |  k s5d |  k r>|  n  |  d d k r|  j d d  }  |  j d d  }  |  j d  \ } } t | | t  } t | | t  } | | f S|  j d  \ } } | j d  \ } }	 d |  k r|	 j d  \ }	 } n |	 j	 d  d }	 } t | | | | t  } t | |	 | | t  } | | f Sn. t |  | t  } t |  | t  } | | f Sd S(   s  
    Parse an interval number given as a string.

    Allowed forms are

    "-1.23e-27"
        Any single decimal floating-point literal.
    "a +- b"  or  "a (b)"
        a is the midpoint of the interval and b is the half-width
    "a +- b%"  or  "a (b%)"
        a is the midpoint of the interval and the half-width
        is b percent of a (`a 	imes b / 100`).
    "[a, b]"
        The interval indicated directly.
    "x[y,z]e"
        x are shared digits, y and z are unequal digits, e is the exponent.

    s&   Improperly formed interval number '%s't    t    i   s   +-t   (i    t   )t   %it   ,t   [t   ]t   eN(
   t
   ValueErrort   replacet   splitR   RB   RA   R   R   R   t   rstrip(
   R8   R9   R   Rl   Rh   Ri   R   RJ   RK   t   z(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_from_str  sN    
			
s   []t   bracketsi   c         K   sf  t  |  } | d } |  \ }	 }
 t |  |  } t |  |  } t |	 | |  } t |
 | |  } t | | |  } d } | r d } n  | \ } } | d k r t t | d  | |  } | | d | | } n| d k rP| t k r t } n6 t | t d   } t | t | t d	   |  } | | d
 t | |  d } n| d k ry| | d | | | } n| d k rR| | k rt |	 | d |  } t |
 | d |  } n  | j	 d  }	 t
 |	  d k r|	 j d  n  | j	 d  }
 t
 |
  d k r"|
 j d  n  |	 d |
 d k r#|	 d |
 d k rxB t t
 |	 d  d  D]& } |	 d | |
 d | k rePqeqeW|	 d |  | |	 d | d | |
 d | | d t t
 |	 d  d  |	 d } qO|	 d | | d t t
 |	 d  d  |	 d } qb| d j |	  d | d j |
  | } n t d |   | S(   s  
    Convert a mpi interval to a string.

    **Arguments**

    *dps*
        decimal places to use for printing
    *use_spaces*
        use spaces for more readable output, defaults to true
    *brackets*
        pair of strings (or two-character string) giving left and right brackets
    *mode*
        mode of display: 'plusminus', 'percent', 'brackets' (default) or 'diff'
    *error_dps*
        limit the error to *error_dps* digits (mode 'plusminus and 'percent')

    Additional keyword arguments are forwarded to the mpf-to-string conversion
    for the components of the output.

    **Examples**

        >>> from mpmath import mpi, mp
        >>> mp.dps = 30
        >>> x = mpi(1, 2)._mpi_
        >>> mpi_to_str(x, 2, mode='plusminus')
        '1.5 +- 0.5'
        >>> mpi_to_str(x, 2, mode='percent')
        '1.5 (33.33%)'
        >>> mpi_to_str(x, 2, mode='brackets')
        '[1.0, 2.0]'
        >>> mpi_to_str(x, 2, mode='brackets' , brackets=('<', '>'))
        '<1.0, 2.0>'
        >>> x = mpi('5.2582327113062393041', '5.2582327113062749951')._mpi_
        >>> mpi_to_str(x, 15, mode='diff')
        '5.2582327113062[4, 7]'
        >>> mpi_to_str(mpi(0)._mpi_, 2, mode='percent')
        '0.0 (0.0%)'

    i   R   R   t	   plusminusis   +-R   id   i   R   s   %)R   R   t   diffi   R   i   i    s%   '%s' is unknown mode for printing mpi(   R	   RO   RN   R   R(   R   R%   R   R'   R   t   lent   appendR    t   mint   joinR   (   Rh   R<   t
   use_spacesR   t   modet	   error_dpst   kwargsR9   Rl   RJ   RK   t   midt   deltat   a_strt   b_strt   mid_strt   spt   br1t   br2t	   delta_strR8   Rv   t   i(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt
   mpi_to_str  sV    (
		!"!\8/c         C   s:   |  \ } } | \ } } t  | | |  t  | | |  f S(   N(   RL   (   Rh   Ri   R9   RJ   RK   Rq   t   d(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_addd  s    c         C   s:   |  \ } } | \ } } t  | | |  t  | | |  f S(   N(   RM   (   Rh   Ri   R9   RJ   RK   Rq   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_subi  s    c         C   s(   |  \ } } t  | |  t  | |  f S(   N(   RQ   (   Rh   R9   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_negn  s    c         C   s(   |  \ } } t  | |  t  | |  f S(   N(   RP   (   Rh   R9   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_posr  s    c         C   s   |  \ } } | \ } } t  | |  } t  | |  } t | | |  }	 t  | |  }
 t  | |  } t |
 | |  } |	 | f S(   N(   RV   RM   RL   (   Rh   Ri   R9   RJ   RK   Rq   R   t   r1t   r2t   ret   i1t   i2t   im(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_mulv  s    c         C   s   |  \ } } | \ } } | d } t  |  } t  |  }	 t | |	 |  }
 t t | |  t | |  |  } t t | |  t | |  |  } t | |
 |  } t | |
 |  } | | f S(   Ni   (   R]   RL   RV   RM   RX   (   Rh   Ri   R9   RJ   RK   Rq   R   Rl   t   m1t   m2t   mR   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_div  s    
$$c         C   sh   |  \ } } | d } t  | |  } t | |  \ } } t | | |  } t | | |  } | | f S(   Ni   (   R_   R~   RV   (   Rh   R9   RJ   RK   Rl   t   rRq   R8   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_exp  s    
c         C   s(   |  \ } } t  | |  t  | |  f S(   N(   R(   (   Rh   Rd   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt	   mpi_shift  s    c         C   sw   | d } t  |  |  } t t | |  } t | | |  } t | | |  } t | d  } t | d  } | | f S(   Ni   i(   R_   RX   t   mpi_oneRL   RM   R   (   Rh   R9   Rl   t   e1t   e2Rq   R8   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_cosh_sinh  s    
c         C   st   |  \ } } | d } t  | |  \ } } t | |  \ } } t | | |  }	 t | | |  }
 |	 t |
  f S(   Ni
   (   R~   R   RV   RQ   (   Rh   R9   RJ   RK   Rl   Rq   R8   t   cht   shR   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_cos  s    
c         C   sn   |  \ } } | d } t  | |  \ } } t | |  \ } } t | | |  }	 t | | |  }
 |	 |
 f S(   Ni
   (   R~   R   RV   (   Rh   R9   RJ   RK   Rl   Rq   R8   R   R   R   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_sin  s    
c         C   ss   |  \ } } | t  k r" t |  S| t  k r8 t |  St |  } t |  } t | | | d  } t | |  S(   Ni   (   t   mpi_zeroRU   R]   RL   Ra   (   Rh   R9   RJ   RK   R>   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_abs  s    

c   	      C   s  |  \ } } | \ } } | | k o/ t  k n rQ t | t   rG t St |  St | t   r t | t   r t | | | t  } n t | | | t  } t | t   r t | | | t  } qt | | | t  } n t | t   r>t | | | t  } t | t   r&t | | | t  } qt | | | t  } n~ t | t   rt | | | t  } t | t   rt | | | t  } qt | | | t  } n t | t  } t	 |  } | | f S(   N(
   R   R   R   R^   R0   R   R   R   R1   R!   (	   Ri   Rh   R9   t   yat   ybR   R   RJ   RK   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt	   mpi_atan2  s4    
c         C   s   |  \ } } t  | | |  S(   N(   R   (   R   R9   Rh   Ri   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_arg  s    c         C   sA   |  \ } } t  t |  | d  |  } t |  |  } | | f S(   Ni   (   R`   R   R   (   R   R9   Rh   Ri   R   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_log  s    c         C   s   | \ } } | t  k r | \ } } | | k r | \ } } }	 }
 | rv |	 d k rv t |  d | t | |	 > |  S| t k r t |  d |  Sq n  | d } t t | t |  |  |  |  S(   Ni    ii   (   R   t   mpci_pow_intt   intR   R   R   R   (   Rh   Ri   R9   t   yret   yimR   R   Rm   Rn   Ro   Rp   Rl   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_pow  s    "
c         C   sU   |  \ } } t  t |  t |  |  } t | | |  } t | d  } | | f S(   Ni   (   RM   R]   RV   R   (   Rh   R9   RJ   RK   R   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_square  s
    c         C   s   | d k  r3 t  t t f t |  | | d  |  S| d k rI t t f S| d k rb t |  |  S| d k r{ t |  |  S| d } t t f } xL | r | d @r t | |  |  } | d 8} n  t |  |  }  | d L} q Wt | |  S(   Ni    i   i   i   (   R   R   R   R   R   R   R   (   Rh   Rd   R9   Rl   t   result(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyR     s"    '

	
g#+Vcb?gVcb?gg?c         C   sB   |  \ } } | \ } } t  | |  r+ t St | |  r> t St S(   N(   R   RB   R   RA   (   Rh   Ri   RJ   RK   Rq   R   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_overlap&  s      c   	      C   sP  |  \ } } | d } | d k r> t  t |  t |  | d  St | t  r | d k r t | | t  } t | | t  } qF| d k r t | | t  } t | | t  } qF| d k rFt	 | | t  } t	 | | t  } qFn]t | t
  rt | t  r| d k r:t | | t  } t | | t  } qF| d k rmt | | t  } t | | t  } qF| d k rFt	 | | t  } t	 | | t  } qFn t |  t |  } | d k rt t  | | d d  |  |  S| d k rt t  | | d d  |  |  S| d k rFt t  | | d d  t |  | d  |  S| | f S(   Ni   i   i    i   i   (   t	   mpi_gammaRL   R   R   t   gamma_min_bR4   R   R   R5   R6   R   R   t   gamma_min_aRX   RV   RM   R`   (	   R   R9   t   typeRJ   RK   Rl   Rq   R   t   znew(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyR   2  s@    
     -c         C   s@  |  \ \ } } \ } } | | k o/ t  k n re | d k sO t | t   re t |  | |  t f S| d } | d k r| d | d } | d | d }	 | t  k r t | |	  }
 n |	 }
 t t |   } t t |   } t | |  } t d | |
  } | t |  7} n  | d k rgt | | f t	 |  \ } } | | f | | f f }  d } n  t
 | t  rLt | | f t t f  rLt | | f t	 |  | | f f } | d k rt t | | d d  |  |  S| d k rt t | | d d  |  |  S| d k rIt t | | d d  t |  | d  |  SqLn  t | t   rt | | f | t  } t | | f | t  } t | | f | t  } t | | f | t  } nt | t   r0t | | f | t  } t | | f | t  } t | | f | t  } t | | f | t  } n t | t  f | t  } t t |  |  rxt | | f | t  } n t | | f | t  } t | | f | t  } t | | f | t  } | d | d f | d | d f f } | d k rt | d |  t | d |  f S| d k r3t |  } n  t | |  S(   Ni   i   i   i    i   (   R   R   R   R   t   maxt   absR   R
   RL   R   R   R   R   t   gamma_mono_imag_at   gamma_mono_imag_bR   t
   mpci_gammaR   R   R   R   R7   R   R   R   R!   RP   R   R   (   R   R9   R   t   a1t   a2t   b1t   b2Rl   t   amagt   bmagt   magt   ant   bnt   absnt
   gamma_sizeR   t   minret   maxret   minimt   maximt   w(    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyR   W  sd    7
 	$     3($c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_loggamma  s    c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_loggamma  s    c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt
   mpi_rgamma  s    c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_rgamma  s    c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpi_factorial  s    c         C   s   t  |  | d d S(   NR   i   (   R   (   R   R9   (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   mpci_factorial  s    N(   t   __doc__t   backendR    t   libmpfR   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+   t	   libelefunR,   R-   R.   R/   R0   R1   R2   R3   t	   gammazetaR4   R5   R6   R7   R=   R   R   R?   R@   RF   RG   RH   RI   RL   RM   RN   RO   RP   RQ   RU   RW   RY   RV   R]   RX   R^   R_   R`   Ra   Rb   Rc   Rg   Rj   Rk   Rs   R~   R   R   R   R   R   R   RA   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t	   gamma_minR   R   R   R   R   R   R   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/mpmath/libmp/libmpi.pyt   <module>   s    :"															D	;						%					4						B\															&						%I					