U
    ZÊ¹jÒ  ã                   @   sš   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ eG dd„ de	eeƒƒZeƒ ZdS )z/Implementation of :class:`ComplexField` class. é    )Ú
SYMPY_INTS)ÚFloatÚI)ÚCharacteristicZero)ÚField©ÚQQ_I)Ú	MPContext)ÚSimpleDomain)ÚDomainErrorÚCoercionFailed)Úpublicc                   @   sX  e Zd ZdZdZd ZZdZdZdZ	dZ
dZedd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZeddfdd„Zedd„ ƒZdJd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d,d-„ Zd.d/„ Z d0d1„ Z!d2d3„ Z"d4d5„ Z#d6d7„ Z$d8d9„ Z%d:d;„ Z&d<d=„ Z'd>d?„ Z(d@dA„ Z)dBdC„ Z*dKdDdE„Z+dFdG„ Z,dHdI„ Z-dS )LÚComplexFieldz+Complex numbers up to the given precision. ÚCCTFé5   c                 C   s   | j | jkS ©N)Ú	precisionÚ_default_precision©Úself© r   ú_/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/polys/domains/complexfield.pyÚhas_default_precision   s    z"ComplexField.has_default_precisionc                 C   s   | j jS r   )Ú_contextÚprecr   r   r   r   r   "   s    zComplexField.precisionc                 C   s   | j jS r   )r   Údpsr   r   r   r   r   &   s    zComplexField.dpsc                 C   s   | j jS r   )r   Ú	tolerancer   r   r   r   r   *   s    zComplexField.toleranceNc                 C   s>   t |||dƒ}| |_|| _|j| _|  d¡| _|  d¡| _d S )NFr   é   )r	   Z_parentr   ZmpcÚ_dtypeÚdtypeÚzeroÚone)r   r   r   ZtolÚcontextr   r   r   Ú__init__.   s    zComplexField.__init__c                 C   s   | j S r   )r   r   r   r   r   Útp7   s    zComplexField.tpr   c                 C   s0   t |tƒrt|ƒ}t |tƒr$t|ƒ}|  ||¡S r   )Ú
isinstancer   Úintr   )r   ÚxÚyr   r   r   r   ?   s
    

zComplexField.dtypec                 C   s"   t |tƒo | j|jko | j|jkS r   )r%   r   r   r   )r   Úotherr   r   r   Ú__eq__I   s
    

