a
    RG5d                     @   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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 )0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   ]/var/www/html/django/DPS/env/lib/python3.9/site-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   s    zRationalField.to_sympyc                 C   sJ   |j rt|j|jS |jr:ddlm} ttt|	| S t
d| dS )z&Convert SymPy's Integer to ``dtype``. r   )RRz"expected `Rational` object, got %sN)is_Rationalr   pqis_Floatr   r   mapr   to_rationalr   )r   r   r   r   r   r   
from_sympy9   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_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)	is_groundconvertLCdomK1r   K0r   r   r   from_AlgebraicFielda   s    z!RationalField.from_AlgebraicFieldc                 C   s   t |S z.Convert a Python ``int`` object to ``dtype``. r   r*   r   r   r   from_ZZi   s    zRationalField.from_ZZc                 C   s   t |S r.   r   r*   r   r   r   from_ZZ_pythonm   s    zRationalField.from_ZZ_pythonc                 C   s   t |j|jS z3Convert a Python ``Fraction`` object to ``dtype``. r   r   r   r*   r   r   r   from_QQq   s    zRationalField.from_QQc                 C   s   t |j|jS r1   r2   r*   r   r   r   from_QQ_pythonu   s    zRationalField.from_QQ_pythonc                 C   s   t |S )z,Convert a GMPY ``mpz`` object to ``dtype``. r   r*   r   r   r   from_ZZ_gmpyy   s    zRationalField.from_ZZ_gmpyc                 C   s   |S )z,Convert a GMPY ``mpq`` object to ``dtype``. r   r*   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   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   s   t |t | S )z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``.  r   r   r   br   r   r   exquo   s    zRationalField.exquoc                 C   s   t |t | S )z6Quotient of ``a`` and ``b``, implies ``__truediv__``. r   r;   r   r   r   quo   s    zRationalField.quoc                 C   s   | j S )z0Remainder of ``a`` and ``b``, implies nothing.  )zeror;   r   r   r   rem   s    zRationalField.remc                 C   s   t |t | | jfS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   r?   r;   r   r   r   div   s    zRationalField.divc                 C   s   |j S )zReturns numerator of ``a``. )r   r   r   r   r   numer   s    zRationalField.numerc                 C   s   |j S )zReturns denominator of ``a``. )r   r   r   r   r   denom   s    zRationalField.denom)%__name__
__module____qualname____doc__repr"   is_RationalFieldis_QQis_Numericalhas_assoc_Ringhas_assoc_Fieldr   dtyper?   onetypetpr   r   r   r!   r%   r-   r/   r0   r3   r4   r5   r6   r9   r:   r=   r>   r@   rA   rB   rC   r   r   r   r   r
      s>   
r
   N)rG   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   r   <module>   s    