+
    i,                        R t Rt^ RIt^ RIt^RIHt ^RIHtHt ^RI	H
t
 ^RI
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t=H>t>H?t?H@t@HAtAHBtBHCtCHDtDHEtEHFtFHGtGHHtHHItIHJtJHKtKHLtLHMtMHNtNHOtOHPtPHQtQHRtRHStSHTtTHUtUHVtVHWtWHXtXHYtYHZtZH[t[H\t\H]t]H^t^Ht ^RI	H_t_ ^RI	H`t` ]aP                  tc]P                  ! R	4      te]R
8X  d   ^ RIfHgth ^ RIfHiu Hju Hktl M^RImHnth ^RI	Hmtl ^RImHotoHptpHqtq  ! R R]h]4      tr ! R R4      ts]tR8X  d   ^ RIutu]uP                  ! 4        R# R# )z[
This module defines the mpf, mpc classes, and standard functions for
operating with them.
	plaintextN)StandardBaseContext)
basestringBACKEND)libmp)UMPZMPZ_ZEROMPZ_ONE	int_typesrepr_dpsround_floorround_ceilingdps_to_precround_nearestprec_to_dpsComplexResultto_pickablefrom_pickable	normalizefrom_int
from_floatfrom_strto_intto_floatto_strfrom_rationalfrom_man_expfonefzerofinffninffnanmpf_absmpf_posmpf_negmpf_addmpf_submpf_mulmpf_mul_intmpf_divmpf_rdiv_intmpf_pow_intmpf_modmpf_eqmpf_cmpmpf_ltmpf_gtmpf_lempf_gempf_hashmpf_randmpf_sumbitcountto_fixed
mpc_to_strmpc_to_complexmpc_hashmpc_posmpc_is_nonzerompc_negmpc_conjugatempc_absmpc_addmpc_add_mpfmpc_submpc_sub_mpfmpc_mulmpc_mul_mpfmpc_mul_intmpc_divmpc_div_mpfmpc_powmpc_pow_mpfmpc_pow_intmpc_mpf_divmpf_powmpf_pi
mpf_degreempf_empf_phimpf_ln2mpf_ln10	mpf_eulermpf_catalan	mpf_aperympf_khinchinmpf_glaishermpf_twinprimempf_mertensr
   )function_docs)rationalz\^\(?(?P<re>[\+\-]?\d*(\.\d*)?(e[\+\-]?\d+)?)??(?P<im>[\+\-]?\d*(\.\d*)?(e[\+\-]?\d+)?j)?\)?$sage)Context)PythonMPContext)ctx_mp_python)_mpf_mpc	mpnumericc                     a  ] tR t^:t o RtR tR tR tR tR t	R t
R tR	 tR8R
 ltR tR tR tR tR tR tR tR tR tR tR tR tR t]R 4       t]R 4       tR9R ltR9R ltR9R lt R9R lt!R:R  lt"R;R! lt#R" t$R# t%R$ t&R%t'R&t(R<R' lt)R( t*R) t+R* t,R+ t-R, t.R- t/R. t0R/ t1R0 t2R1 t3R2 t4R3 t5R4 t6R5 t7 ^ .R3R6 lt8R7t9V t:R# )=	MPContextz@
