ó
    Š*£h  ã                   óÂ   • S r SSKJrJr  SSKJr  SSKJrJrJ	r	J
r
JrJrJrJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
Kr\ " S S\\\5      5       r\" 5       rg
)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                   ó  • \ rS rSrSrSrSr\r\" S5      r	\" S5      r
\" \
5      rS=rrSrSrSrSrS rS rS	 rS
 rS rS rSS.S jrS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S r&S r'S r(S r)S  r*S! r+S" r,S# r-S$ r.S%r/g)&ÚIntegerRingé   a¨  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                 ó   • g)z$Allow instantiation of this domain. N© ©Úselfs    Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/polys/domains/integerring.pyÚ__init__ÚIntegerRing.__init__3   s   � ó    c                 ó:   • [        U[        5      (       a  g[        $ )z0Returns ``True`` if two domains are equivalent. T)Ú
isinstancer   ÚNotImplemented)r   Úothers     r   Ú__eq__ÚIntegerRing.__eq__6   s   € ä�eœ[×)Ñ)Øä!Ð!r   c                 ó   • [        S5      $ )z&Compute a hash value for this domain. r   )Úhashr   s    r   Ú__hash__ÚIntegerRing.__hash__=   s   € ä�D‹zÐr   c                 ó*   • [        [        U5      5      $ )z!Convert ``a`` to a SymPy object. )r   Úint©r   Úas     r   Úto_sympyÚIntegerRing.to_sympyA   s   € äœC ›FÓ#Ð#r   c                 ó²   • UR                   (       a  [        UR                  5      $ [        U5      (       a  [        [	        U5      5      $ [        SU-  5      e)z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %s)Ú
is_Integerr   Úpr   r+   r   r,   s     r   Ú
from_sympyÚIntegerRing.from_sympyE   s>   € à�<�<Ü�q—s‘s“8ˆOÜ˜�]‰]Ü”s˜1“v“;Ðä Ð!>ÀÑ!BÓCÐCr   c                 ó   • SSK Jn  U$ )a  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.domainsr6   )r   r6   s     r   Ú	get_fieldÚIntegerRing.get_fieldN   s   € õ$ 	+Øˆ	r   N)Úaliasc                óB   • U R                  5       R                  " USU06$ )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)>
r:   )r8   Úalgebraic_field)r   r:   Ú	extensions      r   r<   ÚIntegerRing.algebraic_fieldc   s!   € ð6 �~‰~Ó×/Ò/°ÐHÀ%ÑHÐHr   c                 óz   • UR                   (       a*  U R                  UR                  5       UR                  5      $ g)zSConvert a :py:class:`~.ANP` object to :ref:`ZZ`.

