o
    *Î®c9  ã                   @   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)
Úsympy.polys.fieldsr   Ú
isinstanceÚfieldÚdtypeÚgensÚngensÚsymbolsÚdomainÚdom)ÚselfÚdomain_or_fieldr   Úorderr   r   © r   úH/tmp/pip-target-vg8gfxp4/lib/python/sympy/polys/domains/fractionfield.pyÚ__init__   s   zFractionField.__init__c                 C   ó   | j  |¡S ©N)r   Ú	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. )Úas_expr©r   Úar   r   r   Úto_sympyG   r    zFractionField.to_sympyc                 C   r   )z)Convert SymPy's expression to ``dtype``. )r   Ú	from_exprr2   r   r   r   Ú
from_sympyK   s   zFractionField.from_sympyc                 C   ó   | | j  ||¡ƒS ©z.Convert a Python ``int`` object to ``dtype``. ©r   Úconvert©ÚK1r3   ÚK0r   r   r   Úfrom_ZZO   ó   zFractionField.from_ZZc                 C   r7   r8   r9   r;   r   r   r   Úfrom_ZZ_pythonS   r?   zFractionField.from_ZZ_pythonc                 C   sH   | j }|j}|jr| || |¡|ƒƒ| || |¡|ƒƒ S | |||ƒƒS ©z3Convert a Python ``Fraction`` object to ``dtype``. )r   Úconvert_fromÚis_ZZÚnumerÚdenom)r<   r3   r=   r   Úconvr   r   r   Úfrom_QQW   s
   (zFractionField.from_QQc                 C   r7   rA   r9   r;   r   r   r   Úfrom_QQ_python`   r?   zFractionField.from_QQ_pythonc                 C   r7   )z,Convert a GMPY ``mpz`` object to ``dtype``. r9   r;   r   r   r   Úfrom_ZZ_gmpyd   r?   zFractionField.from_ZZ_gmpyc                 C   r7   )z,Convert a GMPY ``mpq`` object to ``dtype``. r9   r;   r   r   r   Úfrom_QQ_gmpyh   r?   zFractionField.from_QQ_gmpyc                 C   r7   )z4Convert a ``GaussianRational`` object to ``dtype``. r9   r;   r   r   r   Úfrom_GaussianRationalFieldl   r?   z(FractionField.from_GaussianRationalFieldc                 C   r7   )z3Convert a ``GaussianInteger`` object to ``dtype``. r9   r;   r   r   r   Úfrom_GaussianIntegerRingp   r?   z&FractionField.from_GaussianIntegerRingc                 C   r7   ©z.Convert a mpmath ``mpf`` object to ``dtype``. r9   r;   r   r   r   Úfrom_RealFieldt   r?   zFractionField.from_RealFieldc                 C   r7   rM   r9   r;   r   r   r   Úfrom_ComplexFieldx   r?   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   rB   r   r;   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)
Ú	is_groundrB   Úcoeffr   r   Úset_ringr   Úringr   r   r;   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)Ú	set_fieldr   r   r   r;   r   r   r   Úfrom_FractionField“   s
   ÿz FractionField.from_FractionFieldc                 C   s   | j  ¡  ¡ S )z*Returns a field associated with ``self``. )r   Úto_ringÚ	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_positiverD   ÚLCr2   r   r   r   r]   ž   ó   zFractionField.is_positivec                 C   r\   )z'Returns True if ``LC(a)`` is negative. )r   Úis_negativerD   r^   r2   r   r   r   r`   ¢   r_   zFractionField.is_negativec                 C   r\   )z+Returns True if ``LC(a)`` is non-positive. )r   Úis_nonpositiverD   r^   r2   r   r   r   ra   ¦   r_   zFractionField.is_nonpositivec                 C   r\   )z+Returns True if ``LC(a)`` is non-negative. )r   Úis_nonnegativerD   r^   r2   r   r   r   rb   ª   r_   zFractionField.is_nonnegativec                 C   ó   |j S )zReturns numerator of ``a``. )rD   r2   r   r   r   rD   ®   ó   zFractionField.numerc                 C   rc   )zReturns denominator of ``a``. )rE   r2   r   r   r   rE   ²   rd   zFractionField.denomc                 C   s   |   | j |¡¡S )zReturns factorial of ``a``. )r   r   Ú	factorialr2   r   r   r   re   ¶   r?   zFractionField.factorial)NN)*r-   Ú
__module__Ú__qualname__Ú__doc__Úis_FractionFieldÚis_FracÚhas_assoc_RingÚhas_assoc_Fieldr   r   Úpropertyr   r!   r   r"   r#   r*   r.   r0   r4   r6   r>   r@   rG   rH   rI   rJ   rK   rL   rN   rO   rP   rV   rX   r[   r]   r`   ra   rb   rD   rE   re   r   r   r   r   r   	   sT    




	r   N)rh   Ú#sympy.polys.domains.compositedomainr   Úsympy.polys.domains.fieldr   Úsympy.polys.polyerrorsr   r   Úsympy.utilitiesr   r   r   r   r   r   Ú<module>   s    