
    g,                        d Z dZddl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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^mZ dd	l	m_Z_ dd
l	m`Z` eajb        Zc ejd        d          Zeedk    rddlfmgZh ddlfmic mjc mkZl nddlmmnZh ddl	mmZl ddlmmoZompZpmqZq  G d dehe          Zr G d d          Zsetdk    rddluZu eujv                     dS dS )z[
This module defines the mpf, mpc classes, and standard functions for
operating with them.
	plaintext    N   )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                   z   e Zd 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d=dZd=dZd=dZd=dZ d>d"Z!d?d$Z"d% Z#d& Z$d' Z%d(Z&d)Z'd@d+Z(d, Z)d- Z*d. Z+d/ Z,d0 Z-d1 Z.d2 Z/d3 Z0d4 Z1d5 Z2d6 Z3d7 Z4d8 Z5d9 Z6	 d:gdfd;Z7d S )A	MPContextzH
    Context for multiprecision arithmetic with a global precision.
    c                    t          j        |            d| _        d| _        | j        | j        | j        g| _        t          j	        | _
        |                                  t          j        |            t          j	        | _	        |                                  i | _        |                                  	 t           j        | j        j        _        t           j        | j        j        _        t           j        | j        j        _        t           j        | j        j        _        n|# t.          $ ro t           j        | j        j        _        t           j        | j        j        _        t           j        | j        j        _        t           j        | j        j        _        Y nw xY wt           j        | j        _        t           j        | j        _        t           j        | j        _        d S NF)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    I/var/www/html/ai-engine/env/lib/python3.11/site-packages/mpmath/ctx_mp.pyrk   zMPContext.__init__?   si   s### 
Wcgs|4	<$S))),
	>-:-DCM!*+8+@CK('4'8CGO$)6)<CI&& 	> 	> 	>.;.ECM"+,9,ACK )(5(9CG%*7*=CI'''	>  -4*0	*0	s   6A,D# #A6FFc                    | j         }| j        }|                     t                    | _        |                     t
                    | _        |                     t
          t          f          | _        |                     t                    | _
        |                     t                    | _        |                     t                    | _        |                     d dd          }|| _        |                     t"          dd          | _        |                     t&          dd          | _        |                     t*          dd          | _        |                     t.          d	d
          | _        |                     t2          dd          | _        |                     t6          dd          | _        |                     t:          dd          | _        |                     t>          dd          | _         |                     tB          dd          | _"        |                     tF          dd          | _$        |                     tJ          dd          | _&        |                     tN          dd          | _(        |                     tR          dd          | _*        | +                    tX          j-        tX          j.                  | _/        | +                    tX          j0        tX          j1                  | _2        | +                    tX          j3        tX          j4                  | _5        | +                    tX          j6        tX          j7                  | _8        | +                    tX          j9        tX          j:                  | _;        | +                    tX          j<        tX          j=                  | _>        | +                    tX          j?        tX          j@                  | _A        | +                    tX          jB        tX          jC                  | _D        | +                    tX          jE        tX          jF                  | _G        | +                    tX          jH        tX          jI                  | _J        | +                    tX          jK        tX          jL                  | _M        | +                    tX          jN        tX          jO                  | _P        | +                    tX          jQ        tX          jR                  | _S        | +                    tX          jT        tX          jU                  | _V        | +                    tX          jW        tX          jX                  | _Y        | +                    tX          j6        tX          j7                  | _8        | +                    tX          jZ        tX          j[                  | _\        | +                    tX          j]        tX          j^                  | __        | +                    tX          j`        tX          ja                  | _b        | +                    tX          jc        tX          jd                  | _e        | +                    tX          jf        tX          jg                  | _h        | +                    tX          ji        tX          jj                  | _k        | +                    tX          jl        tX          jm                  | _n        | +                    tX          jo        tX          jp                  | _q        | +                    tX          jr        tX          js                  | _t        | +                    tX          ju        tX          jv                  x| _w        | _x        | +                    tX          jy        tX          jz                  | _{        | +                    tX          j|        tX          j}                  | _~        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  x| _        | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        d           | _        | +                    tX          j        d           | _        | +                    tX          j        tX          j                  | _        | +                    tX          j        tX          j                  | _        tW          | d| j/                  | _/        tW          | d| j;                  | _;        tW          | d| j5                  | _5        tW          | d | jG                  | _G        tW          | d!| jD                  | _D        d S )"Nc                     dt           d| z
  dfS )Nr   r   )r   )precrnds     r   <lambda>z)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mertens
