ó
'kº[c           @   sS  d  Z  d Z d d l Z d d l m Z d d l m Z m 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/ 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 mZ ZZ m[ Z[ m\ Z\ m] Z] m Z d d	 l m^ Z^ d d
 l m_ Z_ e` ja Zb e jc d ƒ Zd e d k rÂd d le mf Zg d d le jh ji jj Zk n  d d ll mm Zg d d l ml Zk d d ll mn Zn mo Zo mp Zp d eg e f d „  ƒ  YZq d f  d „  ƒ  YZr es d k rOd d lt Zt et ju ƒ  n  d S(   s[   
This module defines the mpf, mpc classes, and standard functions for
operating with them.
t	   plaintextiÿÿÿÿNi   (   t   StandardBaseContext(   t
   basestringt   BACKEND(   t   libmp(U   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_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   function_docs(   t   rationalsX   ^\(?(?P<re>[\+\-]?\d*\.?\d*(e[\+\-]?\d+)?)??(?P<im>[\+\-]?\d*\.?\d*(e[\+\-]?\d+)?j)?\)?$t   sage(   t   Context(   t   PythonMPContext(   t   ctx_mp_python(   t   _mpft   _mpct	   mpnumerict	   MPContextc           B   s  e  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 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „ Z e d „ Z e d „ Z e d „ Z  d7 d8 e d „ Z" d d  „ Z# d! „  Z$ d" „  Z% d# „  Z& d$ Z' d% Z( e) d& „ Z* d' „  Z+ d( „  Z, d) „  Z- d* „  Z. d+ „  Z/ d, „  Z0 d- „  Z1 d. „  Z2 d/ „  Z3 d0 „  Z4 d1 „  Z5 d2 „  Z6 d3 „  Z7 d4 „  Z8 d5 g e d6 „ Z9 RS(9   sH   
    Context for multiprecision arithmetic with a global precision.
    c         C   s_  t  j |  ƒ t |  _ t |  _ |  j |  j |  j g |  _ t	 j
 |  _ |  j ƒ  t j |  ƒ t	 j
 |  _
 |  j ƒ  i  |  _ |  j ƒ  yL t j |  j j _ t j |  j j _ t j |  j j _ t j |  j j _ WnY t k
 r-t j |  j j _ t j |  j j _ t j |  j j _ t j |  j j _ n Xt j |  j _ t j |  j _ t j |  j _ d  S(   N(   t   BaseMPContextt   __init__t   Falset   trap_complext   prettyt   mpft   mpct   constantt   typesRZ   t   mpqt   _mpqt   defaultR   t   init_builtinst   hyp_summatorst   _init_aliasesRY   t	   bernoullit   im_funct   func_doct   primepit   psit   atan2t   AttributeErrort   __func__t   digammat   cospit   sinpi(   t   ctx(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRd   =   s0    		

	
c         C   s'  |  j  } |  j } |  j t ƒ |  _ |  j t ƒ |  _ |  j t t f ƒ |  _ |  j t	 ƒ |  _
 |  j t ƒ |  _ |  j t ƒ |  _ |  j d „  d d ƒ } | |  _ |  j t d d ƒ |  _ |  j t d d ƒ |  _ |  j t d d ƒ |  _ |  j t d	 d
 ƒ |  _ |  j t d d ƒ |  _ |  j t d d ƒ |  _ |  j t d d ƒ |  _ |  j t d d ƒ |  _  |  j t! d d ƒ |  _" |  j t# d d ƒ |  _$ |  j t% d d ƒ |  _& |  j t' d d ƒ |  _( |  j t) d d ƒ |  _* |  j+ t, j- t, j. ƒ |  _/ |  j+ t, j0 t, j1 ƒ |  _2 |  j+ t, j3 t, j4 ƒ |  _5 |  j+ t, j6 t, j7 ƒ |  _8 |  j+ t, j9 t, j: ƒ |  _; |  j+ t, j< t, j= ƒ |  _> |  j+ t, j? t, j@ ƒ |  _A |  j+ t, jB t, jC ƒ |  _D |  j+ t, jE t, jF ƒ |  _G |  j+ t, jH t, jI ƒ |  _J |  j+ t, jK t, jL ƒ |  _M |  j+ t, jN t, jO ƒ |  _P |  j+ t, jQ t, jR ƒ |  _S |  j+ t, jT t, jU ƒ |  _V |  j+ t, jW t, jX ƒ |  _Y |  j+ t, j6 t, j7 ƒ |  _8 |  j+ t, jZ t, j[ ƒ |  _\ |  j+ t, j] t, j^ ƒ |  __ |  j+ t, j` t, ja ƒ |  _b |  j+ t, jc t, jd ƒ |  _e |  j+ t, jf t, jg ƒ |  _h |  j+ t, ji t, jj ƒ |  _k |  j+ t, jl t, jm ƒ |  _n |  j+ t, jo t, jp ƒ |  _q |  j+ t, jr t, js ƒ |  _t |  j+ t, ju t, jv ƒ |  _w |  _x |  j+ t, jy t, jz ƒ |  _{ |  j+ t, j| t, j} ƒ |  _~ |  j+ t, j t, j€ ƒ |  _ |  j+ t, j‚ t, jƒ ƒ |  _„ |  _… |  j+ t, j† t, j‡ ƒ |  _ˆ |  j+ t, j‰ t, jŠ ƒ |  _‹ |  _Œ |  j+ t, j t, jŽ ƒ |  _ |  j+ t, j t, j‘ ƒ |  _’ |  j+ t, j“ t, j” ƒ |  _• |  j+ t, j– t, j— ƒ |  _˜ |  j+ t, j™ t, jš ƒ |  _› |  j+ t, jœ t, j ƒ |  _ž |  j+ t, jŸ t, j  ƒ |  _¡ |  j+ t, j¢ t, j£ ƒ |  _¤ |  j+ t, j¥ t, j¦ ƒ |  _§ |  j+ t, j¨ d  ƒ |  _ª |  j+ t, j« d  ƒ |  _¬ |  j+ t, j­ t, j® ƒ |  _¯ |  j+ t, j° t, j± ƒ |  _² t³ |  d |  j/ ƒ |  _/ t³ |  d |  j; ƒ |  _; t³ |  d |  j5 ƒ |  _5 t³ |  d  |  jG ƒ |  _G t³ |  d! |  jD ƒ |  _D d  S("   Nc         S   s   d t  d |  d f S(   Ni    i   (   R   (   t   prect   rnd(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   <lambda>k   s    s   epsilon of working precisiont   epst   pis   ln(2)t   ln2s   ln(10)t   ln10s   Golden ratio phit   phis
   e = exp(1)t   es   Euler's constantt   eulers   Catalan's constantt   catalans   Khinchin's constantt   khinchins   Glaisher's constantt   glaishers   Apery's constantt   aperys   1 deg = pi / 180t   degrees   Twin prime constantt	   twinprimes   Mertens' constantt   mertenst
   _sage_sqrtt	   _sage_expt   _sage_lnt	   _sage_cost	   _sage_sin(´   Rh   Ri   t   make_mpfR   t   oneR   t   zerot   make_mpct   jR   t   infR   t   ninfR   t   nanRj   R   RL   R‚   RP   Rƒ   RQ   R„   RO   R…   RN   R†   RR   R‡   RS   Rˆ   RU   R‰   RV   RŠ   RT   R‹   RM   RŒ   RW   R   RX   RŽ   t   _wrap_libmp_functionR   t   mpf_sqrtt   mpc_sqrtt   sqrtt   mpf_cbrtt   mpc_cbrtt   cbrtt   mpf_logt   mpc_logt   lnt   mpf_atant   mpc_atant   atant   mpf_expt   mpc_expt   expt   mpf_expjt   mpc_expjt   expjt
   mpf_expjpit
   mpc_expjpit   expjpit   mpf_sint   mpc_sint   sint   mpf_cost   mpc_cost   cost   mpf_tant   mpc_tant   tant   mpf_sinht   mpc_sinht   sinht   mpf_cosht   mpc_cosht   cosht   mpf_tanht   mpc_tanht   tanht   mpf_asint   mpc_asint   asint   mpf_acost   mpc_acost   acost	   mpf_asinht	   mpc_asinht   asinht	   mpf_acosht	   mpc_acosht   acosht	   mpf_atanht	   mpc_atanht   atanht
   mpf_sin_pit
   mpc_sin_piR|   t
   mpf_cos_pit
   mpc_cos_piR{   t	   mpf_floort	   mpc_floort   floort   mpf_ceilt   mpc_ceilt   ceilt   mpf_nintt   mpc_nintt   nintt   mpf_fract   mpc_fract   fract   mpf_fibonaccit   mpc_fibonaccit   fibt	   fibonaccit	   mpf_gammat	   mpc_gammat   gammat
   mpf_rgammat
   mpc_rgammat   rgammat   mpf_loggammat   mpc_loggammat   loggammat   mpf_factorialt   mpc_factorialt   fact	   factorialt   mpf_gamma_oldt   mpc_gamma_oldt	   gamma_oldt   mpf_factorial_oldt   mpc_factorial_oldt   fac_oldt   factorial_oldt   mpf_psi0t   mpc_psi0Rz   t   mpf_harmonict   mpc_harmonict   harmonict   mpf_eit   mpc_eit   eit   mpf_e1t   mpc_e1t   e1t   mpf_cit   mpc_cit   _cit   mpf_sit   mpc_sit   _sit
   mpf_ellipkt
   mpc_ellipkt   ellipkt
   mpf_ellipet
   mpc_ellipet   _ellipet   mpf_agm1t   mpc_agm1t   agm1t   mpf_erft   Nonet   _erft   mpf_erfct   _erfct   mpf_zetat   mpc_zetat   _zetat   mpf_altzetat   mpc_altzetat   _altzetat   getattr(   R}   Rh   Ri   R   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRo   ^   s”    			"""c         C   s   | j  | ƒ S(   N(   R5   (   R}   t   xR~   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR5   ¶   s    c         C   sC   |  j  | ƒ } |  j  | ƒ } |  j t j | j | j |  j Œ ƒ S(   s€   
        Computes the Euclidean norm of the vector `(x, y)`, equal
        to `\sqrt{x^2 + y^2}`. Both `x` and `y` must be real.(   t   convertR”   R   t	   mpf_hypott   _mpf_t   _prec_rounding(   R}   R!  t   y(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   hypot¹   s    c         C   s¬   t  |  j | ƒ ƒ } | d k r. |  j | ƒ St | d ƒ sF t ‚ n  |  j \ } } t j | | j | | d t	 ƒ\ } } | d  k r• |  j | ƒ S|  j | | f ƒ Sd  S(   Ni    R$  Ré   (   t   intt   _reR  t   hasattrt   NotImplementedErrorR%  R   t
   mpf_expintR$  t   TrueR  R”   R—   (   R}   t   nt   zR~   t   roundingt   realt   imag(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _gamma_upper_intÁ   s    	'c         C   s   t  | ƒ } | d k r% |  j | ƒ St | d ƒ s= t ‚ n  |  j \ } } t j | | j | | ƒ \ } } | d  k r† |  j	 | ƒ S|  j
 | | f ƒ Sd  S(   Ni   R$  (   R(  R  R*  R+  R%  R   R,  R$  R  R”   R—   (   R}   R.  R/  R~   R0  R1  R2  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _expint_intÎ   s    	!c         C   s•   t  | d ƒ rm y& |  j t j | j | |  j Œ ƒ SWqv t k
 ri |  j rT ‚  n  | j t j f } qv Xn	 | j	 } |  j
 t j | | |  j Œ ƒ S(   NR$  (   R*  R”   R   t   mpf_nthrootR$  R%  R   Rf   R   t   _mpc_R—   t   mpc_nthroot(   R}   R!  R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _nthrootÛ   s    &		c         C   su   |  j  \ } } t | d ƒ r@ |  j t j | | j | | ƒ ƒ St | d ƒ rq |  j t j | | j | | ƒ ƒ Sd  S(   NR$  R6  (	   R%  R*  R”   R   t   mpf_besseljnR$  R—   t   mpc_besseljnR6  (   R}   R.  R/  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _besseljç   s
    "i   c         C   sì   |  j  \ } } t | d ƒ rs t | d ƒ rs y/ t j | j | j | | ƒ } |  j | ƒ SWqs t k
 ro qs Xn  t | d ƒ r— | j t j f } n	 | j } t | d ƒ rÄ | j t j f } n	 | j } |  j	 t j
 | | | | ƒ ƒ S(   NR$  (   R%  R*  R   t   mpf_agmR$  R”   R   R   R6  R—   t   mpc_agm(   R}   t   at   bR~   R0  t   v(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _agmî   s     	 	c         C   s"   |  j  t j t | ƒ |  j Œ ƒ S(   N(   R”   R   t   mpf_bernoulliR(  R%  (   R}   R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRr   ü   s    c         C   s"   |  j  t j t | ƒ |  j Œ ƒ S(   N(   R”   R   t   mpf_zeta_intR(  R%  (   R}   R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt	   _zeta_intÿ   s    c         C   sC   |  j  | ƒ } |  j  | ƒ } |  j t j | j | j |  j Œ ƒ S(   N(   R"  R”   R   t	   mpf_atan2R$  R%  (   R}   R&  R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRw     s    c         C   sr   |  j  | ƒ } t | ƒ } |  j | ƒ rL |  j t j | | j |  j Œ ƒ S|  j t j	 | | j
 |  j Œ ƒ Sd  S(   N(   R"  R(  t   _is_real_typeR”   R   t   mpf_psiR$  R%  R—   t   mpc_psiR6  (   R}   t   mR/  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRv     s
    "c         K   sô   t  | ƒ |  j k r' |  j | ƒ } n  |  j | ƒ \ } } t | d ƒ r… t j | j | | ƒ \ } } |  j | ƒ |  j | ƒ f St | d ƒ rÎ t j	 | j
 | | ƒ \ } } |  j | ƒ |  j | ƒ f S|  j | |  |  j | |  f Sd  S(   NR$  R6  (   t   typeRk   R"  t   _parse_precR*  R   t   mpf_cos_sinR$  R”   t   mpc_cos_sinR6  R—   R·   R´   (   R}   R!  t   kwargsR~   R0  t   ct   s(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   cos_sin  s    c         K   sô   t  | ƒ |  j k r' |  j | ƒ } n  |  j | ƒ \ } } t | d ƒ r… t j | j | | ƒ \ } } |  j | ƒ |  j | ƒ f St | d ƒ rÎ t j	 | j
 | | ƒ \ } } |  j | ƒ |  j | ƒ f S|  j | |  |  j | |  f Sd  S(   NR$  R6  (   RJ  Rk   R"  RK  R*  R   t   mpf_cos_sin_piR$  R”   t   mpc_cos_sin_piR6  R—   R·   R´   (   R}   R!  RN  R~   R0  RO  RP  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   cospi_sinpi  s    c         C   s   |  j  ƒ  } |  j | _ | S(   sP   
        Create a copy of the context, with the same working precision.
        (   t	   __class__R~   (   R}   R>  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   clone)  s    c         C   s)   t  | d ƒ s! t | ƒ t k r% t St S(   NR6  (   R*  RJ  t   complexRe   R-  (   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRF  4  s    !c         C   s)   t  | d ƒ s! t | ƒ t k r% t St S(   NR6  (   R*  RJ  RW  R-  Re   (   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _is_complex_type9  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

        R$  R6  s   isnan() needs a number as inputN(   R*  R$  R   R6  t
   isinstanceR   RZ   Rl   Re   R"  t   isnant	   TypeError(   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRZ  >  s    !c         C   s&   |  j  | ƒ s |  j | ƒ r" t St S(   sè  
        Return *True* if *x* is a finite number, i.e. neither
        an infinity or a NaN.

            >>> from mpmath import *
            >>> isfinite(inf)
            False
            >>> isfinite(-inf)
            False
            >>> isfinite(3)
            True
            >>> isfinite(nan)
            False
            >>> isfinite(3+4j)
            True
            >>> isfinite(mpc(3,inf))
            False
            >>> isfinite(mpc(nan,3))
            False

        (   t   isinfRZ  Re   R-  (   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   isfiniteZ  s    c         C   sÚ   | s
 t  St | d ƒ r> | j \ } } } } | o= | d k St | d ƒ rg | j of |  j | j ƒ St | ƒ t k rƒ | d k St | |  j	 ƒ rÄ | j
 \ } } | s® t  S| d k oÃ | d k S|  j |  j | ƒ ƒ S(   s<   
        Determine if *x* is a nonpositive integer.
        R$  i    R6  i   (   R-  R*  R$  R2  t   isnpintR1  RJ  R   RY  Rl   t   _mpq_R"  (   R}   R!  t   signt   manR«   t   bct   pt   q(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR^  t  s    
c         C   s[   d d |  j  j d ƒ d d |  j j d ƒ d d |  j j d ƒ d g } d	 j | ƒ S(
   Ns   Mpmath settings:s     mp.prec = %si   s   [default: 53]s     mp.dps = %ss   [default: 15]s     mp.trap_complex = %ss   [default: False]s   
(   R~   t   ljustt   dpsRf   t   join(   R}   t   lines(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   __str__ˆ  s
    c         C   s   t  |  j ƒ S(   N(   R	   t   _prec(   R}   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _repr_digits  s    c         C   s   |  j  S(   N(   t   _dps(   R}   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _str_digits”  s    c            s   t  |  ‡  f d †  d | ƒ S(   sÛ  
        The block

            with extraprec(n):
                <code>

        increases the precision n bits, executes <code>, and then
        restores the precision.

        extraprec(n)(f) returns a decorated version of the function f
        that increases the working precision by n bits before execution,
        and restores the parent precision afterwards. With
        normalize_output=True, it rounds the return value to the parent
        precision.
        c            s   |  ˆ  S(   N(    (   Rc  (   R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR€   ¨  s    N(   t   PrecisionManagerR  (   R}   R.  t   normalize_output(    (   R.  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt	   extraprec˜  s    c            s   t  |  d ‡  f d †  | ƒ S(   s–   
        This function is analogous to extraprec (see documentation)
        but changes the decimal precision instead of the number of bits.
        c            s   |  ˆ  S(   N(    (   t   d(   R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR€   ¯  s    N(   Rn  R  (   R}   R.  Ro  (    (   R.  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   extradpsª  s    c            s   t  |  ‡  f d †  d | ƒ S(   s»  
        The block

            with workprec(n):
                <code>

        sets the precision to n bits, executes <code>, and then restores
        the precision.

        workprec(n)(f) returns a decorated version of the function f
        that sets the precision to n bits before execution,
        and restores the precision afterwards. With normalize_output=True,
        it rounds the return value to the parent precision.
        c            s   ˆ  S(   N(    (   Rc  (   R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR€   À  s    N(   Rn  R  (   R}   R.  Ro  (    (   R.  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   workprec±  s    c            s   t  |  d ‡  f d †  | ƒ S(   s•   
        This function is analogous to workprec (see documentation)
        but changes the decimal precision instead of the number of bits.
        c            s   ˆ  S(   N(    (   Rq  (   R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR€   Ç  s    N(   Rn  R  (   R}   R.  Ro  (    (   R.  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   workdpsÂ  s    c            s   ‡  ‡ ‡ ‡ ‡ f d †  } | S(   s‹
  
        Return a wrapped copy of *f* that repeatedly evaluates *f*
        with increasing precision until the result converges to the
        full precision used at the point of the call.

        This heuristically protects against rounding errors, at the cost of
        roughly a 2x slowdown compared to manually setting the optimal
        precision. This method can, however, easily be fooled if the results
        from *f* depend "discontinuously" on the precision, for instance
        if catastrophic cancellation can occur. Therefore, :func:`~mpmath.autoprec`
        should be used judiciously.

        **Examples**

        Many functions are sensitive to perturbations of the input arguments.
        If the arguments are decimal numbers, they may have to be converted
        to binary at a much higher precision. If the amount of required
        extra precision is unknown, :func:`~mpmath.autoprec` is convenient::

            >>> from mpmath import *
            >>> mp.dps = 15
            >>> mp.pretty = True
            >>> besselj(5, 125 * 10**28)    # Exact input
            -8.03284785591801e-17
            >>> besselj(5, '1.25e30')   # Bad
            7.12954868316652e-16
            >>> autoprec(besselj)(5, '1.25e30')   # Good
            -8.03284785591801e-17

        The following fails to converge because `\sin(\pi) = 0` whereas all
        finite-precision approximations of `\pi` give nonzero values::

            >>> autoprec(sin)(pi) # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
              ...
            NoConvergence: autoprec: prec increased to 2910 without convergence

        As the following example shows, :func:`~mpmath.autoprec` can protect against
        cancellation, but is fooled by too severe cancellation::

            >>> x = 1e-10
            >>> exp(x)-1; expm1(x); autoprec(lambda t: exp(t)-1)(x)
            1.00000008274037e-10
            1.00000000005e-10
            1.00000000005e-10
            >>> x = 1e-50
            >>> exp(x)-1; expm1(x); autoprec(lambda t: exp(t)-1)(x)
            0.0
            1.0e-50
            0.0

        With *catch*, an exception or list of exceptions to intercept
        may be specified. The raised exception is interpreted
        as signaling insufficient precision. This permits, for example,
        evaluating a function where a too low precision results in a
        division by zero::

            >>> f = lambda x: 1/(exp(x)-1)
            >>> f(1e-30)
            Traceback (most recent call last):
              ...
            ZeroDivisionError
            >>> autoprec(f, catch=ZeroDivisionError)(1e-30)
            1.0e+30


        c             sr  ˆ j  } ˆ d  k r' ˆ j | ƒ } n ˆ } z3| d ˆ _  y ˆ |  | Ž  } Wn ˆ  k
 rl ˆ j } n X| d } xå | ˆ _  y ˆ |  | Ž  } Wn ˆ  k
 r² ˆ j } n X| | k rÃ Pn  ˆ j | | ƒ ˆ j | ƒ } | | k  rô Pn  ˆ rd | | | f GHn  | } | | k r8ˆ j d | ƒ ‚ n  | t | d ƒ 7} t | | ƒ } qz WWd  | ˆ _  X| 
S(   Ni
   i   s)   autoprec: target=%s, prec=%s, accuracy=%ss2   autoprec: prec increased to %i without convergencei   (   R~   R  t   _default_hyper_maxprecR›   t   magt   NoConvergenceR(  t   min(   t   argsRN  R~   t   maxprec2t   v1t   prec2t   v2t   err(   t   catchR}   t   ft   maxprect   verbose(    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   f_autoprec_wrapped  sD    	
	 
(    (   R}   R€  R  R  R‚  Rƒ  (    (   R  R}   R€  R  R‚  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   autoprecÉ  s    D%i   c            sý   t  | t ƒ r6 d d j ‡  ‡ ‡ f d †  | Dƒ ƒ St  | t ƒ rl d d j ‡  ‡ ‡ f d †  | Dƒ ƒ St | d ƒ rŽ t | j ˆ ˆ  St | d ƒ r¸ d t | j ˆ ˆ  d	 St  | t	 ƒ rÑ t
 | ƒ St  | ˆ  j ƒ ró | j ˆ ˆ  St | ƒ S(
   s3  
        Convert an ``mpf`` or ``mpc`` to a decimal string literal with *n*
        significant digits. The small default value for *n* is chosen to
        make this function useful for printing collections of numbers
        (lists, matrices, etc).

        If *x* is a list or tuple, :func:`~mpmath.nstr` is applied recursively
        to each element. For unrecognized classes, :func:`~mpmath.nstr`
        simply returns ``str(x)``.

        The companion function :func:`~mpmath.nprint` prints the result
        instead of returning it.

        The keyword arguments *strip_zeros*, *min_fixed*, *max_fixed*
        and *show_zero_exponent* are forwarded to :func:`~mpmath.libmp.to_str`.

        The number will be printed in fixed-point format if the position
        of the leading digit is strictly between min_fixed
        (default = min(-dps/3,-5)) and max_fixed (default = dps).

        To force fixed-point format always, set min_fixed = -inf,
        max_fixed = +inf. To force floating-point format, set
        min_fixed >= max_fixed.

            >>> from mpmath import *
            >>> nstr([+pi, ldexp(1,-500)])
            '[3.14159, 3.05494e-151]'
            >>> nprint([+pi, ldexp(1,-500)])
            [3.14159, 3.05494e-151]
            >>> nstr(mpf("5e-10"), 5)
            '5.0e-10'
            >>> nstr(mpf("5e-10"), 5, strip_zeros=False)
            '5.0000e-10'
            >>> nstr(mpf("5e-10"), 5, strip_zeros=False, min_fixed=-11)
            '0.00000000050000'
            >>> nstr(mpf(0), 5, show_zero_exponent=True)
            '0.0e+0'

        s   [%s]s   , c         3   s$   |  ] } ˆ  j  | ˆ ˆ  Vq d  S(   N(   t   nstr(   t   .0RO  (   R}   RN  R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pys	   <genexpr>]  s    s   (%s)c         3   s$   |  ] } ˆ  j  | ˆ ˆ  Vq d  S(   N(   R…  (   R†  RO  (   R}   RN  R.  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pys	   <genexpr>_  s    R$  R6  t   (t   )(   RY  t   listRg  t   tupleR*  R   R$  R6   R6  R   t   reprt   matrixt   __nstr__t   str(   R}   R!  R.  RN  (    (   R}   RN  R.  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR…  4  s    (''
c         C   s	  | r© t  | t ƒ r© d | j ƒ  k r© | j ƒ  j d d ƒ } t j | ƒ } | j d ƒ } | sl d } n  | j d ƒ j d ƒ } |  j |  j	 | ƒ |  j	 | ƒ ƒ Sn  t
 | d ƒ rï | j \ } } | | k rà |  j | ƒ St d ƒ ‚ n  t d	 t | ƒ ƒ ‚ d  S(
   NR˜   t    t    t   rei    t   imt   _mpi_s,   can only create mpf from zero-width intervals   cannot create mpf from (   RY  R   t   lowert   replacet   get_complext   matcht   groupt   rstripRi   R"  R*  R“  R”   t
   ValueErrorR[  R‹  (   R}   R!  t   stringsR—  R‘  R’  R>  R?  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _convert_fallbackj  s    	%c         O   s   |  j  | | Ž  S(   N(   R"  (   R}   Ry  RN  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt	   mpmathify|  s    c         C   sÂ   | r» | j  d ƒ r d S|  j \ } } d | k rA | d } n  d | k ry | d } | |  j k rj d St | ƒ } n8 d | k r± | d } | |  j k r¢ d	 St | ƒ } n  | | f S|  j S(
   Nt   exacti    R€  R0  R~   Rf  (   i    R€  (   i    R€  (   i    R€  (   t   getR%  R™   R(  R   (   R}   RN  R~   R0  Rf  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRK    s$    


s'   the exact result does not fit in memorysœ   hypsum() failed to converge to the requested %i bits of accuracy
using a working precision of %i bits. Try with a higher maxprec,
maxterms, or set zeroprec.c   !      K   sØ  t  | d ƒ r- | | | d f } | j }	 n- t  | d ƒ rZ | | | d f } | j }	 n  | |  j k r† t j | ƒ d |  j | <n  |  j | }
 |  j } | j d |  j | ƒ ƒ } d } d } i  } d	 } xXt	 | ƒ D]J\ } } | | d
 k r†| | k rÜ | d	 k rÜ t
 } xO t	 | |  ƒ D]= \ } } | | d
 k r'| d	 k r'| | k r't } q'q'W| s€t d ƒ ‚ q€qÜ qÜ n  |  j | ƒ \ } } t | ƒ } | } | | k r| d	 k r| d k r| | k rò| | c | 7<n
 | | | <t | | | d ƒ } n  | t | ƒ 7} qÜ Wxn| | k rYt |  j | | | f ƒ ‚ n  | | } | r‚t d „  | Dƒ ƒ } n i  } |
 | |	 | | | | |  \ } } } | } t } | | k  rx9 | j ƒ  D]( } | d  k só| | k  rÕt
 } PqÕqÕWn  | | d d k  p| } | ry| r/Pn  | j d ƒ }  |  d  k	 ry| |  k rv| ri|  j d	 ƒ S|  j Sqvqyn  | d 9} | d 7} | d 7} q-Wt | ƒ t k rÐ| rÀ|  j | ƒ S|  j | ƒ Sn | Sd  S(   NR$  t   RR6  t   Ci   R  i2   i   i    t   Zs   pole in hypergeometric seriesi   i<   c         s   s   |  ] } | d  f Vq d  S(   N(   R  (   R†  R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pys	   <genexpr>Ç  s    i   t   zeropreci   (   R*  R$  R6  Rp   R   t   make_hyp_summatorR~   RŸ  Ru  t	   enumerateRe   R-  t   ZeroDivisionErrort   nint_distanceR(  t   maxt   absRš  t   _hypsum_msgt   dictt   valuesR  Ri   R–   RJ  RŠ  R—   R”   (!   R}   Rc  Rd  t   flagst   coeffsR/  t   accurate_smallRN  t   keyR@  t   summatorR~   R  Rp  t   epsshiftt   magnitude_checkt   max_total_jumpt   iRO  t   okt   iit   ccR.  Rq  t   wpt   mag_dictt   zvt   have_complext	   magnitudet   cancelt   jumps_resolvedt   accurateR£  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   hypsumš  sˆ    	($
 


c         C   s+   |  j  | ƒ } |  j t j | j | ƒ ƒ S(   s–  
        Computes `x 2^n` efficiently. No rounding is performed.
        The argument `x` must be a real floating-point number (or
        possible to convert into one) and `n` must be a Python ``int``.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> ldexp(1, 10)
            mpf('1024.0')
            >>> ldexp(1, -3)
            mpf('0.125')

        (   R"  R”   R   t	   mpf_shiftR$  (   R}   R!  R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   ldexpï  s    c         C   s:   |  j  | ƒ } t j | j ƒ \ } } |  j | ƒ | f S(   s=  
        Given a real number `x`, returns `(y, n)` with `y \in [0.5, 1)`,
        `n` a Python integer, and such that `x = y 2^n`. No rounding is
        performed.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> frexp(7.5)
            (mpf('0.9375'), 3)

        (   R"  R   t	   mpf_frexpR$  R”   (   R}   R!  R&  R.  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   frexp   s    c         K   sŠ   |  j  | ƒ \ } } |  j | ƒ } t | d ƒ rO |  j t | j | | ƒ ƒ St | d ƒ rz |  j t | j | | ƒ ƒ St	 d ƒ ‚ d S(   s  
        Negates the number *x*, giving a floating-point result, optionally
        using a custom precision and rounding mode.

        See the documentation of :func:`~mpmath.fadd` for a detailed description
        of how to specify precision and rounding.

        **Examples**

        An mpmath number is returned::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fneg(2.5)
            mpf('-2.5')
            >>> fneg(-5+2j)
            mpc(real='5.0', imag='-2.0')

        Precise control over rounding is possible::

            >>> x = fadd(2, 1e-100, exact=True)
            >>> fneg(x)
            mpf('-2.0')
            >>> fneg(x, rounding='f')
            mpf('-2.0000000000000004')

        Negating with and without roundoff::

            >>> n = 200000000000000000000001
            >>> print(int(-mpf(n)))
            -200000000000000016777216
            >>> print(int(fneg(n)))
            -200000000000000016777216
            >>> print(int(fneg(n, prec=log(n,2)+1)))
            -200000000000000000000001
            >>> print(int(fneg(n, dps=log(n,10)+1)))
            -200000000000000000000001
            >>> print(int(fneg(n, prec=inf)))
            -200000000000000000000001
            >>> print(int(fneg(n, dps=inf)))
            -200000000000000000000001
            >>> print(int(fneg(n, exact=True)))
            -200000000000000000000001

        R$  R6  s2   Arguments need to be mpf or mpc compatible numbersN(
   RK  R"  R*  R”   R"   R$  R—   R;   R6  Rš  (   R}   R!  RN  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fneg  s    .c         K   sX  |  j  | ƒ \ } } |  j | ƒ } |  j | ƒ } yì t | d ƒ rª t | d ƒ rv |  j t | j | j | | ƒ ƒ St | d ƒ rª |  j t | j | j | | ƒ ƒ Sn  t | d ƒ rt | d ƒ rê |  j t | j | j | | ƒ ƒ St | d ƒ r|  j t	 | j | j | | ƒ ƒ Sn  Wn& t
 t f k
 rGt |  j ƒ ‚ n Xt
 d ƒ ‚ d S(   s“  
        Adds the numbers *x* and *y*, giving a floating-point result,
        optionally using a custom precision and rounding mode.

        The default precision is the working precision of the context.
        You can specify a custom precision in bits by passing the *prec* keyword
        argument, or by providing an equivalent decimal precision with the *dps*
        keyword argument. If the precision is set to ``+inf``, or if the flag
        *exact=True* is passed, an exact addition with no rounding is performed.

        When the precision is finite, the optional *rounding* keyword argument
        specifies the direction of rounding. Valid options are ``'n'`` for
        nearest (default), ``'f'`` for floor, ``'c'`` for ceiling, ``'d'``
        for down, ``'u'`` for up.

        **Examples**

        Using :func:`~mpmath.fadd` with precision and rounding control::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fadd(2, 1e-20)
            mpf('2.0')
            >>> fadd(2, 1e-20, rounding='u')
            mpf('2.0000000000000004')
            >>> nprint(fadd(2, 1e-20, prec=100), 25)
            2.00000000000000000001
            >>> nprint(fadd(2, 1e-20, dps=15), 25)
            2.0
            >>> nprint(fadd(2, 1e-20, dps=25), 25)
            2.00000000000000000001
            >>> nprint(fadd(2, 1e-20, exact=True), 25)
            2.00000000000000000001

        Exact addition avoids cancellation errors, enforcing familiar laws
        of numbers such as `x+y-x = y`, which don't hold in floating-point
        arithmetic with finite precision::

            >>> x, y = mpf(2), mpf('1e-1000')
            >>> print(x + y - x)
            0.0
            >>> print(fadd(x, y, prec=inf) - x)
            1.0e-1000
            >>> print(fadd(x, y, exact=True) - x)
            1.0e-1000

        Exact addition can be inefficient and may be impossible to perform
        with large magnitude differences::

            >>> fadd(1, '1e-100000000000000000000', prec=inf)
            Traceback (most recent call last):
              ...
            OverflowError: the exact result does not fit in memory

        R$  R6  s2   Arguments need to be mpf or mpc compatible numbersN(   RK  R"  R*  R”   R#   R$  R—   R?   R6  R>   Rš  t   OverflowErrort   _exact_overflow_msg(   R}   R!  R&  RN  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   faddF  s"    8"%")c         K   s^  |  j  | ƒ \ } } |  j | ƒ } |  j | ƒ } yò t | d ƒ r° t | d ƒ rv |  j t | j | j | | ƒ ƒ St | d ƒ r° |  j t | j t f | j	 | | ƒ ƒ Sn  t | d ƒ r$t | d ƒ rð |  j t
 | j	 | j | | ƒ ƒ St | d ƒ r$|  j t | j	 | j	 | | ƒ ƒ Sn  Wn& t t f k
 rMt |  j ƒ ‚ n Xt d ƒ ‚ d S(   s  
        Subtracts the numbers *x* and *y*, giving a floating-point result,
        optionally using a custom precision and rounding mode.

        See the documentation of :func:`~mpmath.fadd` for a detailed description
        of how to specify precision and rounding.

        **Examples**

        Using :func:`~mpmath.fsub` with precision and rounding control::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fsub(2, 1e-20)
            mpf('2.0')
            >>> fsub(2, 1e-20, rounding='d')
            mpf('1.9999999999999998')
            >>> nprint(fsub(2, 1e-20, prec=100), 25)
            1.99999999999999999999
            >>> nprint(fsub(2, 1e-20, dps=15), 25)
            2.0
            >>> nprint(fsub(2, 1e-20, dps=25), 25)
            1.99999999999999999999
            >>> nprint(fsub(2, 1e-20, exact=True), 25)
            1.99999999999999999999

        Exact subtraction avoids cancellation errors, enforcing familiar laws
        of numbers such as `x-y+y = x`, which don't hold in floating-point
        arithmetic with finite precision::

            >>> x, y = mpf(2), mpf('1e1000')
            >>> print(x - y + y)
            0.0
            >>> print(fsub(x, y, prec=inf) + y)
            2.0
            >>> print(fsub(x, y, exact=True) + y)
            2.0

        Exact addition can be inefficient and may be impossible to perform
        with large magnitude differences::

            >>> fsub(1, '1e-100000000000000000000', prec=inf)
            Traceback (most recent call last):
              ...
            OverflowError: the exact result does not fit in memory

        R$  R6  s2   Arguments need to be mpf or mpc compatible numbersN(   RK  R"  R*  R”   R$   R$  R—   R@   R   R6  RA   Rš  RÇ  RÈ  (   R}   R!  R&  RN  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fsub  s"    0"+")c         K   sX  |  j  | ƒ \ } } |  j | ƒ } |  j | ƒ } yì t | d ƒ rª t | d ƒ rv |  j t | j | j | | ƒ ƒ St | d ƒ rª |  j t | j | j | | ƒ ƒ Sn  t | d ƒ rt | d ƒ rê |  j t | j | j | | ƒ ƒ St | d ƒ r|  j t	 | j | j | | ƒ ƒ Sn  Wn& t
 t f k
 rGt |  j ƒ ‚ n Xt
 d ƒ ‚ d S(   s¥  
        Multiplies the numbers *x* and *y*, giving a floating-point result,
        optionally using a custom precision and rounding mode.

        See the documentation of :func:`~mpmath.fadd` for a detailed description
        of how to specify precision and rounding.

        **Examples**

        The result is an mpmath number::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fmul(2, 5.0)
            mpf('10.0')
            >>> fmul(0.5j, 0.5)
            mpc(real='0.0', imag='0.25')

        Avoiding roundoff::

            >>> x, y = 10**10+1, 10**15+1
            >>> print(x*y)
            10000000001000010000000001
            >>> print(mpf(x) * mpf(y))
            1.0000000001e+25
            >>> print(int(mpf(x) * mpf(y)))
            10000000001000011026399232
            >>> print(int(fmul(x, y)))
            10000000001000011026399232
            >>> print(int(fmul(x, y, dps=25)))
            10000000001000010000000001
            >>> print(int(fmul(x, y, exact=True)))
            10000000001000010000000001

        Exact multiplication with complex numbers can be inefficient and may
        be impossible to perform with large magnitude differences between
        real and imaginary parts::

            >>> x = 1+2j
            >>> y = mpc(2, '1e-100000000000000000000')
            >>> fmul(x, y)
            mpc(real='2.0', imag='4.0')
            >>> fmul(x, y, rounding='u')
            mpc(real='2.0', imag='4.0000000000000009')
            >>> fmul(x, y, exact=True)
            Traceback (most recent call last):
              ...
            OverflowError: the exact result does not fit in memory

        R$  R6  s2   Arguments need to be mpf or mpc compatible numbersN(   RK  R"  R*  R”   R%   R$  R—   RC   R6  RB   Rš  RÇ  RÈ  (   R}   R!  R&  RN  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fmulÒ  s"    3"%")c         K   sF  |  j  | ƒ \ } } | s* t d ƒ ‚ n  |  j | ƒ } |  j | ƒ } t | d ƒ rÂ t | d ƒ rˆ |  j t | j | j | | ƒ ƒ St | d ƒ rÂ |  j t | j t	 f | j
 | | ƒ ƒ Sn  t | d ƒ r6t | d ƒ r|  j t | j
 | j | | ƒ ƒ St | d ƒ r6|  j t | j
 | j
 | | ƒ ƒ Sn  t d ƒ ‚ d S(   s©  
        Divides the numbers *x* and *y*, giving a floating-point result,
        optionally using a custom precision and rounding mode.

        See the documentation of :func:`~mpmath.fadd` for a detailed description
        of how to specify precision and rounding.

        **Examples**

        The result is an mpmath number::

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> fdiv(3, 2)
            mpf('1.5')
            >>> fdiv(2, 3)
            mpf('0.66666666666666663')
            >>> fdiv(2+4j, 0.5)
            mpc(real='4.0', imag='8.0')

        The rounding direction and precision can be controlled::

            >>> fdiv(2, 3, dps=3)    # Should be accurate to at least 3 digits
            mpf('0.6666259765625')
            >>> fdiv(2, 3, rounding='d')
            mpf('0.66666666666666663')
            >>> fdiv(2, 3, prec=60)
            mpf('0.66666666666666667')
            >>> fdiv(2, 3, rounding='u')
            mpf('0.66666666666666674')

        Checking the error of a division by performing it at higher precision::

            >>> fdiv(2, 3) - fdiv(2, 3, prec=100)
            mpf('-3.7007434154172148e-17')

        Unlike :func:`~mpmath.fadd`, :func:`~mpmath.fmul`, etc., exact division is not
        allowed since the quotient of two floating-point numbers generally
        does not have an exact floating-point representation. (In the
        future this might be changed to allow the case where the division
        is actually exact.)

            >>> fdiv(2, 3, exact=True)
            Traceback (most recent call last):
              ...
            ValueError: division is not an exact operation

        s"   division is not an exact operationR$  R6  s2   Arguments need to be mpf or mpc compatible numbersN(   RK  Rš  R"  R*  R”   R'   R$  R—   RE   R   R6  RF   (   R}   R!  R&  RN  R~   R0  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fdiv  s     1"+"%c         C   sÄ  t  | ƒ } | t k r+ t | ƒ |  j f S| t j k r¼ | j \ } } t | | ƒ \ } } d | | k r{ | d 7} n | sŽ | |  j f St t	 | | | ƒ ƒ t | ƒ } | | f St
 | d ƒ rà | j } |  j }	 n° t
 | d ƒ rJ| j \ } }
 |
 \ } } } } | r#| | }	 q|
 t k r;|  j }	 qt d ƒ ‚ nF |  j | ƒ } t
 | d ƒ swt
 | d ƒ r„|  j | ƒ St d ƒ ‚ | \ } } } } | | } | d k  rÇd } | } nê | r‡| d k rï| | >} |  j } n… | d k r| d ?d } d } nb | d } | | ?} | d @rL| d 7} | | >| } n | | | >8} | d ?} | t | ƒ } | r±| } q±n* | t k r¥|  j } d } n t d ƒ ‚ | t | |	 ƒ f S(	   sº  
        Return `(n,d)` where `n` is the nearest integer to `x` and `d` is
        an estimate of `\log_2(|x-n|)`. If `d < 0`, `-d` gives the precision
        (measured in bits) lost to cancellation when computing `x-n`.

            >>> from mpmath import *
            >>> n, d = nint_distance(5)
            >>> print(n); print(d)
            5
            -inf
            >>> n, d = nint_distance(mpf(5))
            >>> print(n); print(d)
            5
            -inf
            >>> n, d = nint_distance(mpf(5.00000001))
            >>> print(n); print(d)
            5
            -26
            >>> n, d = nint_distance(mpf(4.99999999))
            >>> print(n); print(d)
            5
            -26
            >>> n, d = nint_distance(mpc(5,10))
            >>> print(n); print(d)
            5
            4
            >>> n, d = nint_distance(mpc(5,0.000001))
            >>> print(n); print(d)
            5
            -19

        i   i   R$  R6  s   requires a finite numbers   requires an mpf/mpci    iÿÿÿÿ(   RJ  R   R(  Rš   RZ   Rl   R_  t   divmodR4   R©  R*  R$  R6  R   Rš  R"  R§  R[  R¨  (   R}   R!  t   typxRc  Rd  R.  t   rRq  R‘  t   im_distR’  t   isignt   imant   iexpt   ibcR`  Ra  R«   Rb  Rv  t   re_distt   t(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR§  Y  sl    !$
	
	
	



		c         C   sC   |  j  } z( |  j } x | D] } | | 9} q WWd | |  _  X| 
S(   sT  
        Calculates a product containing a finite number of factors (for
        infinite products, see :func:`~mpmath.nprod`). The factors will be
        converted to mpmath numbers.

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

        N(   R~   R•   (   R}   t   factorst   origR@  Rc  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fprod»  s    		
c         C   s   |  j  t |  j ƒ ƒ S(   s·   
        Returns an ``mpf`` with value chosen randomly from `[0, 1)`.
        The number of randomly generated bits in the mantissa is equal
        to the working precision.
        (   R”   R2   Rj  (   R}   (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   randÐ  s    c            s&   |  j  ‡  ‡ f d †  d ˆ  ˆ f ƒ S(   s  
        Given Python integers `(p, q)`, returns a lazy ``mpf`` representing
        the fraction `p/q`. The value is updated with the precision.

            >>> from mpmath import *
            >>> mp.dps = 15
            >>> a = fraction(1,100)
            >>> b = mpf(1)/100
            >>> print(a); print(b)
            0.01
            0.01
            >>> mp.dps = 30
            >>> print(a); print(b)      # a will be accurate
            0.01
            0.0100000000000000002081668171172
            >>> mp.dps = 15
        c            s   t  ˆ  ˆ |  | ƒ S(   N(   R   (   R~   R   (   Rc  Rd  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyR€   ê  s    s   %s/%s(   Rj   (   R}   Rc  Rd  (    (   Rc  Rd  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   fractionØ  s    c         C   s   t  |  j | ƒ ƒ S(   N(   R©  R"  (   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   absminí  s    c         C   s   t  |  j | ƒ ƒ S(   N(   R©  R"  (   R}   R!  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   absmaxð  s    c         C   s>   t  | d ƒ r: | j \ } } |  j | ƒ |  j | ƒ g S| S(   NR“  (   R*  R“  R”   (   R}   R!  R>  R?  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt
   _as_pointsó  s    i    c         C   s±   |  j  | ƒ o t | d ƒ s' t ‚ n  t | ƒ } |  j } t j | j | | | | | ƒ \ } } g  | D] }	 |  j |	 ƒ ^ qj } g  | D] }
 |  j |
 ƒ ^ qŒ } | | f S(   NR6  (	   t   isintR*  R+  R(  Rj  R   t   mpc_zetasumR6  R—   (   R}   RP  R>  R.  t   derivativest   reflectR~   t   xst   ysR!  R&  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   _zetasum_fast  s    		'""N(    (:   t   __name__t
   __module__t   __doc__Rd   Ro   R5   R'  R3  R4  R8  R;  RA  Rr   RD  Rw   Rv   RQ  RT  RV  RF  RX  RZ  R]  R^  Ri  t   propertyRk  Rm  Re   Rp  Rr  Rs  Rt  R  R„  R…  Rœ  R  RK  RÈ  Rª  R-  RÁ  RÃ  RÅ  RÆ  RÉ  RÊ  RË  RÌ  R§  RÙ  RÚ  RÛ  RÜ  RÝ  RÞ  Rå  (    (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRb   8   sh   	!	X																			k6			U			6	J	B	E	B	b						Rn  c           B   s/   e  Z e d  „ Z d „  Z d „  Z d „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R}   t   precfunt   dpsfunRo  (   t   selfR}   Rê  Rë  Ro  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRd     s    			c            s.   ‡  ‡ f d †  } ˆ  j  | _  ˆ  j | _ | S(   Nc             sÀ   ˆ j  j } z  ˆ j r6 ˆ j ˆ j  j ƒ ˆ j  _ n ˆ j ˆ j  j ƒ ˆ j  _ ˆ j rž ˆ  |  | Ž  } t | ƒ t k r™ t g  | D] } | 
^ q… ƒ S| 
Sˆ  |  | Ž  SWd  | ˆ j  _ Xd  S(   N(   R}   R~   Rê  Rë  Rf  Ro  RJ  RŠ  (   Ry  RN  RØ  R@  R>  (   R€  Rì  (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   g  s    		(   Ræ  Rè  (   Rì  R€  Rí  (    (   R€  Rì  s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   __call__  s    c         C   sU   |  j  j |  _ |  j r6 |  j |  j  j ƒ |  j  _ n |  j |  j  j ƒ |  j  _ d  S(   N(   R}   R~   t   origpRê  Rë  Rf  (   Rì  (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt	   __enter__/  s    	c         C   s   |  j  |  j _ t S(   N(   Rï  R}   R~   Re   (   Rì  t   exc_typet   exc_valt   exc_tb(    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   __exit__5  s    (   Ræ  Rç  Re   Rd   Rî  Rð  Rô  (    (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyRn    s   		t   __main__(v   Rè  t   __docformat__R‘  t   ctx_baseR   t   libmp.backendR   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.   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   t   objectt   __new__t   newt   compileR–  t   sage.libs.mpmath.ext_mainR\   Rc   t   libst   mpmatht   ext_maint   _mpf_moduleR^   R]   R_   R`   Ra   Rb   Rn  Ræ  t   doctestt   testmod(    (    (    s,   lib/python2.7/site-packages/mpmath/ctx_mp.pyt   <module>   s6   ÿ ÿ 
	ÿ ÿ ÿ ÿ á%