
<Zc           @   s   d  d l  m Z d d l Z d d l Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z d e f d	     YZ d S(
   i   (   t   StandardBaseContextiN(   t   math2(   t   function_docs(   t   mpf_bernoullit   to_floatt	   int_types(   t   libmpt	   FPContextc           B   s  e  Z d  Z d   Z d   Z e j Z d   Z d   Z d   Z	 d   Z
 e Z e e e  Z e e	 e
  Z d Z d Z e j Z e j Z e j Z e j Z d	 Z e d
    Z d   Z e j Z e j  Z  e j! Z! d Z" d Z# d Z$ d Z% d Z& d Z! d Z' d Z( d Z) d Z* e+ Z, Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 e3 Z4 e5 Z6 d   Z7 e8 e j9  Z: e8 e j;  Z; e8 e j<  Z< e8 e j=  Z> Z= e8 e j?  Z? e8 e j@  Z@ e8 e jA  ZA e8 e jB  ZB e8 e jC  ZC e8 e jD  ZD e8 e jE  ZE e8 e jF  ZF e8 e jG  ZG e8 e jH  ZH e8 e jI  ZI e8 e jJ  ZJ e8 e jK  ZL ZK e8 e jM  ZM e8 e jN  ZN e8 e jO  ZO e8 e jP  ZP e8 e jQ  ZQ e8 e jR  ZS e8 e jT  ZU e8 e jV  ZW e8 e jX  ZY ZZ d   Z[ d   Z\ d   Z] e^ j_ Z_ e^ j` Z` d   Za d    Zb d!   Zc d"   Zd d#   Ze d$   Zf d% d&  Zg d'   Zh d(   Zi e8 e jj  Zj d)   Zk el Zm d*   Zn d+   Zo e8 e jp  Zq e8 e jr  Zs d, d-  Zt RS(.   s   
    Context for fast low-precision arithmetic (53-bit precision, giving at most
    about 15-digit accuracy), using Python's builtin float and complex.
    c         C   s9   t  j |   t j |  _ i  |  _ t |  _ |  j   d  S(   N(   R    t   __init__R   t   loggammat   _bernoulli_cachet   Falset   prettyt   _init_aliases(   t   ctx(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyR      s
    		c         C   s   t  | d  | d S(   Ni    i   (   t   float(   t   clst   x(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   <lambda>   s    c         C   s   d S(   Ni5   (    (   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt	   _get_prec    s    c         C   s   d  S(   N(    (   R   t   p(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt	   _set_prec!   s    c         C   s   d S(   Ni   (    (   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _get_dps"   s    c         C   s   d  S(   N(    (   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _set_dps#   s    g        g      ?y              ?c            sM   | r   f d   } n   } t  j j |   j  | _ t |  | |  d  S(   Nc            s8   |  j  } g  | D] } | |  ^ q }   |  | |  S(   N(   t   convert(   R   t   argst   kwargsR   t   a(   t   f(    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt	   f_wrapped6   s    	(   R   t   __dict__t   gett   __doc__t   setattr(   R   t   nameR   t   wrapR   (    (   R   s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _wrap_specfun3   s
    c         C   sG   |  j  } | | k r | | St t | d d  d t | | <| | S(   Ni5   t   nt   strict(   R
   R   R   t   True(   R   R%   t   cache(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt	   bernoulli?   s
    	"g;f?gw@gw?g9B.?gUk@gox?g]O?gm<B{@g!;?gs/O҄?c         C   s   | | d k S(   Ng        (    (   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt
   is_specialV   s    c         C   s
   | | k S(   N(    (   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   isnanY   s    c         C   s   t  |  t j k S(   N(   t   absR   t   INF(   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   isinf\   s    c         C   s   | r | | d k St  S(   Ng        (   R   (   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   isnormal_   s    c         C   sG   t  |  t k r+ | j r t S| j } n  | d k oF t |  | k S(   Ng        (   t   typet   complext   imagR   t   realt   round(   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   isnpintd   s
    	c         C   s#   y t  |  SWn t |  SXd  S(   N(   R   R1   (   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyR   n   s    c         C   s"   t  |  } t j | j | j  S(   N(   R1   t   matht   atan2R2   R3   (   R   t   z(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   arg   s    c         C   s   |  j  |  j |  S(   N(   t   expt   j(   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   expj   s    c         C   s   |  j  |  j |  j |  S(   N(   R:   R;   t   pi(   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   expjpi   s    c         C   s$   | r |  j  t |   d S|  j S(   Ni   (   t   frexpR,   t   ninf(   R   R8   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   mag   s    c         C   sK   t  | d  r( | j r t S| j } n  y | t |  k SWn t SXd  S(   NR2   (   t   hasattrR2   R   R3   t   int(   R   R8   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   isint   s    	c         C   sc   t  | d  r! t | j  } n t |  } | | k rF | |  j f S| |  j t | |   f S(   NR2   (   RB   R4   R3   R@   RA   R,   (   R   R8   R%   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   nint_distance   s    c         C   s   t  |  t k r5 | \ } } |  j |  | d f St | d  rV t | j  } n t |  } | | k rx | d f S| d f S(   Nt   RR2   t   Z(   R0   t   tuplet   mpfRB   RC   R3   (   R   R8   R   t   qt   intz(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _convert_param   s    
c         C   s   t  | t  p t  | t  S(   N(   t
   isinstanceR   R   (   R   R8   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _is_real_type   s    c         C   s   t  | t  S(   N(   RM   R1   (   R   R8   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   _is_complex_type   s    ip  c         K   s   t  |  } t |  } t | | |  }	 |  j }
 d } } d } x x  | D] } | | | | 9} qN Wx  |	 D] } | | | | :} qq W| d 7} | | :} | | 9} | | 7} t |  |
 k  r | S| | k rG |  j  qG qG Wd  S(   Ng      ?i    i   (   t   listt   ranget   epsR,   t   NoConvergence(   R   R   RJ   t   typest   coeffsR8   t   maxtermsR   t   numt   dent   tolt   st   tt   kt   i(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   hypsum   s&    	
  
 
 
 
c         C   s   t  j | |  S(   N(   R6   R7   (   R   R   t   y(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyR7      s    c         C   sR   t  |  } | d k r% |  j |  Sd | d |  j |  |  j | d |  S(   Ni    ii   (   RC   t   digammat   fact   zeta(   R   t   mR8   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   psi   s    c         C   sC   |  j  |  } | d k s' | d k r+ | S|  j | d  |  j S(   Ni    i   (   R   R`   t   euler(   R   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   harmonic   s    c         C   s   t  t j | |   S(   N(   RC   R6   t   ldexp(   R   R   t   prec(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   to_fixed   s    c         C   s   d d  l  } | j    S(   Ni(   t   random(   R   Rj   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   rand   s    i   c         C   so   |  j  } d } xY |   D]N } | | 7} | | r] | r] t |  d t |  k r] Pq] n  | d 7} q W| S(   Ni    gC]r2<i   (   t   zeroR,   (   R   t   termst
   check_stepRZ   R\   t   term(    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   sum_accurately   s    	
(u   t   __name__t
   __module__R    R   t   _mpqR   RS   R   R   R   R   R'   t   _fixed_precisiont   propertyRh   t   dpsRl   t   oneR   t   EPSRR   R-   t   inft   NINFR@   t   NANt   nanR;   t   classmethodR$   R)   R=   t   eRe   t   sqrt2t   sqrt5t   phit   ln2t   ln10t   catalant   khinchint   aperyt   glaisherR,   t   absmint   absmaxR*   R+   R.   R/   R5   R   RI   R1   t   mpcR   t   staticmethodt   powt   powert   sqrtR:   t   logt   lnt   cost   sint   tant   cos_sint   acost   asint   atant   cosht   sinht   tanht   gammat   rgammat	   factorialRa   t   floort   ceilt   cospit   sinpit   cbrtt   nthroott   _nthroott   eit   _eit   e1t   _e1Rb   t   _zetat	   _zeta_intR9   R<   R>   R6   Rg   R?   RA   RD   RE   RL   RN   RO   R^   R7   Rd   R`   Rf   t   strt   nstrRi   Rk   t   erft   _erft   erfct   _erfcRp   (    (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyR      s   	
														
													
										(   t   ctx_baseR    R6   t   cmatht    R   R   R   R   R   R   R   (    (    (    s,   lib/python2.7/site-packages/mpmath/ctx_fp.pyt   <module>   s   