o
    à8Va9  ã                   @   sR   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 e	G dd„ deeƒƒZ
dS )	z0Implementation of :class:`FractionField` class. é    )ÚCompositeDomain)ÚField)ÚCoercionFailedÚGeneratorsError)Úpublicc                   @   s:  e Zd ZdZd ZZdZdZdFdd„Zdd„ Z	e
dd	„ ƒZe
d
d„ ƒZe
dd„ ƒZe
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d0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#d:d;„ Z$d<d=„ Z%d>d?„ Z&d@dA„ Z'dBdC„ Z(dDdE„ Z)dS )GÚFractionFieldz@A class for representing multivariate rational function fields. TNc                 C   sr   ddl m} t||ƒr|d u r|d u r|}n||||ƒ}|| _|j| _|j| _|j| _|j| _|j| _| j| _	d S )Nr   )Ú	FracField)
Zsympy.polys.fieldsr   Ú
isinstanceÚfieldÚdtypeZgensZngensÚsymbolsÚdomainÚdom)ÚselfZdomain_or_fieldr   Úorderr   r
   © r   úC/usr/lib/python3/dist-packages/sympy/polys/domains/fractionfield.pyÚ__init__   s   zFractionField.__init__c                 C   ó   | j  |¡S ©N)r
   Z	field_new)r   Úelementr   r   r   Únew%   s   zFractionField.newc                 C   ó   | j jS r   )r
   Úzero©r   r   r   r   r   (   ó   zFractionField.zeroc                 C   r   r   )r
   Úoner   r   r   r   r   ,   r   zFractionField.onec                 C   r   r   )r
   r   r   r   r   r   r   0   r   zFractionField.orderc                 C   r   r   )r   Úis_Exactr   r   r   r   r   4   r   zFractionField.is_Exactc                 C   s   t | j ¡ | jƒS r   )r   r   Ú	get_exactr   r   r   r   r   r   8   s   zFractionField.get_exactc                 C   s$   t | jƒd d tt | jƒ¡ d S )Nú(ú,ú))Ústrr   ÚjoinÚmapr   r   r   r   r   Ú__str__;   s   $zFractionField.__str__c                 C   s   t | jj| jj| j| jfƒS r   )ÚhashÚ	__class__Ú__name__r   r
   r   r   r   r   r   r   Ú__hash__>   s   zFractionField.__hash__c                 C   s.   t |tƒo| jj| j| jf|jj|j|jfkS )z0Returns ``True`` if two domains are equivalent. )r	   r   r   r
   r   r   )r   Úotherr   r   r   Ú__eq__A   s
   
ÿÿzFractionField.__eq__c                 C   s   |  ¡ S )z!Convert ``a`` to a SymPy object. )Zas_expr©r   Úar   r   r   Úto_sympyG   r   zFractionField.to_sympyc                 C   r   )z)Convert SymPy's expression to ``dtype``. )r
   Z	from_exprr,   r   r   r   Ú
