
n5[c           @   sa  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/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 m: Z: m; Z; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN mO ZO mP ZP mQ ZQ mR ZR mS ZS mT ZT mU ZU mV ZV mW ZW mX ZX mY ZY m Z d  d lZ m[ Z[ d  d lZ m\ Z\ e] j^ Z_ d e] f d     YZ` d e` f d     YZa d	 Zb d
 Zc d Zd d ec ed f Ze d d d d  Zf ef d d d d  ea _g ef d d ec d ec d ed  ea _h ef d d ec d ec d ed  ea _i ef d d ec d ec d ed  ea _j ef d d  ec d! ec d" ed  ea _k ef d# d$ ec d% ec d&  ea _l ef d' ee d( ec d) ed  ea _m ea jh ea _n ea jj ea _o ea jk ea _p ea jq ea _r d* ea f d+     YZs d, e` f d-     YZt eu et f Zv d. e] f d/     YZw y0 d0 d1 lx Zx ex jy jz et  ex j{ jz ea  Wn e| k
 r\n Xd1 S(2   i   (   t
   basestringt   exec_(W   t   MPZt   MPZ_ZEROt   MPZ_ONEt	   int_typest   repr_dpst   round_floort   round_ceilingt   dps_to_prect   round_nearestt   prec_to_dpst   ComplexResultt   to_pickablet   from_pickablet	   normalizet   from_intt
   from_floatt   from_npfloatt   from_Decimalt   from_strt   to_intt   to_floatt   to_strt   from_rationalt   from_man_expt   fonet   fzerot   finft   fninft   fnant   mpf_abst   mpf_post   mpf_negt   mpf_addt   mpf_subt   mpf_mult   mpf_mul_intt   mpf_divt   mpf_rdiv_intt   mpf_pow_intt   mpf_modt   mpf_eqt   mpf_cmpt   mpf_ltt   mpf_gtt   mpf_let   mpf_get   mpf_hasht   mpf_randt   mpf_sumt   bitcountt   to_fixedt
   mpc_to_strt   mpc_to_complext   mpc_hasht   mpc_post   mpc_is_nonzerot   mpc_negt   mpc_conjugatet   mpc_abst   mpc_addt   mpc_add_mpft   mpc_subt   mpc_sub_mpft   mpc_mult   mpc_mul_mpft   mpc_mul_intt   mpc_divt   mpc_div_mpft   mpc_powt   mpc_pow_mpft   mpc_pow_intt   mpc_mpf_divt   mpf_powt   mpf_pit
   mpf_degreet   mpf_et   mpf_phit   mpf_ln2t   mpf_ln10t	   mpf_eulert   mpf_catalant	   mpf_aperyt   mpf_khinchint   mpf_glaishert   mpf_twinprimet   mpf_mertensR   (   t   rational(   t   function_docst	   mpnumericc           B   s   e  Z d  Z g  Z d   Z RS(   s   Base class for mpf and mpc.c         C   s
   t   d  S(   N(   t   NotImplementedError(   t   clst   val(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __new__$   s    (   t   __name__t
   __module__t   __doc__t	   __slots__R^   (    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyRZ   !   s   t   _mpfc           B   s  e  Z d  Z d g 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 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) d&  Z- d'   Z. d(   Z/ RS(*   s   
    An mpf instance holds a real-valued floating-point number. mpf:s
    work analogously to Python floats, but support arbitrary-precision
    arithmetic.
    t   _mpf_c   
      K   s  |  j  j \ } } | r^ | j d |  } d | k rI t | d  } n  | j d |  } n  t |  |  k r | j \ } } } } | r | r | St |   }	 t | | | | | |  |	 _ |	 St |  t k ryt	 |  d k rt |   }	 t
 | d | d | |  |	 _ |	 St	 |  d k rp| \ } } } } t |   }	 t | t |  | | | |  |	 _ |	 St  n4 t |   }	 t |  j | | |  | |  |	 _ |	 Sd S(	   s   A new mpf can be created from a Python float, an int, a
        or a decimal string representing a number in floating-point
        format.t   prect   dpst   roundingi   i    i   i   N(   t   contextt   _prec_roundingt   getR	   t   typeRd   t   newR   t   tuplet   lenR   R   t
   ValueErrorR    t   mpf_convert_arg(
   R\   R]   t   kwargsRe   Rg   t   signt   mant   expt   bct   v(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR^   /   s6     $	$c         C   s)  t  | t  r t |  St  | t  r2 t |  St  | t  rQ t | | |  St  | |  j j  rv | j	 | |  St
 | d  r | j St
 | d  r |  j j | j | |   } t
 | d  r | j Sn  t
 | d  r| j \ } } | | k r | St d   n  t d t |    d  S(   NRd   t   _mpmath_t   _mpi_s,   can only create mpf from zero-width intervals   cannot create mpf from (   t
   isinstanceR   R   t   floatR   R    R   Rh   t   constantt   funct   hasattrRd   t   convertRw   Rx   Ro   t	   TypeErrort   repr(   R\   t   xRe   Rg   t   tt   at   b(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyRp   P   s(     
 
   
c         C   s   t  | t  r t |  St  | t  r2 t |  St  | t  rQ |  j j |  St  | t j	  r | j
 \ } } t | | |  j j  St | d  r | j St | d  r |  j j | j |  j j    } t | d  r | j S| St S(   NRd   Rw   (   Ry   R   R   Rz   R   t   complex_typesRh   t   mpcRX   t   mpqt   _mpq_R   Re   R}   Rd   R~   Rw   Ri   t   NotImplemented(   R\   R   t   pt   qR   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   mpf_convert_rhsb   s"     
 
  !c         C   s5   |  j  |  } t |  t k r1 |  j j |  S| S(   N(   R   Rk   Rm   Rh   t   make_mpf(   R\   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   mpf_convert_lhsr   s    c         C   s   |  j  d d !S(   Ni   i   (   Rd   (   t   self(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   <lambda>y   s    c         C   s   |  j  d S(   Ni   (   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   z   s    c         C   s   |  j  d S(   Ni   (   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   {   s    c         C   s   |  j  d S(   Ni   (   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   |   s    c         C   s   |  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   ~   s    c         C   s
   |  j  j S(   N(   Rh   t   zero(   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR      s    c         C   s   |  S(   N(    (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR      s    c         C   s   t  |  j  S(   N(   R   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __getstate__   s    c         C   s   t  |  |  _ d  S(   N(   R   Rd   (   R   R]   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __setstate__   s    c         C   s0   |  j  j r t |   Sd t |  j |  j  j  S(   Ns	   mpf('%s')(   Rh   t   prettyt   strR   Rd   t   _repr_digits(   t   s(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __repr__   s    
c         C   s   t  |  j |  j j  S(   N(   R   Rd   Rh   t   _str_digits(   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __str__   s    c         C   s   t  |  j  S(   N(   R0   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __hash__   s    c         C   s   t  t |  j   S(   N(   t   intR   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __int__   s    c         C   s   t  t |  j   S(   N(   t   longR   Rd   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __long__   s    c         C   s   t  |  j d |  j j d S(   Nt   rndi   (   R   Rd   Rh   Ri   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt	   __float__   s    c         C   s   t  t |    S(   N(   t   complexRz   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __complex__   s    c         C   s   |  j  t k S(   N(   Rd   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __nonzero__   s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   t   _ctxdataR   Rd   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __abs__   s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   R   R    Rd   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __pos__   s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   R   R!   Rd   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __neg__   s    c         C   sJ   t  | d  r | j } n |  j |  } | t k r: | S| |  j |  S(   NRd   (   R}   Rd   R   R   (   R   R   R|   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _cmp   s    c         C   s   |  j  | t  S(   N(   R   R+   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __cmp__   s    c         C   s   |  j  | t  S(   N(   R   R,   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __lt__   s    c         C   s   |  j  | t  S(   N(   R   R-   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __gt__   s    c         C   s   |  j  | t  S(   N(   R   R.   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __le__   s    c         C   s   |  j  | t  S(   N(   R   R/   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __ge__   s    c         C   s$   |  j  |  } | t k r | S| S(   N(   t   __eq__R   (   R   R   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __ne__   s    c         C   s   |  j  \ } } \ } } t |  t k r[ | |  } t t |  |  j | |  | _ | S|  j |  } | t k rz | S| |  S(   N(   R   Rk   R   R#   R   Rd   R   R   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __rsub__   s    !c         C   sy   |  j  \ } } \ } } t | t  rR | |  } t | |  j | |  | _ | S|  j |  } | t k rq | S| |  S(   N(   R   Ry   R   R'   Rd   R   R   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __rdiv__   s    c         C   s'   |  j  |  } | t k r | S| |  S(   N(   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __rpow__   s    c         C   s'   |  j  |  } | t k r | S| |  S(   N(   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __rmod__   s    c         C   s   |  j  j |   S(   N(   Rh   t   sqrt(   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR      s    c         C   s   |  j  j |  | | |  S(   N(   Rh   t   almosteq(   R   R   t   rel_epst   abs_eps(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   ae   s    c         C   s   t  |  j |  S(   N(   R4   Rd   (   R   Re   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR4      s    c         G   s   t  t |   |  S(   N(   t   roundRz   (   R   t   args(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt	   __round__   s    N(0   R_   R`   Ra   Rb   R   R^   t   classmethodRp   R   R   t   propertyt   man_expRs   Rt   Ru   t   realt   imagt	   conjugateR   R   R   R   R   R   R   R   R   R   t   __bool__R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   NoneR   R4   R   (    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyRc   '   sT   	!																												s  
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)
s-   ; obj = new(mpf); obj._mpf_ = val; return objs-   ; obj = new(mpc); obj._mpc_ = val; return objs  
        try:
            val = mpf_pow(sval, tval, prec, rounding) %s
        except ComplexResult:
            if mpf.context.trap_complex:
                raise
            mpc = mpf.context.mpc
            val = mpc_pow((sval, fzero), (tval, fzero), prec, rounding) %s
t    c         C   so   t  } | j d |  } | j d |  } | j d |  } | j d |   } i  } t | t   |  | |  S(   Ns
   %WITH_INT%s
   %WITH_MPC%s
   %WITH_MPF%s   %NAME%(   t   mpf_binary_opt   replaceR   t   globals(   t   namet   with_mpft   with_intt   with_mpct   codet   np(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt	   binary_op  s    R   s   return mpf_eq(sval, tval)s$   return mpf_eq(sval, from_int(other))s3   return (tval[1] == fzero) and mpf_eq(tval[0], sval)t   __add__s)   val = mpf_add(sval, tval, prec, rounding)s4   val = mpf_add(sval, from_int(other), prec, rounding)s-   val = mpc_add_mpf(tval, sval, prec, rounding)t   __sub__s)   val = mpf_sub(sval, tval, prec, rounding)s4   val = mpf_sub(sval, from_int(other), prec, rounding)s2   val = mpc_sub((sval, fzero), tval, prec, rounding)t   __mul__s)   val = mpf_mul(sval, tval, prec, rounding)s.   val = mpf_mul_int(sval, other, prec, rounding)s-   val = mpc_mul_mpf(tval, sval, prec, rounding)t   __div__s)   val = mpf_div(sval, tval, prec, rounding)s4   val = mpf_div(sval, from_int(other), prec, rounding)s-   val = mpc_mpf_div(sval, tval, prec, rounding)t   __mod__s)   val = mpf_mod(sval, tval, prec, rounding)s4   val = mpf_mod(sval, from_int(other), prec, rounding)s+   raise NotImplementedError("complex modulo")t   __pow__s.   val = mpf_pow_int(sval, other, prec, rounding)s2   val = mpc_pow((sval, fzero), tval, prec, rounding)t	   _constantc           B   sD   e  Z d  Z d d  Z d d d d  Z e d    Z d   Z RS(   s   Represents 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         C   s:   t  j |   } | | _ | | _ t t | d  | _ | S(   NR   (   t   objectR^   R   R|   t   getattrRY   Ra   (   R\   R|   R   t   docnameR   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR^   N  s
    		c         C   sa   |  j  j \ } } | s! | } n  | s0 | } n  | rE t |  } n  |  j  j |  j | |   S(   N(   Rh   Ri   R	   R   R|   (   R   Re   Rf   Rg   t   prec2t	   rounding2(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __call__U  s     	 	 c         C   s"   |  j  j \ } } |  j | |  S(   N(   Rh   Ri   R|   (   R   Re   Rg   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyRd   \  s    c         C   s&   d |  j  |  j j |  d d   f S(   Ns	   <%s: %s~>Rf   i   (   R   Rh   t   nstr(   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   a  s    N(	   R_   R`   Ra   R^   R   R   R   Rd   R   (    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   H  s
   t   _mpcc           B   sa  e  Z d  Z d g Z d 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 d  Z) RS(    s   
    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.
    t   _mpc_i    c         C   s   t  j |   } t | t  r4 | j | j } } n t | d  rS | j | _ | S|  j j	 |  } |  j j	 |  } | j
 | j
 f | _ | S(   NR   (   R   R^   Ry   R   R   R   R}   R   Rh   t   mpfRd   (   R\   R   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR^   n  s    c         C   s   |  j  j |  j d  S(   Ni    (   Rh   R   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   z  s    c         C   s   |  j  j |  j d  S(   Ni   (   Rh   R   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   {  s    c         C   s$   t  |  j d  t  |  j d  f S(   Ni    i   (   R   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   }  s    c         C   s'   t  | d  t  | d  f |  _ d  S(   Ni    i   (   R   R   (   R   R]   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s\   |  j  j r t |   St |  j  d d !} t |  j  d d !} d t |   j | | f S(   Ni   is   %s(real=%s, imag=%s)(   Rh   R   R   R   R   R   Rk   R_   (   R   t   rt   i(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s
    
c         C   s   d t  |  j |  j j  S(   Ns   (%s)(   R5   R   Rh   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   t  |  j d |  j j d S(   NR   i   (   R6   R   Rh   Ri   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   R   R8   R   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s@   |  j  j \ } } t |  j  j  } t |  j | |  | _ | S(   N(   Rh   Ri   Rl   R   R<   R   Rd   (   R   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   R   R:   R   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s@   |  j  \ } } \ } } | |  } t |  j | |  | _ | S(   N(   R   R;   R   (   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   t  |  j  S(   N(   R9   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   t  |  j  S(   N(   R7   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s3   y |  j  j |  } | SWn t k
 r. t SXd  S(   N(   Rh   R~   R   R   (   R\   R   t   y(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   mpc_convert_lhs  s
    c         C   sf   t  | d  sD t | t  r" t S|  j |  } | t k rD | Sn  |  j | j k oe |  j | j k S(   NR   (   R}   Ry   R   t   FalseR   R   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s$   |  j  |  } | t k r | S| S(   N(   R   R   (   R   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c          G   s   t  d   d  S(   Ns3   no ordering relation is defined for complex numbers(   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _compare  s    c         C   s   |  j  \ } } \ } } t | d  s |  j |  } | t k rF | St | d  r | |  } t |  j | j | |  | _ | Sn  | |  } t |  j | j | |  | _ | S(   NR   Rd   (   R   R}   R   R   R>   R   Rd   R=   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   |  j  \ } } \ } } t | d  s |  j |  } | t k rF | St | d  r | |  } t |  j | j | |  | _ | Sn  | |  } t |  j | j | |  | _ | S(   NR   Rd   (   R   R}   R   R   R@   R   Rd   R?   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   |  j  \ } } \ } } t | d  s t | t  ra | |  } t |  j | | |  | _ | S|  j |  } | t k r | St | d  r | |  } t |  j | j	 | |  | _ | S|  j |  } n  | |  } t
 |  j | j | |  | _ | S(   NR   Rd   (   R   R}   Ry   R   RC   R   R   R   RB   Rd   RA   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s"    c         C   s   |  j  \ } } \ } } t | d  s |  j |  } | t k rF | St | d  r | |  } t |  j | j | |  | _ | Sn  | |  } t |  j | j | |  | _ | S(   NR   Rd   (   R   R}   R   R   RE   R   Rd   RD   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   s   |  j  \ } } \ } } t | t  rR | |  } t |  j | | |  | _ | S|  j |  } | t k rq | S| |  } t | d  r t |  j | j	 | |  | _ n t
 |  j | j | |  | _ | S(   NRd   (   R   Ry   R   RH   R   R   R   R}   RG   Rd   RF   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    !c         C   s'   |  j  |  } | t k r | S| |  S(   N(   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s    c         C   sy   |  j  \ } } \ } } t | t  rR | |  } t |  j | | |  | _ | S|  j |  } | t k rq | S| |  S(   N(   R   Ry   R   RC   R   R   R   (   R   R   R\   Rl   Re   Rg   Rv   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __rmul__$  s    c         C   s'   |  j  |  } | t k r | S| |  S(   N(   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   /  s    c         C   s'   |  j  |  } | t k r | S| |  S(   N(   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   5  s    c         C   s   |  j  j |  | | |  S(   N(   Rh   R   (   R   R   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   >  s    N(*   R_   R`   Ra   Rb   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   __radd__R   R   R   R   t   __truediv__t   __rtruediv__R   R   (    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   e  sL   																									t   PythonMPContextc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z e d   e  Z	 e d   e  Z
 e d  Z d	   Z d
   Z d   Z d   Z e d  Z e e d  Z d e d  Z d d d d  Z e d    Z d   Z d   Z d   Z RS(   c         C   s   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(   Ni5   R   R   R{   (   R
   Ri   Rk   Rc   R   R   R   Rl   R   Rh   R   R{   (   t   ctx(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   __init__G  s    c         C   s   t  |  j  } | | _ | S(   N(   Rl   R   Rd   (   R   Rv   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   S  s    	c         C   s   t  |  j  } | | _ | S(   N(   Rl   R   R   (   R   Rv   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   make_mpcX  s    	c         C   s*   d |  _  |  j d <d |  _ t |  _ d  S(   Ni5   i    i   (   t   _precRi   t   _dpsR   t   trap_complex(   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   default]  s    	c         C   s6   t  d t |   |  _ |  j d <t |  |  _ d  S(   Ni   i    (   t   maxR   R   Ri   R   R   (   R   t   n(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt	   _set_precb  s    #c         C   s6   t  |  |  _ |  j d <t d t |   |  _ d  S(   Ni    i   (   R	   R   Ri   R   R   R   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _set_dpsf  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   j  s    c         C   s   |  j  S(   N(   R   (   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   k  s    c         C   sG  t  |  |  j k r | St | t  r; |  j t |   St | t  r] |  j t |   St | t  r |  j	 t | j
  t | j  f  St  |  j d k r |  j |  St | t j  r y( t j t | j  t | j   } Wq q Xn  |  j \ } } t | t j  rC| j \ } } |  j t | | |   S| rt | t  ry# t | | |  } |  j |  SWqt k
 rqXn  t | d  r|  j | j  St | d  r|  j	 | j  St | d  r|  j | j | |   St  |  j d k r7y |  j t  | | |   SWq7q7Xn  |  j! | |  S(   s  
        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')

        t   numpyRd   R   Rw   t   decimal("   Rk   t   typesRy   R   R   R   Rz   R   R   R   R   R   R`   t	   npconvertt   numberst   RationalRX   R   R   t	   numeratort   denominatorRi   R   R   R    R   Ro   R}   Rd   R   R~   Rw   R   t   _convert_fallback(   R   R   t   stringsRe   Rg   R   R   Rd   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR~   m  sJ       %  (     c         C   s   d d l  } t | | j  r7 |  j t t |    St | | j  r\ |  j t |   St | | j  r |  j	 t | j
  t | j  f  St d t |    d S(   s^   
        Converts *x* to an ``mpf`` or ``mpc``. *x* should be a numpy
        scalar.
        iNs   cannot create mpf from (   R   Ry   t   integerR   R   R   t   floatingR   t   complexfloatingR   R   R   R   R   (   R   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR     s      %c         C   s   t  | d  r | j t k St  | d  r8 t | j k St | t  sY t | t j  r] t S|  j	 |  } t  | d  s t  | d  r |  j
 |  St d   d S(   s  
        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

        Rd   R   s   isnan() needs a number as inputN(   R}   Rd   R   R   Ry   R   RX   R   R   R~   t   isnanR   (   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR    s    !c         C   s   t  | d  r" | j t t f k St  | d  rb | j \ } } | t t f k pa | t t f k St | t  s t | t j  r t	 S|  j
 |  } t  | d  s t  | d  r |  j |  St d   d S(   s  
        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

        Rd   R   s   isinf() needs a number as inputN(   R}   Rd   R   R   R   Ry   R   RX   R   R   R~   t   isinfR   (   R   R   t   ret   im(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR    s    "!c         C   s   t  | d  r  t | j d  St  | d  r | j \ } } t | d  } t | d  } | t k rn | S| t k r~ | S| o | St | t  s t | t j  r t |  S|  j	 |  } t  | d  s t  | d  r |  j
 |  St d   d S(   s  
        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
        Rd   i   R   s"   isnormal() needs a number as inputN(   R}   t   boolRd   R   R   Ry   R   RX   R   R~   t   isnormalR   (   R   R   R  R  t	   re_normalt	   im_normal(    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR	    s"      
!
c         C   sw  t  | t  r t St | d  r] | j \ } } } } } t | rP | d k pY | t k  St | d  r | j \ } }	 | \ }
 } } } |	 \ } } } } | r | d k p | t k } | r | r | d k p |	 t k } | o | S| o |	 t k St  | t j	  r*| j
 \ } } | | d k S|  j |  } t | d  sWt | d  rg|  j | |  St d   d S(   s
  
        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

        Rd   i    R   s   isint() needs a number as inputN(   Ry   R   t   TrueR}   Rd   R  R   R   RX   R   R   R~   t   isintR   (   R   R   t   gaussianRr   Rs   Rt   Ru   t   xvalR  R  t   rsignt   rmant   rexpt   rbct   isignt   imant   iexpt   ibct   re_isintt   im_isintR   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR    s*    "
c         C   sa  |  j  \ } } g  } g  } d } x| D]}	 d }
 } t |	 d  rS |	 j }
 n t |	 d  rt |	 j \ }
 } n |  j |	  }	 t |	 d  r |	 j }
 nY t |	 d  r |	 j \ }
 } n8 | r |  j |	  }	 n  | r |	 d }	 n  | |	 7} q( | r| rw| r8| j t |
 |
   | j t | |   qt |
 | f d | d  \ }
 } | j |
  | j |  q| r| j t	 |
 | f |   q| j |
  | j |  q( | rt |
 |
  }
 n | rt
 |
  }
 n  | j |
  q( Wt | | | |  } | r6|  j | t | | |  f  } n |  j |  } | d k rU| S| | Sd S(   sX  
        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.
        i    Rd   R   i   i
   N(   Ri   R}   Rd   R   R~   t   absmaxt   appendR$   RH   R<   R   R2   R   R   (   R   t   termst   absolutet   squaredRe   R   R   R   t   othert   termt   revalt   imvalR   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   fsum>  sZ    
  
"$c         C   s  | d k	 r t | |  } n  |  j \ } } g  } g  } d } t }	 |  j |  j f }
 xO| D]G\ } } t |  |
 k r |  j |  } n  t |  |
 k r |  j |  } n  |	 | d  } |	 | d  } | r | r | j t	 | j
 | j
   q^ n  |	 | d  } |	 | d  } | r| r| j
 } | j \ } } | rUt |  } n  | j t	 | |   | j t	 | |   q^ | r| r| j \ } } | j
 } | j t	 | |   | j t	 | |   q^ | rw| rw| j \ } } | j \ } } | rt |  } n  | j t	 | |   | j t t	 | |    | j t	 | |   | j t	 | |   q^ | r| | |  j |  7} q^ | | | 7} q^ Wt | | |  } | r|  j | t | | |  f  } n |  j |  } | d k r| S| | Sd S(   s.  
        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')

        i    Rd   R   N(   R   t   zipRi   R}   R   R   Rk   R~   R  R$   Rd   R   R!   t   conjR2   R   R   (   R   t   At   BR   Re   R   R   R   R  t   hasattr_R   R   R   t   a_realt   b_realt	   a_complext	   b_complext   avalt   bret   bimt   aret   aimt   bvalR   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   fdot  sf    '  		$s   <no doc>c            sE        f d   }  j  d  t j j  d |  | _ | S(   sO  
        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            sA  t  |     j k r'   j |   }  n    j \ } } | r | j d |  } d | k rm t | d  } n  | j d |  } n  t |  d  r y    j  |  j | |   SWq!t	 k
 r   j
 r   n    j  |  j t f | |   SXn+ t |  d  r!  j  |  j | |   St d  t  |   f   d  S(   NRe   Rf   Rg   Rd   R   s
   %s of a %s(   Rk   R   R~   Ri   Rj   R	   R}   R   Rd   R   R   R   R   R   R[   (   R   Rq   Re   Rg   (   R   t   mpc_ft   mpf_fR   (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   f  s$     	&i   s   Computes the %s of x(   R_   RY   t   __dict__Rj   Ra   (   R   R5  R4  t   mpi_ft   docR6  (    (   R   R4  R5  R   s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _wrap_libmp_function  s    
c            sM   | r   f d   } n   } t  j j |   j  | _ t |  | |  d  S(   Nc            sh   |  j  } g  | D] } | |  ^ q } |  j } z% |  j d 7_   |  | |  } Wd  | |  _ X| 
S(   Ni
   (   R~   Re   (   R   R   Rq   R~   R   Re   t   retval(   R6  (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt	   f_wrapped  s    		
(   RY   R7  Rj   Ra   t   setattr(   R\   R   R6  t   wrapR<  (    (   R6  s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _wrap_specfun  s
    c   
      C   sk  t  | d  r7 | j \ } } | t k r| d f Snrt  | d  rR | j } nWt |  t k rt t |  d f Sd  } t | t	  r | \ } } nl t  | d  r | j
 \ } } nK t | t  rd | k r| j d  \ } } t |  } t |  } n  | d  k	 r>| | s(| | d f S|  j | |  d f S|  j |  } t  | d  r| j \ } } | t k r| d f Sn% t  | d  r| j } n
 | d f S| \ } } } }	 | rS| d	 k r:| r| } n  | d
 k rt |  | >d f S| d	 k r:t |  d | >} } |  j | |  d f Sn  |  j |  } | d f S| s]d S| d f Sd  S(   NR   t   CRd   t   ZR   t   /t   Qt   Uii    i   t   R(   i    RA  (   R}   R   R   Rd   Rk   R   R   R   Ry   Rm   R   R    t   splitR   R~   R   (
   R   R   Rv   R  R   R   Rr   Rs   Rt   Ru   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _convert_param  sX    



c         C   sY   | \ } } } } | r  | | S| t  k r3 |  j S| t k sK | t k rR |  j S|  j S(   N(   R   t   ninfR   R   t   inft   nan(   R   R   Rr   Rs   Rt   Ru   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   _mpf_magE  s    c         C   sT  t  | d  r |  j | j  St  | d  r | j \ } } | t k rV |  j |  S| t k ro |  j |  Sd t |  j |  |  j |   St | t  r | r t t	 |   S|  j
 St | t j  r
| j \ } } | rd t t	 |   t |  S|  j
 S|  j |  } t  | d  s7t  | d  rD|  j |  St d   d S(   s  
        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)

        Rd   R   i   s   requires an mpf/mpcN(   R}   RK  Rd   R   R   R   Ry   R   R3   t   absRH  RX   R   R   R~   t   magR   (   R   R   R   R   R   R   (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyRM  O  s,    #N(   R_   R`   R   R   R   R   R   R   R   Re   Rf   R  R~   R   R  R  R	  R   R  R#  R   R3  R:  R   R?  RG  RK  RM  (    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyR   E  s*   						2			 	(/C^#	1	
iN(}   t   libmp.backendR    R   t   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,   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   R   RX   RY   R   R^   Rl   RZ   Rc   R   t
   return_mpft
   return_mpct   mpf_pow_sameR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   Complext   registert   Realt   ImportError(    (    (    s3   lib/python2.7/site-packages/mpmath/ctx_mp_python.pyt   <module>   sr     	

  A