o
    ôj·“  ã                   @   s  d dl mZmZ d dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)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@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZ d dlZm[Z[ d dlZm\Z\ e]j^Z_G dd„ de]ƒZ`G dd„ de`ƒZad	Zbd
ZcdZddecedf Zed3dd„Zfefddddƒea_gefddec dec ded ƒea_hefddec dec ded ƒea_iefddec dec ded ƒea_jefd d!ec d"ec d#ed ƒea_kefd$d%ec d&ec d'ƒea_lefd(eed)ec d*ed ƒea_meajhea_neajjea_oeajkea_peajqea_rG d+d,„ d,eaƒZsG d-d.„ d.e`ƒZteuetfZvG d/d0„ d0e]ƒZwzd1d2lxZxexjy zet¡ exj{ zea¡ W d2S  e|�yŒ   Y d2S w )4é   )Ú
basestringÚexec_)WÚ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_npfloatÚfrom_DecimalÚ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   )Úrational)Úfunction_docsc                   @   s   e Zd ZdZg Zdd„ ZdS )Ú	mpnumericzBase class for mpf and mpc.c                 C   s   t ‚©N)ÚNotImplementedError)ÚclsÚval© ra   úg/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/mpmath/ctx_mp_python.pyÚ__new__$   s   zmpnumeric.__new__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rc   ra   ra   ra   rb   r\   !   s    r\   c                   @   s|  e Zd ZdZdgZefdd„Zedd„ ƒZedd„ ƒZ	ed	d
„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZeZd'd(„ Zd)d*„ Zd+d,„ Z d-d.„ Z!d/d0„ Z"d1d2„ Z#d3d4„ Z$d5d6„ Z%d7d8„ Z&d9d:„ Z'd;d<„ Z(d=d>„ Z)d?d@„ Z*dAdB„ Z+dCdD„ Z,dLdFdG„Z-dHdI„ Z.dJdK„ Z/dES )MÚ_mpfz¡
    An mpf instance holds a real-valued floating-point number. mpf:s
    work analogously to Python floats, but support arbitrary-precision
    arithmetic.
    Ú_mpf_c           
      K   s4  | j j\}}|r| d|¡}d|v rt|d ƒ}| d|¡}t|ƒ| u rA|j\}}}}|s1|r1|S t| ƒ}	t||||||ƒ|	_|	S t|ƒtu rˆt	|ƒdkr_t| ƒ}	t
|d |d ||ƒ|	_|	S t	|ƒdkr†|tttfvr}|\}}}}t|t|ƒ||||ƒ}t| ƒ}	||	_|	S t‚t| ƒ}	t|  |||¡||ƒ|	_|	S )z‹A new mpf can be created from a Python float, an int, a
        or a decimal string representing a number in floating-point
        format.ÚprecÚdpsÚroundingé   é    r   é   )ÚcontextÚ_prec_roundingÚgetr   Útyperj   Únewr   ÚtupleÚlenr   r   r   r    r   Ú
