Ë
    7^(h  ã                   óÂ   — d Z ddlmZmZ ddlmZ ddlmZ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 dd	lmZ dd
lZe G d„ deee«      «       Z e«       Zy
)z.Implementation of :class:`IntegerRing` class. é    )ÚMPZÚGROUND_TYPES)Ú
int_valued)ÚSymPyIntegerÚ	factorialÚgcdexÚgcdÚlcmÚsqrtÚ	is_squareÚsqrtrem)ÚCharacteristicZero)ÚRing)ÚSimpleDomain)ÚCoercionFailed)ÚpublicNc                   ó  — e Zd ZdZdZdZeZ ed«      Z ed«      Z	 e
e	«      ZdxZZdZdZdZdZd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zddœ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 „ Z*d!„ Z+d"„ Z,d#„ Z-y)$ÚIntegerRingaÌ  The domain ``ZZ`` representing the integers `\mathbb{Z}`.

    The :py:class:`IntegerRing` class represents the ring of integers as a
    :py:class:`~.Domain` in the domain system. :py:class:`IntegerRing` is a
    super class of :py:class:`PythonIntegerRing` and
    :py:class:`GMPYIntegerRing` one of which will be the implementation for
    :ref:`ZZ` depending on whether or not ``gmpy`` or ``gmpy2`` is installed.

    See also
    ========

    Domain
    ÚZZr   é   Tc                  ó   — y)z$Allow instantiation of this domain. N© ©Úselfs    ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/domains/integerring.pyÚ__init__zIntegerRing.__init__3   s   � ó    c                 ó0   — t        |t        «      ryt        S )z0Returns ``True`` if two domains are equivalent. T)Ú
