
    sg                         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e	ee             Z e       Zy)z/Implementation of :class:`ComplexField` class.     )
SYMPY_INTS)FloatI)CharacteristicZero)FieldQQ_I)	MPContext)SimpleDomain)DomainErrorCoercionFailed)publicc                   4   e Zd ZdZdZdxZZdZdZdZ	dZ
dZed        Zed        Zed        Zed	        Zed
d
fdZed        Zd(dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d)d%Z+d& Z,d' Z-y
)*ComplexFieldz+Complex numbers up to the given precision. CCTF5   c                 4    | j                   | j                  k(  S N)	precision_default_precisionselfs    S/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/complexfield.pyhas_default_precisionz"ComplexField.has_default_precision   s    ~~!8!888    c                 .    | j                   j                  S r   )_contextprecr   s    r   r   zComplexField.precision"   s    }}!!!r   c                 .    | j                   j                  S r   )r   dpsr   s    r   r    zComplexField.dps&   s    }}   r   c                 .    | j                   j                  S r   )r   	tolerancer   s    r   r"   zComplexField.tolerance*   s    }}&&&r   Nc                     t        |||d      }| |_        || _        |j                  | _        | j                  d      | _        | j                  d      | _        y )NFr      )r
   _parentr   mpc_dtypedtypezeroone)r   r   r    tolcontexts        r   __init__zComplexField.__init__.   sI    D#sE2kkJJqM	::a=r   c                     | j                   S r   )r'   r   s    r   tpzComplexField.tp7   s     {{r   c                     t        |t              rt        |      }t        |t              rt        |      }| j                  ||      S r   )
isinstancer   intr'   )r   xys      r   r(   zComplexField.dtype?   s;     a$AAa$AA{{1a  r   c                     t        |t              xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r   )r1   r   r   r"   )r   others     r   __eq__zComplexField.__eq__I   s;    5,/ 1~~01~~0	2r   c                     t        | j                  j                  | j                  | j                  | j
                  f      S r   )hash	__class____name__r'   r   r"   r   s    r   __hash__zComplexField.__hash__N   s,    T^^,,dkk4>>4>>Z[[r   c                     t        |j                  | j                        t        t        |j                  | j                        z  z   S )z%Convert ``element`` to SymPy number. )r   realr    r   imagr   elements     r   to_sympyzComplexField.to_sympyQ   s0    W\\488,qw||TXX1N/NNNr   c                     |j                  | j                        }|j                         \  }}|j                  r|j                  r| j	                  ||      S t        d|z        )z%Convert SymPy's number to ``dtype``. )nzexpected complex number, got %s)evalfr    as_real_imag	is_Numberr(   r   )r   exprnumberr>   r?   s        r   
from_sympyzComplexField.from_sympyU   sW    dhh'((*
d>>dnn::dD)) !BT!IJJr   c                 $    | j                  |      S r   r(   r   rA   bases      r   from_ZZzComplexField.from_ZZ_       zz'""r   c                 6    | j                  t        |            S r   )r(   r2   rM   s      r   from_ZZ_gmpyzComplexField.from_ZZ_gmpyb   s    zz#g,''r   c                 $    | j                  |      S r   rL   rM   s      r   from_ZZ_pythonzComplexField.from_ZZ_pythone   rP   r   c                 v    | j                  t        |j                              t        |j                        z  S r   r(   r2   	numeratordenominatorrM   s      r   from_QQzComplexField.from_QQh   ,    zz#g//01C8K8K4LLLr   c                 R    | j                  |j                        |j                  z  S r   )r(   rW   rX   rM   s      r   from_QQ_pythonzComplexField.from_QQ_pythonk   s"    zz'++,w/B/BBBr   c                 v    | j                  t        |j                              t        |j                        z  S r   rV   rM   s      r   from_QQ_gmpyzComplexField.from_QQ_gmpyn   rZ   r   c                 r    | j                  t        |j                        t        |j                              S r   )r(   r2   r3   r4   rM   s      r   from_GaussianIntegerRingz%ComplexField.from_GaussianIntegerRingq   s#    zz#gii.#gii.99r   c                    |j                   }|j                  }| j                  t        |j                              t        |j
                        z  | j                  dt        |j                              t        |j
                        z  z   S )Nr   )r3   r4   r(   r2   rW   rX   )r   rA   rN   r3   r4   s        r   from_GaussianRationalFieldz'ComplexField.from_GaussianRationalFieldt   sh    IIII

3q{{+,s1==/AA

1c!++./#amm2DDE 	Fr   c                 t    | j                  |j                  |      j                  | j                              S r   )rJ   rB   rE   r    rM   s      r   from_AlgebraicFieldz ComplexField.from_AlgebraicFieldz   s)    t}}W5;;DHHEFFr   c                 $    | j                  |      S r   rL   rM   s      r   from_RealFieldzComplexField.from_RealField}   rP   r   c                 2    | |k(  r|S | j                  |      S r   rL   rM   s      r   from_ComplexFieldzComplexField.from_ComplexField   s    4<N::g&&r   c                     t        d| z        )z)Returns a ring associated with ``self``. z#there is no ring associated with %s)r   r   s    r   get_ringzComplexField.get_ring   s    ?$FGGr   c                     t         S )z2Returns an exact domain associated with ``self``. r   r   s    r   	get_exactzComplexField.get_exact   s    r   c                      yz.Returns ``False`` for any ``ComplexElement``. F r@   s     r   is_negativezComplexField.is_negative       r   c                      yrn   ro   r@   s     r   is_positivezComplexField.is_positive   rq   r   c                      yrn   ro   r@   s     r   is_nonnegativezComplexField.is_nonnegative   rq   r   c                      yrn   ro   r@   s     r   is_nonpositivezComplexField.is_nonpositive   rq   r   c                     | j                   S )z Returns GCD of ``a`` and ``b``. )r*   r   abs      r   gcdzComplexField.gcd   s    xxr   c                     ||z  S )z Returns LCM of ``a`` and ``b``. ro   ry   s      r   lcmzComplexField.lcm   s    s
r   c                 <    | j                   j                  |||      S )z+Check if ``a`` and ``b`` are almost equal. )r   almosteq)r   rz   r{   r"   s       r   r   zComplexField.almosteq   s    }}%%aI66r   c                      y)zAReturns ``True``. Every complex number has a complex square root.Tro   r   rz   s     r   	is_squarezComplexField.is_square   s    r   c                     |dz  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      ?ro   r   s     r   exsqrtzComplexField.exsqrt   s     Cxr   )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"   r-   r/   r(   r7   r<   rB   rJ   rO   rR   rT   rY   r\   r^   r`   rb   rd   rf   rh   rj   rl   rp   rs   ru   rw   r|   r~   r   r   r   ro   r   r   r   r      s.   5
C""OeHLNO9 9 " " ! ! ' ' /Dd !  !2
\OK#(#MCM:FG#'H7	r   r   N)r   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   ro   r   r   <module>r      sP    5 + ' E + 4 4 9 > "h5,l h hT ^r   