ValueErrorr"   Úmpf_convert_arg)
r_   r`   Úkwargsrk   rm   ÚsignÚmanÚexpÚbcÚvra   ra   rb   rc   /   s:   z_mpf.__new__c                 C   sÊ   t |tƒr	t|ƒS t |tƒrt|ƒS t |tƒrt|||ƒS t || jjƒr*| 	||¡S t
|dƒr2|jS t
|dƒrI| j | ||¡¡}t
|dƒrI|jS t
|dƒr]|j\}}||krY|S tdƒ‚tdt|ƒ ƒ‚)Nrj   Ú_mpmath_Ú_mpi_z,can only create mpf from zero-width intervalúcannot create mpf from )Ú
isinstancer   r   Úfloatr   r   r   rq   ÚconstantÚfuncÚhasattrrj   Úconvertr€   r�   rx   Ú	TypeErrorÚrepr)r_   Úxrk   rm   ÚtÚaÚbra   ra   rb   ry   R   s   



z_mpf.mpf_convert_argc                 C   s¨   t |tƒr	t|ƒS t |tƒrt|ƒS t |tƒr| j |¡S t |tj	ƒr0|j
\}}t||| jjƒS t|dƒr8|jS t|dƒrR| j |j| jjŽ ¡}t|dƒrP|jS |S tS )Nrj   r€   )rƒ   r   r   r„   r   Úcomplex_typesrq   ÚmpcrZ   ÚmpqÚ_mpq_r   rk   r‡   rj   rˆ   r€   rr   ÚNotImplemented)r_   r‹   ÚpÚqrŒ   ra   ra   rb   Úmpf_convert_rhsd   s   


z_mpf.mpf_convert_rhsc                 C   s&   |   |¡}t|ƒtu r| j |¡S |S r]   )r–   rt   rv   rq   Úmake_mpf)r_   r‹   ra   ra   rb   Úmpf_convert_lhst   s   
z_mpf.mpf_convert_lhsc                 C   s   | j dd… S )Nr   é   ©rj   ©Úselfra   ra   rb   Ú<lambda>{   ó    z_mpf.<lambda>c                 C   ó
   | j d S ©Nr   rš   r›   ra   ra   rb   r�   |   ó   
 c                 C   rŸ   )Nrn   rš   r›   ra   ra   rb   r�   }   r¡   c                 C   rŸ   )Nr™   rš   r›   ra   ra   rb   r�   ~   r¡   c                 C   ó   | S r]   ra   r›   ra   ra   rb   r�   €   ó    c                 C   s   | j jS r]   )rq   Úzeror›   ra   ra   rb   r�   �   s    c                 C   r¢   r]   ra   r›   ra   ra   rb   r�   ƒ   r£   c                 C   ó
   t | jƒS r]   )r   rj   r›   ra   ra   rb   Ú__getstate__…   r¡   z_mpf.__getstate__c                 C   s   t |ƒ| _d S r]   )r   rj   ©rœ   r`   ra   ra   rb   Ú__setstate__†   rž   z_mpf.__setstate__c                 C   s$   | j jrt| ƒS dt| j| j jƒ S )Nz	mpf('%s'))rq   ÚprettyÚstrr   rj   Ú_repr_digits©Úsra   ra   rb   Ú__repr__ˆ   s   z_mpf.__repr__c                 C   s   t | j| jjƒS r]   )r   rj   rq   Ú_str_digitsr¬   ra   ra   rb   Ú__str__�   s    z_mpf.__str__c                 C   r¥   r]   )r2   rj   r¬   ra   ra   rb   Ú__hash__Ž   r¡   z_mpf.__hash__c                 C   ó   t t| jƒƒS r]   )Úintr   rj   r¬   ra   ra   rb   Ú__int__�   rž   z_mpf.__int__c                 C   r²   r]   )Úlongr   rj   r¬   ra   ra   rb   Ú__long__�   rž   z_mpf.__long__c                 C   ó   t | j| jjd d�S ©Nr   )Úrnd)r   rj   rq   rr   r¬   ra   ra   rb   Ú	__float__‘   s    z_mpf.__float__c                 C   s   t t| ƒƒS r]   )Úcomplexr„   r¬   ra   ra   rb   Ú__complex__’   ó    z_mpf.__complex__c                 C   s
   | j tkS r]   )rj   r   r¬   ra   ra   rb   Ú__nonzero__“   r¡   z_mpf.__nonzero__c                 C   ó,   | j \}}\}}||ƒ}t| j||ƒ|_|S r]   )Ú_ctxdatar!   rj   ©r­   r_   ru   rk   rm   r   ra   ra   rb   Ú__abs__—   ó   z_mpf.__abs__c                 C   r¿   r]   )rÀ   r"   rj   rÁ   ra   ra   rb   Ú__pos__�   rÃ   z_mpf.__pos__c                 C   r¿   r]   )rÀ   r#   rj   rÁ   ra   ra   rb   Ú__neg__£   rÃ   z_mpf.__neg__c                 C   s4   t |dƒr	|j}n|  |¡}|tu r|S || j|ƒS ©Nrj   )r‡   rj   r–   r“   )r­   rŒ   r†   ra   ra   rb   Ú_cmp©   s   

z	_mpf._cmpc                 C   ó   |   |t¡S r]   )rÇ   r-   ©r­   rŒ   ra   ra   rb   Ú__cmp__²   r½   z_mpf.__cmp__c                 C   rÈ   r]   )rÇ   r.   rÉ   ra   ra   rb   Ú__lt__³   r½   z_mpf.__lt__c                 C   rÈ   r]   )rÇ   r/   rÉ   ra   ra   rb   Ú__gt__´   r½   z_mpf.__gt__c                 C   rÈ   r]   )rÇ   r0   rÉ   ra   ra   rb   Ú__le__µ   r½   z_mpf.__le__c                 C   rÈ   r]   )rÇ   r1   rÉ   ra   ra   rb   Ú__ge__¶   r½   z_mpf.__ge__c                 C   ó   |   |¡}|tu r|S | S r]   ©Ú__eq__r“   )r­   rŒ   r   ra   ra   rb   Ú__ne__¸   ó   
z_mpf.__ne__c                 C   s\   | j \}}\}}t|ƒtv r||ƒ}tt|ƒ| j||ƒ|_|S |  |¡}|tu r*|S ||  S r]   )rÀ   rt   r   r%   r   rj   r˜   r“   ©r­   rŒ   r_   ru   rk   rm   r   ra   ra   rb   Ú__rsub__¾   s   
z_mpf.__rsub__c                 C   sV   | j \}}\}}t|tƒr||ƒ}t|| j||ƒ|_|S |  |¡}|tu r'|S ||  S r]   )rÀ   rƒ   r   r)   rj   r˜   r“   rÔ   ra   ra   rb   Ú__rdiv__É   ó   