See :py:meth:`~.Domain.convert`.
N)Ú	is_groundÚconvertÚLCÚdom©ÚK1r-   ÚK0s      r   Úfrom_AlgebraicFieldÚIntegerRing.from_AlgebraicField€   s+   € ð
 �;�;Ø—:‘:˜aŸd™d›f b§f¡fÓ-Ð-ð r   c           	      ór   • U R                  [        [        R                  " [        U5      U5      5      5      $ )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   rL   ÚIntegerRing.logˆ   s'   € ð< �z‰zœ#œdŸhšh¤s¨1£v¨qÓ1Ó2Ó3Ð3r   c                 ó6   • [        UR                  U5      5      $ ©z3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. ©r   Úto_intrD   s      r   Úfrom_FFÚIntegerRing.from_FF¨   ó   € ä�2—9‘9˜Q“<Ó Ð r   c                 ó6   • [        UR                  U5      5      $ rQ   rR   rD   s      r   Úfrom_FF_pythonÚIntegerRing.from_FF_python¬   rV   r   c                 ó   • [        U5      $ ©z,Convert Python's ``int`` to GMPY's ``mpz``. ©r   rD   s      r   Úfrom_ZZÚIntegerRing.from_ZZ°   ó   € ä�1‹vˆr   c                 ó   • [        U5      $ r[   r\   rD   s      r   Úfrom_ZZ_pythonÚIntegerRing.from_ZZ_python´   r_   r   c                 óN   • UR                   S:X  a  [        UR                  5      $ g©z1Convert Python's ``Fraction`` to GMPY's ``mpz``. r   N©Údenominatorr   Ú	numeratorrD   s      r   Úfrom_QQÚIntegerRing.from_QQ¸   ó"   € à�=‰=˜AÓÜ�q—{‘{Ó#Ð#ð r   c                 óN   • UR                   S:X  a  [        UR                  5      $ grd   re   rD   s      r   Úfrom_QQ_pythonÚIntegerRing.from_QQ_python½   rj   r   c                 ó6   • [        UR                  U5      5      $ )z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. rR   rD   s      r   Úfrom_FF_gmpyÚIntegerRing.from_FF_gmpyÂ   rV   r   c                 ó   • U$ )z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. r   rD   s      r   Úfrom_ZZ_gmpyÚIntegerRing.from_ZZ_gmpyÆ   s   € àˆr   c                 ó<   • UR                   S:X  a  UR                  $ g)z(Convert GMPY ``mpq`` to GMPY's ``mpz``. r   N)rf   rg   rD   s      r   Úfrom_QQ_gmpyÚIntegerRing.from_QQ_gmpyÊ   s   € à�=‰=˜AÓØ—;‘;Ðð r   c                 ó^   • UR                  U5      u  p4US:X  a  [        [        U5      5      $ g)z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. r   N)Úto_rationalr   r+   )rE   r-   rF   r2   Úqs        r   Úfrom_RealFieldÚIntegerRing.from_RealFieldÏ   s.   € à�~‰~˜aÓ ‰ˆà�‹6ô ”s˜1“v“;Ðð	 r   c                 ó<   • UR                   S:X  a  UR                  $ g )Nr   )ÚyÚxrD   s      r   Úfrom_GaussianIntegerRingÚ$IntegerRing.from_GaussianIntegerRingÙ   s   € Ø�3‰3�!‹8Ø—3‘3ˆJð r   c                 óH   • UR                   (       a  U R                  U5      $ g)z*Convert ``Expression`` to GMPY's ``mpz``. N)r1   r3   rD   s      r   Úfrom_EXÚIntegerRing.from_EXÝ   s   € à�<�<Ø—=‘= Ó#Ð#ð r   c                 óB   • [        X5      u  p4n[        S:X  a  XEU4$ X4U4$ )z)Compute extended GCD of ``a`` and ``b``. Úgmpy)r   r   )r   r-   rN   ÚhÚsÚts         r   r   ÚIntegerRing.gcdexâ   s)   € ä˜“+‰ˆˆaä˜6Ó!Ø˜�7ˆNà˜�7ˆNr   c                 ó   • [        X5      $ )z Compute GCD of ``a`` and ``b``. )r	   rM   s      r   r	   ÚIntegerRing.gcdë   ó   € ä�1‹yÐr   c                 ó   • [        X5      $ )z Compute LCM of ``a`` and ``b``. )r
   rM   s      r   r
   ÚIntegerRing.lcmï   rŒ   r   c                 ó   • [        U5      $ )zCompute square root of ``a``. )r   r,   s     r   r   ÚIntegerRing.sqrtó   s   € ä�A‹wˆr   c                 ó   • [        U5      $ )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   ÚIntegerRing.is_square÷   s   € ô ˜‹|Ðr   c                 ó<   • US:  a  g[        U5      u  p#US:w  a  gU$ )zUNon-negative square root of ``a`` if ``a`` is a square.

See also
========
is_square
r   N)r   )r   r-   ÚrootÚrems       r   ÚexsqrtÚIntegerRing.exsqrt  s(   € ð ˆq‹5ØÜ˜A“J‰	ˆØ�!‹8ØØˆr   c                 ó   • [        U5      $ )zCompute factorial of ``a``. )r   r,   s     r   r   ÚIntegerRing.factorial  s   € ä˜‹|Ðr   r   )0Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úrepr:   r   rJ   ÚzeroÚoneÚtypeÚtpÚis_IntegerRingÚis_ZZÚis_NumericalÚis_PIDÚhas_assoc_RingÚhas_assoc_Fieldr   r$   r(   r.   r3   r8   r<   rG   rL   rT   rX   r]   ra   rh   rl   ro   rr   ru   rz   r   r‚   r   r	   r
   r   r   r–   r   Ú__static_attributes__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   rK   r   r   r   r   r   Ú<module>r³      s]   ðÙ 4ç 1å )÷÷ ó õ FÝ )Ý 9Ý 1Ý "ã àô|�$Ð*¨Ló |ó ð|ñ~ ƒ]�r   