isinstancer   ÚNotImplemented)r   Úothers     r   Ú__eq__zIntegerRing.__eq__6   s   € ä�eœ[Ô)Øä!Ð!r   c                 ó   — t        d«      S )z&Compute a hash value for this domain. r   )Úhashr   s    r   Ú__hash__zIntegerRing.__hash__=   s   € ä�D‹zÐr   c                 ó*   — t        t        |«      «      S )z!Convert ``a`` to a SymPy object. )r   Úint©r   Úas     r   Úto_sympyzIntegerRing.to_sympyA   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IntegerRing.from_sympyE   s<   € à�<Š<Ü�q—s‘s“8ˆOÜ˜Œ]Ü”s˜1“v“;Ðä Ð!>ÀÑ!BÓCÐCr   c                 ó   — ddl m} |S )as  Return the associated field of fractions :ref:`QQ`

        Returns
        =======

        :ref:`QQ`:
            The associated field of fractions :ref:`QQ`, a
            :py:class:`~.Domain` representing the rational numbers
            `\mathbb{Q}`.

        Examples
        ========

        >>> from sympy import ZZ
        >>> ZZ.get_field()
        QQ
        r   )ÚQQ)Úsympy.polys.domainsr0   )r   r0   s     r   Ú	get_fieldzIntegerRing.get_fieldN   s   € õ$ 	+Øˆ	r   N)Úaliasc                óB   —  | j                  «       j                  |d|iŽS )a  Returns an algebraic field, i.e. `\mathbb{Q}(\alpha, \ldots)`.

        Parameters
        ==========

        *extension : One or more :py:class:`~.Expr`.
            Generators of the extension. These should be expressions that are
            algebraic over `\mathbb{Q}`.

        alias : str, :py:class:`~.Symbol`, None, optional (default=None)
            If provided, this will be used as the alias symbol for the
            primitive element of the returned :py:class:`~.AlgebraicField`.

        Returns
        =======

        :py:class:`~.AlgebraicField`
            A :py:class:`~.Domain` representing the algebraic field extension.

        Examples
        ========

        >>> from sympy import ZZ, sqrt
        >>> ZZ.algebraic_field(sqrt(2))
        QQ<sqrt(2)>
        r3   )r2   Úalgebraic_field)r   r3   Ú	extensions      r   r5   zIntegerRing.algebraic_fieldc   s#   € ð6 0ˆt�~‰~Ó×/Ñ/°ÐHÀ%ÑHÐHr   c                 óp   — |j                   r*| j                  |j                  «       |j                  «      S y)zcConvert a :py:class:`~.ANP` object to :ref:`ZZ`.

        See :py:meth:`~.Domain.convert`.
        N)Ú	is_groundÚconvertÚLCÚdom©ÚK1r)   ÚK0s      r   Úfrom_AlgebraicFieldzIntegerRing.from_AlgebraicField€   s+   € ð
 �;Š;Ø—:‘:˜aŸd™d›f b§f¡fÓ-Ð-ð r   c           	      óp   — | j                  t        t        j                  t        |«      |«      «      «      S )a*  Logarithm of *a* to the base *b*.

        Parameters
        ==========

        a: number
        b: number

        Returns
        =======

        $\\lfloor\log(a, b)\\rfloor$:
            Floor of the logarithm of *a* to the base *b*

        Examples
        ========

        >>> from sympy import ZZ
        >>> ZZ.log(ZZ(8), ZZ(2))
        3
        >>> ZZ.log(ZZ(9), ZZ(2))
        3

        Notes
        =====

        This function uses ``math.log`` which is based on ``float`` so it will
        fail for large integer arguments.
        )Údtyper'   ÚmathÚlog©r   r)   Úbs      r   rC   zIntegerRing.logˆ   s'   € ð< �z‰zœ#œdŸh™h¤s¨1£v¨qÓ1Ó2Ó3Ð3r   c                 ó6   — t        |j                  |«      «      S ©z3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. ©r   Úto_intr<   s      r   Úfrom_FFzIntegerRing.from_FF¨   ó   € ä�2—9‘9˜Q“<Ó Ð r   c                 ó6   — t        |j                  |«      «      S rG   rH   r<   s      r   Úfrom_FF_pythonzIntegerRing.from_FF_python¬   rK   r   c                 ó   — t        |«      S ©z,Convert Python's ``int`` to GMPY's ``mpz``. ©r   r<   s      r   Úfrom_ZZzIntegerRing.from_ZZ°   ó   € ä�1‹vˆr   c                 ó   — t        |«      S rO   rP   r<   s      r   Úfrom_ZZ_pythonzIntegerRing.from_ZZ_python´   rR   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IntegerRing.from_QQ¸   ó"   € à�=‰=˜AÒÜ�q—{‘{Ó#Ð#ð r   c                 óL   — |j                   dk(  rt        |j                  «      S yrV   rW   r<   s      r   Úfrom_QQ_pythonzIntegerRing.from_QQ_python½   r[   r   c                 ó6   — t        |j                  |«      «      S )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. rH   r<   s      r   Úfrom_FF_gmpyzIntegerRing.from_FF_gmpyÂ   rK   r   c                 ó   — |S )z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. r   r<   s      r   Úfrom_ZZ_gmpyzIntegerRing.from_ZZ_gmpyÆ   s   € àˆr   c                 ó:   — |j                   dk(  r|j                  S y)z(Convert GMPY ``mpq`` to GMPY's ``mpz``. r   N)rX   rY   r<   s      r   Úfrom_QQ_gmpyzIntegerRing.from_QQ_gmpyÊ   s   € à�=‰=˜AÒØ—;‘;Ðð r   c                 ó^   — |j                  |«      \  }}|dk(  rt        t        |«      «      S y)z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. r   N)Úto_rationalr   r'   )r=   r)   r>   r-   Úqs        r   Úfrom_RealFieldzIntegerRing.from_RealFieldÏ   s0   € à�~‰~˜aÓ ‰ˆˆ1à�Š6ô ”s˜1“v“;Ðð	 r   c                 ó:   — |j                   dk(  r|j                  S y )Nr   )ÚyÚxr<   s      r   Úfrom_GaussianIntegerRingz$IntegerRing.from_GaussianIntegerRingÙ   s   € Ø�3‰3�!Š8Ø—3‘3ˆJð r   c                 ó>   — |j                   r| j                  |«      S y)z*Convert ``Expression`` to GMPY's ``mpz``. N)r,   r.   r<   s      r   Úfrom_EXzIntegerRing.from_EXÝ   s   € à�<Š<Ø—=‘= Ó#Ð#ð r   c                 óH   — t        ||«      \  }}}t        dk(  r|||fS |||fS )z)Compute extended GCD of ``a`` and ``b``. Úgmpy)r   r   )r   r)   rE   ÚhÚsÚts         r   r   zIntegerRing.gcdexâ   s1   € ä˜˜1“+‰ˆˆ1ˆaä˜6Ò!Ø�a˜�7ˆNà�a˜�7ˆNr   c                 ó   — t        ||«      S )z Compute GCD of ``a`` and ``b``. )r	   rD   s      r   r	   zIntegerRing.gcdë   ó   € ä�1�a‹yÐr   c                 ó   — t        ||«      S )z Compute LCM of ``a`` and ``b``. )r
   rD   s      r   r
   zIntegerRing.lcmï   rt   r   c                 ó   — t        |«      S )zCompute square root of ``a``. )r   r(   s     r   r   zIntegerRing.sqrtó   s   € ä�A‹wˆr   c                 ó   — t        |«      S )zÅReturn ``True`` if ``a`` is a square.

        Explanation
        ===========
        An integer is a square if and only if there exists an integer
        ``b`` such that ``b * b == a``.
        )r   r(   s     r   r   zIntegerRing.is_square÷   s   € ô ˜‹|Ðr   c                 ó:   — |dk  ryt        |«      \  }}|dk7  ry|S )zuNon-negative square root of ``a`` if ``a`` is a square.

        See also
        ========
        is_square
        r   N)r   )r   r)   ÚrootÚrems       r   ÚexsqrtzIntegerRing.exsqrt  s*   € ð ˆqŠ5ØÜ˜A“J‰	ˆˆcØ�!Š8ØØˆr   c                 ó   — t        |«      S )zCompute factorial of ``a``. )r   r(   s     r   r   zIntegerRing.factorial  s   € ä˜‹|Ðr   ).Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrepr3   r   rA   ÚzeroÚoneÚtypeÚtpÚis_IntegerRingÚis_ZZÚis_NumericalÚis_PIDÚhas_assoc_RingÚhas_assoc_Fieldr   r"   r%   r*   r.   r2   r5   r?   rC   rJ   rM   rQ   rT   rZ   r]   r_   ra   rc   rg   rk   rm   r   r	   r
   r   r   r{   r   r   r   r   r   r      sç   „ ñð €CØ€EØ€EÙ�‹8€DÙ
�‹(€CÙ	ˆc‹€Bð "Ð!€N�UØ€LØ€Fà€NØ€Oò3ò"òò$òDòð* 15ô Iò:.ò4ò@!ò!òòò$ò
$ò
!òòò
òò$ò
òòòòòór   r   )r€   Úsympy.external.gmpyr   r   Úsympy.core.numbersr   Úsympy.polys.domains.groundtypesr   r   r   r	   r
   r   r   r   Ú&sympy.polys.domains.characteristiczeror   Úsympy.polys.domains.ringr   Ú sympy.polys.domains.simpledomainr   Úsympy.polys.polyerrorsr   Úsympy.utilitiesr   rB   r   r   r   r   r   ú<module>r”      s]   ðÙ 4ç 1å )÷÷ ó õ FÝ )Ý 9Ý 1Ý "ã àô|�$Ð*¨Ló |ó ð|ñ~ ƒ]�r   