U
    L?h                     @   sp   d 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 ddlmZ eG dd deZd	S )
z4Implementation of :class:`PythonIntegerRing` class.     )
int_valued)PythonIntegerSymPyIntegersqrt	factorialpython_gcdex
python_gcd
python_lcm)IntegerRing)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#d$ Zd%S )&PythonIntegerRingzInteger ring based on Python's ``int`` type.

    This will be used as :ref:`ZZ` if ``gmpy`` and ``gmpy2`` are not
    installed. Elements are instances of the standard Python ``int`` type.
    r      Z	ZZ_pythonc                 C   s   dS )z$Allow instantiation of this domain. N )selfr   r   W/var/www/html/venv/lib/python3.8/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   s4   |j rt|jS t|r$tt|S td| dS )z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %sN)Z
is_Integerr   pr   intr   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   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	numeratorr   r   r   r   from_QQ2   s    
zPythonIntegerRing.from_QQc                 C   s   |j dkr|jS dS r   r    r   r   r   r   from_QQ_python7   s    
z PythonIntegerRing.from_QQ_pythonc                 C   s   t ||S )z5Convert ``ModularInteger(mpz)`` to Python's ``int``. )r   r   r   r   r   r   from_FF_gmpy<   s    zPythonIntegerRing.from_FF_gmpyc                 C   s   t |S )z,Convert GMPY's ``mpz`` to Python's ``int``. )r   r   r   r   r   from_ZZ_gmpy@   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)denomr   Znumerr   r   r   r   from_QQ_gmpyD   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_RealFieldI   s    z PythonIntegerRing.from_RealFieldc                 C   s
   t ||S )z)Compute extended GCD of ``a`` and ``b``. )r   r   r   br   r   r   gcdexP   s    zPythonIntegerRing.gcdexc                 C   s
   t ||S )z Compute GCD of ``a`` and ``b``. )r   r+   r   r   r   gcdT   s    zPythonIntegerRing.gcdc                 C   s
   t ||S )z Compute LCM of ``a`` and ``b``. )r	   r+   r   r   r   lcmX   s    zPythonIntegerRing.lcmc                 C   s   t |S )zCompute square root of ``a``. )python_sqrtr   r   r   r   r   \   s    zPythonIntegerRing.sqrtc                 C   s   t |S )zCompute factorial of ``a``. )python_factorialr   r   r   r   r   `   s    zPythonIntegerRing.factorialN)__name__
__module____qualname____doc__r   Zdtypezeroonealiasr   r   r   r   r   r#   r$   r%   r&   r(   r*   r-   r.   r/   r   r   r   r   r   r   r      s*   	r   N)r5   Zsympy.core.numbersr   Zsympy.polys.domains.groundtypesr   r   r   r0   r   r1   r   r   r	   Zsympy.polys.domains.integerringr
   Zsympy.polys.polyerrorsr   Zsympy.utilitiesr   r   r   r   r   r   <module>   s   $