U
    L?h                     @   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. CCTF5   c                 C   s   | j | jkS N)	precision_default_precisionself r   R/var/www/html/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    +