o
    à8Va   ã                   @   sz   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
„ d
eee
ƒƒZeƒ ZdS )z0Implementation of :class:`RationalField` class. é    ©ÚMPQ)ÚSymPyRational)Ú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„ 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$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                 C   s   d S )N© )Úselfr   r   úC/usr/lib/python3/dist-packages/sympy/polys/domains/rationalfield.pyÚ__init__-   s   zRationalField.__init__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_ring0   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_sympy5   ó   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)Zis_Rationalr   ÚpÚqZis_Floatr   r   Úmapr   Úto_rationalr   )r   r   r   r   r   r   Ú
from_sympy9   s   zRationalField.from_sympyc                 G   s   ddl m} || g|¢R Ž S )a(  Returns an algebraic field, i.e. `\mathbb{Q}(\alpha, \ldots)`.

        Parameters
        ==========

        *extension: One or more Expr
            Generators of the extension. These should be expressions that are
            algebraic over `\mathbb{Q}`.

        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   )ÚAlgebraicField)r   r!   )r   Ú	extensionr!   r   r   r   Úalgebraic_fieldC   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)Z	is_groundZconvertZLCZdom©ZK1r   ZK0r   r   r   Úfrom_AlgebraicField]   s   ÿz!RationalField.from_AlgebraicFieldc                 C   ó   t |ƒS ©z.Convert a Python ``int`` object to ``dtype``. r   r$   r   r   r   Úfrom_ZZe   ó   zRationalField.from_ZZc                 C   r&   r'   r   r$   r   r   r   Úfrom_ZZ_pythoni   r)   zRationalField.from_ZZ_pythonc                 C   ó   t |j|jƒS ©z3Convert a Python ``Fraction`` object to ``dtype``. ©r   r   r   r$   r   r   r   Úfrom_QQm   ó   zRationalField.from_QQc                 C   r+   r,   r-   r$   r   r   r   Úfrom_QQ_pythonq   r/   zRationalField.from_QQ_pythonc                 C   r&   )z,Convert a GMPY ``mpz`` object to ``dtype``. r   r$   r   r   r   Úfrom_ZZ_gmpyu   r)   zRationalField.from_ZZ_gmpyc                 C   s   |S )z,Convert a GMPY ``mpq`` object to ``dtype``. r   r$   r   r   r   Úfrom_QQ_gmpyy   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   Úxr$   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   r$   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   r7   )z6Quotient of ``a`` and ``b``, implies ``__truediv__``. r   r8   r   r   r   ÚquoŠ   r;   zRationalField.quoc                 C   s   | j S )z0Remainder of ``a`` and ``b``, implies nothing.  )Úzeror8   r   r   r   ÚremŽ   ó   zRationalField.remc                 C   s   t |ƒt |ƒ | jfS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   r=   r8   r   r   r   Údiv’   r   zRationalField.divc                 C   ó   |j S )zReturns numerator of ``a``. )r   r   r   r   r   Únumer–   r?   zRationalField.numerc                 C   rA   )zReturns denominator of ``a``. )r   r   r   r   r   Údenomš   r?   zRationalField.denomN)%Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZrepÚaliasZis_RationalFieldZis_QQZis_NumericalZhas_assoc_RingZhas_assoc_Fieldr   Zdtyper=   ZoneÚtypeÚtpr   r   r   r    r#   r%   r(   r*   r.   r0   r1   r2   r5   r6   r:   r<   r>   r@   rB   rC   r   r   r   r   r
      s@    
r
   N)rG   Zsympy.external.gmpyr   Zsympy.polys.domains.groundtypesr   Z&sympy.polys.domains.characteristiczeror   Zsympy.polys.domains.fieldr   Z sympy.polys.domains.simpledomainr   Zsympy.polys.polyerrorsr   Zsympy.utilitiesr	   r
   r   r   r   r   r   Ú<module>   s     
