
    sg^                         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y)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(y) 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                      y )N selfs    T/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/domains/rationalfield.py__init__zRationalField.__init__-   s        c                 0    t        |t              ryt        S )z0Returns ``True`` if two domains are equivalent. T)
isinstancer   NotImplemented)r   others     r   __eq__zRationalField.__eq__0   s    e]+!!r   c                     t        d      S )zReturns hash code of ``self``. r   )hashr   s    r   __hash__zRationalField.__hash__7   s    Dz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                 f    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BBr   c                     |j                   r t        |j                  |j                        S |j                  r+ddlm} t        t        t        |j                  |             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   sS    ==qssACC= ZZ.C!2344 !E!IJJr   N)aliasc                &    ddl m}  || g|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   s    6 	7d<Y<e<<r   c                 p    |j                   r*| j                  |j                         |j                        S y)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   s+    
 ;;::addfbff-- r   c                     t        |      S z.Convert a Python ``int`` object to ``dtype``. r   r>   s      r   from_ZZzRationalField.from_ZZt       1vr   c                     t        |      S rC   r   r>   s      r   from_ZZ_pythonzRationalField.from_ZZ_pythonx   rE   r   c                 B    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                 B    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                 L    |j                   dk(  rt        |j                        S y)z3Convert a ``GaussianElement`` object to ``dtype``. r   N)yr   xr>   s      r   from_GaussianRationalFieldz(RationalField.from_GaussianRationalField   s    33!8qss8O r   c                 L    t        t        t        |j                  |             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                 0    t        |      t        |      z  S )z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``.  r   r   r)   bs      r   exquozRationalField.exquo       1vAr   c                 0    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    yyr   c                 H    t        |      t        |      z  | j                  fS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   ra   rZ   s      r   divzRationalField.div   s    1v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                 Z    t        |j                        xr 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)AMM*BBr   c                     |j                   dk  ryt        |j                         \  }}|dk7  ryt        |j                        \  }}|dk7  ry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   sW     ;;?,A:.A: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8D
(C	cB"
CK 15 =<.//
1*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      sM    6 $ M M E + 9 1 "w#E-| w# w#r _r   