o
    jg                     @   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 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.     )
SYMPY_INTS)FloatI)CharacteristicZero)FieldQQ_I)	MPContext)SimpleDomain)DomainErrorCoercionFailed)publicc                   @   sX  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edd ZdJd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*dKdDdEZ+dFdG Z,dHdI Z-dS )LComplexFieldz+Complex numbers up to the given precision. CCTF5   c                 C   s   | j | jkS N)	precision_default_precisionself r   X/var/www/html/zoom/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   r   r   )r   	tolerancer   r   r   r   r   *   r   zComplexField.toleranceNc                 C   s>   t |||d}| |_|| _|j| _| d| _| d| _d S )NFr      )r	   _parentr   mpc_dtypedtypezeroone)r   r   r   tolcontextr   r   r   __init__.   s   zComplexField.__init__c                 C      | j S r   )r#   r   r   r   r   tp7   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$   ?   s
   

zComplexField.dtypec                 C   s"   t |to| j|jko| j|jkS r   )r,   r   r   r   )r   otherr   r   r   __eq__I   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__N      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_sympyQ   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numberr7   r8   r   r   r   
from_sympyU   s
   zComplexField.from_sympyc                 C   
   |  |S r   r$   r   r:   baser   r   r   from_ZZ_      
zComplexField.from_ZZc                 C   s   |  t|S r   )r$   r-   rE   r   r   r   from_ZZ_gmpyb   s   zComplexField.from_ZZ_gmpyc                 C   rC   r   rD   rE   r   r   r   from_ZZ_pythone   rH   zComplexField.from_ZZ_pythonc                 C      |  t|jt|j S r   r$   r-   	numeratordenominatorrE   r   r   r   from_QQh   r6   zComplexField.from_QQc                 C   s   |  |j|j S r   )r$   rM   rN   rE   r   r   r   from_QQ_pythonk   s   zComplexField.from_QQ_pythonc                 C   rK   r   rL   rE   r   r   r   from_QQ_gmpyn   r6   zComplexField.from_QQ_gmpyc                 C   s   |  t|jt|jS r   )r$   r-   r.   r/   rE   r   r   r   from_GaussianIntegerRingq      z%ComplexField.from_GaussianIntegerRingc                 C   sB   |j }|j}| t|jt|j | dt|jt|j  S )Nr   )r.   r/   r$   r-   rM   rN   )r   r:   rF   r.   r/   r   r   r   from_GaussianRationalFieldt   s
   z'ComplexField.from_GaussianRationalFieldc                 C   s   |  ||| jS r   )rB   r;   r=   r   rE   r   r   r   from_AlgebraicFieldz   rS   z ComplexField.from_AlgebraicFieldc                 C   rC   r   rD   rE   r   r   r   from_RealField}   rH   zComplexField.from_RealFieldc                 C   s   | |kr|S |  |S r   rD   rE   r   r   r   from_ComplexField   s   
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   r9   r   r   r   is_negative   rZ   zComplexField.is_negativec                 C   r[   r\   r   r9   r   r   r   is_positive   rZ   zComplexField.is_positivec                 C   r[   r\   r   r9   r   r   r   is_nonnegative   rZ   zComplexField.is_nonnegativec                 C   r[   r\   r   r9   r   r   r   is_nonpositive   rZ   zComplexField.is_nonpositivec                 C   r*   )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   ra   r   r   r   lcm   r   zComplexField.lcmc                 C   s   | j |||S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rb   rc   r   r   r   r   rf      s   zComplexField.almosteqc                 C   r[   )zAReturns ``True``. Every complex number has a complex square root.Tr   r   rb   r   r   r   	is_square   rZ   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   rg   r   r   r   exsqrt   s   	zComplexField.exsqrt)r   r   ).r4   
__module____qualname____doc__repis_ComplexFieldis_CCis_Exactis_Numericalhas_assoc_Ringhas_assoc_Fieldr   propertyr   r   r   r   r)   r+   r$   r1   r5   r;   rB   rG   rI   rJ   rO   rP   rQ   rR   rT   rU   rV   rW   rX   rY   r]   r^   r_   r`   rd   re   rf   rh   ri   r   r   r   r   r      s^    



	




r   N)rl   sympy.external.gmpyr   sympy.core.numbersr   r   &sympy.polys.domains.characteristiczeror   sympy.polys.domains.fieldr   #sympy.polys.domains.gaussiandomainsr   sympy.polys.domains.mpelementsr	    sympy.polys.domains.simpledomainr
   sympy.polys.polyerrorsr   r   sympy.utilitiesr   r   r   r   r   r   r   <module>   s     
+