
    Ed                     ~    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dS )	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dS )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                     dS )z$Allow instantiation of this domain. N )selfs    Clib/python3.11/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FF###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"   sb    < 	Dqs###Z 	DCFFaK 	Ds1vv&&& !>!BCCCr   c                 D    t          |                                          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                 D    |j         dk    rt          |j                  S dS z1Convert Python's ``Fraction`` to GMPY's ``mpz``. r   Ndenominatorr   	numeratorr#   s      r   from_QQzGMPYIntegerRing.from_QQ3   +    =A 	,q{+++	, 	,r   c                 D    |j         dk    rt          |j                  S dS r*   r+   r#   s      r   from_QQ_pythonzGMPYIntegerRing.from_QQ_python8   r/   r   c                 *    |                                 S )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. )r"   r#   s      r   from_FF_gmpyzGMPYIntegerRing.from_FF_gmpy=   s    xxzz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 dS )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                 `    |                     |          \  }}|dk    rt          |          S dS )z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. r   N)to_rationalr   )r$   r   r%   r   qs        r   from_RealFieldzGMPYIntegerRing.from_RealFieldJ   s9    ~~a  16 	"q>>!	" 	"r   c                 *    |j         dk    r|j        S d S )Nr   )yxr#   s      r   from_GaussianIntegerRingz(GMPYIntegerRing.from_GaussianIntegerRingQ   s!    3!8 	3J	 	r   c                 4    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      sS         E588D
%((C	cBE3 3 3$ $ $D D 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                 
 8 7 7 7 7 7 1 1 1 1 1 1 " " " " " "Z! Z! Z! Z! Z!k Z! Z! Z! Z! Z!r   