_sage_sqrt	_sage_exp_sage_ln	_sage_cos	_sage_sin)rn   ro   make_mpfr   oner    zeromake_mpcjr!   infr"   ninfr#   nanrp   r   rP   r   rT   r   rU   r   rS   r   rR   r   rV   r   rW   r   rY   r   rZ   r   rX   r   rQ   r   r[   r   r\   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   rn   ro   r   s       r   ru   zMPContext.init_builtins`   s   gg ,,t$$<<&&eD\**,,t$$<<&&,,t$$llDD*E3 3 fdD11,,w77<<(F;;,,w(:EBBUL#66LL,>HH	ll;0DiPP||L2GTT||L2GTTLL,>HH	\\*.@(KK
]4I;WWll;0CYOO ++ENENKK++ENENKK))%-GG++ENENKK**5=%-HH++ENENKK--e.>@PQQ
**5=%-HH**5=%-HH**5=%-HH++ENENKK++ENENKK++ENENKK++ENENKK++ENENKK++ENENKK,,U_eoNN	,,U_eoNN	,,U_eoNN	,,U-=u?OPP	,,U-=u?OPP	,,U_eoNN	++ENENKK++ENENKK++ENENKK"%":":5;NPUPc"d"dd#-,,U_eoNN	--e.>@PQQ
//0BEDVWW"%":":5;NPUPc"d"dd#-..u~u~NN//0BEDVWW))%,EE))%,EE**5<FF**5<FF--e.>@PQQ
..u/?AQRR++ENENKK++EM4@@,,U^TBB	,,U^U^LL	//0A5CTUU 3ch77#{CG44j#&11#{CG44#{CG44r   c                 ,    |                     |          S N)r9   )r   xr   s      r   r9   zMPContext.to_fixed   s    zz$r   c                     |                      |          }|                      |          }|                     t          j        |j        |j        g| j        R            S )z
        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   hypotzMPContext.hypot   sO     KKNNKKNN||EOAGQWRs?QRRRSSSr   c                 \   t          |                     |                    }|dk    r|                     |          S t          |d          st          | j        \  }}t          j        ||j        ||d          \  }}|| 	                    |          S | 
                    ||f          S )Nr   r*  T)r   )int_rer	  hasattrNotImplementedErrorr+  r   
mpf_expintr*  r   r   r   nzr   roundingrealimags          r   _gamma_upper_intzMPContext._gamma_upper_int   s    

OO6666!99q'"" 	&%%+h%a$MMM
d<<<%%%<<t---r   c                 2   t          |          }|dk    r|                     |          S t          |d          st          | j        \  }}t          j        ||j        ||          \  }}||                     |          S | 	                    ||f          S )Nr   r*  )
r/  r	  r1  r2  r+  r   r3  r*  r   r   r4  s          r   _expint_intzMPContext._expint_int   s    FF6666!99q'"" 	&%%+h%a$AA
d<<<%%%<<t---r   c                 >   t          |d          r\	 |                     t          j        |j        |g| j        R            S # t          $ r | j        r |j        t          j        f}Y nw xY w|j	        }| 
                    t          j        ||g| j        R            S Nr*  )r1  r   r   mpf_nthrootr*  r+  r   rl   r    _mpc_r   mpc_nthrootr   r&  r5  s      r   _nthrootzMPContext._nthroot   s    1g 	+||E$5agq$V3CU$V$V$VWWW  + + +# Wek*+
 A||E-aHS5GHHHIIIs   /A %A*)A*c                    | j         \  }}t          |d          r/|                     t          j        ||j        ||                    S t          |d          r/|                     t          j        ||j        ||                    S d S Nr*  r@  )	r+  r1  r   r   mpf_besseljnr*  r   mpc_besseljnr@  )r   r5  r6  r   r7  s        r   _besseljzMPContext._besselj   s    +h1g 	P<< 21agtX N NOOOQ   	P<< 21agtX N NOOO	P 	Pr   r   c                    | j         \  }}t          |d          rWt          |d          rG	 t          j        |j        |j        ||          }|                     |          S # t          $ r Y nw xY wt          |d          r|j        t          j        f}n|j        }t          |d          r|j        t          j        f}n|j        }| 	                    t          j
        ||||                    S r>  )r+  r1  r   mpf_agmr*  r   r   r    r@  r   mpc_agm)r   abr   r7  vs         r   _agmzMPContext._agm   s    +h1g 	71g#6#6 	M!'17D(CC||A&    1g 	QWek$:'a1g 	QWek$:'a||EM!Qh??@@@s   5A" "
