o
    8Va                     @   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   B/usr/lib/python3/dist-packages/sympy/polys/domains/complexfield.pyhas_default_precision      z"ComplexField.has_default_precisionc                 C      | j jS r   )_contextprecr   r   r   r   r          zComplexField.precisionc                 C   r   r   )r   dpsr   r   r   r   r   $   r   zComplexField.dpsc                 C   r   r   )r   	tolerancer   r   r   r   r   (   r   zComplexField.toleranceNc                 C   s>   t |||d}| |_|| _|j| _| d| _| d| _d S )NFr      )r   Z_parentr   ZmpcdtypeZzeroone)r   r   r   Z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__:      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   s>   |j | jd}| \}}|jr|jr| ||S td| )z%Convert SymPy's number to ``dtype``. )nzexpected complex number, got %s)evalfr   Zas_real_imagZ	is_Numberr   r	   )r   exprZnumberr*   r+   r   r   r   
from_sympyA   s
   zComplexField.from_sympyc                 C   
   |  |S r   r   r   r-   baser   r   r   from_ZZK      
zComplexField.from_ZZc                 C      |  t|jt|j S r   r   int	numeratordenominatorr5   r   r   r   from_QQN   r)   zComplexField.from_QQc                 C   r3   r   r4   r5   r   r   r   from_ZZ_pythonQ   r8   zComplexField.from_ZZ_pythonc                 C   s   |  |j|j S r   )r   r<   r=   r5   r   r   r   from_QQ_pythonT   s   zComplexField.from_QQ_pythonc                 C   s   |  t|S r   )r   r;   r5   r   r   r   from_ZZ_gmpyW   s   zComplexField.from_ZZ_gmpyc                 C   r9   r   r:   r5   r   r   r   from_QQ_gmpyZ   r)   zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r   r;   xyr5   r   r   r   from_GaussianIntegerRing]      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-   r6   rC   rD   r   r   r   from_GaussianRationalField`   s
   z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )r2   r.   r0   r   r5   r   r   r   from_AlgebraicFieldf   rF   z ComplexField.from_AlgebraicFieldc                 C   r3   r   r4   r5   r   r   r   from_RealFieldi   r8   zComplexField.from_RealFieldc                 C   s   | |kr|S |  |S r   r4   r5   r   r   r   from_ComplexFieldl   s   
zComplexField.from_ComplexFieldc                 C      t d|  )z)Returns a ring associated with ``self``. z#there is no ring associated with %sr   r   r   r   r   get_ringr   r   zComplexField.get_ringc                 C   rK   )z2Returns an exact domain associated with ``self``. z+there is no exact domain associated with %srL   r   r   r   r   	get_exactv   r   zComplexField.get_exactc                 C      dS z.Returns ``False`` for any ``ComplexElement``. Fr   r,   r   r   r   is_negativez      zComplexField.is_negativec                 C   rO   rP   r   r,   r   r   r   is_positive~   rR   zComplexField.is_positivec                 C   rO   rP   r   r,   r   r   r   is_nonnegative   rR   zComplexField.is_nonnegativec                 C   rO   rP   r   r,   r   r   r   is_nonpositive   rR   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   rV   r   r   r   lcm   r   zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rW   rX   r   r   r   r   r[      s   zComplexField.almosteqr   )*r'   
__module____qualname____doc__ZrepZis_ComplexFieldZis_CCZis_ExactZis_NumericalZhas_assoc_RingZhas_assoc_Fieldr   propertyr   r   r   r   r!   r$   r(   r.   r2   r7   r>   r?   r@   rA   rB   rE   rG   rH   rI   rJ   rM   rN   rQ   rS   rT   rU   rY   rZ   r[   r   r   r   r   r      sT    



	
r   N)r^   Zsympy.core.numbersr   r   Z&sympy.polys.domains.characteristiczeror   Zsympy.polys.domains.fieldr   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     