z_mpf.__rdiv__c                 C   ó   |   |¡}|tu r|S ||  S r]   ©r˜   r“   rÉ   ra   ra   rb   Ú__rpow__Ô   ó   
z_mpf.__rpow__c                 C   s   |   |¡}|tu r|S ||  S r]   rÙ   rÉ   ra   ra   rb   Ú__rmod__Ú   rÛ   z_mpf.__rmod__c                 C   s   | j  | ¡S r]   )rq   Úsqrtr¬   ra   ra   rb   rÝ   à   ó   z	_mpf.sqrtNc                 C   ó   | j  | |||¡S r]   ©rq   Úalmosteq©r­   rŒ   Úrel_epsÚabs_epsra   ra   rb   Úaeã   ó   z_mpf.aec                 C   s   t | j|ƒS r]   )r6   rj   )rœ   rk   ra   ra   rb   r6   æ   rÞ   z_mpf.to_fixedc                 G   s   t t| ƒg|¢R Ž S r]   )Úroundr„   )rœ   Úargsra   ra   rb   Ú	__round__é   ó   z_mpf.__round__©NN)0rd   re   rf   rg   rh   r   rc   Úclassmethodry   r–   r˜   ÚpropertyZman_expr|   r}   r~   ÚrealÚimagÚ	conjugater¦   r¨   r®   r°   r±   r´   r¶   rº   r¼   r¾   Ú__bool__rÂ   rÄ   rÅ   rÇ   rÊ   rË   rÌ   rÍ   rÎ   rÒ   rÕ   rÖ   rÚ   rÜ   rÝ   rå   r6   ré   ra   ra   ra   rb   ri   '   s\    #


	
ri   a  
def %NAME%(self, other):
    mpf, new, (prec, rounding) = self._ctxdata
    sval = self._mpf_
    if hasattr(other, '_mpf_'):
        tval = other._mpf_
        %WITH_MPF%
    ttype = type(other)
    if ttype in int_types:
        %WITH_INT%
    elif ttype is float:
        tval = from_float(other)
        %WITH_MPF%
    elif hasattr(other, '_mpc_'):
        tval = other._mpc_
        mpc = type(other)
        %WITH_MPC%
    elif ttype is complex:
        tval = from_float(other.real), from_float(other.imag)
        mpc = self.context.mpc
        %WITH_MPC%
    if isinstance(other, mpnumeric):
        return NotImplemented
    try:
        other = mpf.context.convert(other, strings=False)
    except TypeError:
        return NotImplemented
    return self.%NAME%(other)
z-; obj = new(mpf); obj._mpf_ = val; return objz-; obj = new(mpc); obj._mpc_ = val; return obja  
        try:
            val = mpf_pow(sval, tval, prec, rounding) %s
        except ComplexResult:
            if mpf.context.trap_complex:
                raise
            mpc = mpf.context.mpc
            val = mpc_pow((sval, fzero), (tval, fzero), prec, rounding) %s
Ú c                 C   sN   t }| d|¡}| d|¡}| d|¡}| d| ¡}i }t|tƒ |ƒ ||  S )Nz
%WITH_INT%z
%WITH_MPC%z
%WITH_MPF%z%NAME%)Úmpf_binary_opÚreplacer   Úglobals)ÚnameZwith_mpfZwith_intZwith_mpcÚcodeÚnpra   ra   rb   Ú	binary_op  s   rù   rÑ   zreturn mpf_eq(sval, tval)z$return mpf_eq(sval, from_int(other))z3return (tval[1] == fzero) and mpf_eq(tval[0], sval)Ú__add__z)val = mpf_add(sval, tval, prec, rounding)z4val = mpf_add(sval, from_int(other), prec, rounding)z-val = mpc_add_mpf(tval, sval, prec, rounding)Ú__sub__z)val = mpf_sub(sval, tval, prec, rounding)z4val = mpf_sub(sval, from_int(other), prec, rounding)z2val = mpc_sub((sval, fzero), tval, prec, rounding)Ú__mul__z)val = mpf_mul(sval, tval, prec, rounding)z.val = mpf_mul_int(sval, other, prec, rounding)z-val = mpc_mul_mpf(tval, sval, prec, rounding)Ú__div__z)val = mpf_div(sval, tval, prec, rounding)z4val = mpf_div(sval, from_int(other), prec, rounding)z-val = mpc_mpf_div(sval, tval, prec, rounding)Ú__mod__z)val = mpf_mod(sval, tval, prec, rounding)z4val = mpf_mod(sval, from_int(other), prec, rounding)z+raise NotImplementedError("complex modulo")Ú__pow__z.val = mpf_pow_int(sval, other, prec, rounding)z2val = mpc_pow((sval, fzero), tval, prec, rounding)c                   @   s8   e Zd ZdZddd„Zddd„Zedd	„ ƒZd
d„ ZdS )Ú	_constantzõRepresents a mathematical constant with dynamic precision.
    When printed or used in an arithmetic operation, a constant
    is converted to a regular mpf at the working precision. A
    regular mpf can also be obtained using the operation +x.rò   c                 C   s(   t  | ¡}||_||_tt|dƒ|_|S )Nrò   )Úobjectrc   rö   r†   Úgetattrr[   rg   )r_   r†   rö   Zdocnamer�   ra   ra   rb   rc   P  s
   