A/.A/c                 p    |                      t          j        t          |          g| j        R            S r%  )r   r   mpf_bernoullir/  r+  r   r5  s     r   rx   zMPContext.bernoulli   s0    ||E/AL9KLLLMMMr   c                 p    |                      t          j        t          |          g| j        R            S r%  )r   r   mpf_zeta_intr/  r+  rR  s     r   	_zeta_intzMPContext._zeta_int   s0    ||E.s1vvK8JKKKLLLr   c                     |                      |          }|                      |          }|                     t          j        |j        |j        g| j        R            S r%  )r(  r   r   	mpf_atan2r*  r+  )r   r,  r&  s      r   r}   zMPContext.atan2  sM    KKNNKKNN||EOAGQWRs?QRRRSSSr   c                 4   |                      |          }t          |          }|                     |          r0|                     t	          j        ||j        g| j        R            S |                     t	          j	        ||j
        g| j        R            S r%  )r(  r/  _is_real_typer   r   mpf_psir*  r+  r   mpc_psir@  )r   mr6  s      r   r|   zMPContext.psi  s    KKNNFFQ 	P<<a N3;M N N NOOO<<a N3;M N N NOOOr   c                     t          |          | j        vr|                     |          }|                     |          \  }}t	          |d          rHt          j        |j        ||          \  }}|                     |          |                     |          fS t	          |d          rHt          j	        |j
        ||          \  }}|                     |          |                     |          fS  | j        |fi | | j        |fi |fS rE  )typerq   r(  _parse_precr1  r   mpf_cos_sinr*  r   mpc_cos_sinr@  r   r   r   r   r&  kwargsr   r7  css          r   cos_sinzMPContext.cos_sin  s   77#)##AA00h1g 	>$QWdH==DAq<<??CLLOO33Q   	>$QWdH==DAq<<??CLLOO33371'''')=)=f)=)===r   c                     t          |          | j        vr|                     |          }|                     |          \  }}t	          |d          rHt          j        |j        ||          \  }}|                     |          |                     |          fS t	          |d          rHt          j	        |j
        ||          \  }}|                     |          |                     |          fS  | j        |fi | | j        |fi |fS rE  )r^  rq   r(  r_  r1  r   mpf_cos_sin_pir*  r   mpc_cos_sin_pir@  r   r   r   rb  s          r   cospi_sinpizMPContext.cospi_sinpi  s   77#)##AA00h1g 	>'x@@DAq<<??CLLOO33Q   	>'x@@DAq<<??CLLOO33371'''')=)=f)=)===r   c                 F    |                                  }| j        |_        |S )zP
        Create a copy of the context, with the same working precision.
        )	__class__r   )r   rL  s     r   clonezMPContext.clone)  s     MMOOr   c                 V    t          |d          st          |          t          u rdS dS )Nr@  FTr1  r^  complexr   r&  s     r   rY  zMPContext._is_real_type4  s.    1g 	$q''W"4"45tr   c                 V    t          |d          st          |          t          u rdS dS )Nr@  TFro  rq  s     r   _is_complex_typezMPContext._is_complex_type9  s.    1g 	$q''W"4"44ur   c                    t          |d          r|j        t          k    S t          |d          rt          |j        v S t	          |t
                    st	          |t          j                  rdS |                     |          }t          |d          st          |d          r| 	                    |          S t          d          )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*  r@  Fzisnan() needs a number as input)r1  r*  r#   r@  
