a
    <b                     @   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   p/Users/vegardjervell/Documents/master/model/venv/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   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__:   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   Zas_real_imagZ	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denominatorr2   r   r   r   from_QQN   s    zComplexField.from_QQc                 C   s
   |  |S r   r1   r2   r   r   r   from_ZZ_pythonQ   s    zComplexField.from_ZZ_pythonc                 C   s   |  |j|j S r   )r   r7   r8   r2   r   r   r   from_QQ_pythonT   s    zComplexField.from_QQ_pythonc                 C   s   |  t|S r   )r   r6   r2   r   r   r   from_ZZ_gmpyW   s    zComplexField.from_ZZ_gmpyc                 C   s   |  t|jt|j S r   r5   r2   r   r   r   from_QQ_gmpyZ   s    zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r   r6   xyr2   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   )r>   r?   r   r6   r7   r8   )r   r*   r3   r>   r?   r   r   r   from_GaussianRationalField`   s
    z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )r0   r+   r-   r   r2   r   r   r   from_AlgebraicFieldf   s    z ComplexField.from_AlgebraicFieldc                 C   s
   |  |S r   r1   r2   r   r   r   from_RealFieldi   s    zComplexField.from_RealFieldc                 C   s   | |kr|S |  |S d S r   r1   r2   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 %sNrE   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 rH   r   r)   r   r   r   is_positive~   s    zComplexField.is_positivec                 C   s   dS rH   r   r)   r   r   r   is_nonnegative   s    zComplexField.is_nonnegativec                 C   s   dS rH   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   rM   r   r   r   lcm   s    zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rN   rO   r   r   r   r   rR      s    zComplexField.almosteq)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+   r0   r4   r9   r:   r;   r<   r=   r@   rA   rB   rC   rD   rF   rG   rI   rJ   rK   rL   rP   rQ   rR   r   r   r   r   r      sR   



	
r   N)rU   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    