o
    jgÝ  ã                   @   sp   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„ deƒƒZd	S )
z2Implementation of :class:`GMPYIntegerRing` class. é    )ÚGMPYIntegerÚSymPyIntegerÚ	factorialÚ
gmpy_gcdexÚgmpy_gcdÚgmpy_lcmÚsqrt)Ú
int_valued)ÚIntegerRing)ÚCoercionFailed)Úpublicc                   @   s¸   e Zd ZdZeZedƒZedƒZeeƒ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%d&„ Zd'S )(ÚGMPYIntegerRingz³Integer 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                 C   s   dS )z$Allow instantiation of this domain. N© )Úselfr   r   ú[/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/polys/domains/gmpyintegerring.pyÚ__init__   s    zGMPYIntegerRing.__init__c                 C   s   t t|ƒƒS )z!Convert ``a`` to a SymPy object. )r   Úint©r   Úar   r   r   Úto_sympy   s   zGMPYIntegerRing.to_sympyc                 C   s0   |j rt|jƒS t|ƒrtt|ƒƒS td| ƒ‚)z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %s)Ú
is_Integerr   Úpr	   r   r   r   r   r   r   Ú
from_sympy#   s
   
zGMPYIntegerRing.from_sympyc                 C   ó
   |  |¡S )z3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. ©Úto_int©ÚK1r   ÚK0r   r   r   Úfrom_FF_python,   ó   
zGMPYIntegerRing.from_FF_pythonc                 C   ó   t |ƒS )z,Convert Python's ``int`` to GMPY's ``mpz``. )r   r   r   r   r   Úfrom_ZZ_python0   ó   zGMPYIntegerRing.from_ZZ_pythonc                 C   ó   |j dkr
t|jƒS dS ©z1Convert Python's ``Fraction`` to GMPY's ``mpz``. r   N©Údenominatorr   Ú	numeratorr   r   r   r   Úfrom_QQ4   ó   

ÿzGMPYIntegerRing.from_QQc                 C   r&   r'   r(   r   r   r   r   Úfrom_QQ_python9   r,   zGMPYIntegerRing.from_QQ_pythonc                 C   r   )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. r   r   r   r   r   Úfrom_FF_gmpy>   r"   zGMPYIntegerRing.from_FF_gmpyc                 C   s   |S )z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. r   r   r   r   r   Úfrom_ZZ_gmpyB   s   zGMPYIntegerRing.from_ZZ_gmpyc                 C   s   |j dkr|jS dS )z(Convert GMPY ``mpq`` to GMPY's ``mpz``. r   N)r)   r*   r   r   r   r   Úfrom_QQ_gmpyF   s   
ÿzGMPYIntegerRing.from_QQ_gmpyc                 C   s"   |  |¡\}}|dkrt|ƒS dS )z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. r   N)Úto_rationalr   )r   r   r    r   Úqr   r   r   Úfrom_RealFieldK   s   ÿzGMPYIntegerRing.from_RealFieldc                 C   s   |j dkr|jS d S )Nr   )ÚyÚxr   r   r   r   Úfrom_GaussianIntegerRingR   s   
ÿz(GMPYIntegerRing.from_GaussianIntegerRingc                 C   s   t ||ƒ\}}}|||fS )z)Compute extended GCD of ``a`` and ``b``. )r   )r   r   ÚbÚhÚsÚtr   r   r   ÚgcdexV   s   
zGMPYIntegerRing.gcdexc                 C   ó
   t ||ƒS )z Compute GCD of ``a`` and ``b``. )r   ©r   r   r7   r   r   r   Úgcd[   r"   zGMPYIntegerRing.gcdc                 C   r<   )z Compute LCM of ``a`` and ``b``. )r   r=   r   r   r   Úlcm_   r"   zGMPYIntegerRing.lcmc                 C   r#   )zCompute square root of ``a``. )Ú	gmpy_sqrtr   r   r   r   r   c   r%   zGMPYIntegerRing.sqrtc                 C   r#   )zCompute factorial of ``a``. )Úgmpy_factorialr   r   r   r   r   g   r%   zGMPYIntegerRing.factorialN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚdtypeÚzeroÚoneÚtypeÚtpÚaliasr   r   r   r!   r$   r+   r-   r.   r/   r0   r3   r6   r;   r>   r?   r   r   r   r   r   r   r      s0    	r   N)rE   Úsympy.polys.domains.groundtypesr   r   r   rA   r   r   r   r   r@   Úsympy.core.numbersr	   Úsympy.polys.domains.integerringr
   Úsympy.polys.polyerrorsr   Úsympy.utilitiesr   r   r   r   r   r   Ú<module>   s    $