isinstancer   r^   rr   r(  isnan	TypeErrorrq  s     r   rv  zMPContext.isnan>  s    " 1g 	#7d?"1g 	#17?"a## 	z!X\'B'B 	5KKNN1g 	 '!W"5"5 	 99Q<<9:::r   c                 ^    |                      |          s|                     |          rdS dS )a  
        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)isinfrv  rq  s     r   isfinitezMPContext.isfiniteZ  s1    , 99Q<< 	399Q<< 	5tr   c                    |sdS t          |d          r|j        \  }}}}|o|dk    S t          |d          r"|j         o|                     |j                  S t          |          t          v r|dk    S t          || j                  r|j	        \  }}|sdS |dk    o|dk    S |                     | 
                    |                    S )z<
        Determine if *x* is a nonpositive integer.
        Tr*  r   r@  r   )r1  r*  r9  isnpintr8  r^  r   ru  rr   _mpq_r(  )r   r&  signmanr   bcpqs           r   r|  zMPContext.isnpintt  s      	41g 	%!"D#sB$C1H$1g 	6v:5#++af"5"5577i6Ma!! 	%7DAq t6$a1f${{3;;q>>***r   c                     dd| j         z                      d          dz   d| j        z                      d          dz   d| j        z                      d          dz   g}d	                    |          S )
