
    MZd                         d 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
 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)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
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$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    C/usr/lib/python3/dist-packages/sympy/polys/domains/rationalfield.py__init__zRationalField.__init__-   s        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_ring0   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_sympy5   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_sympy9   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   )AlgebraicFieldr)   )r   r+   )r   r)   	extensionr+   s       r   algebraic_fieldzRationalField.algebraic_fieldC   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_AlgebraicFielda   s+    
 ;;::addfbff-- r   c                     t        |      S z.Convert a Python ``int`` object to ``dtype``. r   r3   s      r   from_ZZzRationalField.from_ZZi       1vr   c                     t        |      S r8   r   r3   s      r   from_ZZ_pythonzRationalField.from_ZZ_pythonm   r:   r   c                 B    t        |j                  |j                        S z3Convert a Python ``Fraction`` object to ``dtype``. r   r   r   r3   s      r   from_QQzRationalField.from_QQq       1;;..r   c                 B    t        |j                  |j                        S r>   r?   r3   s      r   from_QQ_pythonzRationalField.from_QQ_pythonu   rA   r   c                     t        |      S )z,Convert a GMPY ``mpz`` object to ``dtype``. r   r3   s      r   from_ZZ_gmpyzRationalField.from_ZZ_gmpyy   r:   r   c                     |S )z,Convert a GMPY ``mpq`` object to ``dtype``. r   r3   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   xr3   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   r&   r   r'   r3   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   rO   s      r   quozRationalField.quo   rR   r   c                     | j                   S )z0Remainder of ``a`` and ``b``, implies nothing.  )zerorO   s      r   remzRationalField.rem   s    yyr   c                 H    t        |      t        |      z  | j                  fS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   rV   rO   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   )%__name__
__module____qualname____doc__repr)   is_RationalFieldis_QQis_Numericalhas_assoc_Ringhas_assoc_Fieldr   dtyperV   onetypetpr   r   r   r(   r-   r6   r9   r<   r@   rC   rE   rG   rK   rM   rQ   rT   rW   rY   r[   r]   r   r   r   r   r      s     CE##uLNOE8D
(C	cB
CK 15 =<.//
1*r   r   N)ra   sympy.external.gmpyr   sympy.polys.domains.groundtypesr   &sympy.polys.domains.characteristiczeror   sympy.polys.domains.fieldr    sympy.polys.domains.simpledomainr   sympy.polys.polyerrorsr	   sympy.utilitiesr
   r   r   r   r   r   <module>rs      sJ    6 $ 9 E + 9 1 "QE-| Q Qh _r   