K idZddlmZmZddlmZddlmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZddlmZdd lmZdd lZeGd d eeeZeZy ) z.Implementation of :class:`IntegerRing` class. )MPZ GROUND_TYPES) int_valued) SymPyInteger factorialgcdexgcdlcmsqrt is_squaresqrtrem)CharacteristicZero)Ring) SimpleDomain)CoercionFailed)publicNceZdZdZdZdZeZedZedZ e e Z dxZ Z dZdZdZdZdZdZdZd Zd Zd Zd d dZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)d Z*d!Z+d"Z,d#Z-y )$ IntegerRingaThe 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 ZZrTcy)z$Allow instantiation of this domain. Nselfs e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/domains/integerring.py__init__zIntegerRing.__init__3sc0t|trytS)z0Returns ``True`` if two domains are equivalent. T) isinstancerNotImplemented)rothers r__eq__zIntegerRing.__eq__6s e[ )! !rctdS)z&Compute a hash value for this domain. r)hashrs r__hash__zIntegerRing.__hash__=s Dzrc*tt|S)z!Convert ``a`` to a SymPy object. )rintras rto_sympyzIntegerRing.to_sympyAsCF##rc|jrt|jSt|rtt |St d|z)z&Convert SymPy's Integer to ``dtype``. zexpected an integer, got %s) is_Integerrprr'rr(s r from_sympyzIntegerRing.from_sympyEs< <<qss8O ]s1v;  !>!BC Crcddlm}|S)asReturn 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)rr0s r get_fieldzIntegerRing.get_fieldNs $ + rN)aliascB|jj|d|iS)aReturns 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 r3)r2algebraic_field)rr3 extensions rr5zIntegerRing.algebraic_fieldcs#60t~~//H%HHrcp|jr*|j|j|jSy)zcConvert a :py:class:`~.ANP` object to :ref:`ZZ`. See :py:meth:`~.Domain.convert`. N) is_groundconvertLCdomK1r)K0s rfrom_AlgebraicFieldzIntegerRing.from_AlgebraicFields+ ;;::addfbff- - rc p|jttjt||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'mathlogrr)bs rrCzIntegerRing.logs'<zz#dhhs1vq1233rc6t|j|Sz3Convert ``ModularInteger(int)`` to GMPY's ``mpz``. rto_intr<s rfrom_FFzIntegerRing.from_FF299Q<  rc6t|j|SrGrHr<s rfrom_FF_pythonzIntegerRing.from_FF_pythonrKrct|Sz,Convert Python's ``int`` to GMPY's ``mpz``. rr<s rfrom_ZZzIntegerRing.from_ZZ 1v rct|SrOrPr<s rfrom_ZZ_pythonzIntegerRing.from_ZZ_pythonrRrcL|jdk(rt|jSyz1Convert Python's ``Fraction`` to GMPY's ``mpz``. rN denominatorr numeratorr<s rfrom_QQzIntegerRing.from_QQ" ==A q{{# # rcL|jdk(rt|jSyrVrWr<s rfrom_QQ_pythonzIntegerRing.from_QQ_pythonr[rc6t|j|S)z3Convert ``ModularInteger(mpz)`` to GMPY's ``mpz``. rHr<s r from_FF_gmpyzIntegerRing.from_FF_gmpyrKrc|S)z*Convert GMPY's ``mpz`` to GMPY's ``mpz``. rr<s r from_ZZ_gmpyzIntegerRing.from_ZZ_gmpysrc:|jdk(r |jSy)z(Convert GMPY ``mpq`` to GMPY's ``mpz``. rN)rXrYr<s r from_QQ_gmpyzIntegerRing.from_QQ_gmpys ==A ;;  rc^|j|\}}|dk(rtt|Sy)z,Convert mpmath's ``mpf`` to GMPY's ``mpz``. rN) to_rationalrr')r=r)r>r-qs rfrom_RealFieldzIntegerRing.from_RealFields0~~a 1 6s1v;  rc:|jdk(r |jSy)Nr)yxr<s rfrom_GaussianIntegerRingz$IntegerRing.from_GaussianIntegerRings 33!833J rc>|jr|j|Sy)z*Convert ``Expression`` to GMPY's ``mpz``. N)r,r.r<s rfrom_EXzIntegerRing.from_EXs <<==# # rcHt||\}}}tdk(r|||fS|||fS)z)Compute extended GCD of ``a`` and ``b``. gmpy)rr)rr)rEhsts rrzIntegerRing.gcdexs11+1a 6 !a7Na7Nrct||S)z Compute GCD of ``a`` and ``b``. )r rDs rr zIntegerRing.gcd1ayrct||S)z Compute LCM of ``a`` and ``b``. )r rDs rr zIntegerRing.lcmrtrct|S)zCompute square root of ``a``. )r r(s rr zIntegerRing.sqrts Awrct|S)zReturn ``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 rr zIntegerRing.is_squares|rc:|dkryt|\}}|dk7ry|S)zuNon-negative square root of ``a`` if ``a`` is a square. See also ======== is_square rN)r )rr)rootrems rexsqrtzIntegerRing.exsqrts* q5AJ c !8 rct|S)zCompute factorial of ``a``. )rr(s rrzIntegerRing.factorials |r).__name__ __module__ __qualname____doc__repr3rrAzeroonetypetpis_IntegerRingis_ZZ is_Numericalis_PIDhas_assoc_Ringhas_assoc_Fieldrr"r%r*r.r2r5r?rCrJrMrQrTrZr]r_rarcrgrkrmrr r r r r{rrrrrrs  C E E 8D (C cB"!NUL FNO3"$D*15I:.4@!!$ $ ! $  rr)rsympy.external.gmpyrrsympy.core.numbersrsympy.polys.domains.groundtypesrrrr r r r r &sympy.polys.domains.characteristiczerorsympy.polys.domains.ringr sympy.polys.domains.simpledomainrsympy.polys.polyerrorsrsympy.utilitiesrrBrrrrrrs]41) F)91" |$*L||~]r