NzMpmath settings:z  mp.prec = %s   z[default: 53]z  mp.dps = %sz[default: 15]z  mp.trap_complex = %sz[default: False]
)r   ljustdpsrl   join)r   liness     r   __str__zMPContext.__str__  sy    #(//33oEsw&--b11OC%(88??CCFXX

 yyr   c                 *    t          | j                  S r%  )r   _precr   s    r   _repr_digitszMPContext._repr_digits  s    	"""r   c                     | j         S r%  )_dpsr   s    r   _str_digitszMPContext._str_digits  s	    xr   Fc                 .    t          | fdd|          S )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                     | z   S r%   r  r5  s    r   r   z%MPContext.extraprec.<locals>.<lambda>  s    q1u r   NPrecisionManagerr   r5  normalize_outputs    ` r   	extrapreczMPContext.extraprec  s        ____d<LMMMr   c                 .    t          | dfd|          S )z
        This function is analogous to extraprec (see documentation)
        but changes the decimal precision instead of the number of bits.
        Nc                     | z   S r%  r  dr5  s    r   r   z$MPContext.extradps.<locals>.<lambda>  s    QU r   r  r  s    ` r   extradpszMPContext.extradps  s     
  T????<LMMMr   c                 .    t          | fdd|          S )a  
        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   z$MPContext.workprec.<locals>.<lambda>  s    q r   Nr  r  s    ` r   workpreczMPContext.workprec  s       [[[[$8HIIIr   c                 .    t          | dfd|          S )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   z#MPContext.workdps.<locals>.<lambda>  s    Q r   r  r  s    ` r   workdpszMPContext.workdps  s     
  T;;;;8HIIIr   Nr  c                 "      fd}|S )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                  P   	j         }	                    |          }n}	 |dz   	_         	  
| i |}n# $ r
 	j        }Y nw xY w|dz   }	 |	_         	  
| i |}n# $ r
 	j        }Y nw xY w||k    rn	                    ||z
            	                    |          z
  }|| k     rnart	          d|d|d|            |}||k    r	                    d|z            |t          |dz            z  }t          ||          }|	_         n# |	_         w xY w|
 S )	N
      r   zautoprec: target=z, prec=z, accuracy=z2autoprec: prec increased to %i without convergence   )r   _default_hyper_maxprecr   magprintNoConvergencer/  min)argsrc  r   maxprec2v1prec2v2errcatchr   fmaxprecverboses           r   f_autoprec_wrappedz.MPContext.autoprec.<locals>.f_autoprec_wrapped  s   8D55d;;" "9!D+F++BB ! ! !BBB!r	1$CH%Q///  % % % W%Rxx''"R%..3772;;6Cte}} 3#ttUUUSDD2 3 3 3B((!//L ! ! ! Sq\\)Ex00E)1,  43JsP   
D 8 D AD AD A!  D !A0-D /A00B!D 	D"r  )r   r  r  r  r  r  s   ````` r   autopreczMPContext.autoprec  s>    H$	 $	 $	 $	 $	 $	 $	 $	 $	J "!r      c                 8    t          |t                    r&dd                     fd|D                       z  S t          |t                    r&dd                     fd|D                       z  S t	          |d          rt          |j        fi S t	          |d          rdt          |j        fi z   d	z   S t          |t                    rt          |          S t          | j                  r |j        fi S t          |          S )
a3  
        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   6   K   | ]} j         |fi V  d S r%  nstr.0rd  r   rc  r5  s     r   	<genexpr>z!MPContext.nstr.<locals>.<genexpr>]  9      &K&KAxsx1'?'?'?'?&K&K&K&K&K&Kr   z(%s)c              3   6   K   | ]} j         |fi V  d S r%  r  r  s     r   r  z!MPContext.nstr.<locals>.<genexpr>_  r  r   r*  r@  ())ru  listr  tupler1  r   r*  r:   r@  r   reprmatrix__nstr__str)r   r&  r5  rc  s   ` ``r   r  zMPContext.nstr4  sK   P a 	MTYY&K&K&K&K&K&K&K&K&KKKLLa 	MTYY&K&K&K&K&K&K&K&K&KKKLL1g 	0!'1/////1g 	AAGQ99&999S@@a$$ 	77Na$$ 	+1:a**6***1vvr   c                    |rt          |t                    rd|                                v r|                                                    dd          }t                              |          }|                    d          }|sd}|                    d                              d          }|                     | 	                    |          | 	                    |                    S t          |d          r4|j        \  }}||k    r|                     |          S t          d          t          d	t          |          z             )
Nr     rer   im_mpi_z,can only create mpf from zero-width intervalzcannot create mpf from )ru  r   lowerreplaceget_complexmatchgrouprstripro   r(  r1  r  r   
ValueErrorrw  r  )r   r&  stringsr  r  r  rL  rM  s           r   _convert_fallbackzMPContext._convert_fallbackj  s%    	Az!Z00 	AaggiiGGII%%c2..#))!,,[[&& B[[&&--c22wws{{2B@@@1g 	Q7DAqAvv||A& !OPPP1DGG;<<<r   c                      | j         |i |S r%  )r(  )r   r  rc  s      r   	mpmathifyzMPContext.mpmathify|  s    s{D+F+++r   c                    |r|                     d          rdS | j        \  }}d|v r|d         }d|v r%|d         }|| j        k    rdS t          |          }n(d|v r$|d         }|| j        k    rdS t	          |          }||fS | j        S )Nexact)r   r  r7  r   r  )getr+  r   r/  r   )r   rc  r   r7  r  s        r   r_  zMPContext._parse_prec  s     	"zz'"" v /ND(V##!*-f~37??!6t99DD&Um#'>>!6"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.Tc                    t          |d          r|||df}|j        }	nt          |d          r|||df}|j        }	|| j        vr"t	          j        |          d         | j        |<   | j        |         }
| j        }|                    d|                     |                    }d}d}i }d	}t          |          D ]\  }}||         d
k    rW||k    rP|d	k    rJd}t          |d |                   D ]\  }}||         d
k    r|d	k    r||k    rd} |st          d          h|                     |          \  }}t          |           }| }||k    r<|d	k    r6|dk    r0||v r||xx         |z  cc<   n|||<   t          |||z
  dz             }|t          |          z  }	 ||k    rt          | j        |||z   fz            ||z   }|rt#          d |D                       }ni } |
||	||||fi |\  }}}| }d}||k     r#|                                D ]}|||k     rd} n||dz
  dz
  k     p| }|r>|rnK|                    d          } | $|| k    r|r|                     d	          S | j        S |dz  }|dz  }|dz  }t+          |          t,          u r,|r|                     |          S |                     |          S |S )Nr*  Rr@  Cr   r  2      r   ZFTzpole in hypergeometric series   <   c              3      K   | ]}|d fV  	d S r%  r  )r  r5  s     r   r  z#MPContext.hypsum.<locals>.<genexpr>  s&      BBQ4BBBBBBr      zeroprecr  )r1  r*  r@  rv   r   make_hyp_summatorr   r  r  	enumerateZeroDivisionErrornint_distancer/  maxabsr  _hypsum_msgdictvaluesro   r   r^  r  r   r   )!r   r  r  flagscoeffsr6  accurate_smallrc  keyrN  summatorr   r  r  epsshiftmagnitude_checkmax_total_jumpird  okiiccr5  r  wpmag_dictzvhave_complex	magnitudecanceljumps_resolvedaccurater  s!                                    r   hypsumzMPContext.hypsum  s   1g 	Qs"CAAQ   	Qs"CAc'''%*%<S%A%A!%DCc"$S)x**Y(B(B4(H(HII	 f%% 	% 	%DAqQx366a1ffB"+F2A2J"7"7 & &B 9++aAGG!%B Q/0OPPP$$Q''DAqQAAAvv!q&&QUU''#A&&&!+&&&&)*OA&	1t8b=99	c!ff$NN#	7"" D$y.3I!IJJJ	!B BB/BBBBB*2(61dB(+. +.&,+. +.'BiZF!N>))!**  A	q4xx). (0 2a/E~3EH 
, !::j11'((' ,#&771::-#&8O NIMHNIG#	J 88u (||B'''||B'''Ir   c                     |                      |          }|                     t          j        |j        |                    S )a  
        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*  rB  s      r   ldexpzMPContext.ldexp  s3     KKNN||EOAGQ77888r   c                     |                      |          }t          j        |j                  \  }}|                     |          |fS )a=  
        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,  r5  s       r   frexpzMPContext.frexp   s=     KKNNqw''1||A!!r   c                 ^   |                      |          \  }}|                     |          }t          |d          r)|                     t	          |j        ||                    S t          |d          r)|                     t          |j        ||                    S t          d          )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*  r@  2Arguments need to be mpf or mpc compatible numbers)
r_  r(  r1  r   r&   r*  r   r?   r@  r  )r   r&  rc  r   r7  s        r   fnegzMPContext.fneg  s    \ 00hKKNN1g 	B<<x @ @AAA1g 	B<<x @ @AAAMNNNr   c                 2   |                      |          \  }}|                     |          }|                     |          }	 t          |d          r~t          |d          r/|                     t	          |j        |j        ||                    S t          |d          r/|                     t          |j        |j        ||                    S t          |d          r~t          |d          r/|                     t          |j        |j        ||                    S t          |d          r/|                     t          |j        |j        ||                    S n)# t          t          f$ r t          | j                  w xY wt          d          )a  
        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*  r@  r  )r_  r(  r1  r   r'   r*  r   rC   r@  rB   r  OverflowError_exact_overflow_msgr   r&  r,  rc  r   r7  s         r   faddzMPContext.faddF  s   p 00hKKNNKKNN	9q'"" W1g&& S<<$(Q(QRRR1g&& W<<AGQWdH(U(UVVVq'"" S1g&& W<<AGQWdH(U(UVVV1g&& S<<$(Q(QRRRM* 	9 	9 	9 7888	9MNNN    AE! >E! AE! !>E! !&Fc                 @   |                      |          \  }}|                     |          }|                     |          }	 t          |d          rt          |d          r/|                     t	          |j        |j        ||                    S t          |d          r6|                     t          |j        t          f|j	        ||                    S t          |d          r~t          |d          r/|                     t          |j	        |j        ||                    S t          |d          r/|                     t          |j	        |j	        ||                    S n)# t          t          f$ r t          | j                  w xY wt          d          )a  
        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*  r@  r  )r_  r(  r1  r   r(   r*  r   rD   r    r@  rE   r  r  r  r  s         r   fsubzMPContext.fsub  s   ` 00hKKNNKKNN	9q'"" \1g&& S<<$(Q(QRRR1g&& \<<%0@!'4QY(Z(Z[[[q'"" S1g&& W<<AGQWdH(U(UVVV1g&& S<<$(Q(QRRRM* 	9 	9 	9 7888	9MNNNs!   AE( AE( AE( (>E( (&Fc                 2   |                      |          \  }}|                     |          }|                     |          }	 t          |d          r~t          |d          r/|                     t	          |j        |j        ||                    S t          |d          r/|                     t          |j        |j        ||                    S t          |d          r~t          |d          r/|                     t          |j        |j        ||                    S t          |d          r/|                     t          |j        |j        ||                    S n)# t          t          f$ r t          | j                  w xY wt          d          )a  
        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*  r@  r  )r_  r(  r1  r   r)   r*  r   rG   r@  rF   r  r  r  r  s         r   fmulzMPContext.fmul  s   f 00hKKNNKKNN	9q'"" W1g&& S<<$(Q(QRRR1g&& W<<AGQWdH(U(UVVVq'"" S1g&& W<<AGQWdH(U(UVVV1g&& S<<$(Q(QRRRM* 	9 	9 	9 7888	9MNNNr  c                    |                      |          \  }}|st          d          |                     |          }|                     |          }t          |d          rt          |d          r/|                     t          |j        |j        ||                    S t          |d          r6|                     t          |j        t          f|j
        ||                    S t          |d          r~t          |d          r/|                     t          |j
        |j        ||                    S t          |d          r/|                     t          |j
        |j
        ||                    S t          d          )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*  r@  r  )r_  r  r(  r1  r   r+   r*  r   rI   r    r@  rJ   r  s         r   fdivzMPContext.fdiv  sf   b 00h 	CABBBKKNNKKNN1g 	Xq'"" O||GAGQWdH$M$MNNNq'"" X||GQWe,<agtX$V$VWWW1g 	Oq'"" S||K$$Q$QRRRq'"" O||GAGQWdH$M$MNNNMNNNr   c                 F   t          |          }|t          v rt          |          | j        fS |t          j        u rm|j        \  }}t          ||          \  }}d|z  |k    r|dz  }n|s	|| j        fS t          t          |||z  z
                      t          |          z
  }||fS t          |d          r|j        }| j        }	nt          |d          r;|j        \  }}
|
\  }}}}|r||z   }	n{|
t          k    r| j        }	nht          d          |                     |          }t          |d          st          |d          r|                     |          S t#          d          |\  }}}}||z   }|dk     rd}|}n|rg|dk    r||z  }| j        }nN|dk    r|dz	  dz   }d}n=| dz
  }||z	  }|dz  r|dz  }||z  |z
  }n|||z  z  }|dz	  }|t          |          z   }|r| }n$|t          k    r
| j        }d}nt          d          |t%          ||	          fS )	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  r   r*  r@  zrequires a finite numberzrequires an mpf/mpcr   )r^  r   r/  r   r^   rr   r}  divmodr8   r  r1  r*  r@  r    r  r(  r  rw  r  )r   r&  typxr  r  r5  rr  r  im_distr  isignimaniexpibcr~  r  r   r  r  re_distts                         r   r  zMPContext.nint_distanceY  s   B Aww9q6638##X\!!7DAq!Q<<DAqsaxxQ ##({"QqsU$$x{{2Aa4K1g 	7BhGGQ   	7WFB%'"E4s =*u( !;<<<AAq'"" 7ga&9&9 7((+++ 5666c3"f77AGG 	9axx3J(!VQJT!V1Hq5 "FAa43,CCAqDMCqDhsmm+ B5[[hGAA7888#gw''''r   c                 d    | j         }	 | j        }|D ]}||z  }	 || _         n# || _         w xY w|
 S )aT  
        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origrN  r  s        r   fprodzMPContext.fprod  sW     x	A  Q CHHtCHOOOOr	s   # 	,c                 P    |                      t          | j                            S )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   r6   r  r   s    r   randzMPContext.rand  s      ||HSY//000r   c                 D    |                      fdd          S )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                 (    t          | |          S r%  )r   )r   r   r  r  s     r   r   z$MPContext.fraction.<locals>.<lambda>  s    mAq$.L.L r   /)rp   )r   r  r  s    ``r   fractionzMPContext.fraction  s9    $ ||LLLLLqq!!  	r   c                 F    t          |                     |                    S r%  r  r(  rq  s     r   absminzMPContext.absmin      3;;q>>"""r   c                 F    t          |                     |                    S r%  r6  rq  s     r   absmaxzMPContext.absmax  r8  r   c                     t          |d          r4|j        \  }}|                     |          |                     |          gS |S )Nr  )r1  r  r   )r   r&  rL  rM  s       r   
