o
    GZh                     @   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   O/var/www/auris/lib/python3.10/site-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      | j S r   )
_tolerancer   r   r   r   	tolerance,      zComplexField.toleranceNc                 C   s   t  }|d u r|d u r| j|_n|d u r||_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dtypezeroonemaxZ
_max_denomr    )r   r   r   Ztolcontextr   r   r   __init__0   s   
zComplexField.__init__c                 C   r   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   )r0   r   r   )r   otherr   r   r   __eq__[      zComplexField.__eq__c                 C   s   t | jj| j| jfS r   )hash	__class____name__r(   r   r   r   r   r   __hash__^   r6   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   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   exprnumberr;   r<   r   r   r   
from_sympye   s
   zComplexField.from_sympyc                 C   
   |  |S r   r)   r   r>   baser   r   r   from_ZZo      
zComplexField.from_ZZc                 C   s   |  t|S r   )r)   r1   rG   r   r   r   from_ZZ_gmpyr   s   zComplexField.from_ZZ_gmpyc                 C   rE   r   rF   rG   r   r   r   from_ZZ_pythonu   rJ   zComplexField.from_ZZ_pythonc                 C      |  t|jt|j S r   r)   r1   	numeratordenominatorrG   r   r   r   from_QQx      zComplexField.from_QQc                 C   s   |  |j|j S r   )r)   rO   rP   rG   r   r   r   from_QQ_python{   s   zComplexField.from_QQ_pythonc                 C   rM   r   rN   rG   r   r   r   from_QQ_gmpy~   rR   zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r)   r1   r2   r3   rG   r   r   r   from_GaussianIntegerRing      z%ComplexField.from_GaussianIntegerRingc                 C   sB   |j }|j}| t|jt|j | dt|jt|j  S )Nr   )r2   r3   r)   r1   rO   rP   )r   r>   rH   r2   r3   r   r   r   from_GaussianRationalField   s
   z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )rD   r?   rA   r   rG   r   r   r   from_AlgebraicField   rV   z ComplexField.from_AlgebraicFieldc                 C   rE   r   rF   rG   r   r   r   from_RealField   rJ   zComplexField.from_RealFieldc                 C   rE   r   rF   rG   r   r   r   from_ComplexField   rJ   zComplexField.from_ComplexFieldc                 C   s   t d|  )z)Returns a ring associated with ``self``. z#there is no ring associated with %s)r
   r   r   r   r   get_ring   r   zComplexField.get_ringc                 C   s   t S )z2Returns an exact domain associated with ``self``. r   r   r   r   r   	get_exact      zComplexField.get_exactc                 C      dS z.Returns ``False`` for any ``ComplexElement``. Fr   r=   r   r   r   is_negative   r]   zComplexField.is_negativec                 C   r^   r_   r   r=   r   r   r   is_positive   r]   zComplexField.is_positivec                 C   r^   r_   r   r=   r   r   r   is_nonnegative   r]   zComplexField.is_nonnegativec                 C   r^   r_   r   r=   r   r   r   is_nonpositive   r]   zComplexField.is_nonpositivec                 C   r   )z Returns GCD of ``a`` and ``b``. )r+   r   abr   r   r   gcd   r"   zComplexField.gcdc                 C   s   || S )z Returns LCM of ``a`` and ``b``. r   rd   r   r   r   lcm   r   zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   re   rf   r!   r   r   r   ri      s   zComplexField.almosteqc                 C   r^   )zAReturns ``True``. Every complex number has a complex square root.Tr   r   re   r   r   r   	is_square   r]   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   rj   r   r   r   exsqrt   s   	zComplexField.exsqrt)NNN)r   r   ).r9   
__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)   r5   r:   r?   rD   rI   rK   rL   rQ   rS   rT   rU   rW   rX   rY   rZ   r[   r\   r`   ra   rb   rc   rg   rh   ri   rk   rl   r   r   r   r   r      s^    









r   N)ro   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