o
     ôj  ã                   @   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. ÚCCTFé5   c                 C   s   | j | jkS ©N)Ú	precisionÚ_default_precision©Úself© r   ús/var/www/html/academy/tools/voices/clone/cosy-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   Z#sympy.polys.domains.gaussiandomainsr   Ú sympy.polys.domains.simpledomainr	   Úsympy.polys.polyerrorsr
   r   Úsympy.utilitiesr   Úmpmathr   r   r   r   r   r   r   Ú<module>   s     
6