z_constant.__new__Nc                 C   s<   | j j\}}|s
|}|s|}|rt|ƒ}| j  |  ||¡¡S r]   )rq   rr   r   r—   r†   )rœ   rk   rl   rm   Úprec2Z	rounding2ra   ra   rb   Ú__call__W  s
   z_constant.__call__c                 C   s   | j j\}}|  ||¡S r]   )rq   rr   r†   )rœ   rk   rm   ra   ra   rb   rj   ^  s   z_constant._mpf_c                 C   s   d| j | j | dd�¡f S )Nz	<%s: %s~>é   )rl   )rö   rq   Únstrr›   ra   ra   rb   r®   c  ó   z_constant.__repr__)rò   )NNN)	rd   re   rf   rg   rc   r  rí   rj   r®   ra   ra   ra   rb   r   J  s    


r   c                   @   s&  e Zd ZdZdgZd<dd„Zedd„ ƒZedd„ ƒZd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZeZdd„ Zedd „ ƒZd!d"„ Zd#d$„ Zd%d&„ ZeZeZeZeZd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Z d/d0„ Z!eZ"d1d2„ Z#d3d4„ Z$d5d6„ Z%d7d8„ Z&e Z'e%Z(d=d:d;„Z)d9S )>Ú_mpczÇ
    An mpc represents a complex number using a pair of mpf:s (one
    for the real part and another for the imaginary part.) The mpc
    class behaves fairly similarly to Python's complex type.
    Ú_mpc_ro   c                 C   sd   t  | ¡}t|tƒr|j|j}}nt|dƒr|j|_|S | j 	|¡}| j 	|¡}|j
|j
f|_|S )Nr	  )r  rc   rƒ   r�   rî   rï   r‡   r	  rq   Úmpfrj   )r_   rî   rï   r­   ra   ra   rb   rc   p  s   


z_mpc.__new__c                 C   ó   | j  | jd ¡S )Nro   ©rq   r—   r	  r›   ra   ra   rb   r�   |  ó    z_mpc.<lambda>c                 C   r  r    r  r›   ra   ra   rb   r�   }  r  c                 C   s   t | jd ƒt | jd ƒfS ©Nro   r   )r   r	  r›   ra   ra   rb   r¦     r  z_mpc.__getstate__c                 C   s   t |d ƒt |d ƒf| _d S r  )r   r	  r§   ra   ra   rb   r¨   ‚  s   z_mpc.__setstate__c                 C   sH   | j jrt| ƒS t| jƒdd… }t| jƒdd… }dt| ƒj||f S )Nrp   éÿÿÿÿz%s(real=%s, imag=%s))rq   r©   rª   rŠ   rî   rï   rt   rd   )r­   ÚrÚira   ra   rb   r®   …  s
   z_mpc.__repr__c                 C   s   dt | j| jjƒ S )Nz(%s))r7   r	  rq   r¯   r¬   ra   ra   rb   r°   Œ  rê   z_mpc.__str__c                 C   r·   r¸   )r8   r	  rq   rr   r¬   ra   ra   rb   r¼   �  s   z_mpc.__complex__c                 C   r¿   r]   )rÀ   r:   r	  rÁ   ra   ra   rb   rÄ   ’  rÃ   z_mpc.__pos__c                 C   s,   | j j\}}t| j jƒ}t| j||ƒ|_|S r]   )rq   rr   ru   r
  r>   r	  rj   )r­   rk   rm   r   ra   ra   rb   rÂ   ˜  s   z_mpc.__abs__c                 C   r¿   r]   )rÀ   r<   r	  rÁ   ra   ra   rb   rÅ   ž  rÃ   z_mpc.__neg__c                 C   r¿   r]   )rÀ   r=   r	  rÁ   ra   ra   rb   rð   ¤  rÃ   z_mpc.conjugatec                 C   r¥   r]   )r;   r	  r¬   ra   ra   rb   r¾   ª  ó   
z_mpc.__nonzero__c                 C   r¥   r]   )r9   r	  r¬   ra   ra   rb   r±   ¯  r  z_mpc.__hash__c                 C   s*   z	| j  |¡}|W S  ty   t Y S w r]   )rq   rˆ   r‰   r“   )r_   r‹   Úyra   ra   rb   Úmpc_convert_lhs²  s   ÿz_mpc.mpc_convert_lhsc                 C   sF   t |dƒst|tƒrdS |  |¡}|tu r|S | j|jko"| j|jkS )Nr	  F)r‡   rƒ   rª   r  r“   rî   rï   rÉ   ra   ra   rb   rÑ   º  s   


z_mpc.__eq__c                 C   rÏ   r]   rÐ   )r­   rŒ   rŽ   ra   ra   rb   rÒ   Ã  rÓ   z_mpc.__ne__c                  G   s   t dƒ‚)Nz3no ordering relation is defined for complex numbers)r‰   )rè   ra   ra   rb   Ú_compareÉ  s   z_mpc._comparec                 C   óz   | j \}}\}}t|dƒs-|  |¡}|tu r|S t|dƒr-||ƒ}t| j|j||ƒ|_|S ||ƒ}t| j|j||ƒ|_|S ©Nr	  rj   )rÀ   r‡   r  r“   r@   r	  rj   r?   rÔ   ra   ra   rb   rú   Ñ  ó   


