
    MZd                     p    d 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e             Zy)	z2Implementation of :class:`GMPYIntegerRing` class.     )GMPYIntegerSymPyInteger	factorial
gmpy_gcdexgmpy_gcdgmpy_lcmsqrt)IntegerRing)CoercionFailed)publicc                       e Zd ZdZeZ ed      Z ed      Z ee      Z	dZ
d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)GMPYIntegerRingzInteger ring based on GMPY's ``mpz`` type.

    This will be the implementation of :ref:`ZZ` if ``gmpy`` or ``gmpy2`` is
    installed. Elements will be of type ``gmpy.mpz``.
    r      ZZ_gmpyc                      y)z$Allow instantiation of this domain. N )selfs    E/usr/lib/python3/dist-packages/sympy/polys/domains/gmpyintegerring.py__init__zGMPYIntegerRing.__init__   s        c                 *    t        t        |            S )z!Convert ``a`` to a SymPy object. )r   intr   as     r   to_sympyzGMPYIntegerRing.to_sympy   s    CF##r   c                     |j                   rt        |j                        S |j                  r"t	        |      |k(  rt        t	        |            S t        d|z        )z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %s)
is_Integerr   pis_Floatr   r   r   s     r   
from_sympyzGMPYIntegerRing.from_sympy"   sI    <<qss##ZZCFaKs1v&& !>!BCCr   c                 4    t        |j                               S )z3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. )r   to_intK1r   K0s      r   from_FF_pythonzGMPYIntegerRing.from_FF_python+   s    188:&&r   c                     t        |      S )z,Convert Python's ``int`` to GMPY's ``mpz``. )r   r#   s      r   from_ZZ_pythonzGMPYIntegerRing.from_ZZ_python/   s    1~r   c                 L    |j                   dk(  rt        |j                        S yz1Convert Python's ``Fraction`` to GMPY's ``mpz``. r   Ndenominatorr   	numeratorr#   s      r   from_QQzGMPYIntegerRing.from_QQ3   "    ==Aq{{++ r   c                 L    |j                   dk(  rt        |j                        S yr*   r+   r#   s      r   from_QQ_pythonzGMPYIntegerRing.from_QQ_python8   r/   r   c                 "    |j                         S )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. )r"   r#   s      r   from_FF_gmpyzGMPYIntegerRing.from_FF_gmpy=   s    xxzr   c                     |S )z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. r   r#   s      r   from_ZZ_gmpyzGMPYIntegerRing.from_ZZ_gmpyA   s    r   c                 :    |j                   dk(  r|j                  S y)z(Convert GMPY ``mpq`` to GMPY's ``mpz``. r   N)r,   r-   r#   s      r   from_QQ_gmpyzGMPYIntegerRing.from_QQ_gmpyE   s    ==A;; r   c                 L    |j                  |      \  }}|dk(  rt        |      S y)z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. r   N)to_rationalr   )r$   r   r%   r   qs        r   from_RealFieldzGMPYIntegerRing.from_RealFieldJ   s*    ~~a 16q>! r   c                 :    |j                   dk(  r|j                  S y )Nr   )yxr#   s      r   from_GaussianIntegerRingz(GMPYIntegerRing.from_GaussianIntegerRingQ   s    33!833J r   c                 ,    t        ||      \  }}}|||fS )z)Compute extended GCD of ``a`` and ``b``. )r   )r   r   bhsts         r   gcdexzGMPYIntegerRing.gcdexU   s    Q"1a!Qwr   c                     t        ||      S )z Compute GCD of ``a`` and ``b``. )r   r   r   rA   s      r   gcdzGMPYIntegerRing.gcdZ       1~r   c                     t        ||      S )z Compute LCM of ``a`` and ``b``. )r   rG   s      r   lcmzGMPYIntegerRing.lcm^   rI   r   c                     t        |      S )zCompute square root of ``a``. )	gmpy_sqrtr   s     r   r	   zGMPYIntegerRing.sqrtb   s    |r   c                     t        |      S )zCompute factorial of ``a``. )gmpy_factorialr   s     r   r   zGMPYIntegerRing.factorialf   s    a  r   N)__name__
__module____qualname____doc__r   dtypezeroonetypetpaliasr   r   r    r&   r(   r.   r1   r3   r5   r7   r;   r?   rE   rH   rK   r	   r   r   r   r   r   r      s     E8D
(C	cBE3$D',
,

"
!r   r   N)rS   sympy.polys.domains.groundtypesr   r   r   rO   r   r   r   r	   rM   sympy.polys.domains.integerringr
   sympy.polys.polyerrorsr   sympy.utilitiesr   r   r   r   r   <module>r^      s>    8  
 8 1 "Z!k Z! Z!r   