
    g^                         d Z ddlmZ ddl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 e G d	 d
e
ee                      Z e            ZdS )z0Implementation of :class:`RationalField` class.     MPQ)SymPyRational	is_squaresqrtrem)CharacteristicZero)Field)SimpleDomain)CoercionFailed)publicc                   
   e Zd ZdZdZdZdxZZdZdZ	dZ
eZ ed          Z ed          Z ee          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S ) RationalFielda  Abstract 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
    QQTr      c                     d S )N selfs    ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/domains/rationalfield.py__init__zRationalField.__init__-   s        c                 >    t          |t                    rdS t          S )z0Returns ``True`` if two domains are equivalent. T)
isinstancer   NotImplemented)r   others     r   __eq__zRationalField.__eq__0   s    e]++ 	"4!!r   c                      t          d          S )zReturns hash code of ``self``. r   )hashr   s    r   __hash__zRationalField.__hash__7   s    Dzzr   c                     ddl m} |S )z'Returns ring associated with ``self``. r   )ZZ)sympy.polys.domainsr!   )r   r!   s     r   get_ringzRationalField.get_ring;   s    ******	r   c                 j    t          t          |j                  t          |j                            S )z!Convert ``a`` to a SymPy object. )r   int	numeratordenominatorr   as     r   to_sympyzRationalField.to_sympy@   s&    S--s1=/A/ABBBr   c                     |j         rt          |j        |j                  S |j        r5ddlm} t          t          t          |	                    |                     S t          d|z            )z&Convert SymPy's Integer to ``dtype``. r   )RRz"expected `Rational` object, got %s)is_Rationalr   pqis_Floatr"   r,   mapr%   to_rationalr   )r   r)   r,   s      r   
from_sympyzRationalField.from_sympyD   sq    = 	KqsAC== Z 	K......C!2!23344 !E!IJJJr   N)aliasc                &    ddl m}  || g|R 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 QQ, sqrt
        >>> QQ.algebraic_field(sqrt(2))
        QQ<sqrt(2)>
        r   )AlgebraicFieldr4   )r"   r6   )r   r4   	extensionr6   s       r   algebraic_fieldzRationalField.algebraic_fieldN   s6    6 	766666~d<Y<<<e<<<r   c                 n    |j         r-|                     |                                |j                  S dS )zbConvert a :py:class:`~.ANP` object to :ref:`QQ`.

        See :py:meth:`~.Domain.convert`
        N)	is_groundconvertLCdomK1r)   K0s      r   from_AlgebraicFieldz!RationalField.from_AlgebraicFieldl   s6    
 ; 	.::addffbf---	. 	.r   c                      t          |          S z.Convert a Python ``int`` object to ``dtype``. r   r>   s      r   from_ZZzRationalField.from_ZZt       1vvr   c                      t          |          S rC   r   r>   s      r   from_ZZ_pythonzRationalField.from_ZZ_pythonx   rE   r   c                 6    t          |j        |j                  S z3Convert a Python ``Fraction`` object to ``dtype``. r   r&   r'   r>   s      r   from_QQzRationalField.from_QQ|       1;...r   c                 6    t          |j        |j                  S rI   rJ   r>   s      r   from_QQ_pythonzRationalField.from_QQ_python   rL   r   c                      t          |          S )z,Convert a GMPY ``mpz`` object to ``dtype``. r   r>   s      r   from_ZZ_gmpyzRationalField.from_ZZ_gmpy   rE   r   c                     |S )z,Convert a GMPY ``mpq`` object to ``dtype``. r   r>   s      r   from_QQ_gmpyzRationalField.from_QQ_gmpy   s    r   c                 D    |j         dk    rt          |j                  S dS )z3Convert a ``GaussianElement`` object to ``dtype``. r   N)yr   xr>   s      r   from_GaussianRationalFieldz(RationalField.from_GaussianRationalField   s!    3!88qs88O 8r   c                 `    t          t          t          |                    |                     S )z.Convert a mpmath ``mpf`` object to ``dtype``. )r   r1   r%   r2   r>   s      r   from_RealFieldzRationalField.from_RealField   s#    CR^^A..//00r   c                 @    t          |          t          |          z  S )z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``.  r   r   r)   bs      r   exquozRationalField.exquo       1vvAr   c                 @    t          |          t          |          z  S )z6Quotient of ``a`` and ``b``, implies ``__truediv__``. r   rZ   s      r   quozRationalField.quo   r]   r   c                     | j         S )z0Remainder of ``a`` and ``b``, implies nothing.  )zerorZ   s      r   remzRationalField.rem   s
    yr   c                 N    t          |          t          |          z  | j        fS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   ra   rZ   s      r   divzRationalField.div   s    1vvA	))r   c                     |j         S )zReturns numerator of ``a``. )r&   r(   s     r   numerzRationalField.numer   s
    {r   c                     |j         S )zReturns denominator of ``a``. )r'   r(   s     r   denomzRationalField.denom   s
    }r   c                 R    t          |j                  ot          |j                  S )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``.
        )r   r&   r'   r(   s     r   r   zRationalField.is_square   s#     %%B)AM*B*BBr   c                     |j         dk     rdS t          |j                   \  }}|dk    rdS t          |j                  \  }}|dk    rdS t          ||          S )zuNon-negative square root of ``a`` if ``a`` is a square.

        See also
        ========
        is_square
        r   N)r&   r   r'   r   )r   r)   p_sqrtp_remq_sqrtq_rems         r   exsqrtzRationalField.exsqrt   sf     ;??4,,A::4..A::466"""r   ))__name__
__module____qualname____doc__repr4   is_RationalFieldis_QQis_Numericalhas_assoc_Ringhas_assoc_Fieldr   dtypera   onetypetpr   r   r   r#   r*   r3   r8   rA   rD   rG   rK   rN   rP   rR   rV   rX   r\   r_   rb   rd   rf   rh   r   ro   r   r   r   r   r      s         CE##uLNOE588D
%((C	cB  " " "    
C C CK K K 15 = = = = =<. . .    / / // / /      
1 1 1      * * *    C C C# # # # #r   r   N)rs   sympy.external.gmpyr   sympy.polys.domains.groundtypesr   r   r   &sympy.polys.domains.characteristiczeror   sympy.polys.domains.fieldr	    sympy.polys.domains.simpledomainr
   sympy.polys.polyerrorsr   sympy.utilitiesr   r   r   r   r   r   <module>r      s    6 6 $ # # # # # M M M M M M M M M M E E E E E E + + + + + + 9 9 9 9 9 9 1 1 1 1 1 1 " " " " " "w# w# w# w# w#E-| w# w# w#r ]__r   