z_mpc.__add__c                 C   r  r  )rÀ   r‡   r  r“   rB   r	  rj   rA   rÔ   ra   ra   rb   rû   ß  r  z_mpc.__sub__c                 C   s¬   | j \}}\}}t|dƒsFt|tƒr!||ƒ}t| j|||ƒ|_|S |  |¡}|tu r,|S t|dƒrA||ƒ}t| j|j	||ƒ|_|S |  |¡}||ƒ}t
| j|j||ƒ|_|S r  )rÀ   r‡   rƒ   r   rE   r	  r  r“   rD   rj   rC   rÔ   ra   ra   rb   rü   í  s"   




z_mpc.__mul__c                 C   r  r  )rÀ   r‡   r  r“   rG   r	  rj   rF   rÔ   ra   ra   rb   rý      r  z_mpc.__div__c                 C   s�   | j \}}\}}t|tƒr||ƒ}t| j|||ƒ|_|S |  |¡}|tu r'|S ||ƒ}t|dƒr<t| j|j	||ƒ|_|S t
| j|j||ƒ|_|S rÆ   )rÀ   rƒ   r   rJ   r	  r  r“   r‡   rI   rj   rH   rÔ   ra   ra   rb   rÿ     s   


ÿz_mpc.__pow__c                 C   s   |   |¡}|tu r|S ||  S r]   ©r  r“   rÉ   ra   ra   rb   rÕ      rÛ   z_mpc.__rsub__c                 C   sV   | j \}}\}}t|tƒr||ƒ}t| j|||ƒ|_|S |  |¡}|tu r'|S ||  S r]   )rÀ   rƒ   r   rE   r	  r  r“   rÔ   ra   ra   rb   Ú__rmul__&  r×   z_mpc.__rmul__c                 C   s   |   |¡}|tu r|S ||  S r]   r  rÉ   ra   ra   rb   rÖ   1  rÛ   z_mpc.__rdiv__c                 C   rØ   r]   r  rÉ   ra   ra   rb   rÚ   7  rÛ   z_mpc.__rpow__Nc                 C   rß   r]   rà   râ   ra   ra   rb   rå   @  ræ   z_mpc.ae)ro   ro   rë   )*rd   re   rf   rg   rh   rc   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ÿ   Ú__radd__rÕ   r  rÖ   rÚ   Ú__truediv__Ú__rtruediv__rå   ra   ra   ra   rb   r  g  sP    

	r  c                   @   sÎ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	dd„ eƒZ
e	dd„ eƒZd.dd„Zdd„ Zdd„ Zdd„ Zdd„ Zd/dd„Zd0dd„Zd1d!d"„Zd2d$d%„Zed&d'„ ƒZd(d)„ Zd*d+„ Zd,d-„ Zd S )3ÚPythonMPContextc                 C   sŒ   dt g| _tdtfi ƒ| _tdtfi ƒ| _| jt| jg| j_| jt| jg| j_| | j_	| | j_	tdt
fi ƒ| _| jt| jg| j_| | j_	d S )Né5   r
  r�   r…   )r   rr   rt   ri   r
  r  r�   ru   rÀ   rq   r   r…   ©Úctxra   ra   rb   Ú__init__I  s   
zPythonMPContext.__init__c                 C   ó   t | jƒ}||_|S r]   )ru   r
  rj   ©r!  r   r�   ra   ra   rb   r—   U  ó   
zPythonMPContext.make_mpfc                 C   r#  r]   )ru   r�   r	  r$  ra   ra   rb   Úmake_mpcZ  r%  zPythonMPContext.make_mpcc                 C   s    d | _ | jd< d| _d| _d S )Nr  ro   r  F)Ú_precrr   Ú_dpsÚtrap_complexr   ra   ra   rb   Údefault_  s   
zPythonMPContext.defaultc                 C   s(   t dt|ƒƒ | _| jd< t|ƒ| _d S )Nr   ro   )Úmaxr³   r'  rr   r   r(  ©r!  Únra   ra   rb   Ú	_set_precd  s   zPythonMPContext._set_precc                 C   s(   t |ƒ | _| jd< tdt|ƒƒ| _d S r  )r   r'  rr   r+  r³   r(  r,  ra   ra   rb   Ú_set_dpsh  s   zPythonMPContext._set_dpsc                 C   ó   | j S r]   )r'  r   ra   ra   rb   r�   l  ó    zPythonMPContext.<lambda>c                 C   r0  r]   )r(  r   ra   ra   rb   r�   m  r1  Tc                 C   sœ  t |ƒ| jv r	|S t|tƒr|  t|ƒ¡S t|tƒr!|  t|ƒ¡S t|tƒr3|  	t|j
ƒt|jƒf¡S t |ƒjdkr?|  |¡S t|tjƒrXzt t|jƒt|jƒ¡}W n   Y | j\}}t|tjƒrq|j\}}|  t|||ƒ¡S |rŽt|tƒrŽzt|||ƒ}|  |¡W S  ty�   Y nw t|dƒr™|  |j¡S t|dƒr¤|  	|j¡S t|dƒr²|  | ||¡¡S t |ƒjdkrÈz
|  t |||ƒ¡W S    Y |  !||¡S )a»  
        Converts *x* to an ``mpf`` or ``mpc``. If *x* is of type ``mpf``,
        ``mpc``, ``int``, ``float``, ``complex``, the conversion
        will be performed losslessly.

        If *x* is a string, the result will be rounded to the present
        working precision. Strings representing fractions or complex
        numbers are permitted.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> mpmathify(3.5)
            mpf('3.5')
            >>> mpmathify('2.1')
            mpf('2.1000000000000001')
            >>> mpmathify('3/4')
            mpf('0.75')
            >>> mpmathify('2+3j')
            mpc(real='2.0', imag='3.0')

        Únumpyrj   r	  r€   Údecimal)"rt   Útypesrƒ   r   r—   r   r„   r   r»   r&  rî   rï   re   Ú	npconvertÚnumbersÚRationalrZ   r‘   r³   Ú	numeratorÚdenominatorrr   r’   r   r   r   rx   r‡   rj   r	  rˆ   r€   r   Ú_convert_fallback)r!  r‹   Ústringsrk   rm   r”   r•   rj   ra   ra   rb   rˆ   o  s8   


