o
    Rh                     @   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   b/home/air/sanwanet/backup_V2/venv/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   mpc_dtypedtypezeroonemax
_max_denomr    )r   r   r   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   )r3   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__^   r9   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   as_real_imag	is_Numberr*   r   )r   exprnumberr>   r?   r   r   r   
from_sympye   s
   zComplexField.from_sympyc                 C   
   |  |S r   r*   r   rA   baser   r   r   from_ZZo      
zComplexField.from_ZZc                 C   s   |  t|S r   )r*   r4   rL   r   r   r   from_ZZ_gmpyr   s   zComplexField.from_ZZ_gmpyc                 C   rJ   r   rK   rL   r   r   r   from_ZZ_pythonu   rO   zComplexField.from_ZZ_pythonc                 C      |  t|jt|j S r   r*   r4   	numeratordenominatorrL   r   r   r   from_QQx      zComplexField.from_QQc                 C   s   |  |j|j S r   )r*   rT   rU   rL   r   r   r   from_QQ_python{   s   zComplexField.from_QQ_pythonc                 C   rR   r   rS   rL   r   r   r   from_QQ_gmpy~   rW   zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r*   r4   r5   r6   rL   r   r   r   from_GaussianIntegerRing      z%ComplexField.from_GaussianIntegerRingc                 C   sB   |j }|j}| t|jt|j | dt|jt|j  S )Nr   )r5   r6   r*   r4   rT   rU   )r   rA   rM   r5   r6   r   r   r   from_GaussianRationalField   s
   z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )rI   rB   rD   r   rL   r   r   r   from_AlgebraicField   r[   z ComplexField.from_AlgebraicFieldc                 C   rJ   r   rK   rL   r   r   r   from_RealField   rO   zComplexField.from_RealFieldc                 C   rJ   r   rK   rL   r   r   r   from_ComplexField   rO   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   rb   zComplexField.is_negativec                 C   rc   rd   r   r@   r   r   r   is_positive   rb   zComplexField.is_positivec                 C   rc   rd   r   r@   r   r   r   is_nonnegative   rb   zComplexField.is_nonnegativec                 C   rc   rd   r   r@   r   r   r   is_nonpositive   rb   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   ri   r   r   r   lcm   r   zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rj   rk   r!   r   r   r   rn      s   zComplexField.almosteqc                 C   rc   )zAReturns ``True``. Every complex number has a complex square root.Tr   r   rj   r   r   r   	is_square   rb   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   ro   r   r   r   exsqrt   s   	zComplexField.exsqrt)NNN)r   r   ).r<   
__module____qualname____doc__repis_ComplexFieldis_CCis_Exactis_Numericalhas_assoc_Ringhas_assoc_Fieldr   propertyr   r   r   r!   r1   r2   r*   r8   r=   rB   rI   rN   rP   rQ   rV   rX   rY   rZ   r\   r]   r^   r_   r`   ra   re   rf   rg   rh   rl   rm   rn   rp   rq   r   r   r   r   r      s^    









r   N)rt   sympy.external.gmpyr   sympy.core.numbersr   r   &sympy.polys.domains.characteristiczeror   sympy.polys.domains.fieldr   #sympy.polys.domains.gaussiandomainsr    sympy.polys.domains.simpledomainr	   sympy.polys.polyerrorsr
   r   sympy.utilitiesr   mpmathr   r   r   r   r   r   r   <module>   s     
6