_as_pointszMPContext._as_points  sC    1g 	67DAqLLOOS\\!__55r   r   c                 
                          |          rt          |d          st          t          |          } j        }t          j        |j        |||||          \  }} fd|D             } fd|D             }||fS )Nr@  c                 :    g | ]}                     |          S r  r   )r  r&  r   s     r   
<listcomp>z+MPContext._zetasum_fast.<locals>.<listcomp>  #    ***!cll1oo***r   c                 :    g | ]}                     |          S r  r?  )r  r,  r   s     r   r@  z+MPContext._zetasum_fast.<locals>.<listcomp>  rA  r   )isintr1  r2  r/  r  r   mpc_zetasumr@  )	r   re  rL  r5  derivativesreflectr   xsyss	   `        r   _zetasum_fastzMPContext._zetasum_fast  s    		! 	&G!4!4 	&%%FFy"17Aq+wMMB****r*******r***2vr   )r   F)Nr  F)r  )T)8__name__
__module____qualname____doc__rk   ru   r9   r-  r:  r<  rC  rH  rO  rx   rU  r}   r|   rf  rj  rm  rY  rs  rv  rz  r|  r  propertyr  r  r  r  r  r  r  r  r  r  r_  r  r  r	  r  r  r  r  r  r  r  r  r.  r0  r4  r7  r:  r<  rI  r  r   r   rg   rg   :   s        1 1 1BT5 T5 T5l     T T T. . .. . .
J 
J 
JP P PA A A AN N NM M MT T T
P P P> > >> > >    
  