ÿ
zPythonMPContext.convertc                 C   sv   ddl }t||jƒr|  tt|ƒƒ¡S t||jƒr |  t|ƒ¡S t||jƒr3|  	t|j
ƒt|jƒf¡S tdt|ƒ ƒ‚)z^
        Converts *x* to an ``mpf`` or ``mpc``. *x* should be a numpy
        scalar.
        ro   Nr‚   )r2  rƒ   Úintegerr—   r   r³   Úfloatingr   Úcomplexfloatingr&  rî   rï   r‰   rŠ   )r!  r‹   rø   ra   ra   rb   r5  ¡  s   zPythonMPContext.npconvertc                 C   sr   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ƒs0t |dƒr5|  	|¡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

        rj   r	  Fzisnan() needs a number as input)r‡   rj   r    r	  rƒ   r   rZ   r‘   rˆ   Úisnanr‰   )r!  r‹   ra   ra   rb   r?  ­  s   





zPythonMPContext.isnanc                 C   sŽ   t |dƒr|jttfv S t |dƒr"|j\}}|ttfv p!|ttfv S t|tƒs-t|tjƒr/dS |  	|¡}t |dƒs>t |dƒrC|  
|¡S tdƒ‚)a«  
        Return *True* if the absolute value of *x* is infinite;
        otherwise return *False*::

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

        rj   r	  Fzisinf() needs a number as input)r‡   rj   r   r   r	  rƒ   r   rZ   r‘   rˆ   Úisinfr‰   )r!  r‹   ÚreÚimra   ra   rb   r@  É  s   




zPythonMPContext.isinfc                 C   s²   t |dƒrt|jd ƒS t |dƒr2|j\}}t|d ƒ}t|d ƒ}|tkr(|S |tkr.|S |o1|S t|tƒs=t|tjƒrAt|ƒS |  	|¡}t |dƒsPt |dƒrU|  
|¡S tdƒ‚)aº  
        Determine whether *x* is "normal" in the sense of floating-point
        representation; that is, return *False* if *x* is zero, an
        infinity or NaN; otherwise return *True*. By extension, a
        complex number *x* is considered "normal" if its magnitude is
        normal::

            >>> from mpmath import *
            >>> isnormal(3)
            True
            >>> isnormal(0)
            False
            >>> isnormal(inf); isnormal(-inf); isnormal(nan)
            False
            False
            False
            >>> isnormal(0+0j)
            False
            >>> isnormal(0+3j)
            True
            >>> isnormal(mpc(2,nan))
            False
        rj   r   r	  z"isnormal() needs a number as input)r‡   Úboolrj   r	  r   rƒ   r   rZ   r‘   rˆ   Úisnormalr‰   )r!  r‹   rA  rB  Z	re_normalZ	im_normalra   ra   rb   rD  é  s   




zPythonMPContext.isnormalFc                 C   s  t |tƒrdS t|dƒr!|j \}}}}}t|r|dkp|tkƒS t|dƒrW|j\}}	|\}
}}}|	\}}}}|r=|dkp@|tk}|rQ|rI|dkpL|	tk}|oP|S |oV|	tkS t |tjƒrh|j	\}}|| dkS |  
|¡}t|dƒswt|dƒr}|  ||¡S tdƒ‚)a
  
        Return *True* if *x* is integer-valued; otherwise return
        *False*::

            >>> from mpmath import *
            >>> isint(3)
            True
            >>> isint(mpf(3))
            True
            >>> isint(3.2)
            False
            >>> isint(inf)
            False

        Optionally, Gaussian integers can be checked for::

            >>> isint(3+0j)
            True
            >>> isint(3+2j)
            False
            >>> isint(3+2j, gaussian=True)
            True

        Trj   ro   r	  zisint() needs a number as input)rƒ   r   r‡   rj   rC  r   r	  rZ   r‘   r’   rˆ   Úisintr‰   )r!  r‹   Úgaussianr{   r|   r}   r~   ZxvalrA  rB  ÚrsignÚrmanÚrexpÚrbcÚisignÚimanÚiexpÚibcZre_isintZim_isintr”   r•   ra   ra   rb   rE    s*   