Context for multiprecision arithmetic with a global precision.
c                   \         P                  ! V 4       R V n        R V n        V P                  V P
                  V P                  .V n        \        P                  V n
        V P                  4        \        P                  ! V 4       \        P                  V n	        V P                  4        / V n        V P                  4         \         P"                  V P"                  P$                  n        \         P(                  V P(                  P$                  n        \         P*                  V P*                  P$                  n        \         P,                  V P,                  P$                  n        \         P2                  V P2                  n        \         P4                  V P4                  n        \         P6                  V P6                  n        R#   \.         d    \         P"                  T P"                  P0                  n        \         P(                  T P(                  P0                  n        \         P*                  T P*                  P0                  n        \         P,                  T P,                  P0                  n         ELi ; i)FN)BaseMPContext__init__trap_complexprettympfmpcconstanttypesr\   mpq_mpqdefaultr   init_builtinshyp_summators_init_aliasesr[   	bernoulliim_funcfunc_docprimepipsiatan2AttributeError__func__digammacospisinpictxs   &m/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/mpmath/ctx_mp.pyrh   MPContext.__init__?   s   s# 
WWcggs||4	<<$$S),,
	>-:-D-DCMM!!*+8+@+@CKK('4'8'8CGGOO$)6)<)<CII&  -44*00		*00		  	>.;.E.ECMM""+,9,A,ACKK  )(5(9(9CGG%*7*=*=CII'	>s   B$G B/I;:I;c                   V P                   pV P                  pV P                  \        4      V n        V P                  \
        4      V n        V P                  \
        \        34      V n        V P                  \        4      V n
        V P                  \        4      V n        V P                  \        4      V n        V P                  R  RR4      pW0n        V P                  \"        RR4      V n        V P                  \&        RR4      V n        V P                  \*        RR4      V n        V P                  \.        RR	4      V n        V P                  \2        R
R4      V n        V P                  \6        RR4      V n        V P                  \:        RR4      V n        V P                  \>        RR4      V n         V P                  \B        RR4      V n"        V P                  \F        RR4      V n$        V P                  \J        RR4      V n&        V P                  \N        RR4      V n(        V P                  \R        RR4      V n*        V PW                  \X        PZ                  \X        P\                  4      V n/        V PW                  \X        P`                  \X        Pb                  4      V n2        V PW                  \X        Pf                  \X        Ph                  4      V n5        V PW                  \X        Pl                  \X        Pn                  4      V n8        V PW                  \X        Pr                  \X        Pt                  4      V n;        V PW                  \X        Px                  \X        Pz                  4      V n>        V PW                  \X        P~                  \X        P                  4      V nA        V PW                  \X        P                  \X        P                  4      V nD        V PW                  \X        P                  \X        P                  4      V nG        V PW                  \X        P                  \X        P                  4      V nJ        V PW                  \X        P                  \X        P                  4      V nM        V PW                  \X        P                  \X        P                  4      V nP        V PW                  \X        P                  \X        P                  4      V nS        V PW                  \X        P                  \X        P                  4      V nV        V PW                  \X        P                  \X        P                  4      V nY        V PW                  \X        Pl                  \X        Pn                  4      V n8        V PW                  \X        P                  \X        P                  4      V n\        V PW                  \X        P                  \X        P                  4      V n_        V PW                  \X        P                  \X        P                  4      V nb        V PW                  \X        P                  \X        P                  4      V ne        V PW                  \X        P                  \X        P                  4      V nh        V PW                  \X        P                  \X        P                  4      V nk        V PW                  \X        P                  \X        P                  4      V nn        V PW                  \X        P                  \X        P                  4      V nq        V PW                  \X        P                  \X        P                  4      V nt        V PW                  \X        P                  \X        P                  4      ;V nw        V nx        V PW                  \X        P                  \X        P                  4      V n{        V PW                  \X        P                  \X        P                  4      V n~        V PW                  \X        P                  \X        EP                   4      V n        V PW                  \X        EP                  \X        EP                  4      ;V n        V n        V PW                  \X        EP                  \X        EP                  4      V n        V PW                  \X        EP                  \X        EP                  4      V n        V PW                  \X        EP                  \X        EP                  4      V n        V PW                  \X        EP                  \X        EP                   4      V n        V PW                  \X        EP$                  \X        EP&                  4      V n        V PW                  \X        EP*                  \X        EP,                  4      V n        V PW                  \X        EP0                  \X        EP2                  4      V n        V PW                  \X        EP6                  \X        EP8                  4      V n        V PW                  \X        EP<                  \X        EP>                  4      V n        V PW                  \X        EPB                  R4      V n        V PW                  \X        EPF                  R4      V n        V PW                  \X        EPJ                  \X        EPL                  4      V n        V PW                  \X        EPP                  \X        EPR                  4      V n        E\W        V RV P^                  4      V n/        E\W        V RV Pv                  4      V n;        E\W        V RV Pj                  4      V n5        E\W        V R V P                  4      V nG        E\W        V R!V P                  4      V nD        R# )"c                 $    ^ \         ^V ,
          ^3# )    )r	   )precrnds   &&r   <lambda>)MPContext.init_builtins.<locals>.<lambda>m   s    a!D&!-D    zepsilon of working precisionepspizln(2)ln2zln(10)ln10zGolden ratio phiphiz
e = exp(1)ezEuler's constanteulerzCatalan's constantcatalanzKhinchin's constantkhinchinzGlaisher's constantglaisherzApery's constantaperyz1 deg = pi / 180degreezTwin prime constant	twinprimezMertens' constantmertensN
_sage_sqrt	_sage_exp_sage_ln	_sage_cos	_sage_sin)rk   rl   make_mpfr   oner   zeromake_mpcjr   infr    ninfr!   nanrm   r   rN   r   rR   r   rS   r   rQ   r   rP   r   rT   r   rU   r   rW   r   rX   r   rV   r   rO   r   rY   r   rZ   r   _wrap_libmp_functionr   mpf_sqrtmpc_sqrtsqrtmpf_cbrtmpc_cbrtcbrtmpf_logmpc_loglnmpf_atanmpc_atanatanmpf_expmpc_expexpmpf_expjmpc_expjexpj
mpf_expjpi
mpc_expjpiexpjpimpf_sinmpc_sinsinmpf_cosmpc_coscosmpf_tanmpc_tantanmpf_sinhmpc_sinhsinhmpf_coshmpc_coshcoshmpf_tanhmpc_tanhtanhmpf_asinmpc_asinasinmpf_acosmpc_acosacos	mpf_asinh	mpc_asinhasinh	mpf_acosh	mpc_acoshacosh	mpf_atanh	mpc_atanhatanh
mpf_sin_pi
mpc_sin_pir   
mpf_cos_pi
mpc_cos_pir~   	mpf_floor	mpc_floorfloormpf_ceilmpc_ceilceilmpf_nintmpc_nintnintmpf_fracmpc_fracfracmpf_fibonaccimpc_fibonaccifib	fibonacci	mpf_gamma	mpc_gammagamma
mpf_rgamma
mpc_rgammargammampf_loggammampc_loggammaloggammampf_factorialmpc_factorialfac	factorialmpf_psi0mpc_psi0r}   mpf_harmonicmpc_harmonicharmonicmpf_eimpc_eieimpf_e1mpc_e1e1mpf_cimpc_ci_cimpf_simpc_si_si
mpf_ellipk
mpc_ellipkellipk
mpf_ellipe
mpc_ellipe_ellipempf_agm1mpc_agm1agm1mpf_erf_erfmpf_erfc_erfcmpf_zetampc_zeta_zetampf_altzetampc_altzeta_altzetagetattr)r   rk   rl   r   s   &   r   rr   MPContext.init_builtins`   s   gggg ,,t$<<&eD\*,,t$<<&,,t$llD*E3 fdD1,,w7<<(F;,,w(:EBUL#6LL,>H	ll;0DiP||L2GT||L2GTLL,>H	\\*.@(K
]4I;Wll;0CYO ++ENNENNK++ENNENNK))%--G++ENNENNK**5==%--H++ENNENNK--e.>.>@P@PQ
**5==%--H**5==%--H**5==%--H++ENNENNK++ENNENNK++ENNENNK++ENNENNK++ENNENNK++ENNENNK,,U__eooN	,,U__eooN	,,U__eooN	,,U-=-=u?O?OP	,,U-=-=u?O?OP	,,U__eooN	++ENNENNK++ENNENNK++ENNENNK"%":":5;N;NPUPcPc"dd#-,,U__eooN	--e.>.>@P@PQ
//0B0BEDVDVW"%":":5;N;NPUPcPc"dd#-..u~~u~~N//0B0BEDVDVW))%,,E))%,,E**5<<F**5<<F--e.>.>@P@PQ
..u/?/?AQAQR++ENNENNK++EMM4@,,U^^TB	,,U^^U^^L	//0A0A5CTCTU 3chh7#{CGG4j#&&1#{CGG4#{CGG4r   c                $    VP                  V4      # N)r7   )r   xr   s   &&&r   r7   MPContext.to_fixed   s    zz$r   c                    V P                  V4      pV P                  V4      pV P                  \        P                  ! VP                  VP                  .V P
                  O5!  4      # )zp
Computes the Euclidean norm of the vector `(x, y)`, equal
to `\sqrt{x^2 + y^2}`. Both `x` and `y` must be real.)convertr   r   	mpf_hypot_mpf__prec_rounding)r   r'  ys   &&&r   hypotMPContext.hypot   sK     KKNKKN||EOOAGGQWWRs?Q?QRSSr   c                J   \        V P                  V4      4      pV^ 8X  d   V P                  V4      # \        VR4      '       g   \        hV P
                  w  r4\        P                  ! WP                  W4RR7      w  rVVf   V P                  V4      # V P                  WV34      # )r   r,  T)r   )int_rer	  hasattrNotImplementedErrorr-  r   
mpf_expintr,  r   r   r   nzr   roundingrealimags   &&&    r   _gamma_upper_intMPContext._gamma_upper_int   s    
O666!9q'""%%++%%a$M
<<<%%<<--r   c                (   \        V4      pV^8X  d   V P                  V4      # \        VR4      '       g   \        hV P                  w  r4\
        P                  ! WP                  W44      w  rVVf   V P                  V4      # V P                  WV34      # )   r,  )
r2  r	  r4  r5  r-  r   r6  r,  r   r   r7  s   &&&    r   _expint_intMPContext._expint_int   s}    F666!9q'""%%++%%a$A
<<<%%<<--r   c                   \        VR 4      '       d>    V P                  \        P                  ! VP                  V.V P
                  O5!  4      # VP                  pV P                  \        P                  ! W.V P
                  O5!  4      #   \         d3    T P                  '       d   h TP                  \        P                  3p Lmi ; ir,  )r4  r   r   mpf_nthrootr,  r-  r   ri   r   _mpc_r   mpc_nthrootr   r'  r8  s   &&&r   _nthrootMPContext._nthroot   s    1g+||E$5$5aggq$V3CUCU$VWW A||E--aHS5G5GHII ! +###WWekk*+s   ;B C
*C
	C
c                *   V P                   w  r4\        VR 4      '       d1   V P                  \        P                  ! WP
                  W44      4      # \        VR4      '       d1   V P                  \        P                  ! WP                  W44      4      # R# )r,  rF  N)	r-  r4  r   r   mpf_besseljnr,  r   mpc_besseljnrF  )r   r8  r9  r   r:  s   &&&  r   _besseljMPContext._besselj   sn    ++1g<< 2 21ggt NOOQ  << 2 21ggt NOO !r   c                <   V P                   w  r4\        VR 4      '       dQ   \        VR 4      '       d?    \        P                  ! VP                  VP                  W44      pV P                  V4      # \        VR 4      '       d   VP                  \        P                  3pMVP                  p\        VR 4      '       d   VP                  \        P                  3pMVP                  pV P                  \        P                  ! WW44      4      #   \         d     Li ; irD  )r-  r4  r   mpf_agmr,  r   r   r   rF  r   mpc_agm)r   abr   r:  vs   &&&   r   _agmMPContext._agm   s    ++1g71g#6#6MM!''177DC||A& 1gQWWekk$:''a1gQWWekk$:''a||EMM!?@@ ! s   <D DDc                v    V P                  \        P                  ! \        V4      .V P                  O5!  4      # r&  )r   r   mpf_bernoullir2  r-  r   r8  s   &&r   ru   MPContext.bernoulli   s+    ||E//AL9K9KLMMr   c                v    V P                  \        P                  ! \        V4      .V P                  O5!  4      # r&  )r   r   mpf_zeta_intr2  r-  rZ  s   &&r   	_zeta_intMPContext._zeta_int   s+    ||E..s1vK8J8JKLLr   c                    V P                  V4      pV P                  V4      pV P                  \        P                  ! VP                  VP                  .V P
                  O5!  4      # r&  )r*  r   r   	mpf_atan2r,  r-  )r   r.  r'  s   &&&r   rz   MPContext.atan2  sI    KKNKKN||EOOAGGQWWRs?Q?QRSSr   c                T   V P                  V4      p\        V4      pV P                  V4      '       d<   V P                  \        P
                  ! WP                  .V P                  O5!  4      # V P                  \        P                  ! WP                  .V P                  O5!  4      # r&  )r*  r2  _is_real_typer   r   mpf_psir,  r-  r   mpc_psirF  )r   mr9  s   &&&r   ry   MPContext.psi  sw    KKNFQ<<a N3;M;M NOO<<a N3;M;M NOOr   c                &   \        V4      V P                  9  d   V P                  V4      pV P                  V4      w  r4\	        VR 4      '       dF   \
        P                  ! VP                  W44      w  rVV P                  V4      V P                  V4      3# \	        VR4      '       dF   \
        P                  ! VP                  W44      w  rVV P                  V4      V P                  V4      3# V P                  ! V3/ VB V P                  ! V3/ VB 3# r,  rF  )typern   r*  _parse_precr4  r   mpf_cos_sinr,  r   mpc_cos_sinrF  r   r   r   r   r'  kwargsr   r:  css   &&,    r   cos_sinMPContext.cos_sin  s    7#))#AA01g$$QWWd=DA<<?CLLO33Q  $$QWWd=DA<<?CLLO33771'')=f)===r   c                &   \        V4      V P                  9  d   V P                  V4      pV P                  V4      w  r4\	        VR 4      '       dF   \
        P                  ! VP                  W44      w  rVV P                  V4      V P                  V4      3# \	        VR4      '       dF   \
        P                  ! VP                  W44      w  rVV P                  V4      V P                  V4      3# V P                  ! V3/ VB V P                  ! V3/ VB 3# rj  )rk  rn   r*  rl  r4  r   mpf_cos_sin_pir,  r   mpc_cos_sin_pirF  r   r   r   ro  s   &&,    r   cospi_sinpiMPContext.cospi_sinpi  s    7#))#AA01g''@DA<<?CLLO33Q  ''@DA<<?CLLO33771'')=f)===r   c                H    V P                  4       pV P                  Vn        V# )z@
Create a copy of the context, with the same working precision.
)	__class__r   )r   rS  s   & r   cloneMPContext.clone)  s     MMOr   c                T    \        VR 4      '       g   \        V4      \        J d   R# R# )rF  FTr4  rk  complexr   r'  s   &&r   rd  MPContext._is_real_type4  s     1g$q'W"4r   c                T    \        VR 4      '       g   \        V4      \        J d   R# R# )rF  TFr  r  s   &&r   _is_complex_typeMPContext._is_complex_type9  s     1g$q'W"4r   c                   \        VR4      '       d   VP                  \        8H  # \        VR4      '       d   \        VP                  9   # \	        V\
        4      '       g!   \	        V\        P                  4      '       d   R# V P                  V4      p\        VR4      '       g   \        VR4      '       d   V P                  V4      # \        R4      h)a:  
Return *True* if *x* is a NaN (not-a-number), or for a complex
number, whether either the real or complex part is NaN;
otherwise return *False*::

    >>> from mpmath import *
    >>> isnan(3.14)
    False
    >>> isnan(nan)
    True
    >>> isnan(mpc(3.14,2.72))
    False
    >>> isnan(mpc(3.14,nan))
    True

r,  rF  Fzisnan() needs a number as input)r4  r,  r!   rF  
isinstancer
   r\   ro   r*  isnan	TypeErrorr  s   &&r   r  MPContext.isnan>  s    " 1g77d?"1g177?"a##z!X\\'B'BKKN1g'!W"5"599Q<9::r   c                f    V P                  V4      '       g   V P                  V4      '       d   R# R# )aX  
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

FT)isinfr  r  s   &&r   isfiniteMPContext.isfiniteZ  s#    , 99Q<<399Q<<r   c                   V'       g   R# \        VR4      '       d   VP                  w  r#rET;'       d    V^ 8  # \        VR4      '       d5   VP                  '       * ;'       d    V P                  VP                  4      # \        V4      \        9   d   V^ 8*  # \        WP                  4      '       d+   VP                  w  rgV'       g   R# V^8H  ;'       d    V^ 8*  # V P                  V P                  V4      4      # )z,
Determine if *x* is a nonpositive integer.
Tr,  rF  )r4  r,  r<  isnpintr;  rk  r
   r  ro   _mpq_r*  )r   r'  signmanr   bcpqs   &&      r   r  MPContext.isnpintt  s     1g!"Ds$$C1H$1gvv:55#++aff"557i6Ma!!77DA6$$a1f${{3;;q>**r   c                   R RV P                   ,          P                  ^4      R,           RV P                  ,          P                  ^4      R,           RV P                  ,          P                  ^4      R,           .pRP	                  V4      # )zMpmath settings:z  mp.prec = %sz[default: 53]z  mp.dps = %sz[default: 15]z  mp.trap_complex = %sz[default: False]
)r   ljustdpsri   join)r   liness   & r   __str__MPContext.__str__  st    #(//3oEsww&--b1OC%(8(88??CFXX

 yyr   c                ,    \        V P                  4      # r&  )r   _precr   s   &r   _repr_digitsMPContext._repr_digits  s    		""r   c                    V P                   # r&  )_dpsr   s   &r   _str_digitsMPContext._str_digits  s    xxr   Fc                (   a \        V V3R lRV4      # )a  
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                    < V S,           # r&   r  r8  s   &r   r   %MPContext.extraprec.<locals>.<lambda>  s	    q1ur   NPrecisionManagerr   r8  normalize_outputs   &f&r   	extraprecMPContext.extraprec  s       _d<LMMr   c                (   a \        V RV3R lV4      # )z~
This function is analogous to extraprec (see documentation)
but changes the decimal precision instead of the number of bits.
Nc                    < V S,           # r&  r  dr8  s   &r   r   $MPContext.extradps.<locals>.<lambda>  s	    QUr   r  r  s   &f&r   extradpsMPContext.extradps  s    
  T?<LMMr   c                (   a \        V V3R lRV4      # )ak  
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# r&  r  r  s   &r   r   $MPContext.workprec.<locals>.<lambda>  s    qr   Nr  r  s   &f&r   workprecMPContext.workprec  s      [$8HIIr   c                (   a \        V RV3R lV4      # )z}
This function is analogous to workprec (see documentation)
but changes the decimal precision instead of the number of bits.
Nc                    < S# r&  r  r  s   &r   r   #MPContext.workdps.<locals>.<lambda>  s    Qr   r  r  s   &f&r   workdpsMPContext.workdps  s    
  T;8HIIr   Nc                $   a aaaa VV VVV3R lpV# )a  
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                    < S	P                   pSf   S	P                  V4      pMSp V^
,           S	n          S
! V / VB pV^,           p VS	n          S
! V / VB pWF8X  d   MS	P                  Wd,
          4      S	P                  V4      ,
          pWr) 8  d   MfS'       d   \	        RV: RV: RV) : 24       TpWS8  d   S	P                  RV,          4      hV\        V^,          4      ,          p\        WS4      pK  VS	n         V5#   S d    S	P                  p Li ; i  S d    S	P                  p Li ; i  TS	n         i ; i)Nzautoprec: target=z, prec=z, accuracy=z2autoprec: prec increased to %i without convergence)r   _default_hyper_maxprecr   magprintNoConvergencer2  min)argsrp  r   maxprec2v1prec2v2errcatchr   fmaxprecverboses   *,      r   f_autoprec_wrapped.MPContext.autoprec.<locals>.f_autoprec_wrapped  sN   88D55d;" "9!D+F+B r	$CH%// x''"%.3772;6Ce}#USD2 3B(!//L ! ! Sq\)E0E3J5  !B! ! % WW%$  sY   D6 D D6 D AD6 AD6 DD6 DD6 D30D6 2D33D6 6	D?r  )r   r  r  r  r  r  s   fffff r   autoprecMPContext.autoprec  s    H$	 $	J "!r   c                f  a aa \        V\        4      '       d%   RRP                  V VV3R lV 4       4      ,          # \        V\        4      '       d%   RRP                  V VV3R lV 4       4      ,          # \	        VR4      '       d   \        VP                  S3/ SB # \	        VR4      '       d&   R\        VP                  S3/ SB ,           R	,           # \        V\        4      '       d   \        V4      # \        VS P                  4      '       d   VP                  ! S3/ SB # \        V4      # )
a;  
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'

z[%s]z, c              3   L   <"   T F  pSP                   ! VS3/ SB x  K  	  R # 5ir&  nstr.0rq  r   rp  r8  s   & r   	<genexpr>!MPContext.nstr.<locals>.<genexpr>]  !     &KAsxx1'?'?   !$z(%s)c              3   L   <"   T F  pSP                   ! VS3/ SB x  K  	  R # 5ir&  r  r  s   & r   r  r  _  r  r  r,  rF  ())r  listr  tupler4  r   r,  r8   rF  r   reprmatrix__nstr__str)r   r'  r8  rp  s   f&flr   r  MPContext.nstr4  s    P aTYY&K&KKLLaTYY&K&KKLL1g!''1///1gAGGQ9&99S@@a$$7Na$$::a*6**1vr   c                b   V'       d   \        V\        4      '       d   R VP                  4       9   d   VP                  4       P                  RR4      p\        P                  V4      pVP                  R4      pV'       g   ^ pVP                  R4      P                  R 4      pV P                  V P                  V4      V P                  V4      4      # \        VR4      '       d1   VP                  w  rgWg8X  d   V P                  V4      # \        R4      h\        R\        V4      ,           4      h)r     reim_mpi_z,can only create mpf from zero-width intervalzcannot create mpf from )r  r   lowerreplaceget_complexmatchgrouprstriprl   r*  r4  r  r   
ValueErrorr  r  )r   r'  stringsr  r  r  rS  rT  s   &&&     r   _convert_fallbackMPContext._convert_fallbackj  s    z!Z00aggiGGI%%c2.#))!,[[&B[[&--c2wws{{2B@@1g77DAv||A& !OPP1DG;<<r   c                &    V P                   ! V/ VB # r&  )r*  )r   r  rp  s   &*,r   	mpmathifyMPContext.mpmathify|  s    {{D+F++r   c                Z   V'       d   VP                  R 4      '       d   R# V P                  w  r#RV9   d
   VR,          pRV9   d+   VR,          pW P                  8X  d   R# \        V4      p W#3# RV9   d'   VR,          pW@P                  8X  d   R# \	        V4      pW#3# V P                  # )exactr:  r   r  )r   r  )getr-  r   r2  r   )r   rp  r   r:  r  s   &&   r   rl  MPContext._parse_prec  s    zz'"" //NDV#!*-f~77?!Mt9D >! &Um''>!M"3'>!!!!r   z'the exact result does not fit in memoryzhypsum() 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                t   \        VR 4      '       d   WVR3pVP                  p	M#\        VR4      '       d   WVR3pVP                  p	XV P                  9  d+   \        P
                  ! V4      ^,          V P                  V&   V P                  V,          p
V P                  pVP                  RV P                  V4      4      p^2p^p/ p^ p\        V4       F  w  ppVV,          R8X  db   VV8  dY   V^ 8:  dR   Rp\        VRV 4       F*  w  ppVV,          R8X  g   K  V^ 8:  g   K  VV8:  g   K(  RpK,  	  V'       g   \        R	4      hKu  V P                  V4      w  pp\        V4      ) pV) pVV8  dK   V^ 8  dD   V^8  d=   VV9   d   VV;;,          V,          uu&   MVVV&   \        VVV,
          ^<,           4      pV\        V4      ,          pK  	   W8  d%   \        V P                   WV,           3,          4      hW,           pV'       d   \#        R
 V 4       4      pM/ pV
! VX	VVVV3/ VB w  pppV) pRpVV8  d'   VP%                  4        F  pVe
   VV8  g   K  Rp M	  VV^,
          ^,
          8  ;'       g    V'       * pV'       dK   V'       d   M_VP                  R4      p V e-   VV 8  d&   V'       d   V P'                  ^ 4      # V P(                  # V^,          pV^,          pV^,          pEK&  \+        V4      \,        J d+   V'       d   V P/                  V4      # V P1                  V4      # V# )r,  RrF  Cr  ZFNTzpole in hypergeometric seriesc              3   (   "   T F  qR 3x  K
  	  R # 5ir&  r  )r  r8  s   & r   r  #MPContext.hypsum.<locals>.<genexpr>  s     B/Q4/s   zeroprec)r4  r,  rF  rs   r   make_hyp_summatorr   r  r  	enumerateZeroDivisionErrornint_distancer2  maxabsr  _hypsum_msgdictvaluesrl   r   rk  r  r   r   )!r   r  r  flagscoeffsr9  accurate_smallrp  keyrU  summatorr   r  r  epsshiftmagnitude_checkmax_total_jumpirq  okiiccr8  r  wpmag_dictzvhave_complex	magnitudecanceljumps_resolvedaccurater
  s!   &&&&&&&,                         r   hypsumMPContext.hypsum  s   1gs"CAQ  s"CAc'''%*%<%<S%A!%DCc"$$S)xx**Y(B(B4(HI	 f%DAqQx36a1fB"+F2AJ"7B 9+aAG!%B #8 /0OPP$$Q'DAqQAAAv!q&QU'#A&!+&)*OA&	1t8b=9	c!f$N) &* " Dy.3I!IJJ!BB/BB*261dB(+.&,+.'BiZF!N>)!*A	q4x). + 2a/EE~3EH!::j1'('#&771:-#&88O NIMHNI8u||B''||B''Ir   c                    V P                  V4      pV P                  \        P                  ! VP                  V4      4      # )aF  
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   	mpf_shiftr,  rH  s   &&&r   ldexpMPContext.ldexp  s/     KKN||EOOAGGQ788r   c                    V P                  V4      p\        P                  ! VP                  4      w  r#V P	                  V4      V3# )z
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   	mpf_frexpr,  r   )r   r'  r.  r8  s   &&  r   frexpMPContext.frexp   s8     KKNqww'||A!!r   c                <   V P                  V4      w  r4V P                  V4      p\        VR4      '       d&   V P                  \	        VP
                  W44      4      # \        VR4      '       d&   V P                  \        VP                  W44      4      # \        R4      h)a  
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,  rF  2Arguments need to be mpf or mpc compatible numbers)
rl  r*  r4  r   r$   r,  r   r=   rF  r  )r   r'  rp  r   r:  s   &&,  r   fnegMPContext.fneg  s|    \ 0KKN1g<< @AA1g<< @AAMNNr   c                0   V P                  V4      w  rEV P                  V4      pV P                  V4      p \        VR4      '       d   \        VR4      '       d1   V P                  \	        VP
                  VP
                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP
                  WE4      4      # \        VR4      '       d   \        VR4      '       d1   V P                  \        VP                  VP
                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP                  WE4      4      # \        R4      h  \        \        3 d    \        T P                  4      hi ; i)a3  
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,  rF  r3  )rl  r*  r4  r   r%   r,  r   rA   rF  r@   r  OverflowError_exact_overflow_msgr   r'  r.  rp  r   r:  s   &&&,  r   faddMPContext.faddF  s7   p 0KKNKKN	9q'""1g&&<<$(QRR1g&&<<AGGQWWd(UVVq'""1g&&<<AGGQWWd(UVV1g&&<<$(QRR MNN M* 	9 7 788	9!   AE. AE. AE. !AE. .'Fc                <   V P                  V4      w  rEV P                  V4      pV P                  V4      p \        VR4      '       d   \        VR4      '       d1   V P                  \	        VP
                  VP
                  WE4      4      # \        VR4      '       d7   V P                  \        VP
                  \        3VP                  WE4      4      # \        VR4      '       d   \        VR4      '       d1   V P                  \        VP                  VP
                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP                  WE4      4      # \        R4      h  \        \        3 d    \        T P                  4      hi ; i)aY  
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,  rF  r3  )rl  r*  r4  r   r&   r,  r   rB   r   rF  rC   r  r7  r8  r9  s   &&&,  r   fsubMPContext.fsub  s<   ` 0KKNKKN	9q'""1g&&<<$(QRR1g&&<<%0@!''4(Z[[q'""1g&&<<AGGQWWd(UVV1g&&<<$(QRR MNN M* 	9 7 788	9s!   AE4 AE4 AE4 'AE4 4'Fc                0   V P                  V4      w  rEV P                  V4      pV P                  V4      p \        VR4      '       d   \        VR4      '       d1   V P                  \	        VP
                  VP
                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP
                  WE4      4      # \        VR4      '       d   \        VR4      '       d1   V P                  \        VP                  VP
                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP                  WE4      4      # \        R4      h  \        \        3 d    \        T P                  4      hi ; i)ae  
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,  rF  r3  )rl  r*  r4  r   r'   r,  r   rE   rF  rD   r  r7  r8  r9  s   &&&,  r   fmulMPContext.fmul  s7   f 0KKNKKN	9q'""1g&&<<$(QRR1g&&<<AGGQWWd(UVVq'""1g&&<<AGGQWWd(UVV1g&&<<$(QRR MNN M* 	9 7 788	9r<  c                   V P                  V4      w  rEV'       g   \        R4      hV P                  V4      pV P                  V4      p\        VR4      '       d   \        VR4      '       d1   V P	                  \        VP                  VP                  WE4      4      # \        VR4      '       d7   V P                  \        VP                  \        3VP                  WE4      4      # \        VR4      '       d   \        VR4      '       d1   V P                  \        VP                  VP                  WE4      4      # \        VR4      '       d1   V P                  \        VP                  VP                  WE4      4      # \        R4      h)a  
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

z"division is not an exact operationr,  rF  r3  )rl  r  r*  r4  r   r)   r,  r   rG   r   rF  rH   r9  s   &&&,  r   fdivMPContext.fdiv  s   b 0ABBKKNKKN1gq'""||GAGGQWWd$MNNq'""||GQWWe,<aggt$VWW1gq'""||K$$QRRq'""||GAGGQWWd$MNNMNNr   c                (   \        V4      pV\        9   d   \        V4      V P                  3# V\        P
                  J d}   VP                  w  r4\        W44      w  rV^V,          V8  d   V^,          pMV'       g   WPP                  3# \        \        W5V,          ,
          4      4      \        V4      ,
          pWW3# \        VR4      '       d   VP                  pV P                  p	M\        VR4      '       dH   VP                  w  rV
w  rrV'       d
   W,           p	MtV
\        8X  d   V P                  p	M\\        R4      hV P                  V4      p\        VR4      '       g   \        VR4      '       d   V P!                  V4      # \#        R4      hVw  ppppVV,           pV^ 8  d   ^ pTpMV'       d   V^ 8  d   VV,          pV P                  pMVR8X  d   V^,	          ^,           p^ pMgV) ^,
          pVV,	          pV^,          '       d   V^,          pVV,          V,
          pMVVV,          ,          pV^,	          pV\        V4      ,           pV'       d   V) pM%V\        8X  d   V P                  p^ pM\        R4      hV\%        VV	4      3# )a  
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

r,  rF  zrequires a finite numberzrequires an mpf/mpc)rk  r
   r2  r   r\   ro   r  divmodr6   r  r4  r,  rF  r   r  r*  r  r  r  )r   r'  typxr  r  r8  rr  r  im_distr  isignimaniexpibcr  r  r   r  r  re_distts   &&                    r   r  MPContext.nint_distanceY  s.   B Aw9q6388##X\\!77DA!<DAsaxQ(({"QsU$x{2A4K1gBhhGQ  WWFB%'"E*u(( !;<<AAq'""ga&9&9((++ 566c3"f7AGax3J((!VQJT!V1Hq55FAa43,CAqDMCqDhsm+B5[hhGA788#gw'''r   c                ~    V P                   p V P                  pV F  pW4,          pK  	  W n         V5#   Y n         i ; i)a  
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')

)r   r   )r   factorsorigrU  r  s   &&   r   fprodMPContext.fprod  sC     xx	A  Hr	 Hs   4 <c                J    V P                  \        V P                  4      4      # )z
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   r4   r  r   s   &r   randMPContext.rand  s     ||HSYY/00r   c                B   aa V P                  VV3R lS: RS: 24      # )a  
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SW4      # r&  )r   )r   r   r  r  s   &&r   r   $MPContext.fraction.<locals>.<lambda>  s    mAq$.Lr   /)rm   )r   r  r  s   &ffr   fractionMPContext.fraction  s!    $ ||L! 	r   c                6    \        V P                  V4      4      # r&  r  r*  r  s   &&r   absminMPContext.absmin      3;;q>""r   c                6    \        V P                  V4      4      # r&  rb  r  s   &&r   absmaxMPContext.absmax  re  r   c                    \        VR 4      '       d1   VP                  w  r#V P                  V4      V P                  V4      .# V# )r  )r4  r  r   )r   r'  rS  rT  s   &&  r   
_as_pointsMPContext._as_points  s:    1g77DALLOS\\!_55r   c                n   V P                  V4      '       d   \        VR 4      '       g   \        h\        V4      pV P                  p\
        P                  ! VP                  W#WEV4      w  rxV U	u. uF  qP                  V	4      NK  	  pp	V U
u. uF  qP                  V
4      NK  	  pp
Wx3# u up	i u up
i )rF  )	isintr4  r5  r2  r  r   mpc_zetasumrF  r   )r   rr  rS  r8  derivativesreflectr   xsysr'  r.  s   &&&&&&     r   _zetasum_fastMPContext._zetasum_fast  s    		!G!4!4%%Fyy""177A+M')*r!ll1or*')*r!ll1or*v +*s   0B-B2r  )r@  F)Nr  F)   )T);__name__
__module____qualname____firstlineno____doc__rh   rr   r7   r/  r=  rA  rI  rN  rV  ru   r^  rz   ry   rs  rx  r|  rd  r  r  r  r  r  propertyr  r  r  r  r  r  r  r  r  r  rl  r8  r  r(  r,  r0  r4  r:  r>  rA  rD  r  rV  rY  r_  rc  rg  rj  rs  __static_attributes____classdictcell____classdict__s   @r   re   re   :   sd    1BT5l T..
JPANMT
P>>

;84+(  # #  N$NJ"Ji"V4l=$,"* DKSj9"" 4OlHOT@ODCOJ@OD`(D*1*##" 23U  r   re   c                   <   a  ] tR tRt o RR ltR tR tR tRtV t	R# )	r  i  c                6    Wn         W n        W0n        W@n        R # r&  )r   precfundpsfunr  )selfr   r  r  r  s   &&&&&r   rh   PrecisionManager.__init__  s     0r   c                J   a a \         P                  ! S4      VV 3R  l4       pV# )c                  j  < SP                   P                  p SP                  '       d6   SP                  SP                   P                  4      SP                   n        M4SP                  SP                   P                  4      SP                   n        SP
                  '       d\   S! V / VB p\        V4      \        J d-   \        V Uu. uF  qD5NK  	  up4      VSP                   n        # V5VSP                   n        # S! V / VB VSP                   n        # u upi   TSP                   n        i ; ir&  )r   r   r  r  r  r  rk  r  )r  rp  rU  rU  rS  r  r  s   *,   r   g$PrecisionManager.__call__.<locals>.g  s    88==D%<<<$(LL$?DHHM#';;txx||#<DHHL(((4*6*AAw%'$!_!Qb!_5
 !%	 2 !% d-f- $ &5
 !%s5   D A:D &$D 
DD -D D D D2)	functoolswraps)r  r  r  s   ff r   __call__PrecisionManager.__call__  s%    			% 
	%  r   c                4   V P                   P                  V n        V P                  '       d7   V P                  V P                   P                  4      V P                   n        R # V P	                  V P                   P
                  4      V P                   n        R # r&  )r   r   origpr  r  r  )r  s   &r   	__enter__PrecisionManager.__enter__.  sR    XX]]
<<< LL7DHHM;;txx||4DHHLr   c                <    V P                   V P                  n        R # ru  )r  r   r   )r  exc_typeexc_valexc_tbs   &&&&r   __exit__PrecisionManager.__exit__4  s    

r   )r   r  r  r  r  Nru  )
rw  rx  ry  rz  rh   r  r  r  r}  r~  r  s   @r   r  r    s     1
&5 r   r  __main__)wr{  __docformat__r  r  ctx_baser   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   object__new__newcompiler  sage.libs.mpmath.ext_mainr^   rg   libsmpmathext_main_mpf_moduler`   r_   ra   rb   rc   re   r  rw  doctesttestmodr  r   r   <module>r     s     	 ) .                      .  nnjj K L fB33?. 0 0Y2 Yv&! !H zOO r   