U
    L?h                     @   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. RRTF5   c                 C   s   | j | jkS N)	precision_default_precisionself r   O/var/www/html/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 )zNon-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    