zPythonMPContext.isintc                 C   sn  | j \}}g }g }|D ]Ž}d }	}
t|dƒr|j}	n&t|dƒr%|j\}	}
n|  |¡}t|dƒr3|j}	nt|dƒr>|j\}	}
nt‚|
r†|rn|rW| t|	|	ƒ¡ | t|
|
ƒ¡ qt|	|
fd|d ƒ\}	}
| |	¡ | |
¡ q|r{| t	|	|
f|ƒ¡ q| |	¡ | |
¡ q|rŽt|	|	ƒ}	n|r”t
|	ƒ}	| |	¡ qt||||ƒ}|r°|  |t|||ƒf¡}|S |  |¡}|S )aX  
        Calculates a sum containing a finite number of terms (for infinite
        series, see :func:`~mpmath.nsum`). The terms will be converted to
        mpmath numbers. For len(terms) > 2, this function is generally
        faster and produces more accurate results than the builtin
        Python function :func:`sum`.

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

        With squared=True each term is squared, and with absolute=True
        the absolute value of each term is used.
        ro   rj   r	  rn   é
   )rr   r‡   rj   r	  rˆ   r^   Úappendr&   rJ   r>   r!   r4   r&  r—   )r!  ÚtermsÚabsoluteÚsquaredrk   r¹   rî   rï   ÚtermZrevalZimvalr­   ra   ra   rb   Úfsum@  sL   








ÿzPythonMPContext.fsumNc                 C   sÜ  |dur	t ||ƒ}| j\}}g }g }t}| j| jf}	|D ]µ\}
}t|
ƒ|	vr+|  |
¡}
t|ƒ|	vr6|  |¡}||
dƒ}||dƒ}|rO|rO| t|
j	|j	ƒ¡ q||
dƒ}||dƒ}|r||r||
j	}|j
\}}|rkt|ƒ}| t||ƒ¡ | t||ƒ¡ q|r™|r™|
j
\}}|j	}| t||ƒ¡ | t||ƒ¡ q|rÐ|rÐ|
j
\}}|j
\}}|r­t|ƒ}| t||ƒ¡ | tt||ƒƒ¡ | t||ƒ¡ | t||ƒ¡ qt‚t|||ƒ}|rç|  |t|||ƒf¡}|S |  |¡}|S )a.  
        Computes the dot product of the iterables `A` and `B`,

        .. math ::

            \sum_{k=0} A_k B_k.

        Alternatively, :func:`~mpmath.fdot` accepts a single iterable of pairs.
        In other words, ``fdot(A,B)`` and ``fdot(zip(A,B))`` are equivalent.
        The elements are automatically converted to mpmath numbers.

        With ``conjugate=True``, the elements in the second vector
        will be conjugated:

        .. math ::

            \sum_{k=0} A_k \overline{B_k}

        **Examples**

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> A = [2, 1.5, 3]
            >>> B = [1, -1, 2]
            >>> fdot(A, B)
            mpf('6.5')
            >>> list(zip(A, B))
            [(2, 1), (1.5, -1), (3, 2)]
            >>> fdot(_)
            mpf('6.5')
            >>> A = [2, 1.5, 3j]
            >>> B = [1+j, 3, -1-j]
            >>> fdot(A, B)
            mpc(real='9.5', imag='-1.0')
            >>> fdot(A, B, conjugate=True)
            mpc(real='3.5', imag='-5.0')

        Nrj   r	  )Úziprr   r‡   r
  r�   rt   rˆ   rP  r&   rj   r	  r#   r^   r4   r&  r—   )r!  ÚAÚBrð   rk   r¹   rî   rï   Zhasattr_r4  r�   rŽ   Za_realZb_realZ	a_complexZ	b_complexZavalÚbreÚbimÚareÚaimZbvalr­   ra   ra   rb   Úfdot|  sZ   '










ÿzPythonMPContext.fdotú<no doc>c                    s8   ‡ ‡‡‡fdd„}ˆj dd… ‰tj ˆd| ¡|_|S )aO  
        Given a low-level mpf_ function, and optionally similar functions
        for mpc_ and mpi_, defines the function as a context method.

        It is assumed that the return type is the same as that of
        the input; the exception is that propagation from mpf to mpc is possible
        by raising ComplexResult.

        c              	      sØ   t | ƒˆ jvrˆ  | ¡} ˆ j\}}|r)| d|¡}d|v r#t|d ƒ}| d|¡}t| dƒrSzˆ  ˆ| j||ƒ¡W S  t	yR   ˆ j
rD‚ ˆ  ˆ| jtf||ƒ¡ Y S w t| dƒrbˆ  ˆ| j||ƒ¡S tdˆt | ƒf ƒ‚)Nrk   rl   rm   rj   r	  z
%s of a %s)rt   r4  rˆ   rr   rs   r   r‡   r—   rj   r   r)  r&  r   r	  r^   )r‹   rz   rk   rm   ©r!  Úmpc_fÚmpf_frö   ra   rb   ÚfÝ  s&   


