a
    RG5d                     @   s   d 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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.     )FloatI)CharacteristicZero)Field)	MPContext)SimpleDomain)DomainErrorCoercionFailed)publicc                   @   s2  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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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(dAd?d@Z)dS )BComplexFieldz+Complex numbers up to the given precision. CCTF5   c                 C   s   | j | jkS N)	precision_default_precisionself r   \/var/www/html/django/DPS/env/lib/python3.9/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   _parentr   mpcdtypezeroone)r   r   r   tolcontextr   r   r   __init__,   s    zComplexField.__init__c                 C   s"   t |to | j|jko | j|jkS r   )
isinstancer   r   r   )r   otherr   r   r   __eq__5   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__:   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_sympy=   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   as_real_imag	is_Numberr   r	   )r   exprnumberr*   r+   r   r   r   
from_sympyA   s
    zComplexField.from_sympyc                 C   s
   |  |S r   r   r   r-   baser   r   r   from_ZZK   s    zComplexField.from_ZZc                 C   s   |  t|jt|j S r   r   int	numeratordenominatorr7   r   r   r   from_QQN   s    zComplexField.from_QQc                 C   s
   |  |S r   r6   r7   r   r   r   from_ZZ_pythonQ   s    zComplexField.from_ZZ_pythonc                 C   s   |  |j|j S r   )r   r<   r=   r7   r   r   r   from_QQ_pythonT   s    zComplexField.from_QQ_pythonc                 C   s   |  t|S r   )r   r;   r7   r   r   r   from_ZZ_gmpyW   s    zComplexField.from_ZZ_gmpyc                 C   s   |  t|jt|j S r   r:   r7   r   r   r   from_QQ_gmpyZ   s    zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r   r;   xyr7   r   r   r   from_GaussianIntegerRing]   s    z%ComplexField.from_GaussianIntegerRingc                 C   sB   |j }|j}| t|jt|j | dt|jt|j  S )Nr   )rC   rD   r   r;   r<   r=   )r   r-   r8   rC   rD   r   r   r   from_GaussianRationalField`   s
    z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )r5   r.   r0   r   r7   r   r   r   from_AlgebraicFieldf   s    z ComplexField.from_AlgebraicFieldc                 C   s
   |  |S r   r6   r7   r   r   r   from_RealFieldi   s    zComplexField.from_RealFieldc                 C   s   | |kr|S |  |S d S r   r6   r7   r   r   r   from_ComplexFieldl   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_ringr   s    zComplexField.get_ringc                 C   s   t d|  dS )z2Returns an exact domain associated with ``self``. z+there is no exact domain associated with %sNrJ   r   r   r   r   	get_exactv   s    zComplexField.get_exactc                 C   s   dS z.Returns ``False`` for any ``ComplexElement``. Fr   r,   r   r   r   is_negativez   s    zComplexField.is_negativec                 C   s   dS rM   r   r,   r   r   r   is_positive~   s    zComplexField.is_positivec                 C   s   dS rM   r   r,   r   r   r   is_nonnegative   s    zComplexField.is_nonnegativec                 C   s   dS rM   r   r,   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   rR   r   r   r   lcm   s    zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rS   rT   r   r   r   r   rW      s    zComplexField.almosteq)N)*r(   
__module____qualname____doc__repis_ComplexFieldis_CCis_Exactis_Numericalhas_assoc_Ringhas_assoc_Fieldr   propertyr   r   r   r   r"   r%   r)   r.   r5   r9   r>   r?   r@   rA   rB   rE   rF   rG   rH   rI   rK   rL   rN   rO   rP   rQ   rU   rV   rW   r   r   r   r   r      sR   



	
r   N)rZ   sympy.core.numbersr   r   &sympy.polys.domains.characteristiczeror   sympy.polys.domains.fieldr   sympy.polys.domains.mpelementsr    sympy.polys.domains.simpledomainr   sympy.polys.polyerrorsr   r	   sympy.utilitiesr
   r   r   r   r   r   r   <module>   s    