ÿ
þzComplexField.__eq__c                 C   s   t | jj| j| j| jfƒS r   )ÚhashÚ	__class__Ú__name__r   r   r   r   r   r   r   Ú__hash__N   s    zComplexField.__hash__c                 C   s    t |j| jƒtt |j| jƒ  S )z%Convert ``element`` to SymPy number. )r   Úrealr   r   Úimag©r   Úelementr   r   r   Úto_sympyQ   s    zComplexField.to_sympyc                 C   sB   |j | jd�}| ¡ \}}|jr2|jr2|  ||¡S td| ƒ‚dS )z%Convert SymPy's number to ``dtype``. )Únzexpected complex number, got %sN)Úevalfr   Zas_real_imagZ	is_Numberr   r   )r   ÚexprÚnumberr/   r0   r   r   r   Ú
from_sympyU   s
    zComplexField.from_sympyc                 C   s
   |   |¡S r   ©r   ©r   r2   Úbaser   r   r   Úfrom_ZZ_   s    zComplexField.from_ZZc                 C   s   |   t|ƒ¡S r   )r   r&   r:   r   r   r   Úfrom_ZZ_gmpyb   s    zComplexField.from_ZZ_gmpyc                 C   s
   |   |¡S r   r9   r:   r   r   r   Úfrom_ZZ_pythone   s    zComplexField.from_ZZ_pythonc                 C   s   |   t|jƒ¡t|jƒ S r   ©r   r&   Ú	numeratorÚdenominatorr:   r   r   r   Úfrom_QQh   s    zComplexField.from_QQc                 C   s   |   |j¡|j S r   )r   r@   rA   r:   r   r   r   Úfrom_QQ_pythonk   s    zComplexField.from_QQ_pythonc                 C   s   |   t|jƒ¡t|jƒ S r   r?   r:   r   r   r   Úfrom_QQ_gmpyn   s    zComplexField.from_QQ_gmpyc                 C   s   |   t|jƒt|jƒ¡S r   )r   r&   r'   r(   r:   r   r   r   Úfrom_GaussianIntegerRingq   s    z%ComplexField.from_GaussianIntegerRingc                 C   sB   |j }|j}|  t|jƒ¡t|jƒ |  dt|jƒ¡t|jƒ  S )Nr   )r'   r(   r   r&   r@   rA   )r   r2   r;   r'   r(   r   r   r   Úfrom_GaussianRationalFieldt   s
    ÿz'ComplexField.from_GaussianRationalFieldc                 C   s   |   | |¡ | j¡¡S r   )r8   r3   r5   r   r:   r   r   r   Úfrom_AlgebraicFieldz   s    z ComplexField.from_AlgebraicFieldc                 C   s
   |   |¡S r   r9   r:   r   r   r   Úfrom_RealField}   s    zComplexField.from_RealFieldc                 C   s   | |kr|S |   |¡S d S r   r9   r:   r   r   r   Úfrom_ComplexField€   s    zComplexField.from_ComplexFieldc                 C   s   t d|  ƒ‚dS )z)Returns a ring associated with ``self``. z#there is no ring associated with %sN)r   r   r   r   r   Úget_ring†   s    zComplexField.get_ringc                 C   s   t S )z2Returns an exact domain associated with ``self``. r   r   r   r   r   Ú	get_exactŠ   s    zComplexField.get_exactc                 C   s   dS ©z.Returns ``False`` for any ``ComplexElement``. Fr   r1   r   r   r   Úis_negativeŽ   s    zComplexField.is_negativec                 C   s   dS rL   r   r1   r   r   r   Úis_positive’   s    zComplexField.is_positivec                 C   s   dS rL   r   r1   r   r   r   Úis_nonnegative–   s    zComplexField.is_nonnegativec                 C   s   dS rL   r   r1   r   r   r   Úis_nonpositiveš   s    zComplexField.is_nonpositivec                 C   s   | j S )z Returns GCD of ``a`` and ``b``. )r!   ©r   ÚaÚbr   r   r   Úgcdž   s    zComplexField.gcdc                 C   s   || S )z Returns LCM of ``a`` and ``b``. r   rQ   r   r   r   Úlcm¢   s    zComplexField.lcmc                 C   s   | j  |||¡S )z+Check if ``a`` and ``b`` are almost equal. )r   Úalmosteq)r   rR   rS   r   r   r   r   rV   ¦   s    zComplexField.almosteqc                 C   s   dS )zAReturns ``True``. Every complex number has a complex square root.Tr   ©r   rR   r   r   r   Ú	is_squareª   s    zComplexField.is_squarec                 C   s   |d S )a,  Returns the principal complex square root of ``a``.

        Explanation
        ===========
        The argument of the principal square root is always within
        $(-\frac{\pi}{2}, \frac{\pi}{2}]$. The square root may be
        slightly inaccurate due to floating point rounding error.
        g      à?r   rW   r   r   r   Úexsqrt®   s    	zComplexField.exsqrt)r   )N).r-   Ú
__module__Ú__qualname__Ú__doc__ÚrepZis_ComplexFieldZis_CCZis_ExactZis_NumericalZhas_assoc_RingZhas_assoc_Fieldr   Úpropertyr   r   r   r   r#   r$   r   r*   r.   r3   r8   r<   r=   r>   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rM   rN   rO   rP   rT   rU   rV   rX   rY   r   r   r   r   r      s\   



	




r   N)r\   Zsympy.external.gmpyr   Zsympy.core.numbersr   r   Z&sympy.polys.domains.characteristiczeror   Zsympy.polys.domains.fieldr   Z#sympy.polys.domains.gaussiandomainsr   Zsympy.polys.domains.mpelementsr	   Z sympy.polys.domains.simpledomainr
   Zsympy.polys.polyerrorsr   r   Zsympy.utilitiesr   r   r   r   r   r   r   Ú<module>   s    +