a
    kh                     @   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mZ dd	l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)SimpleDomain)DomainErrorCoercionFailed)public)	MPContextc                   @   sR  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dJddZedd ZdKd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*dLdDdEZ+dFdG Z,dHdI Z-dS )MComplexFieldz+Complex numbers up to the given precision. CCTF5   c                 C   s   | j | jkS N)	precision_default_precisionself r   N/var/www/auris/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 S r   )
_tolerancer   r   r   r   	tolerance,   s    zComplexField.toleranceNc                 C   s   t  }|d u r |d u r | j|_n(|d u r0||_n|d u r@||_ntd|| _|j| _| d| _	| d| _
td|j d d| _| j
| j | _d S )NzCannot set both prec and dpsr            c   )r   r   r   r   	TypeErrorr   Zmpc_dtypedtypeZzeroonemaxZ
_max_denomr   )r   r   r   Ztolcontextr   r   r   __init__0   s    
zComplexField.__init__c                 C   s   | j S r   )r#   r   r   r   r   tpI   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$   Q   s
    

zComplexField.dtypec                 C   s   t |to| j|jkS r   )r*   r   r   )r   otherr   r   r   __eq__[   s    zComplexField.__eq__c                 C   s   t | jj| j| jfS r   )hash	__class____name__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_sympya   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numberr4   r5   r   r   r   
from_sympye   s
    zComplexField.from_sympyc                 C   s
   |  |S r   r$   r   r7   baser   r   r   from_ZZo   s    zComplexField.from_ZZc                 C   s   |  t|S r   )r$   r+   r?   r   r   r   from_ZZ_gmpyr   s    zComplexField.from_ZZ_gmpyc                 C   s
   |  |S r   r>   r?   r   r   r   from_ZZ_pythonu   s    zComplexField.from_ZZ_pythonc                 C   s   |  t|jt|j S r   r$   r+   	numeratordenominatorr?   r   r   r   from_QQx   s    zComplexField.from_QQc                 C   s   |  |j|j S r   )r$   rE   rF   r?   r   r   r   from_QQ_python{   s    zComplexField.from_QQ_pythonc                 C   s   |  t|jt|j S r   rD   r?   r   r   r   from_QQ_gmpy~   s    zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r$   r+   r,   r-   r?   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$   r+   rE   rF   )r   r7   r@   r,   r-   r   r   r   from_GaussianRationalField   s
    z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )r=   r8   r:   r   r?   r   r   r   from_AlgebraicField   s    z ComplexField.from_AlgebraicFieldc                 C   s
   |  |S r   r>   r?   r   r   r   from_RealField   s    zComplexField.from_RealFieldc                 C   s
   |  |S 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_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   r6   r   r   r   is_negative   s    zComplexField.is_negativec                 C   s   dS rQ   r   r6   r   r   r   is_positive   s    zComplexField.is_positivec                 C   s   dS rQ   r   r6   r   r   r   is_nonnegative   s    zComplexField.is_nonnegativec                 C   s   dS rQ   r   r6   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   rV   r   r   r   lcm   s    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.almosteqc                 C   s   dS )zAReturns ``True``. Every complex number has a complex square root.Tr   r   rW   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   r\   r   r   r   exsqrt   s    	zComplexField.exsqrt)NNN)r   )N).r2   
__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/   r3   r8   r=   rA   rB   rC   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rR   rS   rT   rU   rY   rZ   r[   r]   r^   r   r   r   r   r      s\   









r   N)ra   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.simpledomainr	   Zsympy.polys.polyerrorsr
   r   Zsympy.utilitiesr   Zmpmathr   r   r   r   r   r   r   <module>   s    6