ü
z/PythonMPContext._wrap_libmp_function.<locals>.frp   NzComputes the %s of x)rd   r[   Ú__dict__rs   rg   )r!  ra  r`  Zmpi_fÚdocrb  ra   r_  rb   Ú_wrap_libmp_functionÓ  s   
z$PythonMPContext._wrap_libmp_functionc                    s8   |r	‡ fdd„}nˆ }t j |ˆ j¡|_t| ||ƒ d S )Nc                    sZ   | j ‰ ‡ fdd„|D ƒ}| j}z|  jd7  _ˆ| g|¢R i |¤Ž}W || _|
 S || _w )Nc                    s   g | ]}ˆ |ƒ‘qS ra   ra   )Ú.0r�   ©rˆ   ra   rb   Ú
<listcomp>û  s    zDPythonMPContext._wrap_specfun.<locals>.f_wrapped.<locals>.<listcomp>rO  )rˆ   rk   )r!  rè   rz   rk   Úretval©rb  rg  rb   Ú	f_wrappedù  s   ÿz0PythonMPContext._wrap_specfun.<locals>.f_wrapped)r[   rc  rs   rg   Úsetattr)r_   rö   rb  Úwraprk  ra   rj  rb   Ú_wrap_specfunö  s
   zPythonMPContext._wrap_specfunc           
      C   s¬  t |dƒr|j\}}|tkr|dfS nt |dƒr|j}nvt|ƒtv r(t|ƒdfS d }t|tƒr4|\}}n#t |dƒr?|j	\}}nt|t
ƒrWd|v rW| d¡\}}t|ƒ}t|ƒ}|d urm|| se|| dfS |  ||¡dfS |  |¡}t |dƒr…|j\}}|tkr„|dfS nt |dƒrŽ|j}n|dfS |\}}}}	|rÎ|d	krÅ|r£| }|d
kr¯t|ƒ|> dfS |d	krÅt|ƒd| > }}|  ||¡dfS |  |¡}|dfS |sÒdS |dfS )Nr	  ÚCrj   ÚZr’   ú/ÚQÚUéüÿÿÿro   r   ÚR)ro   rp  )r‡   r	  r   rj   rt   r   r³   rƒ   rv   r’   r   Úsplitr‘   rˆ   r—   )
r!  r‹   r   rB  r”   r•   r{   r|   r}   r~   ra   ra   rb   Ú_convert_param  s\   

ÿ






ÿ

zPythonMPContext._convert_paramc                 C   sB   |\}}}}|r|| S |t kr| jS |tks|tkr| jS | jS r]   )r   Úninfr   r   ÚinfÚnan)r!  r‹   r{   r|   r}   r~   ra   ra   rb   Ú_mpf_mag9  s   zPythonMPContext._mpf_magc                 C   sð   t |dƒr|  |j¡S t |dƒr4|j\}}|tkr|  |¡S |tkr'|  |¡S dt|  |¡|  |¡ƒ S t|tƒrD|rAtt	|ƒƒS | j
S t|tjƒr`|j\}}|r]dtt	|ƒƒ t|ƒ S | j
S |  |¡}t |dƒsot |dƒrt|  |¡S tdƒ‚)a¯  
        Quick logarithmic magnitude estimate of a number. Returns an
        integer or infinity `m` such that `|x| <= 2^m`. It is not
        guaranteed that `m` is an optimal bound, but it will never
        be too large by more than 2 (and probably not more than 1).

        **Examples**

            >>> from mpmath import *
            >>> mp.pretty = True
            >>> mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2)))
            (4, 4, 4, 4)
            >>> mag(10j), mag(10+10j)
            (4, 5)
            >>> mag(0.01), int(ceil(log(0.01,2)))
            (-6, -6)
            >>> mag(0), mag(inf), mag(-inf), mag(nan)
            (-inf, +inf, +inf, nan)

        rj   r	  r   zrequires an mpf/mpc)r‡   r{  rj   r	  r   r+  rƒ   r   r5   Úabsrx  rZ   r‘   r’   rˆ   Úmagr‰   )r!  r‹   r  r  r”   r•   ra   ra   rb   r}  C  s,   








zPythonMPContext.mag)T)F)FF)NF)NNr^  )rd   re   rf   r"  r—   r&  r*  r.  r/  rí   rk   rl   rˆ   r5  r?  r@  rD  rE  rU  r]  re  rì   rn  rw  r{  r}  ra   ra   ra   rb   r  G  s.    
2 
(
/
<
W#
1
r  ro   N)rò   rò   rò   )}Úlibmp.backendr   r   Úlibmpr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rò   rZ   r[   r  rc   ru   r\   ri   ró   Z
return_mpfZ
return_mpcZmpf_pow_samerù   rÑ   rú   rû   rü   rý   rþ   rÿ   r  r  r  rÖ   r  r   r  r»   r�   r  r6  ÚComplexÚregisterÚRealÚImportErrorra   ra   ra   rb   Ú<module>   sŽ   þf  Fø


ýýýýýýý ^    5ÿ