B
    ˜‘[¤  ã               @   sŒ   d Z ddlmZ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 eG d
d„ de
eeƒƒZdS )z/Implementation of :class:`ComplexField` class. é    )Úprint_functionÚdivision)ÚFloatÚI)Úpublic)ÚField)ÚSimpleDomain)ÚCharacteristicZero)Ú	MPContext)ÚDomainErrorÚCoercionFailedc               @   sê   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-d.„Z dS )0ÚComplexFieldz+Complex numbers up to the given precision. ZCCTFé5   c             C   s   | j | jkS )N)Ú	precisionÚ_default_precision)Úself© r   ú?lib/python3.7/site-packages/sympy/polys/domains/complexfield.pyÚhas_default_precision   s    z"ComplexField.has_default_precisionc             C   s   | j jS )N)Ú_contextÚprec)r   r   r   r   r   "   s    zComplexField.precisionc             C   s   | j jS )N)r   Údps)r   r   r   r   r   &   s    zComplexField.dpsc             C   s   | j jS )N)r   Ú	tolerance)r   r   r   r   r   *   s    zComplexField.toleranceNc             C   s<   t |||ƒ}| |_|| _|j| _|  d¡| _|  d¡| _d S )Nr   é   )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 )N)Ú
isinstancer   r   r   )r   Úotherr   r   r   Ú__eq__7   s    
zComplexField.__eq__c             C   s   t | jj| j| j| jfƒS )N)Ú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)Zevalfr   Zas_real_imagZ	is_Numberr   r   )r   ÚexprZnumberr%   r&   r   r   r   Ú
from_sympyC   s
    zComplexField.from_sympyc             C   s
   |   |¡S )N)r   )r   r'   Úbaser   r   r   Úfrom_ZZ_pythonM   s    zComplexField.from_ZZ_pythonc             C   s   |   |j¡|j S )N)r   Ú	numeratorÚdenominator)r   r'   r,   r   r   r   Úfrom_QQ_pythonP   s    zComplexField.from_QQ_pythonc             C   s   |   t|ƒ¡S )N)r   Úint)r   r'   r,   r   r   r   Úfrom_ZZ_gmpyS   s    zComplexField.from_ZZ_gmpyc             C   s   |   t|jƒ¡t|jƒ S )N)r   r1   r.   r/   )r   r'   r,   r   r   r   Úfrom_QQ_gmpyV   s    zComplexField.from_QQ_gmpyc             C   s
   |   |¡S )N)r   )r   r'   r,   r   r   r   Úfrom_RealFieldY   s    zComplexField.from_RealFieldc             C   s   | |kr|S |   |¡S d S )N)r   )r   r'   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_ringb   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 %sN)r   )r   r   r   r   Ú	get_exactf   s    zComplexField.get_exactc             C   s   | j S )z Returns GCD of ``a`` and ``b``. )r   )r   ÚaÚbr   r   r   Úgcdj   s    zComplexField.gcdc             C   s   || S )z Returns LCM of ``a`` and ``b``. r   )r   r8   r9   r   r   r   Úlcmn   s    zComplexField.lcmc             C   s   | j  |||¡S )z+Check if ``a`` and ``b`` are almost equal. )r   Úalmosteq)r   r8   r9   r   r   r   r   r<   r   s    zComplexField.almosteq)N)!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(   r+   r-   r0   r2   r3   r4   r5   r6   r7   r:   r;   r<   r   r   r   r   r      s8   	
r   N)r?   Z
__future__r   r   Zsympy.core.numbersr   r   Zsympy.utilitiesr   Zsympy.polys.domains.fieldr   Z sympy.polys.domains.simpledomainr   Z&sympy.polys.domains.characteristiczeror	   Zsympy.polys.domains.mpelementsr
   Zsympy.polys.polyerrorsr   r   r   r   r   r   r   Ú<module>   s   