
    sg                     |    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 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)
int_valued)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    V/var/www/html/venv/lib/python3.12/site-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 t        |      rt        t	        |            S t        d|z        )z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %s)
is_Integerr   pr
   r   r   r   s     r   
from_sympyzGMPYIntegerRing.from_sympy#   s?    <<qss##]s1v&& !>!BCCr   c                 $    |j                  |      S )z3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. to_intK1r   K0s      r   from_FF_pythonzGMPYIntegerRing.from_FF_python,       yy|r   c                     t        |      S )z,Convert Python's ``int`` to GMPY's ``mpz``. )r   r$   s      r   from_ZZ_pythonzGMPYIntegerRing.from_ZZ_python0   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_QQ4   "    ==Aq{{++ r   c                 L    |j                   dk(  rt        |j                        S yr,   r-   r$   s      r   from_QQ_pythonzGMPYIntegerRing.from_QQ_python9   r1   r   c                 $    |j                  |      S )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. r"   r$   s      r   from_FF_gmpyzGMPYIntegerRing.from_FF_gmpy>   r(   r   c                     |S )z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. r   r$   s      r   from_ZZ_gmpyzGMPYIntegerRing.from_ZZ_gmpyB   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_gmpyF   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_RealFieldK   s*    ~~a 16q>! r   c                 :    |j                   dk(  r|j                  S y )Nr   )yxr$   s      r   from_GaussianIntegerRingz(GMPYIntegerRing.from_GaussianIntegerRingR   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.gcdexV   s    Q"1a!Qwr   c                     t        ||      S )z Compute GCD of ``a`` and ``b``. )r   r   r   rC   s      r   gcdzGMPYIntegerRing.gcd[       1~r   c                     t        ||      S )z Compute LCM of ``a`` and ``b``. )r   rI   s      r   lcmzGMPYIntegerRing.lcm_   rK   r   c                     t        |      S )zCompute square root of ``a``. )	gmpy_sqrtr   s     r   r	   zGMPYIntegerRing.sqrtc   s    |r   c                     t        |      S )zCompute factorial of ``a``. )gmpy_factorialr   s     r   r   zGMPYIntegerRing.factorialg   s    a  r   N)__name__
__module____qualname____doc__r   dtypezeroonetypetpaliasr   r   r    r'   r*   r0   r3   r5   r7   r9   r=   rA   rG   rJ   rM   r	   r   r   r   r   r   r      s     E8D
(C	cBE3$D,
,

"
!r   r   N)rU   sympy.polys.domains.groundtypesr   r   r   rQ   r   r   r   r	   rO   sympy.core.numbersr
   sympy.polys.domains.integerringr   sympy.polys.polyerrorsr   sympy.utilitiesr   r   r   r   r   <module>ra      sA    8  
 * 7 1 "Z!k Z! Z!r   