o
    jg^                     @   s   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
 d
e
eeZe ZdS )z0Implementation of :class:`RationalField` class.     MPQ)SymPyRational	is_squaresqrtrem)CharacteristicZero)Field)SimpleDomain)CoercionFailed)publicc                   @   s  e Zd ZdZdZdZd ZZdZdZ	dZ
eZedZedZeeZdd Zdd	 Zd
d Zdd Zdd Zdd ZddddZdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z d(d) Z!d*d+ Z"d,d- Z#d.d/ Z$d0d1 Z%d2d3 Z&d4d5 Z'd6d7 Z(dS )8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                 C   s   d S )N selfr   r   Y/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/polys/domains/rationalfield.py__init__-   s   zRationalField.__init__c                 C   s   t |trdS tS )z0Returns ``True`` if two domains are equivalent. T)
isinstancer   NotImplemented)r   otherr   r   r   __eq__0   s   
zRationalField.__eq__c                 C   s   t dS )zReturns hash code of ``self``. r   )hashr   r   r   r   __hash__7      zRationalField.__hash__c                 C   s   ddl m} |S )z'Returns ring associated with ``self``. r   )ZZ)sympy.polys.domainsr   )r   r   r   r   r   get_ring;   s   zRationalField.get_ringc                 C   s   t t|jt|jS )z!Convert ``a`` to a SymPy object. )r   int	numeratordenominatorr   ar   r   r   to_sympy@      zRationalField.to_sympyc                 C   sF   |j r
t|j|jS |jrddlm} ttt|	| S t
d| )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%   r   r   r   
from_sympyD   s   zRationalField.from_sympyN)aliasc                G   s"   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   )AlgebraicFieldr-   )r   r.   )r   r-   	extensionr.   r   r   r   algebraic_fieldN   s   zRationalField.algebraic_fieldc                 C   s   |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"   K0r   r   r   from_AlgebraicFieldl   s   z!RationalField.from_AlgebraicFieldc                 C      t |S z.Convert a Python ``int`` object to ``dtype``. r   r5   r   r   r   from_ZZt   r   zRationalField.from_ZZc                 C   r9   r:   r   r5   r   r   r   from_ZZ_pythonx   r   zRationalField.from_ZZ_pythonc                 C      t |j|jS z3Convert a Python ``Fraction`` object to ``dtype``. r   r   r    r5   r   r   r   from_QQ|      zRationalField.from_QQc                 C   r=   r>   r?   r5   r   r   r   from_QQ_python   rA   zRationalField.from_QQ_pythonc                 C   r9   )z,Convert a GMPY ``mpz`` object to ``dtype``. r   r5   r   r   r   from_ZZ_gmpy   r   zRationalField.from_ZZ_gmpyc                 C   s   |S )z,Convert a GMPY ``mpq`` object to ``dtype``. r   r5   r   r   r   from_QQ_gmpy   s   zRationalField.from_QQ_gmpyc                 C   s   |j dkr
t|jS dS )z3Convert a ``GaussianElement`` object to ``dtype``. r   N)yr   xr5   r   r   r   from_GaussianRationalField   s   

z(RationalField.from_GaussianRationalFieldc                 C   s   t tt|| S )z.Convert a mpmath ``mpf`` object to ``dtype``. )r   r*   r   r+   r5   r   r   r   from_RealField   s   zRationalField.from_RealFieldc                 C      t |t | S )z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``.  r   r   r"   br   r   r   exquo      zRationalField.exquoc                 C   rI   )z6Quotient of ``a`` and ``b``, implies ``__truediv__``. r   rJ   r   r   r   quo   rM   zRationalField.quoc                 C   s   | j S )z0Remainder of ``a`` and ``b``, implies nothing.  )zerorJ   r   r   r   rem      zRationalField.remc                 C   s   t |t | | jfS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   rO   rJ   r   r   r   div   r$   zRationalField.divc                 C      |j S )zReturns numerator of ``a``. )r   r!   r   r   r   numer   rQ   zRationalField.numerc                 C   rS   )zReturns denominator of ``a``. )r    r!   r   r   r   denom   rQ   zRationalField.denomc                 C   s   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!   r   r   r   r      s   zRationalField.is_squarec                 C   sL   |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_remr   r   r   exsqrt   s   

zRationalField.exsqrt))__name__
__module____qualname____doc__repr-   is_RationalFieldis_QQis_Numericalhas_assoc_Ringhas_assoc_Fieldr   dtyperO   onetypetpr   r   r   r   r#   r,   r0   r8   r;   r<   r@   rB   rC   rD   rG   rH   rL   rN   rP   rR   rT   rU   r   rZ   r   r   r   r   r      sH    

r   N)r^   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   r   <module>   s     
: