K i^dZddlmZddlmZmZmZddlmZddl m Z ddl m Z ddl mZddlmZeGd d e ee ZeZy ) z0Implementation of :class:`RationalField` class. MPQ) SymPyRational is_squaresqrtrem)CharacteristicZero)Field) SimpleDomain)CoercionFailed)publicceZdZdZdZdZdxZZdZdZ dZ e Z e dZ e dZeeZdZdZdZd Zd Zd Zd d dZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(y ) RationalFieldaAbstract base class for the domain :ref:`QQ`. The :py:class:`RationalField` class represents the field of rational numbers $\mathbb{Q}$ as a :py:class:`~.Domain` in the domain system. :py:class:`RationalField` is a superclass of :py:class:`PythonRationalField` and :py:class:`GMPYRationalField` one of which will be the implementation for :ref:`QQ` depending on whether either of ``gmpy`` or ``gmpy2`` is installed or not. See also ======== Domain QQTrcy)Nselfs g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/domains/rationalfield.py__init__zRationalField.__init__-s c0t|trytS)z0Returns ``True`` if two domains are equivalent. T) isinstancerNotImplemented)rothers r__eq__zRationalField.__eq__0s e] +! !rctdS)zReturns hash code of ``self``. r)hashrs r__hash__zRationalField.__hash__7s Dzrcddlm}|S)z'Returns ring associated with ``self``. r)ZZ)sympy.polys.domainsr!)rr!s rget_ringzRationalField.get_ring;s * rcftt|jt|jS)z!Convert ``a`` to a SymPy object. )rint numerator denominatorras rto_sympyzRationalField.to_sympy@s!S-s1==/ABBrc|jr t|j|jS|jr+ddlm}ttt|j|Std|z)z&Convert SymPy's Integer to ``dtype``. r)RRz"expected `Rational` object, got %s) is_Rationalrpqis_Floatr"r,mapr% to_rationalr )rr)r,s r from_sympyzRationalField.from_sympyDsS ==qssACC= ZZ .C!234 4 !E!IJ JrN)aliasc&ddlm}||g|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 QQ, sqrt >>> QQ.algebraic_field(sqrt(2)) QQ r)AlgebraicFieldr4)r"r6)rr4 extensionr6s ralgebraic_fieldzRationalField.algebraic_fieldNs6 7ds rfrom_ZZzRationalField.from_ZZt 1v rct|SrCrr>s rfrom_ZZ_pythonzRationalField.from_ZZ_pythonxrErcBt|j|jSz3Convert a Python ``Fraction`` object to ``dtype``. rr&r'r>s rfrom_QQzRationalField.from_QQ|1;; ..rcBt|j|jSrIrJr>s rfrom_QQ_pythonzRationalField.from_QQ_pythonrLrct|S)z,Convert a GMPY ``mpz`` object to ``dtype``. rr>s r from_ZZ_gmpyzRationalField.from_ZZ_gmpyrErc|S)z,Convert a GMPY ``mpq`` object to ``dtype``. rr>s r from_QQ_gmpyzRationalField.from_QQ_gmpysrcL|jdk(rt|jSy)z3Convert a ``GaussianElement`` object to ``dtype``. rN)yrxr>s rfrom_GaussianRationalFieldz(RationalField.from_GaussianRationalFields 33!8qss8O rcLttt|j|S)z.Convert a mpmath ``mpf`` object to ``dtype``. )rr1r%r2r>s rfrom_RealFieldzRationalField.from_RealFieldsCR^^A./00rc0t|t|z S)z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``. rrr)bs rexquozRationalField.exquo1vArc0t|t|z S)z6Quotient of ``a`` and ``b``, implies ``__truediv__``. rrZs rquozRationalField.quor]rc|jS)z0Remainder of ``a`` and ``b``, implies nothing. )zerorZs rremzRationalField.rems yyrcHt|t|z |jfS)z6Division of ``a`` and ``b``, implies ``__truediv__``. )rrarZs rdivzRationalField.divs1vA ))rc|jS)zReturns numerator of ``a``. )r&r(s rnumerzRationalField.numers {{rc|jS)zReturns denominator of ``a``. )r'r(s rdenomzRationalField.denoms }}rcZt|jxrt|jS)zReturn ``True`` if ``a`` is a square. Explanation =========== A rational number is a square if and only if there exists a rational number ``b`` such that ``b * b == a``. )rr&r'r(s rrzRationalField.is_squares!%B)AMM*BBrc|jdkryt|j\}}|dk7ryt|j\}}|dk7ryt||S)zuNon-negative square root of ``a`` if ``a`` is a square. See also ======== is_square rN)r&rr'r)rr)p_sqrtp_remq_sqrtq_rems rexsqrtzRationalField.exsqrtsW ;;? ,  A: .  A:66""r))__name__ __module__ __qualname____doc__repr4is_RationalFieldis_QQ is_Numericalhas_assoc_Ringhas_assoc_Fieldrdtyperaonetypetprrrr#r*r3r8rArDrGrKrNrPrRrVrXr\r_rbrdrfrhrrorrrrrs  C E##uLNO E 8D (C cB " CK15=<.// 1*C#rrN)rssympy.external.gmpyrsympy.polys.domains.groundtypesrrr&sympy.polys.domains.characteristiczerorsympy.polys.domains.fieldr sympy.polys.domains.simpledomainr sympy.polys.polyerrorsr sympy.utilitiesr rrrrrrsM6$MME+91"w#E-|w#w#r_r