from_sympyK   s   zFractionField.from_sympyc                 C   ó   | | j  ||¡ƒS ©z.Convert a Python ``int`` object to ``dtype``. ©r   Zconvert©ÚK1r-   ÚK0r   r   r   Úfrom_ZZO   ó   zFractionField.from_ZZc                 C   r0   r1   r2   r3   r   r   r   Úfrom_ZZ_pythonS   r7   zFractionField.from_ZZ_pythonc                 C   sH   | j }|j}|jr| || |¡|ƒƒ| || |¡|ƒƒ S | |||ƒƒS ©z3Convert a Python ``Fraction`` object to ``dtype``. )r   Úconvert_fromZis_ZZÚnumerÚdenom)r4   r-   r5   r   Úconvr   r   r   Úfrom_QQW   s
   (zFractionField.from_QQc                 C   r0   r9   r2   r3   r   r   r   Úfrom_QQ_python`   r7   zFractionField.from_QQ_pythonc                 C   r0   )z,Convert a GMPY ``mpz`` object to ``dtype``. r2   r3   r   r   r   Úfrom_ZZ_gmpyd   r7   zFractionField.from_ZZ_gmpyc                 C   r0   )z,Convert a GMPY ``mpq`` object to ``dtype``. r2   r3   r   r   r   Úfrom_QQ_gmpyh   r7   zFractionField.from_QQ_gmpyc                 C   r0   )z4Convert a ``GaussianRational`` object to ``dtype``. r2   r3   r   r   r   Úfrom_GaussianRationalFieldl   r7   z(FractionField.from_GaussianRationalFieldc                 C   r0   )z3Convert a ``GaussianInteger`` object to ``dtype``. r2   r3   r   r   r   Úfrom_GaussianIntegerRingp   r7   z&FractionField.from_GaussianIntegerRingc                 C   r0   ©z.Convert a mpmath ``mpf`` object to ``dtype``. r2   r3   r   r   r   Úfrom_RealFieldt   r7   zFractionField.from_RealFieldc                 C   r0   rD   r2   r3   r   r   r   Úfrom_ComplexFieldx   r7   zFractionField.from_ComplexFieldc                 C   s.   | j |kr| j  ||¡}|dur|  |¡S dS )z*Convert an algebraic number to ``dtype``. N)r   r:   r   r3   r   r   r   Úfrom_AlgebraicField|   s
   

ÿz!FractionField.from_AlgebraicFieldc                 C   sp   |j r|  | d¡|j¡S z|  | | jj¡¡W S  tt	fy7   z|  |¡W  Y S  tt	fy6   Y Y dS w w )z#Convert a polynomial to ``dtype``. é   N)
Z	is_groundr:   Zcoeffr   r   Zset_ringr
   Zringr   r   r3   r   r   r   Úfrom_PolynomialRingƒ   s   ÿùz!FractionField.from_PolynomialRingc              	   C   s(   z|  | j¡W S  ttfy   Y dS w )z*Convert a rational function to ``dtype``. N)Z	set_fieldr
   r   r   r3   r   r   r   Úfrom_FractionField“   s
   ÿz FractionField.from_FractionFieldc                 C   s   | j  ¡  ¡ S )z*Returns a field associated with ``self``. )r
   Zto_ringZ	to_domainr   r   r   r   Úget_ringš   s   zFractionField.get_ringc                 C   ó   | j  |jj¡S )z'Returns True if ``LC(a)`` is positive. )r   Úis_positiver;   ÚLCr,   r   r   r   rM   ž   ó   zFractionField.is_positivec                 C   rL   )z'Returns True if ``LC(a)`` is negative. )r   Úis_negativer;   rN   r,   r   r   r   rP   ¢   rO   zFractionField.is_negativec                 C   rL   )z+Returns True if ``LC(a)`` is non-positive. )r   Úis_nonpositiver;   rN   r,   r   r   r   rQ   ¦   rO   zFractionField.is_nonpositivec                 C   rL   )z+Returns True if ``LC(a)`` is non-negative. )r   Úis_nonnegativer;   rN   r,   r   r   r   rR   ª   rO   zFractionField.is_nonnegativec                 C   ó   |j S )zReturns numerator of ``a``. )r;   r,   r   r   r   r;   ®   ó   zFractionField.numerc                 C   rS   )zReturns denominator of ``a``. )r<   r,   r   r   r   r<   ²   rT   zFractionField.denomc                 C   s   |   | j |¡¡S )zReturns factorial of ``a``. )r   r   Ú	factorialr,   r   r   r   rU   ¶   r7   zFractionField.factorial)NN)*r(   Ú
__module__Ú__qualname__Ú__doc__Zis_FractionFieldZis_FracZhas_assoc_RingZhas_assoc_Fieldr   r   Úpropertyr   r   r   r   r   r%   r)   r+   r.   r/   r6   r8   r>   r?   r@   rA   rB   rC   rE   rF   rG   rI   rJ   rK   rM   rP   rQ   rR   r;   r<   rU   r   r   r   r   r   	   sT    




	r   N)rX   Z#sympy.polys.domains.compositedomainr   Zsympy.polys.domains.fieldr   Zsympy.polys.polyerrorsr   r   Zsympy.utilitiesr   r   r   r   r   r   Ú<module>   s    