
    Ed                         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dS )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$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                     d S )N )selfs    Alib/python3.11/site-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                 j    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/ABBBr   c                     |j         rt          |j        |j                  S |j        r5ddlm} t          t          t          |	                    |                     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   sq    = 	KqsAC== Z 	K......C!2!23344 !E!IJJJr   N)aliasc                &    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+   s       r   algebraic_fieldzRationalField.algebraic_fieldC   s6    6 	766666~d<Y<<<e<<<r   c                 n    |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   K0s      r   from_AlgebraicFieldz!RationalField.from_AlgebraicFielda   s6    
 ; 	.::addffbf---	. 	.r   c                      t          |          S z.Convert a Python ``int`` object to ``dtype``. r   r3   s      r   from_ZZzRationalField.from_ZZi       1vvr   c                      t          |          S r8   r   r3   s      r   from_ZZ_pythonzRationalField.from_ZZ_pythonm   r:   r   c                 6    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                 6    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                 D    |j         dk    rt          |j                  S dS )z3Convert a ``GaussianElement`` object to ``dtype``. r   N)yr   xr3   s      r   from_GaussianRationalFieldz(RationalField.from_GaussianRationalField   s'    3!8 	qs88O	 	r   c                 `    t          t          t          |                    |                     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                 @    t          |          t          |          z  S )z=Exact quotient of ``a`` and ``b``, implies ``__truediv__``.  r   r   r   bs      r   exquozRationalField.exquo       1vvAr   c                 @    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
    yr   c                 N    t          |          t          |          z  | j        fS )z6Division of ``a`` and ``b``, implies ``__truediv__``. )r   rV   rO   s      r   divzRationalField.div   s    1vv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588D
%((C	cB    
C C CK K K 15 = = = = =<. . .    / / // / /      
1 1 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      s    6 6 $ # # # # # 9 9 9 9 9 9 E E E E E E + + + + + + 9 9 9 9 9 9 1 1 1 1 1 1 " " " " " "Q Q Q Q QE-| Q Q Qh ]__r   