
    g                         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dS )z/Implementation of :class:`ComplexField` class.     )
SYMPY_INTS)FloatI)CharacteristicZero)FieldQQ_I)	MPContext)SimpleDomain)DomainErrorCoercionFailed)publicc                   T   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-d
S )+ComplexFieldz+Complex numbers up to the given precision. CCTF5   c                 "    | j         | j        k    S N)	precision_default_precisionselfs    \/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/domains/complexfield.pyhas_default_precisionz"ComplexField.has_default_precision   s    ~!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        | _        |                     d          | _        |                     d          | _        d S )NFr      )r
   _parentr   mpc_dtypedtypezeroone)r   r   r    tolcontexts        r   __init__zComplexField.__init__.   sR    D#sE22kJJqMM	::a==r   c                     | j         S r   )r'   r   s    r   tpzComplexField.tp7   s     {r   r   c                     t          |t                    rt          |          }t          |t                    rt          |          }|                     ||          S r   )
isinstancer   intr'   )r   xys      r   r(   zComplexField.dtype?   sR     a$$ 	AAa$$ 	AA{{1a   r   c                 l    t          |t                    o| j        |j        k    o| j        |j        k    S r   )r1   r   r   r"   )r   others     r   __eq__zComplexField.__eq__I   s6    5,// 1~01~0	2r   c                 Z    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^,dk4>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   s.    W\48,,qw|TX1N1N/NNNr   c                     |                     | j                  }|                                \  }}|j        r|j        r|                     ||          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   si    dh''((**
d> 	Kdn 	K::dD))) !BT!IJJJr   c                 ,    |                      |          S r   r(   r   rA   bases      r   from_ZZzComplexField.from_ZZ_       zz'"""r   c                 F    |                      t          |                    S r   )r(   r2   rM   s      r   from_ZZ_gmpyzComplexField.from_ZZ_gmpyb   s    zz#g,,'''r   c                 ,    |                      |          S r   rL   rM   s      r   from_ZZ_pythonzComplexField.from_ZZ_pythone   rP   r   c                 z    |                      t          |j                            t          |j                  z  S r   r(   r2   	numeratordenominatorrM   s      r   from_QQzComplexField.from_QQh   /    zz#g/0011C8K4L4LLLr   c                 F    |                      |j                  |j        z  S r   )r(   rW   rX   rM   s      r   from_QQ_pythonzComplexField.from_QQ_pythonk   s    zz'+,,w/BBBr   c                 z    |                      t          |j                            t          |j                  z  S r   rV   rM   s      r   from_QQ_gmpyzComplexField.from_QQ_gmpyn   rZ   r   c                 v    |                      t          |j                  t          |j                            S r   )r(   r2   r3   r4   rM   s      r   from_GaussianIntegerRingz%ComplexField.from_GaussianIntegerRingq   s&    zz#gi..#gi..999r   c                    |j         }|j        }|                     t          |j                            t          |j                  z  |                     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   sn    II

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

1c!+..//#am2D2DDE 	Fr   c                     |                      |                    |                              | j                            S r   )rJ   rB   rE   r    rM   s      r   from_AlgebraicFieldz ComplexField.from_AlgebraicFieldz   s0    t}}W55;;DHEEFFFr   c                 ,    |                      |          S r   rL   rM   s      r   from_RealFieldzComplexField.from_RealField}   rP   r   c                 <    | |k    r|S |                      |          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GGr   c                     t           S )z2Returns an exact domain associated with ``self``. r   r   s    r   	get_exactzComplexField.get_exact   s    r   c                     dS z.Returns ``False`` for any ``ComplexElement``. F r@   s     r   is_negativezComplexField.is_negative       ur   c                     dS rn   ro   r@   s     r   is_positivezComplexField.is_positive   rq   r   c                     dS rn   ro   r@   s     r   is_nonnegativezComplexField.is_nonnegative   rq   r   c                     dS 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	    xr   c                     ||z  S )z Returns LCM of ``a`` and ``b``. ro   ry   s      r   lcmzComplexField.lcm   s    s
r   c                 :    | 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66r   c                     dS )zAReturns ``True``. Every complex number has a complex square root.Tro   r   rz   s     r   	is_squarezComplexField.is_square   s    tr   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5
C""OeHLNO9 9 X9 " " X" ! ! X! ' ' X' /Dd ! ! ! !   X! ! ! !2 2 2
\ \ \O O OK K K# # #( ( (# # #M M MC C CM M M: : :F F FG G G# # #' ' 'H H H              7 7 7 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      s   5 5 + * * * * * ' ' ' ' ' ' ' ' E E E E E E + + + + + + 4 4 4 4 4 4 4 4 4 4 4 4 9 9 9 9 9 9 > > > > > > > > " " " " " "h h h h h5,l h h hT \^^r   