U
    ZÊ¹jí  ã                   @   s†   d 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 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:`RealField` class. é    )Ú
SYMPY_INTS)ÚFloat)ÚField)ÚSimpleDomain)ÚCharacteristicZero)Ú	MPContext)ÚCoercionFailed)Úpublicc                   @   s4  e Zd ZdZdZd ZZd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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 d-d.„ Z!d?d/d0„Z"d1d2„ Z#d3d4„ Z$d5d6„ Z%d7d8„ Z&d@d9d:„Z'd;d<„ Z(d=d>„ Z)dS )AÚ	RealFieldz(Real numbers up to the given precision. ÚRRTFé5   c                 C   s   | j | jkS ©N)Ú	precisionÚ_default_precision©Úself© r   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/polys/domains/realfield.pyÚhas_default_precision   s    zRealField.has_default_precisionc                 C   s   | j jS r   )Ú_contextÚprecr   r   r   r   r   "   s    zRealField.precisionc                 C   s   | j jS r   )r   Údpsr   r   r   r   r   &   s    zRealField.dpsc                 C   s   | j jS r   )r   Ú	tolerancer   r   r   r   r   *   s    zRealField.toleranceNc                 C   s>   t |||dƒ}| |_|| _|j| _|  d¡| _|  d¡| _d S )NTr   é   )r   Z_parentr   ZmpfÚ_dtypeÚdtypeÚzeroÚone)r   r   r   ZtolÚcontextr   r   r   Ú__init__.   s    zRealField.__init__c                 C   s   | j S r   )r   r   r   r   r   Útp7   s    zRealField.tpc                 C   s   t |tƒrt|ƒ}|  |¡S r   )Ú
isinstancer   Úintr   )r   Úargr   r   r   r   ?   s    
zRealField.dtypec                 C   s"   t |tƒo | j|jko | j|jkS r   )r!   r
   r   r   )r   Úotherr   r   r   Ú__eq__G   s
    

ÿ
þzRealField.__eq__c                 C   s   t | jj| j| j| jfƒS r   )ÚhashÚ	__class__Ú__name__r   r   r   r   r   r   r   Ú__hash__L   s    zRealField.__hash__c                 C   s   t || jƒS )z%Convert ``element`` to SymPy number. )r   r   )r   Úelementr   r   r   Úto_sympyO   s    zRealField.to_sympyc                 C   s.   |j | jd�}|jr|  |¡S td| ƒ‚dS )z%Convert SymPy's number to ``dtype``. )Únzexpected real number, got %sN)Úevalfr   Z	is_Numberr   r   )r   ÚexprÚnumberr   r   r   Ú
from_sympyS   s    
zRealField.from_sympyc                 C   s
   |   |¡S r   ©r   ©r   r*   Úbaser   r   r   Úfrom_ZZ\   s    zRealField.from_ZZc                 C   s
   |   |¡S r   r1   r2   r   r   r   Úfrom_ZZ_python_   s    zRealField.from_ZZ_pythonc                 C   s   |   t|ƒ¡S r   )r   r"   r2   r   r   r   Úfrom_ZZ_gmpyb   s    zRealField.from_ZZ_gmpyc                 C   s   |   |j¡t|jƒ S r   ©r   Ú	numeratorr"   Údenominatorr2   r   r   r   Úfrom_QQi   s    zRealField.from_QQc                 C   s   |   |j¡t|jƒ S r   r7   r2   r   r   r   Úfrom_QQ_pythonl   s    zRealField.from_QQ_pythonc                 C   s   |   t|jƒ¡t|jƒ S r   )r   r"   r8   r9   r2   r   r   r   Úfrom_QQ_gmpyo   s    zRealField.from_QQ_gmpyc                 C   s   |   | |¡ | j¡¡S r   )r0   r+   r-   r   r2   r   r   r   Úfrom_AlgebraicFieldr   s    zRealField.from_AlgebraicFieldc                 C   s   | |kr|S |   |¡S d S r   r1   r2   r   r   r   Úfrom_RealFieldu   s    zRealField.from_RealFieldc                 C   s   |j s|  |j¡S d S r   )Úimagr   Úrealr2   r   r   r   Úfrom_ComplexField{   s    zRealField.from_ComplexFieldc                 C   s   | j  ||¡S )z*Convert a real number to rational number. )r   Úto_rational)r   r*   Úlimitr   r   r   rB      s    zRealField.to_rationalc                 C   s   | S )z)Returns a ring associated with ``self``. r   r   r   r   r   Úget_ringƒ   s    zRealField.get_ringc                 C   s   ddl m} |S )z2Returns an exact domain associated with ``self``. r   )ÚQQ)Zsympy.polys.domainsrE   )r   rE   r   r   r   Ú	get_exact‡   s    zRealField.get_exactc                 C   s   | j S )z Returns GCD of ``a`` and ``b``. )r   ©r   ÚaÚbr   r   r   ÚgcdŒ   s    zRealField.gcdc                 C   s   || S )z Returns LCM of ``a`` and ``b``. r   rG   r   r   r   Úlcm�   s    zRealField.lcmc                 C   s   | j  |||¡S )z+Check if ``a`` and ``b`` are almost equal. )r   Úalmosteq)r   rH   rI   r   r   r   r   rL   ”   s    zRealField.almosteqc                 C   s   |dkS )z8Returns ``True`` if ``a >= 0`` and ``False`` otherwise. r   r   ©r   rH   r   r   r   Ú	is_square˜   s    zRealField.is_squarec                 C   s   |dkr|d S dS )zÒNon-negative square root for ``a >= 0`` and ``None`` otherwise.

        Explanation
        ===========
        The square root may be slightly inaccurate due to floating point
        rounding error.
        r   g      à?Nr   rM   r   r   r   Úexsqrtœ   s    zRealField.exsqrt)T)N)*r(   Ú
__module__Ú__qualname__Ú__doc__ÚrepZis_RealFieldZis_RRZis_ExactZis_NumericalZis_PIDZhas_assoc_RingZhas_assoc_Fieldr   Úpropertyr   r   r   r   r   r    r   r%   r)   r+   r0   r4   r5   r6   r:   r;   r<   r=   r>   rA   rB   rD   rF   rJ   rK   rL   rN   rO   r   r   r   r   r
      sT   



	
	

r
   N)rR   Zsympy.external.gmpyr   Zsympy.core.numbersr   Zsympy.polys.domains.fieldr   Z sympy.polys.domains.simpledomainr   Z&sympy.polys.domains.characteristiczeror   Zsympy.polys.domains.mpelementsr   Zsympy.polys.polyerrorsr   Zsympy.utilitiesr	   r
   r   r   r   r   r   Ú<module>   s    