B
    ˜‘[Z
  ã               @   st   d Z ddlmZmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ eG dd„ deƒƒZd	S )
z3Implementaton of :class:`PythonIntegerRing` class. é    )Úprint_functionÚdivision)ÚIntegerRing)ÚPythonIntegerÚSymPyIntegerÚpython_sqrtÚpython_factorialÚpython_gcdexÚ
python_gcdÚ
python_lcm)ÚCoercionFailed)Úpublicc               @   s    e Zd ZdZeZedƒZedƒZ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"„ Zd#S )$ÚPythonIntegerRingz-Integer ring based on Python's ``int`` type. r   é   Z	ZZ_pythonc             C   s   dS )z$Allow instantiation of this domain. N© )Úselfr   r   úDlib/python3.7/site-packages/sympy/polys/domains/pythonintegerring.pyÚ__init__   s    zPythonIntegerRing.__init__c             C   s   t |ƒS )z!Convert ``a`` to a SymPy object. )r   )r   Úar   r   r   Úto_sympy   s    zPythonIntegerRing.to_sympyc             C   s>   |j rt|jƒS |jr.t|ƒ|kr.tt|ƒƒS td| ƒ‚dS )z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %sN)Z
is_Integerr   ÚpZis_FloatÚintr   )r   r   r   r   r   Ú
from_sympy   s
    
zPythonIntegerRing.from_sympyc             C   s   |  ¡ S )z5Convert ``ModularInteger(int)`` to Python's ``int``. )Úto_int)ÚK1r   ÚK0r   r   r   Úfrom_FF_python'   s    z PythonIntegerRing.from_FF_pythonc             C   s   |S )z.Convert Python's ``int`` to Python's ``int``. r   )r   r   r   r   r   r   Úfrom_ZZ_python+   s    z PythonIntegerRing.from_ZZ_pythonc             C   s   |j dkr|jS dS )z3Convert Python's ``Fraction`` to Python's ``int``. r   N)ÚdenominatorÚ	numerator)r   r   r   r   r   r   Úfrom_QQ_python/   s    
z PythonIntegerRing.from_QQ_pythonc             C   s   t | ¡ ƒS )z5Convert ``ModularInteger(mpz)`` to Python's ``int``. )r   r   )r   r   r   r   r   r   Úfrom_FF_gmpy4   s    zPythonIntegerRing.from_FF_gmpyc             C   s   t |ƒS )z,Convert GMPY's ``mpz`` to Python's ``int``. )r   )r   r   r   r   r   r   Úfrom_ZZ_gmpy8   s    zPythonIntegerRing.from_ZZ_gmpyc             C   s   |  ¡ dkrt| ¡ ƒS dS )z,Convert GMPY's ``mpq`` to Python's ``int``. r   N)Zdenomr   Znumer)r   r   r   r   r   r   Úfrom_QQ_gmpy<   s    zPythonIntegerRing.from_QQ_gmpyc             C   s"   |  |¡\}}|dkrt|ƒS dS )z.Convert mpmath's ``mpf`` to Python's ``int``. r   N)Zto_rationalr   )r   r   r   r   Úqr   r   r   Úfrom_RealFieldA   s    z PythonIntegerRing.from_RealFieldc             C   s
   t ||ƒS )z)Compute extended GCD of ``a`` and ``b``. )r	   )r   r   Úbr   r   r   ÚgcdexH   s    zPythonIntegerRing.gcdexc             C   s
   t ||ƒS )z Compute GCD of ``a`` and ``b``. )r
   )r   r   r&   r   r   r   ÚgcdL   s    zPythonIntegerRing.gcdc             C   s
   t ||ƒS )z Compute LCM of ``a`` and ``b``. )r   )r   r   r&   r   r   r   ÚlcmP   s    zPythonIntegerRing.lcmc             C   s   t |ƒS )zCompute square root of ``a``. )r   )r   r   r   r   r   ÚsqrtT   s    zPythonIntegerRing.sqrtc             C   s   t |ƒS )zCompute factorial of ``a``. )r   )r   r   r   r   r   Ú	factorialX   s    zPythonIntegerRing.factorialN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZdtypeZzeroZoneÚaliasr   r   r   r   r   r    r!   r"   r#   r%   r'   r(   r)   r*   r+   r   r   r   r   r      s(   	r   N)r/   Z
__future__r   r   Zsympy.polys.domains.integerringr   Zsympy.polys.domains.groundtypesr   r   r   r   r	   r
   r   Zsympy.polys.polyerrorsr   Zsympy.utilitiesr   r   r   r   r   r   Ú<module>   s   $