; ; ;8  4+ + +(      # # X#   XN N N N$N N N NJ J J J"J J J Ji" i" i" i"V4 4 4 4l= = =$, , ," " "* DKS S S Sj9 9 9"" " " 4O 4O 4OlHO HO HOT@O @O @ODCO CO COJ@O @O @OD`( `( `(D  *1 1 1  *# # ## # #  " 23U      r   rg   c                   (    e Zd ZddZd Zd Zd ZdS )r  Fc                 >    || _         || _        || _        || _        d S r%  )r   precfundpsfunr  )selfr   rR  rS  r  s        r   rk   zPrecisionManager.__init__  s%     0r   c                 J     t          j                   fd            }|S )Nc                     j         j        }	 j        r*                    j         j                  j         _        n)                    j         j                  j         _        j        rR | i |}t          |          t          u r%t          d |D                       |j         _        S |
 |j         _        S  | i ||j         _        S # |j         _        w xY w)Nc                     g | ]}|
 S r  r  )r  rL  s     r   r@  z8PrecisionManager.__call__.<locals>.g.<locals>.<listcomp>'  s    ___Qqb___r   )r   r   rR  rS  r  r  r^  r  )r  rc  r-  rN  r  rT  s       r   gz$PrecisionManager.__call__.<locals>.g  s    8=D%< =$(LL$?$?DHMM#';;tx|#<#<DHL( .4*6**AAww%''$__!___55
 !%	 2 !% 1d-f-- $$$$$s   BC 3C C C$)	functoolswraps)rT  r  rX  s   `` r   __call__zPrecisionManager.__call__  s>    				% 	% 	% 	% 	% 
		%  r   c                     | j         j        | _        | j        r+|                     | j         j                  | j         _        d S |                     | j         j                  | j         _        d S r%  )r   r   origprR  rS  r  )rT  s    r   	__enter__zPrecisionManager.__enter__.  sQ    X]
< 	5 LL77DHMMM;;tx|44DHLLLr   c                 (    | j         | j        _        dS ri   )r]  r   r   )rT  exc_typeexc_valexc_tbs       r   __exit__zPrecisionManager.__exit__4  s    
ur   NrJ  )rK  rL  rM  rk   r[  r^  rc  r  r   r   r  r    sU        1 1 1 1
  &5 5 5    r   r  __main__)wrN  __docformat__rY  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/   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\   r]   r^   object__new__newcompiler  sage.libs.mpmath.ext_mainr`   rj   libsmpmathext_main_mpf_modulerb   ra   rc   rd   re   rg   r  rK  doctesttestmodr  r   r   <module>rs     s0         				 ) ) ) ) ) ) . . . . . . . .                                                                                                                                                                                   .            nbj K L L fBBBBBB3333333333333??????...... 0 0 0 0 0 0 0 0 0 0Y Y Y Y Y2 Y Y Yv&! ! ! ! ! ! ! !H zNNNGO r   